2013-07-03 07:24:32 +00: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 "JavaScriptChild.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-08-01 23:45:17 +00:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2014-08-06 04:43:36 +00:00
|
|
|
#include "mozilla/ipc/MessageChannel.h"
|
2013-07-03 07:24:32 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "xpcprivate.h"
|
|
|
|
#include "jsfriendapi.h"
|
2014-08-06 04:43:36 +00:00
|
|
|
#include "AccessCheck.h"
|
2013-07-03 07:24:32 +00:00
|
|
|
|
|
|
|
using namespace JS;
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
using mozilla::AutoSafeJSContext;
|
|
|
|
|
|
|
|
static void
|
2016-07-23 17:52:47 +00:00
|
|
|
UpdateChildWeakPointersBeforeSweepingZoneGroup(JSContext* cx, void* data)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
static_cast<JavaScriptChild*>(data)->updateWeakPointers();
|
2014-09-02 09:07:22 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:37 +00:00
|
|
|
JavaScriptChild::~JavaScriptChild()
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
2016-08-11 12:39:23 +00:00
|
|
|
JSContext* cx = dom::danger::GetJSContext();
|
|
|
|
JS_RemoveWeakPointerZoneGroupCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup);
|
2013-07-03 07:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::init()
|
|
|
|
{
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!WrapperOwner::init())
|
2013-07-03 07:24:32 +00:00
|
|
|
return false;
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!WrapperAnswer::init())
|
|
|
|
return false;
|
|
|
|
|
2016-08-11 12:39:23 +00:00
|
|
|
JSContext* cx = dom::danger::GetJSContext();
|
|
|
|
JS_AddWeakPointerZoneGroupCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
|
2013-07-03 07:24:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:37 +00:00
|
|
|
void
|
2014-09-24 11:54:11 +00:00
|
|
|
JavaScriptChild::updateWeakPointers()
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
2014-09-02 09:07:22 +00:00
|
|
|
objects_.sweep();
|
2014-09-25 11:13:29 +00:00
|
|
|
unwaivedObjectIds_.sweep();
|
|
|
|
waivedObjectIds_.sweep();
|
2013-07-03 07:24:32 +00:00
|
|
|
}
|
2014-08-20 19:49:10 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject*
|
2014-09-13 00:41:18 +00:00
|
|
|
JavaScriptChild::scopeForTargetObjects()
|
2014-08-20 19:49:10 +00:00
|
|
|
{
|
2014-09-13 00:41:18 +00:00
|
|
|
// CPOWs from the parent need to point into the child's privileged junk
|
|
|
|
// scope so that they can benefit from XrayWrappers in the child.
|
2014-08-20 19:49:10 +00:00
|
|
|
return xpc::PrivilegedJunkScope();
|
|
|
|
}
|
2015-01-26 21:32:18 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
PJavaScriptChild*
|
2016-08-11 12:39:23 +00:00
|
|
|
mozilla::jsipc::NewJavaScriptChild()
|
2015-01-26 21:32:18 +00:00
|
|
|
{
|
2016-08-11 12:39:23 +00:00
|
|
|
JavaScriptChild* child = new JavaScriptChild();
|
2015-01-26 21:32:18 +00:00
|
|
|
if (!child->init()) {
|
|
|
|
delete child;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-28 22:22:11 +00:00
|
|
|
mozilla::jsipc::ReleaseJavaScriptChild(PJavaScriptChild* child)
|
2015-01-26 21:32:18 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
static_cast<JavaScriptChild*>(child)->decref();
|
2015-01-26 21:32:18 +00:00
|
|
|
}
|