Bug 1455707: Add UI allowing the user to choose what to do when a downgrade is detected. r=gijs draft
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 20 Apr 2018 11:50:57 -0700
changeset 802438 74f50130abddfee6f78193a2fbde5d7a120568a3
parent 802437 95ccfef1c70d169dd19035ef25255dcb5553e985
child 802439 ae69028d7941517b627e4f19d8cd38b2c7d53f7f
push id111878
push userdtownsend@mozilla.com
push dateThu, 31 May 2018 19:46:10 +0000
reviewersgijs
bugs1455707
milestone62.0a1
Bug 1455707: Add UI allowing the user to choose what to do when a downgrade is detected. r=gijs Allows the user to choose whether to open the profile manager, launch the last instance of the application or quit. MozReview-Commit-ID: L9DJQ3WZwhy
browser/components/nsBrowserGlue.js
toolkit/locales/en-US/chrome/mozapps/profile/profileDowngrade.dtd
toolkit/locales/jar.mn
toolkit/locales/moz.build
toolkit/profile/content/profileDowngrade.js
toolkit/profile/content/profileDowngrade.xul
toolkit/profile/jar.mn
toolkit/profile/moz.build
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -1121,16 +1121,22 @@ BrowserGlue.prototype = {
         idleService.removeIdleObserver(this._lateTasksIdleObserver,
                                        LATE_TASKS_IDLE_TIME_SEC);
         delete this._lateTasksIdleObserver;
         this._scheduleArbitrarilyLateIdleTasks();
       }
     };
     this._idleService.addIdleObserver(
       this._lateTasksIdleObserver, LATE_TASKS_IDLE_TIME_SEC);
