Commit 46c21b64 authored by Danan S's avatar Danan S Committed by Chromium LUCI CQ

Fix bug where timeout was being erroneously cleared too early.

The timeout was being cleared when the PostMessageAPIServer was
receiving various messages before it received the 'init'
message from the guest content.

We can't rely on the messages only arriving after an 'init' is
received from the guest content.  The channel should be considered
up and ready from the moment that the *Chrome* side sends its 'init'
to the guest content.

We also can't rely on the guest content sending only expected messages,
since the web app frameworks we use for the guest content generate
messages for ui events like scrolling of the guest content, that we
do not process.

Bug: 1161564
Change-Id: I209d0a23b01dd8553a4ede5dedaff2a98f4f8ec3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618621Reviewed-by: default avatarYilkal Abe <yilkal@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Dan S <danan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841894}
parent 3c8956c5
...@@ -172,19 +172,24 @@ export class PostMessageAPIServer { ...@@ -172,19 +172,24 @@ export class PostMessageAPIServer {
return; return;
} }
if (this.initialization_timeout_id_) {
// Cancel the current init timeout, and signal to the initialization
// polling process that we have received an init message from the guest
// content, so it doesn't reschedule the timer.
clearTimeout(this.initialization_timeout_id_);
this.initialization_timeout_id_ = 0;
}
if (event.data === 'init') { if (event.data === 'init') {
if (this.initialization_timeout_id_) {
// Cancel the current init timeout, and signal to the initialization
// polling process that we have received an init message from the guest
// content, so it doesn't reschedule the timer.
clearTimeout(this.initialization_timeout_id_);
this.initialization_timeout_id_ = 0;
}
this.isInitialized_ = true; this.isInitialized_ = true;
return; return;
} }
// If we have gotten this far, we have received a message from a trusted
// origin, and we should try to process it. We can't gate this on whether
// the channel is initialized, because we can receive events out of order,
// and method calls can be received before the init event. Essentially, we
// should treat the channel as being potentially as soon as we send 'init'
// to the guest content.
const methodId = event.data.methodId; const methodId = event.data.methodId;
const fn = event.data.fn; const fn = event.data.fn;
const args = event.data.args || []; const args = event.data.args || [];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment