1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * This module handles JavaScript-implemented JSWindowActors, registered through DOM IPC
8 * infrastructure, and are fission-compatible.
11 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
12 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
15 * Fission-compatible JSProcess implementations.
16 * Each actor options object takes the form of a ProcessActorOptions dictionary.
17 * Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
18 * available at https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
20 let JSPROCESSACTORS = {
23 esModuleURI: "resource://gre/modules/AsyncPrefs.sys.mjs",
26 esModuleURI: "resource://gre/modules/AsyncPrefs.sys.mjs",
32 esModuleURI: "resource://gre/modules/ContentPrefServiceParent.sys.mjs",
35 esModuleURI: "resource://gre/modules/ContentPrefServiceChild.sys.mjs",
41 esModuleURI: "resource://gre/modules/ExtensionContent.sys.mjs",
48 esModuleURI: "resource://gre/modules/ConduitsParent.sys.mjs",
51 esModuleURI: "resource://gre/modules/ConduitsChild.sys.mjs",
57 * Fission-compatible JSWindowActor implementations.
58 * Each actor options object takes the form of a WindowActorOptions dictionary.
59 * Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
60 * available at https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
62 let JSWINDOWACTORS = {
65 esModuleURI: "resource://gre/modules/AboutCertViewerParent.sys.mjs",
68 esModuleURI: "resource://gre/modules/AboutCertViewerChild.sys.mjs",
71 DOMDocElementInserted: { capture: true },
75 matches: ["about:certificate"],
78 AboutHttpsOnlyError: {
80 esModuleURI: "resource://gre/actors/AboutHttpsOnlyErrorParent.sys.mjs",
83 esModuleURI: "resource://gre/actors/AboutHttpsOnlyErrorChild.sys.mjs",
85 DOMDocElementInserted: {},
88 matches: ["about:httpsonlyerror?*"],
94 esModuleURI: "resource://gre/actors/AboutTranslationsParent.sys.mjs",
97 esModuleURI: "resource://gre/actors/AboutTranslationsChild.sys.mjs",
99 // Run the actor before any content of the page appears to inject functions.
100 DOMDocElementInserted: {},
101 DOMContentLoaded: {},
102 // Used to show and hide the translations button.
103 pageshow: { mozSystemGroup: true },
104 pagehide: { mozSystemGroup: true },
107 matches: ["about:translations"],
108 remoteTypes: ["privilegedabout"],
109 enablePreference: "browser.translations.enable",
114 esModuleURI: "resource://gre/actors/AudioPlaybackParent.sys.mjs",
118 esModuleURI: "resource://gre/actors/AudioPlaybackChild.sys.mjs",
119 observers: ["audio-playback"],
127 esModuleURI: "resource://gre/actors/AutoCompleteParent.sys.mjs",
128 // These two messages are also used, but are currently synchronous calls
129 // through the per-process message manager.
130 // "FormAutoComplete:GetSelectedIndex",
131 // "FormAutoComplete:SelectBy"
135 esModuleURI: "resource://gre/actors/AutoCompleteChild.sys.mjs",
143 esModuleURI: "resource://gre/actors/AutoplayParent.sys.mjs",
147 esModuleURI: "resource://gre/actors/AutoplayChild.sys.mjs",
149 GloballyAutoplayBlocked: {},
158 esModuleURI: "resource://gre/actors/AutoScrollParent.sys.mjs",
162 esModuleURI: "resource://gre/actors/AutoScrollChild.sys.mjs",
164 mousedown: { capture: true, mozSystemGroup: true },
171 BackgroundThumbnails: {
173 esModuleURI: "resource://gre/actors/BackgroundThumbnailsChild.sys.mjs",
175 DOMDocElementInserted: { capture: true },
178 messageManagerGroups: ["thumbnails"],
183 esModuleURI: "resource://gre/actors/BrowserElementParent.sys.mjs",
187 esModuleURI: "resource://gre/actors/BrowserElementChild.sys.mjs",
198 esModuleURI: "resource://gre/modules/ConduitsParent.sys.mjs",
202 esModuleURI: "resource://gre/modules/ConduitsChild.sys.mjs",
210 esModuleURI: "resource://gre/actors/ControllersParent.sys.mjs",
213 esModuleURI: "resource://gre/actors/ControllersChild.sys.mjs",
221 esModuleURI: "resource://gre/actors/CookieBannerParent.sys.mjs",
224 esModuleURI: "resource://gre/actors/CookieBannerChild.sys.mjs",
226 DOMContentLoaded: {},
227 load: { capture: true },
230 // Only need handle cookie banners for HTTP/S scheme.
231 matches: ["https://*/*", "http://*/*"],
232 // Only handle banners for browser tabs (including sub-frames).
233 messageManagerGroups: ["browsers"],
234 // Cookie banners can be shown in sub-frames so we need to include them.
236 // Holds lazy pref getters.
238 // Remember current register state to avoid duplicate calls to register /
240 _isRegistered: false,
241 onAddActor(register, unregister) {
242 // Register / unregister on pref changes.
243 let onPrefChange = () => {
245 this._prefs["cookiebanners.bannerClicking.enabled"] &&
246 (this._prefs["cookiebanners.service.mode"] != 0 ||
247 this._prefs["cookiebanners.service.mode.privateBrowsing"] != 0)
249 if (!this._isRegistered) {
251 this._isRegistered = true;
253 } else if (this._isRegistered) {
255 this._isRegistered = false;
259 // Add lazy pref getters with pref observers so we can dynamically enable
260 // or disable the actor.
262 "cookiebanners.bannerClicking.enabled",
263 "cookiebanners.service.mode",
264 "cookiebanners.service.mode.privateBrowsing",
265 ].forEach(prefName => {
266 XPCOMUtils.defineLazyPreferenceGetter(
275 // Check initial state.
282 esModuleURI: "resource://gre/actors/ExtFindChild.sys.mjs",
290 esModuleURI: "resource://gre/actors/FindBarParent.sys.mjs",
293 esModuleURI: "resource://gre/actors/FindBarChild.sys.mjs",
295 keypress: { mozSystemGroup: true },
300 messageManagerGroups: ["browsers", "test"],
303 // This is the actor that responds to requests from the find toolbar and
304 // searches for matches and highlights them.
307 esModuleURI: "resource://gre/actors/FinderChild.sys.mjs",
315 esModuleURI: "resource://gre/actors/FormHistoryParent.sys.mjs",
318 esModuleURI: "resource://gre/actors/FormHistoryChild.sys.mjs",
320 DOMFormBeforeSubmit: {},
327 InlineSpellChecker: {
329 esModuleURI: "resource://gre/actors/InlineSpellCheckerParent.sys.mjs",
333 esModuleURI: "resource://gre/actors/InlineSpellCheckerChild.sys.mjs",
339 KeyPressEventModelChecker: {
342 "resource://gre/actors/KeyPressEventModelCheckerChild.sys.mjs",
344 CheckKeyPressEventModel: { capture: true, mozSystemGroup: true },
353 esModuleURI: "resource://gre/modules/LoginManagerParent.sys.mjs",
356 esModuleURI: "resource://gre/modules/LoginManagerChild.sys.mjs",
358 DOMFormBeforeSubmit: {},
359 DOMFormHasPassword: {},
360 DOMFormHasPossibleUsername: {},
361 DOMInputPasswordAdded: {},
366 messageManagerGroups: ["browsers", "webext-browsers", ""],
371 esModuleURI: "resource://gre/modules/ManifestMessagesChild.sys.mjs",
377 esModuleURI: "resource://gre/actors/NetErrorParent.sys.mjs",
380 esModuleURI: "resource://gre/actors/NetErrorChild.sys.mjs",
382 DOMDocElementInserted: {},
387 matches: ["about:certerror?*", "about:neterror?*"],
391 PictureInPictureLauncher: {
393 esModuleURI: "resource://gre/modules/PictureInPicture.sys.mjs",
396 esModuleURI: "resource://gre/actors/PictureInPictureChild.sys.mjs",
398 MozTogglePictureInPicture: { capture: true },
407 esModuleURI: "resource://gre/modules/PictureInPicture.sys.mjs",
410 esModuleURI: "resource://gre/actors/PictureInPictureChild.sys.mjs",
416 PictureInPictureToggle: {
418 esModuleURI: "resource://gre/modules/PictureInPicture.sys.mjs",
421 esModuleURI: "resource://gre/actors/PictureInPictureChild.sys.mjs",
423 UAWidgetSetupOrChange: {},
424 contextmenu: { capture: true },
433 esModuleURI: "resource://gre/actors/PopupBlockingParent.sys.mjs",
436 esModuleURI: "resource://gre/actors/PopupBlockingChild.sys.mjs",
438 DOMPopupBlocked: { capture: true },
439 // Only listen for the `pageshow` event after the actor has already been
440 // created for some other reason.
441 pageshow: { createActor: false },
449 esModuleURI: "resource://gre/actors/PrintingParent.sys.mjs",
452 esModuleURI: "resource://gre/actors/PrintingChild.sys.mjs",
454 PrintingError: { capture: true },
455 printPreviewUpdate: { capture: true },
462 esModuleURI: "resource://gre/actors/PrintingSelectionChild.sys.mjs",
467 PurgeSessionHistory: {
469 esModuleURI: "resource://gre/actors/PurgeSessionHistoryChild.sys.mjs",
476 esModuleURI: "resource://gre/actors/ReportBrokenSiteParent.sys.mjs",
479 esModuleURI: "resource://gre/actors/ReportBrokenSiteChild.sys.mjs",
487 messageManagerGroups: ["browsers"],
491 // This actor is available for all pages that one can
492 // view the source of, however it won't be created until a
493 // request to view the source is made via the message
494 // 'ViewSource:LoadSource' or 'ViewSource:LoadSourceWithSelection'.
497 esModuleURI: "resource://gre/actors/ViewSourceChild.sys.mjs",
503 // This actor is for the view-source page itself.
506 esModuleURI: "resource://gre/actors/ViewSourcePageParent.sys.mjs",
509 esModuleURI: "resource://gre/actors/ViewSourcePageChild.sys.mjs",
511 pageshow: { capture: true },
516 matches: ["view-source:*"],
522 esModuleURI: "resource://gre/actors/WebChannelParent.sys.mjs",
525 esModuleURI: "resource://gre/actors/WebChannelChild.sys.mjs",
527 WebChannelMessageToChrome: { capture: true, wantUntrusted: true },
536 esModuleURI: "resource://gre/actors/ThumbnailsChild.sys.mjs",
540 // Determines if a page can be translated, and coordinates communication with the
541 // translations engine.
544 esModuleURI: "resource://gre/actors/TranslationsParent.sys.mjs",
547 esModuleURI: "resource://gre/actors/TranslationsChild.sys.mjs",
549 DOMContentLoaded: {},
557 // The actor is explicitly loaded by this page,
558 // so it needs to be allowed for it.
559 "about:translations",
561 enablePreference: "browser.translations.enable",
564 // A single process that controls all of the translations.
565 TranslationsEngine: {
567 esModuleURI: "resource://gre/actors/TranslationsEngineParent.sys.mjs",
570 esModuleURI: "resource://gre/actors/TranslationsEngineChild.sys.mjs",
572 DOMContentLoaded: { createActor: true },
576 matches: ["chrome://global/content/translations/translations-engine.html"],
577 enablePreference: "browser.translations.enable",
582 esModuleURI: "resource://gre/actors/UAWidgetsChild.sys.mjs",
584 UAWidgetSetupOrChange: {},
585 UAWidgetTeardown: {},
593 UnselectedTabHover: {
595 esModuleURI: "resource://gre/actors/UnselectedTabHoverParent.sys.mjs",
598 esModuleURI: "resource://gre/actors/UnselectedTabHoverChild.sys.mjs",
600 "UnselectedTabHover:Enable": {},
601 "UnselectedTabHover:Disable": {},
610 * Note that turning on page data collection for snapshots currently disables
611 * collection of generic page info for normal history entries. See bug 1740234.
613 if (!Services.prefs.getBoolPref("browser.pagedata.enabled", false)) {
614 JSWINDOWACTORS.ContentMeta = {
616 esModuleURI: "resource://gre/actors/ContentMetaParent.sys.mjs",
620 esModuleURI: "resource://gre/actors/ContentMetaChild.sys.mjs",
622 DOMContentLoaded: {},
623 DOMMetaAdded: { createActor: false },
627 messageManagerGroups: ["browsers"],
631 if (AppConstants.platform != "android") {
632 // Note that GeckoView has another implementation in mobile/android/actors.
633 JSWINDOWACTORS.Select = {
635 esModuleURI: "resource://gre/actors/SelectParent.sys.mjs",
639 esModuleURI: "resource://gre/actors/SelectChild.sys.mjs",
642 "mozshowdropdown-sourcetouch": {},
643 mozhidedropdown: { mozSystemGroup: true },
651 // Note that GeckoView handles MozOpenDateTimePicker in GeckoViewPrompt.
652 JSWINDOWACTORS.DateTimePicker = {
654 esModuleURI: "resource://gre/actors/DateTimePickerParent.sys.mjs",
658 esModuleURI: "resource://gre/actors/DateTimePickerChild.sys.mjs",
660 MozOpenDateTimePicker: {},
661 MozUpdateDateTimePicker: {},
662 MozCloseDateTimePicker: {},
671 export var ActorManagerParent = {
672 _addActors(actors, kind) {
673 let register, unregister;
675 case "JSProcessActor":
676 register = ChromeUtils.registerProcessActor;
677 unregister = ChromeUtils.unregisterProcessActor;
679 case "JSWindowActor":
680 register = ChromeUtils.registerWindowActor;
681 unregister = ChromeUtils.unregisterWindowActor;
684 throw new Error("Invalid JSActor kind " + kind);
686 for (let [actorName, actor] of Object.entries(actors)) {
687 // The actor defines its own register/unregister logic.
688 if (actor.onAddActor) {
690 () => register(actorName, actor),
691 () => unregister(actorName, actor)
696 // If enablePreference is set, only register the actor while the
697 // preference is set to true.
698 if (actor.enablePreference) {
699 let actorNameProp = actorName + "_Preference";
700 XPCOMUtils.defineLazyPreferenceGetter(
703 actor.enablePreference,
705 (prefName, prevValue, isEnabled) => {
707 register(actorName, actor);
709 unregister(actorName, actor);
711 if (actor.onPreferenceChanged) {
712 actor.onPreferenceChanged(prefName, prevValue, isEnabled);
716 if (!this[actorNameProp]) {
721 register(actorName, actor);
725 addJSProcessActors(actors) {
726 this._addActors(actors, "JSProcessActor");
728 addJSWindowActors(actors) {
729 this._addActors(actors, "JSWindowActor");
733 ActorManagerParent.addJSProcessActors(JSPROCESSACTORS);
734 ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);