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/chrome_cleaner_dialog_win.h" | 5 #include "chrome/browser/ui/views/chrome_cleaner_dialog_win.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_dialog_cont roller_win.h" | 8 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_dialog_cont roller_win.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 "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 12 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
13 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "components/constrained_window/constrained_window_views.h" | 15 #include "components/constrained_window/constrained_window_views.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
18 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
19 #include "ui/gfx/geometry/insets.h" | 19 #include "ui/gfx/geometry/insets.h" |
20 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
21 #include "ui/gfx/text_constants.h" | 21 #include "ui/gfx/text_constants.h" |
22 #include "ui/views/controls/button/checkbox.h" | |
22 #include "ui/views/controls/button/md_text_button.h" | 23 #include "ui/views/controls/button/md_text_button.h" |
23 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
26 #include "ui/views/layout/layout_provider.h" | |
25 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
26 | 28 |
27 namespace chrome { | 29 namespace chrome { |
28 | 30 |
29 void ShowChromeCleanerPrompt( | 31 void ShowChromeCleanerPrompt( |
30 Browser* browser, | 32 Browser* browser, |
31 safe_browsing::ChromeCleanerDialogController* controller) { | 33 safe_browsing::ChromeCleanerDialogController* controller) { |
32 ChromeCleanerDialog* dialog = new ChromeCleanerDialog(controller); | 34 ChromeCleanerDialog* dialog = new ChromeCleanerDialog(controller); |
33 dialog->Show(browser); | 35 dialog->Show(browser); |
34 } | 36 } |
35 | 37 |
36 } // namespace chrome | 38 } // namespace chrome |
37 | 39 |
38 namespace { | 40 namespace { |
39 constexpr int kDialogWidth = 448; | 41 constexpr int kDialogWidth = 448; |
40 | 42 |
41 } // namespace | 43 } // namespace |
42 | 44 |
43 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
44 // ChromeCleanerDialog | 46 // ChromeCleanerDialog |
45 | 47 |
46 ChromeCleanerDialog::ChromeCleanerDialog( | 48 ChromeCleanerDialog::ChromeCleanerDialog( |
47 safe_browsing::ChromeCleanerDialogController* controller) | 49 safe_browsing::ChromeCleanerDialogController* controller) |
48 : browser_(nullptr), controller_(controller) { | 50 : browser_(nullptr), |
51 controller_(controller), | |
52 details_button_(nullptr), | |
53 logs_permission_checkbox_(nullptr) { | |
49 DCHECK(controller_); | 54 DCHECK(controller_); |
50 | 55 |
51 SetLayoutManager( | 56 SetLayoutManager( |
52 new views::BoxLayout(views::BoxLayout::kVertical, | 57 new views::BoxLayout(views::BoxLayout::kVertical, |
53 ChromeLayoutProvider::Get()->GetInsetsMetric( | 58 ChromeLayoutProvider::Get()->GetInsetsMetric( |
54 views::INSETS_DIALOG_CONTENTS), | 59 views::INSETS_DIALOG_CONTENTS), |
55 0)); | 60 0)); |
56 views::Label* label = new views::Label( | 61 views::Label* label = new views::Label( |
57 l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_PROMPT_EXPLANATION)); | 62 l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_PROMPT_EXPLANATION)); |
58 label->SetMultiLine(true); | 63 label->SetMultiLine(true); |
(...skipping 26 matching lines...) Expand all Loading... | |
85 return ui::MODAL_TYPE_WINDOW; | 90 return ui::MODAL_TYPE_WINDOW; |
86 } | 91 } |
87 | 92 |
88 base::string16 ChromeCleanerDialog::GetWindowTitle() const { | 93 base::string16 ChromeCleanerDialog::GetWindowTitle() const { |
89 DCHECK(controller_); | 94 DCHECK(controller_); |
90 return l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_PROMPT_TITLE); | 95 return l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_PROMPT_TITLE); |
91 } | 96 } |
92 | 97 |
93 // DialogDelegate overrides. | 98 // DialogDelegate overrides. |
94 | 99 |
100 views::View* ChromeCleanerDialog::CreateFootnoteView() { | |
101 DCHECK(!logs_permission_checkbox_); | |
102 DCHECK(controller_); | |
103 | |
104 views::View* footnote_view = new views::View(); | |
105 footnote_view->SetLayoutManager(new views::BoxLayout( | |
106 views::BoxLayout::kVertical, ChromeLayoutProvider::Get()->GetInsetsMetric( | |
107 views::INSETS_DIALOG_CONTENTS))); | |
msw
2017/06/29 21:52:48
nit: can you just give the checkbox view an empty
alito
2017/06/30 00:00:09
I tried several ways, but I cannot get it to work.
msw
2017/06/30 00:26:36
Hmm, that's strange. What you have is fine.
| |
108 logs_permission_checkbox_ = new views::Checkbox( | |
109 l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_LOGS_PERMISSION)); | |
110 logs_permission_checkbox_->SetChecked(controller_->LogsEnabled()); | |
111 logs_permission_checkbox_->set_listener(this); | |
112 footnote_view->AddChildView(logs_permission_checkbox_); | |
113 return footnote_view; | |
114 } | |
115 | |
95 base::string16 ChromeCleanerDialog::GetDialogButtonLabel( | 116 base::string16 ChromeCleanerDialog::GetDialogButtonLabel( |
96 ui::DialogButton button) const { | 117 ui::DialogButton button) const { |
97 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); | 118 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); |
98 DCHECK(controller_); | 119 DCHECK(controller_); |
99 | 120 |
100 return button == ui::DIALOG_BUTTON_OK | 121 return button == ui::DIALOG_BUTTON_OK |
101 ? l10n_util::GetStringUTF16( | 122 ? l10n_util::GetStringUTF16( |
102 IDS_CHROME_CLEANUP_PROMPT_REMOVE_BUTTON_LABEL) | 123 IDS_CHROME_CLEANUP_PROMPT_REMOVE_BUTTON_LABEL) |
103 : DialogDelegate::GetDialogButtonLabel(button); | 124 : DialogDelegate::GetDialogButtonLabel(button); |
104 } | 125 } |
105 | 126 |
106 views::View* ChromeCleanerDialog::CreateExtraView() { | 127 views::View* ChromeCleanerDialog::CreateExtraView() { |
107 return views::MdTextButton::CreateSecondaryUiButton( | 128 DCHECK(!details_button_); |
129 | |
130 details_button_ = views::MdTextButton::CreateSecondaryUiButton( | |
108 this, l10n_util::GetStringUTF16( | 131 this, l10n_util::GetStringUTF16( |
109 IDS_CHROME_CLEANUP_PROMPT_DETAILS_BUTTON_LABEL)); | 132 IDS_CHROME_CLEANUP_PROMPT_DETAILS_BUTTON_LABEL)); |
133 return details_button_; | |
110 } | 134 } |
111 | 135 |
112 bool ChromeCleanerDialog::Accept() { | 136 bool ChromeCleanerDialog::Accept() { |
113 if (controller_) { | 137 if (controller_) { |
114 controller_->Accept(); | 138 controller_->Accept(/*logs_enabled=*/logs_permission_checkbox_->checked()); |
msw
2017/06/29 21:52:48
Consider just calling controller_->SetLogsEnabled
alito
2017/06/30 00:00:09
I thought about that. If this dialog was the only
msw
2017/06/30 00:26:36
Hmm, it seems like you really only need to call Se
alito
2017/06/30 00:54:02
Some more details: a logs upload permission checkb
msw
2017/06/30 01:15:58
Thanks for the additional details and thinking thr
msw
2017/06/30 01:18:40
Actually, I wonder if then there's no need for Set
| |
115 controller_ = nullptr; | 139 controller_ = nullptr; |
116 } | 140 } |
117 return true; | 141 return true; |
118 } | 142 } |
119 | 143 |
120 bool ChromeCleanerDialog::Cancel() { | 144 bool ChromeCleanerDialog::Cancel() { |
121 if (controller_) { | 145 if (controller_) { |
122 controller_->Cancel(); | 146 controller_->Cancel(); |
123 controller_ = nullptr; | 147 controller_ = nullptr; |
124 } | 148 } |
(...skipping 13 matching lines...) Expand all Loading... | |
138 gfx::Size ChromeCleanerDialog::CalculatePreferredSize() const { | 162 gfx::Size ChromeCleanerDialog::CalculatePreferredSize() const { |
139 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); | 163 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); |
140 } | 164 } |
141 | 165 |
142 // views::ButtonListener overrides. | 166 // views::ButtonListener overrides. |
143 | 167 |
144 void ChromeCleanerDialog::ButtonPressed(views::Button* sender, | 168 void ChromeCleanerDialog::ButtonPressed(views::Button* sender, |
145 const ui::Event& event) { | 169 const ui::Event& event) { |
146 DCHECK(browser_); | 170 DCHECK(browser_); |
147 | 171 |
148 // TODO(alito): Navigate to the webui version of the Chrome Cleaner UI when | 172 if (sender == details_button_) { |
149 // that is implemented. | 173 if (controller_) { |
150 if (controller_) { | 174 controller_->DetailsButtonClicked( |
151 controller_->DetailsButtonClicked(); | 175 /*logs_enabled=*/logs_permission_checkbox_->checked()); |
152 controller_ = nullptr; | 176 controller_ = nullptr; |
robertshield
2017/06/29 18:43:14
double checking: there's no way that Show() would
alito
2017/06/29 19:06:34
No. Show() is only called right after the instance
| |
177 } | |
178 GetWidget()->Close(); | |
179 return; | |
153 } | 180 } |
154 GetWidget()->Close(); | 181 |
182 DCHECK_EQ(logs_permission_checkbox_, sender); | |
183 | |
184 if (controller_) | |
185 controller_->SetLogsEnabled(logs_permission_checkbox_->checked()); | |
155 } | 186 } |
OLD | NEW |