From a48dd7b64ba730f98128e2b2ebe1a534541e7244 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Tue, 9 Jan 2018 15:53:46 +0000 Subject: [PATCH] Bug 1429091 - Use global message manager in AsyncMessageChannel. r=maja_zf Whenever we make proxied IPC calls to the content frame's message manager, we do so over the global message manager. AsyncMessageChannel takes a closure that returns the current message manager from GeckoDriver#mm, but this is unnecessary because it always holds a global message channel. By not having to pass in a closure returning a message manager to AsyncMessageChannel we losen the tight coupling a little bit. Future patches will further reduce the tight coupling of browserFn. MozReview-Commit-ID: EU0pkxA7lab --HG-- extra : rebase_source : f6d6735e2d5bacdfbf20bde9a835f3f83846b2d6 --- testing/marionette/driver.js | 4 ++-- testing/marionette/listener.js | 4 +--- testing/marionette/proxy.js | 29 +++++++++++++---------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index 6c5bcc6980b0..abff8f0d9dc6 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -150,8 +150,8 @@ this.GeckoDriver = function(appId, server) { this.capabilities = new session.Capabilities(); this.mm = globalMessageManager; - this.listener = proxy.toListener(() => this.mm, this.sendAsync.bind(this), - () => this.curBrowser); + this.listener = proxy.toListener( + this.sendAsync.bind(this), () => this.curBrowser); // points to an alert instance if a modal dialog is present this.dialog = null; diff --git a/testing/marionette/listener.js b/testing/marionette/listener.js index 8e2caa1ceae4..06c848fff229 100644 --- a/testing/marionette/listener.js +++ b/testing/marionette/listener.js @@ -627,9 +627,7 @@ function deregister() { * an empty dictionary. */ function sendToServer(uuid, data = undefined) { - let channel = new proxy.AsyncMessageChannel( - () => this, - sendAsyncMessage.bind(this)); + let channel = new proxy.AsyncMessageChannel(sendAsyncMessage.bind(this)); channel.reply(uuid, data); } diff --git a/testing/marionette/proxy.js b/testing/marionette/proxy.js index 59ee4cb5ed39..7447758793ab 100644 --- a/testing/marionette/proxy.js +++ b/testing/marionette/proxy.js @@ -21,8 +21,11 @@ this.EXPORTED_SYMBOLS = ["proxy"]; XPCOMUtils.defineLazyServiceGetter( this, "uuidgen", "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator"); +XPCOMUtils.defineLazyServiceGetter( + this, "globalMessageManager", "@mozilla.org/globalmessagemanager;1", + "nsIMessageBroadcaster"); -const logger = Log.repository.getLogger("Marionette"); +const log = Log.repository.getLogger("Marionette"); // Proxy handler that traps requests to get a property. Will prioritise // properties that exist on the object's own prototype. @@ -50,14 +53,13 @@ this.proxy = {}; * passed literally. The latter specialisation is temporary to achieve * backwards compatibility with listener.js. * - * @param {function(): (nsIMessageSender|nsIMessageBroadcaster)} mmFn - * Closure function returning the current message manager. * @param {function(string, Object, number)} sendAsyncFn * Callback for sending async messages. + * @param {function(): browser.Context} browserFn + * Closure that returns the current browsing context. */ -proxy.toListener = function(mmFn, sendAsyncFn, browserFn) { - let sender = new proxy.AsyncMessageChannel( - mmFn, sendAsyncFn, browserFn); +proxy.toListener = function(sendAsyncFn, browserFn) { + let sender = new proxy.AsyncMessageChannel(sendAsyncFn, browserFn); return new Proxy(sender, ownPriorityGetterTrap); }; @@ -71,8 +73,7 @@ proxy.toListener = function(mmFn, sendAsyncFn, browserFn) { * .reply(...). */ proxy.AsyncMessageChannel = class { - constructor(mmFn, sendAsyncFn, browserFn) { - this.mmFn_ = mmFn; + constructor(sendAsyncFn, browserFn) { this.sendAsync = sendAsyncFn; this.browserFn_ = browserFn; @@ -88,10 +89,6 @@ proxy.AsyncMessageChannel = class { return this.browserFn_(); } - get mm() { - return this.mmFn_(); - } - /** * Send a message across the channel. The name of the function to * call must be registered as a message listener. @@ -150,7 +147,7 @@ proxy.AsyncMessageChannel = class { // The currently selected tab or window has been closed. No clean-up // is necessary to do because all loaded listeners are gone. this.closeHandler = ({type, target}) => { - logger.debug(`Received DOM event ${type} for ${target}`); + log.debug(`Received DOM event ${type} for ${target}`); switch (type) { case "TabClose": @@ -165,7 +162,7 @@ proxy.AsyncMessageChannel = class { // the active command has to be aborted. Therefore remove all handlers, // and cancel any ongoing requests in the listener. this.dialogueObserver_ = (subject, topic) => { - logger.debug(`Received observer notification ${topic}`); + log.debug(`Received observer notification ${topic}`); this.removeAllListeners_(); // TODO(ato): It's not ideal to have listener specific behaviour here: @@ -294,7 +291,7 @@ proxy.AsyncMessageChannel = class { callback(msg); }; - this.mm.addMessageListener(path, autoRemover); + globalMessageManager.addMessageListener(path, autoRemover); this.listeners_.set(path, autoRemover); } @@ -304,7 +301,7 @@ proxy.AsyncMessageChannel = class { } let l = this.listeners_.get(path); - this.mm.removeMessageListener(path, l[1]); + globalMessageManager.removeMessageListener(path, l[1]); return this.listeners_.delete(path); }