Bug 1300376 - Update the zoom indicator status on XULBrowserWindow location changes to catch cases where the indicator wasn't getting updated such as swapping doc shells. r=Gijs
authorJared Wein <jwein@mozilla.com>
Tue, 01 Nov 2016 15:25:06 -0400
changeset 347127 dad84422bcfccd4ebfda9c93b475527aa502f10d
parent 347126 0b3122d59d17056b6d0142f74a0a4bff78f56ece
child 347128 c88863b6401043a0b951a6ddd983d0ca3b93e1d3
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1300376
milestone52.0a1
Bug 1300376 - Update the zoom indicator status on XULBrowserWindow location changes to catch cases where the indicator wasn't getting updated such as swapping doc shells. r=Gijs MozReview-Commit-ID: 9Qk3Aa0W8Vl
browser/base/content/browser.js
browser/modules/URLBarZoom.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -45,16 +45,17 @@ Cu.import("resource://gre/modules/Notifi
   ["SimpleServiceDiscovery", "resource://gre/modules/SimpleServiceDiscovery.jsm"],
   ["SitePermissions", "resource:///modules/SitePermissions.jsm"],
   ["Social", "resource:///modules/Social.jsm"],
   ["TabCrashHandler", "resource:///modules/ContentCrashHandlers.jsm"],
   ["Task", "resource://gre/modules/Task.jsm"],
   ["TelemetryStopwatch", "resource://gre/modules/TelemetryStopwatch.jsm"],
   ["Translation", "resource:///modules/translation/Translation.jsm"],
   ["UITour", "resource:///modules/UITour.jsm"],
+  ["URLBarZoom", "resource:///modules/URLBarZoom.jsm"],
   ["UpdateUtils", "resource://gre/modules/UpdateUtils.jsm"],
   ["Weave", "resource://services-sync/main.js"],
   ["fxAccounts", "resource://gre/modules/FxAccounts.jsm"],
   ["gDevTools", "resource://devtools/client/framework/gDevTools.jsm"],
   ["gDevToolsBrowser", "resource://devtools/client/framework/gDevTools.jsm"],
   ["webrtcUI", "resource:///modules/webrtcUI.jsm", ]
 ].forEach(([name, resource]) => XPCOMUtils.defineLazyModuleGetter(this, name, resource));
 
@@ -4450,26 +4451,23 @@ var XULBrowserWindow = {
           location == "") {  // Second condition is for new tabs, otherwise
                              // reload function is enabled until tab is refreshed.
         this.reloadCommand.setAttribute("disabled", "true");
       } else {
         this.reloadCommand.removeAttribute("disabled");
       }
 
       URLBarSetURI(aLocationURI);
-
       BookmarkingUI.onLocationChange();
-
       gIdentityHandler.onLocationChange();
-
       SocialUI.updateState();
-
       UITour.onLocationChange(location);
-
       gTabletModePageCounter.inc();
+      ReaderParent.updateReaderButton(gBrowser.selectedBrowser);
+      URLBarZoom.updateZoomButton(gBrowser.selectedBrowser, "browser-fullZoom:location-change");
 
       // Utility functions for disabling find
       var shouldDisableFind = function shouldDisableFind(aDocument) {
         let docElt = aDocument.documentElement;
         return docElt && docElt.getAttribute("disablefastfind") == "true";
       }
 
       var disableFindCommands = function disableFindCommands(aDisable) {
@@ -4513,17 +4511,16 @@ var XULBrowserWindow = {
           gBrowser.selectedTab.hasAttribute("customizemode")) {
         gCustomizeMode.enter();
       } else if (CustomizationHandler.isEnteringCustomizeMode ||
                  CustomizationHandler.isCustomizing()) {
         gCustomizeMode.exit();
       }
     }
     UpdateBackForwardCommands(gBrowser.webNavigation);
-    ReaderParent.updateReaderButton(gBrowser.selectedBrowser);
 
     gGestureSupport.restoreRotationState();
 
     // See bug 358202, when tabs are switched during a drag operation,
     // timers don't fire on windows (bug 203573)
     if (aRequest)
       setTimeout(function () { XULBrowserWindow.asyncUpdateUI(); }, 0);
     else
