diff --git a/dom/base/DOMParser.cpp b/dom/base/DOMParser.cpp index bf4ce4f6680c..ee5a2dc34b8d 100644 --- a/dom/base/DOMParser.cpp +++ b/dom/base/DOMParser.cpp @@ -28,7 +28,7 @@ using namespace mozilla::dom; DOMParser::DOMParser() : mAttemptedInit(false) - , mOriginalPrincipalWasSystem(false) + , mForceEnableXULXBL(false) { } @@ -95,7 +95,7 @@ DOMParser::ParseFromString(const nsAString& str, // Keep the XULXBL state in sync with the XML case. - if (mOriginalPrincipalWasSystem) { + if (mForceEnableXULXBL) { document->ForceEnableXULXBL(); } @@ -262,7 +262,7 @@ DOMParser::ParseFromStream(nsIInputStream* aStream, // Keep the XULXBL state in sync with the HTML case - if (mOriginalPrincipalWasSystem) { + if (mForceEnableXULXBL) { document->ForceEnableXULXBL(); } @@ -345,7 +345,7 @@ DOMParser::Init(nsIPrincipal* principal, nsIURI* documentURI, if (nsContentUtils::IsSystemPrincipal(mPrincipal)) { // Don't give DOMParsers the system principal. Use a null // principal instead. - mOriginalPrincipalWasSystem = true; + mForceEnableXULXBL = true; mPrincipal = NullPrincipal::CreateWithoutOriginAttributes(); if (!mDocumentURI) { @@ -410,20 +410,6 @@ DOMParser::InitInternal(nsISupports* aOwner, nsIPrincipal* prin, return Init(prin, documentURI, baseURI, scriptglobal); } -void -DOMParser::Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, - nsIURI* aBaseURI, mozilla::ErrorResult& rv) -{ - AttemptedInitMarker marker(&mAttemptedInit); - - nsCOMPtr principal = aPrincipal; - if (!principal && !aDocumentURI) { - principal = nsContentUtils::SubjectPrincipal(); - } - - rv = Init(principal, aDocumentURI, aBaseURI, GetEntryGlobal()); -} - nsresult DOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult) { diff --git a/dom/base/DOMParser.h b/dom/base/DOMParser.h index d1656a6c346e..db1b88507dd0 100644 --- a/dom/base/DOMParser.h +++ b/dom/base/DOMParser.h @@ -63,8 +63,11 @@ public: int32_t aContentLength, mozilla::dom::SupportedType aType, mozilla::ErrorResult& rv); - void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, - nsIURI* aBaseURI, mozilla::ErrorResult& rv); + void + ForceEnableXULXBL() + { + mForceEnableXULXBL = true; + } nsISupports* GetParentObject() const { @@ -80,7 +83,7 @@ private: explicit DOMParser(nsISupports* aOwner) : mOwner(aOwner) , mAttemptedInit(false) - , mOriginalPrincipalWasSystem(false) + , mForceEnableXULXBL(false) { MOZ_ASSERT(aOwner); } @@ -140,7 +143,7 @@ private: nsWeakPtr mScriptHandlingObject; bool mAttemptedInit; - bool mOriginalPrincipalWasSystem; + bool mForceEnableXULXBL; }; } // namespace dom diff --git a/dom/base/test/chrome/test_domparsing.xul b/dom/base/test/chrome/test_domparsing.xul index 7e9ead3aeb83..9b2ab439110b 100644 --- a/dom/base/test/chrome/test_domparsing.xul +++ b/dom/base/test/chrome/test_domparsing.xul @@ -37,13 +37,6 @@ new DOMParser(0); new DOMParser(""); new DOMParser({}); -{ - let parser = new DOMParser(); - throws(function() { - parser.init(); - }, "NS_ERROR_UNEXPECTED", "init method should throw when DOMParser is created by constructor"); -} - // XMLSerializer constructor should not throw for extra arguments new XMLSerializer(undefined); new XMLSerializer(null); @@ -54,15 +47,6 @@ new XMLSerializer({}); runTest(new DOMParser(), new XMLSerializer()); -{ - let parser = Cc["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Ci.nsIDOMParser); - parser.init(); - throws(function() { - parser.init(); - }, "NS_ERROR_UNEXPECTED", "init method should throw when called twice"); -} - runTest(Cc["@mozilla.org/xmlextras/domparser;1"] .createInstance(Ci.nsIDOMParser), new XMLSerializer()); @@ -71,7 +55,6 @@ function runTest(parser, serializer) { is(typeof parser.parseFromString, "function", "parseFromString should exist"); is(typeof parser.parseFromBuffer, "function", "parseFromBuffer should exist"); is(typeof parser.parseFromStream, "function", "parseFromStream should exist"); - is(typeof parser.init, "function", "init should exist"); is(typeof serializer.serializeToString, "function", "serializeToString should exist"); is(typeof serializer.serializeToStream, "function", "serializeToStream should exist"); diff --git a/dom/base/test/unit/head_xml.js b/dom/base/test/unit/head_xml.js index e5db03e8e0e7..55bf5fcca2a8 100644 --- a/dom/base/test/unit/head_xml.js +++ b/dom/base/test/unit/head_xml.js @@ -22,7 +22,7 @@ Cu.importGlobalProperties(["XMLSerializer"]); function DOMParser() { var parser = C["@mozilla.org/xmlextras/domparser;1"].createInstance(nsIDOMParser); - parser.init(); + parser.forceEnableXULXBL(); return parser; } diff --git a/dom/base/test/unit/test_cancelPrefetch.js b/dom/base/test/unit/test_cancelPrefetch.js index 7e67e40fa8ca..54f2040cef03 100644 --- a/dom/base/test/unit/test_cancelPrefetch.js +++ b/dom/base/test/unit/test_cancelPrefetch.js @@ -21,7 +21,6 @@ var node2; function run_test() { prefs.setBoolPref("network.prefetch-next", true); - parser.init(); doc = parser.parseFromString(docbody, "text/html"); node1 = doc.getElementById("node1"); diff --git a/dom/base/test/unit/test_xhr_document.js b/dom/base/test/unit/test_xhr_document.js index 81ab512a8906..24a21a8a5115 100644 --- a/dom/base/test/unit/test_xhr_document.js +++ b/dom/base/test/unit/test_xhr_document.js @@ -22,7 +22,6 @@ function run_test() { server.registerPathHandler("/foo", handler); var parser = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser); - parser.init(); let doc = parser.parseFromString(docbody, "text/html"); let xhr = new XMLHttpRequest(); xhr.onload = function() { diff --git a/dom/webidl/DOMParser.webidl b/dom/webidl/DOMParser.webidl index f81460626dcb..f608ee45d147 100644 --- a/dom/webidl/DOMParser.webidl +++ b/dom/webidl/DOMParser.webidl @@ -36,9 +36,9 @@ interface DOMParser { [NewObject, Throws, ChromeOnly] Document parseFromStream(InputStream stream, DOMString? charset, long contentLength, SupportedType type); - [Throws, ChromeOnly] - void init(optional Principal? principal = null, - optional URI? documentURI = null, - optional URI? baseURI = null); + // Can be used to allow a DOMParser to parse XUL/XBL no matter what + // principal it's using for the document. + [ChromeOnly] + void forceEnableXULXBL(); }; diff --git a/toolkit/modules/tests/modules/MockDocument.jsm b/toolkit/modules/tests/modules/MockDocument.jsm index 37260a2c29fb..501ba545f286 100644 --- a/toolkit/modules/tests/modules/MockDocument.jsm +++ b/toolkit/modules/tests/modules/MockDocument.jsm @@ -18,7 +18,6 @@ const MockDocument = { createTestDocument(aDocumentURL, aContent = "
", aType = "text/html") { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - parser.init(); let parsedDoc = parser.parseFromString(aContent, aType); // Assign ownerGlobal to documentElement as well for the form-less