зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1453869 part 3. Remove the used-only-in-tests DOMParser.init method. r=mrbkap
Some DOM unit tests rely on being able to parse XUL via DOMParser. That was allowed due to them calling init() with a system subject principal. It can be more narrowly allowed by adding an explicit setter for being able to parse XUL/XBL. MozReview-Commit-ID: 3h0WWGHmYOn
This commit is contained in:
Родитель
2cb41e7954
Коммит
4527d58c1c
|
@ -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<nsIPrincipal> principal = aPrincipal;
|
||||
if (!principal && !aDocumentURI) {
|
||||
principal = nsContentUtils::SubjectPrincipal();
|
||||
}
|
||||
|
||||
rv = Init(principal, aDocumentURI, aBaseURI, GetEntryGlobal());
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ const MockDocument = {
|
|||
createTestDocument(aDocumentURL, aContent = "<form>", 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
|
||||
|
|
Загрузка…
Ссылка в новой задаче