Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_wkwebview] Add support for WKNavigationDelegate#4893

Merged
bparrishMines merged 11 commits intoflutter:mainfrom
bparrishMines:ios_webview_4
Mar 10, 2022
Merged

[webview_flutter_wkwebview] Add support for WKNavigationDelegate#4893
bparrishMines merged 11 commits intoflutter:mainfrom
bparrishMines:ios_webview_4

Conversation

@bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Feb 18, 2022

No version change:
Part of flutter/flutter#93732 and doesn't make any changes to the current implementation.

No CHANGELOG change: Incremental unused code doesn't need to be noted in the CHANGELOG.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-ios labels Feb 18, 2022
@bparrishMines bparrishMines changed the title [WIP] Ios webview 4 [webview_flutter_wkwebview] Ios webview 4 Feb 24, 2022
@bparrishMines bparrishMines changed the title [webview_flutter_wkwebview] Ios webview 4 [webview_flutter_wkwebview] Add support for WKNavigationDelegate Feb 24, 2022
errorType: WebResourceErrorType.webContentProcessTerminated,
));
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WKUserContentController userContentController,
WKScriptMessage message,
)
)?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These can be nullable now since null parameters with pigeon are on their way.

webViewProxy.createNavigationDelegate()
..didStartProvisionalNavigation = (WKWebView webView) {
webView.url.then<void>(
(String? url) => callbacksHandler.onPageStarted(url ?? ''),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative to needing to make another method call to retrieve the url would be to create a custom method in WKNavigationDelegate that also includes the url.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a case where we are going to actually need to flex the boundary away from the direct wrapping slightly, because of the async calls. This won't actually give correct results in all cases, because If there's a sequence of redirects there's no guarantee that the URL that is retrieved asynchronously is actually the one that the delegate callback was actually about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I updated the method

///
/// Provide a delegate object when you want to manage or restrict navigation
/// in your web content, track the progress of navigation requests, and handle
/// authentication challenges for any new content.
Copy link
Contributor

Choose a reason for hiding this comment

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

Per previous discussion, we should be linking to docs rather that duplicating them for wrappers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was to include basic information, so someone wouldn't have to open a browser for every class/method. I removed this paragraph and just kept the summary above.

webViewProxy.createNavigationDelegate()
..didStartProvisionalNavigation = (WKWebView webView) {
webView.url.then<void>(
(String? url) => callbacksHandler.onPageStarted(url ?? ''),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a case where we are going to actually need to flex the boundary away from the direct wrapping slightly, because of the async calls. This won't actually give correct results in all cases, because If there's a sequence of redirects there's no guarantee that the URL that is retrieved asynchronously is actually the one that the delegate callback was actually about.

@bparrishMines
Copy link
Contributor Author

@stuartmorgan This should be ready for another review.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM with nit, sorry for the delay.

@@ -1,5 +1,5 @@
// Mocks generated by Mockito 5.0.17 from annotations
// in webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart.
// in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong; any idea how this path got messed up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, but I upgraded Flutter and mockito to the latest versions and it still outputs the symlink. I created an issue for the dart team: dart-lang/mockito#521

@bparrishMines bparrishMines added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Mar 9, 2022
@bparrishMines bparrishMines merged commit 197af08 into flutter:main Mar 10, 2022
@bparrishMines bparrishMines deleted the ios_webview_4 branch March 10, 2022 01:39
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p: webview_flutter Edits files for a webview_flutter plugin platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants