Bug 1522856 - Add an "import" option to the file menu to make browser migration discoverable. r=MattN,felipe
authorSoeren Hentzschel <cadeyrn@ymail.com>
Mon, 04 Mar 2019 15:29:03 -0800
changeset 462320 dfeea1a4375a8c70d1700f9a2a4bad3fd0e1397e
parent 462319 5a124664ca71877aa4835efd224c95f7e8b9f5e5
child 462321 bd4cd4017fd48b359d44c1436f2cde8bfa714924
push id35647
push useraciure@mozilla.com
push dateTue, 05 Mar 2019 04:21:25 +0000
treeherdermozilla-central@c59f0f40e0f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, felipe
bugs1522856
milestone67.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 1522856 - Add an "import" option to the file menu to make browser migration discoverable. r=MattN,felipe Differential Revision: https://phabricator.services.mozilla.com/D19274
browser/base/content/browser-menubar.inc
browser/base/content/browser-sets.inc
browser/base/content/browser.js
browser/base/content/test/menubar/.eslintrc.js
browser/base/content/test/menubar/browser.ini
browser/base/content/test/menubar/browser_file_menu_import_wizard.js
browser/base/content/utilityOverlay.js
browser/base/moz.build
browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js
browser/components/migration/MigrationUtils.jsm
browser/locales/en-US/chrome/browser/browser.dtd
toolkit/components/telemetry/Histograms.json
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -6,17 +6,18 @@
        <menubar id="main-menubar"
                 onpopupshowing="if (event.target.parentNode.parentNode == this &amp;&amp;
                                     !('@mozilla.org/widget/nativemenuservice;1' in Cc))
                                   this.setAttribute('openedwithkey',
                                                     event.target.parentNode.openedWithKey);">
             <menu id="file-menu" label="&fileMenu.label;"
                   accesskey="&fileMenu.accesskey;">
               <menupopup id="menu_FilePopup"
-                         onpopupshowing="updateFileMenuUserContextUIVisibility('menu_newUserContext');">
+                         onpopupshowing="updateFileMenuUserContextUIVisibility('menu_newUserContext');
+                                         updateFileMenuImportUIVisibility('cmd_importFromAnotherBrowser');">
                 <menuitem id="menu_newNavigatorTab"
                           label="&tabCmd.label;"
                           command="cmd_newNavigatorTab"
                           key="key_newNavigatorTab"
                           accesskey="&tabCmd.accesskey;"/>
                 <menu id="menu_newUserContext"
                       label="&newUserContext.label;"
                       accesskey="&newUserContext.accesskey;"
@@ -80,16 +81,21 @@
                           command="cmd_printPreview"/>
 #endif
                 <menuitem id="menu_print"
                           label="&printCmd.label;"
                           accesskey="&printCmd.accesskey;"
                           key="printKb"
                           command="cmd_print"/>
                 <menuseparator/>
+                <menuitem id="menu_importFromAnotherBrowser"
+                          label="&importFromAnotherBrowserCmd.label;"
+                          accesskey="&importFromAnotherBrowserCmd.accesskey;"
+                          command="cmd_importFromAnotherBrowser"/>
+                <menuseparator/>
                 <menuitem id="goOfflineMenuitem"
                           label="&goOfflineCmd.label;"
                           accesskey="&goOfflineCmd.accesskey;"
                           type="checkbox"
                           command="cmd_toggleOfflineStatus"/>
                 <menuitem id="menu_FileQuitItem"
 #ifdef XP_WIN
                           label="&quitApplicationCmdWin2.label;"
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -27,16 +27,17 @@
     <command id="Browser:SavePage" oncommand="saveBrowser(gBrowser.selectedBrowser);"/>
 
     <command id="Browser:SendLink"
              oncommand="MailIntegration.sendLinkForBrowser(gBrowser.selectedBrowser);"/>
 
     <command id="cmd_pageSetup" oncommand="PrintUtils.showPageSetup();"/>
     <command id="cmd_print" oncommand="PrintUtils.printWindow(window.gBrowser.selectedBrowser.outerWindowID, window.gBrowser.selectedBrowser);"/>
     <command id="cmd_printPreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
