Bug 790732 - Omit Components object for content scopes. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Tue, 05 Mar 2013 10:02:00 -0800
changeset 123861 6d8d36cce3e341f942ec694924fa45a42a281770
parent 123860 00b10e10d3564383a297f808fe2778ae96457140
child 123862 fa67fd3bbb44c6e15f1d3671005e2293a2ab1503
push id1401
push userpastithas@mozilla.com
push dateThu, 07 Mar 2013 07:26:45 +0000
treeherderfx-team@ee4879719f78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs790732
milestone22.0a1
Bug 790732 - Omit Components object for content scopes. r=mrbkap
dom/base/nsGlobalWindow.cpp
js/xpconnect/src/XPCJSRuntime.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1941,20 +1941,26 @@ CreateNativeGlobalForInner(JSContext* aC
   MOZ_ASSERT(aNewInner);
   MOZ_ASSERT(aNewInner->IsInnerWindow());
   MOZ_ASSERT(aPrincipal);
   MOZ_ASSERT(aNativeGlobal);
   MOZ_ASSERT(aHolder);
 
   nsIXPConnect* xpc = nsContentUtils::XPConnect();
 
+  // If we've got XBL scopes enabled, we can now turn off the Components object
+  // for content.
+  bool usingXBLScope = !nsContentUtils::IsSystemPrincipal(aPrincipal) &&
+                       Preferences::GetBool("dom.xbl_scopes",  true);
+  uint32_t flags = usingXBLScope ? nsIXPConnect::OMIT_COMPONENTS_OBJECT : 0;
+
   nsRefPtr<nsIXPConnectJSObjectHolder> jsholder;
   nsresult rv = xpc->InitClassesWithNewWrappedGlobal(
     aCx, ToSupports(aNewInner),
-    aPrincipal, 0, getter_AddRefs(jsholder));
+    aPrincipal, flags, getter_AddRefs(jsholder));
   NS_ENSURE_SUCCESS(rv, rv);
 
   MOZ_ASSERT(jsholder);
   jsholder->GetJSObject(aNativeGlobal);
   jsholder.forget(aHolder);
 
   // Set the location information for the new global, so that tools like
   // about:memory may use that information
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -277,18 +277,28 @@ EnableUniversalXPConnect(JSContext *cx)
         return true;
     CompartmentPrivate *priv = GetCompartmentPrivate(compartment);
     if (!priv)
         return true;
     priv->universalXPConnectEnabled = true;
 
     // Recompute all the cross-compartment wrappers leaving the newly-privileged
     // compartment.
-    return js::RecomputeWrappers(cx, js::SingleCompartment(compartment),
-                                 js::AllCompartments());
+    bool ok = js::RecomputeWrappers(cx, js::SingleCompartment(compartment),
+                                    js::AllCompartments());
+    NS_ENSURE_TRUE(ok, false);
+
+    // The Components object normally isn't defined for unprivileged web content,
+    // but we define it when UniversalXPConnect is enabled to support legacy
+    // tests.
+    XPCWrappedNativeScope *scope = priv->scope;
+    if (!scope)
+        return true;
+    XPCCallContext ccx(NATIVE_CALLER, cx);
+    return nsXPCComponents::AttachComponentsObject(ccx, scope);
 }
 
 }
 
 static void
 CompartmentDestroyedCallback(JSFreeOp *fop, JSCompartment *compartment)
 {
     XPCJSRuntime* self = nsXPConnect::GetRuntimeInstance();