-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Filter onChanged events for invalid displays #1964
Conversation
93fed39 to
63b421d
Compare
mklim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
|
||
| /** Should be called prior to the webview's initialization. */ | ||
| void onPreWebViewInitialization(DisplayManager displayManager) { | ||
| listenersBeforeWebView = yoinkDisplayListeners(displayManager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Learned from the best 😄
| /** Should be called after the webview's initialization. */ | ||
| void onPostWebViewInitialization(final DisplayManager displayManager) { | ||
| final ArrayList<DisplayListener> listeners = yoinkDisplayListeners(displayManager); | ||
| // We recorded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is this comment incomplete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, completed it.
| name = "Embed Frameworks"; | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| }; | ||
| /* End PBXCopyFilesBuildPhase section */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The changes in this file look like they could be reverted.
.../webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java
Show resolved
Hide resolved
…er#1964) Works around an Android WebView bug that was causing a crash by filtering some DisplayListener invocations. Older Android WebView versions had assumed that when DisplayListener#onDisplayChanged is invoked, the display ID it is provided is of a valid display. However it turns out that when a display is removed Android may call onDisplayChanged with the ID of the removed display, in this case the Android WebView code tries to fetch and use the display with this ID and crashes with an NPE. The issue was fixed in the Android WebView code in https://chromium-review.googlesource.com/517913 which is available starting WebView version 58.0.3029.125 however older webviews in the wild still have this issue. Since Flutter removes virtual displays whenever a platform view is resized the webview crash is more likely to happen than other apps. And users were reporting this issue see: flutter/flutter#30420 This change works around the webview bug by unregistering the WebView's DisplayListener, and instead registering our own DisplayListener which delegates the callbacks to the WebView's listener unless it's a onDisplayChanged for an invalid display.
Description
Works around an Android WebView bug that was causing a crash by filtering some DisplayListener invocations.
Older Android WebView versions had assumed that when
DisplayListener#onDisplayChangedis invoked, the display ID it is provided is of a valid display. However it turns out that when a display is removed Android may call onDisplayChanged with the ID of the removed display, in this case the Android WebView code tries to fetch and use the display with this ID and crashes with an NPE.The issue was fixed in the Android WebView code in https://chromium-review.googlesource.com/517913 which is available starting WebView version 58.0.3029.125 however older webviews in the wild still have this issue.
Since Flutter removes virtual displays whenever a platform view is resized the webview crash is more likely to happen than other apps. And users were reporting this issue see: flutter/flutter#30420
This change works around the webview bug by unregistering the WebView's DisplayListener, and instead registering our own DisplayListener which delegates the callbacks to the WebView's listener unless it's a onDisplayChanged for an invalid display.
Related Issues
Fixes flutter/flutter#30420
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?