-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
This came up as part of #25329:
The Android WebView API allows passing in a delegate that is invoked on the platform thread before a page is about to be loaded, the delegate needs to synchronously return true or false to determine whether to allow the navigation or to block it.
We needed to expose the same functionality in the webview_flutter plugin, ideally by delegating the decision to the Flutter application's Dart code. But this is currently impossible due to the combination of:
- Communication over platform channels is asynchronous.
- Messages sent from Dart to the platform channels are only delivered to the platform thread(by posting a task to the message loop).
Even if we were to block the platform thread waiting for the Dart code to make a decision, we would not be able to receive the message back from Dart(as the platform thread is blocked) and create a deadlock.
One potential approach for overriding this is to allow "platform channels" that deliver message to platform code on a separate thread. We could then:
- Send a message to Dart from the platform thread.
- Block the platform thread with some thread synchronization primitive.
- Dart code will send the response to a dedicated thread.
- The dedicated thread will release the latch that the platform thread is waiting on.
If we do this we should probably require that the "special thread" is always different from the platform thread.
For #25329 we're currently proceeding with a workaround that makes some security compromises(which means when an app sets a navigation delegate it should only load trusted content). But we should remove that workaround as soon as this issue is resolved.