Files
palemoon27/js/ipc/JavaScriptParent.cpp
T
roytam1 2859b42d1c import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1210573 - Add attribute 'packageIdentifier' to nsIPackagedAppUtils. r=valentin. (0115fa1b85)
- Bug 1178518 - Verify signed packages. r=valentin (5decf51ecb)
- Bug 1178518 - Add an AppTrustedRoot for signed packaged app. r=keeler (15e50605b4)
- Bug 1177013 - test_cpows.xul test for CPOW cancelation (r=dvander) (867c40bec1)
- Bug 1215167 - Forbid unsafe browser CPOWs (disabled by default for now) (r=mrbkap) (cee45a21b1)
- Bug 1174487. Stop using JS_ReportPendingException in ThrowAndReport. Just let the AutoJSAPI do the work for us. r=bholley (877d91b8ab)
- Bug 1213289 part 1. Change dom::Throw to take an XPCOM string, not a raw C string, for the message. r=bkelly (d15fbd30d5)
- Bug 1213289 part 2. Introduce ErrorResult::ClearUnionData and use it in various places where we're trying to do that. r=bkelly (c7e5dac146)
- Bug 1213289 part 3. Add a way to throw a DOMException with a custom message on ErrorResult. r=bkelly (aef71f28a9)
- Bug 1213289 part 4. Convert to using an enum for tracking our union state. r=bkelly (def36e74a1)
- Bug 1174593 - Null check context compartment in GetCurrentJSStack(). r=bholley (a785100a75)
- Bug 1216819 - Allow JSAPI SavedFrame accessors to skip past self-hosted frames. r=bz (e7c40f2c30)
- Bug 1200832 - make Console.trace follow async parents; r=baku,bgrins (9694111f6b)
- Bug 1218496 - Add MOZ_COUNT_CTOR/DTOR to ErrorResult::Message. r=bz (53ad08d1d3)
- Bug 1209107 - Only expose module environment object through testing functions r=shu (5fc969293e)
- Bug 930414 - Update module scope chain handling following addition of global lexical scope r=shu (1fc60942f1)
- fix typo (385064acb8)
- Bug 1215341 - Make assignment to const errors runtime TypeErrors in the frontend and interpreter. (r=jandem) (b1f959ad34)
- Bug 930414 - Implement module namespaces r=shu (8c78ae93f2)
- Bug 930414 - Make |this| undefined in modules r=shu (effe64e5ec)
- Bug 930414 - Replace |thisObject| object op with |thisValue| and use if for modules r=shu r=smaug (4875da587e)
- Bug 1125423 part 1 - Attach WindowProxies to globals instead of using innerObject/outerObject hooks. r=bz,luke (ae07ae6add)
- Bug 1125423 part 2 - Rename stopAtOuter argument to *Unwrap functionsto stopAtWindowProxy. r=bz (87334947c7)
- Bug 1125423 part 3 - Use IsWindow/IsWindowProxy functions instead of checking for Class hooks. r=bz (ec479123de)
- Bug 1219183 - Update comments that reference renamed thisObject hook r=shu (d99fd5f5a4)
- Bug 1125423 part 4 - Make GetThisValue infallible, stop invoking the Class hook. r=shu (7780fae25c)
- Bug 1125423 part 5 - Remove innerObject/outerObject/thisValue Class hooks. r=luke (e6798ba62f)
- Bug 1125423 part 6 - Remove nsGlobalWindow::OuterObject and ObjectToOuterObjectValue. r=bz (9c69c88ffc)
- Bug 1217061 - Report OOMs in IonCache::linkAndAttachStub(). r=djvj (6515dfc38f)
- Bug 1215573 - Remove AutoWritableJitCode from IonCache::updateBaseAddress. r=nbp (3b01574971)
- Bug 1209118 part 1 - Add id operand to MGetPropertyCache. r=efaust (d030b03035)
- Bug 1209118 part 2 - Fix GetPropertyIC stubs. r=efaust (3de861379e)
- Bug 1209118 part 3 - Move arguments element stub. r=efaust (90416752ec)
- Bug 1209118 part 4 - Move dense element stub. r=efaust (1c00927242)
- Bug 1209118 part 5 - Move dense element hole stub. r=efaust (888aeac645)
- Bug 1209118 part 6 - Move typed-or-unboxed element stub. r=efaust (1faf3c96eb)
- Bug 1209118 part 7 - Disable GetPropertyIC when the IC fails to attach stubs. r=efaust (ee29616d9e)
- Bug 1209118 part 8 - Use MGetPropertyCache for GETELEM. r=efaust (9ce7df2660)
- Bug 1209118 part 9 - rm MGetElementCache, GetElementIC. r=efaust (0c1747a8f8)
- Bug 1209118 part 10 - Fix a performance issue when disabling GetPropertyIC. r=efaust (c915688ed4)
- Bug 1209118 part 11 - Fix and simplify condition in GetPropertyIC::maybeDisable. r=efaust (051d4bc465)
- Bug 1214562 part 1 - SetElementCache no longer needs a byteop register on x86. r=bhackett (51353013a1)
- Bug 1214163 - Clean up SetPropertyIC::update. r=efaust (a520d092ac)
- Bug 1214562 part 2 - Refactor SetPropertyCache regalloc. r=bhackett (e7be5c651b)
- Bug 1216151 - Ensure the object has a non-lazy group in SetPropertyIC::tryAttachStub. r=efaust (205f6770cb)
- Bug 1213859 - Focus and blur events should not be cancelable; r=smaug (17e8f894d7)
2022-10-24 11:58:19 +08:00

