-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[webview_flutter] Add interface for showing javascript dialog message #4704
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] 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this method
| }, | ||
| runJavaScriptAlertDialog: (String message) async { | ||
| final Future<void> Function(String message)? callback = | ||
| _onJavaScriptAlertDialogCallback; |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it. Can you check it again?
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.
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
d18d501 to
2b35ddd
Compare
bparrishMines
left a comment
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
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; looks like I just pressed the wrong button last time.
flutter/packages@29d8cc0...11152d2 2024-02-09 [email protected] [webview_flutter] Add interface for showing javascript dialog message (flutter/packages#4704) 2024-02-09 [email protected] [pigeon] Implement Screaming Snake Case Conversion for Kotlin Enum Cases (flutter/packages#5918) 2024-02-09 [email protected] [camerax] Small fixes to starting/stopping video capture (flutter/packages#6068) 2024-02-08 [email protected] Roll Flutter from 8431cae to eb5d0a4 (33 revisions) (flutter/packages#6079) 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
…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: flutter/packages#5670 * The PR that contains all changes can be found at flutter/packages#4704

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.