From 9d923c0785dcdc1adb4c579e6d3243151468461e Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Thu, 24 Apr 2008 14:54:42 -0700 Subject: [PATCH] Don't report bogus errors when DOMParser is used from chrome. Bug 429785, r+sr=sicking, a=dsicore --- content/base/src/nsDOMParser.cpp | 18 +++--- content/base/test/chrome/Makefile.in | 1 + content/base/test/chrome/test_bug429785.xul | 68 +++++++++++++++++++++ 3 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 content/base/test/chrome/test_bug429785.xul diff --git a/content/base/src/nsDOMParser.cpp b/content/base/src/nsDOMParser.cpp index 42e9a4671755..025bd0ea426a 100644 --- a/content/base/src/nsDOMParser.cpp +++ b/content/base/src/nsDOMParser.cpp @@ -232,10 +232,6 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream, scriptHandlingObject, getter_AddRefs(domDocument)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr document(do_QueryInterface(domDocument)); - if (!document) return NS_ERROR_FAILURE; - - document->SetPrincipal(mPrincipal); // Register as a load listener on the document nsCOMPtr target(do_QueryInterface(domDocument)); @@ -256,7 +252,8 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream, nsDependentCString(contentType), nsnull); NS_ENSURE_STATE(parserChannel); - parserChannel->SetOwner(mPrincipal); + // More principal-faking here + parserChannel->SetOwner(mOriginalPrincipal); if (charset) { parserChannel->SetContentCharset(nsDependentCString(charset)); @@ -271,17 +268,20 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream, // our event listener. Should that listener addition move to later // than this call? Then we wouldn't need to mess around with // SetPrincipal, etc, probably! + nsCOMPtr document(do_QueryInterface(domDocument)); + if (!document) return NS_ERROR_FAILURE; + rv = document->StartDocumentLoad(kLoadAsData, parserChannel, nsnull, nsnull, getter_AddRefs(listener), PR_FALSE); - // Make sure to give this document the right principal - document->SetPrincipal(mPrincipal); - - // And the right base URI + // Make sure to give this document the right base URI document->SetBaseURI(mBaseURI); + // And the right principal + document->SetPrincipal(mPrincipal); + if (NS_FAILED(rv) || !listener) { return NS_ERROR_FAILURE; } diff --git a/content/base/test/chrome/Makefile.in b/content/base/test/chrome/Makefile.in index 8efa5baff0da..ed7204b7ddb8 100644 --- a/content/base/test/chrome/Makefile.in +++ b/content/base/test/chrome/Makefile.in @@ -49,6 +49,7 @@ _TEST_FILES = \ _CHROME_FILES = \ test_bug421622.xul \ + test_bug429785.xul \ test_bug430050.xul \ $(NULL) diff --git a/content/base/test/chrome/test_bug429785.xul b/content/base/test/chrome/test_bug429785.xul new file mode 100644 index 000000000000..8f7f323d3b41 --- /dev/null +++ b/content/base/test/chrome/test_bug429785.xul @@ -0,0 +1,68 @@ + + + + + + +