commit e9aefad31a1151c65fa6ee6b76c4becd81105b4f parent f3ed477ea7b778fec5c3a5a2ef504c45d92d709d Author: Lando <lando@lando.test> Date: Wed, 1 Oct 2025 07:32:27 +0000 Merge mozilla-central to autoland Diffstat:
48 files changed, 248 insertions(+), 401 deletions(-)
diff --git a/dom/base/DOMImplementation.cpp b/dom/base/DOMImplementation.cpp @@ -99,8 +99,8 @@ nsresult DOMImplementation::CreateDocument(const nsAString& aNamespaceURI, rv = NS_NewDOMDocument(getter_AddRefs(doc), aNamespaceURI, aQualifiedName, aDoctype, mDocumentURI, mBaseURI, - mOwner->NodePrincipal(), LoadedAsData::AsData, - scriptHandlingObject, DocumentFlavor::XML); + mOwner->NodePrincipal(), true, scriptHandlingObject, + DocumentFlavor::XML); NS_ENSURE_SUCCESS(rv, rv); // When DOMImplementation's createDocument method is invoked with @@ -150,10 +150,10 @@ nsresult DOMImplementation::CreateHTMLDocument(const nsAString& aTitle, NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject); nsCOMPtr<Document> doc; - nsresult rv = NS_NewDOMDocument( - getter_AddRefs(doc), u""_ns, u""_ns, doctype, mDocumentURI, mBaseURI, - mOwner->NodePrincipal(), LoadedAsData::AsData, scriptHandlingObject, - DocumentFlavor::LegacyGuess); + nsresult rv = + NS_NewDOMDocument(getter_AddRefs(doc), u""_ns, u""_ns, doctype, + mDocumentURI, mBaseURI, mOwner->NodePrincipal(), true, + scriptHandlingObject, DocumentFlavor::LegacyGuess); NS_ENSURE_SUCCESS(rv, rv); ErrorResult error; diff --git a/dom/base/DOMParser.cpp b/dom/base/DOMParser.cpp @@ -326,9 +326,9 @@ already_AddRefed<Document> DOMParser::SetUpDocument(DocumentFlavor aFlavor, NS_ASSERTION(mDocumentURI, "Must have document URI by now"); nsCOMPtr<Document> doc; - nsresult rv = NS_NewDOMDocument( - getter_AddRefs(doc), u""_ns, u""_ns, nullptr, mDocumentURI, mDocumentURI, - mPrincipal, LoadedAsData::AsData, scriptHandlingObject, aFlavor); + nsresult rv = NS_NewDOMDocument(getter_AddRefs(doc), u""_ns, u""_ns, nullptr, + mDocumentURI, mDocumentURI, mPrincipal, true, + scriptHandlingObject, aFlavor); if (NS_WARN_IF(NS_FAILED(rv))) { aRv.Throw(rv); return nullptr; diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp @@ -1362,8 +1362,7 @@ void Document::Shutdown() { } } -Document::Document(const char* aContentType, - mozilla::dom::LoadedAsData aLoadedAsData) +Document::Document(const char* aContentType) : nsINode(nullptr), DocumentOrShadowRoot(this), mCharacterSet(WINDOWS_1252_ENCODING), @@ -1374,7 +1373,6 @@ Document::Document(const char* aContentType, #ifdef DEBUG mStyledLinksCleared(false), #endif - mLoadedAsData(aLoadedAsData), mCachedStateObjectValid(false), mBlockAllMixedContent(false), mBlockAllMixedContentPreloads(false), @@ -1387,6 +1385,7 @@ Document::Document(const char* aContentType, mIsInitialDocumentInWindow(false), mIsEverInitialDocumentInWindow(false), mIgnoreDocGroupMismatches(false), + mLoadedAsData(false), mAddedToMemoryReportingAsDataDocument(false), mMayStartLayout(true), mHaveFiredTitleChange(false), @@ -2055,8 +2054,8 @@ void Document::LoadEventFired() { // Release the JS bytecode cache from its wait on the load event, and // potentially dispatch the encoding of the bytecode. - if (mScriptLoader) { - mScriptLoader->LoadEventFired(); + if (ScriptLoader()) { + ScriptLoader()->LoadEventFired(); } } @@ -3035,9 +3034,7 @@ nsresult Document::Init(nsIPrincipal* aPrincipal, // Force initialization. mOnloadBlocker = new OnloadBlocker(); - if (mLoadedAsData != LoadedAsData::AsData) { - mStyleImageLoader = new css::ImageLoader(this); - } + mStyleImageLoader = new css::ImageLoader(this); mNodeInfoManager = new nsNodeInfoManager(this, aPrincipal); @@ -3049,11 +3046,9 @@ nsresult Document::Init(nsIPrincipal* aPrincipal, NS_ASSERTION(OwnerDoc() == this, "Our nodeinfo is busted!"); - if (mLoadedAsData != LoadedAsData::AsData) { - mCSSLoader = new css::Loader(this); - // Assume we're not quirky, until we know otherwise - mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards); - } + mCSSLoader = new css::Loader(this); + // Assume we're not quirky, until we know otherwise + mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards); // If after creation the owner js global is not set for a document // we use the default compartment for this document, instead of creating @@ -3065,9 +3060,7 @@ nsresult Document::Init(nsIPrincipal* aPrincipal, mScopeObject = do_GetWeakReference(global); MOZ_ASSERT(mScopeObject); - if (mLoadedAsData == LoadedAsData::No) { - mScriptLoader = new dom::ScriptLoader(this); - } + mScriptLoader = new dom::ScriptLoader(this); // we need to create a policy here so getting the policy within // ::Policy() can *always* return a non null policy @@ -3538,10 +3531,7 @@ void Document::FillStyleSetDocumentSheets() { void Document::CompatibilityModeChanged() { MOZ_ASSERT(IsHTMLOrXHTML()); - if (!mCSSLoader) { - return; - } - mCSSLoader->SetCompatibilityMode(mCompatMode); + CSSLoader()->SetCompatibilityMode(mCompatMode); if (mStyleSet) { mStyleSet->CompatibilityModeChanged(); @@ -3708,16 +3698,21 @@ nsresult Document::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, SetReadyStateInternal(READYSTATE_LOADING); if (nsCRT::strcmp(kLoadAsData, aCommand) == 0) { - MOZ_RELEASE_ASSERT(mLoadedAsData != LoadedAsData::No); + mLoadedAsData = true; SetLoadedAsData(true, /* aConsiderForMemoryReporting */ true); // We need to disable script & style loading in this case. // We leave them disabled even in EndLoad(), and let anyone // who puts the document on display to worry about enabling. + + // Do not load/process scripts when loading as data + ScriptLoader()->SetEnabled(false); + + // styles + CSSLoader()->SetEnabled( + false); // Do not load/process styles when loading as data } else if (nsCRT::strcmp("external-resource", aCommand) == 0) { // Allow CSS, but not scripts - // TODO: Enforce this via the constructor and make mScriptLoader null here. - MOZ_ASSERT(mScriptLoader); - mScriptLoader->SetEnabled(false); + ScriptLoader()->SetEnabled(false); } mMayStartLayout = false; @@ -3894,11 +3889,7 @@ nsresult Document::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, void Document::SetLoadedAsData(bool aLoadedAsData, bool aConsiderForMemoryReporting) { - if (aLoadedAsData) { - MOZ_RELEASE_ASSERT(mLoadedAsData != LoadedAsData::No); - } else { - MOZ_RELEASE_ASSERT(mLoadedAsData == LoadedAsData::No); - } + mLoadedAsData = aLoadedAsData; if (aConsiderForMemoryReporting) { nsIGlobalObject* global = GetScopeObject(); if (global) { @@ -4035,7 +4026,7 @@ nsresult Document::InitCSP(nsIChannel* aChannel) { "Policy container must be initialized before CSP!"); // If this is a data document - no need to set CSP. - if (mLoadedAsData != LoadedAsData::No) { + if (mLoadedAsData) { return NS_OK; } @@ -4628,24 +4619,16 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal, } } - if (mScriptLoader) { - mScriptLoader->DeregisterFromCache(); - } - if (mCSSLoader) { - mCSSLoader->DeregisterFromSheetCache(); - } + mScriptLoader->DeregisterFromCache(); + mCSSLoader->DeregisterFromSheetCache(); mNodeInfoManager->SetDocumentPrincipal(aNewPrincipal); mPartitionedPrincipal = aNewPartitionedPrincipal; mCachedURLData = nullptr; - if (mCSSLoader) { - mCSSLoader->RegisterInSheetCache(); - } - if (mScriptLoader) { - mScriptLoader->RegisterToCache(); - } + mCSSLoader->RegisterInSheetCache(); + mScriptLoader->RegisterToCache(); RecomputeResistFingerprinting(); @@ -7291,10 +7274,7 @@ Element* Document::GetActiveElement() { } Element* Document::GetCurrentScript() { - if (!mScriptLoader) { - return nullptr; - } - nsCOMPtr<Element> el(do_QueryInterface(mScriptLoader->GetCurrentScript())); + nsCOMPtr<Element> el(do_QueryInterface(ScriptLoader()->GetCurrentScript())); return el; } @@ -9431,9 +9411,6 @@ void Document::EnableStyleSheetsForSet(const nsAString& aSheetSet) { void Document::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet, bool aUpdateCSSLoader) { - if (!GetCSSLoader()) { - return; - } size_t count = SheetCount(); nsAutoString title; for (size_t index = 0; index < count; index++) { @@ -9446,7 +9423,7 @@ void Document::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet, } } if (aUpdateCSSLoader) { - GetCSSLoader()->DocumentStyleSheetSetChanged(); + CSSLoader()->DocumentStyleSheetSetChanged(); } if (EnsureStyleSet().StyleSheetsHaveChanged()) { ApplicableStylesChanged(); @@ -10126,9 +10103,7 @@ SMILAnimationController* Document::GetAnimationController() { // one and only SVG documents and the like will call this if (mAnimationController) return mAnimationController; // Refuse to create an Animation Controller for data documents. - if (mLoadedAsData != LoadedAsData::No) { - return nullptr; - } + if (mLoadedAsData) return nullptr; mAnimationController = new SMILAnimationController(this); @@ -12261,9 +12236,8 @@ void Document::Destroy() { mASMJSExecutionTimer = nullptr; RecordExecutionTimeForAsmJS(this); } - if (mScriptLoader) { - mScriptLoader->Destroy(); - } + + ScriptLoader()->Destroy(); SetScriptGlobalObject(nullptr); RemovedFromDocShell(); @@ -12987,10 +12961,8 @@ void Document::SuppressEventHandling(uint32_t aIncrease) { wgc->BlockBFCacheFor(BFCacheStatus::EVENT_HANDLING_SUPPRESSED); } } - if (mScriptLoader) { - for (uint32_t i = 0; i < aIncrease; ++i) { - mScriptLoader->AddExecuteBlocker(); - } + for (uint32_t i = 0; i < aIncrease; ++i) { + ScriptLoader()->AddExecuteBlocker(); } EnumerateSubDocuments([aIncrease](Document& aSubDoc) { @@ -13295,9 +13267,6 @@ SheetPreloadStatus Document::PreloadStyle( const nsAString& aIntegrity, css::StylePreloadKind aKind, uint64_t aEarlyHintPreloaderId, const nsAString& aFetchPriority) { MOZ_ASSERT(aKind != css::StylePreloadKind::None); - if (!mCSSLoader) { - return SheetPreloadStatus::Errored; - } // The CSSLoader will retain this object after we return. nsCOMPtr<nsICSSLoaderObserver> obs = new StubCSSLoaderObserver(); @@ -13306,7 +13275,7 @@ SheetPreloadStatus Document::PreloadStyle( ReferrerInfo::CreateFromDocumentAndPolicyOverride(this, aReferrerPolicy); // Charset names are always ASCII. - auto result = GetCSSLoader()->LoadSheet( + auto result = CSSLoader()->LoadSheet( uri, aKind, aEncoding, referrerInfo, obs, aEarlyHintPreloaderId, Element::StringToCORSMode(aCrossOriginAttr), aNonce, aIntegrity, nsGenericHTMLElement::ToFetchPriority(aFetchPriority)); @@ -13320,6 +13289,12 @@ SheetPreloadStatus Document::PreloadStyle( return SheetPreloadStatus::InProgress; } +RefPtr<StyleSheet> Document::LoadChromeSheetSync(nsIURI* uri) { + return CSSLoader() + ->LoadSheetSync(uri, css::eAuthorSheetFeatures) + .unwrapOr(nullptr); +} + void Document::ResetDocumentDirection() { if (!nsContentUtils::IsChromeDoc(this)) { return; @@ -13378,9 +13353,7 @@ static void GetAndUnsuppressSubDocuments( Document& aDocument, nsTArray<nsCOMPtr<Document>>& aDocuments) { if (aDocument.EventHandlingSuppressed() > 0) { aDocument.DecreaseEventSuppression(); - if (dom::ScriptLoader* loader = aDocument.GetScriptLoader()) { - loader->RemoveExecuteBlocker(); - } + aDocument.ScriptLoader()->RemoveExecuteBlocker(); } aDocuments.AppendElement(&aDocument); aDocument.EnumerateSubDocuments([&aDocuments](Document& aSubDoc) { @@ -13530,8 +13503,8 @@ Document* Document::GetTemplateContentsOwner() { u""_ns, // aQualifiedName nullptr, // aDoctype Document::GetDocumentURI(), Document::GetDocBaseURI(), NodePrincipal(), - LoadedAsData::AsData, // aLoadedAsData - scriptObject, // aEventObject + true, // aLoadedAsData + scriptObject, // aEventObject IsHTMLDocument() ? DocumentFlavor::HTML : DocumentFlavor::XML); NS_ENSURE_SUCCESS(rv, nullptr); @@ -17032,10 +17005,9 @@ already_AddRefed<Document> Document::Constructor(const GlobalObject& aGlobal, } nsCOMPtr<Document> doc; - nsresult res = - NS_NewDOMDocument(getter_AddRefs(doc), VoidString(), u""_ns, nullptr, uri, - uri, prin->GetPrincipal(), LoadedAsData::AsData, global, - DocumentFlavor::Plain); + nsresult res = NS_NewDOMDocument(getter_AddRefs(doc), VoidString(), u""_ns, + nullptr, uri, uri, prin->GetPrincipal(), + true, global, DocumentFlavor::Plain); if (NS_FAILED(res)) { rv.Throw(res); return nullptr; @@ -17090,7 +17062,7 @@ WindowContext* Document::GetTopLevelWindowContext() const { Document* Document::GetTopLevelContentDocumentIfSameProcess() { Document* parent; - if (mLoadedAsData == LoadedAsData::No) { + if (!mLoadedAsData) { parent = this; } else { nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetScopeObject()); @@ -20658,9 +20630,9 @@ static already_AddRefed<Document> CreateHTMLDocument(GlobalObject& aGlobal, } nsCOMPtr<Document> doc; - aError = - NS_NewHTMLDocument(getter_AddRefs(doc), aGlobal.GetSubjectPrincipal(), - aGlobal.GetSubjectPrincipal(), LoadedAsData::AsData); + aError = NS_NewHTMLDocument( + getter_AddRefs(doc), aGlobal.GetSubjectPrincipal(), + aGlobal.GetSubjectPrincipal(), /* aLoadedAsData */ true); if (aError.Failed()) { return nullptr; } diff --git a/dom/base/Document.h b/dom/base/Document.h @@ -546,15 +546,6 @@ enum class SheetPreloadStatus : uint8_t { //---------------------------------------------------------------------- -enum class LoadedAsData : uint8_t { - // Not "loaded as data" - No, - // The usual "loaded as data" case: both scripts and CSS are disabled - AsData, - // The printing case: counts as "loaded as data" but still allows styling - AsDataWithStyling, -}; - // Document interface. This is implemented by all document objects in // Gecko. class Document : public nsINode, @@ -568,7 +559,7 @@ class Document : public nsINode, friend class LinkedListElement<Document>; protected: - Document(const char* aContentType, LoadedAsData aLoadedAsData); + explicit Document(const char* aContentType); virtual ~Document(); Document(const Document&) = delete; @@ -1717,18 +1708,15 @@ class Document : public nsINode, size_t FindDocStyleSheetInsertionPoint(const StyleSheet& aSheet); /** - * Get this document's CSSLoader. This is guaranteed not to return null - * during normal loads but will return null when loading as data with - * styling disabled. + * Get this document's CSSLoader. This is guaranteed to not return null. */ - css::Loader* GetCSSLoader() const { return mCSSLoader; } + css::Loader* CSSLoader() const { return mCSSLoader; } /** - * Get this document's StyleImageLoader. This is guaranteed not to return null - * during normal loads but will return null when loading as data with - * styling disabled. + * Get this document's StyleImageLoader. This is guaranteed to not return + * null. */ - css::ImageLoader* GetStyleImageLoader() const { return mStyleImageLoader; } + css::ImageLoader* StyleImageLoader() const { return mStyleImageLoader; } /** * Get the channel that was passed to StartDocumentLoad or Reset for this @@ -1829,10 +1817,9 @@ class Document : public nsINode, } /** - * Get the script loader for this document. Non-null for normal loads - * and null when loaded as data. + * Get the script loader for this document */ - dom::ScriptLoader* GetScriptLoader() { return mScriptLoader; } + dom::ScriptLoader* ScriptLoader() { return mScriptLoader; } /** * Add/Remove an element to the document's id and name hashes @@ -2573,9 +2560,7 @@ class Document : public nsINode, !NodePrincipal()->SchemeIs("file"); } - bool IsLoadedAsData() const { - return mLoadedAsData != mozilla::dom::LoadedAsData::No; - } + bool IsLoadedAsData() { return mLoadedAsData; } void SetAddedToMemoryReportAsDataDocument() { mAddedToMemoryReportingAsDataDocument = true; @@ -3058,6 +3043,13 @@ class Document : public nsINode, const nsAString& aFetchPriority); /** + * Called by the chrome registry to load style sheets. + * + * This always does a synchronous load, and parses as a normal document sheet. + */ + RefPtr<StyleSheet> LoadChromeSheetSync(nsIURI* aURI); + + /** * Returns true if the locale used for the document specifies a direction of * right to left. For chrome documents, this comes from the chrome registry. * This is used to determine the current state for the :-moz-locale-dir @@ -4784,10 +4776,6 @@ class Document : public nsINode, DocumentState mState{DocumentState::LTR_LOCALE}; - // Indicates whether this document is normal as in navigation, loaded as data - // as in XHR or DOMParser, or loaded as data with styling as in printing. - const mozilla::dom::LoadedAsData mLoadedAsData; - RefPtr<Promise> mReadyForIdle; RefPtr<mozilla::dom::FeaturePolicy> mFeaturePolicy; @@ -4824,6 +4812,10 @@ class Document : public nsINode, bool mIgnoreDocGroupMismatches : 1; + // True if we're loaded as data and therefor has any dangerous stuff, such + // as scripts and plugins, disabled. + bool mLoadedAsData : 1; + // True if the document is considered for memory reporting as a // data document bool mAddedToMemoryReportingAsDataDocument : 1; @@ -5760,21 +5752,20 @@ bool IsInActiveTab(Document* aDoc); NON_VIRTUAL_ADDREF_RELEASE(mozilla::dom::Document) // XXX These belong somewhere else -nsresult NS_NewHTMLDocument( - mozilla::dom::Document** aInstancePtrResult, nsIPrincipal* aPrincipal, - nsIPrincipal* aPartitionedPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData = mozilla::dom::LoadedAsData::No); - -nsresult NS_NewXMLDocument( - mozilla::dom::Document** aInstancePtrResult, nsIPrincipal* aPrincipal, - nsIPrincipal* aPartitionedPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData = mozilla::dom::LoadedAsData::No, - bool aIsPlainDocument = false); - -nsresult NS_NewSVGDocument( - mozilla::dom::Document** aInstancePtrResult, nsIPrincipal* aPrincipal, - nsIPrincipal* aPartitionedPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData = mozilla::dom::LoadedAsData::No); +nsresult NS_NewHTMLDocument(mozilla::dom::Document** aInstancePtrResult, + nsIPrincipal* aPrincipal, + nsIPrincipal* aPartitionedPrincipal, + bool aLoadedAsData = false); + +nsresult NS_NewXMLDocument(mozilla::dom::Document** aInstancePtrResult, + nsIPrincipal* aPrincipal, + nsIPrincipal* aPartitionedPrincipal, + bool aLoadedAsData = false, + bool aIsPlainDocument = false); + +nsresult NS_NewSVGDocument(mozilla::dom::Document** aInstancePtrResult, + nsIPrincipal* aPrincipal, + nsIPrincipal* aPartitionedPrincipal); nsresult NS_NewImageDocument(mozilla::dom::Document** aInstancePtrResult, nsIPrincipal* aPrincipal, @@ -5800,8 +5791,7 @@ nsresult NS_NewDOMDocument( mozilla::dom::Document** aInstancePtrResult, const nsAString& aNamespaceURI, const nsAString& aQualifiedName, mozilla::dom::DocumentType* aDoctype, nsIURI* aDocumentURI, nsIURI* aBaseURI, nsIPrincipal* aPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData, nsIGlobalObject* aEventObject, - DocumentFlavor aFlavor); + bool aLoadedAsData, nsIGlobalObject* aEventObject, DocumentFlavor aFlavor); inline mozilla::dom::Document* nsINode::GetOwnerDocument() const { mozilla::dom::Document* ownerDoc = OwnerDoc(); diff --git a/dom/base/LinkStyle.cpp b/dom/base/LinkStyle.cpp @@ -259,7 +259,7 @@ Result<LinkStyle::Update, nsresult> LinkStyle::DoUpdateStyleSheet( // Loader could be null during unlink, see bug 1425866. // ... No need to update if updating is disabled, as well. - if (!doc || !doc->GetCSSLoader() || !doc->GetCSSLoader()->GetEnabled() || + if (!doc || !doc->CSSLoader() || !doc->CSSLoader()->GetEnabled() || !mUpdatesEnabled) { return Update{}; } @@ -329,7 +329,7 @@ Result<LinkStyle::Update, nsresult> LinkStyle::DoUpdateStyleSheet( } // Parse the style sheet. - return doc->GetCSSLoader()->LoadInlineStyle(*info, text, aObserver); + return doc->CSSLoader()->LoadInlineStyle(*info, text, aObserver); } if (thisContent.IsElement()) { nsAutoString integrity; @@ -340,7 +340,7 @@ Result<LinkStyle::Update, nsresult> LinkStyle::DoUpdateStyleSheet( NS_ConvertUTF16toUTF8(integrity).get())); } } - auto resultOrError = doc->GetCSSLoader()->LoadStyleLink(*info, aObserver); + auto resultOrError = doc->CSSLoader()->LoadStyleLink(*info, aObserver); if (resultOrError.isErr()) { // Don't propagate LoadStyleLink() errors further than this, since some // consumers (e.g. nsXMLContentSink) will completely abort on innocuous @@ -365,7 +365,7 @@ void LinkStyle::MaybeStartCopyStyleSheetTo(LinkStyle* aDest, } void LinkStyle::MaybeFinishCopyStyleSheet(Document* aDocument) { - if (!mStyleSheet || !aDocument->GetCSSLoader()) { + if (!mStyleSheet) { return; } auto& thisContent = AsContent(); @@ -388,7 +388,7 @@ void LinkStyle::MaybeFinishCopyStyleSheet(Document* aDocument) { } RefPtr<StyleSheet> sheet = mStyleSheet->Clone(nullptr, root); SetStyleSheet(sheet.get()); - aDocument->GetCSSLoader()->InsertSheetInTree(*sheet); + aDocument->CSSLoader()->InsertSheetInTree(*sheet); } } // namespace mozilla::dom diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp @@ -1940,9 +1940,9 @@ bool nsAttrValue::ParseStyleAttribute(const nsAString& aString, } } - RefPtr<DeclarationBlock> decl = DeclarationBlock::FromCssText( - aString, data, doc->GetCompatibilityMode(), doc->GetCSSLoader(), - StyleCssRuleType::Style); + RefPtr<DeclarationBlock> decl = + DeclarationBlock::FromCssText(aString, data, doc->GetCompatibilityMode(), + doc->CSSLoader(), StyleCssRuleType::Style); if (!decl) { return false; } diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp @@ -163,7 +163,7 @@ nsresult nsContentSink::Init(Document* aDoc, nsIURI* aURI, mDocumentURI = aURI; mDocShell = do_QueryInterface(aContainer); - mScriptLoader = mDocument->GetScriptLoader(); + mScriptLoader = mDocument->ScriptLoader(); if (!mRunsToCompletion) { if (mDocShell) { @@ -176,7 +176,7 @@ nsresult nsContentSink::Init(Document* aDoc, nsIURI* aURI, ProcessHTTPHeaders(aChannel); } - mCSSLoader = aDoc->GetCSSLoader(); + mCSSLoader = aDoc->CSSLoader(); mNodeInfoManager = aDoc->NodeInfoManager(); @@ -218,13 +218,11 @@ nsContentSink::StyleSheetLoaded(StyleSheet* aSheet, bool aWasDeferred, ScrollToRef(); } - if (mScriptLoader) { - mScriptLoader->RemoveParserBlockingScriptExecutionBlocker(); + mScriptLoader->RemoveParserBlockingScriptExecutionBlocker(); - if (loadedAllSheets && - mDocument->GetReadyStateEnum() >= Document::READYSTATE_INTERACTIVE) { - mScriptLoader->DeferCheckpointReached(); - } + if (loadedAllSheets && + mDocument->GetReadyStateEnum() >= Document::READYSTATE_INTERACTIVE) { + mScriptLoader->DeferCheckpointReached(); } return NS_OK; @@ -325,8 +323,7 @@ nsresult nsContentSink::ProcessLinkFromHeader(const net::LinkHeader& aHeader, } if ((linkTypes & LinkStyle::eMODULE_PRELOAD) && - mDocument->GetScriptLoader() && - mDocument->GetScriptLoader()->GetModuleLoader()) { + mDocument->ScriptLoader()->GetModuleLoader()) { PreloadModule(aHeader.mHref, aHeader.mAs, aHeader.mMedia, aHeader.mNonce, aHeader.mIntegrity, aHeader.mCrossOrigin, aHeader.mReferrerPolicy, aEarlyHintPreloaderId, @@ -351,9 +348,6 @@ nsresult nsContentSink::ProcessStyleLinkFromHeader( const nsAString& aIntegrity, const nsAString& aType, const nsAString& aMedia, const nsAString& aReferrerPolicy, const nsAString& aFetchPriority) { - if (!mCSSLoader) { - return NS_OK; - } if (aAlternate && aTitle.IsEmpty()) { // alternates must have title return without error, for now return NS_OK; @@ -413,9 +407,7 @@ nsresult nsContentSink::ProcessStyleLinkFromHeader( if (loadResultOrErr.inspect().ShouldBlock() && !mRunsToCompletion) { ++mPendingSheetCount; - if (mScriptLoader) { - mScriptLoader->AddParserBlockingScriptExecutionBlocker(); - } + mScriptLoader->AddParserBlockingScriptExecutionBlocker(); } return NS_OK; @@ -481,11 +473,7 @@ void nsContentSink::PreloadModule( const nsAString& aNonce, const nsAString& aIntegrity, const nsAString& aCORS, const nsAString& aReferrerPolicy, uint64_t aEarlyHintPreloaderId, const nsAString& aFetchPriority) { - dom::ScriptLoader* scriptLoader = mDocument->GetScriptLoader(); - if (!scriptLoader) { - return; - } - ModuleLoader* moduleLoader = scriptLoader->GetModuleLoader(); + ModuleLoader* moduleLoader = mDocument->ScriptLoader()->GetModuleLoader(); if (!StaticPrefs::network_modulepreload()) { // Keep behavior from https://phabricator.services.mozilla.com/D149371, @@ -894,7 +882,7 @@ void nsContentSink::DropParserAndPerfHint(void) { } bool nsContentSink::IsScriptExecutingImpl() { - return mScriptLoader && mScriptLoader->GetCurrentScript(); + return !!mScriptLoader->GetCurrentScript(); } void nsContentSink::ContinueParsingDocumentAfterCurrentScriptImpl() { diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp @@ -6462,7 +6462,7 @@ static already_AddRefed<Document> CreateInertDocument(const Document* aTemplate, nsresult rv = NS_NewDOMDocument( getter_AddRefs(doc), u""_ns, u""_ns, nullptr, aTemplate->GetDocumentURI(), aTemplate->GetDocBaseURI(), - aTemplate->NodePrincipal(), LoadedAsData::AsData, sgo, aFlavor); + aTemplate->NodePrincipal(), true, sgo, aFlavor); if (NS_FAILED(rv)) { return nullptr; } @@ -6483,7 +6483,7 @@ static already_AddRefed<Document> CreateInertDocument(const Document* aTemplate, nsCOMPtr<Document> doc; nsresult rv = NS_NewDOMDocument(getter_AddRefs(doc), u""_ns, u""_ns, nullptr, uri, uri, - nullPrincipal, LoadedAsData::AsData, nullptr, aFlavor); + nullPrincipal, true, nullptr, aFlavor); if (NS_FAILED(rv)) { return nullptr; } diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp @@ -1288,12 +1288,8 @@ nsDOMWindowUtils::GetParsedStyleSheets(uint32_t* aSheets) { if (!doc) { return NS_ERROR_UNEXPECTED; } - css::Loader* cssLoader = doc->GetCSSLoader(); - if (cssLoader) { - *aSheets = cssLoader->ParsedSheetCount(); - } else { - *aSheets = 0; - } + + *aSheets = doc->CSSLoader()->ParsedSheetCount(); return NS_OK; } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp @@ -7628,7 +7628,7 @@ JS::loader::ModuleLoaderBase* nsGlobalWindowInner::GetModuleLoader( return nullptr; } - ScriptLoader* loader = document->GetScriptLoader(); + ScriptLoader* loader = document->ScriptLoader(); if (!loader) { return nullptr; } diff --git a/dom/base/nsSyncLoadService.cpp b/dom/base/nsSyncLoadService.cpp @@ -161,8 +161,7 @@ nsresult nsSyncLoader::LoadDocument(nsIChannel* aChannel, bool aChannelIsSync, // Create document nsCOMPtr<Document> document; - rv = NS_NewXMLDocument(getter_AddRefs(document), nullptr, nullptr, - LoadedAsData::AsData); + rv = NS_NewXMLDocument(getter_AddRefs(document), nullptr, nullptr); NS_ENSURE_SUCCESS(rv, rv); // Start the document load. Do this before we attach the load listener diff --git a/dom/base/test/gtest/TestCharacterDataBuffer.cpp b/dom/base/test/gtest/TestCharacterDataBuffer.cpp @@ -33,8 +33,8 @@ static already_AddRefed<Document> CreateHTMLDoc() { u""_ns, // aQualifiedName nullptr, // aDoctype uri, uri, principal, - LoadedAsData::No, // aLoadedAsData - nullptr, // aEventObject + false, // aLoadedAsData + nullptr, // aEventObject DocumentFlavor::HTML)); MOZ_RELEASE_ASSERT(doc); return doc.forget(); diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1294,7 +1294,7 @@ CanvasRenderingContext2D::ColorStyleCacheEntry CanvasRenderingContext2D::ParseColorSlow(const nsACString& aString) { ColorStyleCacheEntry result{nsCString(aString)}; Document* document = mCanvasElement ? mCanvasElement->OwnerDoc() : nullptr; - css::Loader* loader = document ? document->GetCSSLoader() : nullptr; + css::Loader* loader = document ? document->CSSLoader() : nullptr; PresShell* presShell = GetPresShell(); ServoStyleSet* set = presShell ? presShell->StyleSet() : nullptr; @@ -2794,7 +2794,7 @@ static already_AddRefed<StyleLockedDeclarationBlock> CreateDeclarationForServo( Document* aDocument) { ServoCSSParser::ParsingEnvironment env{aDocument->DefaultStyleAttrURLData(), aDocument->GetCompatibilityMode(), - aDocument->GetCSSLoader()}; + aDocument->CSSLoader()}; RefPtr<StyleLockedDeclarationBlock> servoDeclarations = ServoCSSParser::ParseProperty(aProperty, aPropertyValue, env, StyleParsingMode::DEFAULT); diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp @@ -508,10 +508,7 @@ void HTMLLinkElement:: } if (linkTypes & eMODULE_PRELOAD) { - ScriptLoader* scriptLoader = OwnerDoc()->GetScriptLoader(); - if (!scriptLoader) { - return; - } + ScriptLoader* scriptLoader = OwnerDoc()->ScriptLoader(); ModuleLoader* moduleLoader = scriptLoader->GetModuleLoader(); if (!moduleLoader) { diff --git a/dom/html/MediaDocument.cpp b/dom/html/MediaDocument.cpp @@ -121,8 +121,7 @@ const char* const MediaDocument::sFormatNames[4] = { "" // eWithDimAndFile }; -MediaDocument::MediaDocument() - : nsHTMLDocument(LoadedAsData::No), mDidInitialDocumentSetup(false) { +MediaDocument::MediaDocument() : mDidInitialDocumentSetup(false) { mCompatMode = eCompatibility_FullStandards; } MediaDocument::~MediaDocument() = default; diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp @@ -102,8 +102,8 @@ static bool IsAsciiCompatible(const Encoding* aEncoding) { nsresult NS_NewHTMLDocument(Document** aInstancePtrResult, nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData) { - RefPtr<nsHTMLDocument> doc = new nsHTMLDocument(aLoadedAsData); + bool aLoadedAsData) { + RefPtr<nsHTMLDocument> doc = new nsHTMLDocument(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal); @@ -112,15 +112,14 @@ nsresult NS_NewHTMLDocument(Document** aInstancePtrResult, return rv; } - doc->SetLoadedAsData(aLoadedAsData != mozilla::dom::LoadedAsData::No, - /* aConsiderForMemoryReporting */ true); + doc->SetLoadedAsData(aLoadedAsData, /* aConsiderForMemoryReporting */ true); doc.forget(aInstancePtrResult); return NS_OK; } -nsHTMLDocument::nsHTMLDocument(mozilla::dom::LoadedAsData aLoadedAsData) - : Document("text/html", aLoadedAsData), +nsHTMLDocument::nsHTMLDocument() + : Document("text/html"), mContentListHolder(nullptr), mNumForms(0), mLoadFlags(0), @@ -146,9 +145,7 @@ nsresult nsHTMLDocument::Init(nsIPrincipal* aPrincipal, // Now reset the compatibility mode of the CSSLoader // to match our compat mode. - if (mCSSLoader) { - mCSSLoader->SetCompatibilityMode(mCompatMode); - } + CSSLoader()->SetCompatibilityMode(mCompatMode); return NS_OK; } @@ -733,9 +730,7 @@ nsresult nsHTMLDocument::Clone(dom::NodeInfo* aNodeInfo, NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager, "Can't import this document into another document!"); - // TODO: Disable styling when not needed. - RefPtr<nsHTMLDocument> clone = - new nsHTMLDocument(LoadedAsData::AsDataWithStyling); + RefPtr<nsHTMLDocument> clone = new nsHTMLDocument(); nsresult rv = CloneDocHelper(clone.get()); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h @@ -40,7 +40,7 @@ class nsHTMLDocument : public mozilla::dom::Document { public: using Document::SetDocumentURI; - explicit nsHTMLDocument(mozilla::dom::LoadedAsData aLoadedAsData); + nsHTMLDocument(); virtual nsresult Init(nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal) override; diff --git a/dom/l10n/tests/gtest/TestL10nOverlays.cpp b/dom/l10n/tests/gtest/TestL10nOverlays.cpp @@ -20,15 +20,14 @@ static already_AddRefed<Document> SetUpDocument() { nsCOMPtr<nsIPrincipal> principal = NullPrincipal::CreateWithoutOriginAttributes(); nsCOMPtr<Document> document; - nsresult rv = - NS_NewDOMDocument(getter_AddRefs(document), - u""_ns, // aNamespaceURI - u""_ns, // aQualifiedName - nullptr, // aDoctype - uri, uri, principal, - mozilla::dom::LoadedAsData::No, // aLoadedAsData - nullptr, // aEventObject - DocumentFlavor::HTML); + nsresult rv = NS_NewDOMDocument(getter_AddRefs(document), + u""_ns, // aNamespaceURI + u""_ns, // aQualifiedName + nullptr, // aDoctype + uri, uri, principal, + false, // aLoadedAsData + nullptr, // aEventObject + DocumentFlavor::HTML); if (NS_WARN_IF(NS_FAILED(rv))) { return nullptr; diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -115,7 +115,7 @@ nsresult PrototypeDocumentContentSink::Init(Document* aDoc, nsIURI* aURI, nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(mDocumentURI)); NS_ENSURE_SUCCESS(rv, rv); - mScriptLoader = mDocument->GetScriptLoader(); + mScriptLoader = mDocument->ScriptLoader(); return NS_OK; } @@ -152,10 +152,6 @@ nsISupports* PrototypeDocumentContentSink::GetTarget() { } bool PrototypeDocumentContentSink::IsScriptExecuting() { - if (!mScriptLoader) { - MOZ_ASSERT(false, "Can't load prototype docs as data"); - return false; - } return !!mScriptLoader->GetCurrentScript(); } diff --git a/dom/script/ScriptElement.cpp b/dom/script/ScriptElement.cpp @@ -248,10 +248,7 @@ bool ScriptElement::MaybeProcessScript(const nsAString& aSourceText) { } } - RefPtr<ScriptLoader> loader = ownerDoc->GetScriptLoader(); - if (!loader) { - return false; - } + RefPtr<ScriptLoader> loader = ownerDoc->ScriptLoader(); return loader->ProcessScriptElement(this, aSourceText); } diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -3957,8 +3957,8 @@ bool ScriptLoader::ReadyToExecuteParserBlockingScripts() { mDocument->GetWindowContext()->GetParentWindowContext(); wc; wc = wc->GetParentWindowContext()) { if (Document* doc = wc->GetDocument()) { - ScriptLoader* ancestor = doc->GetScriptLoader(); - if (ancestor && !ancestor->SelfReadyToExecuteParserBlockingScripts() && + ScriptLoader* ancestor = doc->ScriptLoader(); + if (!ancestor->SelfReadyToExecuteParserBlockingScripts() && ancestor->AddPendingChildLoader(this)) { AddParserBlockingScriptExecutionBlocker(); return false; @@ -4848,8 +4848,8 @@ void ScriptLoader::BeginDeferringScripts() { } nsAutoScriptLoaderDisabler::nsAutoScriptLoaderDisabler(Document* aDoc) { - mLoader = aDoc->GetScriptLoader(); - mWasEnabled = mLoader && mLoader->GetEnabled(); + mLoader = aDoc->ScriptLoader(); + mWasEnabled = mLoader->GetEnabled(); if (mWasEnabled) { mLoader->SetEnabled(false); } @@ -4857,7 +4857,6 @@ nsAutoScriptLoaderDisabler::nsAutoScriptLoaderDisabler(Document* aDoc) { nsAutoScriptLoaderDisabler::~nsAutoScriptLoaderDisabler() { if (mWasEnabled) { - MOZ_ASSERT(mLoader, "mWasEnabled can be true only if we have a loader"); mLoader->SetEnabled(true); } } diff --git a/dom/script/ShadowRealmGlobalScope.cpp b/dom/script/ShadowRealmGlobalScope.cpp @@ -108,10 +108,7 @@ ModuleLoaderBase* ShadowRealmGlobalScope::GetModuleLoader(JSContext* aCx) { return nullptr; } - ScriptLoader* scriptLoader = doc->GetScriptLoader(); - if (!scriptLoader) { - return nullptr; - } + ScriptLoader* scriptLoader = doc->ScriptLoader(); mModuleLoader = new ModuleLoader(scriptLoader, this, ModuleLoader::Normal); diff --git a/dom/svg/SVGDocument.cpp b/dom/svg/SVGDocument.cpp @@ -28,8 +28,7 @@ nsresult SVGDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const { NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager, "Can't import this document into another document!"); - // TODO: Disable styling when not needed - RefPtr<SVGDocument> clone = new SVGDocument(LoadedAsData::AsDataWithStyling); + RefPtr<SVGDocument> clone = new SVGDocument(); nsresult rv = CloneDocHelper(clone.get()); NS_ENSURE_SUCCESS(rv, rv); @@ -44,9 +43,8 @@ nsresult SVGDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const { nsresult NS_NewSVGDocument(Document** aInstancePtrResult, nsIPrincipal* aPrincipal, - nsIPrincipal* aPartitionedPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData) { - RefPtr<SVGDocument> doc = new SVGDocument(aLoadedAsData); + nsIPrincipal* aPartitionedPrincipal) { + RefPtr<SVGDocument> doc = new SVGDocument(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal); if (NS_FAILED(rv)) { diff --git a/dom/svg/SVGDocument.h b/dom/svg/SVGDocument.h @@ -19,10 +19,7 @@ class SVGForeignObjectElement; class SVGDocument final : public XMLDocument { public: - explicit SVGDocument(LoadedAsData aLoadedAsData) - : XMLDocument("image/svg+xml", aLoadedAsData) { - mType = eSVG; - } + SVGDocument() : XMLDocument("image/svg+xml") { mType = eSVG; } nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; }; diff --git a/dom/svg/SVGElement.cpp b/dom/svg/SVGElement.cpp @@ -1262,8 +1262,8 @@ void MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName, changed = Servo_DeclarationBlock_SetPropertyById( &EnsureDeclarationBlock(), propertyID, &value, false, &EnsureExtraData(), StyleParsingMode::ALLOW_UNITLESS_LENGTH, - doc->GetCompatibilityMode(), doc->GetCSSLoader(), - StyleCssRuleType::Style, {}); + doc->GetCompatibilityMode(), doc->CSSLoader(), StyleCssRuleType::Style, + {}); // TODO(emilio): If we want to record these from CSSOM more generally, we // can pass the document use counters down the FFI call. For now manually diff --git a/dom/view-transitions/ViewTransition.cpp b/dom/view-transitions/ViewTransition.cpp @@ -592,7 +592,7 @@ static bool SetProp(StyleLockedDeclarationBlock* aDecls, Document* aDoc, aDecls, aProp, &aValue, /* is_important = */ false, aDoc->DefaultStyleAttrURLData(), StyleParsingMode::DEFAULT, eCompatibility_FullStandards, - aDoc->GetCSSLoader(), StyleCssRuleType::Style, {}); + aDoc->CSSLoader(), StyleCssRuleType::Style, {}); } static bool SetProp(StyleLockedDeclarationBlock* aDecls, Document*, diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -2178,7 +2178,7 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest* request) { rv = NS_NewDOMDocument( getter_AddRefs(mResponseXML), emptyStr, emptyStr, nullptr, docURI, - baseURI, requestingPrincipal, LoadedAsData::AsData, global, + baseURI, requestingPrincipal, true, global, mIsHtml ? DocumentFlavor::HTML : DocumentFlavor::LegacyGuess); NS_ENSURE_SUCCESS(rv, rv); mResponseXML->SetChromeXHRDocURI(chromeXHRDocURI); diff --git a/dom/xml/XMLDocument.cpp b/dom/xml/XMLDocument.cpp @@ -53,8 +53,7 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult, const nsAString& aQualifiedName, DocumentType* aDoctype, nsIURI* aDocumentURI, nsIURI* aBaseURI, nsIPrincipal* aPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData, - nsIGlobalObject* aEventObject, + bool aLoadedAsData, nsIGlobalObject* aEventObject, DocumentFlavor aFlavor) { // Note: can't require that aDocumentURI/aBaseURI/aPrincipal be non-null, // since at least one caller (XMLHttpRequest) doesn't have decent args to @@ -68,15 +67,12 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult, bool isHTML = false; bool isXHTML = false; if (aFlavor == DocumentFlavor::SVG) { - rv = NS_NewSVGDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewSVGDocument(getter_AddRefs(d), aPrincipal, aPrincipal); } else if (aFlavor == DocumentFlavor::HTML) { - rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal); isHTML = true; } else if (aFlavor == DocumentFlavor::XML) { - rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal); } else if (aFlavor == DocumentFlavor::Plain) { rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, aLoadedAsData, true); @@ -94,28 +90,23 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult, publicId.EqualsLiteral("-//W3C//DTD HTML 4.0//EN") || publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Frameset//EN") || publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Transitional//EN")) { - rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal); isHTML = true; } else if (publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Strict//EN") || publicId.EqualsLiteral( "-//W3C//DTD XHTML 1.0 Transitional//EN") || publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Frameset//EN")) { - rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewHTMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal); isHTML = true; isXHTML = true; } else if (publicId.EqualsLiteral("-//W3C//DTD SVG 1.1//EN")) { - rv = NS_NewSVGDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewSVGDocument(getter_AddRefs(d), aPrincipal, aPrincipal); } else { - rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal); } } else { MOZ_ASSERT(aFlavor == DocumentFlavor::LegacyGuess); - rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal, - aLoadedAsData); + rv = NS_NewXMLDocument(getter_AddRefs(d), aPrincipal, aPrincipal); } if (NS_FAILED(rv)) { @@ -126,8 +117,7 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult, d->SetCompatibilityMode(eCompatibility_FullStandards); d->AsHTMLDocument()->SetIsXHTML(isXHTML); } - d->SetLoadedAsData(aLoadedAsData != mozilla::dom::LoadedAsData::No, - /* aConsiderForMemoryReporting */ true); + d->SetLoadedAsData(aLoadedAsData, /* aConsiderForMemoryReporting */ true); d->SetDocumentURI(aDocumentURI); d->SetBaseURI(aBaseURI); @@ -184,9 +174,8 @@ nsresult NS_NewDOMDocument(Document** aInstancePtrResult, nsresult NS_NewXMLDocument(Document** aInstancePtrResult, nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal, - mozilla::dom::LoadedAsData aLoadedAsData, - bool aIsPlainDocument) { - RefPtr<XMLDocument> doc = new XMLDocument("application/xml", aLoadedAsData); + bool aLoadedAsData, bool aIsPlainDocument) { + RefPtr<XMLDocument> doc = new XMLDocument(); nsresult rv = doc->Init(aPrincipal, aPartitionedPrincipal); @@ -195,8 +184,7 @@ nsresult NS_NewXMLDocument(Document** aInstancePtrResult, return rv; } - doc->SetLoadedAsData(aLoadedAsData != mozilla::dom::LoadedAsData::No, - /* aConsiderForMemoryReporting */ true); + doc->SetLoadedAsData(aLoadedAsData, /* aConsiderForMemoryReporting */ true); doc->mIsPlainDocument = aIsPlainDocument; doc.forget(aInstancePtrResult); @@ -205,9 +193,8 @@ nsresult NS_NewXMLDocument(Document** aInstancePtrResult, namespace mozilla::dom { -XMLDocument::XMLDocument(const char* aContentType, - mozilla::dom::LoadedAsData aLoadedAsData) - : Document(aContentType, aLoadedAsData), +XMLDocument::XMLDocument(const char* aContentType) + : Document(aContentType), mChannelIsPending(false), mIsPlainDocument(false), mSuppressParserErrorElement(false), @@ -303,7 +290,7 @@ nsresult XMLDocument::StartDocumentLoad( void XMLDocument::EndLoad() { mChannelIsPending = false; - mSynchronousDOMContentLoaded = mLoadedAsData != LoadedAsData::No; + mSynchronousDOMContentLoaded = mLoadedAsData; Document::EndLoad(); if (mSynchronousDOMContentLoaded) { mSynchronousDOMContentLoaded = false; @@ -327,9 +314,7 @@ nsresult XMLDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const { NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager, "Can't import this document into another document!"); - // TODO: Disable styling when not needed. - RefPtr<XMLDocument> clone = - new XMLDocument("application/xml", LoadedAsData::AsDataWithStyling); + RefPtr<XMLDocument> clone = new XMLDocument(); nsresult rv = CloneDocHelper(clone); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/xml/XMLDocument.h b/dom/xml/XMLDocument.h @@ -19,8 +19,7 @@ namespace mozilla::dom { class XMLDocument : public Document { public: - XMLDocument(const char* aContentType, - mozilla::dom::LoadedAsData aLoadedAsData); + explicit XMLDocument(const char* aContentType = "application/xml"); NS_INLINE_DECL_REFCOUNTING_INHERITED(XMLDocument, Document) @@ -64,7 +63,7 @@ class XMLDocument : public Document { JS::Handle<JSObject*> aGivenProto) override; friend nsresult(::NS_NewXMLDocument)(Document**, nsIPrincipal*, nsIPrincipal*, - mozilla::dom::LoadedAsData, bool); + bool, bool); // mChannelIsPending indicates whether we're currently asynchronously loading // data from mChannel. It's set to true when we first find out about the diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp @@ -305,8 +305,8 @@ nsXMLContentSink::DidBuildModel(bool aTerminated) { // We're pretty-printing now. See whether we should wait up on // stylesheet loads - if (mCSSLoader && mCSSLoader->HasPendingLoads()) { - mCSSLoader->AddObserver(this); + if (mDocument->CSSLoader()->HasPendingLoads()) { + mDocument->CSSLoader()->AddObserver(this); // wait for those sheets to load startLayout = false; } @@ -445,9 +445,8 @@ nsXMLContentSink::StyleSheetLoaded(StyleSheet* aSheet, bool aWasDeferred, return nsContentSink::StyleSheetLoaded(aSheet, aWasDeferred, aStatus); } - if (mDocument->GetCSSLoader() && - !mDocument->GetCSSLoader()->HasPendingLoads()) { - mDocument->GetCSSLoader()->RemoveObserver(this); + if (!mDocument->CSSLoader()->HasPendingLoads()) { + mDocument->CSSLoader()->RemoveObserver(this); StartLayout(false); ScrollToRef(); } @@ -669,9 +668,7 @@ nsresult nsXMLContentSink::CloseElement(nsIContent* aContent) { rv = updateOrError.unwrapErr(); } else if (updateOrError.unwrap().ShouldBlock() && !mRunsToCompletion) { ++mPendingSheetCount; - if (mScriptLoader) { - mScriptLoader->AddParserBlockingScriptExecutionBlocker(); - } + mScriptLoader->AddParserBlockingScriptExecutionBlocker(); } } @@ -947,9 +944,7 @@ bool nsXMLContentSink::SetDocElement(int32_t aNameSpaceID, nsAtom* aTagName, // Successfully started a stylesheet load if (update.ShouldBlock() && !mRunsToCompletion) { ++mPendingSheetCount; - if (mScriptLoader) { - mScriptLoader->AddParserBlockingScriptExecutionBlocker(); - } + mScriptLoader->AddParserBlockingScriptExecutionBlocker(); } } } @@ -962,9 +957,7 @@ bool nsXMLContentSink::SetDocElement(int32_t aNameSpaceID, nsAtom* aTagName, if (mPrettyPrintXML) { // In this case, disable script execution, stylesheet // loading, and auto XLinks since we plan to prettyprint. - if (dom::ScriptLoader* scriptLoader = mDocument->GetScriptLoader()) { - scriptLoader->SetEnabled(false); - } + mDocument->ScriptLoader()->SetEnabled(false); if (mCSSLoader) { mCSSLoader->SetEnabled(false); } diff --git a/dom/xslt/xslt/txMozillaTextOutput.cpp b/dom/xslt/xslt/txMozillaTextOutput.cpp @@ -123,9 +123,8 @@ nsresult txMozillaTextOutput::createResultDocument(bool aLoadedAsData) { */ // Create the document - nsresult rv = NS_NewXMLDocument( - getter_AddRefs(mDocument), nullptr, nullptr, - aLoadedAsData ? LoadedAsData::AsData : LoadedAsData::No); + nsresult rv = NS_NewXMLDocument(getter_AddRefs(mDocument), nullptr, nullptr, + aLoadedAsData); NS_ENSURE_SUCCESS(rv, rv); mCreatedDocument = true; // This should really be handled by Document::BeginLoad diff --git a/dom/xslt/xslt/txMozillaXMLOutput.cpp b/dom/xslt/xslt/txMozillaXMLOutput.cpp @@ -216,7 +216,7 @@ nsresult txMozillaXMLOutput::endDocument(nsresult aResult) { MOZ_ASSERT(mDocument->GetReadyStateEnum() == Document::READYSTATE_LOADING, "Bad readyState"); mDocument->SetReadyStateInternal(Document::READYSTATE_INTERACTIVE); - if (ScriptLoader* loader = mDocument->GetScriptLoader()) { + if (ScriptLoader* loader = mDocument->ScriptLoader()) { loader->ParsingComplete(false); } } @@ -382,7 +382,7 @@ nsresult txMozillaXMLOutput::startDocument() { } if (mCreatingNewDocument) { - ScriptLoader* loader = mDocument->GetScriptLoader(); + ScriptLoader* loader = mDocument->ScriptLoader(); if (loader) { loader->BeginDeferringScripts(); } @@ -690,15 +690,13 @@ nsresult txMozillaXMLOutput::createResultDocument(const nsAString& aName, bool aLoadedAsData) { // Create the document if (mOutputFormat.mMethod == eHTMLOutput) { - MOZ_TRY(NS_NewHTMLDocument( - getter_AddRefs(mDocument), nullptr, nullptr, - aLoadedAsData ? LoadedAsData::AsData : LoadedAsData::No)); + MOZ_TRY(NS_NewHTMLDocument(getter_AddRefs(mDocument), nullptr, nullptr, + aLoadedAsData)); } else { // We should check the root name/namespace here and create the // appropriate document - MOZ_TRY(NS_NewXMLDocument( - getter_AddRefs(mDocument), nullptr, nullptr, - aLoadedAsData ? LoadedAsData::AsData : LoadedAsData::No)); + MOZ_TRY(NS_NewXMLDocument(getter_AddRefs(mDocument), nullptr, nullptr, + aLoadedAsData)); } // This should really be handled by Document::BeginLoad MOZ_ASSERT( @@ -760,14 +758,12 @@ nsresult txMozillaXMLOutput::createResultDocument(const nsAString& aName, } // Set up script loader of the result document. - ScriptLoader* loader = mDocument->GetScriptLoader(); - if (loader) { - if (mNotifier) { - loader->AddObserver(mNotifier); - } else { - // Don't load scripts, we can't notify the caller when they're loaded. - loader->SetEnabled(false); - } + ScriptLoader* loader = mDocument->ScriptLoader(); + if (mNotifier) { + loader->AddObserver(mNotifier); + } else { + // Don't load scripts, we can't notify the caller when they're loaded. + loader->SetEnabled(false); } if (mNotifier) { @@ -924,15 +920,12 @@ void txTransformNotifier::SignalTransformEnd(nsresult aResult) { nsCOMPtr<nsIScriptLoaderObserver> kungFuDeathGrip(this); if (mDocument) { - if (dom::ScriptLoader* scriptLoader = mDocument->GetScriptLoader()) { - scriptLoader->DeferCheckpointReached(); - scriptLoader->RemoveObserver(this); - // XXX Maybe we want to cancel script loads if NS_FAILED(rv)? - } + mDocument->ScriptLoader()->DeferCheckpointReached(); + mDocument->ScriptLoader()->RemoveObserver(this); + // XXX Maybe we want to cancel script loads if NS_FAILED(rv)? + if (NS_FAILED(aResult)) { - if (css::Loader* cssLoader = mDocument->GetCSSLoader()) { - cssLoader->Stop(); - } + mDocument->CSSLoader()->Stop(); } } diff --git a/editor/libeditor/gtest/TestHTMLEditUtils.cpp b/editor/libeditor/gtest/TestHTMLEditUtils.cpp @@ -39,8 +39,8 @@ static already_AddRefed<Document> CreateHTMLDoc() { u""_ns, // aQualifiedName nullptr, // aDoctype uri, uri, principal, - LoadedAsData::No, // aLoadedAsData - nullptr, // aEventObject + false, // aLoadedAsData + nullptr, // aEventObject DocumentFlavor::HTML)); MOZ_RELEASE_ASSERT(doc); diff --git a/gfx/thebes/gfxSVGGlyphs.cpp b/gfx/thebes/gfxSVGGlyphs.cpp @@ -372,8 +372,8 @@ nsresult gfxSVGGlyphsDocument::ParseDocument(const uint8_t* aBuffer, u""_ns, // aQualifiedName nullptr, // aDoctype uri, uri, principal, - mozilla::dom::LoadedAsData::No, // aLoadedAsData - nullptr, // aEventObject + false, // aLoadedAsData + nullptr, // aEventObject DocumentFlavor::SVG); NS_ENSURE_SUCCESS(rv, rv); diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp @@ -2220,9 +2220,7 @@ void PresShell::SetIgnoreFrameDestruction(bool aIgnore) { if (mDocument) { // We need to tell the ImageLoader to drop all its references to frames // because they're about to go away and it won't get notifications of that. - if (css::ImageLoader* loader = mDocument->GetStyleImageLoader()) { - loader->ClearFrames(mPresContext); - } + mDocument->StyleImageLoader()->ClearFrames(mPresContext); } mIgnoreFrameDestruction = aIgnore; } @@ -2235,9 +2233,7 @@ void PresShell::NotifyDestroyingFrame(nsIFrame* aFrame) { if (!mIgnoreFrameDestruction) { if (aFrame->HasImageRequest()) { - if (css::ImageLoader* loader = mDocument->GetStyleImageLoader()) { - loader->DropRequestsForFrame(aFrame); - } + mDocument->StyleImageLoader()->DropRequestsForFrame(aFrame); } mFrameConstructor->NotifyDestroyingFrame(aFrame); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp @@ -1347,9 +1347,7 @@ void nsPresContext::SetImageAnimationMode(uint16_t aMode) { if (mPresShell) { dom::Document* doc = mPresShell->GetDocument(); if (doc) { - if (css::ImageLoader* loader = doc->GetStyleImageLoader()) { - loader->SetAnimationMode(aMode); - } + doc->StyleImageLoader()->SetAnimationMode(aMode); Element* rootElement = doc->GetRootElement(); if (rootElement) { diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp @@ -1025,10 +1025,9 @@ static void CompareLayers( } static void AddAndRemoveImageAssociations( - ImageLoader* aImageLoader, nsIFrame* aFrame, + ImageLoader& aImageLoader, nsIFrame* aFrame, const nsStyleImageLayers* aOldLayers, const nsStyleImageLayers* aNewLayers) { - MOZ_ASSERT(aImageLoader); // If the old context had a background-image image, or mask-image image, // and new context does not have the same image, clear the image load // notifier (which keeps the image loading, if it still is) for the frame. @@ -1039,12 +1038,12 @@ static void AddAndRemoveImageAssociations( // interval.) if (aOldLayers && aFrame->HasImageRequest()) { CompareLayers(aOldLayers, aNewLayers, [&](imgRequestProxy* aReq) { - aImageLoader->DisassociateRequestFromFrame(aReq, aFrame); + aImageLoader.DisassociateRequestFromFrame(aReq, aFrame); }); } CompareLayers(aNewLayers, aOldLayers, [&](imgRequestProxy* aReq) { - aImageLoader->AssociateRequestToFrame(aReq, aFrame); + aImageLoader.AssociateRequestToFrame(aReq, aFrame); }); } @@ -1241,7 +1240,7 @@ void nsIFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) { MaybeScheduleReflowSVGNonDisplayText(this); Document* doc = PresContext()->Document(); - ImageLoader* loader = doc->GetStyleImageLoader(); + ImageLoader* loader = doc->StyleImageLoader(); // Continuing text frame doesn't initialize its continuation pointer before // reaching here for the first time, so we have to exclude text frames. This // doesn't affect correctness because text can't match selectors. @@ -1266,12 +1265,12 @@ void nsIFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) { aOldComputedStyle ? &aOldComputedStyle->StyleBackground()->mImage : nullptr; const nsStyleImageLayers* newLayers = &StyleBackground()->mImage; - AddAndRemoveImageAssociations(loader, this, oldLayers, newLayers); + AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers); oldLayers = aOldComputedStyle ? &aOldComputedStyle->StyleSVGReset()->mMask : nullptr; newLayers = &StyleSVGReset()->mMask; - AddAndRemoveImageAssociations(loader, this, oldLayers, newLayers); + AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers); const nsStyleDisplay* disp = StyleDisplay(); bool handleStickyChange = false; @@ -6133,10 +6132,7 @@ bool nsIFrame::AssociateImage(const StyleImage& aImage) { } mozilla::css::ImageLoader* loader = - PresContext()->Document()->GetStyleImageLoader(); - if (!loader) { - return false; - } + PresContext()->Document()->StyleImageLoader(); loader->AssociateRequestToFrame(req, this); return true; @@ -6149,10 +6145,7 @@ void nsIFrame::DisassociateImage(const StyleImage& aImage) { } mozilla::css::ImageLoader* loader = - PresContext()->Document()->GetStyleImageLoader(); - if (!loader) { - return; - } + PresContext()->Document()->StyleImageLoader(); loader->DisassociateRequestFromFrame(req, this); } diff --git a/layout/style/FontFaceSetDocumentImpl.cpp b/layout/style/FontFaceSetDocumentImpl.cpp @@ -82,9 +82,7 @@ void FontFaceSetDocumentImpl::Initialize() { CheckLoadingFinished(); } - if (mDocument->GetCSSLoader()) { - mDocument->GetCSSLoader()->AddObserver(this); - } + mDocument->CSSLoader()->AddObserver(this); mStandardFontLoadPrincipal = MakeRefPtr<gfxFontSrcPrincipal>( mDocument->NodePrincipal(), mDocument->PartitionedPrincipal()); @@ -93,11 +91,11 @@ void FontFaceSetDocumentImpl::Initialize() { void FontFaceSetDocumentImpl::Destroy() { RemoveDOMContentLoadedListener(); - if (mDocument && mDocument->GetCSSLoader()) { + if (mDocument && mDocument->CSSLoader()) { // We're null checking CSSLoader() since FontFaceSetImpl::Disconnect() might // be being called during unlink, at which time the loader may already have // been unlinked from the document. - mDocument->GetCSSLoader()->RemoveObserver(this); + mDocument->CSSLoader()->RemoveObserver(this); } mRuleFaces.Clear(); @@ -714,8 +712,7 @@ bool FontFaceSetDocumentImpl::MightHavePendingFontLoads() { // And we also wait for any CSS style sheets to finish loading, as their // styles might cause new fonts to load. - if (mDocument->GetCSSLoader() && - mDocument->GetCSSLoader()->HasPendingLoads()) { + if (mDocument->CSSLoader()->HasPendingLoads()) { return true; } diff --git a/layout/style/ServoCSSParser.cpp b/layout/style/ServoCSSParser.cpp @@ -107,5 +107,5 @@ already_AddRefed<URLExtraData> ServoCSSParser::GetURLExtraData( /* static */ ServoCSSParser::ParsingEnvironment ServoCSSParser::GetParsingEnvironment(Document* aDocument) { return {GetURLExtraData(aDocument), aDocument->GetCompatibilityMode(), - aDocument->GetCSSLoader()}; + aDocument->CSSLoader()}; } diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp @@ -210,7 +210,7 @@ nsresult ServoCSSRuleList::InsertRule(const nsACString& aRule, // StyleSheet::ReparseSheet just mints a new loader, but that'd be wrong in // this case I think, since such a load will bypass CSP checks. if (Document* doc = mStyleSheet->GetAssociatedDocument()) { - loader = doc->GetCSSLoader(); + loader = doc->CSSLoader(); } auto containingState = css::Rule::ContainingRuleState::From(mParentRule); StyleCssRuleType type; diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp @@ -677,18 +677,12 @@ already_AddRefed<dom::Promise> StyleSheet::Replace(const nsACString& aText, return promise.forget(); } - if (!mConstructorDocument || !mConstructorDocument->GetCSSLoader()) { - promise->MaybeRejectWithNotAllowedError( - "Must not use this on documents loaded as data."); - return promise.forget(); - } - // 3. Disallow modifications until finished. SetModificationDisallowed(true); // TODO(emilio, 1642227): Should constructable stylesheets notify global // observers (i.e., set mMustNotify to true)? - auto* loader = mConstructorDocument->GetCSSLoader(); + auto* loader = mConstructorDocument->CSSLoader(); auto loadData = MakeRefPtr<css::SheetLoadData>( loader, /* aURI = */ nullptr, this, css::SyncLoad::No, css::Loader::UseSystemPrincipal::No, css::StylePreloadKind::None, @@ -731,14 +725,9 @@ void StyleSheet::ReplaceSync(const nsACString& aText, ErrorResult& aRv) { "Can only be called on modifiable style sheets"); } - if (!mConstructorDocument->GetCSSLoader()) { - return aRv.ThrowNotAllowedError( - "Must not use this on documents loaded as data"); - } - // 3. Parse aText into rules. // 4. If rules contain @imports, skip them and continue parsing. - auto* loader = mConstructorDocument->GetCSSLoader(); + auto* loader = mConstructorDocument->CSSLoader(); RefPtr<const StyleStylesheetContents> rawContent = Servo_StyleSheet_FromUTF8Bytes( loader, this, @@ -1350,12 +1339,9 @@ void StyleSheet::ReparseSheet(const nsACString& aInput, ErrorResult& aRv) { // kills the document RefPtr<css::Loader> loader; if (Document* doc = GetAssociatedDocument()) { - loader = doc->GetCSSLoader(); - MOZ_ASSERT(loader, - "Should not come here without a CSS loader, i.e. in the " - "loadedAsData case"); - } - if (!loader) { + loader = doc->CSSLoader(); + NS_ASSERTION(loader, "Document with no CSS loader!"); + } else { loader = new css::Loader; } diff --git a/layout/style/nsDOMCSSAttrDeclaration.cpp b/layout/style/nsDOMCSSAttrDeclaration.cpp @@ -133,7 +133,7 @@ nsDOMCSSAttributeDeclaration::GetParsingEnvironment( return { mElement->GetURLDataForStyleAttr(aSubjectPrincipal), mElement->OwnerDoc()->GetCompatibilityMode(), - mElement->OwnerDoc()->GetCSSLoader(), + mElement->OwnerDoc()->CSSLoader(), }; } diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp @@ -217,7 +217,7 @@ nsDOMCSSDeclaration::GetParsingEnvironmentForRule(const css::Rule* aRule, return { sheet->URLData(), document->GetCompatibilityMode(), - document->GetCSSLoader(), + document->CSSLoader(), aRuleType, }; } diff --git a/layout/svg/SVGObserverUtils.cpp b/layout/svg/SVGObserverUtils.cpp @@ -1114,9 +1114,7 @@ void SVGMaskObserverList::ResolveImage(uint32_t aIndex) { const_cast<StyleImage&>(image).ResolveImage(*doc, nullptr); if (imgRequestProxy* req = image.GetImageRequest()) { // FIXME(emilio): What disassociates this request? - if (css::ImageLoader* loader = doc->GetStyleImageLoader()) { - loader->AssociateRequestToFrame(req, mFrame); - } + doc->StyleImageLoader()->AssociateRequestToFrame(req, mFrame); } } diff --git a/netwerk/test/gtest/TestCookie.cpp b/netwerk/test/gtest/TestCookie.cpp @@ -126,15 +126,14 @@ void GetACookieNoHttp(nsICookieService* aCookieService, const char* aSpec, MOZ_RELEASE_ASSERT(principal); nsCOMPtr<mozilla::dom::Document> document; - nsresult rv = - NS_NewDOMDocument(getter_AddRefs(document), - u""_ns, // aNamespaceURI - u""_ns, // aQualifiedName - nullptr, // aDoctype - uri, uri, principal, - mozilla::dom::LoadedAsData::No, // aLoadedAsData - nullptr, // aEventObject - DocumentFlavor::HTML); + nsresult rv = NS_NewDOMDocument(getter_AddRefs(document), + u""_ns, // aNamespaceURI + u""_ns, // aQualifiedName + nullptr, // aDoctype + uri, uri, principal, + false, // aLoadedAsData + nullptr, // aEventObject + DocumentFlavor::HTML); Unused << NS_WARN_IF(NS_FAILED(rv)); nsAutoString cookie; diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -1187,10 +1187,6 @@ void nsHtml5TreeOpExecutor::PreloadScript( const nsAString& aNonce, const nsAString& aFetchPriority, const nsAString& aIntegrity, dom::ReferrerPolicy aReferrerPolicy, bool aScriptFromHead, bool aAsync, bool aDefer, bool aLinkPreload) { - dom::ScriptLoader* loader = mDocument->GetScriptLoader(); - if (!loader) { - return; - } nsCOMPtr<nsIURI> uri = ConvertIfNotPreloadedYetAndMediaApplies(aURL, aMedia); if (!uri) { return; @@ -1199,9 +1195,10 @@ void nsHtml5TreeOpExecutor::PreloadScript( if (mDocument->Preloads().PreloadExists(key)) { return; } - loader->PreloadURI(uri, aCharset, aType, aCrossOrigin, aNonce, aFetchPriority, - aIntegrity, aScriptFromHead, aAsync, aDefer, aLinkPreload, - GetPreloadReferrerPolicy(aReferrerPolicy), 0); + mDocument->ScriptLoader()->PreloadURI( + uri, aCharset, aType, aCrossOrigin, aNonce, aFetchPriority, aIntegrity, + aScriptFromHead, aAsync, aDefer, aLinkPreload, + GetPreloadReferrerPolicy(aReferrerPolicy), 0); } void nsHtml5TreeOpExecutor::PreloadStyle( diff --git a/parser/html/nsParserUtils.cpp b/parser/html/nsParserUtils.cpp @@ -92,14 +92,11 @@ nsParserUtils::ParseFragment(const nsAString& aFragment, uint32_t aFlags, nsAutoScriptBlockerSuppressNodeRemoved autoBlocker; - bool scripts_enabled = false; // stop scripts - RefPtr<ScriptLoader> loader = document->GetScriptLoader(); - if (loader) { - scripts_enabled = loader->GetEnabled(); - if (scripts_enabled) { - loader->SetEnabled(false); - } + RefPtr<ScriptLoader> loader = document->ScriptLoader(); + bool scripts_enabled = loader->GetEnabled(); + if (scripts_enabled) { + loader->SetEnabled(false); } // Wrap things in a div or body for parsing, but it won't show up in diff --git a/uriloader/preload/PreloadService.cpp b/uriloader/preload/PreloadService.cpp @@ -259,12 +259,10 @@ void PreloadService::PreloadScript( const nsAString& aNonce, const nsAString& aFetchPriority, const nsAString& aIntegrity, bool aScriptFromHead, uint64_t aEarlyHintPreloaderId) { - if (ScriptLoader* scriptLoader = mDocument->GetScriptLoader()) { - scriptLoader->PreloadURI( - aURI, aCharset, aType, aCrossOrigin, aNonce, aFetchPriority, aIntegrity, - aScriptFromHead, false, false, true, - PreloadReferrerPolicy(aReferrerPolicy), aEarlyHintPreloaderId); - } + mDocument->ScriptLoader()->PreloadURI( + aURI, aCharset, aType, aCrossOrigin, aNonce, aFetchPriority, aIntegrity, + aScriptFromHead, false, false, true, + PreloadReferrerPolicy(aReferrerPolicy), aEarlyHintPreloaderId); } void PreloadService::PreloadImage(nsIURI* aURI, const nsAString& aCrossOrigin,