Bug 1397426 - Only fire TabSwitchDone if a tab switch was requested. r?billm draft
authorMike Conley <mconley@mozilla.com>
Thu, 28 Sep 2017 10:37:32 -0700
changeset 672216 65962e5175f95079b593d547401bee1a2a4a6399
parent 672215 2b25b3e41f0b11b6227dac3361d122c2445e45de
child 672217 a696894caaa53827443a23b7a0d93e476fdf560d
push id82194
push userbmo:mconley@mozilla.com
push dateThu, 28 Sep 2017 22:33:08 +0000
reviewersbillm
bugs1397426
milestone57.0a1
Bug 1397426 - Only fire TabSwitchDone if a tab switch was requested. r?billm MozReview-Commit-ID: LoMsALCRhLH
browser/base/content/tabbrowser.xml
--- 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) {