Commit d4692321 authored by K Moon's avatar K Moon Committed by Commit Bot

Suppress exception in PDFViewer.sendScriptingMessage()

The postMessage() in sendScriptingMessage() may throw if targetOrigin is
an opaque URL (such as a "data:" URL). To work around this, suppress the
exception, which has the same effect as a blocked cross-origin message
(message is not sent, but caller completes normally).

This prevents the proposed changes in crrev.com/c/1747170 from causing
the ExtensionApiTest.TemporaryAddressSpoof test to get stuck, due to
asynchronous layout never completing.

Also made some tweaks to crrev.com/696209, which fixed the flakiness in
ExtensionApiTest.TemporaryAddressSpoof. The previous fix misunderstood
the purpose of TestNavigationManager, which observes navigations rather
than causing them. It also doesn't make sense to proceed if the call to
WaitForRequestStart() fails, so this is now an ASSERT.

Bug: 885110, 1004425
Change-Id: I5eb42992a8c3306c6c76eafac5caa34e5cf3134d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857598
Commit-Queue: K Moon <kmoon@chromium.org>
Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707625}
parent d445daff
......@@ -2096,7 +2096,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TemporaryAddressSpoof) {
blink::WebMouseEvent::Button::kLeft,
gfx::Point(400, 400));
EXPECT_TRUE(navigation_manager.WaitForRequestStart());
ASSERT_TRUE(navigation_manager.WaitForRequestStart());
browser()->tab_strip_model()->ActivateTabAt(
0, {TabStripModel::GestureType::kOther});
......@@ -2109,7 +2109,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TemporaryAddressSpoof) {
EXPECT_EQ(url, second_web_contents->GetVisibleURL());
// Wait for the TestNavigationManager-initiated navigation to complete to
// Wait for the TestNavigationManager-monitored navigation to complete to
// avoid a race during browser teardown (see crbug.com/882213).
navigation_manager.WaitForNavigationFinished();
}
......
......@@ -1166,7 +1166,12 @@ export class PDFViewer {
} else {
targetOrigin = this.originalUrl_;
}
this.parentWindow_.postMessage(message, targetOrigin);
try {
this.parentWindow_.postMessage(message, targetOrigin);
} catch (ok) {
// TODO(crbug.com/1004425): targetOrigin probably was rejected, such as
// a "data:" URL. This shouldn't cause this method to throw, though.
}
}
}
......
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