Bug 1486414 - Add prefs to hide the Trackers and FastBlock categories in the Content Blocking preferences; r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 28 Aug 2018 13:20:13 -0400
changeset 491705 dacda8522abacd0880311e95890c8ede79958f5c
parent 491704 2526c62d36d81dcfa3ef68792d4215a55a480a91
child 491706 505226ad06ab36d8a66ceabead0ccab9aed2b3e8
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1486414
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 1486414 - Add prefs to hide the Trackers and FastBlock categories in the Content Blocking preferences; r=johannh
browser/app/profile/firefox.js
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/privacy.xul
browser/components/preferences/in-content/tests/browser_contentblocking.js
browser/components/preferences/in-content/tests/browser_spotlight.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1497,16 +1497,18 @@ pref("browser.ping-centre.production.end
 
 // Enable GMP support in the addon manager.
 pref("media.gmp-provider.enabled", true);
 
 pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.recommended", true);
 pref("browser.contentblocking.fastblock.control-center.ui.enabled", true);
 pref("browser.contentblocking.trackingprotection.control-center.ui.enabled", true);
 pref("browser.contentblocking.rejecttrackers.ui.recommended", true);
+pref("browser.contentblocking.fastblock.ui.enabled", true);
+pref("browser.contentblocking.trackingprotection.ui.enabled", true);
 #ifdef NIGHTLY_BUILD
 pref("browser.contentblocking.ui.enabled", true);
 pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.enabled", true);
 pref("browser.contentblocking.rejecttrackers.control-center.ui.enabled", true);
 pref("browser.contentblocking.rejecttrackers.ui.enabled", true);
 #else
 pref("browser.contentblocking.ui.enabled", false);
 pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.enabled", false);
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -24,16 +24,22 @@ XPCOMUtils.defineLazyPreferenceGetter(th
                                       "browser.contentblocking.ui.enabled");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingCookiesAndSiteDataRejectTrackersRecommended",
                                       "browser.contentblocking.cookies-site-data.ui.reject-trackers.recommended");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingCookiesAndSiteDataRejectTrackersEnabled",
                                       "browser.contentblocking.cookies-site-data.ui.reject-trackers.enabled");
 
+XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingFastBlockUiEnabled",
+                                      "browser.contentblocking.fastblock.ui.enabled");
+
+XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingTrackingProtectionUiEnabled",
+                                      "browser.contentblocking.trackingprotection.ui.enabled");
+
 XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingRejectTrackersUiEnabled",
                                       "browser.contentblocking.rejecttrackers.ui.enabled");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingRejectTrackersRecommended",
                                       "browser.contentblocking.rejecttrackers.ui.recommended");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "contentBlockingEnabled",
                                       "browser.contentblocking.enabled");
@@ -488,21 +494,31 @@ var gPrivacyPane = {
       gPrivacyPane.readBlockCookiesCheckbox.bind(gPrivacyPane));
 
     this.readBlockCookiesCheckbox();
 
     let link = document.getElementById("contentBlockingLearnMore");
     let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "tracking-protection";
     link.setAttribute("href", url);
 
