Bug 1234936 - part 2: always focus tabs when they show an onbeforeunload dialog, r=billm draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 29 Dec 2015 18:49:27 +0000
changeset 318005 f10dd511583205a4f6801e1a7d93fa7b97bd17dd
parent 318004 64f62187adfc0b7ff8adb0effa6e6bea9862d3ee
child 512399 c57290134cb0b4395f8363427df9f3a8d15a385f
push id8808
push usergijskruitbosch@gmail.com
push dateWed, 30 Dec 2015 11:29:27 +0000
reviewersbillm
bugs1234936
milestone46.0a1
Bug 1234936 - part 2: always focus tabs when they show an onbeforeunload dialog, r=billm
browser/base/content/tabbrowser.xml
toolkit/components/prompts/src/nsPrompter.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -4364,19 +4364,21 @@
           let tabForEvent = targetIsWindow ?
                             this._getTabForContentWindow(event.target.top) :
                             this.getTabForBrowser(event.originalTarget);
 
           // Don't need to act if the tab is already selected:
           if (tabForEvent.selected)
             return;
 
-          // If this is a tabprompt, we won't switch tabs
-          // (unless this behaviour has been disabled entirely using the pref)
+          // If this is a tabprompt, we won't switch tabs, unless:
+          // - this is a beforeunload prompt
+          // - this behaviour has been disabled entirely using the pref
           if (event.detail && event.detail.tabPrompt &&
+              !event.detail.inPermitUnload &&
               Services.prefs.getBoolPref("browser.tabs.dontfocusfordialogs")) {
             let docPrincipal = targetIsWindow ? event.target.document.nodePrincipal : null;
             // At least one of these should/will be non-null:
             let promptPrincipal = event.detail.promptPrincipal || docPrincipal ||
                                   tabForEvent.linkedBrowser.contentPrincipal;
             // For null principals, we bail immediately and don't show the checkbox:
             if (!promptPrincipal || promptPrincipal.isNullPrincipal) {
               tabForEvent.setAttribute("attention", "true");
--- a/toolkit/components/prompts/src/nsPrompter.js
+++ b/toolkit/components/prompts/src/nsPrompter.js
@@ -475,16 +475,17 @@ function openRemotePrompt(domWin, args, 
         domWin.removeEventListener("pagehide", pagehide);
         messageManager.sendAsyncMessage("Prompt:ForceClose", { _remoteId: id });
     }
 
     let topPrincipal = domWin.top.document.nodePrincipal;
     let promptPrincipal = domWin.document.nodePrincipal;
     args.promptPrincipal = promptPrincipal;
     args.showAlertOrigin = topPrincipal.equals(promptPrincipal);
+    args.inPermitUnload = inPermitUnload;
 
     args._remoteId = id;
 
     messageManager.sendAsyncMessage("Prompt:Open", args, {});
 
     let thread = Services.tm.currentThread;
     while (!closed) {
         thread.processNextEvent(true);