js/ipc/JavaScriptChild.cpp
author David Keeler <dkeeler@mozilla.com>
Wed, 08 Oct 2014 09:48:15 -0700
changeset 209464 3ae75c8b8f640c99186f04e7ffbacd4450b57e4b
parent 207253 4d94f2bf456a1a941851bd8ee0e50a52dffd61c1
child 238636 d7aa4c72ebaba57bb6a8f1c718bd63fb9e9feec1
permissions -rw-r--r--
bug 1058812 - (3/3) mozilla::pkix: test handling unsupported signature algorithms r=briansmith

/* -*- 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"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/ipc/MessageChannel.h"
#include "nsContentUtils.h"
#include "xpcprivate.h"
#include "jsfriendapi.h"
#include "AccessCheck.h"

using namespace JS;
using namespace mozilla;
using namespace mozilla::jsipc;

using mozilla::AutoSafeJSContext;

static void
UpdateChildWeakPointersAfterGC(JSRuntime *rt, void *data)
{
    static_cast<JavaScriptChild *>(data)->updateWeakPointers();
}

JavaScriptChild::JavaScriptChild(JSRuntime *rt)
  : JavaScriptShared(rt),
    JavaScriptBase<PJavaScriptChild>(rt)
{
}

JavaScriptChild::~JavaScriptChild()
{
    JS_RemoveWeakPointerCallback(rt_, UpdateChildWeakPointersAfterGC);
}

bool
JavaScriptChild::init()
{
    if (!WrapperOwner::init())
        return false;
    if (!WrapperAnswer::init())
        return false;

    JS_AddWeakPointerCallback(rt_, UpdateChildWeakPointersAfterGC, this);
    return true;
}

void
JavaScriptChild::updateWeakPointers()
{
    objects_.sweep();
    unwaivedObjectIds_.sweep();
    waivedObjectIds_.sweep();
}

JSObject *
JavaScriptChild::scopeForTargetObjects()
{
    // CPOWs from the parent need to point into the child's privileged junk
    // scope so that they can benefit from XrayWrappers in the child.
    return xpc::PrivilegedJunkScope();
}