-    // Disable the Content Blocking Third-Party Cookies UI based on a pref
-    if (!contentBlockingRejectTrackersUiEnabled) {
-      let elements = document.querySelectorAll(".reject-trackers-ui");
-      for (let element of elements) {
-        element.hidden = true;
+    // Honour our Content Blocking category UI prefs. If each pref is set to false,
+    // Make all descendants of the corresponding selector hidden.
+    let selectorPrefMap = {
+      ".fast-block-ui": contentBlockingFastBlockUiEnabled,
+      ".tracking-protection-ui": contentBlockingTrackingProtectionUiEnabled,
+      ".reject-trackers-ui": contentBlockingRejectTrackersUiEnabled,
+    };
+
+    for (let selector in selectorPrefMap) {
+      let pref = selectorPrefMap[selector];
+      if (!pref) {
+        let elements = document.querySelectorAll(selector);
+        for (let element of elements) {
+          element.hidden = true;
+        }
       }
     }
 
     // Allow turning off the "(recommended)" label using a pref
     let blockCookiesFromTrackers = document.getElementById("blockCookiesFromTrackersCB");
     if (contentBlockingRejectTrackersRecommended) {
       document.l10n.setAttributes(blockCookiesFromTrackers, "content-blocking-reject-trackers-block-trackers-option-recommended");
     }
--- a/browser/components/preferences/in-content/privacy.xul
+++ b/browser/components/preferences/in-content/privacy.xul
@@ -326,17 +326,17 @@
       <button id="contentBlockingToggle"
               data-l10n-id="content-blocking-toggle-on"/>
       <label id="contentBlockingToggleLabel"
              data-l10n-id="content-blocking-toggle-label-on"
              control="contentBlockingToggle"/>
     </hbox>
     <vbox id="contentBlockingCategories">
       <label id="content-blocking-categories-label" data-l10n-id="content-blocking-category-label"/>
-      <hbox class="content-blocking-category">
+      <hbox class="content-blocking-category fast-block-ui">
         <vbox class="content-blocking-category-checkbox">
           <checkbox id="contentBlockingFastBlockCheckbox"
                     class="content-blocking-checkbox"
                     preference="browser.fastblock.enabled" />
         </vbox>
         <vbox class="content-blocking-category-icon">
           <image class="fastblock-icon content-blocking-icon"/>
         </vbox>
@@ -351,17 +351,17 @@
         <hbox id="contentBlockingTrackingProtectionExtensionContentLabel" align="center" hidden="true">
           <description control="contentBlockingDisableTrackingProtectionExtension" flex="1"/>
         </hbox>
         <hbox id="contentBlockingTrackingProtectionExtensionContentButton" hidden="true">
           <button id="contentBlockingDisableTrackingProtectionExtension"
                   class="extension-controlled-button accessory-button"
                   data-l10n-id="disable-extension"/>
         </hbox>
-        <hbox class="content-blocking-category">
+        <hbox class="content-blocking-category tracking-protection-ui">
           <vbox class="content-blocking-category-checkbox">
             <checkbox id="contentBlockingTrackingProtectionCheckbox" class="content-blocking-checkbox" />
           </vbox>
           <vbox class="content-blocking-category-icon">
             <image class="tracking-protection-icon content-blocking-icon" />
           </vbox>
           <vbox class="content-blocking-category-labels" flex="1">
             <label data-l10n-id="content-blocking-tracking-protection-label"
--- a/browser/components/preferences/in-content/tests/browser_contentblocking.js
+++ b/browser/components/preferences/in-content/tests/browser_contentblocking.js
@@ -1,12 +1,14 @@
 /* eslint-env webextensions */
 
 const CB_PREF = "browser.contentblocking.enabled";
 const CB_UI_PREF = "browser.contentblocking.ui.enabled";
+const CB_FB_UI_PREF = "browser.contentblocking.fastblock.ui.enabled";
+const CB_TP_UI_PREF = "browser.contentblocking.trackingprotection.ui.enabled";
 const CB_RT_UI_PREF = "browser.contentblocking.rejecttrackers.ui.enabled";
 const TP_PREF = "privacy.trackingprotection.enabled";
 const TP_PBM_PREF = "privacy.trackingprotection.pbmode.enabled";
 const TP_LIST_PREF = "urlclassifier.trackingTable";
 const FB_PREF = "browser.fastblock.enabled";
 const NCB_PREF = "network.cookie.cookieBehavior";
 
 requestLongerTimeout(2);
@@ -217,16 +219,18 @@ async function doDependentControlChecks(
 }
 
 // Checks that the granular controls are disabled or enabled depending on the master pref for CB.
 add_task(async function testContentBlockingDependentControls() {
   // In Accept All Cookies mode, the radiogroup under Third-Party Cookies is always disabled
   // since the checkbox next to Third-Party Cookies would be unchecked.
   SpecialPowers.pushPrefEnv({set: [
     [CB_UI_PREF, true],
+    [CB_FB_UI_PREF, true],
+    [CB_TP_UI_PREF, true],
     [CB_RT_UI_PREF, true],
     [NCB_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT],
   ]});
 
   let dependentControls = [
     "#content-blocking-categories-label",
     ".content-blocking-checkbox",
     ".content-blocking-icon",
@@ -239,16 +243,18 @@ add_task(async function testContentBlock
   ];
 
   await doDependentControlChecks(dependentControls, alwaysDisabledControls);
 
   // In Block Cookies from Trackers (or Block Cookies from All Third-Parties) mode, the
   // radiogroup's disabled status must obey the content blocking enabled state.
   SpecialPowers.pushPrefEnv({set: [
     [CB_UI_PREF, true],
+    [CB_FB_UI_PREF, true],
+    [CB_TP_UI_PREF, true],
     [CB_RT_UI_PREF, true],
     [NCB_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
   ]});
 
   dependentControls = [
     "#content-blocking-categories-label",
     ".content-blocking-checkbox",
     ".content-blocking-icon",
@@ -260,16 +266,18 @@ add_task(async function testContentBlock
 
   await doDependentControlChecks(dependentControls);
 });
 
 // Checks that the controls for tracking protection are disabled when all TP prefs are off.
 add_task(async function testContentBlockingDependentTPControls() {
   SpecialPowers.pushPrefEnv({set: [
     [CB_UI_PREF, true],
+    [CB_FB_UI_PREF, true],
+    [CB_TP_UI_PREF, true],
     [CB_RT_UI_PREF, true],
     [TP_PREF, false],
     [TP_PBM_PREF, false],
     [NCB_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
   ]});
 
   let dependentControls = [
     "#content-blocking-categories-label",
@@ -295,16 +303,18 @@ add_task(async function testContentBlock
 add_task(async function testContentBlockingDependentControlsOnSiteDataUI() {
   let prefValuesToTest = [
     Ci.nsICookieService.BEHAVIOR_REJECT,        // Block All Cookies
     Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN, // Block Cookies from unvisited websites
   ];
   for (let value of prefValuesToTest) {
     await SpecialPowers.pushPrefEnv({set: [
       [CB_UI_PREF, true],
+      [CB_FB_UI_PREF, true],
+      [CB_TP_UI_PREF, true],
       [CB_RT_UI_PREF, true],
       [TP_PREF, false],
       [TP_PBM_PREF, true],
       [NCB_PREF, value],
     ]});
 
     let dependentControls = [
       "#content-blocking-categories-label",
@@ -329,16 +339,18 @@ add_task(async function testContentBlock
   }
 
   prefValuesToTest = [
     Ci.nsICookieService.BEHAVIOR_ACCEPT,         // Accept All Cookies
   ];
   for (let value of prefValuesToTest) {
     await SpecialPowers.pushPrefEnv({set: [
       [CB_UI_PREF, true],
+      [CB_FB_UI_PREF, true],
+      [CB_TP_UI_PREF, true],
       [CB_RT_UI_PREF, true],
       [TP_PREF, false],
       [TP_PBM_PREF, true],
       [NCB_PREF, value],
     ]});
 
     let dependentControls = [
       "#content-blocking-categories-label",
@@ -360,16 +372,18 @@ add_task(async function testContentBlock
   // The rest of the values
   prefValuesToTest = [
     Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN, // Block All Third-Party Cookies
     Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER, // Block Cookies from third-party trackers
   ];
   for (let value of prefValuesToTest) {
     await SpecialPowers.pushPrefEnv({set: [
       [CB_UI_PREF, true],
+      [CB_FB_UI_PREF, true],
+      [CB_TP_UI_PREF, true],
       [CB_RT_UI_PREF, true],
       [TP_PREF, false],
       [TP_PBM_PREF, true],
       [NCB_PREF, value],
     ]});
 
     let dependentControls = [
       "#content-blocking-categories-label",
@@ -389,16 +403,18 @@ add_task(async function testContentBlock
 
 
 // Checks that the warnings in the Content Blocking Third-Party Cookies section correctly appear based on
 // the selections in the Cookies and Site Data section.
 add_task(async function testContentBlockingThirdPartyCookiesWarning() {
   await SpecialPowers.pushPrefEnv({set: [
     [CB_PREF, true],
     [CB_UI_PREF, true],
+    [CB_FB_UI_PREF, true],
+    [CB_TP_UI_PREF, true],
     [CB_RT_UI_PREF, true],
   ]});
 
   let expectedDeckIndex = new Map([
     [Ci.nsICookieService.BEHAVIOR_ACCEPT, 0],
     [Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN, 0],
     [Ci.nsICookieService.BEHAVIOR_REJECT, 1],
     [Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN, 2],
--- a/browser/components/preferences/in-content/tests/browser_spotlight.js
+++ b/browser/components/preferences/in-content/tests/browser_spotlight.js
@@ -37,16 +37,18 @@ add_task(async function test_credit_card
     "The credit-card-autofill section is spotlighted.");
   BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 add_task(async function test_change_cookie_settings() {
   await SpecialPowers.pushPrefEnv({set: [
     ["browser.contentblocking.enabled", true],
     ["browser.contentblocking.ui.enabled", true],
+    ["browser.contentblocking.fastblock.ui.enabled", true],
+    ["browser.contentblocking.trackingprotection.ui.enabled", true],
     ["browser.contentblocking.rejecttrackers.ui.enabled", true],
   ]});
   let prefs = await openPreferencesViaOpenPreferencesAPI("privacy-trackingprotection", {leaveOpen: true});
   is(prefs.selectedPane, "panePrivacy", "Privacy pane is selected by default");
   let doc = gBrowser.contentDocument;
   is(doc.location.hash, "#privacy", "The subcategory should be removed from the URI");
   await TestUtils.waitForCondition(() => doc.querySelector(".spotlight"),
     "Wait for the content-blocking section to be spotlighted.");