Bug 1731548 - [remote] Cache innerWindowId on WindowGlobalMessageHandler. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D132060
This commit is contained in:
Henrik Skupin 2021-11-26 12:45:43 +00:00
parent b5283b0fef
commit 809bd45036
2 changed files with 18 additions and 5 deletions

View File

@ -25,6 +25,14 @@ XPCOMUtils.defineLazyModuleGetters(this, {
* MessageHandler network.
*/
class WindowGlobalMessageHandler extends MessageHandler {
constructor() {
super(...arguments);
// Bug 1743083: Temporarily delay caching of the inner window id until
// the session data is no longer applied before super() returns.
this._innerWindowId;
}
/**
* Returns the WindowGlobalMessageHandler module path.
*
@ -57,6 +65,14 @@ class WindowGlobalMessageHandler extends MessageHandler {
return context.id;
}
get innerWindowId() {
if (this._innerWindowId === undefined) {
this._innerWindowId = this._context.window.windowGlobalChild.innerWindowId;
}
return this._innerWindowId;
}
forwardCommand(command) {
throw new Error(
`Cannot forward commands from a "WINDOW_GLOBAL" MessageHandler`

View File

@ -54,12 +54,9 @@ class Log extends Module {
}
_onConsoleAPILogEvent(message) {
const browsingContext = BrowsingContext.get(this.messageHandler.contextId);
const innerWindowId =
browsingContext.window.windowGlobalChild?.innerWindowId;
const messageObject = message.wrappedJSObject;
if (innerWindowId !== messageObject.innerID) {
if (messageObject.innerID !== this.messageHandler.innerWindowId) {
// If the message doesn't match the innerWindowId of the current context
// ignore it.
return;