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/settings_reset_prompt_dialog.h" | 5 #include "chrome/browser/ui/views/settings_reset_prompt_dialog.h" |
6 | 6 |
7 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_controller.h" | 7 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_controller.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "components/constrained_window/constrained_window_views.h" | 10 #include "components/constrained_window/constrained_window_views.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 } // namespace safe_browsing | 31 } // namespace safe_browsing |
32 | 32 |
33 namespace { | 33 namespace { |
34 constexpr int kDialogWidth = 448; | 34 constexpr int kDialogWidth = 448; |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 SettingsResetPromptDialog::SettingsResetPromptDialog( | 37 SettingsResetPromptDialog::SettingsResetPromptDialog( |
38 safe_browsing::SettingsResetPromptController* controller) | 38 safe_browsing::SettingsResetPromptController* controller) |
39 : browser_(nullptr), controller_(controller), interaction_done_(false) { | 39 : browser_(nullptr), controller_(controller) { |
40 DCHECK(controller_); | 40 DCHECK(controller_); |
41 | 41 |
42 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | 42 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
43 views::kButtonHEdgeMarginNew, | 43 views::kButtonHEdgeMarginNew, |
44 views::kPanelVertMargin, 0)); | 44 views::kPanelVertMargin, 0)); |
45 | 45 |
46 views::StyledLabel* dialog_label = | 46 views::StyledLabel* dialog_label = |
47 new views::StyledLabel(controller_->GetMainText(), /*listener=*/nullptr); | 47 new views::StyledLabel(controller_->GetMainText(), /*listener=*/nullptr); |
48 views::StyledLabel::RangeStyleInfo url_style; | 48 views::StyledLabel::RangeStyleInfo url_style; |
49 url_style.weight = gfx::Font::Weight::BOLD; | 49 url_style.weight = gfx::Font::Weight::BOLD; |
50 dialog_label->AddStyleRange(controller_->GetMainTextUrlRange(), url_style); | 50 dialog_label->AddStyleRange(controller_->GetMainTextUrlRange(), url_style); |
51 AddChildView(dialog_label); | 51 AddChildView(dialog_label); |
52 } | 52 } |
53 | 53 |
54 SettingsResetPromptDialog::~SettingsResetPromptDialog() { | 54 SettingsResetPromptDialog::~SettingsResetPromptDialog() { |
55 // Make sure the controller is correctly notified in case the dialog widget is | 55 // Make sure the controller is correctly notified in case the dialog widget is |
56 // closed by some other means than the dialog buttons. | 56 // closed by some other means than the dialog buttons. |
57 Close(); | 57 if (controller_) |
| 58 controller_->Close(); |
58 } | 59 } |
59 | 60 |
60 void SettingsResetPromptDialog::Show(Browser* browser) { | 61 void SettingsResetPromptDialog::Show(Browser* browser) { |
61 DCHECK(browser); | 62 DCHECK(browser); |
| 63 DCHECK(controller_); |
| 64 |
62 browser_ = browser; | 65 browser_ = browser; |
63 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 66 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
64 constrained_window::CreateBrowserModalDialogViews( | 67 constrained_window::CreateBrowserModalDialogViews( |
65 this, browser_view->GetNativeWindow()) | 68 this, browser_view->GetNativeWindow()) |
66 ->Show(); | 69 ->Show(); |
67 controller_->DialogShown(); | 70 controller_->DialogShown(); |
68 } | 71 } |
69 | 72 |
70 // WidgetDelegate overrides. | 73 // WidgetDelegate overrides. |
71 | 74 |
72 ui::ModalType SettingsResetPromptDialog::GetModalType() const { | 75 ui::ModalType SettingsResetPromptDialog::GetModalType() const { |
73 return ui::MODAL_TYPE_WINDOW; | 76 return ui::MODAL_TYPE_WINDOW; |
74 } | 77 } |
75 | 78 |
76 bool SettingsResetPromptDialog::ShouldShowWindowIcon() const { | 79 bool SettingsResetPromptDialog::ShouldShowWindowIcon() const { |
77 return false; | 80 return false; |
78 } | 81 } |
79 | 82 |
80 base::string16 SettingsResetPromptDialog::GetWindowTitle() const { | 83 base::string16 SettingsResetPromptDialog::GetWindowTitle() const { |
| 84 DCHECK(controller_); |
81 return controller_->GetWindowTitle(); | 85 return controller_->GetWindowTitle(); |
82 } | 86 } |
83 | 87 |
84 // DialogModel overrides. | 88 // DialogModel overrides. |
85 | 89 |
86 bool SettingsResetPromptDialog::ShouldDefaultButtonBeBlue() const { | 90 bool SettingsResetPromptDialog::ShouldDefaultButtonBeBlue() const { |
87 return true; | 91 return true; |
88 } | 92 } |
89 | 93 |
90 // DialogDelegate overrides. | 94 // DialogDelegate overrides. |
91 | 95 |
92 base::string16 SettingsResetPromptDialog::GetDialogButtonLabel( | 96 base::string16 SettingsResetPromptDialog::GetDialogButtonLabel( |
93 ui::DialogButton button) const { | 97 ui::DialogButton button) const { |
94 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); | 98 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); |
| 99 DCHECK(controller_); |
95 | 100 |
96 if (button == ui::DIALOG_BUTTON_OK) | 101 if (button == ui::DIALOG_BUTTON_OK) |
97 return controller_->GetButtonLabel(); | 102 return controller_->GetButtonLabel(); |
98 return DialogDelegate::GetDialogButtonLabel(button); | 103 return DialogDelegate::GetDialogButtonLabel(button); |
99 } | 104 } |
100 | 105 |
101 bool SettingsResetPromptDialog::Accept() { | 106 bool SettingsResetPromptDialog::Accept() { |
102 if (!interaction_done_) { | 107 if (controller_) { |
103 interaction_done_ = true; | |
104 controller_->Accept(); | 108 controller_->Accept(); |
| 109 controller_ = nullptr; |
105 } | 110 } |
106 return true; | 111 return true; |
107 } | 112 } |
108 | 113 |
109 bool SettingsResetPromptDialog::Cancel() { | 114 bool SettingsResetPromptDialog::Cancel() { |
110 if (!interaction_done_) { | 115 if (controller_) { |
111 interaction_done_ = true; | |
112 controller_->Cancel(); | 116 controller_->Cancel(); |
| 117 controller_ = nullptr; |
113 } | 118 } |
114 return true; | 119 return true; |
115 } | 120 } |
| 121 |
| 122 bool SettingsResetPromptDialog::Close() { |
| 123 if (controller_) { |
| 124 controller_->Close(); |
| 125 controller_ = nullptr; |
| 126 } |
| 127 return true; |
| 128 } |
116 | 129 |
117 // View overrides. | 130 // View overrides. |
118 | 131 |
119 gfx::Size SettingsResetPromptDialog::GetPreferredSize() const { | 132 gfx::Size SettingsResetPromptDialog::GetPreferredSize() const { |
120 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); | 133 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); |
121 } | 134 } |
OLD | NEW |