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. r=jaws
authorEvan Tseng <evan@tseng.io>
Fri, 18 Aug 2017 16:11:34 +0800
changeset 377783 873f47053dd68c5f5a5550c2a8517b050e2625b1
parent 377782 54c1e69db5b309d72224ed5880089a8896ff3ca5
child 377784 1a1f4fe397d9c41e71b44645c85399ae0726bfd1
push id94338
push userkwierso@gmail.com
push dateThu, 31 Aug 2017 02:58:58 +0000
treeherdermozilla-inbound@9ca18987dabb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1390561
milestone57.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 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. r=jaws 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;
   }