144 lines
3.9 KiB
C++

/* -*- 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 "jswrapper.h"
#include "js/Proxy.h"
#include "js/HeapAPI.h"
#include "xpcprivate.h"
#include "mozilla/Casting.h"
using namespace js;
using namespace JS;
using namespace mozilla;
using namespace mozilla::jsipc;
using namespace mozilla::dom;
static void
TraceParent(JSTracer* trc, void* data)
{
static_cast<JavaScriptParent*>(data)->trace(trc);
}
JavaScriptParent::JavaScriptParent(JSRuntime* rt)
: JavaScriptShared(rt),
JavaScriptBase<PJavaScriptParent>(rt)
{
}
JavaScriptParent::~JavaScriptParent()
{
JS_RemoveExtraGCRootsTracer(rt_, TraceParent, this);
}
bool
JavaScriptParent::init()
{
if (!WrapperOwner::init())
return false;
JS_AddExtraGCRootsTracer(rt_, TraceParent, this);
return true;
}
static bool
ForbidUnsafeBrowserCPOWs()
{
static bool result;
static bool cached = false;
if (!cached) {
cached = true;
Preferences::AddBoolVarCache(&result, "dom.ipc.cpows.forbid-unsafe-from-browser", false);
}
return result;
}
bool
JavaScriptParent::allowMessage(JSContext* cx)
{
MessageChannel* channel = GetIPCChannel();
if (channel->IsInTransaction())
return true;
if (ForbidUnsafeBrowserCPOWs()) {
if (JSObject* global = JS::CurrentGlobalOrNull(cx)) {
if (!JS::AddonIdOfObject(global)) {
JS_ReportError(cx, "unsafe CPOW usage forbidden");
return false;
}
}
}
static bool disableUnsafeCPOWWarnings = PR_GetEnv("DISABLE_UNSAFE_CPOW_WARNINGS");
if (!disableUnsafeCPOWWarnings) {
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
if (console && cx) {
nsAutoString filename;
uint32_t lineno = 0, column = 0;
nsJSUtils::GetCallingLocation(cx, filename, &lineno, &column);
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
error->Init(NS_LITERAL_STRING("unsafe CPOW usage"), filename,
EmptyString(), lineno, column,
nsIScriptError::warningFlag, "chrome javascript");
console->LogMessage(error);
} else {
NS_WARNING("Unsafe synchronous IPC message");
}
}
return true;
}
void
JavaScriptParent::trace(JSTracer* trc)
{
objects_.trace(trc);
unwaivedObjectIds_.trace(trc);
waivedObjectIds_.trace(trc);
}
JSObject*
JavaScriptParent::scopeForTargetObjects()
{
// 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.
return xpc::UnprivilegedJunkScope();
}
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();
}
PJavaScriptParent*
mozilla::jsipc::NewJavaScriptParent(JSRuntime* rt)
{
JavaScriptParent* parent = new JavaScriptParent(rt);
if (!parent->init()) {
delete parent;
return nullptr;
}
return parent;
}
void
mozilla::jsipc::ReleaseJavaScriptParent(PJavaScriptParent* parent)
{
static_cast<JavaScriptParent*>(parent)->decref();
}