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 619368 f95a5a1168fe0532043735fc665a2c093cdbb742
parent 619309 a3e675a3b10a0ea289c301bedc31866f3daf7875
child 619369 f587f29bef203d4f5013e31faf8e5cbdd5c66cde
push id71648
push usermconley@mozilla.com
push dateTue, 01 Aug 2017 21:53: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);
@@ -2913,21 +2912,30 @@
         <parameter name="aCloseWindowFastpath"/>
         <parameter name="aSkipPermitUnload"/>
         <body>
           <![CDATA[
             if (aTab.closing ||
                 this._windowIsClosing)
               return false;
 
+            let skipPermitUnload = aSkipPermitUnload;
             var browser = this.getBrowserForTab(aTab);
 
+            if (!skipPermitUnload) {
+              if (!aTab.linkedPanel) {
+                skipPermitUnload = true;
+              } else if (browser.isRemoteBrowser) {
+                skipPermitUnload = !browser.frameLoader.tabParent ||
+                                   !browser.frameLoader.tabParent.hasBeforeUnload;
+              }
+            }
+
             if (!aTab._pendingPermitUnload &&
-                !aSkipPermitUnload &&
-                aTab.linkedPanel &&
+                !skipPermitUnload &&
                 !aAdoptedByTab) {
               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();
@@ -2938,16 +2946,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");