diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index d86d3fb1a3..da3207e9c9 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -295,6 +295,7 @@ bool nsContentUtils::sGettersDecodeURLHash = false; bool nsContentUtils::sPrivacyResistFingerprinting = false; bool nsContentUtils::sSendPerformanceTimingNotifications = false; bool nsContentUtils::sUseActivityCursor = false; +bool nsContentUtils::sPreloadEnabled = true; uint32_t nsContentUtils::sHandlingInputTimeout = 1000; @@ -633,6 +634,9 @@ nsContentUtils::Init() Preferences::AddBoolVarCache(&sUseActivityCursor, "ui.use_activity_cursor", false); + Preferences::AddBoolVarCache(&sPreloadEnabled, + "network.preload", true); + Element::InitCCCallbacks(); nsCOMPtr uuidGenerator = @@ -4125,6 +4129,10 @@ void nsContentUtils::DispatchEventForPreloadURI(nsIDOMNode* aNode, nsContentPolicyType& aPolicyType) { + if (!IsPreloadEnabled()) { + return; + } + nsCOMPtr domNode = do_QueryInterface(aNode); if (domNode && domNode->IsInComposedDoc()) { bool success = aPolicyType != nsIContentPolicy::TYPE_INVALID; @@ -7396,6 +7404,12 @@ nsContentUtils::GPCEnabled() return nsContentUtils::sGPCEnabled; } +bool +nsContentUtils::IsPreloadEnabled() +{ + return nsContentUtils::sPreloadEnabled; +} + mozilla::LogModule* nsContentUtils::DOMDumpLog() { diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 0073c4953f..3d5476d7aa 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2149,6 +2149,11 @@ public: return sUseActivityCursor; } + /** + * Returns true if the preload service is enabled. + */ + static bool IsPreloadEnabled(); + /** * Return true if this doc is controlled by a ServiceWorker. */ @@ -2969,6 +2974,7 @@ private: static bool sPrivacyResistFingerprinting; static bool sSendPerformanceTimingNotifications; static bool sUseActivityCursor; + static bool sPreloadEnabled; static uint32_t sCookiesLifetimePolicy; static uint32_t sCookiesBehavior; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index fef4c449cd..dfa0fd0caa 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1906,6 +1906,9 @@ pref("network.ftp.idleConnectionTimeout", 300); // all other values are treated like 2 pref("network.dir.format", 2); +// enables the preload service (i.e., preloading of URLs). +pref("network.preload", true); + // enables the prefetch service (i.e., prefetching of URLs). pref("network.prefetch-next", true); diff --git a/parser/html/nsHtml5TreeBuilderCppSupplement.h b/parser/html/nsHtml5TreeBuilderCppSupplement.h index 8e1cbe8f9a..a3a7e92155 100644 --- a/parser/html/nsHtml5TreeBuilderCppSupplement.h +++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h @@ -230,7 +230,7 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace, mSpeculativeLoadQueue.AppendElement()->InitPreconnect( url, crossOrigin); } - } else if (rel.LowerCaseEqualsASCII("preload")) { + } else if (rel.LowerCaseEqualsASCII("preload") && nsContentUtils::IsPreloadEnabled()) { nsHtml5String url = aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF); if (url) {