[go: nahoru, domu]

blob: 1cba4cd322d3fb40b85f09512098a35cba78e6c3 [file] [log] [blame]
xiaoyinh2bbdd102017-05-18 23:29:421// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Jacob Dufaultffd9b0d2017-11-15 23:07:165#include "ash/login/login_screen_controller.h"
xiaoyinh2bbdd102017-05-18 23:29:426
Quan Nguyen92f924a2018-10-18 18:36:467#include <utility>
8
Quan Nguyen3d7a0f02018-09-04 23:53:559#include "ash/focus_cycler.h"
Fabian Sommerdcb675c2020-02-12 09:31:0510#include "ash/login/parent_access_controller.h"
jdufaulteb4c9f1e2017-06-08 23:08:3011#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5312#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4013#include "ash/public/cpp/ash_pref_names.h"
Evan Stade2e4c22e2019-06-07 02:13:5514#include "ash/public/cpp/login_screen_client.h"
Anastasiia Nikolaienko94f9f7d2019-06-11 08:12:0715#include "ash/public/cpp/toast_data.h"
Aga Wronska16abb432018-01-11 23:49:5916#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1817#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3018#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3219#include "ash/shelf/shelf.h"
20#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4021#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5922#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5523#include "ash/system/status_area_widget_delegate.h"
Anastasiia Nikolaienko8cdd7e62019-06-12 12:16:2424#include "ash/system/toast/toast_manager_impl.h"
Jun Mukai5c7b5b42018-11-30 00:08:5025#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4626#include "base/bind.h"
Maksim Ivanovdbd9ade72019-08-09 15:34:1627#include "base/callback.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1728#include "base/debug/alias.h"
Renato Silva0c0e1bb2019-09-11 13:04:1729#include "base/strings/string_util.h"
Jialiu Linf99b788b2018-01-17 23:01:2130#include "base/strings/utf_string_conversions.h"
Sarah Hu069eea12017-09-08 01:28:4031#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0932#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4233
34namespace ash {
35
Sarah Hu069eea12017-09-08 01:28:4036namespace {
xiaoyinh2bbdd102017-05-18 23:29:4237
Aga Wronskaa844cdcd12018-01-29 16:06:4438enum class SystemTrayVisibility {
39 kNone, // Tray not visible anywhere.
40 kPrimary, // Tray visible only on primary display.
41 kAll, // Tray visible on all displays.
42};
43
44void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
45 RootWindowController* primary_window_controller =
46 Shell::GetPrimaryRootWindowController();
47 for (RootWindowController* window_controller :
48 Shell::GetAllRootWindowControllers()) {
49 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
50 if (!status_area)
51 continue;
52 if (window_controller == primary_window_controller) {
53 status_area->SetSystemTrayVisibility(
54 visibility == SystemTrayVisibility::kPrimary ||
55 visibility == SystemTrayVisibility::kAll);
56 } else {
57 status_area->SetSystemTrayVisibility(visibility ==
58 SystemTrayVisibility::kAll);
59 }
60 }
Aga Wronska16abb432018-01-11 23:49:5961}
62
Sarah Hu069eea12017-09-08 01:28:4063} // namespace
64
Jun Mukai5c7b5b42018-11-30 00:08:5065LoginScreenController::LoginScreenController(
66 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0067 : system_tray_notifier_(system_tray_notifier) {
Jun Mukai5c7b5b42018-11-30 00:08:5068 system_tray_notifier_->AddSystemTrayFocusObserver(this);
69}
James Cook8f1e6062017-11-13 23:40:5970
Jun Mukai5c7b5b42018-11-30 00:08:5071LoginScreenController::~LoginScreenController() {
72 system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
73}
xiaoyinh2bbdd102017-05-18 23:29:4274
Sarah Hu069eea12017-09-08 01:28:4075// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1676void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
77 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4078 if (for_test) {
79 // There is no remote pref service, so pretend that ash owns the pref.
80 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
81 return;
82 }
Sarah Hu069eea12017-09-08 01:28:4083}
84
Jacob Dufault2ca8c502018-06-25 19:12:1485bool LoginScreenController::IsAuthenticating() const {
86 return authentication_stage_ != AuthenticationStage::kIdle;
87}
88
Jacob Dufault2d20ae62018-09-20 22:19:5289void LoginScreenController::AuthenticateUserWithPasswordOrPin(
90 const AccountId& account_id,
91 const std::string& password,
92 bool authenticated_by_pin,
93 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4394 // It is an error to call this function while an authentication is in
95 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:5296 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:5697 << "Duplicate authentication attempt; current authentication stage is "
98 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:4399
Evan Stade2e4c22e2019-06-07 02:13:55100 if (!client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:15101 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32102 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15103 }
xiaoyinh9f6fa0e2017-06-07 19:22:32104
Jacob Dufaulteafc6fe2017-10-11 21:16:52105 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
106 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24107 switch (force_fail_auth_for_debug_overlay_) {
108 case ForceFailAuth::kOff:
109 break;
110 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15111 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24112 return;
113 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14114 // Set a dummy authentication stage so that |IsAuthenticating| returns
115 // true.
116 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24117 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15118 FROM_HERE,
119 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
120 weak_factory_.GetWeakPtr(), base::Passed(&callback),
121 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24122 base::TimeDelta::FromSeconds(1));
123 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52124 }
125
Quan Nguyenf5224352018-11-06 02:03:34126 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
127
Renato Silva0c0e1bb2019-09-11 13:04:17128 // Checking if the password is only formed of numbers with base::StringToInt
129 // will easily fail due to numeric limits. ContainsOnlyChars is used instead.
130 const bool is_pin =
131 authenticated_by_pin && base::ContainsOnlyChars(password, "0123456789");
Evan Stade2e4c22e2019-06-07 02:13:55132 client_->AuthenticateUserWithPasswordOrPin(
Quan Nguyenf5224352018-11-06 02:03:34133 account_id, password, is_pin,
134 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
135 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32136}
137
Jacob Dufault2d20ae62018-09-20 22:19:52138void LoginScreenController::AuthenticateUserWithExternalBinary(
139 const AccountId& account_id,
140 OnAuthenticateCallback callback) {
141 // It is an error to call this function while an authentication is in
142 // progress.
143 LOG_IF(FATAL, IsAuthenticating())
144 << "Duplicate authentication attempt; current authentication stage is "
145 << static_cast<int>(authentication_stage_);
146
Evan Stade2e4c22e2019-06-07 02:13:55147 if (!client_) {
Jacob Dufault2d20ae62018-09-20 22:19:52148 std::move(callback).Run(base::nullopt);
149 return;
150 }
151
152 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Evan Stade2e4c22e2019-06-07 02:13:55153 client_->AuthenticateUserWithExternalBinary(
Jacob Dufault2d20ae62018-09-20 22:19:52154 account_id,
155 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
156 weak_factory_.GetWeakPtr(), std::move(callback)));
157}
158
Quan Nguyen92f924a2018-10-18 18:36:46159void LoginScreenController::EnrollUserWithExternalBinary(
160 OnAuthenticateCallback callback) {
Evan Stade2e4c22e2019-06-07 02:13:55161 if (!client_) {
Quan Nguyen92f924a2018-10-18 18:36:46162 std::move(callback).Run(base::nullopt);
163 return;
164 }
165
Evan Stade2e4c22e2019-06-07 02:13:55166 client_->EnrollUserWithExternalBinary(base::BindOnce(
Quan Nguyen92f924a2018-10-18 18:36:46167 [](OnAuthenticateCallback callback, bool success) {
168 std::move(callback).Run(base::make_optional<bool>(success));
169 },
170 std::move(callback)));
171}
172
Jacob Dufault2d20ae62018-09-20 22:19:52173void LoginScreenController::AuthenticateUserWithEasyUnlock(
174 const AccountId& account_id) {
175 // TODO(jdufault): integrate this into authenticate stage after mojom is
176 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55177 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32178 return;
Evan Stade2e4c22e2019-06-07 02:13:55179 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32180}
181
Maksim Ivanov675dd762019-07-29 18:31:10182void LoginScreenController::AuthenticateUserWithChallengeResponse(
183 const AccountId& account_id,
184 OnAuthenticateCallback callback) {
185 LOG_IF(FATAL, IsAuthenticating())
186 << "Duplicate authentication attempt; current authentication stage is "
187 << static_cast<int>(authentication_stage_);
188
189 if (!client_) {
190 std::move(callback).Run(/*success=*/base::nullopt);
191 return;
192 }
193
194 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
195 client_->AuthenticateUserWithChallengeResponse(
196 account_id,
197 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
198 weak_factory_.GetWeakPtr(), std::move(callback)));
199}
200
Evan Stade2e4c22e2019-06-07 02:13:55201bool LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17202 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05203 base::Time validation_time,
204 const std::string& code) {
205 DCHECK(!validation_time.is_null());
206
Evan Stade2e4c22e2019-06-07 02:13:55207 if (!client_)
208 return false;
Aga Wronskaac6cf362019-02-26 21:36:55209
Henrique Grandinetti914c34b62019-08-12 14:03:19210 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55211}
212
Fabian Sommer502d7a8b2020-02-04 14:37:45213void LoginScreenController::OnSecurityTokenPinRequestCancelledByUser() {
214 security_token_pin_request_cancelled_ = true;
215 std::move(on_request_security_token_ui_closed_).Run();
216}
217
218bool LoginScreenController::GetSecurityTokenPinRequestCancelled() const {
219 return security_token_pin_request_cancelled_;
220}
221
Jacob Dufaultffd9b0d2017-11-15 23:07:16222void LoginScreenController::HardlockPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55223 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32224 return;
Evan Stade2e4c22e2019-06-07 02:13:55225 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32226}
227
Jacob Dufaultffd9b0d2017-11-15 23:07:16228void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55229 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27230 return;
Evan Stade2e4c22e2019-06-07 02:13:55231 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27232}
233
Jacob Dufaultffd9b0d2017-11-15 23:07:16234void LoginScreenController::OnNoPodFocused() {
Evan Stade2e4c22e2019-06-07 02:13:55235 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27236 return;
Evan Stade2e4c22e2019-06-07 02:13:55237 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27238}
239
Jacob Dufaultffd9b0d2017-11-15 23:07:16240void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55241 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27242 return;
Evan Stade2e4c22e2019-06-07 02:13:55243 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27244}
245
Jacob Dufaultffd9b0d2017-11-15 23:07:16246void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55247 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27248 return;
Evan Stade2e4c22e2019-06-07 02:13:55249 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27250}
251
Jacob Dufaultffd9b0d2017-11-15 23:07:16252void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55253 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30254 return;
Evan Stade2e4c22e2019-06-07 02:13:55255 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30256}
257
Aga Wronska6a32f9872018-01-06 00:16:10258void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55259 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10260 return;
Evan Stade2e4c22e2019-06-07 02:13:55261 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10262}
263
Jacob Dufaultffd9b0d2017-11-15 23:07:16264void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27265 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55266 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27267 return;
Evan Stade2e4c22e2019-06-07 02:13:55268 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27269}
270
Jacob Dufaultffd9b0d2017-11-15 23:07:16271void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55272 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48273 return;
Evan Stade2e4c22e2019-06-07 02:13:55274 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48275}
276
Roman Sorokin26d7e9662020-02-24 17:52:18277void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Evan Stade2e4c22e2019-06-07 02:13:55278 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09279 return;
Roman Sorokin26d7e9662020-02-24 17:52:18280 client_->ShowGaiaSignin(prefilled_account);
281}
282
283void LoginScreenController::HideGaiaSignin() {
284 if (!client_)
285 return;
286 client_->HideGaiaSignin();
Sarah Hu9fba0e752018-02-07 01:41:09287}
288
Jacob Dufaultfc31c742018-03-20 17:32:19289void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55290 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19291 return;
Evan Stade2e4c22e2019-06-07 02:13:55292 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19293}
294
295void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55296 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19297 return;
Evan Stade2e4c22e2019-06-07 02:13:55298 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19299}
300
Sarah Hu3fcf9f82018-03-22 20:32:54301void LoginScreenController::LaunchPublicSession(
302 const AccountId& account_id,
303 const std::string& locale,
304 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55305 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54306 return;
Evan Stade2e4c22e2019-06-07 02:13:55307 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54308}
309
Sarah Huf9affb122018-04-27 21:36:36310void LoginScreenController::RequestPublicSessionKeyboardLayouts(
311 const AccountId& account_id,
312 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55313 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36314 return;
Evan Stade2e4c22e2019-06-07 02:13:55315 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36316}
317
Sarah Hu0007c932018-06-18 20:21:04318void LoginScreenController::ShowFeedback() {
Evan Stade2e4c22e2019-06-07 02:13:55319 if (!client_)
Sarah Hu0007c932018-06-18 20:21:04320 return;
Evan Stade2e4c22e2019-06-07 02:13:55321 client_->ShowFeedback();
Sarah Hu0007c932018-06-18 20:21:04322}
323
Evan Stade2e4c22e2019-06-07 02:13:55324void LoginScreenController::SetClient(LoginScreenClient* client) {
325 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48326}
327
Evan Stadeb153f822019-05-23 19:14:43328LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31329 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43330}
331
Evan Stade9fe9cbe2019-06-03 23:05:55332void LoginScreenController::ShowKioskAppError(const std::string& message) {
333 ToastData toast_data(
334 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
335 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
336 true /*visible_on_lock_screen*/);
337 Shell::Get()->toast_manager()->Show(toast_data);
338}
339
340void LoginScreenController::FocusLoginShelf(bool reverse) {
341 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
342 // Tell the focus direction to the status area or the shelf so they can focus
343 // the correct child view.
344 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
345 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
346 return;
347 shelf->GetStatusAreaWidget()
348 ->status_area_widget_delegate()
349 ->set_default_last_focusable_child(reverse);
350 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
351 } else {
352 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
353 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
354 }
355}
356
357bool LoginScreenController::IsReadyForPassword() {
358 return LockScreen::HasInstance() && !IsAuthenticating();
359}
360
361void LoginScreenController::EnableAddUserButton(bool enable) {
362 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
363 ->shelf_widget()
364 ->login_shelf_view()
365 ->SetAddUserButtonEnabled(enable);
366}
367
368void LoginScreenController::EnableShutdownButton(bool enable) {
369 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
370 ->shelf_widget()
371 ->login_shelf_view()
372 ->SetShutdownButtonEnabled(enable);
373}
374
Evan Stade98b718e2019-06-03 17:15:34375void LoginScreenController::ShowGuestButtonInOobe(bool show) {
376 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
377 ->shelf_widget()
378 ->login_shelf_view()
379 ->ShowGuestButtonInOobe(show);
380}
381
382void LoginScreenController::ShowParentAccessButton(bool show) {
383 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
384 ->shelf_widget()
385 ->login_shelf_view()
386 ->ShowParentAccessButton(show);
387}
388
Evan Stade9fe9cbe2019-06-03 23:05:55389void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
390 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
391 ->shelf_widget()
392 ->login_shelf_view()
393 ->SetAllowLoginAsGuest(allow_guest);
394}
395
Alexander Alekseev7020c6b52019-07-25 03:25:48396std::unique_ptr<ScopedGuestButtonBlocker>
397LoginScreenController::GetScopedGuestButtonBlocker() {
398 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
399 ->shelf_widget()
400 ->login_shelf_view()
401 ->GetScopedGuestButtonBlocker();
402}
403
Fabian Sommerdcb675c2020-02-12 09:31:05404void LoginScreenController::ShowParentAccessWidget(
405 const AccountId& child_account_id,
Fabian Sommer06c38092020-02-13 14:08:43406 base::OnceCallback<void(bool success)> callback,
Fabian Sommerdcb675c2020-02-12 09:31:05407 ParentAccessRequestReason reason,
408 bool extra_dimmer,
409 base::Time validation_time) {
Fabian Sommer06c38092020-02-13 14:08:43410 DCHECK(!PinRequestWidget::Get());
Fabian Sommerdcb675c2020-02-12 09:31:05411 Shell::Get()->parent_access_controller()->ShowWidget(
412 child_account_id, std::move(callback), reason, extra_dimmer,
413 validation_time);
414}
415
Maksim Ivanovdbd9ade72019-08-09 15:34:16416void LoginScreenController::RequestSecurityTokenPin(
417 SecurityTokenPinRequest request) {
Fabian Sommer502d7a8b2020-02-04 14:37:45418 if (LockScreen::HasInstance() && !security_token_pin_request_cancelled_) {
419 // The caller must ensure that there is no unresolved pin request currently
420 // in progress.
421 on_request_security_token_ui_closed_ =
422 std::move(request.pin_ui_closed_callback);
423 // base::Unretained(this) could lead to errors if this controller is
424 // destroyed before the callback happens. This will be fixed by
425 // crbug.com/1001288 by using a UI owned by the controller.
426 request.pin_ui_closed_callback = base::BindOnce(
427 &LoginScreenController::OnSecurityTokenPinRequestCancelledByUser,
428 base::Unretained(this));
429 LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
430 } else {
431 // The user closed the PIN UI on a previous request that was part of the
432 // same smart card login attempt, or the PIN request is made at an
433 // inappropriate time, racing with the lock screen showing/hiding.
Maksim Ivanovdbd9ade72019-08-09 15:34:16434 std::move(request.pin_ui_closed_callback).Run();
Maksim Ivanovdbd9ade72019-08-09 15:34:16435 }
Maksim Ivanovdbd9ade72019-08-09 15:34:16436}
437
438void LoginScreenController::ClearSecurityTokenPinRequest() {
439 if (!LockScreen::HasInstance()) {
440 // Corner case: the request is made at inappropriate time, racing with the
441 // lock screen showing/hiding.
442 return;
443 }
444 LockScreen::Get()->ClearSecurityTokenPinRequest();
445}
446
Evan Stade2e4c22e2019-06-07 02:13:55447void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47448 OnShow();
Evan Stade98b718e2019-06-03 17:15:34449 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47450}
451
Evan Stade2e4c22e2019-06-07 02:13:55452void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47453 // Login screen can only be used during login.
Evan Stade2e4c22e2019-06-07 02:13:55454 CHECK_EQ(session_manager::SessionState::LOGIN_PRIMARY,
455 Shell::Get()->session_controller()->GetSessionState())
456 << "Not showing login screen since session state is "
457 << static_cast<int>(
458 Shell::Get()->session_controller()->GetSessionState());
Jacob Dufault589d9942018-03-27 20:28:47459
460 OnShow();
Evan Stade98b718e2019-06-03 17:15:34461 // TODO(jdufault): rename LockScreen to LoginScreen.
462 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47463}
464
Evan Stade9c07ab42019-05-13 21:21:56465void LoginScreenController::SetKioskApps(
466 const std::vector<KioskAppMenuEntry>& kiosk_apps,
467 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
468 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
469 ->shelf_widget()
470 ->login_shelf_view()
471 ->SetKioskApps(kiosk_apps, launch_app);
472}
473
Quan Nguyene3e1d252018-07-19 23:00:44474void LoginScreenController::ShowResetScreen() {
Evan Stade2e4c22e2019-06-07 02:13:55475 client_->ShowResetScreen();
Quan Nguyene3e1d252018-07-19 23:00:44476}
477
Roman Sorokin925cddec2020-01-23 08:19:02478void LoginScreenController::ShowAccountAccessHelpApp(
479 gfx::NativeWindow parent_window) {
480 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11481}
482
Roman Sorokin925cddec2020-01-23 08:19:02483void LoginScreenController::ShowParentAccessHelpApp(
484 gfx::NativeWindow parent_window) {
485 client_->ShowParentAccessHelpApp(parent_window);
Aga Wronska7fef27e92019-08-22 17:51:27486}
487
Evan Stade3c971bc2019-06-11 22:12:44488void LoginScreenController::ShowLockScreenNotificationSettings() {
489 client_->ShowLockScreenNotificationSettings();
490}
491
Quan Nguyen3d7a0f02018-09-04 23:53:55492void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55493 if (!client_)
Tony de Luna46801932019-03-11 18:02:01494 return;
Evan Stade2e4c22e2019-06-07 02:13:55495 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55496}
497
Quan Nguyene377eb62019-02-11 23:02:25498void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55499 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48500 return;
Evan Stade2e4c22e2019-06-07 02:13:55501 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25502}
503
Jacob Dufaultb7a2d842017-12-01 23:21:15504void LoginScreenController::OnAuthenticateComplete(
505 OnAuthenticateCallback callback,
506 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43507 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46508 std::move(callback).Run(base::make_optional<bool>(success));
Fabian Sommer502d7a8b2020-02-04 14:37:45509 security_token_pin_request_cancelled_ = false;
510 on_request_security_token_ui_closed_.Reset();
Jacob Dufault8876ba82018-03-27 22:55:43511 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42512}
513
Jacob Dufaultcbc1ee02018-02-28 18:38:54514void LoginScreenController::OnShow() {
515 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17516 if (authentication_stage_ != AuthenticationStage::kIdle) {
517 AuthenticationStage authentication_stage = authentication_stage_;
518 base::debug::Alias(&authentication_stage);
519 LOG(FATAL) << "Unexpected authentication stage "
520 << static_cast<int>(authentication_stage_);
521 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54522}
523
Jun Mukai5c7b5b42018-11-30 00:08:50524void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55525 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50526 return;
Evan Stade2e4c22e2019-06-07 02:13:55527 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50528}
529
xiaoyinh2bbdd102017-05-18 23:29:42530} // namespace ash