Skip to content

Commit

Permalink
webview: fix host.js logic (#10336)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paul-marechal authored Oct 28, 2021
1 parent 008c2a1 commit fd50e5c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/plugin-ext/src/main/browser/webview/pre/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down

0 comments on commit fd50e5c

Please sign in to comment.