+
+    let env = Cc["@mozilla.org/process/environment;1"].
+              getService(Ci.nsIEnvironment);
+    if (env.exists("XRE_SETUP_SYNC")) {
+      this._openPreferences("sync");
+    }
   },
 
   /**
    * Use this function as an entry point to schedule tasks that
    * need to run only once after startup, and can be scheduled
    * by using an idle callback.
    *
    * The functions scheduled here will fire from idle callbacks
new file mode 100644
--- /dev/null
+++ b/toolkit/locales/en-US/chrome/mozapps/profile/profileDowngrade.dtd
@@ -0,0 +1,14 @@
+<!-- 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/. -->
+
+<!ENTITY window.title "You’ve launched an older version of &brandShortName;">
+<!ENTITY window.style "width: 40em;">
+
+<!ENTITY window.description "To avoid problem accessing your bookmarks and browsing history, you must choose a different profile.">
+<!ENTITY window.nosync "To launch this version safely, open Profile Manager and choose a different profile.">
+<!ENTITY window.sync "To launch this version safely, open Profile Manager and choose a different profile. Afterwards, sign in with a &syncBrand.fxAccount.label; to sync your bookmarks and browsing history between these profiles.">
+
+<!ENTITY window.manager "Launch Profile Manager">
+<!ENTITY window.launchLast "Exit and Launch Newer Version">
+<!ENTITY window.cancel "Exit">
--- a/toolkit/locales/jar.mn
+++ b/toolkit/locales/jar.mn
@@ -98,16 +98,19 @@
   locale/@AB_CD@/mozapps/handling/handling.dtd                    (%chrome/mozapps/handling/handling.dtd)
   locale/@AB_CD@/mozapps/handling/handling.properties             (%chrome/mozapps/handling/handling.properties)
   locale/@AB_CD@/mozapps/preferences/changemp.dtd                 (%chrome/mozapps/preferences/changemp.dtd)
   locale/@AB_CD@/mozapps/preferences/removemp.dtd                 (%chrome/mozapps/preferences/removemp.dtd)
   locale/@AB_CD@/mozapps/preferences/preferences.properties       (%chrome/mozapps/preferences/preferences.properties)
   locale/@AB_CD@/mozapps/profile/createProfileWizard.dtd          (%chrome/mozapps/profile/createProfileWizard.dtd)
   locale/@AB_CD@/mozapps/profile/profileSelection.properties      (%chrome/mozapps/profile/profileSelection.properties)
   locale/@AB_CD@/mozapps/profile/profileSelection.dtd             (%chrome/mozapps/profile/profileSelection.dtd)
+#ifdef MOZ_BUILD_APP_IS_BROWSER
+  locale/@AB_CD@/mozapps/profile/profileDowngrade.dtd             (%chrome/mozapps/profile/profileDowngrade.dtd)
+#endif
 #ifndef MOZ_FENNEC
   locale/@AB_CD@/mozapps/update/updates.dtd                       (%chrome/mozapps/update/updates.dtd)
   locale/@AB_CD@/mozapps/update/updates.properties                (%chrome/mozapps/update/updates.properties)
 #endif
   locale/@AB_CD@/mozapps/update/history.dtd                       (%chrome/mozapps/update/history.dtd)
   locale/@AB_CD@/mozapps/xpinstall/xpinstallConfirm.dtd           (%chrome/mozapps/extensions/xpinstallConfirm.dtd)
   locale/@AB_CD@/mozapps/xpinstall/xpinstallConfirm.properties    (%chrome/mozapps/extensions/xpinstallConfirm.properties)
 % locale pluginproblem @AB_CD@ %locale/@AB_CD@/pluginproblem/
--- a/toolkit/locales/moz.build
+++ b/toolkit/locales/moz.build
@@ -5,16 +5,19 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files('**'):
     BUG_COMPONENT = ('Firefox Build System', 'General')
 
 if CONFIG['MOZ_BUILD_APP'] == 'mobile/android':
   DEFINES['MOZ_FENNEC'] = True
 
+if CONFIG['MOZ_BUILD_APP'] == 'browser':
+  DEFINES['MOZ_BUILD_APP_IS_BROWSER'] = True
+
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
   DEFINES['MOZ_GTK'] = True
 
 JAR_MANIFESTS += ['jar.mn']
 
 GENERATED_FILES = [
     'multilocale.txt',
 ]
new file mode 100644
--- /dev/null
+++ b/toolkit/profile/content/profileDowngrade.js
@@ -0,0 +1,42 @@
+/* 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/. */
+
+let gParams;
+
+function init() {
+  /*
+   * The C++ code passes a dialog param block using its integers as in and out
+   * arguments for this UI. The following are the uses of the integers:
+   *
+   *  0: 0 or 1 describing whether the selected profile is signed in to sync.
+   *  1: 0 or 1 describing whether the previous binary is available to run.
+   *  2: A return argument, 0 for cancel, 1 for launching the last binart and
+   *     2 for launching the profile manager.
+   */
+  gParams = window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
+  let hasSync = gParams.GetInt(0) == 1;
+  let hasBinary = gParams.GetInt(1) == 1;
+
+  let dialog = document.documentElement;
+  dialog.buttons = hasBinary ? "extra2,accept" : "extra2,cancel";
+  dialog.defaultButton = hasBinary ? "accept" : "cancel";
+
+  document.getElementById("sync").hidden = !hasSync;
+  document.getElementById("nosync").hidden = hasSync;
+}
+
+function cancel() {
+  gParams.SetInt(2, 0);
+  window.close();
+}
+
+function launchLast() {
+  gParams.SetInt(2, 1);
+  window.close();
+}
+
+function launchManager() {
+  gParams.SetInt(2, 2);
+  window.close();
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/profile/content/profileDowngrade.xul
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!-- 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/. -->
+
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE dialog [
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
+%brandDTD;
+<!ENTITY % syncBrandDTD SYSTEM "chrome://browser/locale/syncBrand.dtd">
+%syncBrandDTD;
+<!ENTITY % profileDTD SYSTEM "chrome://mozapps/locale/profile/profileDowngrade.dtd">
+%profileDTD;
+]>
+
+<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="&window.title;" onload="init()" style="&window.style;"
+        buttonlabelextra2="&window.manager;" ondialogextra2="launchManager()"
+        buttonlabelaccept="&window.launchLast;" ondialogaccept="launchLast()"
+        buttonlabelcancel="&window.cancel;" ondialogcancel="cancel()">
+
+  <script type="application/javascript" src="profileDowngrade.js"/>
+
+  <description>&window.description;</description>
+  <description id="nosync">&window.nosync;</description>
+  <description id="sync">&window.sync;</description>
+
+</dialog>
--- a/toolkit/profile/jar.mn
+++ b/toolkit/profile/jar.mn
@@ -2,8 +2,12 @@
 # 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/.
 
 toolkit.jar:
   content/mozapps/profile/createProfileWizard.js  (content/createProfileWizard.js)
 * content/mozapps/profile/createProfileWizard.xul (content/createProfileWizard.xul)
   content/mozapps/profile/profileSelection.js     (content/profileSelection.js)
   content/mozapps/profile/profileSelection.xul    (content/profileSelection.xul)
+#ifdef MOZ_BUILD_APP_IS_BROWSER
+  content/mozapps/profile/profileDowngrade.js     (content/profileDowngrade.js)
+  content/mozapps/profile/profileDowngrade.xul    (content/profileDowngrade.xul)
+#endif
--- a/toolkit/profile/moz.build
+++ b/toolkit/profile/moz.build
@@ -1,16 +1,19 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
 
+if CONFIG['MOZ_BUILD_APP'] == 'browser':
+    DEFINES['MOZ_BUILD_APP_IS_BROWSER'] = True
+
 if CONFIG['ENABLE_TESTS']:
     DIRS += ['gtest']
 
 XPIDL_SOURCES += [
     'nsIProfileMigrator.idl',
     'nsIProfileUnlocker.idl',
     'nsIToolkitProfile.idl',
     'nsIToolkitProfileService.idl',