2020-11-04 18:53:18 +03:00
|
|
|
/* 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");
|
|
|
|
|
2020-11-10 01:54:55 +03:00
|
|
|
const EXPORTED_SYMBOLS = [
|
|
|
|
"EventDispatcher",
|
|
|
|
"MarionetteEventsParent",
|
|
|
|
"registerEventsActor",
|
|
|
|
"unregisterEventsActor",
|
|
|
|
];
|
2020-11-04 18:53:18 +03:00
|
|
|
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
|
|
|
EventEmitter: "resource://gre/modules/EventEmitter.jsm",
|
2021-07-08 11:12:53 +03:00
|
|
|
Log: "chrome://remote/content/shared/Log.jsm",
|
2020-11-04 18:53:18 +03:00
|
|
|
});
|
|
|
|
|
2021-07-08 11:12:53 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "logger", () =>
|
|
|
|
Log.get(Log.TYPES.MARIONETTE)
|
|
|
|
);
|
2020-11-10 23:11:26 +03:00
|
|
|
|
2020-11-04 18:53:18 +03:00
|
|
|
// Singleton to allow forwarding events to registered listeners.
|
|
|
|
const EventDispatcher = {
|
|
|
|
init() {
|
|
|
|
EventEmitter.decorate(this);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
EventDispatcher.init();
|
|
|
|
|
|
|
|
class MarionetteEventsParent extends JSWindowActorParent {
|
|
|
|
async receiveMessage(msg) {
|
|
|
|
const { name, data } = msg;
|
|
|
|
|
|
|
|
let rv;
|
|
|
|
switch (name) {
|
|
|
|
case "MarionetteEventsChild:PageLoadEvent":
|
|
|
|
EventDispatcher.emit("page-load", data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 01:54:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register Events actors to listen for page load events via EventDispatcher.
|
|
|
|
*/
|
|
|
|
function registerEventsActor() {
|
2020-11-10 23:11:26 +03:00
|
|
|
try {
|
|
|
|
// Register the JSWindowActor pair for events as used by Marionette
|
|
|
|
ChromeUtils.registerWindowActor("MarionetteEvents", {
|
|
|
|
kind: "JSWindowActor",
|
|
|
|
parent: {
|
|
|
|
moduleURI:
|
2021-06-07 13:08:24 +03:00
|
|
|
"chrome://remote/content/marionette/actors/MarionetteEventsParent.jsm",
|
2020-11-10 23:11:26 +03:00
|
|
|
},
|
|
|
|
child: {
|
|
|
|
moduleURI:
|
2021-06-07 13:08:24 +03:00
|
|
|
"chrome://remote/content/marionette/actors/MarionetteEventsChild.jsm",
|
2020-11-10 23:11:26 +03:00
|
|
|
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 },
|
2020-12-17 21:50:20 +03:00
|
|
|
|
|
|
|
click: {},
|
|
|
|
dblclick: {},
|
2021-05-11 20:29:25 +03:00
|
|
|
unload: { capture: true, createActor: false },
|
2020-11-10 23:11:26 +03:00
|
|
|
},
|
2020-11-10 01:54:55 +03:00
|
|
|
},
|
|
|
|
|
2020-11-10 23:11:26 +03:00
|
|
|
allFrames: true,
|
|
|
|
includeChrome: true,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
if (e.name === "NotSupportedError") {
|
|
|
|
logger.warn(`MarionetteEvents actor is already registered!`);
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 01:54:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function unregisterEventsActor() {
|
|
|
|
ChromeUtils.unregisterWindowActor("MarionetteEvents");
|
|
|
|
}
|