Bug 1390561 - Add a new param "buttonAutoFocus" for appUpdater object to focus the button automatically because we need auto focus in about dialog but do not need it in preferences page. draft
authorEvan Tseng <evan@tseng.io>
Fri, 18 Aug 2017 16:11:34 +0800
changeset 655516 7e2d372f1e1e482ccdd93f0d00f11013ac7706b0
parent 655385 db7f19e26e571ae1dd309f5d2f387b06ba670c30
child 728853 5f63fd0a58d50b858eedac4e10b3e883f4bd7215
push id76895
push userbmo:evan@tseng.io
push dateWed, 30 Aug 2017 03:21:01 +0000
bugs1390561
milestone57.0a1
Bug 1390561 - Add a new param "buttonAutoFocus" for appUpdater object to focus the button automatically because we need auto focus in about dialog but do not need it in preferences page. MozReview-Commit-ID: KcQVPguaP1o
browser/base/content/aboutDialog-appUpdater.js
browser/base/content/aboutDialog.js
--- a/browser/base/content/aboutDialog-appUpdater.js
+++ b/browser/base/content/aboutDialog-appUpdater.js
@@ -22,27 +22,28 @@ function onUnload(aEvent) {
   if (gAppUpdater.isChecking)
     gAppUpdater.checker.stopChecking(Components.interfaces.nsIUpdateChecker.CURRENT_CHECK);
   // Safe to call even when there isn't a download in progress.
   gAppUpdater.removeDownloadListener();
   gAppUpdater = null;
 }
 
 
-function appUpdater() {
+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");
 
   // 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) {
@@ -181,19 +182,25 @@ appUpdater.prototype =
           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 (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;
     }
-
-    this.updateDeck.selectedPanel = panel;
   },
 
   /**
    * Check for updates
    */
   checkForUpdates() {
     // Clear prefs that could prevent a user from discovering available updates.
     if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CANCELATIONS_OSX)) {
--- a/browser/base/content/aboutDialog.js
+++ b/browser/base/content/aboutDialog.js
@@ -59,23 +59,17 @@ function init(aEvent) {
     let relNotesURL = Services.urlFormatter.formatURLPref("app.releaseNotesURL");
     if (relNotesURL != "about:blank") {
       relNotesLink.href = relNotesURL;
       relNotesLink.hidden = false;
     }
   }
 
   if (AppConstants.MOZ_UPDATER) {
-    gAppUpdater = new appUpdater();
-
-    let button = gAppUpdater.updateDeck.selectedPanel.querySelector("button");
-    if (button && (!document.commandDispatcher.focusedElement || // don't steal the focus
-                   document.commandDispatcher.focusedElement.localName == "button")) { // except from the other buttons
-      button.focus();
-    }
+    gAppUpdater = new appUpdater({ buttonAutoFocus: true });
 
     let channelLabel = document.getElementById("currentChannel");
     let currentChannelText = document.getElementById("currentChannelText");
     channelLabel.value = UpdateUtils.UpdateChannel;
     if (/^release($|\-)/.test(channelLabel.value))
         currentChannelText.hidden = true;
   }