From fd50e5c08e134457a342bfc13d5a339be7ae514a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Mar=C3=A9chal?= Date: Thu, 28 Oct 2021 01:07:27 -0400 Subject: [PATCH] webview: fix host.js logic (#10336) The logic previously stopped the handler after running `this.postMessage` but I forgot to follow this when modifying this code in another PR. Fix the logic by respecting what was previously done. --- packages/plugin-ext/src/main/browser/webview/pre/host.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/webview/pre/host.js b/packages/plugin-ext/src/main/browser/webview/pre/host.js index 50255b5cf2f9b..2532e22557bed 100644 --- a/packages/plugin-ext/src/main/browser/webview/pre/host.js +++ b/packages/plugin-ext/src/main/browser/webview/pre/host.js @@ -26,6 +26,8 @@ constructor() { this.handlers = new Map(); window.addEventListener('message', e => { + // Note: `window.parent === window` when there is no parent... + const sourceIsSelfOrParentFrame = e.source === window.parent; let sourceIsChildFrame = false; for (let i = 0; i < window.frames.length; i++) { const frame = window.frames[i]; @@ -35,11 +37,8 @@ } } if (sourceIsChildFrame && e.data && (e.data.command === 'onmessage' || e.data.command === 'do-update-state')) { - // Came from inner iframe this.postMessage(e.data.command, e.data.data); - } - // Note: `window.parent === window` when there is no parent... - if (sourceIsChildFrame || e.source === window.parent) { + } else if (sourceIsChildFrame || sourceIsSelfOrParentFrame) { const channel = e.data.channel; const handler = this.handlers.get(channel); if (handler) {