Bug 1378819 - fix combined stop/reload button not working in the overflow menu, r?jaws
MozReview-Commit-ID: LXRbfRsKBC6
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1354,17 +1354,17 @@ var gBrowserInit = {
if (!window.toolbar.visible) {
// adjust browser UI for popups
gURLBar.setAttribute("readonly", "true");
gURLBar.setAttribute("enablehistory", "false");
}
// Misc. inits.
TabletModeUpdater.init();
- CombinedStopReload.init();
+ CombinedStopReload.ensureInitialized();
gPrivateBrowsingUI.init();
BrowserPageActions.init();
gAccessibilityServiceIndicator.init();
if (window.matchMedia("(-moz-os-version: windows-win8)").matches &&
window.matchMedia("(-moz-windows-default-theme)").matches) {
let windowFrameColor = new Color(...Cu.import("resource:///modules/Windows8WindowFrameColor.jsm", {})
.Windows8WindowFrameColor.get());
@@ -4919,42 +4919,55 @@ var LinkTargetDisplay = {
_hide() {
clearTimeout(this._timer);
XULBrowserWindow.updateStatusField();
}
};
var CombinedStopReload = {
- init() {
+ // Try to initialize. Returns whether initialization was successful, which
+ // may mean we had already initialized.
+ ensureInitialized() {
if (this._initialized)
- return;
+ return true;
+ if (this._destroyed)
+ return false;
let reload = document.getElementById("reload-button");
let stop = document.getElementById("stop-button");
- if (!stop || !reload || reload.nextSibling != stop)
- return;
+ // It's possible the stop/reload buttons have been moved to the palette.
+ // They may be reinserted later, so we will retry initialization if/when
+ // we get notified of document loads.
+ if (!stop || !reload)
+ return false;
this._initialized = true;
if (XULBrowserWindow.stopCommand.getAttribute("disabled") != "true")
reload.setAttribute("displaystop", "true");
stop.addEventListener("click", this);
this.reload = reload;
this.stop = stop;
this.stopReloadContainer = this.reload.parentNode;
this.timeWhenSwitchedToStop = 0;
+
+ if (this._shouldStartPrefMonitoring) {
+ this.startAnimationPrefMonitoring();
+ }
+ return true;
},
uninit() {
+ this._destroyed = true;
+
if (!this._initialized)
return;
Services.prefs.removeObserver("toolkit.cosmeticAnimations.enabled", this);
this._cancelTransition();
- this._initialized = false;
this.stop.removeEventListener("click", this);
this.stopReloadContainer.removeEventListener("animationend", this);
this.stopReloadContainer = null;
this.reload = null;
this.stop = null;
},
handleEvent(event) {
@@ -4979,33 +4992,37 @@ var CombinedStopReload = {
observe(subject, topic, data) {
if (topic == "nsPref:changed") {
this.animate = Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled");
}
},
startAnimationPrefMonitoring() {
// CombinedStopReload may have been uninitialized before the idleCallback is executed.
- if (!this._initialized)
+ if (this._destroyed)
return;
+ if (!this.ensureInitialized()) {
+ this._shouldStartPrefMonitoring = true;
+ return;
+ }
this.animate = Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled") &&
Services.prefs.getBoolPref("browser.stopReloadAnimation.enabled");
Services.prefs.addObserver("toolkit.cosmeticAnimations.enabled", this);
this.stopReloadContainer.addEventListener("animationend", this);
},
onTabSwitch() {
// Reset the time in the event of a tabswitch since the stored time
// would have been associated with the previous tab, so the animation will
// still run if the page has been loading until long after the tab switch.
this.timeWhenSwitchedToStop = window.performance.now();
},
switchToStop(aRequest, aWebProgress) {
- if (!this._initialized || !this._shouldSwitch(aRequest, aWebProgress)) {
+ if (!this.ensureInitialized() || !this._shouldSwitch(aRequest, aWebProgress)) {
return;
}
// Store the time that we switched to the stop button only if a request
// is active. Requests are null if the switch is related to a tabswitch.
// This is used to determine if we should show the stop->reload animation.
if (aRequest instanceof Ci.nsIRequest) {
this.timeWhenSwitchedToStop = window.performance.now();
@@ -5024,17 +5041,17 @@ var CombinedStopReload = {
this.stopReloadContainer.setAttribute("animate", "true");
} else {
this.stopReloadContainer.removeAttribute("animate");
}
this.reload.setAttribute("displaystop", "true");
},
switchToReload(aRequest, aWebProgress) {
- if (!this._initialized || !this._shouldSwitch(aRequest, aWebProgress) ||
+ if (!this.ensureInitialized() || !this._shouldSwitch(aRequest, aWebProgress) ||
!this.reload.hasAttribute("displaystop")) {
return;
}
let shouldAnimate = aRequest instanceof Ci.nsIRequest &&
aWebProgress.isTopLevel &&
!aWebProgress.isLoadingDocument &&
!gBrowser.tabAnimationsInProgress &&