-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[webview_flutter_android] Fixes iframe navigation with onNavigationRequest
#6335
[webview_flutter_android] Fixes iframe navigation with onNavigationRequest
#6335
Conversation
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.
This is a good fix! It looks like I missed this code in the pre webview v4
code: https://github.com/flutter/plugins/pull/1236/files#diff-8ba24b285f0228d5dd613ad64b1e63f6ce4be9819ec1a7e102a2dd269de569c6R53
I think we should also change AndroidWebViewController
to only call onNavigationRequest
for the main frame. Otherwise, someone may return prevent
to the callback and it would be ignored for an unknown reason.
...ndroid/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientHostApiImpl.java
Outdated
Show resolved
Hide resolved
...oid/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatImplTest.java
Outdated
Show resolved
Hide resolved
I was thinking the same, but for now restored the 'old' behaviour. I guess it was like that to still inform the flutter side. My current fix indeed needs this in our implementation, which doesn't make much sense. if (!navigation.isMainFrame) {
return _platformRepo.isIOS ? NavigationDecision.navigate : NavigationDecision.prevent;
} I will apply your suggestion tomorrow. |
6076ea3
to
7ffecb4
Compare
...ndroid/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientHostApiImpl.java
Outdated
Show resolved
Hide resolved
…ionDelegate.onNavigationRequest` is present.
… tests and comments
1542a28
to
76a210f
Compare
76a210f
to
d1d3bd6
Compare
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.
Most of this looks good. Just a few more comments.
@stuartmorgan This is ready for a secondary review. And what are your thoughts on this being a bug fix on needing to be a breaking change?
...utter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientTest.java
Show resolved
Hide resolved
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
@stuartmorgan for secondary review
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
flutter/packages@aea93d2...f4719ca 2024-05-02 [email protected] [in_app_purchase] implement countryCode correctly (flutter/packages#6636) 2024-05-02 [email protected] Skip podspec Swift Search Path validation if only swift file is Package.swift for darwin plugins (flutter/packages#6635) 2024-05-02 [email protected] Roll Flutter from d33bb8f to bf7191f (34 revisions) (flutter/packages#6637) 2024-05-01 [email protected] [webview_flutter_android] Fixes iframe navigation with `onNavigationRequest` (flutter/packages#6335) 2024-05-01 [email protected] Roll Flutter from b597dd2 to d33bb8f (7 revisions) (flutter/packages#6633) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…equest` (flutter#6335) This PR reintroduces the check on `WebResourceRequest.isForMainFrame` in the `shouldOverrideUrlLoading` callback. This check already existed in the implementation before the change to Pigeon, but was not taken over. See https://github.com/flutter/packages/blob/418bef0d6f3100e7a4bafb86537285e6d2095159/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java#L99 The reasoning was already already in comment there: ``` // Since we cannot call loadUrl for a subframe, we currently only allow the delegate to stop // navigations that target the main frame, if the request is not for the main frame // we just return false to allow the navigation. // // For more details see: flutter/flutter#25329 (comment) ``` Currently when a `NavigationDeletage.onNavigationRequest` is set and a navigation request for an iframe happens it will automatically be blocked and handed to the Flutter `onNavigationRequest`. If the request gets a `NavigationDecision.navigate` it will be loaded into the mainframe through a `loadUrl`. If the request gets a `NavigationDecision.prevent` it will never be executed. This causes an issue when for example an iframe loads local data. Example ```data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}<\/script>``` An iframe is allowed to do this, but with the current implementation this data will be loaded in the main frame, leading to a white page. Issue: flutter/flutter#145208
…equest` (flutter#6335) This PR reintroduces the check on `WebResourceRequest.isForMainFrame` in the `shouldOverrideUrlLoading` callback. This check already existed in the implementation before the change to Pigeon, but was not taken over. See https://github.com/flutter/packages/blob/418bef0d6f3100e7a4bafb86537285e6d2095159/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java#L99 The reasoning was already already in comment there: ``` // Since we cannot call loadUrl for a subframe, we currently only allow the delegate to stop // navigations that target the main frame, if the request is not for the main frame // we just return false to allow the navigation. // // For more details see: flutter/flutter#25329 (comment) ``` Currently when a `NavigationDeletage.onNavigationRequest` is set and a navigation request for an iframe happens it will automatically be blocked and handed to the Flutter `onNavigationRequest`. If the request gets a `NavigationDecision.navigate` it will be loaded into the mainframe through a `loadUrl`. If the request gets a `NavigationDecision.prevent` it will never be executed. This causes an issue when for example an iframe loads local data. Example ```data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}<\/script>``` An iframe is allowed to do this, but with the current implementation this data will be loaded in the main frame, leading to a white page. Issue: flutter/flutter#145208
This PR reintroduces the check on
WebResourceRequest.isForMainFrame
in theshouldOverrideUrlLoading
callback.This check already existed in the implementation before the change to Pigeon, but was not taken over. See
packages/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java
Line 99 in 418bef0
The reasoning was already already in comment there:
Currently when a
NavigationDeletage.onNavigationRequest
is set and a navigation request for an iframe happens it will automatically be blocked and handed to the FlutteronNavigationRequest
.If the request gets a
NavigationDecision.navigate
it will be loaded into the mainframe through aloadUrl
.If the request gets a
NavigationDecision.prevent
it will never be executed.This causes an issue when for example an iframe loads local data.
Example
data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}<\/script>
An iframe is allowed to do this, but with the current implementation this data will be loaded in the main frame, leading to a white page.
Issue: flutter/flutter#145208
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.