Skip to content

Add option to use navigation delegate feature of WebViews for iframes #434

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

Conversation

DFelten
Copy link
Contributor

@DFelten DFelten commented Oct 25, 2020

Currently it's not possible to overwrite the link handling within the iframe WebViews of flutter_html. With this merge request a new parameter for the HTML widget is added, which is forwarded to the WebView and can control the navigation within it.

Unfortunately the WebView package must be available within the app, otherwise NavigationDecision is not known. You could write a wrapper for this, but in my opinion this is not necessary.

@DFelten
Copy link
Contributor Author

DFelten commented Oct 29, 2020

@erickok Did you have time to look at this MR? Are the changes ok like this?

@erickok
Copy link
Contributor

erickok commented Oct 29, 2020

It's okay, but I wonder what we can do to prevent the more and more constructor parameters from getting out of hand... Especially since now you have to keep passing this on to where you eventually want to use it. it's not so bad, but I'm just thinking out loud.

@DFelten
Copy link
Contributor Author

DFelten commented Oct 30, 2020

Yes, you're right. So there can be more and more parameters and at some point it becomes too much. But here it is more important that functionality is available. Otherwise I would have to create a custom renderer for each WebView.

Another idea would be to group the constructor parameters. Then there would be for example an iFrameConfig object.

@erickok
Copy link
Contributor

erickok commented Oct 30, 2020

Yes I agree, in this end we want to use this library. I hope to have some time very soon to dive into the code, as for now I am just trying to answer questions, clean up issues and give my review/opinion. Without counter argument soon, your pr should be merged.

@erickok
Copy link
Contributor

erickok commented Nov 19, 2020

I have tested this and it is working well. For example, I used in the example app:

          navigationDelegateForIframe: (request) {
            if (request.isForMainFrame && !Uri.parse(request.url).host.endsWith("google.com")) {
              return NavigationDecision.prevent;
            } else {
              return NavigationDecision.navigate;
            }
          },

and it prevents any navigation away from Google itself. (This is often used to start an external browser in such cases, to 'escape' the iframe.)

This is good to merge for me! @ryan-berger

@ryan-berger ryan-berger merged commit ac4db23 into Sub6Resources:master Nov 22, 2020
@DFelten DFelten deleted the feature/support-for-iframe-navigation-delegate branch November 22, 2020 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants