WebView Prerender: Implement new communication channel between host app and...
WebView Prerender: Implement new communication channel between host app and prerendered pages for tests This CL introduces a new communication channel between a host app (Java) and prerendered pages to notify lifecycle events on the prerendered pages in tests. 1) Before this CL AwPrerenderTest.java depended on onLoadResource() to detect a timing where prerendering is triggered and it's ready for activation. However, this was not appropriate for following reasons: - We shouldn't call onLoadResource() during prerendering to avoid a hosted app from being confused. See https://crbug.com/340041665. - onLoadResource() is called when a prerender request is sent. This doesn't work for No-Vary-Search header tests that will be added by subsequent CLs, as the tests need to wait until WebView receives a response for prerendering request to see the header. onLoadResource() is too early for them. 2) After this CL This CL adds a new communication channel to notify the primary page that a prerendered page starts executing JavaScript for tests. The timing should work for the No-Vary-Search header tests to be added by subsequent CLs. The communication channel is implemented in a tricky way, as communication among a host app (Java), the primary page, and prerendered pages are restricted. First, when a prerendered page starts executing JavaScript, the page writes a data in `window.localStorage`. This data is visible to the primary page as well. The primary page detects writes on the storage using `window.onstorage` event, and then forwards it to the host app using postMessage on WebMessage. In summary: Prerendered page --(window.localStorage)--> Primary page --(postMessage)--> Host app 3) Alternative ways to implement communication channel - WebMessage between the host app and the prerendered page: Messages posted by prerendered pages are deferred until activation, so WebMessage is not available for notifying lifecycle events on prerendered pages. - addJavascriptInterface(): In the current implementation, prerendered pages can access interfaces injected by addJavascriptInterface() and notify the host app of lifecycle events. However, we plan to disallow this communication path (calling an injected interface will result in prerender cancellation). See https://crbug.com/340005446 for details. Bug: 339588213, 340005446, 340041665 Change-Id: Id56f4cb99b3e49dfcdb6404cad57e6c4fc9b70f3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5526702 Reviewed-by:Richard (Torne) Coles <torne@chromium.org> Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org> Reviewed-by:
Ken Okada <kenoss@chromium.org> Reviewed-by:
Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/main@{#1300905}
Loading
Please register or sign in to comment