| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_views.h" | 5 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_views.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/constrained_window/constrained_window_views.h" | 8 #include "components/constrained_window/constrained_window_views.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/views/controls/message_box_view.h" | 10 #include "ui/views/controls/message_box_view.h" |
| 11 #include "ui/views/controls/textfield/textfield.h" | 11 #include "ui/views/controls/textfield/textfield.h" |
| 12 #include "ui/views/layout/layout_constants.h" | 12 #include "ui/views/layout/layout_constants.h" |
| 13 | 13 |
| 14 JavaScriptDialogViews::~JavaScriptDialogViews() = default; | 14 JavaScriptDialogViews::~JavaScriptDialogViews() = default; |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 base::WeakPtr<JavaScriptDialogViews> JavaScriptDialogViews::Create( | 17 base::WeakPtr<JavaScriptDialogViews> JavaScriptDialogViews::Create( |
| 18 content::WebContents* parent_web_contents, | 18 content::WebContents* parent_web_contents, |
| 19 content::WebContents* alerting_web_contents, | 19 content::WebContents* alerting_web_contents, |
| 20 const base::string16& title, | 20 const base::string16& title, |
| 21 content::JavaScriptMessageType message_type, | 21 content::JavaScriptDialogType dialog_type, |
| 22 const base::string16& message_text, | 22 const base::string16& message_text, |
| 23 const base::string16& default_prompt_text, | 23 const base::string16& default_prompt_text, |
| 24 const content::JavaScriptDialogManager::DialogClosedCallback& | 24 const content::JavaScriptDialogManager::DialogClosedCallback& |
| 25 dialog_callback) { | 25 dialog_callback) { |
| 26 return (new JavaScriptDialogViews(parent_web_contents, alerting_web_contents, | 26 return (new JavaScriptDialogViews(parent_web_contents, alerting_web_contents, |
| 27 title, message_type, message_text, | 27 title, dialog_type, message_text, |
| 28 default_prompt_text, dialog_callback)) | 28 default_prompt_text, dialog_callback)) |
| 29 ->weak_factory_.GetWeakPtr(); | 29 ->weak_factory_.GetWeakPtr(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void JavaScriptDialogViews::CloseDialogWithoutCallback() { | 32 void JavaScriptDialogViews::CloseDialogWithoutCallback() { |
| 33 dialog_callback_.Reset(); | 33 dialog_callback_.Reset(); |
| 34 GetWidget()->Close(); | 34 GetWidget()->Close(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 int JavaScriptDialogViews::GetDefaultDialogButton() const { | 37 int JavaScriptDialogViews::GetDefaultDialogButton() const { |
| 38 return ui::DIALOG_BUTTON_OK; | 38 return ui::DIALOG_BUTTON_OK; |
| 39 } | 39 } |
| 40 | 40 |
| 41 int JavaScriptDialogViews::GetDialogButtons() const { | 41 int JavaScriptDialogViews::GetDialogButtons() const { |
| 42 const bool is_alert = message_type_ == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 42 const bool is_alert = dialog_type_ == content::JAVASCRIPT_DIALOG_TYPE_ALERT; |
| 43 return ui::DIALOG_BUTTON_OK | (is_alert ? 0 : ui::DIALOG_BUTTON_CANCEL); | 43 return ui::DIALOG_BUTTON_OK | (is_alert ? 0 : ui::DIALOG_BUTTON_CANCEL); |
| 44 } | 44 } |
| 45 | 45 |
| 46 base::string16 JavaScriptDialogViews::GetWindowTitle() const { | 46 base::string16 JavaScriptDialogViews::GetWindowTitle() const { |
| 47 return title_; | 47 return title_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool JavaScriptDialogViews::Cancel() { | 50 bool JavaScriptDialogViews::Cancel() { |
| 51 if (dialog_callback_) | 51 if (dialog_callback_) |
| 52 dialog_callback_.Run(false, base::string16()); | 52 dialog_callback_.Run(false, base::string16()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 ui::ModalType JavaScriptDialogViews::GetModalType() const { | 89 ui::ModalType JavaScriptDialogViews::GetModalType() const { |
| 90 return ui::MODAL_TYPE_CHILD; | 90 return ui::MODAL_TYPE_CHILD; |
| 91 } | 91 } |
| 92 | 92 |
| 93 JavaScriptDialogViews::JavaScriptDialogViews( | 93 JavaScriptDialogViews::JavaScriptDialogViews( |
| 94 content::WebContents* parent_web_contents, | 94 content::WebContents* parent_web_contents, |
| 95 content::WebContents* alerting_web_contents, | 95 content::WebContents* alerting_web_contents, |
| 96 const base::string16& title, | 96 const base::string16& title, |
| 97 content::JavaScriptMessageType message_type, | 97 content::JavaScriptDialogType dialog_type, |
| 98 const base::string16& message_text, | 98 const base::string16& message_text, |
| 99 const base::string16& default_prompt_text, | 99 const base::string16& default_prompt_text, |
| 100 const content::JavaScriptDialogManager::DialogClosedCallback& | 100 const content::JavaScriptDialogManager::DialogClosedCallback& |
| 101 dialog_callback) | 101 dialog_callback) |
| 102 : JavaScriptDialog(parent_web_contents), | 102 : JavaScriptDialog(parent_web_contents), |
| 103 title_(title), | 103 title_(title), |
| 104 message_type_(message_type), | 104 dialog_type_(dialog_type), |
| 105 message_text_(message_text), | 105 message_text_(message_text), |
| 106 default_prompt_text_(default_prompt_text), | 106 default_prompt_text_(default_prompt_text), |
| 107 dialog_callback_(dialog_callback), | 107 dialog_callback_(dialog_callback), |
| 108 weak_factory_(this) { | 108 weak_factory_(this) { |
| 109 int options = views::MessageBoxView::DETECT_DIRECTIONALITY; | 109 int options = views::MessageBoxView::DETECT_DIRECTIONALITY; |
| 110 if (message_type == content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) | 110 if (dialog_type == content::JAVASCRIPT_DIALOG_TYPE_PROMPT) |
| 111 options |= views::MessageBoxView::HAS_PROMPT_FIELD; | 111 options |= views::MessageBoxView::HAS_PROMPT_FIELD; |
| 112 | 112 |
| 113 views::MessageBoxView::InitParams params(message_text); | 113 views::MessageBoxView::InitParams params(message_text); |
| 114 params.options = options; | 114 params.options = options; |
| 115 params.default_prompt = default_prompt_text; | 115 params.default_prompt = default_prompt_text; |
| 116 message_box_view_ = new views::MessageBoxView(params); | 116 message_box_view_ = new views::MessageBoxView(params); |
| 117 DCHECK(message_box_view_); | 117 DCHECK(message_box_view_); |
| 118 | 118 |
| 119 constrained_window::ShowWebModalDialogViews(this, parent_web_contents); | 119 constrained_window::ShowWebModalDialogViews(this, parent_web_contents); |
| 120 } | 120 } |
| OLD | NEW |