gecko-dev/toolkit/modules/ActorChild.jsm
Felipe Gomes 3b972f7f7a Bug 1493984 - Implement Fission-aware message handling to actors. r=mconley
This patch adds a messaging mechanism to actors that work like this:

If browser.fission.simulate is true, messages handled by ActorManagerChild will only be dispatched to an actor tied to a specific frame, specified either by its frameId (outerWindowId) or by its browsingContextId. Messages that lack the information about the destination frame will be considered meant for the top-level frame.

In addition, a sendMessage API is added to ActorChild that automatically adds the id information to the outbound message, making it easier for it to be handled in the parent.

The frameId support is to ease the transition of some code that is already using outerWindowIds. For new code, it is preferred to use the browsing context ids, together with bug 1496840

Differential Revision: https://phabricator.services.mozilla.com/D7933

--HG--
extra : moz-landing-system : lando
2018-10-30 21:47:04 +00:00

51 lines
1.5 KiB
JavaScript

/* vim: set ts=2 sw=2 sts=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["ActorChild"];
/**
* This should be the base class of any actor class registered via
* ActorManagerParent and implemented in the child process. It currently takes
* care of setting the `mm`, `content`, and `docShell` properties based on the
* message manager it's bound to, but may do more in the future.
*
* If Fission is being simulated, and the actor is registered as "allFrames",
* the `content` property of this class will be bound to a specific subframe.
* Otherwise, the `content` is always the top-level content tied to the `mm`.
*/
class ActorChild {
constructor(dispatcher) {
this._dispatcher = dispatcher;
this.mm = dispatcher.mm;
}
get content() {
return this._dispatcher.window;
}
get docShell() {
return this.mm.docShell;
}
addEventListener(event, options) {
this._dispatcher.addEventListener(event, this.constructor.name, options);
}
addMessageListener(msg) {
this._dispatcher.addMessageListener(msg, this.constructor.name);
}
sendAsyncMessage(msg, data = {}) {
data.frameId = this._dispatcher.frameId;
data.browsingContextId = this._dispatcher.browsingContextId;
this.mm.sendAsyncMessage(msg, data);
}
cleanup() {
this._dispatcher = null;
}
}