Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" | |
| 6 | |
| 7 #import "ios/web_view/public/cwv_ui_delegate.h" | |
| 8 #import "net/base/mac/url_conversions.h" | |
| 9 | |
| 10 namespace ios_web_view { | |
| 11 | |
| 12 WebViewJavaScriptDialogPresenter::WebViewJavaScriptDialogPresenter( | |
| 13 CWVWebView* web_view, | |
| 14 id<CWVUIDelegate> ui_delegate) | |
| 15 : ui_delegate_(ui_delegate), web_view_(web_view) {} | |
| 16 | |
| 17 WebViewJavaScriptDialogPresenter::~WebViewJavaScriptDialogPresenter() = default; | |
| 18 | |
| 19 void WebViewJavaScriptDialogPresenter::RunJavaScriptDialog( | |
| 20 web::WebState* web_state, | |
| 21 const GURL& origin_url, | |
| 22 web::JavaScriptDialogType dialog_type, | |
| 23 NSString* message_text, | |
| 24 NSString* default_prompt_text, | |
| 25 const web::DialogClosedCallback& callback) { | |
| 26 switch (dialog_type) { | |
| 27 case web::JAVASCRIPT_DIALOG_TYPE_ALERT: { | |
|
Eugene But (OOO till 7-30)
2017/02/27 22:01:05
Do you still need braces?
michaeldo
2017/02/27 23:39:15
Nope. Removed.
| |
| 28 HandleJavaScriptAlert(origin_url, message_text, callback); | |
| 29 break; | |
| 30 } | |
| 31 case web::JAVASCRIPT_DIALOG_TYPE_CONFIRM: { | |
| 32 HandleJavaScriptConfirmDialog(origin_url, message_text, callback); | |
| 33 break; | |
| 34 } | |
| 35 case web::JAVASCRIPT_DIALOG_TYPE_PROMPT: { | |
| 36 HandleJavaScriptTextPrompt(origin_url, message_text, default_prompt_text, | |
| 37 callback); | |
| 38 break; | |
| 39 } | |
| 40 default: | |
|
Eugene But (OOO till 7-30)
2017/02/27 22:01:05
Please remove default. It is better to get a compi
michaeldo
2017/02/27 23:39:15
Done.
| |
| 41 break; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void WebViewJavaScriptDialogPresenter::HandleJavaScriptAlert( | |
| 46 const GURL& origin_url, | |
| 47 NSString* message_text, | |
| 48 const web::DialogClosedCallback& callback) { | |
| 49 if ([ui_delegate_ respondsToSelector:@selector | |
|
Eugene But (OOO till 7-30)
2017/02/27 22:01:05
Optional nit: do you want to swap if-else block an
michaeldo
2017/02/27 23:39:15
Done.
| |
| 50 (webView:runJavaScriptAlertPanelWithMessage:pageURL | |
| 51 :completionHandler:)]) { | |
| 52 web::DialogClosedCallback scoped_callback = callback; | |
| 53 [ui_delegate_ webView:web_view_ | |
| 54 runJavaScriptAlertPanelWithMessage:message_text | |
| 55 pageURL:net::NSURLWithGURL(origin_url) | |
| 56 completionHandler:^{ | |
| 57 if (!scoped_callback.is_null()) { | |
| 58 scoped_callback.Run(YES, nil); | |
| 59 } | |
| 60 }]; | |
| 61 } else { | |
| 62 callback.Run(NO, nil); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void WebViewJavaScriptDialogPresenter::HandleJavaScriptConfirmDialog( | |
| 67 const GURL& origin_url, | |
| 68 NSString* message_text, | |
| 69 const web::DialogClosedCallback& callback) { | |
| 70 if ([ui_delegate_ respondsToSelector:@selector | |
| 71 (webView:runJavaScriptConfirmPanelWithMessage:pageURL | |
| 72 :completionHandler:)]) { | |
| 73 web::DialogClosedCallback scoped_callback = callback; | |
| 74 [ui_delegate_ webView:web_view_ | |
| 75 runJavaScriptConfirmPanelWithMessage:message_text | |
| 76 pageURL:net::NSURLWithGURL(origin_url) | |
| 77 completionHandler:^(BOOL is_confirmed) { | |
| 78 if (!scoped_callback.is_null()) { | |
| 79 scoped_callback.Run(is_confirmed, nil); | |
| 80 } | |
| 81 }]; | |
| 82 } else { | |
| 83 callback.Run(NO, nil); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void WebViewJavaScriptDialogPresenter::HandleJavaScriptTextPrompt( | |
| 88 const GURL& origin_url, | |
| 89 NSString* message_text, | |
| 90 NSString* default_prompt_text, | |
| 91 const web::DialogClosedCallback& callback) { | |
| 92 if ([ui_delegate_ respondsToSelector:@selector | |
| 93 (webView:runJavaScriptTextInputPanelWithPrompt:defaultText | |
| 94 :pageURL:completionHandler:)]) { | |
| 95 web::DialogClosedCallback scoped_callback = callback; | |
| 96 [ui_delegate_ webView:web_view_ | |
| 97 runJavaScriptTextInputPanelWithPrompt:message_text | |
| 98 defaultText:default_prompt_text | |
| 99 pageURL:net::NSURLWithGURL(origin_url) | |
| 100 completionHandler:^(NSString* text_input) { | |
| 101 if (!scoped_callback.is_null()) { | |
| 102 if (text_input == nil) { | |
| 103 scoped_callback.Run(NO, nil); | |
| 104 } else { | |
| 105 scoped_callback.Run(YES, text_input); | |
| 106 } | |
| 107 } | |
| 108 }]; | |
| 109 } else { | |
| 110 callback.Run(NO, nil); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 void WebViewJavaScriptDialogPresenter::CancelDialogs(web::WebState* web_state) { | |
| 115 } | |
| 116 | |
| 117 void WebViewJavaScriptDialogPresenter::SetUIDelegate( | |
| 118 id<CWVUIDelegate> ui_delegate) { | |
| 119 ui_delegate_.reset(ui_delegate); | |
| 120 } | |
| 121 | |
| 122 } // namespace ios_web_view | |
| OLD | NEW |