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

Side by Side 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, 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
« no previous file with comments | « ios/web_view/shell/shell_view_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/MobileCoreServices.h> 7 #import <MobileCoreServices/MobileCoreServices.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 ()<CWVUIDelegate, 22 @interface ShellViewController ()<CWVUIDelegate,
19 CWVWebViewDelegate, 23 CWVWebViewDelegate,
20 UITextFieldDelegate> 24 UITextFieldDelegate>
21 // Container for |webView|. 25 // Container for |webView|.
22 @property(nonatomic, strong) UIView* containerView; 26 @property(nonatomic, strong) UIView* containerView;
23 // Text field used for navigating to URLs. 27 // Text field used for navigating to URLs.
24 @property(nonatomic, strong) UITextField* field; 28 @property(nonatomic, strong) UITextField* field;
25 // Toolbar containing navigation buttons and |field|. 29 // Toolbar containing navigation buttons and |field|.
26 @property(nonatomic, strong) UIToolbar* toolbar; 30 @property(nonatomic, strong) UIToolbar* toolbar;
27 // CWV view which renders the web page. 31 // CWV view which renders the web page.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 style:UIAlertActionStyleDefault 213 style:UIAlertActionStyleDefault
210 handler:copyHandler]]; 214 handler:copyHandler]];
211 215
212 [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" 216 [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
213 style:UIAlertActionStyleCancel 217 style:UIAlertActionStyleCancel
214 handler:nil]]; 218 handler:nil]];
215 219
216 [self presentViewController:alert animated:YES completion:nil]; 220 [self presentViewController:alert animated:YES completion:nil];
217 } 221 }
218 222
223 - (void)webView:(CWVWebView*)webView
224 runJavaScriptAlertPanelWithMessage:(NSString*)message
225 pageURL:(NSURL*)URL
226 completionHandler:(void (^)(void))handler {
227 UIAlertController* alert =
228 [UIAlertController alertControllerWithTitle:nil
229 message:message
230 preferredStyle:UIAlertControllerStyleAlert];
231
232 [alert addAction:[UIAlertAction actionWithTitle:@"Ok"
233 style:UIAlertActionStyleDefault
234 handler:^(UIAlertAction* action) {
235 handler();
236 }]];
237
238 [self presentViewController:alert animated:YES completion:nil];
239 }
240
241 - (void)webView:(CWVWebView*)webView
242 runJavaScriptConfirmPanelWithMessage:(NSString*)message
243 pageURL:(NSURL*)URL
244 completionHandler:(void (^)(BOOL))handler {
245 UIAlertController* alert =
246 [UIAlertController alertControllerWithTitle:nil
247 message:message
248 preferredStyle:UIAlertControllerStyleAlert];
249
250 [alert addAction:[UIAlertAction actionWithTitle:@"Ok"
251 style:UIAlertActionStyleDefault
252 handler:^(UIAlertAction* action) {
253 handler(YES);
254 }]];
255 [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
256 style:UIAlertActionStyleCancel
257 handler:^(UIAlertAction* action) {
258 handler(NO);
259 }]];
260
261 [self presentViewController:alert animated:YES completion:nil];
262 }
263
264 - (void)webView:(CWVWebView*)webView
265 runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
266 defaultText:(NSString*)defaultText
267 pageURL:(NSURL*)URL
268 completionHandler:(void (^)(NSString*))handler {
269 UIAlertController* alert =
270 [UIAlertController alertControllerWithTitle:nil
271 message:prompt
272 preferredStyle:UIAlertControllerStyleAlert];
273
274 [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
275 textField.text = defaultText;
276 textField.accessibilityIdentifier =
277 kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier;
278 }];
279
280 __weak UIAlertController* weakAlert = alert;
281 [alert addAction:[UIAlertAction
282 actionWithTitle:@"Ok"
283 style:UIAlertActionStyleDefault
284 handler:^(UIAlertAction* action) {
285 NSString* textInput =
286 weakAlert.textFields.firstObject.text;
287 handler(textInput);
288 }]];
289 [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
290 style:UIAlertActionStyleCancel
291 handler:^(UIAlertAction* action) {
292 handler(nil);
293 }]];
294
295 [self presentViewController:alert animated:YES completion:nil];
296 }
297
219 #pragma mark CWVWebViewDelegate methods 298 #pragma mark CWVWebViewDelegate methods
220 299
221 - (void)webView:(CWVWebView*)webView 300 - (void)webView:(CWVWebView*)webView
222 didFinishLoadingWithURL:(NSURL*)url 301 didFinishLoadingWithURL:(NSURL*)url
223 loadSuccess:(BOOL)loadSuccess { 302 loadSuccess:(BOOL)loadSuccess {
224 // TODO(crbug.com/679895): Add some visual indication that the page load has 303 // TODO(crbug.com/679895): Add some visual indication that the page load has
225 // finished. 304 // finished.
226 [self updateToolbar]; 305 [self updateToolbar];
227 } 306 }
228 307
(...skipping 12 matching lines...) Expand all
241 } 320 }
242 } 321 }
243 322
244 - (id<CWVTranslateDelegate>)translateDelegate { 323 - (id<CWVTranslateDelegate>)translateDelegate {
245 if (!_translateController) 324 if (!_translateController)
246 self.translateController = [[TranslateController alloc] init]; 325 self.translateController = [[TranslateController alloc] init];
247 return _translateController; 326 return _translateController;
248 } 327 }
249 328
250 @end 329 @end
OLDNEW
« 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