Issue #2158 - Part 5: Guard preload links support with a preference

This is enabled by default.
This commit is contained in:
FranklinDM 2024-01-27 12:02:10 +08:00 • committed by roytam1
commit 6c53117699
4 changed files with 24 additions and 1 deletions

View file

@ -295,6 +295,7 @@ bool nsContentUtils::sGettersDecodeURLHash = false;
bool nsContentUtils::sPrivacyResistFingerprinting = false; bool nsContentUtils::sPrivacyResistFingerprinting = false;
bool nsContentUtils::sSendPerformanceTimingNotifications = false; bool nsContentUtils::sSendPerformanceTimingNotifications = false;
bool nsContentUtils::sUseActivityCursor = false; bool nsContentUtils::sUseActivityCursor = false;
bool nsContentUtils::sPreloadEnabled = true;
uint32_t nsContentUtils::sHandlingInputTimeout = 1000; uint32_t nsContentUtils::sHandlingInputTimeout = 1000;
@ -633,6 +634,9 @@ nsContentUtils::Init()
Preferences::AddBoolVarCache(&sUseActivityCursor, Preferences::AddBoolVarCache(&sUseActivityCursor,
"ui.use_activity_cursor", false); "ui.use_activity_cursor", false);
Preferences::AddBoolVarCache(&sPreloadEnabled,
"network.preload", true);
Element::InitCCCallbacks(); Element::InitCCCallbacks();
nsCOMPtr<nsIUUIDGenerator> uuidGenerator = nsCOMPtr<nsIUUIDGenerator> uuidGenerator =
@ -4125,6 +4129,10 @@ void
nsContentUtils::DispatchEventForPreloadURI(nsIDOMNode* aNode, nsContentUtils::DispatchEventForPreloadURI(nsIDOMNode* aNode,
nsContentPolicyType& aPolicyType) nsContentPolicyType& aPolicyType)
{ {
if (!IsPreloadEnabled()) {
return;
}
nsCOMPtr<nsINode> domNode = do_QueryInterface(aNode); nsCOMPtr<nsINode> domNode = do_QueryInterface(aNode);
if (domNode && domNode->IsInComposedDoc()) { if (domNode && domNode->IsInComposedDoc()) {
bool success = aPolicyType != nsIContentPolicy::TYPE_INVALID; bool success = aPolicyType != nsIContentPolicy::TYPE_INVALID;
@ -7396,6 +7404,12 @@ nsContentUtils::GPCEnabled()
return nsContentUtils::sGPCEnabled; return nsContentUtils::sGPCEnabled;
} }
bool
nsContentUtils::IsPreloadEnabled()
{
return nsContentUtils::sPreloadEnabled;
}
mozilla::LogModule* mozilla::LogModule*
nsContentUtils::DOMDumpLog() nsContentUtils::DOMDumpLog()
{ {

View file

@ -2149,6 +2149,11 @@ public:
return sUseActivityCursor; return sUseActivityCursor;
} }
/**
* Returns true if the preload service is enabled.
*/
static bool IsPreloadEnabled();
/** /**
* Return true if this doc is controlled by a ServiceWorker. * Return true if this doc is controlled by a ServiceWorker.
*/ */
@ -2969,6 +2974,7 @@ private:
static bool sPrivacyResistFingerprinting; static bool sPrivacyResistFingerprinting;
static bool sSendPerformanceTimingNotifications; static bool sSendPerformanceTimingNotifications;
static bool sUseActivityCursor; static bool sUseActivityCursor;
static bool sPreloadEnabled;
static uint32_t sCookiesLifetimePolicy; static uint32_t sCookiesLifetimePolicy;
static uint32_t sCookiesBehavior; static uint32_t sCookiesBehavior;

View file

@ -1906,6 +1906,9 @@ pref("network.ftp.idleConnectionTimeout", 300);
// all other values are treated like 2 // all other values are treated like 2
pref("network.dir.format", 2); pref("network.dir.format", 2);
// enables the preload service (i.e., preloading of <link rel="preload"> URLs).
pref("network.preload", true);
// enables the prefetch service (i.e., prefetching of <link rel="next"> URLs). // enables the prefetch service (i.e., prefetching of <link rel="next"> URLs).
pref("network.prefetch-next", true); pref("network.prefetch-next", true);

View file

@ -230,7 +230,7 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace,
mSpeculativeLoadQueue.AppendElement()->InitPreconnect( mSpeculativeLoadQueue.AppendElement()->InitPreconnect(
url, crossOrigin); url, crossOrigin);
} }
} else if (rel.LowerCaseEqualsASCII("preload")) { } else if (rel.LowerCaseEqualsASCII("preload") && nsContentUtils::IsPreloadEnabled()) {
nsHtml5String url = nsHtml5String url =
aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF); aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
if (url) { if (url) {