2013-07-03 00:24:32 -07: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-17 15:50:18 -07:00
|
|
|
#include "jswrapper.h"
|
2013-07-03 00:24:32 -07: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 03:14:37 -07:00
|
|
|
using namespace mozilla::dom;
|
2013-07-03 00:24:32 -07:00
|
|
|
|
2014-05-16 16:40:37 -07:00
|
|
|
static void
|
|
|
|
TraceParent(JSTracer *trc, void *data)
|
2013-07-03 00:24:32 -07:00
|
|
|
{
|
2014-05-16 16:40:37 -07:00
|
|
|
static_cast<JavaScriptParent *>(data)->trace(trc);
|
2013-07-03 00:24:32 -07:00
|
|
|
}
|
|
|
|
|
2014-05-16 16:40:37 -07:00
|
|
|
JavaScriptParent::JavaScriptParent(JSRuntime *rt)
|
|
|
|
: JavaScriptShared(rt),
|
|
|
|
JavaScriptBase<PJavaScriptParent>(rt)
|
2013-07-11 08:23:34 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-16 16:40:37 -07:00
|
|
|
JavaScriptParent::~JavaScriptParent()
|
2013-07-03 00:24:32 -07:00
|
|
|
{
|
2014-05-16 16:40:37 -07:00
|
|
|
JS_RemoveExtraGCRootsTracer(rt_, TraceParent, this);
|
2013-07-03 00:24:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-16 16:40:37 -07:00
|
|
|
JavaScriptParent::init()
|
2013-07-03 00:24:32 -07:00
|
|
|
{
|
2014-05-16 16:40:37 -07:00
|
|
|
if (!WrapperOwner::init())
|
2013-07-03 00:24:32 -07:00
|
|
|
return false;
|
|
|
|
|
2014-05-16 16:40:37 -07:00
|
|
|
JS_AddExtraGCRootsTracer(rt_, TraceParent, this);
|
2013-07-03 00:24:32 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-16 16:40:37 -07:00
|
|
|
JavaScriptParent::trace(JSTracer *trc)
|
2013-07-03 00:24:32 -07:00
|
|
|
{
|
2014-05-16 16:40:37 -07:00
|
|
|
if (active())
|
|
|
|
objects_.trace(trc);
|
2013-07-03 00:24:32 -07:00
|
|
|
}
|
|
|
|
|
2014-08-20 12:49:10 -07:00
|
|
|
JSObject *
|
|
|
|
JavaScriptParent::defaultScope()
|
|
|
|
{
|
|
|
|
return xpc::UnprivilegedJunkScope();
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:37 -07: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();
|
|
|
|
}
|