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/profiles/forced_reauthentication_dialog.h" | 5 #include "chrome/browser/ui/views/profiles/forced_reauthentication_dialog_view.h
" |
6 | 6 |
| 7 #include <map> |
7 #include <memory> | 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/i18n/message_formatter.h" | 12 #include "base/i18n/message_formatter.h" |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 : views::StyledLabel(text, listener) {} | 76 : views::StyledLabel(text, listener) {} |
76 | 77 |
77 gfx::Insets GetInsets() const override { | 78 gfx::Insets GetInsets() const override { |
78 return ChromeLayoutProvider::Get()->GetInsetsMetric( | 79 return ChromeLayoutProvider::Get()->GetInsetsMetric( |
79 views::INSETS_DIALOG_CONTENTS); | 80 views::INSETS_DIALOG_CONTENTS); |
80 } | 81 } |
81 }; | 82 }; |
82 | 83 |
83 } // namespace | 84 } // namespace |
84 | 85 |
85 ForcedReauthenticationDialog::ForcedReauthenticationDialog( | 86 // ForcedReauthenticationDialogView |
| 87 |
| 88 ForcedReauthenticationDialogView::ForcedReauthenticationDialogView( |
86 Browser* browser, | 89 Browser* browser, |
87 SigninManager* signin_manager, | 90 SigninManager* signin_manager, |
88 const base::TimeDelta& countdown_duration) | 91 base::TimeDelta countdown_duration) |
89 : browser_(browser), | 92 : browser_(browser), |
90 signin_manager_(signin_manager), | 93 signin_manager_(signin_manager), |
91 desired_close_time_(base::TimeTicks::Now() + countdown_duration) { | 94 desired_close_time_(base::TimeTicks::Now() + countdown_duration), |
| 95 weak_factory_(this) { |
92 constrained_window::CreateBrowserModalDialogViews( | 96 constrained_window::CreateBrowserModalDialogViews( |
93 this, browser->window()->GetNativeWindow()) | 97 this, browser->window()->GetNativeWindow()) |
94 ->Show(); | 98 ->Show(); |
95 browser->window()->FlashFrame(true); | 99 browser->window()->FlashFrame(true); |
96 browser->window()->Activate(); | 100 browser->window()->Activate(); |
97 } | 101 } |
98 | 102 |
99 ForcedReauthenticationDialog::~ForcedReauthenticationDialog() {} | 103 ForcedReauthenticationDialogView::~ForcedReauthenticationDialogView() {} |
100 | 104 |
101 // static | 105 // static |
102 ForcedReauthenticationDialog* ForcedReauthenticationDialog::ShowDialog( | 106 ForcedReauthenticationDialogView* ForcedReauthenticationDialogView::ShowDialog( |
103 Profile* profile, | 107 Profile* profile, |
104 SigninManager* signin_manager, | 108 SigninManager* signin_manager, |
105 const base::TimeDelta& countdown_duration) { | 109 base::TimeDelta countdown_duration) { |
106 Browser* browser = FindBrowserWithProfile(profile); | 110 Browser* browser = FindBrowserWithProfile(profile); |
107 if (browser == nullptr) { // If there is no browser, we can just sign | 111 if (browser == nullptr) { // If there is no browser, we can just sign |
108 // out profile directly. | 112 // out profile directly. |
109 Signout(signin_manager); | 113 Signout(signin_manager); |
110 return nullptr; | 114 return nullptr; |
111 } | 115 } |
112 | 116 |
113 return new ForcedReauthenticationDialog(browser, signin_manager, | 117 return new ForcedReauthenticationDialogView(browser, signin_manager, |
114 countdown_duration); | 118 countdown_duration); |
115 } | 119 } |
116 | 120 |
117 bool ForcedReauthenticationDialog::Accept() { | 121 bool ForcedReauthenticationDialogView::Accept() { |
118 if (GetTimeRemaining() < base::TimeDelta::FromSeconds(kCloseDirectlyTimer)) { | 122 if (GetTimeRemaining() < base::TimeDelta::FromSeconds(kCloseDirectlyTimer)) { |
119 Signout(signin_manager_); | 123 Signout(signin_manager_); |
120 } else { | 124 } else { |
121 browser_->signin_view_controller()->ShowModalSignin( | 125 browser_->signin_view_controller()->ShowModalSignin( |
122 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser_, | 126 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser_, |
123 signin_metrics::AccessPoint::ACCESS_POINT_FORCE_SIGNIN_WARNING); | 127 signin_metrics::AccessPoint::ACCESS_POINT_FORCE_SIGNIN_WARNING); |
124 } | 128 } |
125 return true; | 129 return true; |
126 } | 130 } |
127 | 131 |
128 bool ForcedReauthenticationDialog::Cancel() { | 132 bool ForcedReauthenticationDialogView::Cancel() { |
129 return true; | 133 return true; |
130 } | 134 } |
131 | 135 |
132 void ForcedReauthenticationDialog::WindowClosing() { | 136 void ForcedReauthenticationDialogView::WindowClosing() { |
133 refresh_timer_.Stop(); | 137 refresh_timer_.Stop(); |
134 } | 138 } |
135 | 139 |
136 base::string16 ForcedReauthenticationDialog::GetWindowTitle() const { | 140 base::string16 ForcedReauthenticationDialogView::GetWindowTitle() const { |
137 base::TimeDelta time_left = GetTimeRemaining(); | 141 base::TimeDelta time_left = GetTimeRemaining(); |
138 return base::i18n::MessageFormatter::FormatWithNumberedArgs( | 142 return base::i18n::MessageFormatter::FormatWithNumberedArgs( |
139 l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_TITLE), | 143 l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_TITLE), |
140 time_left.InMinutes(), time_left.InSeconds() % 60); | 144 time_left.InMinutes(), time_left.InSeconds() % 60); |
141 } | 145 } |
142 | 146 |
143 base::string16 ForcedReauthenticationDialog::GetDialogButtonLabel( | 147 base::string16 ForcedReauthenticationDialogView::GetDialogButtonLabel( |
144 ui::DialogButton button) const { | 148 ui::DialogButton button) const { |
145 if (button == ui::DIALOG_BUTTON_OK) { | 149 if (button == ui::DIALOG_BUTTON_OK) { |
146 return l10n_util::GetStringUTF16( | 150 return l10n_util::GetStringUTF16( |
147 IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_CONFIRM); | 151 IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_CONFIRM); |
148 } | 152 } |
149 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_DELAY); | 153 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_DELAY); |
150 } | 154 } |
151 | 155 |
152 ui::ModalType ForcedReauthenticationDialog::GetModalType() const { | 156 ui::ModalType ForcedReauthenticationDialogView::GetModalType() const { |
153 return ui::MODAL_TYPE_WINDOW; | 157 return ui::MODAL_TYPE_WINDOW; |
154 } | 158 } |
155 | 159 |
156 void ForcedReauthenticationDialog::AddedToWidget() { | 160 void ForcedReauthenticationDialogView::AddedToWidget() { |
157 const SkColor prompt_bar_background_color = | 161 const SkColor prompt_bar_background_color = |
158 GetSigninConfirmationPromptBarColor( | 162 GetSigninConfirmationPromptBarColor( |
159 GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha); | 163 GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha); |
160 // Create the prompt label. | 164 // Create the prompt label. |
161 size_t offset; | 165 size_t offset; |
162 std::string email = signin_manager_->GetAuthenticatedAccountInfo().email; | 166 std::string email = signin_manager_->GetAuthenticatedAccountInfo().email; |
163 const base::string16 domain = | 167 const base::string16 domain = |
164 base::ASCIIToUTF16(gaia::ExtractDomainName(email)); | 168 base::ASCIIToUTF16(gaia::ExtractDomainName(email)); |
165 const base::string16 prompt_text = | 169 const base::string16 prompt_text = |
166 l10n_util::GetStringFUTF16(IDS_ENTERPRISE_SIGNIN_ALERT, domain, &offset); | 170 l10n_util::GetStringFUTF16(IDS_ENTERPRISE_SIGNIN_ALERT, domain, &offset); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 views::GridLayout::FILL, 100, | 228 views::GridLayout::FILL, 100, |
225 views::GridLayout::USE_PREF, 0, 0); | 229 views::GridLayout::USE_PREF, 0, 0); |
226 explanation_columns->AddPaddingColumn(0.0, dialog_insets.right()); | 230 explanation_columns->AddPaddingColumn(0.0, dialog_insets.right()); |
227 dialog_layout->StartRow(0, 1); | 231 dialog_layout->StartRow(0, 1); |
228 const int kPreferredWidth = 440; | 232 const int kPreferredWidth = 440; |
229 dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL, | 233 dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL, |
230 views::GridLayout::FILL, kPreferredWidth, | 234 views::GridLayout::FILL, kPreferredWidth, |
231 explanation_label->GetHeightForWidth(kPreferredWidth)); | 235 explanation_label->GetHeightForWidth(kPreferredWidth)); |
232 refresh_timer_.Start(FROM_HERE, | 236 refresh_timer_.Start(FROM_HERE, |
233 base::TimeDelta::FromSeconds(kRefreshTitleTimer), this, | 237 base::TimeDelta::FromSeconds(kRefreshTitleTimer), this, |
234 &ForcedReauthenticationDialog::OnCountDown); | 238 &ForcedReauthenticationDialogView::OnCountDown); |
235 } | 239 } |
236 | 240 |
237 void ForcedReauthenticationDialog::OnCountDown() { | 241 void ForcedReauthenticationDialogView::CloseDialog() { |
| 242 GetWidget()->Close(); |
| 243 } |
| 244 |
| 245 void ForcedReauthenticationDialogView::OnCountDown() { |
238 if (desired_close_time_ <= base::TimeTicks::Now()) { | 246 if (desired_close_time_ <= base::TimeTicks::Now()) { |
239 Cancel(); | 247 Cancel(); |
240 GetWidget()->Close(); | 248 GetWidget()->Close(); |
241 } | 249 } |
242 GetWidget()->UpdateWindowTitle(); | 250 GetWidget()->UpdateWindowTitle(); |
243 } | 251 } |
244 | 252 |
245 base::TimeDelta ForcedReauthenticationDialog::GetTimeRemaining() const { | 253 base::TimeDelta ForcedReauthenticationDialogView::GetTimeRemaining() const { |
246 base::TimeTicks now = base::TimeTicks::Now(); | 254 base::TimeTicks now = base::TimeTicks::Now(); |
247 if (desired_close_time_ <= now) | 255 if (desired_close_time_ <= now) |
248 return base::TimeDelta(); | 256 return base::TimeDelta(); |
249 return desired_close_time_ - now; | 257 return desired_close_time_ - now; |
250 } | 258 } |
| 259 |
| 260 // ForcedReauthenticationDialogImpl |
| 261 |
| 262 ForcedReauthenticationDialogImpl::ForcedReauthenticationDialogImpl() {} |
| 263 ForcedReauthenticationDialogImpl::~ForcedReauthenticationDialogImpl() { |
| 264 if (dialog_view_) |
| 265 dialog_view_->CloseDialog(); |
| 266 } |
| 267 |
| 268 void ForcedReauthenticationDialogImpl::ShowDialog( |
| 269 Profile* profile, |
| 270 SigninManager* signin_manager, |
| 271 base::TimeDelta countdown_duration) { |
| 272 dialog_view_ = ForcedReauthenticationDialogView::ShowDialog( |
| 273 profile, signin_manager, countdown_duration) |
| 274 ->AsWeakPtr(); |
| 275 } |
| 276 |
| 277 // ForcedReauthenticationDialog |
| 278 |
| 279 // static |
| 280 std::unique_ptr<ForcedReauthenticationDialog> |
| 281 ForcedReauthenticationDialog::Create() { |
| 282 return base::MakeUnique<ForcedReauthenticationDialogImpl>(); |
| 283 } |
OLD | NEW |