+    <command id="cmd_importFromAnotherBrowser" oncommand="MigrationUtils.showMigrationWizard(window, [MigrationUtils.MIGRATION_ENTRYPOINT_FILE_MENU]);"/>
     <command id="cmd_close" oncommand="BrowserCloseTabOrWindow(event);"/>
     <command id="cmd_closeWindow" oncommand="BrowserTryToCloseWindow()"/>
     <command id="cmd_toggleMute" oncommand="gBrowser.toggleMuteAudioOnMultiSelectedTabs(gBrowser.selectedTab)"/>
     <command id="cmd_CustomizeToolbars" oncommand="gCustomizeMode.enter()"/>
     <command id="cmd_toggleOfflineStatus" oncommand="BrowserOffline.toggleOfflineStatus();"/>
     <command id="cmd_quitApplication" oncommand="goQuitApplication()"/>
 
 #include ../../../toolkit/content/editMenuCommands.inc.xul
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -28,16 +28,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
   E10SUtils: "resource://gre/modules/E10SUtils.jsm",
   ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
   FormValidationHandler: "resource:///modules/FormValidationHandler.jsm",
   HomePage: "resource:///modules/HomePage.jsm",
   LightweightThemeConsumer: "resource://gre/modules/LightweightThemeConsumer.jsm",
   LightweightThemeManager: "resource://gre/modules/LightweightThemeManager.jsm",
   Log: "resource://gre/modules/Log.jsm",
   LoginManagerParent: "resource://gre/modules/LoginManagerParent.jsm",
+  MigrationUtils: "resource:///modules/MigrationUtils.jsm",
   NetUtil: "resource://gre/modules/NetUtil.jsm",
   NewTabUtils: "resource://gre/modules/NewTabUtils.jsm",
   OpenInTabsUtils: "resource:///modules/OpenInTabsUtils.jsm",
   PageActions: "resource:///modules/PageActions.jsm",
   PageThumbs: "resource://gre/modules/PageThumbs.jsm",
   PanelMultiView: "resource:///modules/PanelMultiView.jsm",
   PanelView: "resource:///modules/PanelMultiView.jsm",
   PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/menubar/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/browser-test"
+  ]
+};
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/menubar/browser.ini
@@ -0,0 +1,3 @@
+[DEFAULT]
+
+[browser_file_menu_import_wizard.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/menubar/browser_file_menu_import_wizard.js
@@ -0,0 +1,13 @@
+add_task(async function file_menu_import_wizard() {
+  // We can't call this code directly or our JS execution will get blocked on Windows/Linux where
+  // the dialog is modal.
+  executeSoon(() => document.getElementById("menu_importFromAnotherBrowser").doCommand());
+
+  await TestUtils.waitForCondition(() => Services.wm.getMostRecentWindow("Browser:MigrationWizard"),
+                                   "Migrator window opened");
+
+  let migratorWindow = Services.wm.getMostRecentWindow("Browser:MigrationWizard");
+  ok(migratorWindow, "Migrator window opened");
+
+  await BrowserTestUtils.closeWindow(migratorWindow);
+});
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -1068,8 +1068,19 @@ function trimURL(aURL) {
   } catch (ex) {
     return url;
   }
   if (fixedUpURL.displaySpec == expectedURLSpec) {
     return urlWithoutProtocol;
   }
   return url;
 }
+
+/**
+ * Updates visibility of "Import From Another Browser" command depending on
+ * the DisableProfileImport policy.
+ */
+function updateFileMenuImportUIVisibility(id) {
+  if (!Services.policies.isAllowed("profileImport")) {
+    let command = document.getElementById(id);
+    command.setAttribute("disabled", "true");
+  }
+}
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -26,16 +26,17 @@ BROWSER_CHROME_MANIFESTS += [
     'content/test/alerts/browser.ini',
     'content/test/captivePortal/browser.ini',
     'content/test/contextMenu/browser.ini',
     'content/test/favicons/browser.ini',
     'content/test/forms/browser.ini',
     'content/test/general/browser.ini',
     'content/test/historySwipeAnimation/browser.ini',
     'content/test/keyboard/browser.ini',
+    'content/test/menubar/browser.ini',
     'content/test/metaTags/browser.ini',
     'content/test/pageActions/browser.ini',
     'content/test/pageinfo/browser.ini',
     'content/test/performance/browser.ini',
     'content/test/performance/hidpi/browser.ini',
     'content/test/performance/legacyurlbar/browser.ini',
     'content/test/performance/lowdpi/browser.ini',
     'content/test/permissions/browser.ini',
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js
@@ -29,8 +29,24 @@ add_task(async function test_disable_pro
   let promisePopupHidden = BrowserTestUtils.waitForEvent(menu, "popuphidden");
   menu.hidePopup();
   await promisePopupHidden;
 
   await BrowserTestUtils.closeWindow(library);
 
   checkLockedPref("browser.newtabpage.activity-stream.migrationExpired", true);
 });
