[webview_flutter] Add interface for showing javascript dialog message#4704
Conversation
4788137 to
7dfb120
Compare
|
@bparrishMines Hi, Can you check this PR? This is my first contribution here so I don't know exact routine for contribution. Help me please. Thanks :) |
7dfb120 to
850e9f5
Compare
bparrishMines
left a comment
There was a problem hiding this comment.
Thanks for implementing this for Android and iOS! I left my first comments.
Also, we're working on updating pigeon to handle more of the wrapping code if you would prefer to wait for that before continuing.
There was a problem hiding this comment.
nit:
| * Add support to show JavaScript dialog. See `PlatformWebViewController.setJavaScriptAlertDialogCallback`. | |
| * Adds support to show JavaScript dialog. See `PlatformWebViewController.setJavaScriptAlertDialogCallback`. |
This can also list the other two callback methods.
There was a problem hiding this comment.
Since this is only setting one callback method, the pattern should be
| Future<void> setJavaScriptAlertDialogCallback( | |
| Future<void> Function(String message) | |
| javaScriptAlertDialogCallback) async { | |
| Future<void> setOnJavaScriptAlertDialog( | |
| Future<void> Function(String message) | |
| onJavaScriptAlertDialog) async { |
Same for the two methods below.
There was a problem hiding this comment.
This will be a minor version bump since it is adding a new feature. (e.g. 2.6.0)
There was a problem hiding this comment.
Since the platform interface separates handling the callbacks into three separate methods, you should also have three separate flags for each alert/confirm/prompt. What happens if a user only wants to set the confirm dialog?
There was a problem hiding this comment.
Since the native WKUIDelegate separates handling dialogs into separate methods, this should also.
232e186 to
41bf657
Compare
|
@bparrishMines It has been modified according to the review. Could you please check the code again? |
|
|
||
| /// Sets a callback that notifies the host application that the web page | ||
| /// wants to display a JavaScript alert() dialog. | ||
| Future<void> setOnJavaScriptAlertDialogCallback( |
There was a problem hiding this comment.
This still uses Callback at the end. It should be setOnJavaScriptAlertDialog. Same for the confirm and textInputDialog methods below.
| ); | ||
| } | ||
|
|
||
| Future<void> setHasJavaScriptAlertCallback( |
There was a problem hiding this comment.
This and the two methods below should follow the same pattern as onShowFileChooser and be called setSynchronousReturnValueForOnJsAlert.
| /// mode. | ||
| final HideCustomViewCallback? onHideCustomView; | ||
|
|
||
| final Future<void> Function(String message)? onHandleJavaScriptAlert; |
There was a problem hiding this comment.
These should have the same name as the corresponding Java method. (e.g. onJsAlert). They should also have a return value of void since they can't return a synchronous value.
There was a problem hiding this comment.
@bparrishMines
Sorry, I cannot fully understand on your comment.
They should also have a return value of void since they can't return a synchronous value.
They should have a Future value to pass the value for JSResult and it works well in my test.
FileChooser in android_webview also return a List previously, So I just follow it to implement.
Can you explain more to fix this?
I really appreciate your help :)
There was a problem hiding this comment.
Ah, now I understand. Your implementation is correct. I didn't notice the JSResult in the params.
| final bool Function()? hasJavaScriptAlertCallback; | ||
| final bool Function()? hasJavaScriptConfirmCallback; | ||
| final bool Function()? hasJavaScriptPromptCallback; |
There was a problem hiding this comment.
These can be removed. I don't believe they are used and they are redundant with the callback methods above.
| ), | ||
| onHandleJavaScriptAlert: withWeakReferenceTo(this, (WeakReference<AndroidWebViewController> weakReference) { | ||
| return (String message) async { | ||
| final Future<void> Function(String)? callback = _onJavaScriptAlertCallback; |
There was a problem hiding this comment.
This should use weakReference?.target._onJavaScriptAlertCallback, otherwise this will cause a leak. Same for the other dialog fields below.
| 'runJavaScriptAlertPanelForDelegateWithIdentifier:message:', | ||
| ) | ||
| @async | ||
| void runJavaScriptAlertPanelWithIdentifier( |
There was a problem hiding this comment.
This should be runJavaScriptAlertPanel. The withIdentifier should only be added to the @ObjCSelector annotation above and not in the method.
| 'runJavaScriptConfirmPanelForDelegateWithIdentifier:message:', | ||
| ) | ||
| @async | ||
| bool runJavaScriptConfirmPanelWithIdentifier( |
There was a problem hiding this comment.
Same for this method
| }, | ||
| runJavaScriptAlertDialog: (String message) async { | ||
| final Future<void> Function(String message)? callback = | ||
| _onJavaScriptAlertDialogCallback; |
There was a problem hiding this comment.
This needs to be weakThis.target?._onJavaScriptAlertDialogCallback. The methods below also need to be updated.
54a7f6b to
634c05f
Compare
There was a problem hiding this comment.
It looks like WebChromeClient.onJsAlert and WKUIDelegate.runJavaScriptAlertPanelWithMessage also provide the URL for these callbacks. We should change String message to a class that contains a message field where we can add additional information at a later point. You could create a class named something like JavaScriptAlertDialogRequest. See JavaScriptConsoleMessage as an example.
This goes for the methods below as well. (e.g. JavaScriptConfirmDialogRequest and JavaScriptTextInputDialogRequest).
There was a problem hiding this comment.
I fixed it. Can you check it again?
There was a problem hiding this comment.
nit:
| * Adds support to show JavaScript dialog. Sees `PlatformWebViewController.setOnJavaScriptAlertDialog`, `PlatformWebViewController.setOnJavaScriptConfirmDialog` and `PlatformWebViewController.setOnJavaScriptTextInputDialog`. | |
| * Adds support to show JavaScript dialog. See | |
| `PlatformWebViewController.setOnJavaScriptAlertDialog`, | |
| `PlatformWebViewController.setOnJavaScriptConfirmDialog`, and | |
| `PlatformWebViewController.setOnJavaScriptTextInputDialog`. |
2e83c14 to
3930794
Compare
185378d to
3913e59
Compare
…iew (#5795) * There are cases where Web calls System Popup with javascript on webview_flutter * At this time, the message comes in the WKUIDelegate part in iOS. * https://developer.apple.com/documentation/webkit/wkuidelegate/1537406-webview * https://developer.apple.com/documentation/webkit/wkuidelegate/1536489-webview * Related issue: flutter/flutter#30358 (comment) * Related Interface PR: #5670 * The PR that contains all changes can be found at #4704
…5796) * There are cases where Web calls System Popup with javascript on webview_flutter * Android has a interface on WebChromeClient * https://developer.android.com/reference/android/webkit/WebChromeClient#onJsAlert(android.webkit.WebView,%20java.lang.String,%20java.lang.String,%20android.webkit.JsResult) * Related issue: flutter/flutter#30358 (comment) * Related Interface PR: #5670 * The PR that contains all changes can be found at #4704
3913e59 to
41253b3
Compare
|
@bparrishMines @stuartmorgan @hellohuanlin HI, This PR only contains webview_flutter package part now. |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
LGTM with CHANGELOG nit. @bparrishMines for secondary approval.
There was a problem hiding this comment.
Nit: "Adds support for custom handling of JavaScript dialogs. See [...]"
There was a problem hiding this comment.
(Also, please wrap to ~80 characters.)
There was a problem hiding this comment.
This two lines can be removed you have the content now in 4.6.0
|
@jsharp83 I think you missed that line break change request. I cannot await that this goes finally live. |
|
auto label is removed for flutter/packages/4704, due to This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
|
@stuartmorgan It looks like this needs the approval along with your LGTM |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
LGTM; looks like I just pressed the wrong button last time.

Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto 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.