Bug 1482129 - Exempt stylesheets, fonts and images when canceling loading of slow HTTP requests of tracking resources; r=valentin
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 09 Aug 2018 11:56:45 -0400
changeset 430891 258ab6ac738176bf18f81ceab2f4d931c5575653
parent 430890 97ab168799b94f4a8bd6ad002ef9917fa33ad779
child 430892 b5a9f0882836c16bf2fbc7f2eab60f9f143f65f2
push id34415
push userebalazs@mozilla.com
push dateFri, 10 Aug 2018 09:17:55 +0000
treeherdermozilla-central@d999fb858fb2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1482129
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482129 - Exempt stylesheets, fonts and images when canceling loading of slow HTTP requests of tracking resources; r=valentin
dom/base/nsIContentPolicy.idl
netwerk/protocol/http/nsHttpChannel.cpp
--- a/dom/base/nsIContentPolicy.idl
+++ b/dom/base/nsIContentPolicy.idl
@@ -343,20 +343,21 @@ interface nsIContentPolicy : nsISupports
 
   /**
    * Indicates a speculative connection.
    */
   const nsContentPolicyType TYPE_SPECULATIVE = 44;
 
   /* 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. */
 
   //////////////////////////////////////////////////////////////////////
 
   /**
    * Returned from shouldLoad or shouldProcess if the load or process request
    * is rejected based on details of the request.
    */
   const short REJECT_REQUEST = -1;
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -591,16 +591,41 @@ nsHttpChannel::Connect()
         MOZ_DIAGNOSTIC_ASSERT(!mOnTailUnblock);
         mOnTailUnblock = &nsHttpChannel::ConnectOnTailUnblock;
         return NS_OK;
     }
 
     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()
 {
     LOG(("nsHttpChannel::CheckFastBlocked [this=%p]\n", this));
 
     static bool sFastBlockInited = false;
     static bool sIsFastBlockEnabled = false;
     static uint32_t sFastBlockTimeout = 0;
@@ -611,17 +636,19 @@ nsHttpChannel::CheckFastBlocked()
         Preferences::AddUintVarCache(&sFastBlockTimeout, "browser.fastblock.timeout");
     }
 
     TimeStamp timestamp;
     if (NS_FAILED(GetNavigationStartTimeStamp(&timestamp))) {
         return false;
     }
 
-    if (!sIsFastBlockEnabled || !timestamp) {
+    if (!sIsFastBlockEnabled ||
+        IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo) ||
+        !timestamp) {
         return false;
     }
 
     TimeDuration duration = TimeStamp::NowLoRes() - timestamp;
     if (duration.ToMilliseconds() < sFastBlockTimeout) {
         return false;
     }