Bug 752357 - Include compartment location (sandbox name) in compartment name when it differs from the principal name. r=nnethercote.
authorKevin Locke <kevin@kevinlocke.name>
Tue, 08 May 2012 19:02:37 -0700
changeset 93569 92cc1b470177e395b167a953f52e3927751220f9
parent 93568 fcf1739a4e17be40ee1f87c65f410e21f040307a
child 93570 6793673018a9f8928ef1008c9414ecf8ead989a5
push id9208
push usernnethercote@mozilla.com
push dateWed, 09 May 2012 02:03:34 +0000
treeherdermozilla-inbound@92cc1b470177 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnnethercote
bugs752357
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 752357 - Include compartment location (sandbox name) in compartment name when it differs from the principal name. r=nnethercote.
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1199,24 +1199,27 @@ XPCJSRuntime::~XPCJSRuntime()
 static void
 GetCompartmentName(JSCompartment *c, nsCString &name)
 {
     if (js::IsAtomsCompartment(c)) {
         name.AssignLiteral("atoms");
     } else if (JSPrincipals *principals = JS_GetCompartmentPrincipals(c)) {
         nsJSPrincipals::get(principals)->GetScriptLocation(name);
 
-        // For system compartments we append the location, if there is one.
-        if (js::IsSystemCompartment(c)) {
-            xpc::CompartmentPrivate *compartmentPrivate =
-                static_cast<xpc::CompartmentPrivate*>(JS_GetCompartmentPrivate(c));
-            if (compartmentPrivate && !compartmentPrivate->location.IsEmpty()) {
-                name.AppendLiteral(", ");
-                name.Append(compartmentPrivate->location);
-            }
+        // If the compartment's location (name) differs from the principal's
+        // script location, append the compartment's location to allow
+        // differentiation of multiple compartments owned by the same principal
+        // (e.g. components owned by the system or null principal).
+        xpc::CompartmentPrivate *compartmentPrivate =
+            static_cast<xpc::CompartmentPrivate*>(JS_GetCompartmentPrivate(c));
+        if (compartmentPrivate &&
+            !compartmentPrivate->location.IsEmpty() &&
+            !compartmentPrivate->location.Equals(name)) {
+            name.AppendLiteral(", ");
+            name.Append(compartmentPrivate->location);
         }
         
         // 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 {
         name.AssignLiteral("null-principal");