+
+add_task(async function test_file_menu() {
+  updateFileMenuImportUIVisibility("cmd_importFromAnotherBrowser");
+
+  let command = document.getElementById("cmd_importFromAnotherBrowser");
+  ok(command.getAttribute("disabled"),
+     "The `Import from Another Browser…` menu item command should be disabled");
+
+  if (Services.appinfo.OS == "Darwin") {
+    // We would need to have a lot of boilerplate to open the menus on Windows
+    // and Linux to test this there.
+    let menuitem = document.getElementById("menu_importFromAnotherBrowser");
+    ok(menuitem.disabled,
+       "The `Import from Another Browser…` menu item should be disabled");
+  }
+});
--- a/browser/components/migration/MigrationUtils.jsm
+++ b/browser/components/migration/MigrationUtils.jsm
@@ -1142,16 +1142,17 @@ var MigrationUtils = Object.freeze({
   gAvailableMigratorKeys,
 
   MIGRATION_ENTRYPOINT_UNKNOWN: 0,
   MIGRATION_ENTRYPOINT_FIRSTRUN: 1,
   MIGRATION_ENTRYPOINT_FXREFRESH: 2,
   MIGRATION_ENTRYPOINT_PLACES: 3,
   MIGRATION_ENTRYPOINT_PASSWORDS: 4,
   MIGRATION_ENTRYPOINT_NEWTAB: 5,
+  MIGRATION_ENTRYPOINT_FILE_MENU: 6,
 
   _sourceNameToIdMapping: {
     "nothing":    1,
     "firefox":    2,
     "edge":       3,
     "ie":         4,
     "chrome":     5,
     "chromium":   6,
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -124,16 +124,18 @@ when there are no windows but Firefox is
 <!ENTITY openFileCmd.commandkey "o">
 <!ENTITY printSetupCmd.label "Page Setup…">
 <!ENTITY printSetupCmd.accesskey "u">
 <!ENTITY printPreviewCmd.label "Print Preview">
 <!ENTITY printPreviewCmd.accesskey "v">
 <!ENTITY printCmd.label "Print…">
 <!ENTITY printCmd.accesskey "P">
 <!ENTITY printCmd.commandkey "p">
+<!ENTITY importFromAnotherBrowserCmd.label "Import from Another Browser…">
+<!ENTITY importFromAnotherBrowserCmd.accesskey "I">
 
 <!ENTITY taskManagerCmd.label "Task Manager">
 
 <!ENTITY goOfflineCmd.label "Work Offline">
 <!ENTITY goOfflineCmd.accesskey "k">
 
 <!ENTITY menubarCmd.label "Menu Bar">
 <!ENTITY menubarCmd.accesskey "M">
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -6302,17 +6302,17 @@
   "FX_MIGRATION_ENTRY_POINT": {
     "record_in_processes": ["main", "content"],
     "bug_numbers": [731025],
     "alert_emails": ["gijs@mozilla.com"],
     "expires_in_version": "65",
     "kind": "enumerated",
     "n_values": 10,
     "releaseChannelCollection": "opt-out",
-    "description": "Where the migration wizard was entered from. 0=Other/catch-all, 1=first-run, 2=refresh-firefox, 3=Places window, 4=Password manager"
+    "description": "Where the migration wizard was entered from. 0=Other/catch-all, 1=first-run, 2=refresh-firefox, 3=Places window, 4=Password manager, 5=New tab, 6=File menu"
   },
   "FX_MIGRATION_SOURCE_BROWSER": {
     "record_in_processes": ["main", "content"],
     "bug_numbers": [731025],
     "alert_emails": ["gijs@mozilla.com"],
     "expires_in_version": "65",
     "kind": "enumerated",
     "n_values": 15,