Bug 1509555 - Part 2: Remove the core fastblock code r=valentin
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 26 Nov 2018 11:37:01 +0000
changeset 504750 dd23df519c7e68fda26bee823685cd2efe1f2a54
parent 504749 e01c587ecd1dea5b3a65a65d66f316d769a519ec
child 504751 4374fb0c23357edfe09c1901fd745ec6393e77f2
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1509555
milestone65.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 1509555 - Part 2: Remove the core fastblock code r=valentin Depends on D12828 Differential Revision: https://phabricator.services.mozilla.com/D12829
dom/base/nsIContentPolicy.idl
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
--- a/dom/base/nsIContentPolicy.idl
+++ b/dom/base/nsIContentPolicy.idl
@@ -343,21 +343,20 @@ 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, 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. */
+   * 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. */
 
   //////////////////////////////////////////////////////////////////////
 
   /**
    * 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/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1711,23 +1711,16 @@ VARCACHE_PREF(
 // How many recent block/unblock actions per origins we remember in the
 // Content Blocking log for each top-level window.
 VARCACHE_PREF(
   "browser.contentblocking.originlog.length",
    browser_contentblocking_originlog_length,
   uint32_t, 32
 )
 
-// Whether FastBlock has been enabled.
-VARCACHE_PREF(
-  "browser.fastblock.enabled",
-  browser_fastblock_enabled,
-  bool, false
-)
-
 // Anti-tracking permission expiration
 VARCACHE_PREF(
   "privacy.restrict3rdpartystorage.expiration",
    privacy_restrict3rdpartystorage_expiration,
   uint32_t, 2592000 // 30 days (in seconds)
 )
 
 // Anti-tracking user-interaction expiration
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5558,17 +5558,17 @@ pref("urlclassifier.trackingAnnotationTa
 #else
 pref("urlclassifier.trackingAnnotationTable", "test-track-simple,base-track-digest256");
 #endif
 pref("urlclassifier.trackingAnnotationWhitelistTable", "test-trackwhite-simple,mozstd-trackwhite-digest256");
 pref("urlclassifier.trackingTable", "test-track-simple,base-track-digest256");
 pref("urlclassifier.trackingWhitelistTable", "test-trackwhite-simple,mozstd-trackwhite-digest256");
 
 // These tables will never trigger a gethash call.
-pref("urlclassifier.disallow_completions", "test-malware-simple,test-harmful-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,goog-downloadwhite-digest256,base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,goog-passwordwhite-proto,ads-track-digest256,social-track-digest256,analytics-track-digest256,fastblock1-track-digest256,fastblock1-trackwhite-digest256,fastblock2-track-digest256,fastblock2-trackwhite-digest256,fastblock3-track-digest256");
+pref("urlclassifier.disallow_completions", "test-malware-simple,test-harmful-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,goog-downloadwhite-digest256,base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,goog-passwordwhite-proto,ads-track-digest256,social-track-digest256,analytics-track-digest256");
 
 // Number of random entries to send with a gethash request
 pref("urlclassifier.gethashnoise", 4);
 
 // Gethash timeout for Safe Browsing
 pref("urlclassifier.gethash.timeout_ms", 5000);
 // Update server response timeout for Safe Browsing
 pref("urlclassifier.update.response_timeout_ms", 30000);
@@ -5630,17 +5630,17 @@ pref("browser.safebrowsing.provider.goog
 pref("browser.safebrowsing.provider.google4.advisoryName", "Google Safe Browsing");
 pref("browser.safebrowsing.provider.google4.dataSharingURL", "https://safebrowsing.googleapis.com/v4/threatHits?$ct=application/x-protobuf&key=%GOOGLE_API_KEY%&$httpMethod=POST");
 pref("browser.safebrowsing.provider.google4.dataSharing.enabled", false);
 
 pref("browser.safebrowsing.reportPhishURL", "https://%LOCALE%.phish-report.mozilla.com/?hl=%LOCALE%&url=");
 
 // Mozilla Safe Browsing provider (for tracking protection and plugin blocking)
 pref("browser.safebrowsing.provider.mozilla.pver", "2.2");
-pref("browser.safebrowsing.provider.mozilla.lists", "base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,ads-track-digest256,social-track-digest256,analytics-track-digest256,fastblock1-track-digest256,fastblock1-trackwhite-digest256,fastblock2-track-digest256,fastblock2-trackwhite-digest256,fastblock3-track-digest256");
+pref("browser.safebrowsing.provider.mozilla.lists", "base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,ads-track-digest256,social-track-digest256,analytics-track-digest256");
 pref("browser.safebrowsing.provider.mozilla.updateURL", "https://shavar.services.mozilla.com/downloads?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
 pref("browser.safebrowsing.provider.mozilla.gethashURL", "https://shavar.services.mozilla.com/gethash?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
 // Set to a date in the past to force immediate download in new profiles.
 pref("browser.safebrowsing.provider.mozilla.nextupdatetime", "1");
 // Block lists for tracking protection. The name values will be used as the keys
 // to lookup the localized name in preferences.properties.
 pref("browser.safebrowsing.provider.mozilla.lists.base", "moz-std");
 pref("browser.safebrowsing.provider.mozilla.lists.content", "moz-full");
@@ -5970,23 +5970,16 @@ pref("layers.omtp.dump-capture", false);
 // a content to view.  This is mostly intended to prevent infinite
 // loops with faulty converters involved.
 pref("general.document_open_conversion_depth_limit", 20);
 
 // If true, touchstart and touchmove listeners on window, document,
 // documentElement and document.body are passive by default.
 pref("dom.event.default_to_passive_touch_listeners", true);
 
-// The amount of time (ms) since navigation start after which all
-// tracker connections will be cancelled.
-pref("browser.fastblock.timeout", 5000);
-// The amount of time (ms) since navigation start after which
-// we'll stop blocking tracker connections (0 = no limit).
-pref("browser.fastblock.limit", 20000);
-
 // Enable clipboard readText() and writeText() by default
 pref("dom.events.asyncClipboard", true);
 // Disable clipboard read() and write() by default
 pref("dom.events.asyncClipboard.dataTransfer", false);
 // Should only be enabled in tests
 pref("dom.events.testing.asyncClipboard", false);
 
 #ifdef NIGHTLY_BUILD
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -663,144 +663,23 @@ 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, url=%s]",
-         this, mSpec.get()));
-    MOZ_ASSERT(mIsThirdPartyTrackingResource);
-
-    static bool sFastBlockInited = false;
-    static uint32_t sFastBlockTimeout = 0;
-    static uint32_t sFastBlockLimit = 0;
-
-    if (!sFastBlockInited) {
-        sFastBlockInited = true;
-        Preferences::AddUintVarCache(&sFastBlockTimeout, "browser.fastblock.timeout");
-        Preferences::AddUintVarCache(&sFastBlockLimit, "browser.fastblock.limit");
-    }
-
-    if (!StaticPrefs::browser_fastblock_enabled()) {
-        LOG(("FastBlock disabled by pref [this=%p]\n", this));
-
-        return false;
-    }
-
-    TimeStamp timestamp;
-    if (NS_FAILED(GetNavigationStartTimeStamp(&timestamp)) || !timestamp) {
-        LOG(("FastBlock passed (no timestamp) [this=%p]\n", this));
-
-        return false;
-    }
-
-    bool engageFastBlock = false;
-
-    TimeDuration duration = TimeStamp::NowLoRes() - timestamp;
-    if (IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo)) {
-        LOG(("FastBlock passed (whitelisted content type %u) (%lf) [this=%p]\n",
-             mLoadInfo ? mLoadInfo->GetExternalContentPolicyType() : nsIContentPolicy::TYPE_OTHER,
-             duration.ToMilliseconds(), this));
-    } else if (mLoadInfo && mLoadInfo->GetDocumentHasUserInteracted()) {
-        LOG(("FastBlock passed (user interaction) (%lf) [this=%p]\n",
-             duration.ToMilliseconds(), this));
-    } else if (mLoadInfo && mLoadInfo->GetDocumentHasLoaded()) {
-        LOG(("FastBlock passed (document loaded) (%lf) [this=%p]\n",
-             duration.ToMilliseconds(), this));
-    } else {
-            bool hasFastBlockStarted = duration.ToMilliseconds() >= sFastBlockTimeout;
-        bool hasFastBlockStopped = false;
-        if ((sFastBlockLimit != 0) && (sFastBlockLimit > sFastBlockTimeout)) {
-            hasFastBlockStopped = duration.ToMilliseconds() > sFastBlockLimit;
-        }
-        LOG(("FastBlock started=%d stopped=%d (%lf) [this=%p]\n",
-             static_cast<int>(hasFastBlockStarted),
-             static_cast<int>(hasFastBlockStopped),
-             duration.ToMilliseconds(),
-             this));
-        engageFastBlock = hasFastBlockStarted && !hasFastBlockStopped;
-    }
-
-    if (!engageFastBlock) {
-        return false;
-    }
-
-    TimeDuration duration = TimeStamp::NowLoRes() - timestamp;
-    bool hasFastBlockStarted = duration.ToMilliseconds() >= sFastBlockTimeout;
-    bool hasFastBlockStopped = false;
-    if ((sFastBlockLimit != 0) && (sFastBlockLimit > sFastBlockTimeout)) {
-        hasFastBlockStopped = duration.ToMilliseconds() > sFastBlockLimit;
-    }
-    const bool isFastBlocking = hasFastBlockStarted && !hasFastBlockStopped;
-
-    if (isFastBlocking && mLoadInfo) {
-        MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(true));
-    }
-
-    LOG(("FastBlock started=%d stopped=%d (%lf) [this=%p]\n",
-         static_cast<int>(hasFastBlockStarted),
-         static_cast<int>(hasFastBlockStopped),
-         duration.ToMilliseconds(),
-         this));
-    return isFastBlocking;
-}
-
 nsresult
 nsHttpChannel::ConnectOnTailUnblock()
 {
     nsresult rv;
 
     LOG(("nsHttpChannel::ConnectOnTailUnblock [this=%p]\n", this));
 
-    bool isTrackingResource = mIsThirdPartyTrackingResource; // is atomic
-    if (isTrackingResource) {
-        bool engageFastBlock = CheckFastBlocked();
-        AntiTrackingCommon::NotifyBlockingDecision(this,
-                                                   engageFastBlock ?
-                                                     AntiTrackingCommon::BlockingDecision::eBlock :
-                                                     AntiTrackingCommon::BlockingDecision::eAllow,
-                                                   nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT);
-        if (engageFastBlock) {
-          Unused << AsyncAbort(NS_ERROR_TRACKING_ANNOTATION_URI);
-          CloseCacheEntry(false);
-          return NS_OK;
-        }
-    }
-
     // Consider opening a TCP connection right away.
     SpeculativeConnect();
 
     // open a cache entry for this channel...
     bool isHttps = false;
     rv = mURI->SchemeIs("https", &isHttps);
     NS_ENSURE_SUCCESS(rv,rv);
     rv = OpenCacheEntry(isHttps);
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -683,19 +683,16 @@ private:
     // A function we trigger when untail callback is triggered by our request
     // context in case this channel was tail-blocked.
     nsresult (nsHttpChannel::*mOnTailUnblock)();
     // Called on untail when tailed during AsyncOpen execution.
     nsresult AsyncOpenOnTailUnblock();
     // Called on untail when tailed because of being a tracking resource.
     nsresult ConnectOnTailUnblock();
 
-    // Check if current channel should be canceled by FastBlock rules.
-    bool CheckFastBlocked();
-
     nsCString mUsername;
 
     // If non-null, warnings should be reported to this object.
     RefPtr<HttpChannelSecurityWarningReporter> mWarningReporter;
 
     RefPtr<ADivertableParentChannel> mParentChannel;
 
     // True if the channel is reading from cache.