Bug 1395525 - Make all changes landed as part of tracker request tailing preferrable. r=dragana
authorHonza Bambas <honzab.moz@firemni.cz>
Thu, 31 Aug 2017 06:07:00 -0400
changeset 430090 e4fcf1fd4e54edb02b6320dbd22f938fcdaf8198
parent 430089 fcd75aec9410c44c10d903eb8fb061da73d64599
child 430091 873139ecdbd2334ef99a9a30f6ba780628355bb3
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1395525
milestone57.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 1395525 - Make all changes landed as part of tracker request tailing preferrable. r=dragana
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/fetch/FetchDriver.cpp
dom/script/ScriptLoader.cpp
dom/xhr/XMLHttpRequestMainThread.cpp
netwerk/base/nsChannelClassifier.cpp
netwerk/protocol/http/nsHttpChannel.cpp
toolkit/components/places/FaviconHelpers.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -299,16 +299,17 @@ bool nsContentUtils::sDevToolsEnabled = 
 bool nsContentUtils::sSendPerformanceTimingNotifications = false;
 bool nsContentUtils::sUseActivityCursor = false;
 bool nsContentUtils::sAnimationsAPICoreEnabled = false;
 bool nsContentUtils::sAnimationsAPIElementAnimateEnabled = false;
 bool nsContentUtils::sGetBoxQuadsEnabled = false;
 bool nsContentUtils::sSkipCursorMoveForSameValueSet = false;
 bool nsContentUtils::sRequestIdleCallbackEnabled = false;
 bool nsContentUtils::sLowerNetworkPriority = false;
+bool nsContentUtils::sTailingEnabled = false;
 bool nsContentUtils::sShowInputPlaceholderOnFocus = true;
 bool nsContentUtils::sAutoFocusEnabled = true;
 #ifndef RELEASE_OR_BETA
 bool nsContentUtils::sBypassCSSOMOriginCheck = false;
 #endif
 bool nsContentUtils::sIsScopedStyleEnabled = false;
 
 bool nsContentUtils::sIsBytecodeCacheEnabled = false;
@@ -763,16 +764,19 @@ nsContentUtils::Init()
 #endif
 
   Preferences::AddBoolVarCache(&sIsScopedStyleEnabled,
                                "layout.css.scoped-style.enabled", false);
 
   Preferences::AddBoolVarCache(&sLowerNetworkPriority,
                                "privacy.trackingprotection.lower_network_priority", false);
 
+  Preferences::AddBoolVarCache(&sTailingEnabled,
+                               "network.http.tailing.enabled", true);
+
   Preferences::AddBoolVarCache(&sShowInputPlaceholderOnFocus,
                                "dom.placeholder.show_on_focus", true);
 
   Preferences::AddBoolVarCache(&sAutoFocusEnabled,
                                "browser.autofocus", true);
 
   Preferences::AddBoolVarCache(&sIsBytecodeCacheEnabled,
                                "dom.script_loader.bytecode_cache.enabled", false);
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3088,16 +3088,19 @@ public:
    */
   static bool
   GetUserIsInteracting();
 
   // Check pref "privacy.trackingprotection.lower_network_priority" to see
   // if we want to lower the priority of the channel.
   static bool IsLowerNetworkPriority() { return sLowerNetworkPriority; }
 
+  // Whether tracker tailing is turned on - "network.http.tailing.enabled".
+  static bool IsTailingEnabled() { return sTailingEnabled; }
+
   // Check pref "dom.placeholder.show_on_focus" to see
   // if we want to show the placeholder inside input elements
   // when they have focus.
   static bool ShowInputPlaceholderOnFocus() { return sShowInputPlaceholderOnFocus; }
 
   // Check pref "browser.autofocus" to see if we want to enable autofocusing elements
   // when the page requests it.
   static bool AutoFocusEnabled() { return sAutoFocusEnabled; }
