From 6463b16c2580b8762a2a681d7106eabc70724a01 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Tue, 26 Mar 2013 23:40:45 -0700 Subject: [PATCH] Back out 8e59146e161e:29acf1494fed (bug 790732) for failing in exactly the same way it failed on the tryserver CLOSED TREE --- dom/base/nsDOMClassInfo.cpp | 98 ------------------- dom/base/nsGlobalWindow.cpp | 22 +---- js/xpconnect/src/XPCComponents.cpp | 7 +- js/xpconnect/src/XPCJSRuntime.cpp | 14 +-- js/xpconnect/src/nsXPConnect.cpp | 3 + js/xpconnect/src/xpcprivate.h | 6 +- js/xpconnect/tests/chrome/test_bug795275.xul | 18 +--- js/xpconnect/tests/mochitest/Makefile.in | 2 - .../tests/mochitest/file_bug790732.html | 56 ----------- .../tests/mochitest/test_bug790732.html | 46 --------- modules/libpref/src/init/all.js | 3 - .../passwordmgr/test/test_prompt.html | 12 ++- .../satchel/test/test_form_autocomplete.html | 2 +- toolkit/components/telemetry/Histograms.json | 4 - 14 files changed, 29 insertions(+), 264 deletions(-) delete mode 100644 js/xpconnect/tests/mochitest/file_bug790732.html delete mode 100644 js/xpconnect/tests/mochitest/test_bug790732.html diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 6dfc8380a433..33b2fcaa6a26 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -5162,98 +5162,6 @@ LocationSetterUnwrapper(JSContext *cx, JSHandleObject obj_, JSHandleId id, JSBoo return LocationSetter(cx, obj, id, strict, vp); } -struct InterfaceShimEntry { - const char *geckoName; - const char *domName; -}; - -// We add shims from Components.interfaces.nsIDOMFoo to window.Foo for each -// interface that has interface constants that sites might be getting off -// of Ci. -const InterfaceShimEntry kInterfaceShimMap[] = -{ { "nsIDOMFileReader", "FileReader" }, - { "nsIXMLHttpRequest", "XMLHttpRequest" }, - { "nsIDOMDOMException", "DOMException" }, - { "nsIDOMNode", "Node" }, - { "nsIDOMUserDataHandler", "UserDataHandler" }, - { "nsIDOMCSSPrimitiveValue", "CSSPrimitiveValue" }, - { "nsIDOMCSSRule", "CSSRule" }, - { "nsIDOMCSSValue", "CSSValue" }, - { "nsIDOMEvent", "Event" }, - { "nsIDOMNSEvent", "Event" }, - { "nsIDOMKeyEvent", "KeyEvent" }, - { "nsIDOMMouseEvent", "MouseEvent" }, - { "nsIDOMMouseScrollEvent", "MouseScrollEvent" }, - { "nsIDOMMutationEvent", "MutationEvent" }, - { "nsIDOMSimpleGestureEvent", "SimpleGestureEvent" }, - { "nsIDOMUIEvent", "UIEvent" }, - { "nsIDOMGeoPositionError", "GeoPositionError" }, - { "nsIDOMHTMLMediaElement", "HTMLMediaElement" }, - { "nsIDOMMediaError", "MediaError" }, - { "nsIDOMLoadStatus", "LoadStatus" }, - { "nsIDOMOfflineResourceList", "OfflineResourceList" }, - { "nsIDOMRange", "Range" }, - { "nsIDOMSVGFETurbulenceElement", "SVGFETurbulenceElement" }, - { "nsIDOMSVGFEMorphologyElement", "SVGFEMorphologyElement" }, - { "nsIDOMSVGFEConvolveMatrixElement", "SVGFEConvolveMatrixElement" }, - { "nsIDOMSVGFEDisplacementMapElement", "SVGFEDisplacementMapElement" }, - { "nsIDOMSVGLength", "SVGLength" }, - { "nsIDOMSVGUnitTypes", "SVGUnitTypes" }, - { "nsIDOMNodeFilter", "NodeFilter" }, - { "nsIDOMXPathNamespace", "XPathNamespace" }, - { "nsIDOMXPathResult", "XPathResult" }, - { "nsIDOMXULButtonElement", "XULButtonElement" }, - { "nsIDOMXULCheckboxElement", "XULCheckboxElement" }, - { "nsIDOMXULPopupElement", "XULPopupElement" } }; - -static nsresult -DefineComponentsShim(JSContext *cx, JS::HandleObject global) -{ - // Keep track of how often this happens. - Telemetry::Accumulate(Telemetry::COMPONENTS_SHIM_ACCESSED_BY_CONTENT, true); - - // Create a fake Components object. - JSObject *components = JS_NewObject(cx, nullptr, nullptr, global); - NS_ENSURE_TRUE(components, NS_ERROR_OUT_OF_MEMORY); - bool ok = JS_DefineProperty(cx, global, "Components", JS::ObjectValue(*components), - JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE); - NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); - - // Create a fake interfaces object. - JSObject *interfaces = JS_NewObject(cx, nullptr, nullptr, global); - NS_ENSURE_TRUE(interfaces, NS_ERROR_OUT_OF_MEMORY); - ok = JS_DefineProperty(cx, components, "interfaces", JS::ObjectValue(*interfaces), - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); - - // Define a bunch of shims from the Ci.nsIDOMFoo to window.Foo for DOM - // interfaces with constants. - for (uint32_t i = 0; i < ArrayLength(kInterfaceShimMap); ++i) { - - // Grab the names from the table. - const char *geckoName = kInterfaceShimMap[i].geckoName; - const char *domName = kInterfaceShimMap[i].domName; - - // Look up the appopriate interface object on the global. - JS::Value v = JS::UndefinedValue(); - ok = JS_GetProperty(cx, global, domName, &v); - NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); - if (!v.isObject()) { - NS_WARNING("Unable to find interface object on global"); - continue; - } - - // Define the shim on the interfaces object. - ok = JS_DefineProperty(cx, interfaces, geckoName, v, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); - } - - return NS_OK; -} - NS_IMETHODIMP nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj_, jsid id_, uint32_t flags, @@ -5266,12 +5174,6 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, return NS_OK; } - MOZ_ASSERT(*_retval == true); // guaranteed by XPC_WN_Helper_NewResolve - if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)) { - *objp = obj; - return DefineComponentsShim(cx, obj); - } - nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper); MOZ_ASSERT(win->IsInnerWindow()); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index b25a59b46e1b..faba920f3359 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1971,17 +1971,6 @@ nsGlobalWindow::SetOuterObject(JSContext* aCx, JSObject* aOuterObject) return NS_OK; } -// We need certain special behavior for remote XUL whitelisted domains, but we -// don't want that behavior to take effect in automation, because we whitelist -// all the mochitest domains. So we need to check a pref here. -static bool -TreatAsRemoteXUL(nsIPrincipal* aPrincipal) -{ - MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(aPrincipal)); - return nsContentUtils::AllowXULXBLForPrincipal(aPrincipal) && - !Preferences::GetBool("dom.use_xbl_scopes_for_remote_xul", false); -} - /** * Create a new global object that will be used for an inner window. * Return the native global and an nsISupports 'holder' that can be used @@ -2015,19 +2004,10 @@ CreateNativeGlobalForInner(JSContext* aCx, nsIXPConnect* xpc = nsContentUtils::XPConnect(); - // Determine if we need the Components object. - bool componentsInContent = - !Preferences::GetBool("dom.omit_components_in_content", true) || - !Preferences::GetBool("dom.xbl_scopes", true); - bool needComponents = componentsInContent || - nsContentUtils::IsSystemPrincipal(aPrincipal) || - TreatAsRemoteXUL(aPrincipal); - uint32_t flags = needComponents ? 0 : nsIXPConnect::OMIT_COMPONENTS_OBJECT; - nsRefPtr jsholder; nsresult rv = xpc->InitClassesWithNewWrappedGlobal( aCx, ToSupports(aNewInner), - aPrincipal, flags, zoneSpec, getter_AddRefs(jsholder)); + aPrincipal, 0, zoneSpec, getter_AddRefs(jsholder)); NS_ENSURE_SUCCESS(rv, rv); MOZ_ASSERT(jsholder); diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index bf1c0d110f5a..6153f8ab579d 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -4880,7 +4880,8 @@ ContentComponentsGetterOp(JSContext *cx, JSHandleObject obj, JSHandleId id, // static JSBool nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx, - XPCWrappedNativeScope* aScope) + XPCWrappedNativeScope* aScope, + JSObject* aTarget) { JSObject *components = aScope->GetComponentsJSObject(ccx); if (!components) @@ -4888,11 +4889,13 @@ nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx, JSObject *global = aScope->GetGlobalJSObject(); MOZ_ASSERT(js::IsObjectInContextCompartment(global, ccx)); + if (!aTarget) + aTarget = global; jsid id = ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_COMPONENTS); JSPropertyOp getter = AccessCheck::isChrome(global) ? nullptr : &ContentComponentsGetterOp; - return JS_DefinePropertyById(ccx, global, id, js::ObjectValue(*components), + return JS_DefinePropertyById(ccx, aTarget, id, js::ObjectValue(*components), getter, nullptr, JSPROP_PERMANENT | JSPROP_READONLY); } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 535a55de9ece..5e7413cca5b4 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -282,18 +282,8 @@ EnableUniversalXPConnect(JSContext *cx) // Recompute all the cross-compartment wrappers leaving the newly-privileged // compartment. - 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); + return js::RecomputeWrappers(cx, js::SingleCompartment(compartment), + js::AllCompartments()); } } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 2e8e89876c09..f667c7cf260e 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -946,6 +946,9 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj) scope->RemoveWrappedNativeProtos(); + if (!nsXPCComponents::AttachComponentsObject(ccx, scope)) + return UnexpectedFailure(NS_ERROR_FAILURE); + if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, aGlobalJSObj)) return UnexpectedFailure(NS_ERROR_FAILURE); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 80f6916c1dce..7f9752fb08e1 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -3722,9 +3722,13 @@ public: NS_DECL_NSISECURITYCHECKEDCOMPONENT public: + // The target is the object upon which |Components| will be defined. If + // aTarget is left null, a default object will be computed. This is usually + // the right thing to do. static JSBool AttachComponentsObject(XPCCallContext& ccx, - XPCWrappedNativeScope* aScope); + XPCWrappedNativeScope* aScope, + JSObject* aTarget = NULL); void SystemIsBeingShutDown() {ClearMembers();} diff --git a/js/xpconnect/tests/chrome/test_bug795275.xul b/js/xpconnect/tests/chrome/test_bug795275.xul index 816013f491a0..e752b4ed07f3 100644 --- a/js/xpconnect/tests/chrome/test_bug795275.xul +++ b/js/xpconnect/tests/chrome/test_bug795275.xul @@ -20,14 +20,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275 /** Test for Warning in content scopes about Components. **/ SimpleTest.waitForExplicitFinish(); - SpecialPowers.pushPrefEnv({set: [['dom.omit_components_in_content', false]]}, startLoad); - function startLoad() { - for (var i = 1; i <= document.getElementsByTagName('iframe').length; ++i) { - var frame = document.getElementById('frame' + i); - frame.contentWindow.location = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html'; - frame.onload = frameLoaded; - } - } // Set up our console listener. var gWarnings = 0; @@ -81,10 +73,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275 ]]> - - - diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 5a3f213174d5..46c10df52794 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -715,9 +715,6 @@ pref("dom.min_background_timeout_value", 1000); // Run content XBL in a separate scope. pref("dom.xbl_scopes", true); -// Stop defining the Components object in content. -pref("dom.omit_components_in_content", false); - // Don't use new input types pref("dom.experimental_forms", false); diff --git a/toolkit/components/passwordmgr/test/test_prompt.html b/toolkit/components/passwordmgr/test/test_prompt.html index 31f85d153b8b..bc1f8424987b 100644 --- a/toolkit/components/passwordmgr/test/test_prompt.html +++ b/toolkit/components/passwordmgr/test/test_prompt.html @@ -138,7 +138,7 @@ var resolveCallback = { const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports]; if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; + throw Components.results.NS_ERROR_NO_INTERFACE; return this; }, @@ -160,10 +160,12 @@ var resolveCallback = { function startup() { //need to allow for arbitrary network servers defined in PAC instead of a hardcoded moz-proxy. - var ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]. - getService(SpecialPowers.Ci.nsIIOService); + var ios = SpecialPowers.wrap(Components). + classes["@mozilla.org/network/io-service;1"]. + getService(Components.interfaces.nsIIOService); - var pps = SpecialPowers.Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(); + var pps = SpecialPowers.wrap(Components). + classes["@mozilla.org/network/protocol-proxy-service;1"].getService(); var uri = ios.newURI("http://example.com", null, null); pps.asyncResolve(uri, 0, resolveCallback); @@ -181,7 +183,7 @@ var storageObserver = { Ci.nsISupports, Ci.nsISupportsWeakReference]; if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; + throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; return this; }, diff --git a/toolkit/components/satchel/test/test_form_autocomplete.html b/toolkit/components/satchel/test/test_form_autocomplete.html index 03142d3529c7..e18b860cf0a1 100644 --- a/toolkit/components/satchel/test/test_form_autocomplete.html +++ b/toolkit/components/satchel/test/test_form_autocomplete.html @@ -122,7 +122,7 @@ const shiftModifier = Event.SHIFT_MASK; // Get the form history service var fh = SpecialPowers.Cc["@mozilla.org/satchel/form-history;1"]. - getService(SpecialPowers.Ci.nsIFormHistory2); + getService(Components.interfaces.nsIFormHistory2); ok(fh != null, "got form history service"); fh.removeAllEntries(); diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index f4101c8de78d..bf03877c3675 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -2895,10 +2895,6 @@ "kind": "flag", "description": "Whether content ever accesed Components.interfaces in this session" }, - "COMPONENTS_SHIM_ACCESSED_BY_CONTENT": { - "kind": "flag", - "description": "Whether content ever accesed the Components shim in this session" - }, "CHECK_ADDONS_MODIFIED_MS": { "kind": "exponential", "high": "5000",