Bug 1472535 - Put the main menu tracking protection toggle behind a pref. r=mikedeboer draft
authorJohann Hofmann <jhofmann@mozilla.com>
Mon, 09 Jul 2018 13:09:53 +0200
changeset 817328 5839daaac17384fdca8969e750af2bb76b6403fb
parent 817076 3aca103e49150145dbff910be15e7886b7c4495a
push id116020
push userjhofmann@mozilla.com
push dateThu, 12 Jul 2018 11:42:54 +0000
reviewersmikedeboer
bugs1472535
milestone63.0a1
Bug 1472535 - Put the main menu tracking protection toggle behind a pref. r=mikedeboer This is assuming we want to pref off for 62 and pref on again for 63, simply delaying the feature by one release. MozReview-Commit-ID: 7Q4uD7QJDFc
browser/app/profile/firefox.js
browser/base/content/browser-trackingprotection.js
browser/base/content/test/trackingUI/browser_trackingUI_appMenu.js
browser/base/content/test/trackingUI/browser_trackingUI_appMenu_toggle.js
browser/components/customizableui/content/panelUI.inc.xul
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1487,16 +1487,21 @@ pref("browser.ping-centre.staging.endpoi
 pref("browser.ping-centre.production.endpoint", "https://tiles.services.mozilla.com/v3/links/ping-centre");
 
 // Enable GMP support in the addon manager.
 pref("media.gmp-provider.enabled", true);
 
 pref("privacy.trackingprotection.ui.enabled", true);
 pref("privacy.trackingprotection.introCount", 0);
 pref("privacy.trackingprotection.introURL", "https://www.mozilla.org/%LOCALE%/firefox/%VERSION%/tracking-protection/start/");
+#ifdef NIGHTLY_BUILD
+pref("privacy.trackingprotection.appMenuToggle.enabled", true);
+#else
+pref("privacy.trackingprotection.appMenuToggle.enabled", false);
+#endif
 
 // Always enable newtab segregation using containers
 pref("privacy.usercontext.about_newtab_segregation.enabled", true);
 // Enable Contextual Identity Containers
 #ifdef NIGHTLY_BUILD
 pref("privacy.userContext.enabled", true);
 pref("privacy.userContext.ui.enabled", true);
 
--- a/browser/base/content/browser-trackingprotection.js
+++ b/browser/base/content/browser-trackingprotection.js
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var TrackingProtection = {
   // If the user ignores the doorhanger, we stop showing it after some time.
   MAX_INTROS: 20,
   PREF_ENABLED_GLOBALLY: "privacy.trackingprotection.enabled",
   PREF_ENABLED_IN_PRIVATE_WINDOWS: "privacy.trackingprotection.pbmode.enabled",
+  PREF_APP_MENU_TOGGLE: "privacy.trackingprotection.appMenuToggle.enabled",
   enabledGlobally: false,
   enabledInPrivateWindows: false,
   container: null,
   content: null,
   icon: null,
   activeTooltipText: null,
   disabledTooltipText: null,
 
@@ -28,43 +29,60 @@ var TrackingProtection = {
     }
   },
 
   init() {
     let $ = selector => document.querySelector(selector);
     this.container = $("#tracking-protection-container");
     this.content = $("#tracking-protection-content");
     this.icon = $("#tracking-protection-icon");
+    this.appMenuContainer = $("#appMenu-tp-container");
+    this.appMenuSeparator = $("#appMenu-tp-separator");
     this.broadcaster = $("#trackingProtectionBroadcaster");
 
     this.enableTooltip =
       gNavigatorBundle.getString("trackingProtection.toggle.enable.tooltip");
     this.disableTooltip =
       gNavigatorBundle.getString("trackingProtection.toggle.disable.tooltip");
     this.enableTooltipPB =
       gNavigatorBundle.getString("trackingProtection.toggle.enable.pbmode.tooltip");
     this.disableTooltipPB =
       gNavigatorBundle.getString("trackingProtection.toggle.disable.pbmode.tooltip");
 
     this.updateEnabled();
+
+    this.updateAppMenuToggle = () => {
+      if (Services.prefs.getBoolPref(this.PREF_APP_MENU_TOGGLE, false)) {
+        this.appMenuContainer.removeAttribute("hidden");
+        this.appMenuSeparator.removeAttribute("hidden");
+      } else {
+        this.appMenuContainer.setAttribute("hidden", "true");
+        this.appMenuSeparator.setAttribute("hidden", "true");
+      }
+    };
+
     Services.prefs.addObserver(this.PREF_ENABLED_GLOBALLY, this);
     Services.prefs.addObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this);
+    Services.prefs.addObserver(this.PREF_APP_MENU_TOGGLE, this.updateAppMenuToggle);
+
+    this.updateAppMenuToggle();
 
     this.activeTooltipText =
       gNavigatorBundle.getString("trackingProtection.icon.activeTooltip");
     this.disabledTooltipText =
       gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip");
 
     this.enabledHistogramAdd(this.enabledGlobally);
     this.disabledPBMHistogramAdd(!this.enabledInPrivateWindows);
   },
 
   uninit() {
     Services.prefs.removeObserver(this.PREF_ENABLED_GLOBALLY, this);
     Services.prefs.removeObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this);
