Description[Android] Java Bridge: handle requests from Java Script on the background thread
This allows the page code that calls into injected objects methods to run even
if the browser UI thread is blocked (in WebView, the browser UI thread is the main
app thread, and sometimes people use synchronization primitives there that wait
on some action performed by the injected object, see the bug for an example).
In this CL, we make the minimal required amount of changes in order to simplify
cherry-picking into older branches. A cleanup CL (or CLs) will follow.
High-level description of changes:
1. We intercept messages from renderers on the IO thread using BrowserMessageFilter
and handle Java Bridge messages entirely on the background thread. This implies
the following changes:
2. GinJavaBridgeDispatcherHost has become RefCountedThreadSafe
(via BrowserMessageFilter)
3. We have to use route IDs of RenderFrameHosts instead of pointers to them, as
we can't access RFHs from IO or background threads.
4. Objects registry is now accessed from UI and background threads, and we have to use
locking. We can't anymore restrict access to the registry to a single thread.
This also means we can't anymore implement the registry using IDMap, as it is
explicitly non-thread-safe.
5. A lot of code was removed, as we now serve synchronous requests from renderers
without inter-thread hopping!
6. Of course, a new regression test has been added that now passes.
BUG=438255
Committed: https://crrev.com/a4b0d4cc0b9780aecd3e23a94293b2e3002baf7e
Cr-Commit-Position: refs/heads/master@{#307460}
Patch Set 1 #Patch Set 2 : Fixed AwJavaBridgeTest.testDestroyFromJavaObject and FindBugs warning #Patch Set 3 : Fix causes for test crashes #Patch Set 4 : Fixed remaining crashes, added 2 WebViews test, made it pass #
Total comments: 8
Patch Set 5 : Comments addressed, removed reliance on the Notifications service, added one more test #Patch Set 6 : Add the filter in more places, and make sure that the channel is present #
Total comments: 2
Patch Set 7 : Addressed benm's comment #
Total comments: 12
Patch Set 8 : Addressed Sami's comments #
Total comments: 4
Patch Set 9 : Addressed more Sami's comments #Messages
Total messages: 21 (3 generated)
|