OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include "ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.h" |
| 6 |
| 7 #import "ios/chrome/browser/ui/dialogs/dialog_presenter.h" |
| 8 #import "ios/chrome/browser/ui/dialogs/javascript_dialog_blocking_util.h" |
| 9 |
| 10 JavaScriptDialogPresenterImpl::JavaScriptDialogPresenterImpl( |
| 11 DialogPresenter* dialogPresenter) |
| 12 : dialog_presenter_([dialogPresenter retain]) {} |
| 13 |
| 14 JavaScriptDialogPresenterImpl::~JavaScriptDialogPresenterImpl() {} |
| 15 |
| 16 void JavaScriptDialogPresenterImpl::RunJavaScriptDialog( |
| 17 web::WebState* web_state, |
| 18 const GURL& origin_url, |
| 19 web::JavaScriptDialogType dialog_type, |
| 20 NSString* message_text, |
| 21 NSString* default_prompt_text, |
| 22 const web::DialogClosedCallback& callback) { |
| 23 if (ShouldBlockJavaScriptDialogs(web_state)) { |
| 24 // Block the dialog if needed. |
| 25 callback.Run(NO, nil); |
| 26 return; |
| 27 } |
| 28 switch (dialog_type) { |
| 29 case web::JAVASCRIPT_DIALOG_TYPE_ALERT: { |
| 30 web::DialogClosedCallback scoped_callback = callback; |
| 31 [dialog_presenter_ runJavaScriptAlertPanelWithMessage:message_text |
| 32 requestURL:origin_url |
| 33 webState:web_state |
| 34 completionHandler:^{ |
| 35 if (!scoped_callback.is_null()) { |
| 36 scoped_callback.Run(YES, nil); |
| 37 } |
| 38 }]; |
| 39 break; |
| 40 } |
| 41 case web::JAVASCRIPT_DIALOG_TYPE_CONFIRM: { |
| 42 web::DialogClosedCallback scoped_callback = callback; |
| 43 [dialog_presenter_ |
| 44 runJavaScriptConfirmPanelWithMessage:message_text |
| 45 requestURL:origin_url |
| 46 webState:web_state |
| 47 completionHandler:^(BOOL is_confirmed) { |
| 48 if (!scoped_callback.is_null()) { |
| 49 scoped_callback.Run(is_confirmed, nil); |
| 50 } |
| 51 }]; |
| 52 break; |
| 53 } |
| 54 case web::JAVASCRIPT_DIALOG_TYPE_PROMPT: { |
| 55 web::DialogClosedCallback scoped_callback = callback; |
| 56 [dialog_presenter_ |
| 57 runJavaScriptTextInputPanelWithPrompt:message_text |
| 58 defaultText:default_prompt_text |
| 59 requestURL:origin_url |
| 60 webState:web_state |
| 61 completionHandler:^(NSString* text_input) { |
| 62 if (!scoped_callback.is_null()) { |
| 63 scoped_callback.Run(YES, text_input); |
| 64 } |
| 65 }]; |
| 66 break; |
| 67 } |
| 68 default: |
| 69 break; |
| 70 } |
| 71 } |
| 72 |
| 73 void JavaScriptDialogPresenterImpl::CancelDialogs(web::WebState* web_state) { |
| 74 [dialog_presenter_ cancelDialogForWebState:web_state]; |
| 75 } |
OLD | NEW |