@@ -3279,16 +3282,17 @@ private:
   static bool sSendPerformanceTimingNotifications;
   static bool sUseActivityCursor;
   static bool sAnimationsAPICoreEnabled;
   static bool sAnimationsAPIElementAnimateEnabled;
   static bool sGetBoxQuadsEnabled;
   static bool sSkipCursorMoveForSameValueSet;
   static bool sRequestIdleCallbackEnabled;
   static bool sLowerNetworkPriority;
+  static bool sTailingEnabled;
   static bool sShowInputPlaceholderOnFocus;
   static bool sAutoFocusEnabled;
 #ifndef RELEASE_OR_BETA
   static bool sBypassCSSOMOriginCheck;
 #endif
   static bool sIsScopedStyleEnabled;
   static bool sIsBytecodeCacheEnabled;
   static int32_t sBytecodeCacheStrategy;
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -373,20 +373,22 @@ FetchDriver::HttpFetch()
     AutoTArray<nsCString, 5> unsafeHeaders;
     mRequest->Headers()->GetUnsafeHeaders(unsafeHeaders);
     nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
     if (loadInfo) {
       loadInfo->SetCorsPreflightInfo(unsafeHeaders, false);
     }
   }
 
-  if (mIsTrackingFetch && nsContentUtils::IsLowerNetworkPriority()) {
+  if (mIsTrackingFetch && nsContentUtils::IsTailingEnabled()) {
     cos->AddClassFlags(nsIClassOfService::Throttleable |
                        nsIClassOfService::Tail);
+  }
 
+  if (mIsTrackingFetch && nsContentUtils::IsLowerNetworkPriority()) {
     nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(chan);
     if (p) {
       p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
     }
   }
 
   rv = chan->AsyncOpen2(this);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -1062,17 +1062,22 @@ ScriptLoader::StartLoad(ScriptLoadReques
        aRequest, async, defer, aRequest->IsTracking()));
 
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
   if (cos) {
     if (aRequest->mScriptFromHead && !async && !defer) {
       // synchronous head scripts block loading of most other non js/css
       // content such as images, Leader implicitely disallows tailing
       cos->AddClassFlags(nsIClassOfService::Leader);
-    } else if (defer && !async) {
+    } else if (defer && (!async || !nsContentUtils::IsTailingEnabled())) {
+      // Bug 1395525 and the !nsContentUtils::IsTailingEnabled() bit:
+      // We want to make sure that turing tailing off by the pref makes
+      // the browser behave exactly the same way as before landing
+      // the tailing patch, which has added the "&& !async" part.
+
       // head/body deferred scripts are blocked by leaders but are not
       // allowed tailing because they block DOMContentLoaded
       cos->AddClassFlags(nsIClassOfService::TailForbidden);
     } else {
       // other scripts (=body sync or head/body async) are neither blocked
       // nor prioritized
       cos->AddClassFlags(nsIClassOfService::Unblocked);
 
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -2616,23 +2616,25 @@ XMLHttpRequestMainThread::MaybeLowerChan
   if (!nsJSUtils::GetCallingLocation(cx, fileNameString)) {
     return;
   }
 
   if (!doc->IsScriptTracking(fileNameString)) {
     return;
   }
 
-  nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(mChannel);
-  if (cos) {
-    // Adding TailAllowed to overrule the Unblocked flag, but to preserve
-    // the effect of Unblocked when tailing is off.
-    cos->AddClassFlags(nsIClassOfService::Throttleable |
-                       nsIClassOfService::Tail |
-                       nsIClassOfService::TailAllowed);
+  if (nsContentUtils::IsTailingEnabled()) {
+    nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(mChannel);
+    if (cos) {
+      // Adding TailAllowed to overrule the Unblocked flag, but to preserve
+      // the effect of Unblocked when tailing is off.
+      cos->AddClassFlags(nsIClassOfService::Throttleable |
+                         nsIClassOfService::Tail |
+                         nsIClassOfService::TailAllowed);
+    }
   }
 
   nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);
   if (p) {
     p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
   }
 }
 
--- a/netwerk/base/nsChannelClassifier.cpp
+++ b/netwerk/base/nsChannelClassifier.cpp
@@ -205,26 +205,33 @@ static void
 LowerPriorityHelper(nsIChannel* aChannel)
 {
   MOZ_ASSERT(aChannel);
 
   bool isBlockingResource = false;
 
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(aChannel));
   if (cos) {
-    uint32_t cosFlags = 0;
-    cos->GetClassFlags(&cosFlags);
-    isBlockingResource = cosFlags & (nsIClassOfService::UrgentStart |
-                                     nsIClassOfService::Leader |
-                                     nsIClassOfService::Unblocked);
+    if (nsContentUtils::IsTailingEnabled()) {
+      uint32_t cosFlags = 0;
+      cos->GetClassFlags(&cosFlags);
+      isBlockingResource = cosFlags & (nsIClassOfService::UrgentStart |
+                                       nsIClassOfService::Leader |
+                                       nsIClassOfService::Unblocked);
 
-    // Requests not allowed to be tailed are usually those with higher
-    // prioritization.  That overweights being a tracker: don't throttle
-    // them when not in background.
-    if (!(cosFlags & nsIClassOfService::TailForbidden)) {
+      // Requests not allowed to be tailed are usually those with higher
+      // prioritization.  That overweights being a tracker: don't throttle
+      // them when not in background.
+      if (!(cosFlags & nsIClassOfService::TailForbidden)) {
+        cos->AddClassFlags(nsIClassOfService::Throttleable);
+      }
+    } else {
+      // Yes, we even don't want to evaluate the isBlockingResource when tailing is off
+      // see bug 1395525.
+
       cos->AddClassFlags(nsIClassOfService::Throttleable);
     }
   }
 
   if (!isBlockingResource) {
     nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(aChannel);
     if (p) {
       p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -7571,17 +7571,16 @@ nsHttpChannel::OnStopRequest(nsIRequest 
     if (mListener) {
         LOG(("nsHttpChannel %p calling OnStopRequest\n", this));
         MOZ_ASSERT(mOnStartRequestCalled,
                    "OnStartRequest should be called before OnStopRequest");
         MOZ_ASSERT(!mOnStopRequestCalled,
                    "We should not call OnStopRequest twice");
         mListener->OnStopRequest(this, mListenerContext, status);
         mOnStopRequestCalled = true;
-
     }
 
     RemoveAsNonTailRequest();
 
     // If a preferred alt-data type was set, this signals the consumer is
     // interested in reading and/or writing the alt-data representation.
     // We need to hold a reference to the cache entry in case the listener calls
     // openAlternativeOutputStream() after CloseCacheEntry() clears mCacheEntry.
--- a/toolkit/components/places/FaviconHelpers.cpp
+++ b/toolkit/components/places/FaviconHelpers.cpp
@@ -589,20 +589,22 @@ AsyncFetchAndSetIconForPage::FetchFromNe
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsISupportsPriority> priorityChannel = do_QueryInterface(channel);
   if (priorityChannel) {
     priorityChannel->AdjustPriority(nsISupportsPriority::PRIORITY_LOWEST);
   }
 
-  nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(channel);
-  if (cos) {
-    cos->AddClassFlags(nsIClassOfService::Tail |
-                       nsIClassOfService::Throttleable);
+  if (nsContentUtils::IsTailingEnabled()) {
+    nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(channel);
+    if (cos) {
+      cos->AddClassFlags(nsIClassOfService::Tail |
+                         nsIClassOfService::Throttleable);
+    }
   }
 
   rv = channel->AsyncOpen2(this);
   if (NS_SUCCEEDED(rv)) {
     mRequest = channel;
   }
   return rv;
 }