Bug 1485400 - Part 1: fix tracker found/blocked counter; r=mayhemer
☠☠ backed out by 8d89bfeb0b2f ☠ ☠
authorLiang-Heng Chen <xeonchen@gmail.com>
Fri, 31 Aug 2018 15:13:30 +0000
changeset 434339 c476aa79a8ca991dc8ea1e5c2eab98e442dad406
parent 434338 9370432b26adcd6399e586190a47d4c8a8cdc56d
child 434340 34d7cf7fa7eb1c51c6e7f2b4cbf3e5da20ba36d8
push id107338
push useraciure@mozilla.com
push dateFri, 31 Aug 2018 23:45:51 +0000
treeherdermozilla-inbound@ee4f4e66f861 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1485400
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 1485400 - Part 1: fix tracker found/blocked counter; r=mayhemer make counter increased when trackers are found Differential Revision: https://phabricator.services.mozilla.com/D4068
netwerk/base/nsChannelClassifier.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/base/nsChannelClassifier.cpp
+++ b/netwerk/base/nsChannelClassifier.cpp
@@ -906,18 +906,16 @@ nsChannelClassifier::SetBlockedContent(n
   auto* pwin = nsPIDOMWindowOuter::From(win);
   nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
   if (!docShell) {
     return NS_OK;
   }
   nsCOMPtr<nsIDocument> doc = docShell->GetDocument();
   NS_ENSURE_TRUE(doc, NS_OK);
 
-  doc->IncrementTrackerCount(true);
-
   unsigned state;
   if (aErrorCode == NS_ERROR_TRACKING_URI) {
     state = nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT;
   } else {
     state = nsIWebProgressListener::STATE_BLOCKED_UNSAFE_CONTENT;
   }
   pwin->NotifyContentBlockingState(state, channel);
 
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -326,16 +326,20 @@ HttpBaseChannel::SetIsTrackingResource(b
 
   if (aIsThirdParty) {
     MOZ_ASSERT(!mIsFirstPartyTrackingResource);
     mIsThirdPartyTrackingResource = true;
   } else {
     MOZ_ASSERT(!mIsThirdPartyTrackingResource);
     mIsFirstPartyTrackingResource = true;
   }
+
+  if (mLoadInfo) {
+    MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTracker(true));
+  }
 }
 
 nsresult
 HttpBaseChannel::Init(nsIURI *aURI,
                       uint32_t aCaps,
                       nsProxyInfo *aProxyInfo,
                       uint32_t aProxyResolveFlags,
                       nsIURI *aProxyURI,
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -742,29 +742,31 @@ HttpChannelChild::DoOnStartRequest(nsIRe
   }
 
   if (mSynthesizedResponsePump && mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) {
     mSynthesizedResponsePump->PeekStream(CallTypeSniffers,
                                          static_cast<nsIChannel*>(this));
   }
 
   bool isTracker;
-  if (NS_SUCCEEDED(mLoadInfo->GetIsTracker(&isTracker)) && isTracker) {
+  MOZ_ALWAYS_SUCCEEDS(mLoadInfo->GetIsTracker(&isTracker));
+  if (isTracker) {
     bool isTrackerBlocked;
-    Unused << mLoadInfo->GetIsTrackerBlocked(&isTrackerBlocked);
-
+    MOZ_ALWAYS_SUCCEEDS(mLoadInfo->GetIsTrackerBlocked(&isTrackerBlocked));
     LOG(("HttpChannelChild::DoOnStartRequest FastBlock %d [this=%p]\n",
          isTrackerBlocked,
          this));
 
     nsCOMPtr<nsIDocument> doc;
     if (!NS_WARN_IF(NS_FAILED(GetTopDocument(this,
                                              getter_AddRefs(doc))))) {
-
-      doc->IncrementTrackerCount(isTrackerBlocked);
+      doc->IncrementTrackerCount();
+      if (isTrackerBlocked) {
+        doc->IncrementTrackerBlockedCount();
+      }
     }
   }
 
   nsresult rv = mListener->OnStartRequest(aRequest, aContext);
   if (NS_FAILED(rv)) {
     Cancel(rv);
     return;
   }
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -689,45 +689,49 @@ IsContentPolicyTypeWhitelistedForFastBlo
     return false;
   }
 }
 
 bool
 nsHttpChannel::CheckFastBlocked()
 {
     LOG(("nsHttpChannel::CheckFastBlocked [this=%p]\n", this));
+    MOZ_ASSERT(mIsThirdPartyTrackingResource);
 
     static bool sFastBlockInited = false;
     static bool sIsFastBlockEnabled = false;
     static uint32_t sFastBlockTimeout = 0;
 
     if (!sFastBlockInited) {
         sFastBlockInited = true;
         Preferences::AddBoolVarCache(&sIsFastBlockEnabled, "browser.fastblock.enabled");
         Preferences::AddUintVarCache(&sFastBlockTimeout, "browser.fastblock.timeout");
     }
 
     TimeStamp timestamp;
-    if (NS_FAILED(GetNavigationStartTimeStamp(&timestamp))) {
+    if (NS_FAILED(GetNavigationStartTimeStamp(&timestamp)) || !timestamp) {
+        LOG(("FastBlock passed (no timestamp) [this=%p]\n", this));
+
         return false;
     }
 
     if (!StaticPrefs::browser_contentblocking_enabled() ||
         !sIsFastBlockEnabled ||
-        IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo) ||
-        !timestamp) {
+        IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo)) {
+
+        LOG(("FastBlock passed (invalid) [this=%p]\n", this));
+
         return false;
     }
 
     TimeDuration duration = TimeStamp::NowLoRes() - timestamp;
     bool isFastBlocking = duration.ToMilliseconds() >= sFastBlockTimeout;
 
-    if (mLoadInfo) {
-        MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTracker(true));
-        MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(isFastBlocking));
+    if (isFastBlocking && mLoadInfo) {
+        MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(true));
     }
 
     LOG(("FastBlock %s (%lf) [this=%p]\n",
          isFastBlocking ? "timeout" : "passed",
          duration.ToMilliseconds(),
          this));
     return isFastBlocking;
 }
@@ -6100,16 +6104,20 @@ nsHttpChannel::ContinueCancelledByTracki
 
 nsresult
 nsHttpChannel::CancelInternal(nsresult status)
 {
     bool trackingProtectionCancellationPending =
       !!mTrackingProtectionCancellationPending;
     if (status == NS_ERROR_TRACKING_URI) {
       mTrackingProtectionCancellationPending = 0;
+      if (mLoadInfo) {
+        MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTracker(true));
+        MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(true));
+      }
     }
 
     mCanceled = true;
     mStatus = status;
     if (mProxyRequest)
         mProxyRequest->Cancel(status);
     CancelNetworkRequest(status);
     mCacheInputStream.CloseAndRelease();