Source code

Revision control

Copy as Markdown

Other Tools

/* 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/. */
/**
* This module handles JavaScript-implemented JSWindowActors, registered through DOM IPC
* infrastructure, and are fission-compatible.
*/
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
/**
* Fission-compatible JSProcess implementations.
* Each actor options object takes the form of a ProcessActorOptions dictionary.
* Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
*/
let JSPROCESSACTORS = {
AsyncPrefs: {
parent: {
},
},
},
ContentPrefs: {
},
},
},
ExtensionContent: {
},
includeParent: true,
},
ProcessConduits: {
},
},
},
};
/**
* Fission-compatible JSWindowActor implementations.
* Each actor options object takes the form of a WindowActorOptions dictionary.
* Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
*/
let JSWINDOWACTORS = {
AboutCertViewer: {
},
child: {
events: {
DOMDocElementInserted: { capture: true },
},
},
matches: ["about:certificate"],
},
AboutHttpsOnlyError: {
},
child: {
events: {
DOMDocElementInserted: {},
},
},
matches: ["about:httpsonlyerror?*"],
allFrames: true,
},
AboutTranslations: {
},
child: {
events: {
// Run the actor before any content of the page appears to inject functions.
DOMDocElementInserted: {},
DOMContentLoaded: {},
// Used to show and hide the translations button.
pageshow: { mozSystemGroup: true },
pagehide: { mozSystemGroup: true },
},
},
matches: ["about:translations"],
remoteTypes: ["privilegedabout"],
enablePreference: "browser.translations.enable",
},
AudioPlayback: {
},
child: {
observers: ["audio-playback"],
},
allFrames: true,
},
AutoComplete: {
parent: {
// These two messages are also used, but are currently synchronous calls
// through the per-process message manager.
// "AutoComplete:GetSelectedIndex",
// "AutoComplete:SelectBy"
},
},
allFrames: true,
},
Autoplay: {
},
child: {
events: {
GloballyAutoplayBlocked: {},
},
},
allFrames: true,
},
AutoScroll: {
},
child: {
events: {
mousedown: { capture: true, mozSystemGroup: true },
},
},
allFrames: true,
},
BackgroundThumbnails: {
child: {
events: {
DOMDocElementInserted: { capture: true },
},
},
messageManagerGroups: ["thumbnails"],
},
BrowserElement: {
},
child: {
events: {
DOMWindowClose: {},
},
},
allFrames: true,
},
Conduits: {
},
},
allFrames: true,
},
Controllers: {
},
},
allFrames: true,
},
CookieBanner: {
},
child: {
events: {
DOMContentLoaded: {},
load: { capture: true },
},
},
// Only need handle cookie banners for HTTP/S scheme.
matches: ["https://*/*", "http://*/*"],
// Only handle banners for browser tabs (including sub-frames).
messageManagerGroups: ["browsers"],
// Cookie banners can be shown in sub-frames so we need to include them.
allFrames: true,
// Holds lazy pref getters.
_prefs: {},
// Remember current register state to avoid duplicate calls to register /
// unregister.
_isRegistered: false,
onAddActor(register, unregister) {
// Register / unregister on pref changes.
let onPrefChange = () => {
if (
this._prefs["cookiebanners.bannerClicking.enabled"] &&
(this._prefs["cookiebanners.service.mode"] != 0 ||
this._prefs["cookiebanners.service.mode.privateBrowsing"] != 0)
) {
if (!this._isRegistered) {
register();
this._isRegistered = true;
}
} else if (this._isRegistered) {
unregister();
this._isRegistered = false;
}
};
// Add lazy pref getters with pref observers so we can dynamically enable
// or disable the actor.
[
"cookiebanners.bannerClicking.enabled",
"cookiebanners.service.mode",
"cookiebanners.service.mode.privateBrowsing",
].forEach(prefName => {
XPCOMUtils.defineLazyPreferenceGetter(
this._prefs,
prefName,
prefName,
null,
onPrefChange
);
});
// Check initial state.
onPrefChange();
},
},
ExtFind: {
},
allFrames: true,
},
FindBar: {
},
child: {
events: {
keypress: { mozSystemGroup: true },
},
},
allFrames: true,
messageManagerGroups: ["browsers", "test"],
},
// This is the actor that responds to requests from the find toolbar and
// searches for matches and highlights them.
Finder: {
},
allFrames: true,
},
FormHistory: {
},
child: {
events: {
"form-submission-detected": {},
},
},
allFrames: true,
},
FormHandler: {
child: {
events: {
DOMFormBeforeSubmit: {},
},
},
allFrames: true,
},
InlineSpellChecker: {
},
},
allFrames: true,
},
KeyPressEventModelChecker: {
child: {
esModuleURI:
events: {
CheckKeyPressEventModel: { capture: true, mozSystemGroup: true },
},
},
allFrames: true,
},
LoginManager: {
},
child: {
events: {
"form-submission-detected": {},
DOMFormHasPassword: {},
DOMFormHasPossibleUsername: {},
DOMInputPasswordAdded: {},
},
},
allFrames: true,
messageManagerGroups: ["browsers", "webext-browsers", ""],
},
ManifestMessages: {
},
},
// A single process (shared with translations) that manages machine learning engines.
MLEngine: {
},
child: {
events: {
DOMContentLoaded: { createActor: true },
},
},
includeChrome: true,
enablePreference: "browser.ml.enable",
},
NetError: {
},
child: {
events: {
DOMDocElementInserted: {},
click: {},
},
},
matches: ["about:certerror?*", "about:neterror?*"],
allFrames: true,
},
PictureInPictureLauncher: {
},
child: {
events: {
MozTogglePictureInPicture: { capture: true },
},
},
allFrames: true,
},
PictureInPicture: {
},
},
allFrames: true,
},
PictureInPictureToggle: {
},
child: {
events: {
UAWidgetSetupOrChange: {},
contextmenu: { capture: true },
},
},
allFrames: true,
},
PopupBlocking: {
},
child: {
events: {
DOMPopupBlocked: { capture: true },
// Only listen for the `pageshow` event after the actor has already been
// created for some other reason.
pageshow: { createActor: false },
},
},
allFrames: true,
},
Printing: {
},
child: {
events: {
PrintingError: { capture: true },
printPreviewUpdate: { capture: true },
},
},
},
PrintingSelection: {
},
allFrames: true,
},
PurgeSessionHistory: {
},
allFrames: true,
},
ReportBrokenSite: {
},
},
matches: [
"about:certerror?*",
"about:neterror?*",
],
messageManagerGroups: ["browsers"],
allFrames: true,
},
// This actor is available for all pages that one can
// view the source of, however it won't be created until a
// request to view the source is made via the message
// 'ViewSource:LoadSource' or 'ViewSource:LoadSourceWithSelection'.
ViewSource: {
},
allFrames: true,
},
// This actor is for the view-source page itself.
ViewSourcePage: {
},
child: {
events: {
pageshow: { capture: true },
click: {},
},
},
matches: ["view-source:*"],
allFrames: true,
},
WebChannel: {
},
child: {
events: {
WebChannelMessageToChrome: { capture: true, wantUntrusted: true },
},
},
allFrames: true,
},
Thumbnails: {
},
},
// Determines if a page can be translated, and coordinates communication with the
// translations engine.
Translations: {
},
child: {
events: {
DOMContentLoaded: {},
},
},
matches: [
// The actor is explicitly loaded by this page,
// so it needs to be allowed for it.
"about:translations",
],
enablePreference: "browser.translations.enable",
},
// A single process that controls all of the translations.
TranslationsEngine: {
},
child: {
events: {
DOMContentLoaded: { createActor: true },
},
},
includeChrome: true,
enablePreference: "browser.translations.enable",
},
UAWidgets: {
child: {
events: {
UAWidgetSetupOrChange: {},
UAWidgetTeardown: {},
},
},
includeChrome: true,
allFrames: true,
},
UnselectedTabHover: {
},
child: {
events: {
"UnselectedTabHover:Enable": {},
"UnselectedTabHover:Disable": {},
},
},
allFrames: true,
},
};
/**
* Note that turning on page data collection for snapshots currently disables
* collection of generic page info for normal history entries. See bug 1740234.
*/
if (!Services.prefs.getBoolPref("browser.pagedata.enabled", false)) {
JSWINDOWACTORS.ContentMeta = {
},
child: {
events: {
DOMContentLoaded: {},
DOMMetaAdded: { createActor: false },
},
},
messageManagerGroups: ["browsers"],
};
}
if (AppConstants.platform != "android") {
// Note that GeckoView has another implementation in mobile/android/actors.
JSWINDOWACTORS.Select = {
parent: {
},
child: {
events: {
mozshowdropdown: {},
"mozshowdropdown-sourcetouch": {},
mozhidedropdown: { mozSystemGroup: true },
},
},
includeChrome: true,
allFrames: true,
};
// Note that GeckoView handles MozOpenDateTimePicker in GeckoViewPrompt.
JSWINDOWACTORS.DateTimePicker = {
},
child: {
events: {
MozOpenDateTimePicker: {},
MozUpdateDateTimePicker: {},
MozCloseDateTimePicker: {},
},
},
includeChrome: true,
allFrames: true,
};
}
export var ActorManagerParent = {
_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)) {
// The actor defines its own register/unregister logic.
if (actor.onAddActor) {
actor.onAddActor(
() => register(actorName, actor),
() => unregister(actorName, actor)
);
continue;
}
// If enablePreference is set, only register the actor while the
// preference is set to true.
if (actor.enablePreference) {
let actorNameProp = actorName + "_Preference";
XPCOMUtils.defineLazyPreferenceGetter(
this,
actorNameProp,
actor.enablePreference,
false,
(prefName, prevValue, isEnabled) => {
if (isEnabled) {
register(actorName, actor);
} else {
unregister(actorName, actor);
}
if (actor.onPreferenceChanged) {
actor.onPreferenceChanged(prefName, prevValue, isEnabled);
}
}
);
if (!this[actorNameProp]) {
continue;
}
}
register(actorName, actor);
}
},
addJSProcessActors(actors) {
this._addActors(actors, "JSProcessActor");
},
addJSWindowActors(actors) {
this._addActors(actors, "JSWindowActor");
},
};
ActorManagerParent.addJSProcessActors(JSPROCESSACTORS);
ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);