Bug 1844752, initialize nsNodeInfoManager::mPrincipal with the correct principal when available, r=dom-core,emilio,peterv

Differential Revision: https://phabricator.services.mozilla.com/D184219
This commit is contained in:
Olli Pettay 2023-07-31 23:44:15 +00:00
parent 3aa820e646
commit de706ffb77
21 changed files with 129 additions and 75 deletions

View file

@ -2757,7 +2757,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Document)
NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE
NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_UNLINK_END
nsresult Document::Init() { nsresult Document::Init(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) {
if (mCSSLoader || mStyleImageLoader || mNodeInfoManager || mScriptLoader) { if (mCSSLoader || mStyleImageLoader || mNodeInfoManager || mScriptLoader) {
return NS_ERROR_ALREADY_INITIALIZED; return NS_ERROR_ALREADY_INITIALIZED;
} }
@ -2766,7 +2767,7 @@ nsresult Document::Init() {
mOnloadBlocker = new OnloadBlocker(); mOnloadBlocker = new OnloadBlocker();
mStyleImageLoader = new css::ImageLoader(this); mStyleImageLoader = new css::ImageLoader(this);
mNodeInfoManager = new nsNodeInfoManager(this); mNodeInfoManager = new nsNodeInfoManager(this, aPrincipal);
// mNodeInfo keeps NodeInfoManager alive! // mNodeInfo keeps NodeInfoManager alive!
mNodeInfo = mNodeInfoManager->GetDocumentNodeInfo(); mNodeInfo = mNodeInfoManager->GetDocumentNodeInfo();
@ -2799,6 +2800,10 @@ nsresult Document::Init() {
mStyleSet = MakeUnique<ServoStyleSet>(*this); mStyleSet = MakeUnique<ServoStyleSet>(*this);
if (aPrincipal) {
SetPrincipals(aPrincipal, aPartitionedPrincipal);
}
RecomputeResistFingerprinting(); RecomputeResistFingerprinting();
return NS_OK; return NS_OK;
@ -12064,7 +12069,7 @@ nsresult Document::CloneDocHelper(Document* clone) const {
clone->mIsStaticDocument = mCreatingStaticClone; clone->mIsStaticDocument = mCreatingStaticClone;
// Init document // Init document
nsresult rv = clone->Init(); nsresult rv = clone->Init(NodePrincipal(), mPartitionedPrincipal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (mCreatingStaticClone) { if (mCreatingStaticClone) {
@ -12120,7 +12125,6 @@ nsresult Document::CloneDocHelper(Document* clone) const {
// them. // them.
clone->SetDocumentURI(Document::GetDocumentURI()); clone->SetDocumentURI(Document::GetDocumentURI());
clone->SetChromeXHRDocURI(mChromeXHRDocURI); clone->SetChromeXHRDocURI(mChromeXHRDocURI);
clone->SetPrincipals(NodePrincipal(), mPartitionedPrincipal);
clone->mActiveStoragePrincipal = mActiveStoragePrincipal; clone->mActiveStoragePrincipal = mActiveStoragePrincipal;
clone->mActiveCookiePrincipal = mActiveCookiePrincipal; clone->mActiveCookiePrincipal = mActiveCookiePrincipal;
// NOTE(emilio): Intentionally setting this to the GetDocBaseURI rather than // NOTE(emilio): Intentionally setting this to the GetDocBaseURI rather than

View file

@ -2348,7 +2348,12 @@ class Document : public nsINode,
bool aIncludeSubdocuments, bool aIncludeSubdocuments,
bool aAllowUnloadListeners = true); bool aAllowUnloadListeners = true);
virtual nsresult Init(); /**
* Pass principals if the correct ones are known when calling Init. That way
* NodeInfoManager doesn't need to create a temporary null principal.
*/
virtual nsresult Init(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal);
/** /**
* Notify the document that its associated ContentViewer is being destroyed. * Notify the document that its associated ContentViewer is being destroyed.
@ -5492,17 +5497,27 @@ bool IsInActiveTab(Document* aDoc);
// XXX These belong somewhere else // XXX These belong somewhere else
nsresult NS_NewHTMLDocument(mozilla::dom::Document** aInstancePtrResult, nsresult NS_NewHTMLDocument(mozilla::dom::Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal,
bool aLoadedAsData = false); bool aLoadedAsData = false);
nsresult NS_NewXMLDocument(mozilla::dom::Document** aInstancePtrResult, nsresult NS_NewXMLDocument(mozilla::dom::Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal,
bool aLoadedAsData = false, bool aLoadedAsData = false,
bool aIsPlainDocument = false); bool aIsPlainDocument = false);
nsresult NS_NewSVGDocument(mozilla::dom::Document** aInstancePtrResult); nsresult NS_NewSVGDocument(mozilla::dom::Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal);
nsresult NS_NewImageDocument(mozilla::dom::Document** aInstancePtrResult); nsresult NS_NewImageDocument(mozilla::dom::Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal);
nsresult NS_NewVideoDocument(mozilla::dom::Document** aInstancePtrResult); nsresult NS_NewVideoDocument(mozilla::dom::Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal);
// Enum for requesting a particular type of document when creating a doc // Enum for requesting a particular type of document when creating a doc
enum DocumentFlavor { enum DocumentFlavor {

View file

@ -40,12 +40,11 @@ using mozilla::dom::NodeInfo;
static LazyLogModule gNodeInfoManagerLeakPRLog("NodeInfoManagerLeak"); static LazyLogModule gNodeInfoManagerLeakPRLog("NodeInfoManagerLeak");
static const uint32_t kInitialNodeInfoHashSize = 32; static const uint32_t kInitialNodeInfoHashSize = 32;
nsNodeInfoManager::nsNodeInfoManager(mozilla::dom::Document* aDocument) nsNodeInfoManager::nsNodeInfoManager(mozilla::dom::Document* aDocument,
nsIPrincipal* aPrincipal)
: mNodeInfoHash(kInitialNodeInfoHashSize), : mNodeInfoHash(kInitialNodeInfoHashSize),
mDocument(aDocument), mDocument(aDocument),
mNonDocumentNodeInfos(0), mNonDocumentNodeInfos(0),
mPrincipal(NullPrincipal::CreateWithoutOriginAttributes()),
mDefaultPrincipal(mPrincipal),
mTextNodeInfo(nullptr), mTextNodeInfo(nullptr),
mCommentNodeInfo(nullptr), mCommentNodeInfo(nullptr),
mDocumentNodeInfo(nullptr), mDocumentNodeInfo(nullptr),
@ -53,6 +52,13 @@ nsNodeInfoManager::nsNodeInfoManager(mozilla::dom::Document* aDocument)
mArena(nullptr) { mArena(nullptr) {
nsLayoutStatics::AddRef(); nsLayoutStatics::AddRef();
if (aPrincipal) {
mPrincipal = aPrincipal;
} else {
mPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
}
mDefaultPrincipal = mPrincipal;
if (gNodeInfoManagerLeakPRLog) { if (gNodeInfoManagerLeakPRLog) {
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug, MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
("NODEINFOMANAGER %p created, document=%p", this, aDocument)); ("NODEINFOMANAGER %p created, document=%p", this, aDocument));

View file

@ -35,7 +35,8 @@ class nsNodeInfoManager final {
~nsNodeInfoManager(); ~nsNodeInfoManager();
public: public:
explicit nsNodeInfoManager(mozilla::dom::Document* aDocument); explicit nsNodeInfoManager(mozilla::dom::Document* aDocument,
nsIPrincipal* aPrincipal);
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_NATIVE_CLASS(nsNodeInfoManager) NS_DECL_CYCLE_COLLECTION_SKIPPABLE_NATIVE_CLASS(nsNodeInfoManager)

View file

@ -159,7 +159,7 @@ nsresult nsSyncLoader::LoadDocument(nsIChannel* aChannel, bool aChannelIsSync,
// Create document // Create document
nsCOMPtr<Document> document; nsCOMPtr<Document> document;
rv = NS_NewXMLDocument(getter_AddRefs(document)); rv = NS_NewXMLDocument(getter_AddRefs(document), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Start the document load. Do this before we attach the load listener // Start the document load. Do this before we attach the load listener

View file

@ -145,8 +145,9 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(ImageDocument, MediaDocument,
imgINotificationObserver, imgINotificationObserver,
nsIDOMEventListener) nsIDOMEventListener)
nsresult ImageDocument::Init() { nsresult ImageDocument::Init(nsIPrincipal* aPrincipal,
nsresult rv = MediaDocument::Init(); nsIPrincipal* aPartitionedPrincipal) {
nsresult rv = MediaDocument::Init(aPrincipal, aPartitionedPrincipal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mShouldResize = StaticPrefs::browser_enable_automatic_image_resizing(); mShouldResize = StaticPrefs::browser_enable_automatic_image_resizing();
@ -796,11 +797,13 @@ void ImageDocument::MaybeSendResultToEmbedder(nsresult aResult) {
} }
} // namespace mozilla::dom } // namespace mozilla::dom
nsresult NS_NewImageDocument(mozilla::dom::Document** aResult) { nsresult NS_NewImageDocument(mozilla::dom::Document** aResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) {
auto* doc = new mozilla::dom::ImageDocument(); auto* doc = new mozilla::dom::ImageDocument();
NS_ADDREF(doc); NS_ADDREF(doc);
nsresult rv = doc->Init(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_RELEASE(doc); NS_RELEASE(doc);
} }

View file

@ -31,7 +31,8 @@ class ImageDocument final : public MediaDocument,
return MediaDocumentKind::Image; return MediaDocumentKind::Image;
} }
nsresult Init() override; nsresult Init(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) override;
nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup, nsISupports* aContainer, nsILoadGroup* aLoadGroup, nsISupports* aContainer,

View file

@ -112,8 +112,9 @@ MediaDocument::MediaDocument()
} }
MediaDocument::~MediaDocument() = default; MediaDocument::~MediaDocument() = default;
nsresult MediaDocument::Init() { nsresult MediaDocument::Init(nsIPrincipal* aPrincipal,
nsresult rv = nsHTMLDocument::Init(); nsIPrincipal* aPartitionedPrincipal) {
nsresult rv = nsHTMLDocument::Init(aPrincipal, aPartitionedPrincipal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mIsSyntheticDocument = true; mIsSyntheticDocument = true;

View file

@ -29,7 +29,8 @@ class MediaDocument : public nsHTMLDocument {
// Subclasses need to override this. // Subclasses need to override this.
enum MediaDocumentKind MediaDocumentKind() const override = 0; enum MediaDocumentKind MediaDocumentKind() const override = 0;
virtual nsresult Init() override; virtual nsresult Init(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) override;
virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,

View file

@ -140,11 +140,13 @@ void VideoDocument::UpdateTitle(nsIChannel* aChannel) {
} // namespace mozilla::dom } // namespace mozilla::dom
nsresult NS_NewVideoDocument(mozilla::dom::Document** aResult) { nsresult NS_NewVideoDocument(mozilla::dom::Document** aResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) {
auto* doc = new mozilla::dom::VideoDocument(); auto* doc = new mozilla::dom::VideoDocument();
NS_ADDREF(doc); NS_ADDREF(doc);
nsresult rv = doc->Init(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_RELEASE(doc); NS_RELEASE(doc);

View file

@ -102,10 +102,13 @@ static bool IsAsciiCompatible(const Encoding* aEncoding) {
return aEncoding->IsAsciiCompatible() || aEncoding == ISO_2022_JP_ENCODING; return aEncoding->IsAsciiCompatible() || aEncoding == ISO_2022_JP_ENCODING;
} }
nsresult NS_NewHTMLDocument(Document** aInstancePtrResult, bool aLoadedAsData) { nsresult NS_NewHTMLDocument(Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal,
bool aLoadedAsData) {
RefPtr<nsHTMLDocument> doc = new nsHTMLDocument(); RefPtr<nsHTMLDocument> doc = new nsHTMLDocument();
nsresult rv = doc->Init(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
*aInstancePtrResult = nullptr; *aInstancePtrResult = nullptr;
@ -138,8 +141,9 @@ JSObject* nsHTMLDocument::WrapNode(JSContext* aCx,
return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto); return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto);
} }
nsresult nsHTMLDocument::Init() { nsresult nsHTMLDocument::Init(nsIPrincipal* aPrincipal,
nsresult rv = Document::Init(); nsIPrincipal* aPartitionedPrincipal) {
nsresult rv = Document::Init(aPrincipal, aPartitionedPrincipal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Now reset the compatibility mode of the CSSLoader // Now reset the compatibility mode of the CSSLoader

View file

@ -42,7 +42,8 @@ class nsHTMLDocument : public mozilla::dom::Document {
using Document::SetDocumentURI; using Document::SetDocumentURI;
nsHTMLDocument(); nsHTMLDocument();
virtual nsresult Init() override; virtual nsresult Init(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) override;
// Document // Document
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override; virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;

View file

@ -41,10 +41,12 @@ nsresult SVGDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const {
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Exported creation functions // Exported creation functions
nsresult NS_NewSVGDocument(Document** aInstancePtrResult) { nsresult NS_NewSVGDocument(Document** aInstancePtrResult,
nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) {
RefPtr<SVGDocument> doc = new SVGDocument(); RefPtr<SVGDocument> doc = new SVGDocument();
nsresult rv = doc->Init(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }

View file

@ -67,14 +67,15 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult,
bool isHTML = false; bool isHTML = false;
bool isXHTML = false; bool isXHTML = false;
if (aFlavor == DocumentFlavorSVG) { if (aFlavor == DocumentFlavorSVG) {
rv = NS_NewSVGDocument(getter_AddRefs(d)); rv = NS_NewSVGDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
} else if (aFlavor == DocumentFlavorHTML) { } else if (aFlavor == DocumentFlavorHTML) {
rv = NS_NewHTMLDocument(getter_AddRefs(d)); rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
isHTML = true; isHTML = true;
} else if (aFlavor == DocumentFlavorXML) { } else if (aFlavor == DocumentFlavorXML) {
rv = NS_NewXMLDocument(getter_AddRefs(d)); rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
} else if (aFlavor == DocumentFlavorPlain) { } else if (aFlavor == DocumentFlavorPlain) {
rv = NS_NewXMLDocument(getter_AddRefs(d), aLoadedAsData, true); rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal,
aLoadedAsData, true);
} else if (aDoctype) { } else if (aDoctype) {
MOZ_ASSERT(aFlavor == DocumentFlavorLegacyGuess); MOZ_ASSERT(aFlavor == DocumentFlavorLegacyGuess);
nsAutoString publicId, name; nsAutoString publicId, name;
@ -89,25 +90,25 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult,
publicId.EqualsLiteral("-//W3C//DTD HTML 4.0//EN") || publicId.EqualsLiteral("-//W3C//DTD HTML 4.0//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Frameset//EN") || publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Frameset//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Transitional//EN")) { publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Transitional//EN")) {
rv = NS_NewHTMLDocument(getter_AddRefs(d)); rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
isHTML = true; isHTML = true;
} else if (publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Strict//EN") || } else if (publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Strict//EN") ||
publicId.EqualsLiteral( publicId.EqualsLiteral(
"-//W3C//DTD XHTML 1.0 Transitional//EN") || "-//W3C//DTD XHTML 1.0 Transitional//EN") ||
publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Frameset//EN")) { publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Frameset//EN")) {
rv = NS_NewHTMLDocument(getter_AddRefs(d)); rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
isHTML = true; isHTML = true;
isXHTML = true; isXHTML = true;
} else if (publicId.EqualsLiteral("-//W3C//DTD SVG 1.1//EN")) { } else if (publicId.EqualsLiteral("-//W3C//DTD SVG 1.1//EN")) {
rv = NS_NewSVGDocument(getter_AddRefs(d)); rv = NS_NewSVGDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
} }
// XXX Add support for XUL documents. // XXX Add support for XUL documents.
else { else {
rv = NS_NewXMLDocument(getter_AddRefs(d)); rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
} }
} else { } else {
MOZ_ASSERT(aFlavor == DocumentFlavorLegacyGuess); MOZ_ASSERT(aFlavor == DocumentFlavorLegacyGuess);
rv = NS_NewXMLDocument(getter_AddRefs(d)); rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal);
} }
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -120,8 +121,6 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult,
} }
d->SetLoadedAsData(aLoadedAsData, /* aConsiderForMemoryReporting */ true); d->SetLoadedAsData(aLoadedAsData, /* aConsiderForMemoryReporting */ true);
d->SetDocumentURI(aDocumentURI); d->SetDocumentURI(aDocumentURI);
// Must set the principal first, since SetBaseURI checks it.
d->SetPrincipals(aPrincipal, aPrincipal);
d->SetBaseURI(aBaseURI); d->SetBaseURI(aBaseURI);
// We need to set the script handling object after we set the principal such // We need to set the script handling object after we set the principal such
@ -174,11 +173,13 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult,
return NS_OK; return NS_OK;
} }
nsresult NS_NewXMLDocument(Document** aInstancePtrResult, bool aLoadedAsData, nsresult NS_NewXMLDocument(Document** aInstancePtrResult,
bool aIsPlainDocument) { nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal,
bool aLoadedAsData, bool aIsPlainDocument) {
RefPtr<XMLDocument> doc = new XMLDocument(); RefPtr<XMLDocument> doc = new XMLDocument();
nsresult rv = doc->Init(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
*aInstancePtrResult = nullptr; *aInstancePtrResult = nullptr;
@ -203,8 +204,9 @@ XMLDocument::XMLDocument(const char* aContentType)
mType = eGenericXML; mType = eGenericXML;
} }
nsresult XMLDocument::Init() { nsresult XMLDocument::Init(nsIPrincipal* aPrincipal,
nsresult rv = Document::Init(); nsIPrincipal* aPartitionedPrincipal) {
nsresult rv = Document::Init(aPrincipal, aPartitionedPrincipal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return rv; return rv;

View file

@ -43,7 +43,8 @@ class XMLDocument : public Document {
// TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230, bug 1535398) // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230, bug 1535398)
MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void EndLoad() override; MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void EndLoad() override;
virtual nsresult Init() override; virtual nsresult Init(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal) override;
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
@ -61,7 +62,8 @@ class XMLDocument : public Document {
virtual JSObject* WrapNode(JSContext* aCx, virtual JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override; JS::Handle<JSObject*> aGivenProto) override;
friend nsresult(::NS_NewXMLDocument)(Document**, bool, bool); friend nsresult(::NS_NewXMLDocument)(Document**, nsIPrincipal*, nsIPrincipal*,
bool, bool);
// mChannelIsPending indicates whether we're currently asynchronously loading // mChannelIsPending indicates whether we're currently asynchronously loading
// data from mChannel. It's set to true when we first find out about the // data from mChannel. It's set to true when we first find out about the

View file

@ -123,7 +123,8 @@ nsresult txMozillaTextOutput::createResultDocument(bool aLoadedAsData) {
*/ */
// Create the document // Create the document
nsresult rv = NS_NewXMLDocument(getter_AddRefs(mDocument), aLoadedAsData); nsresult rv = NS_NewXMLDocument(getter_AddRefs(mDocument), nullptr, nullptr,
aLoadedAsData);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mCreatedDocument = true; mCreatedDocument = true;
// This should really be handled by Document::BeginLoad // This should really be handled by Document::BeginLoad

View file

@ -698,12 +698,14 @@ nsresult txMozillaXMLOutput::createResultDocument(const nsAString& aName,
// Create the document // Create the document
if (mOutputFormat.mMethod == eHTMLOutput) { if (mOutputFormat.mMethod == eHTMLOutput) {
rv = NS_NewHTMLDocument(getter_AddRefs(mDocument), aLoadedAsData); rv = NS_NewHTMLDocument(getter_AddRefs(mDocument), nullptr, nullptr,
aLoadedAsData);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} else { } else {
// We should check the root name/namespace here and create the // We should check the root name/namespace here and create the
// appropriate document // appropriate document
rv = NS_NewXMLDocument(getter_AddRefs(mDocument), aLoadedAsData); rv = NS_NewXMLDocument(getter_AddRefs(mDocument), nullptr, nullptr,
aLoadedAsData);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
// This should really be handled by Document::BeginLoad // This should really be handled by Document::BeginLoad

View file

@ -972,7 +972,7 @@ void txMozillaXSLTProcessor::reportError(nsresult aResult,
void txMozillaXSLTProcessor::notifyError() { void txMozillaXSLTProcessor::notifyError() {
nsCOMPtr<Document> document; nsCOMPtr<Document> document;
{ {
nsresult rv = NS_NewXMLDocument(getter_AddRefs(document)); nsresult rv = NS_NewXMLDocument(getter_AddRefs(document), nullptr, nullptr);
NS_ENSURE_SUCCESS_VOID(rv); NS_ENSURE_SUCCESS_VOID(rv);
} }

View file

@ -47,7 +47,7 @@ nsXULPrototypeDocument::nsXULPrototypeDocument()
} }
nsresult nsXULPrototypeDocument::Init() { nsresult nsXULPrototypeDocument::Init() {
mNodeInfoManager = new nsNodeInfoManager(nullptr); mNodeInfoManager = new nsNodeInfoManager(nullptr, nullptr);
return NS_OK; return NS_OK;
} }

View file

@ -126,7 +126,8 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
aCommand, aChannel, aLoadGroup, aContainer, aCommand, aChannel, aLoadGroup, aContainer,
[]() -> already_AddRefed<Document> { []() -> already_AddRefed<Document> {
RefPtr<Document> doc; RefPtr<Document> doc;
nsresult rv = NS_NewHTMLDocument(getter_AddRefs(doc)); nsresult rv =
NS_NewHTMLDocument(getter_AddRefs(doc), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
return doc.forget(); return doc.forget();
}, },
@ -137,7 +138,8 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
aCommand, aChannel, aLoadGroup, aContainer, aCommand, aChannel, aLoadGroup, aContainer,
[]() -> already_AddRefed<Document> { []() -> already_AddRefed<Document> {
RefPtr<Document> doc; RefPtr<Document> doc;
nsresult rv = NS_NewXMLDocument(getter_AddRefs(doc)); nsresult rv =
NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
return doc.forget(); return doc.forget();
}, },
@ -148,7 +150,8 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
aCommand, aChannel, aLoadGroup, aContainer, aCommand, aChannel, aLoadGroup, aContainer,
[]() -> already_AddRefed<Document> { []() -> already_AddRefed<Document> {
RefPtr<Document> doc; RefPtr<Document> doc;
nsresult rv = NS_NewSVGDocument(getter_AddRefs(doc)); nsresult rv =
NS_NewSVGDocument(getter_AddRefs(doc), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
return doc.forget(); return doc.forget();
}, },
@ -160,7 +163,8 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
aCommand, aChannel, aLoadGroup, aContainer, aCommand, aChannel, aLoadGroup, aContainer,
[]() -> already_AddRefed<Document> { []() -> already_AddRefed<Document> {
RefPtr<Document> doc; RefPtr<Document> doc;
nsresult rv = NS_NewVideoDocument(getter_AddRefs(doc)); nsresult rv =
NS_NewVideoDocument(getter_AddRefs(doc), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
return doc.forget(); return doc.forget();
}, },
@ -172,7 +176,8 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
aCommand, aChannel, aLoadGroup, aContainer, aCommand, aChannel, aLoadGroup, aContainer,
[]() -> already_AddRefed<Document> { []() -> already_AddRefed<Document> {
RefPtr<Document> doc; RefPtr<Document> doc;
nsresult rv = NS_NewImageDocument(getter_AddRefs(doc)); nsresult rv =
NS_NewImageDocument(getter_AddRefs(doc), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
return doc.forget(); return doc.forget();
}, },
@ -212,7 +217,8 @@ already_AddRefed<Document> nsContentDLF::CreateBlankDocument(
nsIPrincipal* aPartitionedPrincipal, nsDocShell* aContainer) { nsIPrincipal* aPartitionedPrincipal, nsDocShell* aContainer) {
// create a new blank HTML document // create a new blank HTML document
RefPtr<Document> blankDoc; RefPtr<Document> blankDoc;
mozilla::Unused << NS_NewHTMLDocument(getter_AddRefs(blankDoc)); mozilla::Unused << NS_NewHTMLDocument(getter_AddRefs(blankDoc), nullptr,
nullptr);
if (!blankDoc) { if (!blankDoc) {
return nullptr; return nullptr;

View file

@ -283,7 +283,7 @@ TEST(TestFetchPreloader, CacheNoneBeforeConsume)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -321,7 +321,7 @@ TEST(TestFetchPreloader, CacheStartBeforeConsume)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -361,7 +361,7 @@ TEST(TestFetchPreloader, CachePartOfDataBeforeConsume)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -401,7 +401,7 @@ TEST(TestFetchPreloader, CacheAllDataBeforeConsume)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -441,7 +441,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsume)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -480,7 +480,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeWithChannelError)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -519,7 +519,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeWithChannelCancel)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -562,7 +562,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeThrowFromOnStartRequest)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -602,7 +602,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeThrowFromOnDataAvailable)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -642,7 +642,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeThrowFromOnStopRequest)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -684,7 +684,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeCancelInOnStartRequest)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -727,7 +727,7 @@ TEST(TestFetchPreloader, CacheAllBeforeConsumeCancelInOnDataAvailable)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -771,7 +771,7 @@ TEST(TestFetchPreloader, CachePartlyBeforeConsumeCancelInOnDataAvailable)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -812,7 +812,7 @@ TEST(TestFetchPreloader, CachePartlyBeforeConsumeCancelInOnStartRequestAndRace)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -861,7 +861,7 @@ TEST(TestFetchPreloader, CachePartlyBeforeConsumeCancelInOnDataAvailableAndRace)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,
@ -910,7 +910,7 @@ TEST(TestFetchPreloader, CachePartlyBeforeConsumeThrowFromOnStartRequestAndRace)
RefPtr<FakeChannel> channel = new FakeChannel(); RefPtr<FakeChannel> channel = new FakeChannel();
RefPtr<FakePreloader> preloader = new FakePreloader(channel); RefPtr<FakePreloader> preloader = new FakePreloader(channel);
RefPtr<mozilla::dom::Document> doc; RefPtr<mozilla::dom::Document> doc;
NS_NewXMLDocument(getter_AddRefs(doc)); NS_NewXMLDocument(getter_AddRefs(doc), nullptr, nullptr);
EXPECT_TRUE(NS_SUCCEEDED( EXPECT_TRUE(NS_SUCCEEDED(
preloader->OpenChannel(key, uri, mozilla::CORS_NONE, preloader->OpenChannel(key, uri, mozilla::CORS_NONE,