Bug 1741861 - Move shared logic from _subscribeEvent and _unsubscribeEvent. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D149401
This commit is contained in:
Alexandra Borovova 2022-06-22 12:15:08 +00:00
Родитель 6a2f271bac
Коммит f49bf0fabd
5 изменённых файлов: 55 добавлений и 69 удалений

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

@ -6,6 +6,17 @@
const EXPORTED_SYMBOLS = ["Module"];
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
ContextDescriptorType:
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
});
class Module {
#messageHandler;
@ -19,6 +30,25 @@ class Module {
this.#messageHandler = messageHandler;
}
/**
* Add session data for a given module and event.
*
* @param {string} moduleName
* Name of the module.
* @param {string} event
* Name of the event.
*/
addEventSessionData(moduleName, event) {
return this.messageHandler.addSessionData({
moduleName,
category: "event",
contextDescriptor: {
type: lazy.ContextDescriptorType.All,
},
values: [event],
});
}
/**
* Clean-up the module instance.
*
@ -60,6 +90,25 @@ class Module {
});
}
/**
* Remove session data for a given module and event.
*
* @param {string} moduleName
* Name of the module.
* @param {string} event
* Name of the event.
*/
removeEventSessionData(moduleName, event) {
return this.messageHandler.removeSessionData({
moduleName,
category: "event",
contextDescriptor: {
type: lazy.ContextDescriptorType.All,
},
values: [event],
});
}
/**
* Instance shortcut for supportsMethod to avoid reaching the constructor for
* consumers which directly deal with an instance.

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

@ -530,45 +530,19 @@ class BrowsingContextModule extends Module {
*/
_subscribeEvent(params) {
// TODO: Bug 1741861. Move this logic to a shared module or the an abstract
// class.
switch (params.event) {
case "browsingContext.contextCreated":
this.#contextListener.startListening();
return this.messageHandler.addSessionData({
moduleName: "browsingContext",
category: "event",
contextDescriptor: {
type: lazy.ContextDescriptorType.All,
},
values: [params.event],
});
default:
throw new Error(
`Unsupported event for browsingContext module ${params.event}`
);
}
return this.addEventSessionData("browsingContext", params.event);
}
_unsubscribeEvent(params) {
switch (params.event) {
case "browsingContext.contextCreated":
this.#contextListener.stopListening();
return this.messageHandler.removeSessionData({
moduleName: "browsingContext",
category: "event",
contextDescriptor: {
type: lazy.ContextDescriptorType.All,
},
values: [params.event],
});
default:
throw new Error(
`Unsupported event for browsingContext module ${params.event}`
);
}
return this.removeEventSessionData("browsingContext", params.event);
}
static get supportedEvents() {

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

@ -6,21 +6,10 @@
const EXPORTED_SYMBOLS = ["log"];
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Module } = ChromeUtils.import(
"chrome://remote/content/shared/messagehandler/Module.jsm"
);
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
ContextDescriptorType:
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
});
class LogModule extends Module {
destroy() {}
@ -29,37 +18,11 @@ class LogModule extends Module {
*/
_subscribeEvent(params) {
// TODO: Bug 1741861. Move this logic to a shared module or the an abstract
// class.
switch (params.event) {
case "log.entryAdded":
return this.messageHandler.addSessionData({
moduleName: "log",
category: "event",
contextDescriptor: {
type: lazy.ContextDescriptorType.All,
},
values: ["log.entryAdded"],
});
default:
throw new Error(`Unsupported event for log module ${params.event}`);
}
return this.addEventSessionData("log", params.event);
}
_unsubscribeEvent(params) {
switch (params.event) {
case "log.entryAdded":
return this.messageHandler.removeSessionData({
moduleName: "log",
category: "event",
contextDescriptor: {
type: lazy.ContextDescriptorType.All,
},
values: ["log.entryAdded"],
});
default:
throw new Error(`Unsupported event for log module ${params.event}`);
}
return this.removeEventSessionData("log", params.event);
}
static get supportedEvents() {

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

@ -62,7 +62,7 @@ class BrowsingContextModule extends Module {
*/
_applySessionData(params) {
// TODO: Bug 1741861. Move this logic to a shared module or the an abstract
// TODO: Bug 1775231. Move this logic to a shared module or an abstract
// class.
const { category, added = [], removed = [] } = params;
if (category === "internal-event") {

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

@ -203,7 +203,7 @@ class LogModule extends Module {
*/
_applySessionData(params) {
// TODO: Bug 1741861. Move this logic to a shared module or the an abstract
// TODO: Bug 1775231. Move this logic to a shared module or an abstract
// class.
const { category, added = [], removed = [] } = params;
if (category === "event") {