Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: ios/web_view/shell/shell_view_controller.m

Issue 2715343002: Add JavaScript prompts support to CWVUIDelegate. (Closed)
Patch Set: Respond to comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web_view/shell/shell_view_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web_view/shell/shell_view_controller.m
diff --git a/ios/web_view/shell/shell_view_controller.m b/ios/web_view/shell/shell_view_controller.m
index 89f19d98f5dc9c8ef589bcd1753751770befe42e..18a08c2f879316b1d6eac1f6663a9e28594d5064 100644
--- a/ios/web_view/shell/shell_view_controller.m
+++ b/ios/web_view/shell/shell_view_controller.m
@@ -15,6 +15,10 @@
#error "This file requires ARC support."
#endif
+// Externed accessibility identifier.
+NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
+ @"WebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier";
+
@interface ShellViewController ()<CWVUIDelegate,
CWVWebViewDelegate,
UITextFieldDelegate>
@@ -216,6 +220,81 @@
[self presentViewController:alert animated:YES completion:nil];
}
+- (void)webView:(CWVWebView*)webView
+ runJavaScriptAlertPanelWithMessage:(NSString*)message
+ pageURL:(NSURL*)URL
+ completionHandler:(void (^)(void))handler {
+ UIAlertController* alert =
+ [UIAlertController alertControllerWithTitle:nil
+ message:message
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ [alert addAction:[UIAlertAction actionWithTitle:@"Ok"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ handler();
+ }]];
+
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)webView:(CWVWebView*)webView
+ runJavaScriptConfirmPanelWithMessage:(NSString*)message
+ pageURL:(NSURL*)URL
+ completionHandler:(void (^)(BOOL))handler {
+ UIAlertController* alert =
+ [UIAlertController alertControllerWithTitle:nil
+ message:message
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ [alert addAction:[UIAlertAction actionWithTitle:@"Ok"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ handler(YES);
+ }]];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:^(UIAlertAction* action) {
+ handler(NO);
+ }]];
+
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)webView:(CWVWebView*)webView
+ runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
+ defaultText:(NSString*)defaultText
+ pageURL:(NSURL*)URL
+ completionHandler:(void (^)(NSString*))handler {
+ UIAlertController* alert =
+ [UIAlertController alertControllerWithTitle:nil
+ message:prompt
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
+ textField.text = defaultText;
+ textField.accessibilityIdentifier =
+ kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier;
+ }];
+
+ __weak UIAlertController* weakAlert = alert;
+ [alert addAction:[UIAlertAction
+ actionWithTitle:@"Ok"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ NSString* textInput =
+ weakAlert.textFields.firstObject.text;
+ handler(textInput);
+ }]];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:^(UIAlertAction* action) {
+ handler(nil);
+ }]];
+
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
#pragma mark CWVWebViewDelegate methods
- (void)webView:(CWVWebView*)webView
« no previous file with comments | « ios/web_view/shell/shell_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698