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
--- 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]);