Bug 1510798 - Port bug 1506371 and bug 1506915: Align aboutDialog-appUpdater.js with M-C. r=jorgk
authorRichard Marti <richard.marti@gmail.com>
Thu, 29 Nov 2018 20:41:39 +0100
changeset 32967 785c09b1b20ec61730025cfbdaca35f4c405a291
parent 32966 b3c0c0a2e783ae7ef151b8a5312eafc2cb36f8af
child 32968 9063f5e11b9e74c7d6f1f8239ef9a958af2662c7
push id2343
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:37:21 +0000
treeherdercomm-beta@a0750c375f71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1510798, 1506371, 1506915
Bug 1510798 - Port bug 1506371 and bug 1506915: Align aboutDialog-appUpdater.js with M-C. r=jorgk
mail/app/profile/all-thunderbird.js
mail/base/content/aboutDialog-appUpdater.js
mail/components/preferences/advanced.js
--- a/mail/app/profile/all-thunderbird.js
+++ b/mail/app/profile/all-thunderbird.js
@@ -73,19 +73,18 @@ pref("app.update.certs.1.commonName", "a
 
 pref("app.update.certs.2.issuerName", "CN=thawte SSL CA - G2,O=\"thawte, Inc.\",C=US");
 pref("app.update.certs.2.commonName", "aus5.mozilla.org");
 
 // If set to true, the Update Service will automatically download updates when
 // user can apply updates. This pref is no longer used on Windows, except as the
 // default value to migrate to the new location that this data is now stored
 // (which is in a file in the update directory). Because of this, this pref
-// should no longer be used directly. Instead,
-// nsIUpdateService::getAutoUpdateIsEnabled and
-// nsIUpdateService::setAutoUpdateIsEnabled should be used.
+// should no longer be used directly. Instead, getAppUpdateAutoEnabled and
+// getAppUpdateAutoEnabled from UpdateUtils.jsm should be used.
 #ifndef XP_WIN
  pref("app.update.auto", true);
 #endif
 
 // If set to true, the Update Service will present no UI for any event.
 pref("app.update.silent", false);
 
 // If set to true, the Update Service will apply updates in the background
--- a/mail/base/content/aboutDialog-appUpdater.js
+++ b/mail/base/content/aboutDialog-appUpdater.js
@@ -4,51 +4,58 @@
 
 // Note: this file is included in aboutDialog.xul and preferences/advanced.xul
 // if MOZ_UPDATER is defined.
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
 
+ChromeUtils.defineModuleGetter(this, "UpdateUtils",
+                               "resource://gre/modules/UpdateUtils.jsm");
+
 const PREF_APP_UPDATE_CANCELATIONS_OSX = "app.update.cancelations.osx";
 const PREF_APP_UPDATE_ELEVATE_NEVER    = "app.update.elevate.never";
 
 var gAppUpdater;
 
 function onUnload(aEvent) {
   if (gAppUpdater.isChecking)
     gAppUpdater.checker.stopCurrentCheck();
   // Safe to call even when there isn't a download in progress.
   gAppUpdater.removeDownloadListener();
   gAppUpdater = null;
 }
 
 
-function appUpdater() {
-  this.updateDeck = document.getElementById("updateDeck");
-  // nonsensical line still present in M-C: this.promiseAutoUpdateSetting;
-
-  // Hide the update deck when there is already an update window open to avoid
-  // syncing issues between them.
-  if (Services.wm.getMostRecentWindow("Update:Wizard")) {
-    this.updateDeck.hidden = true;
-    return;
-  }
-
+function appUpdater(options = {}) {
   XPCOMUtils.defineLazyServiceGetter(this, "aus",
                                      "@mozilla.org/updates/update-service;1",
                                      "nsIApplicationUpdateService");
   XPCOMUtils.defineLazyServiceGetter(this, "checker",
                                      "@mozilla.org/updates/update-checker;1",
                                      "nsIUpdateChecker");
   XPCOMUtils.defineLazyServiceGetter(this, "um",
                                      "@mozilla.org/updates/update-manager;1",
                                      "nsIUpdateManager");
 
+  this.options = options;
+  this.updateDeck = document.getElementById("updateDeck");
+  this.promiseAutoUpdateSetting = null;
+
+  // Hide the update deck when the update window is already open and it's not
+  // already applied, to avoid syncing issues between them. Applied updates
+  // don't have any information to sync between the windows as they both just
+  // show the "Restart to continue"-type button.
+  if (Services.wm.getMostRecentWindow("Update:Wizard") &&
+      !this.isApplied) {
+    this.updateDeck.hidden = true;
+    return;
+  }
+
   this.bundle = Services.strings.
                 createBundle("chrome://messenger/locale/messenger.properties");
 
   let manualURL = Services.urlFormatter.formatURLPref("app.update.url.manual");
   document.getElementById("manualLink")
           .setAttribute("onclick", 'openURL("' + manualURL + '");');
   document.getElementById("failedLink")
           .setAttribute("onclick", 'openURL("' + manualURL + '");');
@@ -70,17 +77,17 @@ function appUpdater() {
 
   if (this.isDownloading) {
     this.startDownload();
     // selectPanel("downloading") is called from setupDownloadingUI().
     return;
   }
 
   // We might need this value later, so start loading it from the disk now.
-  this.promiseAutoUpdateSetting = this.aus.getAutoUpdateIsEnabled();
+  this.promiseAutoUpdateSetting = UpdateUtils.getAppUpdateAutoEnabled();
 
   // That leaves the options
   // "Check for updates, but let me choose whether to install them", and
   // "Automatically install updates".
   // In both cases, we check for updates without asking.
   // In the "let me choose" case, we ask before downloading though, in onCheckComplete.
   this.checkForUpdates();
 }
@@ -99,37 +106,35 @@ appUpdater.prototype = {
     return this.um.activeUpdate &&
            (this.um.activeUpdate.state == "pending" ||
             this.um.activeUpdate.state == "pending-service" ||
             this.um.activeUpdate.state == "pending-elevate");
   },
 
   // true when there is an update already installed in the background.
   get isApplied() {
-    if (this.update) {
+    if (this.update)
       return this.update.state == "applied" ||
              this.update.state == "applied-service";
-    }
     return this.um.activeUpdate &&
            (this.um.activeUpdate.state == "applied" ||
             this.um.activeUpdate.state == "applied-service");
   },
 
   // true when there is an update download in progress.
   get isDownloading() {
     if (this.update)
       return this.update.state == "downloading";
     return this.um.activeUpdate &&
            this.um.activeUpdate.state == "downloading";
   },
 
-  // true when updating has been disabled by enterprise policy. Not yet used.
+  // true when updating has been disabled by enterprise policy
   get updateDisabledByPolicy() {
-    return Services.policies &&
-           !Services.policies.isAllowed("appUpdate");
+    return Services.policies && !Services.policies.isAllowed("appUpdate");
   },
 
   // true when updating in background is enabled.
   get backgroundUpdateEnabled() {
     return !this.updateDisabledByPolicy &&
            gAppUpdater.aus.canStageUpdates;
   },
 
@@ -141,32 +146,33 @@ appUpdater.prototype = {
    */
   selectPanel(aChildID) {
     let panel = document.getElementById(aChildID);
 
     let button = panel.querySelector("button");
     if (button) {
       if (aChildID == "downloadAndInstall") {
         let updateVersion = gAppUpdater.update.displayVersion;
-        // Include the build ID if this is an "a#" (nightly) build
+        // Include the build ID if this is an "a#" (nightly or aurora) build
         if (/a\d+$/.test(updateVersion)) {
           let buildID = gAppUpdater.update.buildID;
           let year = buildID.slice(0, 4);
           let month = buildID.slice(4, 6);
           let day = buildID.slice(6, 8);
           updateVersion += ` (${year}-${month}-${day})`;
         }
         button.label = this.bundle.formatStringFromName("update.downloadAndInstallButton.label", [updateVersion], 1);
         button.accessKey = this.bundle.GetStringFromName("update.downloadAndInstallButton.accesskey");
       }
       this.updateDeck.selectedPanel = panel;
-      if (!document.commandDispatcher.focusedElement || // don't steal the focus
-          document.commandDispatcher.focusedElement.localName == "button") // except from the other buttons
+      if (this.options.buttonAutoFocus &&
+          (!document.commandDispatcher.focusedElement || // don't steal the focus
+           document.commandDispatcher.focusedElement.localName == "button")) { // except from the other buttons
         button.focus();
-
+      }
     } else {
       this.updateDeck.selectedPanel = panel;
     }
   },
 
   /**
    * Check for updates
    */
@@ -188,33 +194,37 @@ appUpdater.prototype = {
    * Handles oncommand for the "Restart to Update" button
    * which is presented after the download has been downloaded.
    */
   buttonRestartAfterDownload() {
     if (!this.isPending && !this.isApplied) {
       return;
     }
 
+    gAppUpdater.selectPanel("restarting");
+
     // Notify all windows that an application quit has been requested.
     let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].
                      createInstance(Ci.nsISupportsPRBool);
     Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
     // Something aborted the quit process.
     if (cancelQuit.data) {
+      gAppUpdater.selectPanel("apply");
       return;
     }
 
     // If already in safe mode restart in safe mode (bug 327119)
     if (Services.appinfo.inSafeMode) {
-      Services.startup.restartInSafeMode(Services.startup.eAttemptQuit);
+      Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
       return;
     }
 
-    Services.startup.quit(Services.startup.eAttemptQuit | Services.startup.eRestart);
+    Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit |
+                          Ci.nsIAppStartup.eRestart);
   },
 
   /**
    * Implements nsIUpdateCheckListener. The methods implemented by
    * nsIUpdateCheckListener are in a different scope from nsIIncrementalDownload
    * to make it clear which are used by each interface.
    */
   updateCheckListener: {
@@ -242,17 +252,17 @@ appUpdater.prototype = {
       }
 
       if (!gAppUpdater.aus.canApplyUpdates) {
         gAppUpdater.selectPanel("manualUpdate");
         return;
       }
 
       if (!gAppUpdater.promiseAutoUpdateSetting) {
-        gAppUpdater.promiseAutoUpdateSetting = gAppUpdater.aus.getAutoUpdateIsEnabled();
+        gAppUpdater.promiseAutoUpdateSetting = UpdateUtils.getAppUpdateAutoEnabled();
       }
       gAppUpdater.promiseAutoUpdateSetting.then(updateAuto => {
         if (updateAuto) { // automatically download and install
           gAppUpdater.startDownload();
         } else { // ask
           gAppUpdater.selectPanel("downloadAndInstall");
         }
       });
@@ -337,17 +347,17 @@ appUpdater.prototype = {
     case Cr.NS_BINDING_ABORTED:
       // Do not remove UI listener since the user may resume downloading again.
       break;
     case Cr.NS_OK:
       this.removeDownloadListener();
       if (this.backgroundUpdateEnabled) {
         this.selectPanel("applying");
         let self = this;
-        Services.obs.addObserver(function selectPanelOnUpdate(aSubject, aTopic, aData) {
+        Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
           // Update the UI when the background updater is finished
           let status = aData;
           if (status == "applied" || status == "applied-service" ||
               status == "pending" || status == "pending-service" ||
               status == "pending-elevate") {
             // If the update is successfully applied, or if the updater has
             // fallen back to non-staged updates, show the "Restart to Update"
             // button.
@@ -358,17 +368,17 @@ appUpdater.prototype = {
             self.selectPanel("downloadFailed");
           } else if (status == "downloading") {
             // We've fallen back to downloading the full update because the
             // partial update failed to get staged in the background.
             // Therefore we need to keep our observer.
             self.setupDownloadingUI();
             return;
           }
-          Services.obs.removeObserver(selectPanelOnUpdate, "update-staged");
+          Services.obs.removeObserver(observer, "update-staged");
         }, "update-staged");
       } else {
         this.selectPanel("apply");
       }
       break;
     default:
       this.removeDownloadListener();
       this.selectPanel("downloadFailed");
@@ -388,11 +398,10 @@ appUpdater.prototype = {
   onProgress(aRequest, aContext, aProgress, aProgressMax) {
     this.downloadStatus.value =
       DownloadUtils.getTransferTotal(aProgress, aProgressMax);
   },
 
   /**
    * See nsISupports.idl
    */
-  QueryInterface: ChromeUtils.generateQI(["nsIProgressEventSink",
-                                          "nsIRequestObserver"]),
+  QueryInterface: ChromeUtils.generateQI(["nsIProgressEventSink", "nsIRequestObserver"]),
 };
--- a/mail/components/preferences/advanced.js
+++ b/mail/components/preferences/advanced.js
@@ -8,20 +8,18 @@
 
 // Load DownloadUtils module for convertByteUnits
 ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
 ChromeUtils.import("resource://gre/modules/Localization.jsm");
-
-XPCOMUtils.defineLazyServiceGetters(this, {
-  gAUS: ["@mozilla.org/updates/update-service;1", "nsIApplicationUpdateService"],
-});
+ChromeUtils.defineModuleGetter(this, "UpdateUtils",
+  "resource://gre/modules/UpdateUtils.jsm");
 
 const AUTO_UPDATE_CHANGED_TOPIC = "auto-update-config-change";
 
 var gAdvancedPane = {
   mPane: null,
   mInitialized: false,
   mShellServiceWorking: false,
   mBundle: null,
@@ -317,17 +315,17 @@ var gAdvancedPane = {
    * Selects the correct item in the update radio group
    */
   async updateReadPrefs() {
     if (AppConstants.MOZ_UPDATER &&
         (!Services.policies || Services.policies.isAllowed("appUpdate"))) {
       let radiogroup = document.getElementById("updateRadioGroup");
       radiogroup.disabled = true;
       try {
-        let enabled = await gAUS.getAutoUpdateIsEnabled();
+        let enabled = await UpdateUtils.getAppUpdateAutoEnabled();
         radiogroup.value = enabled;
         radiogroup.disabled = false;
       } catch (error) {
         Cu.reportError(error);
       }
     }
   },
 
@@ -336,17 +334,17 @@ var gAdvancedPane = {
    */
   async updateWritePrefs() {
     if (AppConstants.MOZ_UPDATER &&
         (!Services.policies || Services.policies.isAllowed("appUpdate"))) {
       let radiogroup = document.getElementById("updateRadioGroup");
       let updateAutoValue = (radiogroup.value == "true");
       radiogroup.disabled = true;
       try {
-        await gAUS.setAutoUpdateIsEnabled(updateAutoValue);
+        await UpdateUtils.setAppUpdateAutoEnabled(updateAutoValue);
         radiogroup.disabled = false;
       } catch (error) {
         Cu.reportError(error);
         await this.updateReadPrefs();
         await this.reportUpdatePrefWriteError(error);
       }
     }
   },