Bug 1397426 - Only fire TabSwitchDone if a tab switch was requested. r?billm
MozReview-Commit-ID: LoMsALCRhLH
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -4264,16 +4264,17 @@
tabbrowser: this, // Reference to gBrowser.
loadTimer: null, // TAB_SWITCH_TIMEOUT nsITimer instance.
unloadTimer: null, // UNLOAD_DELAY nsITimer instance.
// Map from tabs to STATE_* (below).
tabState: new Map(),
+ tabWasRequested: false,
// True if we're in the midst of switching tabs.
switchInProgress: false,
// Keep an exact list of content processes (tabParent) in which
// we're actively suppressing the display port. This gives a robust
// way to make sure we don't forget to un-suppress.
activeSuppressDisplayport: new Set(),
@@ -4440,34 +4441,36 @@
this.assert(!this.loadTimer);
this.assert(!this.loadingTab);
this.assert(this.lastVisibleTab === this.requestedTab);
this.assert(this.minimizedOrFullyOccluded ||
this.getTabState(this.requestedTab) == this.STATE_LOADED);
this.destroy();
- let toBrowser = this.requestedTab.linkedBrowser;
- toBrowser.setAttribute("primary", "true");
-
- let fromBrowser = this.originalTab.linkedBrowser;
- // It's possible that the tab we're switching from closed
- // before we were able to finalize, in which case, fromBrowser
- // doesn't exist.
- if (fromBrowser) {
- fromBrowser.removeAttribute("primary");
- }
-
- document.commandDispatcher.unlock();
-
- let event = new CustomEvent("TabSwitchDone", {
- bubbles: true,
- cancelable: true
- });
- this.tabbrowser.dispatchEvent(event);
+ if (this.tabWasRequested) {
+ let toBrowser = this.requestedTab.linkedBrowser;
+ toBrowser.setAttribute("primary", "true");
+
+ let fromBrowser = this.originalTab.linkedBrowser;
+ // It's possible that the tab we're switching from closed
+ // before we were able to finalize, in which case, fromBrowser
+ // doesn't exist.
+ if (fromBrowser) {
+ fromBrowser.removeAttribute("primary");
+ }
+
+ document.commandDispatcher.unlock();
+
+ let event = new CustomEvent("TabSwitchDone", {
+ bubbles: true,
+ cancelable: true
+ });
+ this.tabbrowser.dispatchEvent(event);
+ }
},
// This function is called after all the main state changes to
// make sure we display the right tab.
updateDisplay() {
let requestedTabState = this.getTabState(this.requestedTab);
let requestedBrowser = this.requestedTab.linkedBrowser;
@@ -4980,16 +4983,18 @@
},
// Called when the user asks to switch to a given tab.
requestTab(tab) {
if (tab === this.requestedTab) {
return;
}
+ this.tabWasRequested = true;
+
if (this.tabbrowser.tabWarmingEnabled) {
let warmingState = "disqualified";
if (this.warmingTabs.has(tab)) {
let tabState = this.getTabState(tab);
if (tabState == this.STATE_LOADING) {
warmingState = "stillLoading";
} else if (tabState == this.STATE_LOADED) {