--- a/browser/modules/URLBarZoom.jsm
+++ b/browser/modules/URLBarZoom.jsm
@@ -6,46 +6,57 @@
 "use strict";
 
 this.EXPORTED_SYMBOLS = [ "URLBarZoom" ];
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 var URLBarZoom = {
 
-  init: function(aWindow) {
+  init(aWindow) {
     // Register ourselves with the service so we know when the zoom prefs change.
-    Services.obs.addObserver(updateZoomButton, "browser-fullZoom:zoomChange", false);
-    Services.obs.addObserver(updateZoomButton, "browser-fullZoom:zoomReset", false);
-    Services.obs.addObserver(updateZoomButton, "browser-fullZoom:location-change", false);
+    Services.obs.addObserver(this, "browser-fullZoom:zoomChange", false);
+    Services.obs.addObserver(this, "browser-fullZoom:zoomReset", false);
+    Services.obs.addObserver(this, "browser-fullZoom:location-change", false);
+  },
+
+  observe(aSubject, aTopic) {
+    this.updateZoomButton(aSubject, aTopic);
   },
-}
 
-function updateZoomButton(aSubject, aTopic) {
-  let win = aSubject.ownerDocument.defaultView;
-  let customizableZoomControls = win.document.getElementById("zoom-controls");
-  let zoomResetButton = win.document.getElementById("urlbar-zoom-button");
-  let zoomFactor = Math.round(win.ZoomManager.zoom * 100);
+  updateZoomButton(aSubject, aTopic) {
+    // aSubject.ownerGlobal may no longer exist if a tab has been dragged to a
+    // new window. In this case, aSubject.ownerGlobal will be supplied by
+    // updateZoomButton() called in XULBrowserWindow.onLocationChange().
+    if (!aSubject.ownerGlobal) {
+      return;
+    }
+
+    let win = aSubject.ownerGlobal;
+    let customizableZoomControls = win.document.getElementById("zoom-controls");
+    let zoomResetButton = win.document.getElementById("urlbar-zoom-button");
+    let zoomFactor = Math.round(win.ZoomManager.zoom * 100);
 
-  // Ensure that zoom controls haven't already been added to browser in Customize Mode
-  if (customizableZoomControls &&
-      customizableZoomControls.getAttribute("cui-areatype") == "toolbar") {
-    zoomResetButton.hidden = true;
-    return;
-  }
-  if (zoomFactor != 100) {
-    // Check if zoom button is visible and update label if it is
-    if (zoomResetButton.hidden) {
-      zoomResetButton.hidden = false;
+    // Ensure that zoom controls haven't already been added to browser in Customize Mode
+    if (customizableZoomControls &&
+        customizableZoomControls.getAttribute("cui-areatype") == "toolbar") {
+      zoomResetButton.hidden = true;
+      return;
     }
-    // Only allow pulse animation for zoom changes, not tab switching
-    if (aTopic != "browser-fullZoom:location-change") {
-      zoomResetButton.setAttribute("animate", "true");
+    if (zoomFactor != 100) {
+      // Check if zoom button is visible and update label if it is
+      if (zoomResetButton.hidden) {
+        zoomResetButton.hidden = false;
+      }
+      // Only allow pulse animation for zoom changes, not tab switching
+      if (aTopic != "browser-fullZoom:location-change") {
+        zoomResetButton.setAttribute("animate", "true");
+      } else {
+        zoomResetButton.removeAttribute("animate");
+      }
+      zoomResetButton.setAttribute("label",
+        win.gNavigatorBundle.getFormattedString("urlbar-zoom-button.label", [zoomFactor]));
     } else {
-      zoomResetButton.removeAttribute("animate");
+      // Hide button if zoom is at 100%
+      zoomResetButton.hidden = true;
     }
-    zoomResetButton.setAttribute("label",
-        win.gNavigatorBundle.getFormattedString("urlbar-zoom-button.label", [zoomFactor]));
-  // Hide button if zoom is at 100%
-  } else {
-      zoomResetButton.hidden = true;
-  }
-}
+  },
+};