Chromium Code Reviews| 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 152279a665cf3fef3ca79ed4120b9b80b5098e49..f1c15934ea0540a9142ab4be8d5ff2f0d8a93a37 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 () |
| // Container for |webView|. |
| @property(nonatomic, strong) UIView* containerView; |
| @@ -214,6 +218,87 @@ |
| [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* _Nonnull action) { |
|
Eugene But (OOO till 7-30)
2017/02/27 18:30:53
Is it possible to remove |action| to improve the f
michaeldo
2017/02/27 21:35:51
I get an error without the parameter name, but I c
|
| + 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* _Nonnull action) { |
| + handler(true); |
|
Eugene But (OOO till 7-30)
2017/02/27 18:30:52
s/true/YES
michaeldo
2017/02/27 21:35:51
Done.
|
| + }]]; |
| + [alert addAction:[UIAlertAction |
| + actionWithTitle:@"Cancel" |
| + style:UIAlertActionStyleCancel |
| + handler:^(UIAlertAction* _Nonnull action) { |
| + handler(false); |
|
Eugene But (OOO till 7-30)
2017/02/27 18:30:53
s/false/NO
michaeldo
2017/02/27 21:35:51
Done.
|
| + }]]; |
| + |
| + [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* _Nonnull action) { |
| + NSString* textInput = nil; |
| + if (weakAlert.textFields.count > 0) { |
| + textInput = weakAlert.textFields[0].text; |
|
Eugene But (OOO till 7-30)
2017/02/27 18:30:53
How about this?:
NSString* textInput = weakAlert.
michaeldo
2017/02/27 21:35:51
Done.
|
| + } |
| + handler(textInput); |
| + }]]; |
| + [alert addAction:[UIAlertAction |
| + actionWithTitle:@"Cancel" |
| + style:UIAlertActionStyleCancel |
| + handler:^(UIAlertAction* _Nonnull action) { |
| + handler(nil); |
| + }]]; |
| + |
| + [self presentViewController:alert animated:YES completion:nil]; |
| +} |
| + |
| #pragma mark CWVWebViewDelegate methods |
| - (void)webView:(CWVWebView*)webView |