Bug 1686523, remove home button if proton is enabled and the button hasn't been used r=mstriemer,mconley
authorEmma Malysz <emalysz@mozilla.com>
Wed, 10 Feb 2021 16:58:53 +0000
changeset 566871 2cd494905b896c854351d4d3b8b327d04644976d
parent 566870 8ef970eae3d15bd78af6458148060b3a56485407
child 566872 d94de995a62b8d4f65c1a8f759320cf6f6bf30bf
push id136169
push useremalysz@mozilla.com
push dateWed, 10 Feb 2021 18:48:00 +0000
treeherderautoland@2cd494905b89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, mconley
bugs1686523
milestone87.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 1686523, remove home button if proton is enabled and the button hasn't been used r=mstriemer,mconley Differential Revision: https://phabricator.services.mozilla.com/D103796
browser/app/profile/firefox.js
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_1686523_hide_home_button.js
browser/components/enterprisepolicies/Policies.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -818,16 +818,17 @@ pref("browser.preferences.search", true)
 pref("browser.preferences.experimental", true);
 #else
 pref("browser.preferences.experimental", false);
 #endif
 pref("browser.preferences.experimental.hidden", false);
 pref("browser.preferences.defaultPerformanceSettings.enabled", true);
 
 pref("browser.proton.enabled", false);
+pref("browser.proton.toolbar.version", 0);
 
 // Backspace and Shift+Backspace behavior
 // 0 goes Back/Forward
 // 1 act like PgUp/PgDown
 // 2 and other values, nothing
 pref("browser.backspace_action", 2);
 
 pref("intl.regional_prefs.use_os_locales", false);
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -17,16 +17,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
   AddonManager: "resource://gre/modules/AddonManager.jsm",
   AddonManagerPrivate: "resource://gre/modules/AddonManager.jsm",
   SearchWidgetTracker: "resource:///modules/SearchWidgetTracker.jsm",
   CustomizableWidgets: "resource:///modules/CustomizableWidgets.jsm",
   PanelMultiView: "resource:///modules/PanelMultiView.jsm",
   PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
   ShortcutUtils: "resource://gre/modules/ShortcutUtils.jsm",
   BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.jsm",
+  HomePage: "resource:///modules/HomePage.jsm",
 });
 
 XPCOMUtils.defineLazyGetter(this, "gWidgetsBundle", function() {
   const kUrl =
     "chrome://browser/locale/customizableui/customizableWidgets.properties";
   return Services.strings.createBundle(kUrl);
 });
 
