Bug 1480450 - Honor browser.contentblocking.enabled in tracking protection. r=dimi!
authorFrancois Marier <francois@mozilla.com>
Mon, 13 Aug 2018 23:20:40 +0000
changeset 486408 cd55c4ac10c3a3040b406a4d13e09e828a45634b
parent 486407 b3f01b9ce2bf9c4cf05bf4bca16330560439db0b
child 486409 597222dce884518ce020cd7a1552d0b571a158de
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1480450
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 1480450 - Honor browser.contentblocking.enabled in tracking protection. r=dimi! Depends on D3131 Differential Revision: https://phabricator.services.mozilla.com/D3132
docshell/base/nsDocShell.cpp
toolkit/components/url-classifier/SafeBrowsing.jsm
toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html
toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html
toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -13110,30 +13110,33 @@ nsDocShell::GetNestedFrameId(uint64_t* a
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetUseTrackingProtection(bool* aUseTrackingProtection)
 {
   *aUseTrackingProtection  = false;
 
+  static bool sCBEnabled = false;
   static bool sTPEnabled = false;
   static bool sTPInPBEnabled = false;
   static bool sPrefsInit = false;
 
   if (!sPrefsInit) {
     sPrefsInit = true;
+    Preferences::AddBoolVarCache(&sCBEnabled,
+      "browser.contentblocking.enabled", true);
     Preferences::AddBoolVarCache(&sTPEnabled,
       "privacy.trackingprotection.enabled", false);
     Preferences::AddBoolVarCache(&sTPInPBEnabled,
       "privacy.trackingprotection.pbmode.enabled", false);
   }
 
-  if (mUseTrackingProtection || sTPEnabled ||
-      (UsePrivateBrowsing() && sTPInPBEnabled)) {
+  if (mUseTrackingProtection || (sCBEnabled && sTPEnabled) ||
+      (sCBEnabled && UsePrivateBrowsing() && sTPInPBEnabled)) {
     *aUseTrackingProtection = true;
     return NS_OK;
   }
 
   RefPtr<nsDocShell> parent = GetParentDocshell();
   if (parent) {
     return parent->GetUseTrackingProtection(aUseTrackingProtection);
   }
--- a/toolkit/components/url-classifier/SafeBrowsing.jsm
+++ b/toolkit/components/url-classifier/SafeBrowsing.jsm
@@ -55,16 +55,17 @@ const tablePreferences = [
 var SafeBrowsing = {
 
   init() {
     if (this.initialized) {
       log("Already initialized");
       return;
     }
 
+    Services.prefs.addObserver("browser.contentblocking.enabled", this);
     Services.prefs.addObserver("browser.safebrowsing", this);
     Services.prefs.addObserver("privacy.trackingprotection", this);
     Services.prefs.addObserver("urlclassifier", this);
     Services.prefs.addObserver("plugins.flashBlock.enabled", this);
     Services.prefs.addObserver("plugins.show_infobar", this);
 
     this.readPrefs();
     this.addMozEntries();
@@ -225,21 +226,23 @@ var SafeBrowsing = {
 
     this.readPrefs();
   },
 
   readPrefs() {
     loggingEnabled = Services.prefs.getBoolPref(PREF_DEBUG_ENABLED);
     log("reading prefs");
 
+    let contentBlockingEnabled = Services.prefs.getBoolPref("browser.contentblocking.enabled", true);
+
     this.phishingEnabled = Services.prefs.getBoolPref("browser.safebrowsing.phishing.enabled");
     this.malwareEnabled = Services.prefs.getBoolPref("browser.safebrowsing.malware.enabled");
     this.downloadsEnabled = Services.prefs.getBoolPref("browser.safebrowsing.downloads.enabled");
     this.passwordsEnabled = Services.prefs.getBoolPref("browser.safebrowsing.passwords.enabled");
-    this.trackingEnabled = Services.prefs.getBoolPref("privacy.trackingprotection.enabled") || Services.prefs.getBoolPref("privacy.trackingprotection.pbmode.enabled");
+    this.trackingEnabled = contentBlockingEnabled && (Services.prefs.getBoolPref("privacy.trackingprotection.enabled") || Services.prefs.getBoolPref("privacy.trackingprotection.pbmode.enabled"));
     this.blockedEnabled = Services.prefs.getBoolPref("browser.safebrowsing.blockedURIs.enabled");
     this.trackingAnnotations = Services.prefs.getBoolPref("privacy.trackingprotection.annotate_channels");
     this.flashBlockEnabled = Services.prefs.getBoolPref("plugins.flashBlock.enabled");
     this.flashInfobarListEnabled = Services.prefs.getBoolPref("plugins.show_infobar", false);
 
     let flashAllowTable, flashAllowExceptTable, flashTable,
         flashExceptTable, flashSubDocTable,
         flashSubDocExceptTable;
--- a/toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html
@@ -99,19 +99,21 @@ function checkLoads(aWindow, aBlocked) {
     }
 
     allNodeMatch = allNodeMatch && nodeMatch;
   }
   is(allNodeMatch, aBlocked, "All tracking nodes are expected to be annotated as such");
 }
 
 SpecialPowers.pushPrefEnv(
-  {"set": [["privacy.trackingprotection.enabled", false],
-           ["privacy.trackingprotection.pbmode.enabled", true]]},
-  test);
+  {"set": [
+      ["browser.contentblocking.enabled", true],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", true],
+  ]}, test);
 
 async function test() {
   SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers);
   await UrlClassifierTestUtils.addTestTrackers();
 
   // Normal mode, with the pref (trackers should be loaded)
   await testOnWindow(false).then(function(aWindow) {
     checkLoads(aWindow, false);
@@ -125,16 +127,25 @@ async function test() {
   });
 
   // Private Browsing, without the pref (trackers should be loaded)
   await SpecialPowers.setBoolPref("privacy.trackingprotection.pbmode.enabled", false);
   await testOnWindow(true).then(function(aWindow) {
     checkLoads(aWindow, false);
     aWindow.close();
   });
+
+  // Private Browsing, without the content blocking pref (trackers should be loaded)
+  await SpecialPowers.setBoolPref("privacy.trackingprotection.pbmode.enabled", true);
+  await SpecialPowers.setBoolPref("browser.contentblocking.enabled", false);
+  await testOnWindow(true).then(function(aWindow) {
+    checkLoads(aWindow, false);
+    aWindow.close();
+  });
+
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 
 </script>
 
 </pre>
--- a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html
@@ -52,16 +52,17 @@ var badids = [
 function checkLoads(aWindow, aBlocked) {
   var win = aWindow.content;
   is(win.document.getElementById("badscript").dataset.touched, aBlocked ? "no" : "yes", "Should not load tracking javascript");
 }
 
 SpecialPowers.pushPrefEnv(
   {"set": [["urlclassifier.trackingTable", "test-track-simple"],
            ["privacy.trackingprotection.enabled", true],
+           ["browser.contentblocking.enabled", true],
            ["browser.safebrowsing.malware.enabled", false],
            ["browser.safebrowsing.phishing.enabled", false],
            ["channelclassifier.allowlist_example", true]]},
   test);
 
 function test() {
   SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers);
   UrlClassifierTestUtils.addTestTrackers().then(() => {
--- a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html
@@ -51,18 +51,24 @@ function testOnWindow(contentPage) {
     }, {capture: true, once: true});
   });
 }
 
 var alwaysbadids = [
   "badscript",
 ];
 
-function checkLoads(aWindow, aWhitelisted) {
+function checkLoads(aWindow, aWhitelisted, tpEnabled) {
   var win = aWindow.content;
+  if (!tpEnabled) {
+    is(win.document.getElementById("badscript").dataset.touched, "yes", "Should load tracking javascript");
+    is(win.document.blockedTrackingNodeCount, 0, "Should not identify any tracking elements");
+    return;
+  }
+
   is(win.document.getElementById("badscript").dataset.touched, "no", "Should not load tracking javascript");
   is(win.document.getElementById("goodscript").dataset.touched, aWhitelisted ? "yes" : "no", "Should load whitelisted tracking javascript");
 
   var badids = alwaysbadids.slice();
   if (!aWhitelisted) {
     badids.push("goodscript");
   }
   is(win.document.blockedTrackingNodeCount, badids.length, "Should identify all tracking elements");
@@ -104,32 +110,40 @@ SpecialPowers.pushPrefEnv(
   {"set": [["privacy.trackingprotection.enabled", true],
            ["channelclassifier.allowlist_example", true]]},
   test);
 
 async function test() {
   SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers);
   await UrlClassifierTestUtils.addTestTrackers();
 
-  // Load the test from a URL on the whitelist
-  await testOnWindow(contentPage1).then(function(aWindow) {
-    checkLoads(aWindow, true);
+  // Load the test from a URL that's NOT on the whitelist with content blocking disabled
+  await SpecialPowers.setBoolPref("browser.contentblocking.enabled", false);
+  await testOnWindow(contentPage2).then(function(aWindow) {
+    checkLoads(aWindow, false, false);
+    aWindow.close();
+  });
+  await SpecialPowers.clearUserPref("browser.contentblocking.enabled");
+
+  // Load the test from a URL that's NOT on the whitelist
+  await testOnWindow(contentPage2).then(function(aWindow) {
+    checkLoads(aWindow, false, true);
     aWindow.close();
   });
 
-  // Load the test from a URL that's NOT on the whitelist
-  await testOnWindow(contentPage2).then(function(aWindow) {
-    checkLoads(aWindow, false);
+  // Load the test from a URL on the whitelist
+  await testOnWindow(contentPage1).then(function(aWindow) {
+    checkLoads(aWindow, true, true);
     aWindow.close();
   });
 
   // Load the test from a URL on the whitelist but without the whitelist
   await SpecialPowers.setCharPref("urlclassifier.trackingWhitelistTable", "");
   await testOnWindow(contentPage1).then(function(aWindow) {
-    checkLoads(aWindow, false);
+    checkLoads(aWindow, false, true);
     aWindow.close();
   });
   await SpecialPowers.clearUserPref("urlclassifier.trackingWhitelistTable");
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();