Bug 1675320 - [marionette] Add register/unregisterEventsActor helpers to MarionetteEventsParent r=marionette-reviewers,whimboo

Expose the boilerplate code to register the MarionetteEventsActor to later reuse it from driver.js

Differential Revision: https://phabricator.services.mozilla.com/D96117
This commit is contained in:
Julian Descottes 2020-11-09 22:54:55 +00:00
Родитель c5072b6139
Коммит 30c0f10791
2 изменённых файлов: 45 добавлений и 26 удалений

Просмотреть файл

@ -4,7 +4,12 @@
("use strict"); ("use strict");
const EXPORTED_SYMBOLS = ["EventDispatcher", "MarionetteEventsParent"]; const EXPORTED_SYMBOLS = [
"EventDispatcher",
"MarionetteEventsParent",
"registerEventsActor",
"unregisterEventsActor",
];
const { XPCOMUtils } = ChromeUtils.import( const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm" "resource://gre/modules/XPCOMUtils.jsm"
@ -36,3 +41,36 @@ class MarionetteEventsParent extends JSWindowActorParent {
return rv; return rv;
} }
} }
/**
* Register Events actors to listen for page load events via EventDispatcher.
*/
function registerEventsActor() {
// Register the JSWindowActor pair for events as used by Marionette
ChromeUtils.registerWindowActor("MarionetteEvents", {
kind: "JSWindowActor",
parent: {
moduleURI:
"chrome://marionette/content/actors/MarionetteEventsParent.jsm",
},
child: {
moduleURI: "chrome://marionette/content/actors/MarionetteEventsChild.jsm",
events: {
beforeunload: { capture: true },
DOMContentLoaded: { mozSystemGroup: true },
hashchange: { mozSystemGroup: true },
pagehide: { mozSystemGroup: true },
pageshow: { mozSystemGroup: true },
// popstate doesn't bubble, as such use capturing phase
popstate: { capture: true, mozSystemGroup: true },
},
},
allFrames: true,
includeChrome: true,
});
}
function unregisterEventsActor() {
ChromeUtils.unregisterWindowActor("MarionetteEvents");
}

Просмотреть файл

@ -19,8 +19,12 @@ XPCOMUtils.defineLazyModuleGetters(this, {
MarionettePrefs: "chrome://marionette/content/prefs.js", MarionettePrefs: "chrome://marionette/content/prefs.js",
modal: "chrome://marionette/content/modal.js", modal: "chrome://marionette/content/modal.js",
PageLoadStrategy: "chrome://marionette/content/capabilities.js", PageLoadStrategy: "chrome://marionette/content/capabilities.js",
registerEventsActor:
"chrome://marionette/content/actors/MarionetteEventsParent.jsm",
TimedPromise: "chrome://marionette/content/sync.js", TimedPromise: "chrome://marionette/content/sync.js",
truncate: "chrome://marionette/content/format.js", truncate: "chrome://marionette/content/format.js",
unregisterEventsActor:
"chrome://marionette/content/actors/MarionetteEventsParent.jsm",
}); });
XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get()); XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
@ -330,30 +334,7 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
if (MarionettePrefs.useActors) { if (MarionettePrefs.useActors) {
// Register the JSWindowActor pair for events as used by Marionette // Register the JSWindowActor pair for events as used by Marionette
ChromeUtils.registerWindowActor("MarionetteEvents", { registerEventsActor();
kind: "JSWindowActor",
parent: {
moduleURI:
"chrome://marionette/content/actors/MarionetteEventsParent.jsm",
},
child: {
moduleURI:
"chrome://marionette/content/actors/MarionetteEventsChild.jsm",
events: {
beforeunload: { capture: true },
DOMContentLoaded: { mozSystemGroup: true },
hashchange: { mozSystemGroup: true },
pagehide: { mozSystemGroup: true },
pageshow: { mozSystemGroup: true },
// popstate doesn't bubble, as such use capturing phase
popstate: { capture: true, mozSystemGroup: true },
},
},
allFrames: true,
includeChrome: true,
});
EventDispatcher.on("page-load", onNavigation); EventDispatcher.on("page-load", onNavigation);
} else { } else {
driver.mm.addMessageListener( driver.mm.addMessageListener(
@ -406,7 +387,7 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
if (MarionettePrefs.useActors) { if (MarionettePrefs.useActors) {
EventDispatcher.off("page-load", onNavigation); EventDispatcher.off("page-load", onNavigation);
ChromeUtils.unregisterWindowActor("MarionetteEvents"); unregisterEventsActor();
} else { } else {
driver.mm.removeMessageListener( driver.mm.removeMessageListener(
"Marionette:NavigationEvent", "Marionette:NavigationEvent",