Bug 673331 - Add identifying information to system compartments. r=mrbkap.

This commit is contained in:
Sander van Veen 2011-08-21 16:02:24 -07:00
Родитель e108d74316
Коммит 0d93bbb4b5
10 изменённых файлов: 58 добавлений и 17 удалений

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

@ -256,7 +256,8 @@ FeedWriter.prototype = {
__contentSandbox: null,
get _contentSandbox() {
if (!this.__contentSandbox)
this.__contentSandbox = new Cu.Sandbox(this._window);
this.__contentSandbox = new Cu.Sandbox(this._window,
{sandboxName: 'FeedWriter'});
return this.__contentSandbox;
},

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

@ -59,7 +59,7 @@ window.onload = function() {
gStateObject = JSON.parse(sessionData.value);
}
catch (exJSON) {
var s = new Cu.Sandbox("about:blank");
var s = new Cu.Sandbox("about:blank", {sandboxName: 'aboutSessionRestore'});
gStateObject = Cu.evalInSandbox("(" + sessionData.value + ")", s);
// If we couldn't parse the string with JSON.parse originally, make sure
// that the value in the textbox will be parsable.

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

@ -135,7 +135,7 @@ SessionStartup.prototype = {
this._initialState = JSON.parse(iniString);
}
catch (exJSON) {
var s = new Cu.Sandbox("about:blank");
var s = new Cu.Sandbox("about:blank", {sandboxName: 'nsSessionStartup'});
this._initialState = Cu.evalInSandbox("(" + iniString + ")", s);
}

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

@ -178,7 +178,8 @@ var Scratchpad = {
this._previousLocation != this.gBrowser.contentWindow.location.href) {
let contentWindow = this.gBrowser.selectedBrowser.contentWindow;
this._contentSandbox = new Cu.Sandbox(contentWindow,
{ sandboxPrototype: contentWindow, wantXrays: false });
{ sandboxPrototype: contentWindow, wantXrays: false,
sandboxName: 'scratchpad-content'});
this._previousBrowserWindow = this.browserWindow;
this._previousBrowser = this.gBrowser.selectedBrowser;
@ -211,7 +212,8 @@ var Scratchpad = {
if (!this._chromeSandbox ||
this.browserWindow != this._previousBrowserWindow) {
this._chromeSandbox = new Cu.Sandbox(this.browserWindow,
{ sandboxPrototype: this.browserWindow, wantXrays: false });
{ sandboxPrototype: this.browserWindow, wantXrays: false,
sandboxName: 'scratchpad-chrome'});
this._previousBrowserWindow = this.browserWindow;
}

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

@ -2073,7 +2073,8 @@ nsXPConnect::CreateSandbox(JSContext *cx, nsIPrincipal *principal,
jsval rval = JSVAL_VOID;
AUTO_MARK_JSVAL(ccx, &rval);
nsresult rv = xpc_CreateSandboxObject(cx, &rval, principal, NULL, false);
nsresult rv = xpc_CreateSandboxObject(cx, &rval, principal, NULL, false,
EmptyCString());
NS_ASSERTION(NS_FAILED(rv) || !JSVAL_IS_PRIMITIVE(rval),
"Bad return value from xpc_CreateSandboxObject()!");

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

@ -3153,7 +3153,7 @@ NS_IMPL_ISUPPORTS0(Identity)
nsresult
xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop, JSObject *proto,
bool wantXrays)
bool wantXrays, const nsACString &sandboxName)
{
// Create the sandbox global object
nsresult rv;
@ -3240,6 +3240,10 @@ xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop, JSOb
}
}
xpc::CompartmentPrivate *compartmentPrivate =
static_cast<xpc::CompartmentPrivate*>(JS_GetCompartmentPrivate(cx, compartment));
compartmentPrivate->location = sandboxName;
return NS_OK;
}
@ -3351,6 +3355,8 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
JSObject *proto = nsnull;
bool wantXrays = true;
nsCString sandboxName;
if (argc > 1) {
if (!JSVAL_IS_OBJECT(argv[1]))
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
@ -3382,9 +3388,26 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
wantXrays = JSVAL_TO_BOOLEAN(option);
}
if (!JS_HasProperty(cx, optionsObject, "sandboxName", &found))
return NS_ERROR_INVALID_ARG;
if (found) {
if (!JS_GetProperty(cx, optionsObject, "sandboxName", &option) ||
!JSVAL_IS_STRING(option)) {
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
char *tmp = JS_EncodeString(cx, JSVAL_TO_STRING(option));
if (!tmp) {
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
sandboxName.Adopt(tmp, strlen(tmp));
}
}
rv = xpc_CreateSandboxObject(cx, vp, prinOrSop, proto, wantXrays);
rv = xpc_CreateSandboxObject(cx, vp, prinOrSop, proto, wantXrays, sandboxName);
if (NS_FAILED(rv)) {
return ThrowAndFail(rv, cx, _retval);

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

@ -1578,22 +1578,30 @@ CompartmentStats::CompartmentStats(JSContext *cx, JSCompartment *c)
{
if(c->principals->codebase)
{
// A hack: replace forward slashes with '\\' so they aren't
// treated as path separators. Users of the reporters
// (such as about:memory) have to undo this change.
name.Assign(c->principals->codebase);
name.ReplaceChar('/', '\\');
// If it's the system compartment, append the address.
// This means that multiple system compartments (and there
// can be many) can be distinguished.
if(c->isSystemCompartment)
{
if (c->data &&
!((xpc::CompartmentPrivate*)c->data)->location.IsEmpty())
{
name.AppendLiteral(", ");
name.Append(((xpc::CompartmentPrivate*)c->data)->location);
}
// ample; 64-bit address max is 18 chars
static const int maxLength = 31;
nsPrintfCString address(maxLength, ", 0x%llx", PRUint64(c));
name.Append(address);
}
// A hack: replace forward slashes with '\\' so they aren't
// treated as path separators. Users of the reporters
// (such as about:memory) have to undo this change.
name.ReplaceChar('/', '\\');
}
else
{

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

@ -4315,7 +4315,7 @@ xpc_GetJSPrivate(JSObject *obj)
// and used.
nsresult
xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop,
JSObject *proto, bool preferXray);
JSObject *proto, bool preferXray, const nsACString &sandboxName);
// Helper for evaluating scripts in a sandbox object created with
// xpc_CreateSandboxObject(). The caller is responsible of ensuring
@ -4394,6 +4394,7 @@ struct CompartmentPrivate
JSObject2JSObjectMap *waiverWrapperMap;
// NB: we don't want this map to hold a strong reference to the wrapper.
nsDataHashtable<nsPtrHashKey<XPCWrappedNative>, JSObject *> *expandoMap;
nsCString location;
bool RegisterExpandoObject(XPCWrappedNative *wn, JSObject *expando) {
if (!expandoMap) {

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

@ -75,7 +75,8 @@ nsProxyAutoConfig.prototype = {
}
// allocate a fresh Sandbox to clear global scope for new PAC script
this._sandBox = new Components.utils.Sandbox(pacURI);
this._sandBox = new Components.utils.Sandbox(pacURI,
{sandboxName: 'nsProxyAutoConfig'});
Components.utils.evalInSandbox(pacUtils, this._sandBox);
// add predefined functions to pac

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

@ -3461,13 +3461,18 @@ var XPIProvider = {
let principal = Cc["@mozilla.org/systemprincipal;1"].
createInstance(Ci.nsIPrincipal);
this.bootstrapScopes[aId] = new Components.utils.Sandbox(principal);
if (!aFile.exists()) {
this.bootstrapScopes[aId] = new Components.utils.Sandbox(principal,
{sandboxName: aFile.path});
ERROR("Attempted to load bootstrap scope from missing directory " + bootstrap.path);
return;
}
let uri = getURIForResourceInFile(aFile, "bootstrap.js").spec;
this.bootstrapScopes[aId] = new Components.utils.Sandbox(principal,
{sandboxName: uri});
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
createInstance(Ci.mozIJSSubScriptLoader);
@ -3475,8 +3480,7 @@ var XPIProvider = {
// As we don't want our caller to control the JS version used for the
// bootstrap file, we run loadSubScript within the context of the
// sandbox with the latest JS version set explicitly.
this.bootstrapScopes[aId].__SCRIPT_URI_SPEC__ =
getURIForResourceInFile(aFile, "bootstrap.js").spec;
this.bootstrapScopes[aId].__SCRIPT_URI_SPEC__ = uri;
Components.utils.evalInSandbox(
"Components.classes['@mozilla.org/moz/jssubscript-loader;1'] \
.createInstance(Components.interfaces.mozIJSSubScriptLoader) \