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

Side by Side Diff: ios/web_view/shell/shell_view_controller.m

Issue 2715343002: Add JavaScript prompts support to CWVUIDelegate. (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web_view/shell/shell_view_controller.h" 5 #import "ios/web_view/shell/shell_view_controller.h"
6 6
7 #import <MobileCoreServices/UTCoreTypes.h> 7 #import <MobileCoreServices/UTCoreTypes.h>
8 8
9 #import "ios/web_view/public/cwv.h" 9 #import "ios/web_view/public/cwv.h"
10 #import "ios/web_view/public/cwv_html_element.h" 10 #import "ios/web_view/public/cwv_html_element.h"
11 #import "ios/web_view/public/cwv_web_view.h" 11 #import "ios/web_view/public/cwv_web_view.h"
12 #import "ios/web_view/shell/translate_controller.h" 12 #import "ios/web_view/shell/translate_controller.h"
13 13
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 15 #error "This file requires ARC support."
16 #endif 16 #endif
17 17
18 // Externed accessibility identifier.
19 NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
20 @"WebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier";
21
18 @interface ShellViewController () 22 @interface ShellViewController ()
19 // Container for |webView|. 23 // Container for |webView|.
20 @property(nonatomic, strong) UIView* containerView; 24 @property(nonatomic, strong) UIView* containerView;
21 // Text field used for navigating to URLs. 25 // Text field used for navigating to URLs.
22 @property(nonatomic, strong) UITextField* field; 26 @property(nonatomic, strong) UITextField* field;
23 // Toolbar containing navigation buttons and |field|. 27 // Toolbar containing navigation buttons and |field|.
24 @property(nonatomic, strong) UIToolbar* toolbar; 28 @property(nonatomic, strong) UIToolbar* toolbar;
25 // CWV view which renders the web page. 29 // CWV view which renders the web page.
26 @property(nonatomic, strong) CWVWebView* webView; 30 @property(nonatomic, strong) CWVWebView* webView;
27 // Handles the translation of the content displayed in |webView|. 31 // Handles the translation of the content displayed in |webView|.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 style:UIAlertActionStyleDefault 211 style:UIAlertActionStyleDefault
208 handler:handler]]; 212 handler:handler]];
209 213
210 [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" 214 [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
211 style:UIAlertActionStyleCancel 215 style:UIAlertActionStyleCancel
212 handler:nil]]; 216 handler:nil]];
213 217
214 [self presentViewController:alert animated:YES completion:nil]; 218 [self presentViewController:alert animated:YES completion:nil];
215 } 219 }
216 220
221 - (void)webView:(CWVWebView*)webView
222 runJavaScriptAlertPanelWithMessage:(NSString*)message
223 pageURL:(NSURL*)URL
224 completionHandler:(void (^)(void))handler {
225 UIAlertController* alert =
226 [UIAlertController alertControllerWithTitle:nil
227 message:message
228 preferredStyle:UIAlertControllerStyleAlert];
229
230 [alert addAction:[UIAlertAction
231 actionWithTitle:@"Ok"
232 style:UIAlertActionStyleDefault
233 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
234 handler();
235 }]];
236
237 [self presentViewController:alert animated:YES completion:nil];
238 }
239
240 - (void)webView:(CWVWebView*)webView
241 runJavaScriptConfirmPanelWithMessage:(NSString*)message
242 pageURL:(NSURL*)URL
243 completionHandler:(void (^)(BOOL))handler {
244 UIAlertController* alert =
245 [UIAlertController alertControllerWithTitle:nil
246 message:message
247 preferredStyle:UIAlertControllerStyleAlert];
248
249 [alert addAction:[UIAlertAction
250 actionWithTitle:@"Ok"
251 style:UIAlertActionStyleDefault
252 handler:^(UIAlertAction* _Nonnull action) {
253 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.
254 }]];
255 [alert addAction:[UIAlertAction
256 actionWithTitle:@"Cancel"
257 style:UIAlertActionStyleCancel
258 handler:^(UIAlertAction* _Nonnull action) {
259 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.
260 }]];
261
262 [self presentViewController:alert animated:YES completion:nil];
263 }
264
265 - (void)webView:(CWVWebView*)webView
266 runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
267 defaultText:(NSString*)defaultText
268 pageURL:(NSURL*)URL
269 completionHandler:(void (^)(NSString*))handler {
270 UIAlertController* alert =
271 [UIAlertController alertControllerWithTitle:nil
272 message:prompt
273 preferredStyle:UIAlertControllerStyleAlert];
274
275 [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
276 textField.text = defaultText;
277 textField.accessibilityIdentifier =
278 kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier;
279 }];
280
281 __weak UIAlertController* weakAlert = alert;
282 [alert addAction:[UIAlertAction
283 actionWithTitle:@"Ok"
284 style:UIAlertActionStyleDefault
285 handler:^(UIAlertAction* _Nonnull action) {
286 NSString* textInput = nil;
287 if (weakAlert.textFields.count > 0) {
288 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.
289 }
290 handler(textInput);
291 }]];
292 [alert addAction:[UIAlertAction
293 actionWithTitle:@"Cancel"
294 style:UIAlertActionStyleCancel
295 handler:^(UIAlertAction* _Nonnull action) {
296 handler(nil);
297 }]];
298
299 [self presentViewController:alert animated:YES completion:nil];
300 }
301
217 #pragma mark CWVWebViewDelegate methods 302 #pragma mark CWVWebViewDelegate methods
218 303
219 - (void)webView:(CWVWebView*)webView 304 - (void)webView:(CWVWebView*)webView
220 didFinishLoadingWithURL:(NSURL*)url 305 didFinishLoadingWithURL:(NSURL*)url
221 loadSuccess:(BOOL)loadSuccess { 306 loadSuccess:(BOOL)loadSuccess {
222 // TODO(crbug.com/679895): Add some visual indication that the page load has 307 // TODO(crbug.com/679895): Add some visual indication that the page load has
223 // finished. 308 // finished.
224 [self updateToolbar]; 309 [self updateToolbar];
225 } 310 }
226 311
(...skipping 12 matching lines...) Expand all
239 } 324 }
240 } 325 }
241 326
242 - (id<CWVTranslateDelegate>)translateDelegate { 327 - (id<CWVTranslateDelegate>)translateDelegate {
243 if (!_translateController) 328 if (!_translateController)
244 self.translateController = [[TranslateController alloc] init]; 329 self.translateController = [[TranslateController alloc] init];
245 return _translateController; 330 return _translateController;
246 } 331 }
247 332
248 @end 333 @end
OLDNEW
« ios/web_view/public/cwv_ui_delegate.h ('K') | « 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