Bug 1560192 - Clean up prompt open calls in Prompter.jsm. r=Gijs, a=pascalc
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 19 Jun 2019 21:59:18 +0000
changeset 537027 4c21940d5185815ccac9f39a7299ac7bec18f9fe
parent 537026 3d0f2d47703954d9c19b8044e0ebc6e74c8bcfec
child 537028 0c5232da74a4bb5041be42ac1c76f9a34b4ecf0c
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, pascalc
bugs1560192
milestone68.0
Bug 1560192 - Clean up prompt open calls in Prompter.jsm. r=Gijs, a=pascalc 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);
     },
 
 
 
     /*