Bug 1560192 - Clean up prompt open calls in Prompter.jsm. r=Gijs
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 19 Jun 2019 21:59:18 +0000
changeset 479262 bfd88bfc61c42a09475da8749b2218f540e4592c
parent 479261 b5f437bf0c8f15263da1ef22510040bfa685d036
child 479263 c05a24ea5373052bde91d5aeb736ad7a230dc9c7
push id36177
push userrmaries@mozilla.com
push dateThu, 20 Jun 2019 09:46:31 +0000
treeherdermozilla-central@a440f0629814 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1560192
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1560192 - Clean up prompt open calls in Prompter.jsm. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D35371
browser/modules/RemotePrompt.jsm
toolkit/components/prompts/src/Prompter.jsm
--- a/browser/modules/RemotePrompt.jsm
+++ b/browser/modules/RemotePrompt.jsm
@@ -12,20 +12,24 @@ ChromeUtils.defineModuleGetter(this, "Pr
 ChromeUtils.defineModuleGetter(this, "Services",
                                "resource://gre/modules/Services.jsm");
 
 var RemotePrompt = {
   // Listeners are added in BrowserGlue.jsm
   receiveMessage(message) {
     switch (message.name) {
       case "Prompt:Open":
-        if (message.data.uri) {
-          this.openModalWindow(message.data, message.target);
+        const COMMON_DIALOG = "chrome://global/content/commonDialog.xul";
+        const SELECT_DIALOG = "chrome://global/content/selectDialog.xul";
+
+        if (message.data.tabPrompt) {
+          this.openTabPrompt(message.data, message.target);
         } else {
-          this.openTabPrompt(message.data, message.target);
+          let uri = (message.data.promptType == "select") ? SELECT_DIALOG : COMMON_DIALOG;
+          this.openModalWindow(uri, message.data, message.target);
         }
         break;
     }
   },
 
   openTabPrompt(args, browser) {
     let window = browser.ownerGlobal;
     let tabPrompt = window.gBrowser.getTabModalPromptBox(browser);
@@ -80,23 +84,23 @@ var RemotePrompt = {
       // there's other stuff in nsWindowWatcher::OpenWindowInternal
       // that we might need to do here as well.
     } catch (ex) {
       Cu.reportError(ex);
       onPromptClose(true);
     }
   },
 
-  openModalWindow(args, browser) {
+  openModalWindow(uri, args, browser) {
     let window = browser.ownerGlobal;
     try {
       PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser);
       let bag = PromptUtils.objectToPropBag(args);
 
-      Services.ww.openWindow(window, args.uri, "_blank",
+      Services.ww.openWindow(window, uri, "_blank",
                              "centerscreen,chrome,modal,titlebar", bag);
 
       PromptUtils.propBagToObject(bag, args);
     } finally {
       PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
       browser.messageManager.sendAsyncMessage("Prompt:Close", args);
     }
   },
--- a/toolkit/components/prompts/src/Prompter.jsm
+++ b/toolkit/components/prompts/src/Prompter.jsm
@@ -426,24 +426,24 @@ function openTabPrompt(domWin, tabPrompt
             throw Components.Exception("prompt aborted by user", Cr.NS_ERROR_NOT_AVAILABLE);
     } finally {
         // If the prompt unexpectedly failed to invoke the callback, do so here.
         if (!callbackInvoked)
             onPromptClose(true);
     }
 }
 
-function openRemotePrompt(domWin, args, tabPrompt) {
+function openRemotePrompt(domWin, args) {
     let docShell = domWin.docShell;
     let messageManager = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                                  .getInterface(Ci.nsIBrowserChild)
                                  .messageManager;
 
     let inPermitUnload = docShell.contentViewer && docShell.contentViewer.inPermitUnload;
-    let eventDetail = Cu.cloneInto({tabPrompt, inPermitUnload}, domWin);
+    let eventDetail = Cu.cloneInto({tabPrompt: args.tabPrompt, inPermitUnload}, domWin);
     PromptUtils.fireDialogEvent(domWin, "DOMWillOpenModalDialog", null, eventDetail);
 
     // If domWin is reloaded while we're showing a remote modal
     // dialog, it is possible to detach domWin from its tree, and make
     // it impossible to reach its scriptable top,
     // a.k.a. window.top. To prevent this, make sure to enter/exit
     // modal state beginning from top.
     let winUtils = domWin.top.windowUtils;
@@ -534,39 +534,39 @@ ModalPrompter.prototype = {
         let prefValue = false;
         if (Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL)
             prefValue = Services.prefs.getBoolPref(prefName);
 
         let allowTabModal = this.allowTabModal && prefValue;
 
         if (allowTabModal && this.domWin) {
             if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
-                openRemotePrompt(this.domWin, args, true);
+                args.tabPrompt = true;
+                openRemotePrompt(this.domWin, args);
                 return;
             }
 
             let tabPrompt = PromptUtils.getTabModalPrompt(this.domWin);
             if (tabPrompt) {
                 openTabPrompt(this.domWin, tabPrompt, args);
                 return;
             }
         }
 
         // If we can't do a tab modal prompt, fallback to using a window-modal dialog.
+        if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
+            args.tabPrompt = false;
+            openRemotePrompt(this.domWin, args);
+            return;
+        }
+
         const COMMON_DIALOG = "chrome://global/content/commonDialog.xul";
         const SELECT_DIALOG = "chrome://global/content/selectDialog.xul";
 
         let uri = (args.promptType == "select") ? SELECT_DIALOG : COMMON_DIALOG;
-
-        if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
-            args.uri = uri;
-            openRemotePrompt(this.domWin, args);
-            return;
-        }
-
         let propBag = PromptUtils.objectToPropBag(args);
         openModalWindow(this.domWin, uri, propBag);
         PromptUtils.propBagToObject(propBag, args);
     },
 
 
 
     /*