Bug 1355426 - Make tabbrowser binding call blurTab earlier when removing tab. r?dao draft
authorMike Conley <mconley@mozilla.com>
Mon, 31 Jul 2017 15:01:39 -0400
changeset 619843 6acc9538cbcbec25c4b98351dc9984aab9f43b8d
parent 619309 a3e675a3b10a0ea289c301bedc31866f3daf7875
child 619844 64e1dbeeea61ce8fcc194113deb4566f0b91f6a3
push id71845
push usermconley@mozilla.com
push dateWed, 02 Aug 2017 18:13:02 +0000
reviewersdao
bugs1355426
milestone56.0a1
Bug 1355426 - Make tabbrowser binding call blurTab earlier when removing tab. r?dao MozReview-Commit-ID: JVIAs58p7wW
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2880,17 +2880,16 @@
               TelemetryStopwatch.cancel("FX_TAB_CLOSE_TIME_ANIM_MS", aTab);
               this._endRemoveTab(aTab);
               return;
             }
 
             // We're animating, so we can cancel the non-animation stopwatch.
             TelemetryStopwatch.cancel("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
 
-            this._blurTab(aTab);
             aTab.style.maxWidth = ""; // ensure that fade-out transition happens
             aTab.removeAttribute("fadein");
 
             setTimeout(function(tab, tabbrowser) {
               if (tab.parentNode &&
                   window.getComputedStyle(tab).maxWidth == "0.1px") {
                 NS_ASSERT(false, "Giving up waiting for the tab closing animation to finish (bug 608589)");
                 tabbrowser._endRemoveTab(tab);
@@ -2915,20 +2914,27 @@
         <body>
           <![CDATA[
             if (aTab.closing ||
                 this._windowIsClosing)
               return false;
 
             var browser = this.getBrowserForTab(aTab);
 
-            if (!aTab._pendingPermitUnload &&
-                !aSkipPermitUnload &&
-                aTab.linkedPanel &&
-                !aAdoptedByTab) {
+            let checkPermitUnload = !aSkipPermitUnload &&
+                                    !aAdoptedByTab &&
+                                    aTab.linkedPanel &&
+                                    !aTab._pendingPermitUnload;
+
+            if (checkPermitUnload && browser.isRemoteBrowser) {
+              checkPermitUnload = browser.frameLoader.tabParent &&
+                                  browser.frameLoader.tabParent.hasBeforeUnload;
+            }
+
+            if (checkPermitUnload) {
               TelemetryStopwatch.start("FX_TAB_CLOSE_PERMIT_UNLOAD_TIME_MS", aTab);
 
               // We need to block while calling permitUnload() because it
               // processes the event queue and may lead to another removeTab()
               // call before permitUnload() returns.
               aTab._pendingPermitUnload = true;
               let {permitUnload, timedOut} = browser.permitUnload();
               delete aTab._pendingPermitUnload;
@@ -2938,16 +2944,17 @@
               // If we were closed during onbeforeunload, we return false now
               // so we don't (try to) close the same tab again. Of course, we
               // also stop if the unload was cancelled by the user:
               if (aTab.closing || (!timedOut && !permitUnload)) {
                 return false;
               }
             }
 
+            this._blurTab(aTab);
 
             var closeWindow = false;
             var newTab = false;
             if (this.tabs.length - this._removingTabs.length == 1) {
               closeWindow = aCloseWindowWithLastTab != null ? aCloseWindowWithLastTab :
                             !window.toolbar.visible ||
                               Services.prefs.getBoolPref("browser.tabs.closeWindowWithLastTab");