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 WebViewJavaScriptDialogPresenter::WebViewJavaScriptDialogPresenter( | |
| 11 CWVWebView* web_view, | |
| 12 id<CWVUIDelegate> ui_delegate) | |
| 13 : ui_delegate_(ui_delegate), web_view_(web_view) {} | |
| 14 | |
| 15 WebViewJavaScriptDialogPresenter::~WebViewJavaScriptDialogPresenter() = default; | |
| 16 | |
| 17 void WebViewJavaScriptDialogPresenter::RunJavaScriptDialog( | |
| 18 web::WebState* web_state, | |
| 19 const GURL& origin_url, | |
| 20 web::JavaScriptDialogType dialog_type, | |
| 21 NSString* message_text, | |
| 22 NSString* default_prompt_text, | |
| 23 const web::DialogClosedCallback& callback) { | |
| 24 switch (dialog_type) { | |
| 25 case web::JAVASCRIPT_DIALOG_TYPE_ALERT: { | |
| 26 if ([ui_delegate_ respondsToSelector:@selector | |
|
Eugene But (OOO till 7-30)
2017/02/27 18:30:52
This is quite a long method. Do you want to move t
michaeldo
2017/02/27 21:35:51
Done.
| |
| 27 (webView:runJavaScriptAlertPanelWithMessage:pageURL | |
| 28 :completionHandler:)]) { | |
| 29 web::DialogClosedCallback scoped_callback = callback; | |
| 30 [ui_delegate_ webView:web_view_ | |
| 31 runJavaScriptAlertPanelWithMessage:message_text | |
| 32 pageURL:net::NSURLWithGURL(origin_url) | |
| 33 completionHandler:^{ | |
| 34 if (!scoped_callback.is_null()) { | |
| 35 scoped_callback.Run(YES, nil); | |
| 36 } | |
| 37 }]; | |
| 38 } else { | |
| 39 callback.Run(NO, nil); | |
| 40 } | |
| 41 break; | |
| 42 } | |
| 43 case web::JAVASCRIPT_DIALOG_TYPE_CONFIRM: { | |
| 44 if ([ui_delegate_ respondsToSelector:@selector | |
| 45 (webView:runJavaScriptConfirmPanelWithMessage:pageURL | |
| 46 :completionHandler:)]) { | |
| 47 web::DialogClosedCallback scoped_callback = callback; | |
| 48 [ui_delegate_ webView:web_view_ | |
| 49 runJavaScriptConfirmPanelWithMessage:message_text | |
| 50 pageURL:net::NSURLWithGURL(origin_url) | |
| 51 completionHandler:^(BOOL is_confirmed) { | |
| 52 if (!scoped_callback.is_null()) { | |
| 53 scoped_callback.Run(is_confirmed, nil); | |
| 54 } | |
| 55 }]; | |
| 56 } else { | |
| 57 callback.Run(NO, nil); | |
| 58 } | |
| 59 break; | |
| 60 } | |
| 61 case web::JAVASCRIPT_DIALOG_TYPE_PROMPT: { | |
| 62 if ([ui_delegate_ respondsToSelector:@selector | |
| 63 (webView:runJavaScriptTextInputPanelWithPrompt | |
| 64 :defaultText:pageURL:completionHandler:)]) { | |
| 65 web::DialogClosedCallback scoped_callback = callback; | |
| 66 [ui_delegate_ webView:web_view_ | |
| 67 runJavaScriptTextInputPanelWithPrompt:message_text | |
| 68 defaultText:default_prompt_text | |
| 69 pageURL:net::NSURLWithGURL(origin_url) | |
| 70 completionHandler:^(NSString* text_input) { | |
| 71 if (!scoped_callback.is_null()) { | |
| 72 if (text_input == nil) { | |
| 73 scoped_callback.Run(NO, nil); | |
| 74 } else { | |
| 75 scoped_callback.Run(YES, text_input); | |
| 76 } | |
| 77 } | |
| 78 }]; | |
| 79 } else { | |
| 80 callback.Run(NO, nil); | |
| 81 } | |
| 82 break; | |
| 83 } | |
| 84 default: | |
| 85 break; | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void WebViewJavaScriptDialogPresenter::CancelDialogs(web::WebState* web_state) { | |
| 90 if ([ui_delegate_ respondsToSelector:@selector(cancelDialogsForWebView:)]) { | |
| 91 [ui_delegate_ cancelDialogsForWebView:web_view_]; | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void WebViewJavaScriptDialogPresenter::SetUIDelegate( | |
| 96 id<CWVUIDelegate> ui_delegate) { | |
| 97 ui_delegate_.reset(ui_delegate); | |
| 98 } | |
| OLD | NEW |