2013-07-03 11:24:32 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=80:
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "JavaScriptParent.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "jsfriendapi.h"
|
|
|
|
#include "jsproxy.h"
|
2013-08-18 02:50:18 +04:00
|
|
|
#include "jswrapper.h"
|
2013-07-03 11:24:32 +04:00
|
|
|
#include "HeapAPI.h"
|
|
|
|
#include "xpcprivate.h"
|
|
|
|
#include "mozilla/Casting.h"
|
|
|
|
|
|
|
|
using namespace js;
|
|
|
|
using namespace JS;
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::jsipc;
|
2013-06-03 14:14:37 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-07-03 11:24:32 +04:00
|
|
|
|
2014-05-17 03:40:37 +04:00
|
|
|
static void
|
|
|
|
TraceParent(JSTracer *trc, void *data)
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2014-05-17 03:40:37 +04:00
|
|
|
static_cast<JavaScriptParent *>(data)->trace(trc);
|
2013-07-03 11:24:32 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 03:40:37 +04:00
|
|
|
JavaScriptParent::JavaScriptParent(JSRuntime *rt)
|
|
|
|
: JavaScriptShared(rt),
|
|
|
|
JavaScriptBase<PJavaScriptParent>(rt)
|
2013-07-11 19:23:34 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-17 03:40:37 +04:00
|
|
|
JavaScriptParent::~JavaScriptParent()
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2014-05-17 03:40:37 +04:00
|
|
|
JS_RemoveExtraGCRootsTracer(rt_, TraceParent, this);
|
2013-07-03 11:24:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-17 03:40:37 +04:00
|
|
|
JavaScriptParent::init()
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2014-05-17 03:40:37 +04:00
|
|
|
if (!WrapperOwner::init())
|
2013-07-03 11:24:32 +04:00
|
|
|
return false;
|
|
|
|
|
2014-05-17 03:40:37 +04:00
|
|
|
JS_AddExtraGCRootsTracer(rt_, TraceParent, this);
|
2013-07-03 11:24:32 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-17 03:40:37 +04:00
|
|
|
JavaScriptParent::trace(JSTracer *trc)
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2014-09-24 15:54:11 +04:00
|
|
|
if (active()) {
|
2014-05-17 03:40:37 +04:00
|
|
|
objects_.trace(trc);
|
2014-09-25 15:13:29 +04:00
|
|
|
unwaivedObjectIds_.trace(trc);
|
|
|
|
waivedObjectIds_.trace(trc);
|
2014-09-24 15:54:11 +04:00
|
|
|
}
|
2013-07-03 11:24:32 +04:00
|
|
|
}
|
|
|
|
|
2014-08-20 23:49:10 +04:00
|
|
|
JSObject *
|
2014-09-13 04:41:18 +04:00
|
|
|
JavaScriptParent::scopeForTargetObjects()
|
2014-08-20 23:49:10 +04:00
|
|
|
{
|
2014-09-13 04:41:18 +04:00
|
|
|
// CPWOWs from the child need to point into the parent's unprivileged junk
|
|
|
|
// scope so that a compromised child cannot compromise the parent. In
|
|
|
|
// practice, this means that a child process can only (a) hold parent
|
|
|
|
// objects alive and (b) invoke them if they are callable.
|
2014-08-20 23:49:10 +04:00
|
|
|
return xpc::UnprivilegedJunkScope();
|
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
mozilla::ipc::IProtocol*
|
|
|
|
JavaScriptParent::CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx)
|
|
|
|
{
|
|
|
|
ContentParent *contentParent = aCtx->GetContentParent();
|
|
|
|
nsAutoPtr<PJavaScriptParent> actor(contentParent->AllocPJavaScriptParent());
|
|
|
|
if (!actor || !contentParent->RecvPJavaScriptConstructor(actor)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return actor.forget();
|
|
|
|
}
|