From 7d314b5011ad2f3631d775d5d6a2eef70a8565cf Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 9 Aug 2018 11:56:45 -0400 Subject: [PATCH] Bug 1482129 - Exempt stylesheets, fonts and images when canceling loading of slow HTTP requests of tracking resources; r=valentin --- dom/base/nsIContentPolicy.idl | 9 ++++---- netwerk/protocol/http/nsHttpChannel.cpp | 29 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/dom/base/nsIContentPolicy.idl b/dom/base/nsIContentPolicy.idl index eddc89f64a91..511b7d010c97 100644 --- a/dom/base/nsIContentPolicy.idl +++ b/dom/base/nsIContentPolicy.idl @@ -348,10 +348,11 @@ interface nsIContentPolicy : nsISupports /* When adding new content types, please update nsContentBlocker, * NS_CP_ContentTypeName, nsCSPContext, CSP_ContentTypeToDirective, - * DoContentSecurityChecks, all nsIContentPolicy implementations, the - * static_assert in dom/cache/DBSchema.cpp, ChannelWrapper.webidl, - * ChannelWrapper.cpp, nsPermissionManager.cpp, and other things that are not - * listed here that are related to nsIContentPolicy. */ + * DoContentSecurityChecks, IsContentPolicyTypeWhitelistedForFastBlock, + * all nsIContentPolicy implementations, the static_assert in + * dom/cache/DBSchema.cpp, ChannelWrapper.webidl, ChannelWrapper.cpp, + * nsPermissionManager.cpp, and other things that are not listed here + * that are related to nsIContentPolicy. */ ////////////////////////////////////////////////////////////////////// diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 95527eb38312..14d2efcc69a7 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -596,6 +596,31 @@ nsHttpChannel::Connect() return ConnectOnTailUnblock(); } +static bool +IsContentPolicyTypeWhitelistedForFastBlock(nsILoadInfo* aLoadInfo) +{ + nsContentPolicyType type = aLoadInfo ? + aLoadInfo->GetExternalContentPolicyType() : + nsIContentPolicy::TYPE_OTHER; + switch (type) { + // images + case nsIContentPolicy::TYPE_IMAGE: + case nsIContentPolicy::TYPE_IMAGESET: + case nsIContentPolicy::TYPE_INTERNAL_IMAGE: + case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD: + case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON: + // fonts + case nsIContentPolicy::TYPE_FONT: + // stylesheets + case nsIContentPolicy::TYPE_STYLESHEET: + case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET: + case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD: + return true; + default: + return false; + } +} + bool nsHttpChannel::CheckFastBlocked() { @@ -616,7 +641,9 @@ nsHttpChannel::CheckFastBlocked() return false; } - if (!sIsFastBlockEnabled || !timestamp) { + if (!sIsFastBlockEnabled || + IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo) || + !timestamp) { return false; }