@@ -39,28 +40,37 @@ XPCOMUtils.defineLazyServiceGetter(
 
 XPCOMUtils.defineLazyPreferenceGetter(
   this,
   "gBookmarksToolbar2h2020",
   "browser.toolbars.bookmarks.2h2020",
   false
 );
 
+XPCOMUtils.defineLazyPreferenceGetter(
+  this,
+  "gProtonToolbarEnabled",
+  "browser.proton.toolbar.enabled",
+  false
+);
+
 const kDefaultThemeID = "default-theme@mozilla.org";
 
 const kSpecialWidgetPfx = "customizableui-special-";
 
 const kPrefCustomizationState = "browser.uiCustomization.state";
 const kPrefCustomizationAutoAdd = "browser.uiCustomization.autoAdd";
 const kPrefCustomizationDebug = "browser.uiCustomization.debug";
 const kPrefDrawInTitlebar = "browser.tabs.drawInTitlebar";
 const kPrefExtraDragSpace = "browser.tabs.extraDragSpace";
 const kPrefUIDensity = "browser.uidensity";
 const kPrefAutoTouchMode = "browser.touchmode.auto";
 const kPrefAutoHideDownloadsButton = "browser.download.autohideButton";
+const kPrefProtonToolbarVersion = "browser.proton.toolbar.version";
+const kPrefHomeButtonUsed = "browser.engagement.home-button.has-used";
 
 const kExpectedWindowURL = AppConstants.BROWSER_CHROME_URL;
 
 var gDefaultTheme;
 var gSelectedTheme;
 
 /**
  * The keys are the handlers that are fired when the event type (the value)
@@ -223,45 +233,43 @@ var CustomizableUIInternal = {
       gDefaultTheme = addons.find(addon => addon.id == kDefaultThemeID);
       gSelectedTheme = addons.find(addon => addon.isActive) || gDefaultTheme;
     });
 
     this.addListener(this);
     this._defineBuiltInWidgets();
     this.loadSavedState();
     this._updateForNewVersion();
+    this._updateForNewProtonVersion();
     this._markObsoleteBuiltinButtonsSeen();
 
     this.registerArea(
       CustomizableUI.AREA_FIXED_OVERFLOW_PANEL,
       {
         type: CustomizableUI.TYPE_MENU_PANEL,
         defaultPlacements: [],
         anchor: "nav-bar-overflow-button",
       },
       true
     );
 
     let navbarPlacements = [
       "back-button",
       "forward-button",
       "stop-reload-button",
-      "home-button",
+      gProtonToolbarEnabled ? null : "home-button",
       "spring",
       "urlbar-container",
       "spring",
       "downloads-button",
       "library-button",
+      AppConstants.MOZ_DEV_EDITION ? "developer-button" : null,
       "sidebar-button",
       "fxa-toolbar-menu-button",
-    ];
-
-    if (AppConstants.MOZ_DEV_EDITION) {
-      navbarPlacements.splice(7, 0, "developer-button");
-    }
+    ].filter(name => name);
 
     this.registerArea(
       CustomizableUI.AREA_NAVBAR,
       {
         type: CustomizableUI.TYPE_TOOLBAR,
         overflowable: true,
         defaultPlacements: navbarPlacements,
         defaultCollapsed: false,
@@ -587,16 +595,43 @@ var CustomizableUIInternal = {
       let navbarPlacements = gSavedState.placements[CustomizableUI.AREA_NAVBAR];
       // Place the menu item as the first item to the left of the hamburger menu
       if (navbarPlacements) {
         navbarPlacements.push("fxa-toolbar-menu-button");
       }
     }
   },
 
+  _updateForNewProtonVersion() {
+    const VERSION = 1;
+    let currentVersion = Services.prefs.getIntPref(
+      kPrefProtonToolbarVersion,
+      0
+    );
+    if (!gProtonToolbarEnabled || currentVersion >= VERSION) {
+      return;
+    }
+
+    // Remove the home button if it hasn't been used and is set to about:home
+    if (currentVersion < 1) {
+      let placements = gSavedState.placements[CustomizableUI.AREA_NAVBAR];
+      let homePage = HomePage.get();
+      if (
+        placements.includes("home-button") &&
+        !Services.prefs.getBoolPref(kPrefHomeButtonUsed) &&
+        (homePage == "about:home" || homePage == "about:blank") &&
+        Services.policies.isAllowed("removeHomeButtonByDefault")
+      ) {
+        placements.splice(placements.indexOf("home-button"), 1);
+      }
+
+      Services.prefs.setIntPref(kPrefProtonToolbarVersion, VERSION);
+    }
+  },
+
   /**
    * _markObsoleteBuiltinButtonsSeen
    * when upgrading, ensure obsoleted buttons are in seen state.
    */
   _markObsoleteBuiltinButtonsSeen() {
     if (!gSavedState) {
       return;
     }
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -129,16 +129,17 @@ skip-if = os == "linux" # crashing on Li
 tags = fullscreen
 skip-if = os == "mac"
 [browser_1087303_button_preferences.js]
 [browser_1089591_still_customizable_after_reset.js]
 [browser_1096763_seen_widgets_post_reset.js]
 [browser_1161838_inserted_new_default_buttons.js]
 skip-if = verify
 [browser_1484275_PanelMultiView_toggle_with_other_popup.js]
+[browser_1686523_hide_home_button.js]
 [browser_allow_dragging_removable_false.js]
 [browser_bookmarks_toolbar_collapsed_restore_default.js]
 [browser_bookmarks_toolbar_shown_newtab.js]
 [browser_bootstrapped_custom_toolbar.js]
 [browser_character_encoding_ctrl_click.js]
 [browser_ctrl_click_panel_opening.js]
 [browser_currentset_post_reset.js]
 [browser_customizemode_contextmenu_menubuttonstate.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_1686523_hide_home_button.js
@@ -0,0 +1,127 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+"use strict";
+
+/* eslint-disable-next-line mozilla/reject-chromeutils-import-null */
+let CustomizableUIBSPass = ChromeUtils.import(
+  "resource:///modules/CustomizableUI.jsm",
+  null
+);
+
+ChromeUtils.defineModuleGetter(
+  this,
+  "HomePage",
+  "resource:///modules/HomePage.jsm"
+);
+
+const kPrefProtonToolbarEnabled = "browser.proton.toolbar.enabled";
+const kPrefProtonToolbarVersion = "browser.proton.toolbar.version";
+const kPrefHomeButtonUsed = "browser.engagement.home-button.has-used";
+
+async function testHomeButton(shouldRemoveHomeButton, shouldUpdateVersion) {
+  const defaultPlacements = [
+    "back-button",
+    "forward-button",
+    "stop-reload-button",
+    "home-button",
+    "customizableui-special-spring1",
+    "urlbar-container",
+    "customizableui-special-spring2",
+    "downloads-button",
+    "library-button",
+    "sidebar-button",
+    "fxa-toolbar-menu-button",
+  ];
+  let oldState = CustomizableUIBSPass.gSavedState;
+
+  Assert.equal(
+    Services.prefs.getIntPref(kPrefProtonToolbarVersion),
+    0,
+    "Toolbar proton version is 0"
+  );
+
+  let { CustomizableUIInternal } = CustomizableUIBSPass;
+
+  CustomizableUIBSPass.gSavedState = {
+    placements: {
+      "nav-bar": defaultPlacements,
+    },
+  };
+  CustomizableUIInternal._updateForNewProtonVersion();
+
+  let includesHomeButton = CustomizableUIBSPass.gSavedState.placements[
+    "nav-bar"
+  ].includes("home-button");
+
+  Assert.equal(
+    !includesHomeButton,
+    shouldRemoveHomeButton,
+    "Correctly handles home button"
+  );
+
+  let toolbarVersion = Services.prefs.getIntPref(kPrefProtonToolbarVersion);
+  if (shouldUpdateVersion) {
+    Assert.ok(toolbarVersion >= 1, "Toolbar proton version updated");
+  } else {
+    Assert.ok(toolbarVersion == 0, "Toolbar proton version not updated");
+  }
+
+  // Cleanup
+  CustomizableUIBSPass.gSavedState = oldState;
+}
+
+/**
+ * Checks that the home button is removed from the nav-bar under
+ * these conditions: proton must be enabled, the toolbar engagement
+ * pref is false, and the homepage is about:home or about:blank.
+ * Otherwise, the home button should remain if it was previously
+ * in the navbar.
+ */
+add_task(async function() {
+  let tests = [
+    // Proton enabled without engagement
+    {
+      prefs: [[kPrefProtonToolbarEnabled, true]],
+      shouldRemoveHomeButton: true,
+      shouldUpdateVersion: true,
+    },
+    // Proton enabled with engagement
+    {
+      prefs: [
+        [kPrefProtonToolbarEnabled, true],
+        [kPrefHomeButtonUsed, true],
+      ],
+      shouldRemoveHomeButton: false,
+      shouldUpdateVersion: true,
+    },
+    // Proton disabled
+    {
+      prefs: [[kPrefProtonToolbarEnabled, false]],
+      shouldRemoveHomeButton: false,
+      shouldUpdateVersion: false,
+    },
+    // Proton enabled with custom homepage
+    {
+      prefs: [[kPrefProtonToolbarEnabled, true]],
+      shouldRemoveHomeButton: false,
+      shouldUpdateVersion: true,
+      async fn() {
+        HomePage.safeSet("https://example.com");
+      },
+    },
+  ];
+
+  for (let test of tests) {
+    await SpecialPowers.pushPrefEnv({
+      set: [[kPrefProtonToolbarVersion, 0], ...test.prefs],
+    });
+    if (test.fn) {
+      await test.fn();
+    }
+    testHomeButton(test.shouldRemoveHomeButton, test.shouldUpdateVersion);
+    HomePage.reset();
+    await SpecialPowers.popPrefEnv();
+  }
+});
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -1198,16 +1198,19 @@ var Policies = {
           setAndLockPref(
             "pref.browser.homepage.disable_button.bookmark_page",
             true
           );
           setAndLockPref(
             "pref.browser.homepage.disable_button.restore_default",
             true
           );
+          if (param.URL != "about:blank") {
+            manager.disallowFeature("removeHomeButtonByDefault");
+          }
         } else {
           // Clear out old run once modification that is no longer used.
           clearRunOnceModification("setHomepage");
         }
       }
       if (param.StartPage) {
         let prefValue;
         switch (param.StartPage) {