Bug 1636089 - ActorManagerParent.addJSProcessActors;r=kmag,geckoview-reviewers,snorp

Differential Revision: https://phabricator.services.mozilla.com/D75047
This commit is contained in:
David Teller 2020-05-19 16:29:36 +00:00
parent e943dbb1da
commit 49d5a4d3b4
6 changed files with 54 additions and 16 deletions

View File

@ -64,12 +64,20 @@ XPCOMUtils.defineLazyServiceGetter(
const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
/**
* Fission-compatible JSProcess implementations.
* Each actor options object takes the form of a ProcessActorOptions dictionary.
* Detailed documentation of these options is in dom/docs/Fission.rst,
* available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jsprocessactor
*/
let JSPROCESSACTORS = {};
/**
* Fission-compatible JSWindowActor implementations.
* Detailed documentation of these is in dom/docs/Fission.rst,
* available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jswindowactor
*/
let ACTORS = {
let JSWINDOWACTORS = {
AboutLogins: {
parent: {
moduleURI: "resource:///actors/AboutLoginsParent.jsm",
@ -1176,7 +1184,8 @@ BrowserGlue.prototype = {
os.addObserver(this, "handlersvc-store-initialized");
os.addObserver(this, "shield-init-complete");
ActorManagerParent.addActors(ACTORS);
ActorManagerParent.addJSProcessActors(JSPROCESSACTORS);
ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);
ActorManagerParent.addLegacyActors(LEGACY_ACTORS);
ActorManagerParent.flush();

View File

@ -46,7 +46,7 @@ async function registerWatcher(watcher, watchedBrowsingContextID) {
watchers.set(prefix, watcher);
if (watchers.size == 1) {
// Register the JSWindowActor pair "DevToolsFrame" only once we register our first WindowGlobal Watcher
ActorManagerParent.addActors({
ActorManagerParent.addJSWindowActors({
DevToolsFrame: {
parent: {
moduleURI:

View File

@ -305,7 +305,7 @@ class DevToolsFrameChild extends JSWindowActorChild {
}
handleEvent({ type }) {
// DOMWindowCreated is registered from FrameWatcher via `ActorManagerParent.addActors`
// DOMWindowCreated is registered from FrameWatcher via `ActorManagerParent.addJSWindowActors`
// as a DOM event to be listened to and so is fired by JS Window Actor code platform code.
if (type == "DOMWindowCreated") {
this.instantiate();

View File

@ -233,7 +233,7 @@ You can find the list of Message Manager Actors (or "Legacy Actors") in `Browser
.. note::
The split in Message Manager Actors defined between ``BrowserGlue`` and ``ActorManagerParent`` is mainly to keep Firefox Desktop specific Actors separate from Actors that can (in theory) be instantiated for non-Desktop browsers (like Fennec and GeckoView-based browsers). Firefox Desktop-specific Actors should be registered in ``BrowserGlue``. Shared "toolkit" Actors should go into ``ActorManagerParent``.
"Porting" these Actors often means doing what is necessary in order to move their registration entries from ``LEGACY_ACTORS`` to the ``ACTORS`` list.
"Porting" these Actors often means doing what is necessary in order to move their registration entries from ``LEGACY_ACTORS`` to the ``JSWINDOWACTORS`` list.
Figuring out the lifetime of a new Actor pair
`````````````````````````````````````````````
@ -256,9 +256,9 @@ For example, when porting the content area context menu for Firefox, it was note
Registering a new JSWindowActor
```````````````````````````````
``ChromeUtils`` exposes an API for registering window actors, but both ``BrowserGlue`` and ``ActorManagerParent`` are the main entry points where the registration occurs. If you want to register an actor, you should put them in one of the ``ACTORS`` lists in one of those two files. See :ref:`fission.message-manager-actors` for details.
``ChromeUtils`` exposes an API for registering window actors, but both ``BrowserGlue`` and ``ActorManagerParent`` are the main entry points where the registration occurs. If you want to register an actor, you should put them in one of the ``JSWINDOWACTORS`` lists in one of those two files. See :ref:`fission.message-manager-actors` for details.
The ``ACTORS`` lists expect a key-value pair, where the key is the name of the actor pair (example: ``ContextMenu``), and the value is an ``Object`` of registration parameters.
The ``JSWINDOWACTORS`` lists expect a key-value pair, where the key is the name of the actor pair (example: ``ContextMenu``), and the value is an ``Object`` of registration parameters.
The full list of registration parameters can be found in the `JSWindowActor.webidl`_ file as ``WindowActorOptions``, ``WindowActorSidedOptions`` and ``WindowActorChildOptions``.

View File

@ -21,7 +21,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
const { debug, warn } = GeckoViewUtils.initLogging("Startup"); // eslint-disable-line no-unused-vars
const ACTORS = {
const JSWINDOWACTORS = {
BrowserTab: {
parent: {
moduleURI: "resource:///actors/BrowserTabParent.jsm",
@ -160,7 +160,7 @@ GeckoViewStartup.prototype = {
if (
Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT
) {
ActorManagerParent.addActors(ACTORS);
ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);
ActorManagerParent.flush();
Services.mm.loadFrameScript(

View File

@ -27,13 +27,21 @@ const { XPCOMUtils } = ChromeUtils.import(
const { DefaultMap } = ExtensionUtils;
/**
* Fission-compatible JSProcess implementations.
* Each actor options object takes the form of a ProcessActorOptions dictionary.
* Detailed documentation of these options is in dom/docs/Fission.rst,
* available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jsprocessactor
*/
let JSPROCESSACTORS = {};
/**
* Fission-compatible JSWindowActor implementations.
* Each actor options object takes the form of a WindowActorOptions dictionary.
* Detailed documentation of these options is in dom/docs/Fission.rst,
* available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jswindowactor
*/
let ACTORS = {
let JSWINDOWACTORS = {
AudioPlayback: {
parent: {
moduleURI: "resource://gre/actors/AudioPlaybackParent.jsm",
@ -431,7 +439,7 @@ let ACTORS = {
* AudioPlaybackChild which lives in AudioPlaybackChild.jsm.
*
*
* Actors are defined by calling ActorManagerParent.addActors, with an object
* Actors are defined by calling ActorManagerParent.addJSWindowActors, with an object
* containing a property for each actor being defined, whose value is an object
* describing how the actor should be loaded. That object may have the following
* properties:
@ -569,7 +577,20 @@ var ActorManagerParent = {
// filter keys as understood by MozDocumentMatcher.
singletons: new DefaultMap(() => new ActorSet(null, "Child")),
addActors(actors) {
_addActors(actors, kind) {
let register, unregister;
switch (kind) {
case "JSProcessActor":
register = ChromeUtils.registerProcessActor;
unregister = ChromeUtils.unregisterProcessActor;
break;
case "JSWindowActor":
register = ChromeUtils.registerWindowActor;
unregister = ChromeUtils.unregisterWindowActor;
break;
default:
throw new Error("Invalid JSActor kind " + kind);
}
for (let [actorName, actor] of Object.entries(actors)) {
// If enablePreference is set, only register the actor while the
// preference is set to true.
@ -582,9 +603,9 @@ var ActorManagerParent = {
false,
(prefName, prevValue, isEnabled) => {
if (isEnabled) {
ChromeUtils.registerWindowActor(actorName, actor);
register(actorName, actor);
} else {
ChromeUtils.unregisterWindowActor(actorName, actor);
unregister(actorName, actor);
}
}
);
@ -593,10 +614,17 @@ var ActorManagerParent = {
}
}
ChromeUtils.registerWindowActor(actorName, actor);
register(actorName, actor);
}
},
addJSProcessActors(actors) {
this._addActors(actors, "JSProcessActor");
},
addJSWindowActors(actors) {
this._addActors(actors, "JSWindowActor");
},
addLegacyActors(actors) {
for (let [actorName, actor] of Object.entries(actors)) {
let { child } = actor;
@ -636,5 +664,6 @@ var ActorManagerParent = {
},
};
ActorManagerParent.addActors(ACTORS);
ActorManagerParent.addJSProcessActors(JSPROCESSACTORS);
ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);
ActorManagerParent.addLegacyActors(LEGACY_ACTORS);