Skip to content

Commit

Permalink
Bug 1453869 part 7. Make the DOMParser WebIDL constructor use a nullp…
Browse files Browse the repository at this point in the history
…rincipal for the document if the caller is system-principal. r=mrbkap

In our test suite, we only run into two calls to this constructor with a system
principal, and both are in test code.

After this, calling the WebIDL constructor from system code is _almost_
equivalent to creating by contract.  The one difference is that the resulting
DOMParser (and the documents it creates) will have its script handling object
set to the global the constructor came from instead of being null.

MozReview-Commit-ID: Fe2yMeqoYnB
  • Loading branch information
bzbarsky committed Apr 21, 2018
1 parent df65914 commit c2c0695
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dom/base/DOMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "nsIDOMDocument.h"
#include "nsNetUtil.h"
#include "nsDOMString.h"
#include "MainThreadUtils.h"
#include "nsIStreamListener.h"
#include "nsStringStream.h"
#include "nsIScriptError.h"
Expand Down Expand Up @@ -296,10 +297,20 @@ DOMParser::Init(nsIPrincipal* principal, nsIURI* documentURI,
DOMParser::Constructor(const GlobalObject& aOwner,
ErrorResult& rv)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<DOMParser> domParser = new DOMParser(aOwner.GetAsSupports());
rv = domParser->InitInternal(aOwner.GetAsSupports(),
nsContentUtils::SubjectPrincipal(),
nullptr, nullptr);

nsCOMPtr<nsIPrincipal> docPrincipal = aOwner.GetSubjectPrincipal();
if (nsContentUtils::IsSystemPrincipal(docPrincipal)) {
docPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
// Call Init() directly so we don't pick up our window's URI and
// base URI, for backwards compat.
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner.GetAsSupports());
rv = domParser->Init(docPrincipal, nullptr, nullptr, global);
} else {
rv = domParser->InitInternal(aOwner.GetAsSupports(), docPrincipal,
nullptr, nullptr);
}
if (rv.Failed()) {
return nullptr;
}
Expand Down

0 comments on commit c2c0695

Please sign in to comment.