+    Services.prefs.removeObserver(this.PREF_APP_MENU_TOGGLE, this.updateAppMenuToggle);
   },
 
   observe() {
     this.updateEnabled();
   },
 
   get enabled() {
     return this.enabledGlobally ||
--- a/browser/base/content/test/trackingUI/browser_trackingUI_appMenu.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_appMenu.js
@@ -2,16 +2,18 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
 
 // Test that the "Tracking Protection" button in the app menu loads about:preferences
 add_task(async function testPreferencesButton() {
+  await SpecialPowers.pushPrefEnv({set: [["privacy.trackingprotection.appMenuToggle.enabled", true]]});
+
   let cuiTestUtils = new CustomizableUITestUtils(window);
 
   await BrowserTestUtils.withNewTab(gBrowser, async function(browser) {
     await cuiTestUtils.openMainMenu();
 
     let loaded = TestUtils.waitForCondition(() => gBrowser.currentURI.spec == "about:preferences#privacy",
       "Should open about:preferences.");
     document.getElementById("appMenu-tp-label").click();
--- a/browser/base/content/test/trackingUI/browser_trackingUI_appMenu_toggle.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_appMenu_toggle.js
@@ -3,16 +3,18 @@
 
 "use strict";
 
 ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
 
 // Test that the app menu toggle correctly flips the TP pref in
 // normal windows and private windows.
 add_task(async function testGlobalToggle() {
+  await SpecialPowers.pushPrefEnv({set: [["privacy.trackingprotection.appMenuToggle.enabled", true]]});
+
   async function runTest(privateWindow) {
     let win = await BrowserTestUtils.openNewBrowserWindow({private: privateWindow});
 
     let panelUIButton = await TestUtils.waitForCondition(() => win.document.getElementById("PanelUI-menu-button"));
 
     let prefName = privateWindow ? "privacy.trackingprotection.pbmode.enabled" :
       "privacy.trackingprotection.enabled";
 
--- a/browser/components/customizableui/content/panelUI.inc.xul
+++ b/browser/components/customizableui/content/panelUI.inc.xul
@@ -204,30 +204,30 @@
                          oncommand="gSync.doSync();"
                          closemenu="none">
             <observes element="sync-status" attribute="syncstatus"/>
             <observes element="sync-status" attribute="tooltiptext"/>
             <observes element="sync-status" attribute="onmouseover"/>
           </toolbarbutton>
         </toolbaritem>
         <toolbarseparator class="sync-ui-item"/>
-        <toolbaritem>
+        <toolbaritem id="appMenu-tp-container" hidden="true">
           <toolbarbutton id="appMenu-tp-label"
                          tooltiptext="&trackingProtection.tooltip;"
                          class="subviewbutton subviewbutton-iconic"
                          oncommand="TrackingProtection.openPreferences('appMenu-trackingprotection');"
                          label="&trackingProtection.title;"/>
           <toolbarseparator orient="vertical"/>
           <toolbarbutton id="appMenu-tp-toggle"
                          closemenu="none"
                          class="subviewkeynav"
                          observes="trackingProtectionBroadcaster"
                          oncommand="TrackingProtection.onGlobalToggleCommand();" />
         </toolbaritem>
-        <toolbarseparator />
+        <toolbarseparator id="appMenu-tp-separator" hidden="true" />
         <toolbarbutton id="appMenu-new-window-button"
                        class="subviewbutton subviewbutton-iconic"
                        label="&newNavigatorCmd.label;"
                        key="key_newNavigator"
                        command="cmd_newNavigator"/>
         <toolbarbutton id="appMenu-private-window-button"
                        class="subviewbutton subviewbutton-iconic"
                        label="&newPrivateWindow.label;"