Bug 1776377 changed MessageHandler classes to use private class fields. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D154885
This commit is contained in:
harshrai654 2022-08-22 07:23:08 +00:00
Родитель 912f1eb914
Коммит b6c5f1c902
3 изменённых файлов: 39 добавлений и 28 удалений

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

@ -82,6 +82,12 @@ const ContextDescriptorType = {
* session id as well as some other context information.
*/
class MessageHandler extends EventEmitter {
#context;
#contextId;
#eventsDispatcher;
#moduleCache;
#sessionId;
/**
* Create a new MessageHandler instance.
*
@ -93,28 +99,28 @@ class MessageHandler extends EventEmitter {
constructor(sessionId, context) {
super();
this._moduleCache = new lazy.ModuleCache(this);
this.#moduleCache = new lazy.ModuleCache(this);
this._sessionId = sessionId;
this._context = context;
this._contextId = this.constructor.getIdFromContext(context);
this._eventsDispatcher = new lazy.EventsDispatcher(this);
this.#sessionId = sessionId;
this.#context = context;
this.#contextId = this.constructor.getIdFromContext(context);
this.#eventsDispatcher = new lazy.EventsDispatcher(this);
}
get context() {
return this._context;
return this.#context;
}
get contextId() {
return this._contextId;
return this.#contextId;
}
get eventsDispatcher() {
return this._eventsDispatcher;
return this.#eventsDispatcher;
}
get moduleCache() {
return this._moduleCache;
return this.#moduleCache;
}
get name() {
@ -122,15 +128,15 @@ class MessageHandler extends EventEmitter {
}
get sessionId() {
return this._sessionId;
return this.#sessionId;
}
destroy() {
lazy.logger.trace(
`MessageHandler ${this.constructor.type} for session ${this.sessionId} is being destroyed`
);
this._eventsDispatcher.destroy();
this._moduleCache.destroy();
this.#eventsDispatcher.destroy();
this.#moduleCache.destroy();
// At least the MessageHandlerRegistry will be expecting this event in order
// to remove the instance from the registry when destroyed.
@ -211,7 +217,7 @@ class MessageHandler extends EventEmitter {
* An array of Module classes.
*/
getAllModuleClasses(moduleName, destination) {
return this._moduleCache.getAllModuleClasses(moduleName, destination);
return this.#moduleCache.getAllModuleClasses(moduleName, destination);
}
/**
@ -236,7 +242,7 @@ class MessageHandler extends EventEmitter {
);
}
const module = this._moduleCache.getModuleInstance(moduleName, destination);
const module = this.#moduleCache.getModuleInstance(moduleName, destination);
if (module && module.supportsMethod(commandName)) {
return module[commandName](params, destination);
}

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

@ -31,6 +31,9 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
* layers (at the moment WindowGlobalMessageHandlers in content processes).
*/
class RootMessageHandler extends MessageHandler {
#frameTransport;
#sessionData;
/**
* Returns the RootMessageHandler module path.
*
@ -66,16 +69,16 @@ class RootMessageHandler extends MessageHandler {
constructor(sessionId) {
super(sessionId, null);
this._frameTransport = new lazy.FrameTransport(this);
this._sessionData = new lazy.SessionData(this);
this.#frameTransport = new lazy.FrameTransport(this);
this.#sessionData = new lazy.SessionData(this);
}
get sessionData() {
return this._sessionData;
return this.#sessionData;
}
destroy() {
this._sessionData.destroy();
this.#sessionData.destroy();
super.destroy();
}
@ -103,7 +106,7 @@ class RootMessageHandler extends MessageHandler {
forwardCommand(command) {
switch (command.destination.type) {
case lazy.WindowGlobalMessageHandler.type:
return this._frameTransport.forwardCommand(command);
return this.#frameTransport.forwardCommand(command);
default:
throw new Error(
`Cannot forward command to "${command.destination.type}" from "${this.constructor.type}".`
@ -136,7 +139,7 @@ class RootMessageHandler extends MessageHandler {
const isAdding = mode === "add";
const updateMethod = isAdding ? "addSessionData" : "removeSessionData";
const updatedValues = this._sessionData[updateMethod](
const updatedValues = this.#sessionData[updateMethod](
moduleName,
category,
contextDescriptor,
@ -155,7 +158,7 @@ class RootMessageHandler extends MessageHandler {
// Don't apply session data if the module is not present
// for the destination.
if (!this._moduleCache.hasModule(moduleName, destination)) {
if (!this.moduleCache.hasModule(moduleName, destination)) {
return Promise.resolve();
}

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

@ -18,10 +18,12 @@ const { ContextDescriptorType, MessageHandler } = ChromeUtils.import(
* MessageHandler network.
*/
class WindowGlobalMessageHandler extends MessageHandler {
#innerWindowId;
constructor() {
super(...arguments);
this._innerWindowId = this._context.window.windowGlobalChild.innerWindowId;
this.#innerWindowId = this.context.window.windowGlobalChild.innerWindowId;
}
/**
@ -57,11 +59,11 @@ class WindowGlobalMessageHandler extends MessageHandler {
}
get innerWindowId() {
return this._innerWindowId;
return this.#innerWindowId;
}
get window() {
return this._context.window;
return this.context.window;
}
async applyInitialSessionDataItems(sessionDataItems) {
@ -86,7 +88,7 @@ class WindowGlobalMessageHandler extends MessageHandler {
// Don't apply session data if the module is not present
// for the destination.
if (!this._moduleCache.hasModule(moduleName, destination)) {
if (!this.moduleCache.hasModule(moduleName, destination)) {
return Promise.resolve();
}
@ -109,8 +111,8 @@ class WindowGlobalMessageHandler extends MessageHandler {
// With the session data applied the handler is now ready to be used.
this.emitEvent("window-global-handler-created", {
contextId: this._contextId,
innerWindowId: this._innerWindowId,
contextId: this.contextId,
innerWindowId: this.#innerWindowId,
});
}
@ -124,7 +126,7 @@ class WindowGlobalMessageHandler extends MessageHandler {
return (
contextDescriptor.type === ContextDescriptorType.All ||
(contextDescriptor.type === ContextDescriptorType.TopBrowsingContext &&
contextDescriptor.id === this._context.browserId)
contextDescriptor.id === this.context.browserId)
);
}
}