OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/views/srt_prompt_dialog.h" | 5 #include "chrome/browser/ui/views/chrome_cleaner_dialog.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "chrome/browser/safe_browsing/srt_prompt_controller.h" | 8 #include "chrome/browser/safe_browsing/chrome_cleaner_dialog_controller.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
12 #include "components/constrained_window/constrained_window_views.h" | 12 #include "components/constrained_window/constrained_window_views.h" |
13 #include "ui/base/ui_base_types.h" | 13 #include "ui/base/ui_base_types.h" |
14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
16 #include "ui/gfx/text_constants.h" | 16 #include "ui/gfx/text_constants.h" |
17 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
18 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
19 #include "ui/views/layout/layout_constants.h" | 19 #include "ui/views/layout/layout_constants.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 | 21 |
22 namespace chrome { | 22 namespace chrome { |
23 | 23 |
24 void ShowSRTPrompt(Browser* browser, | 24 void ShowChromeCleanerPrompt( |
25 safe_browsing::SRTPromptController* controller) { | 25 Browser* browser, |
26 SRTPromptDialog* dialog = new SRTPromptDialog(controller); | 26 safe_browsing::ChromeCleanerDialogController* controller) { |
| 27 ChromeCleanerDialog* dialog = new ChromeCleanerDialog(controller); |
27 dialog->Show(browser); | 28 dialog->Show(browser); |
28 } | 29 } |
29 | 30 |
30 } // namespace chrome | 31 } // namespace chrome |
31 | 32 |
32 namespace { | 33 namespace { |
33 constexpr int kDialogWidth = 448; | 34 constexpr int kDialogWidth = 448; |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
37 // SRTPromptDialog | 38 // ChromeCleanerDialog |
38 | 39 |
39 SRTPromptDialog::SRTPromptDialog(safe_browsing::SRTPromptController* controller) | 40 ChromeCleanerDialog::ChromeCleanerDialog( |
| 41 safe_browsing::ChromeCleanerDialogController* controller) |
40 : browser_(nullptr), | 42 : browser_(nullptr), |
41 controller_(controller), | 43 controller_(controller), |
42 advanced_button_( | 44 advanced_button_( |
43 new views::LabelButton(this, controller_->GetAdvancedButtonLabel())) { | 45 new views::LabelButton(this, controller_->GetAdvancedButtonLabel())) { |
44 DCHECK(controller_); | 46 DCHECK(controller_); |
45 | 47 |
46 SetLayoutManager(new views::BoxLayout( | 48 SetLayoutManager(new views::BoxLayout( |
47 /*orientation=*/views::BoxLayout::kVertical, | 49 /*orientation=*/views::BoxLayout::kVertical, |
48 /*inside_border_horizontal_spacing=*/views::kButtonHEdgeMarginNew, | 50 /*inside_border_horizontal_spacing=*/views::kButtonHEdgeMarginNew, |
49 /*inside_border_vertical_spacing=*/views::kPanelVertMargin, | 51 /*inside_border_vertical_spacing=*/views::kPanelVertMargin, |
50 /*between_child_spacing=*/0)); | 52 /*between_child_spacing=*/0)); |
51 views::Label* label = new views::Label(controller_->GetMainText()); | 53 views::Label* label = new views::Label(controller_->GetMainText()); |
52 label->SetMultiLine(true); | 54 label->SetMultiLine(true); |
53 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 55 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
54 AddChildView(label); | 56 AddChildView(label); |
55 | 57 |
56 advanced_button_->SetStyle(views::Button::STYLE_BUTTON); | 58 advanced_button_->SetStyle(views::Button::STYLE_BUTTON); |
57 } | 59 } |
58 | 60 |
59 SRTPromptDialog::~SRTPromptDialog() { | 61 ChromeCleanerDialog::~ChromeCleanerDialog() { |
60 // Make sure the controller is correctly notified in case the dialog widget is | 62 // Make sure the controller is correctly notified in case the dialog widget is |
61 // closed by some other means than the dialog buttons. | 63 // closed by some other means than the dialog buttons. |
62 if (controller_) | 64 if (controller_) |
63 controller_->Cancel(); | 65 controller_->Cancel(); |
64 } | 66 } |
65 | 67 |
66 void SRTPromptDialog::Show(Browser* browser) { | 68 void ChromeCleanerDialog::Show(Browser* browser) { |
67 DCHECK(browser); | 69 DCHECK(browser); |
68 DCHECK(!browser_); | 70 DCHECK(!browser_); |
69 DCHECK(controller_); | 71 DCHECK(controller_); |
70 | 72 |
71 browser_ = browser; | 73 browser_ = browser; |
72 constrained_window::CreateBrowserModalDialogViews( | 74 constrained_window::CreateBrowserModalDialogViews( |
73 this, browser_->window()->GetNativeWindow()) | 75 this, browser_->window()->GetNativeWindow()) |
74 ->Show(); | 76 ->Show(); |
75 controller_->DialogShown(); | 77 controller_->DialogShown(); |
76 } | 78 } |
77 | 79 |
78 // DialogModel overrides. | 80 // DialogModel overrides. |
79 | 81 |
80 bool SRTPromptDialog::ShouldDefaultButtonBeBlue() const { | 82 bool ChromeCleanerDialog::ShouldDefaultButtonBeBlue() const { |
81 return true; | 83 return true; |
82 } | 84 } |
83 | 85 |
84 // WidgetDelegate overrides. | 86 // WidgetDelegate overrides. |
85 | 87 |
86 ui::ModalType SRTPromptDialog::GetModalType() const { | 88 ui::ModalType ChromeCleanerDialog::GetModalType() const { |
87 return ui::MODAL_TYPE_WINDOW; | 89 return ui::MODAL_TYPE_WINDOW; |
88 } | 90 } |
89 | 91 |
90 base::string16 SRTPromptDialog::GetWindowTitle() const { | 92 base::string16 ChromeCleanerDialog::GetWindowTitle() const { |
91 DCHECK(controller_); | 93 DCHECK(controller_); |
92 return controller_->GetWindowTitle(); | 94 return controller_->GetWindowTitle(); |
93 } | 95 } |
94 | 96 |
95 // DialogDelegate overrides. | 97 // DialogDelegate overrides. |
96 | 98 |
97 base::string16 SRTPromptDialog::GetDialogButtonLabel( | 99 base::string16 ChromeCleanerDialog::GetDialogButtonLabel( |
98 ui::DialogButton button) const { | 100 ui::DialogButton button) const { |
99 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); | 101 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); |
100 DCHECK(controller_); | 102 DCHECK(controller_); |
101 | 103 |
102 return button == ui::DIALOG_BUTTON_OK | 104 return button == ui::DIALOG_BUTTON_OK |
103 ? controller_->GetAcceptButtonLabel() | 105 ? controller_->GetAcceptButtonLabel() |
104 : DialogDelegate::GetDialogButtonLabel(button); | 106 : DialogDelegate::GetDialogButtonLabel(button); |
105 } | 107 } |
106 | 108 |
107 views::View* SRTPromptDialog::CreateExtraView() { | 109 views::View* ChromeCleanerDialog::CreateExtraView() { |
108 return advanced_button_; | 110 return advanced_button_; |
109 } | 111 } |
110 | 112 |
111 bool SRTPromptDialog::Accept() { | 113 bool ChromeCleanerDialog::Accept() { |
112 if (controller_) { | 114 if (controller_) { |
113 controller_->Accept(); | 115 controller_->Accept(); |
114 controller_ = nullptr; | 116 controller_ = nullptr; |
115 } | 117 } |
116 return true; | 118 return true; |
117 } | 119 } |
118 | 120 |
119 bool SRTPromptDialog::Cancel() { | 121 bool ChromeCleanerDialog::Cancel() { |
120 if (controller_) { | 122 if (controller_) { |
121 controller_->Cancel(); | 123 controller_->Cancel(); |
122 controller_ = nullptr; | 124 controller_ = nullptr; |
123 } | 125 } |
124 return true; | 126 return true; |
125 } | 127 } |
126 | 128 |
127 bool SRTPromptDialog::Close() { | 129 bool ChromeCleanerDialog::Close() { |
128 if (controller_) { | 130 if (controller_) { |
129 controller_->Close(); | 131 controller_->Close(); |
130 controller_ = nullptr; | 132 controller_ = nullptr; |
131 } | 133 } |
132 return true; | 134 return true; |
133 } | 135 } |
134 | 136 |
135 // View overrides. | 137 // View overrides. |
136 | 138 |
137 gfx::Size SRTPromptDialog::GetPreferredSize() const { | 139 gfx::Size ChromeCleanerDialog::GetPreferredSize() const { |
138 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); | 140 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); |
139 } | 141 } |
140 | 142 |
141 // views::ButtonListener overrides. | 143 // views::ButtonListener overrides. |
142 | 144 |
143 void SRTPromptDialog::ButtonPressed(views::Button* sender, | 145 void ChromeCleanerDialog::ButtonPressed(views::Button* sender, |
144 const ui::Event& event) { | 146 const ui::Event& event) { |
145 DCHECK_EQ(sender, advanced_button_); | 147 DCHECK_EQ(sender, advanced_button_); |
146 DCHECK(browser_); | 148 DCHECK(browser_); |
147 | 149 |
148 // TODO(alito): Navigate to the webui version of the Chrome Cleaner UI when | 150 // TODO(alito): Navigate to the webui version of the Chrome Cleaner UI when |
149 // that is implemented. | 151 // that is implemented. |
150 if (controller_) { | 152 if (controller_) { |
151 controller_->AdvancedButtonClicked(); | 153 controller_->AdvancedButtonClicked(); |
152 controller_ = nullptr; | 154 controller_ = nullptr; |
153 } | 155 } |
154 GetWidget()->Close(); | 156 GetWidget()->Close(); |
155 } | 157 } |
OLD | NEW |