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 "JavaScriptChild.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-08-02 03:45:17 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2014-08-06 08:43:36 +04:00
|
|
|
#include "mozilla/ipc/MessageChannel.h"
|
2013-07-03 11:24:32 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "xpcprivate.h"
|
|
|
|
#include "jsfriendapi.h"
|
2014-08-06 08:43:36 +04:00
|
|
|
#include "AccessCheck.h"
|
2013-07-03 11:24:32 +04:00
|
|
|
|
|
|
|
using namespace JS;
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
using mozilla::AutoSafeJSContext;
|
|
|
|
|
|
|
|
static void
|
2016-07-23 20:52:47 +03:00
|
|
|
UpdateChildWeakPointersBeforeSweepingZoneGroup(JSContext* cx, void* data)
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
static_cast<JavaScriptChild*>(data)->updateWeakPointers();
|
2014-09-02 13:07:22 +04:00
|
|
|
}
|
|
|
|
|
2016-10-19 01:58:33 +03:00
|
|
|
static void
|
|
|
|
TraceChild(JSTracer* trc, void* data)
|
|
|
|
{
|
|
|
|
static_cast<JavaScriptChild*>(data)->trace(trc);
|
|
|
|
}
|
|
|
|
|
2014-05-17 03:40:37 +04:00
|
|
|
JavaScriptChild::~JavaScriptChild()
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2016-08-11 15:39:23 +03:00
|
|
|
JSContext* cx = dom::danger::GetJSContext();
|
2017-03-22 20:30:50 +03:00
|
|
|
JS_RemoveWeakPointerZonesCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup);
|
2016-10-19 01:58:33 +03:00
|
|
|
JS_RemoveExtraGCRootsTracer(cx, TraceChild, this);
|
2013-07-03 11:24:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::init()
|
|
|
|
{
|
2014-05-17 03:40:36 +04:00
|
|
|
if (!WrapperOwner::init())
|
2013-07-03 11:24:32 +04:00
|
|
|
return false;
|
2014-05-17 03:40:36 +04:00
|
|
|
if (!WrapperAnswer::init())
|
|
|
|
return false;
|
|
|
|
|
2016-08-11 15:39:23 +03:00
|
|
|
JSContext* cx = dom::danger::GetJSContext();
|
2017-03-22 20:30:50 +03:00
|
|
|
JS_AddWeakPointerZonesCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
|
2016-10-19 01:58:33 +03:00
|
|
|
JS_AddExtraGCRootsTracer(cx, TraceChild, this);
|
2013-07-03 11:24:32 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-19 01:58:33 +03:00
|
|
|
void
|
|
|
|
JavaScriptChild::trace(JSTracer* trc)
|
|
|
|
{
|
|
|
|
objects_.trace(trc, strongReferenceObjIdMinimum_);
|
|
|
|
}
|
|
|
|
|
2014-05-17 03:40:37 +04:00
|
|
|
void
|
2014-09-24 15:54:11 +04:00
|
|
|
JavaScriptChild::updateWeakPointers()
|
2013-07-03 11:24:32 +04:00
|
|
|
{
|
2014-09-02 13:07:22 +04:00
|
|
|
objects_.sweep();
|
2014-09-25 15:13:29 +04:00
|
|
|
unwaivedObjectIds_.sweep();
|
|
|
|
waivedObjectIds_.sweep();
|
2013-07-03 11:24:32 +04:00
|
|
|
}
|
2014-08-20 23:49:10 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
JSObject*
|
2014-09-13 04:41:18 +04:00
|
|
|
JavaScriptChild::scopeForTargetObjects()
|
2014-08-20 23:49:10 +04:00
|
|
|
{
|
2014-09-13 04:41:18 +04: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 23:49:10 +04:00
|
|
|
return xpc::PrivilegedJunkScope();
|
|
|
|
}
|
2015-01-27 00:32:18 +03:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2016-10-19 01:58:33 +03:00
|
|
|
JavaScriptChild::RecvDropTemporaryStrongReferences(const uint64_t& upToObjId)
|
|
|
|
{
|
|
|
|
strongReferenceObjIdMinimum_ = upToObjId + 1;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-10-19 01:58:33 +03:00
|
|
|
}
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
PJavaScriptChild*
|
2016-08-11 15:39:23 +03:00
|
|
|
mozilla::jsipc::NewJavaScriptChild()
|
2015-01-27 00:32:18 +03:00
|
|
|
{
|
2016-08-11 15:39:23 +03:00
|
|
|
JavaScriptChild* child = new JavaScriptChild();
|
2015-01-27 00:32:18 +03:00
|
|
|
if (!child->init()) {
|
|
|
|
delete child;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-29 01:22:11 +03:00
|
|
|
mozilla::jsipc::ReleaseJavaScriptChild(PJavaScriptChild* child)
|
2015-01-27 00:32:18 +03:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
static_cast<JavaScriptChild*>(child)->decref();
|
2015-01-27 00:32:18 +03:00
|
|
|
}
|