Bug 1478275 part 2 - Add a CompartmentPrivate::isSandboxCompartment flag and xpc::IsInSandboxCompartment(obj). r=bholley

Wrappers are per-compartment, not per-realm, so this will simplify the next patch. Also, considering the upcoming Realms proposal, it might eventually be possible to have multiple globals in a sandbox compartment.
This commit is contained in:
Jan de Mooij 2018-07-26 10:58:37 +02:00
Родитель 1f193575a4
Коммит ce81f1f7ef
4 изменённых файлов: 17 добавлений и 0 удалений

Просмотреть файл

@ -1112,6 +1112,7 @@ xpc::CreateSandboxObject(JSContext* cx, MutableHandleValue vp, nsISupports* prin
priv->allowWaivers = options.allowWaivers;
priv->isWebExtensionContentScript = options.isWebExtensionContentScript;
priv->isContentXBLCompartment = options.isContentXBLScope;
priv->isSandboxCompartment = true;
// Set up the wantXrays flag, which indicates whether xrays are desired even
// for same-origin access.

Просмотреть файл

@ -215,6 +215,7 @@ CompartmentPrivate::CompartmentPrivate(JS::Compartment* c)
, isWebExtensionContentScript(false)
, allowCPOWs(false)
, isContentXBLCompartment(false)
, isSandboxCompartment(false)
, universalXPConnectEnabled(false)
, forcePermissiveCOWs(false)
, wasNuked(false)
@ -491,6 +492,16 @@ IsInContentXBLScope(JSObject* obj)
return IsContentXBLCompartment(js::GetObjectCompartment(obj));
}
bool
IsInSandboxCompartment(JSObject* obj)
{
JS::Compartment* comp = js::GetObjectCompartment(obj);
// We always eagerly create compartment privates for sandbox compartments.
CompartmentPrivate* priv = CompartmentPrivate::Get(comp);
return priv && priv->isSandboxCompartment;
}
bool
IsUniversalXPConnectEnabled(JS::Compartment* compartment)
{

Просмотреть файл

@ -2873,6 +2873,9 @@ public:
// such a compartment is a content XBL scope.
bool isContentXBLCompartment;
// True if this is a sandbox compartment. See xpc::CreateSandboxObject.
bool isSandboxCompartment;
// This is only ever set during mochitest runs when enablePrivilege is called.
// It's intended as a temporary stopgap measure until we can finish ripping out
// enablePrivilege. Once set, this value is never unset (i.e., it doesn't follow

Просмотреть файл

@ -85,6 +85,8 @@ bool IsContentXBLCompartment(JS::Compartment* compartment);
bool IsContentXBLScope(JS::Realm* realm);
bool IsInContentXBLScope(JSObject* obj);
bool IsInSandboxCompartment(JSObject* obj);
// Return a raw XBL scope object corresponding to contentScope, which must
// be an object whose global is a DOM window.
//