Bug 1450344 - 3. Use EventDispatcher directly for child process prompts; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Thu, 05 Apr 2018 18:50:12 -0400
changeset 778198 7995e89837a4fa99fba3533546faf643a9878f3a
parent 778197 5da6ff4a6e6cf5edcba0f0bcc80fa8d68cf201b0
child 778201 7532aa2153e0640ab5287831e81fa9f846a1f425
push id105423
push userbmo:nchen@mozilla.com
push dateThu, 05 Apr 2018 22:54:08 +0000
reviewersesawin
bugs1450344
milestone61.0a1
Bug 1450344 - 3. Use EventDispatcher directly for child process prompts; r?esawin We had some custom messaging code in GeckoViewPrompts for supporting child processes, but using EventDispatcher directly works just as well. MozReview-Commit-ID: JRFzp96z11i
mobile/android/components/geckoview/GeckoViewPrompt.js
mobile/android/components/geckoview/GeckoViewStartup.js
--- a/mobile/android/components/geckoview/GeckoViewPrompt.js
+++ b/mobile/android/components/geckoview/GeckoViewPrompt.js
@@ -17,17 +17,17 @@ XPCOMUtils.defineLazyServiceGetter(this,
 function PromptFactory() {
   this.wrappedJSObject = this;
 }
 
 PromptFactory.prototype = {
   classID: Components.ID("{076ac188-23c1-4390-aa08-7ef1f78ca5d9}"),
 
   QueryInterface: XPCOMUtils.generateQI([
-    Ci.nsIPromptFactory, Ci.nsIPromptService]),
+    Ci.nsIDOMEventListener, Ci.nsIPromptFactory, Ci.nsIPromptService]),
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "click":
         this._handleClick(aEvent);
         break;
       case "contextmenu":
         this._handleContextMenu(aEvent);
@@ -268,30 +268,16 @@ PromptFactory.prototype = {
       if (result && result.choices !== undefined) {
         builder.click(result.choices[0]);
       }
     });
 
     aEvent.preventDefault();
   },
 
-  receiveMessage: function(aMsg) {
-    if (aMsg.name !== "GeckoView:Prompt") {
-      return;
-    }
-
-    let prompt = new PromptDelegate(aMsg.target.contentWindow || aMsg.target.ownerGlobal);
-    prompt.asyncShowPrompt(aMsg.data, result => {
-      aMsg.target.messageManager.sendAsyncMessage("GeckoView:PromptClose", {
-        uuid: aMsg.data.uuid,
-        result: result,
-      });
-    });
-  },
-
   /* ----------  nsIPromptFactory  ---------- */
   getPrompt: function(aDOMWin, aIID) {
     // Delegated to login manager here, which in turn calls back into us via nsIPromptService.
     if (aIID.equals(Ci.nsIAuthPrompt2) || aIID.equals(Ci.nsIAuthPrompt)) {
       try {
         let pwmgr = Cc["@mozilla.org/passwordmanager/authpromptfactory;1"].getService(Ci.nsIPromptFactory);
         return pwmgr.getPrompt(aDOMWin, aIID);
       } catch (e) {
@@ -348,20 +334,16 @@ PromptFactory.prototype = {
   asyncPromptAuth: function() {
     return this.callProxy("asyncPromptAuth", arguments);
   }
 };
 
 function PromptDelegate(aDomWin) {
   this._domWin = aDomWin;
 
-  if (Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_DEFAULT) {
-    return;
-  }
-
   if (aDomWin) {
     this._dispatcher = GeckoViewUtils.getDispatcherForWindow(aDomWin);
   }
 
   if (!this._dispatcher) {
     this._dispatcher = GeckoViewUtils.getActiveDispatcher();
   }
 }
@@ -420,39 +402,16 @@ PromptDelegate.prototype = {
       Services.tm.spinEventLoopUntil(() => result !== undefined);
     } finally {
       this._changeModalState(/* aEntering */ false);
     }
     return result;
   },
 
   asyncShowPrompt: function(aMsg, aCallback) {
-    if (Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_DEFAULT) {
-      let docShell = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor)
-                                 .getInterface(Ci.nsIDocShell)
-                                 .QueryInterface(Ci.nsIDocShellTreeItem)
-                                 .rootTreeItem;
-      let messageManager = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
-                                   .getInterface(Ci.nsITabChild)
-                                   .messageManager;
-
-      let uuid = UUIDGen.generateUUID().toString();
-      aMsg.uuid = uuid;
-
-      messageManager.addMessageListener("GeckoView:PromptClose", function listener(msg) {
-        if (msg.data.uuid !== uuid) {
-          return;
-        }
-        messageManager.removeMessageListener(msg.name, listener);
-        aCallback(msg.data.result);
-      });
-      messageManager.sendAsyncMessage("GeckoView:Prompt", aMsg);
-      return;
-    }
-
     let handled = false;
     let onResponse = response => {
       if (handled) {
         return;
       }
       aCallback(response);
       // This callback object is tied to the Java garbage collector because
       // it is invoked from Java. Manually release the target callback
--- a/mobile/android/components/geckoview/GeckoViewStartup.js
+++ b/mobile/android/components/geckoview/GeckoViewStartup.js
@@ -64,22 +64,15 @@ GeckoViewStartup.prototype = {
           module: "resource://gre/modules/ContentPrefServiceParent.jsm",
           init: cpsp => cpsp.alwaysInit(),
           ppmm: [
             "ContentPrefs:FunctionCall",
             "ContentPrefs:AddObserverForName",
             "ContentPrefs:RemoveObserverForName",
           ],
         });
-
-        GeckoViewUtils.addLazyGetter(this, "GeckoViewPrompt", {
-          service: "@mozilla.org/prompter;1",
-          mm: [
-            "GeckoView:Prompt",
-          ],
-        });
         break;
       }
     }
   },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([GeckoViewStartup]);