Bug 1450344 - 2. Make getDispatcherForWindow work in child process; r?esawin
Make getDispatcherForWindow work in the child process by returning a
dispatcher through EventDispatcher.forMessageManager.
MozReview-Commit-ID: JertLoDBJW2
--- a/mobile/android/modules/geckoview/GeckoViewUtils.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewUtils.jsm
@@ -173,53 +173,72 @@ var GeckoViewUtils = {
dispatcher.unregisterListener(listener, args[0]);
handlers.forEach(handler =>
dispatcher.registerListener(handler, args[0]));
}
handlers.forEach(handler => handler.onEvent(...args));
});
},
- /**
- * Return the outermost chrome DOM window (the XUL window) for a given DOM
- * window.
- *
- * @param aWin a DOM window.
- */
- getChromeWindow: function(aWin) {
+ _getRootDocShell: function(aWin) {
if (!aWin) {
return null;
}
let docShell;
try {
docShell = aWin.QueryInterface(Ci.nsIDocShell);
} catch (e) {
docShell = aWin.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell);
}
- return docShell.QueryInterface(Ci.nsIDocShellTreeItem)
- .rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
+ return docShell.QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor);
},
/**
- * Return the per-nsWindow EventDispatcher for a given DOM window.
+ * Return the outermost chrome DOM window (the XUL window) for a given DOM
+ * window, in the parent process.
+ *
+ * @param aWin a DOM window.
+ */
+ getChromeWindow: function(aWin) {
+ const docShell = this._getRootDocShell(aWin);
+ return docShell && docShell.getInterface(Ci.nsIDOMWindow);
+ },
+
+ /**
+ * Return the content frame message manager (aka the frame script global
+ * object) for a given DOM window, in a child process.
+ *
+ * @param aWin a DOM window.
+ */
+ getContentFrameMessageManager: function(aWin) {
+ const docShell = this._getRootDocShell(aWin);
+ return docShell && docShell.getInterface(Ci.nsITabChild).messageManager;
+ },
+
+ /**
+ * Return the per-nsWindow EventDispatcher for a given DOM window, in either
+ * the parent process or a child process.
*
* @param aWin a DOM window.
*/
getDispatcherForWindow: function(aWin) {
try {
- let win = this.getChromeWindow(aWin.top || aWin);
- let dispatcher = win.WindowEventDispatcher || EventDispatcher.for(win);
- if (!win.closed && dispatcher) {
- return dispatcher;
+ if (!this.IS_PARENT_PROCESS) {
+ const mm = this.getContentFrameMessageManager(aWin.top || aWin);
+ return mm && EventDispatcher.forMessageManager(mm);
+ }
+ const win = this.getChromeWindow(aWin.top || aWin);
+ if (!win.closed) {
+ return win.WindowEventDispatcher || EventDispatcher.for(win);
}
} catch (e) {
- return null;
}
+ return null;
},
getActiveDispatcher: function() {
let dispatcher = this.getDispatcherForWindow(Services.focus.activeWindow);
if (dispatcher) {
return dispatcher;
}
@@ -229,8 +248,11 @@ var GeckoViewUtils = {
iter.getNext().QueryInterface(Ci.nsIDOMWindow));
if (dispatcher) {
return dispatcher;
}
}
return null;
},
};
+
+XPCOMUtils.defineLazyGetter(GeckoViewUtils, "IS_PARENT_PROCESS", _ =>
+ Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT);