diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index a91fe995ce6..f8dbfc46df4 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -1082,7 +1082,28 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JS::Handle global, bool nsXBLBinding::AllowScripts() { - return mPrototypeBinding->GetAllowScripts(); + if (!mPrototypeBinding->GetAllowScripts()) + return false; + + // Nasty hack. Use the JSContext of the bound node, since the + // security manager API expects to get the docshell type from + // that. But use the nsIPrincipal of our document. + nsIScriptSecurityManager* mgr = nsContentUtils::GetSecurityManager(); + if (!mgr) { + return false; + } + + nsIDocument* doc = mBoundElement ? mBoundElement->OwnerDoc() : nullptr; + if (!doc) { + return false; + } + + nsCOMPtr global = do_QueryInterface(doc->GetInnerWindow()); + if (!global || !global->GetGlobalJSObject()) { + return false; + } + + return mgr->ScriptAllowed(global->GetGlobalJSObject()); } nsXBLBinding* diff --git a/content/xbl/src/nsXBLBinding.h b/content/xbl/src/nsXBLBinding.h index c2af9a993db..ac577fe3b1b 100644 --- a/content/xbl/src/nsXBLBinding.h +++ b/content/xbl/src/nsXBLBinding.h @@ -141,7 +141,7 @@ public: JS::MutableHandle aClassObject, bool* aNew); - bool AllowScripts(); + bool AllowScripts(); // XXX make const mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild); diff --git a/content/xbl/src/nsXBLDocumentInfo.cpp b/content/xbl/src/nsXBLDocumentInfo.cpp index b3f6acde8d4..5c304c26566 100644 --- a/content/xbl/src/nsXBLDocumentInfo.cpp +++ b/content/xbl/src/nsXBLDocumentInfo.cpp @@ -403,24 +403,6 @@ nsXBLDocumentInfo::nsXBLDocumentInfo(nsIDocument* aDocument) mScriptAccess = allow; } mIsChrome = true; - } else { - // If this binding isn't running with system principal, then it's running - // from a remote-XUL whitelisted domain. This is already a not-really- - // supported configuration (among other things, we don't use XBL scopes in - // that configuration for compatibility reasons). But we should still at - // least make an effort to prevent binding code from running if content - // script is disabled or if the source domain is blacklisted (since the - // source domain for remote XBL must always be the same as the source domain - // of the bound content). - // - // If we just ask the binding document if script is enabled, it will - // discover that it has no inner window, and return false. So instead, we - // short-circuit the normal compartment-managed script-disabling machinery, - // and query the policy for the URI directly. - bool allow; - nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); - nsresult rv = ssm->PolicyAllowsScript(uri, &allow); - mScriptAccess = NS_SUCCEEDED(rv) && allow; } } diff --git a/content/xbl/src/nsXBLDocumentInfo.h b/content/xbl/src/nsXBLDocumentInfo.h index 412738a4118..9c88d504e90 100644 --- a/content/xbl/src/nsXBLDocumentInfo.h +++ b/content/xbl/src/nsXBLDocumentInfo.h @@ -27,7 +27,7 @@ public: already_AddRefed GetDocument() { nsCOMPtr copy = mDocument; return copy.forget(); } - bool GetScriptAccess() const { return mScriptAccess; } + bool GetScriptAccess() { return mScriptAccess; } nsIURI* DocumentURI() { return mDocument->GetDocumentURI(); } diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index 385c3dd3ba4..eb0e351ab59 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -214,7 +214,7 @@ nsXBLPrototypeBinding::SetBindingElement(nsIContent* aElement) } bool -nsXBLPrototypeBinding::GetAllowScripts() const +nsXBLPrototypeBinding::GetAllowScripts() { return mXBLDocInfoWeak->GetScriptAccess(); } diff --git a/content/xbl/src/nsXBLPrototypeBinding.h b/content/xbl/src/nsXBLPrototypeBinding.h index eb3fe54df2d..e38fc8e9e35 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.h +++ b/content/xbl/src/nsXBLPrototypeBinding.h @@ -48,7 +48,7 @@ public: // binding URIs. bool CompareBindingURI(nsIURI* aURI) const; - bool GetAllowScripts() const; + bool GetAllowScripts(); nsresult BindingAttached(nsIContent* aBoundElement); nsresult BindingDetached(nsIContent* aBoundElement); diff --git a/content/xbl/test/chrome.ini b/content/xbl/test/chrome.ini index cf117273acf..f55d0ff8c4e 100644 --- a/content/xbl/test/chrome.ini +++ b/content/xbl/test/chrome.ini @@ -1,6 +1,4 @@ [DEFAULT] -support-files = - file_bug944407.xml [test_bug378518.xul] [test_bug398135.xul] @@ -8,4 +6,3 @@ support-files = [test_bug721452.xul] [test_bug723676.xul] [test_bug772966.xul] -[test_bug944407.xul] diff --git a/content/xbl/test/file_bug944407.html b/content/xbl/test/file_bug944407.html deleted file mode 100644 index e0cf92c5b82..00000000000 --- a/content/xbl/test/file_bug944407.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -
-
- - diff --git a/content/xbl/test/file_bug944407.xml b/content/xbl/test/file_bug944407.xml deleted file mode 100644 index 302cd43c294..00000000000 --- a/content/xbl/test/file_bug944407.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - return 3; - - - - - - - - - - Anonymous Content - - diff --git a/content/xbl/test/mochitest.ini b/content/xbl/test/mochitest.ini index b390426f19a..8c82329009d 100644 --- a/content/xbl/test/mochitest.ini +++ b/content/xbl/test/mochitest.ini @@ -12,8 +12,6 @@ support-files = file_bug591198_xbl.xml file_bug821850.xhtml file_bug844783.xhtml - file_bug944407.html - file_bug944407.xml [test_bug310107.html] [test_bug366770.html] diff --git a/content/xbl/test/test_bug944407.xul b/content/xbl/test/test_bug944407.xul deleted file mode 100644 index 157439685cd..00000000000 --- a/content/xbl/test/test_bug944407.xul +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - -