Skip to content
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

Merged

Conversation

petermnt
Copy link
Contributor

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

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: https://github.com/flutter/flutter/issues/25329#issuecomment-464863209

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

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@bparrishMines bparrishMines left a 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.

@petermnt
Copy link
Contributor Author

petermnt commented Mar 21, 2024

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.

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.

@petermnt petermnt force-pushed the webview-android-navigation-delegate branch from 6076ea3 to 7ffecb4 Compare March 21, 2024 20:20
@petermnt petermnt force-pushed the webview-android-navigation-delegate branch from 1542a28 to 76a210f Compare March 27, 2024 19:36
@petermnt petermnt force-pushed the webview-android-navigation-delegate branch from 76a210f to d1d3bd6 Compare March 27, 2024 19:38
Copy link
Contributor

@bparrishMines bparrishMines left a 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?

Copy link
Contributor

@bparrishMines bparrishMines left a 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

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label May 1, 2024
@auto-submit auto-submit bot merged commit 6e60826 into flutter:main May 1, 2024
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 3, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 3, 2024
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
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
…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
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants