[go: nahoru, domu]

blob: d0242739b2ed22e8ff9090a44df5f81b117feb6f [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 Sommer4e0fc3d2020-02-27 14:16:3310#include "ash/login/security_token_request_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,
Jan Wilken Dörried76713f2020-03-31 12:12:11120 weak_factory_.GetWeakPtr(), std::move(callback),
Jacob Dufaultb7a2d842017-12-01 23:21:15121 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,
Jan Wilken Dörried76713f2020-03-31 12:12:11135 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32136}
137
Jacob Dufault2d20ae62018-09-20 22:19:52138void LoginScreenController::AuthenticateUserWithEasyUnlock(
139 const AccountId& account_id) {
140 // TODO(jdufault): integrate this into authenticate stage after mojom is
141 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55142 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32143 return;
Evan Stade2e4c22e2019-06-07 02:13:55144 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32145}
146
Maksim Ivanov675dd762019-07-29 18:31:10147void LoginScreenController::AuthenticateUserWithChallengeResponse(
148 const AccountId& account_id,
149 OnAuthenticateCallback callback) {
150 LOG_IF(FATAL, IsAuthenticating())
151 << "Duplicate authentication attempt; current authentication stage is "
152 << static_cast<int>(authentication_stage_);
153
154 if (!client_) {
155 std::move(callback).Run(/*success=*/base::nullopt);
156 return;
157 }
158
159 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
160 client_->AuthenticateUserWithChallengeResponse(
161 account_id,
162 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
163 weak_factory_.GetWeakPtr(), std::move(callback)));
164}
165
Evan Stade2e4c22e2019-06-07 02:13:55166bool LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17167 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05168 base::Time validation_time,
169 const std::string& code) {
170 DCHECK(!validation_time.is_null());
171
Evan Stade2e4c22e2019-06-07 02:13:55172 if (!client_)
173 return false;
Aga Wronskaac6cf362019-02-26 21:36:55174
Henrique Grandinetti914c34b62019-08-12 14:03:19175 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55176}
177
Fabian Sommer4e0fc3d2020-02-27 14:16:33178bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
179 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45180}
181
Jacob Dufaultffd9b0d2017-11-15 23:07:16182void LoginScreenController::HardlockPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55183 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32184 return;
Evan Stade2e4c22e2019-06-07 02:13:55185 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32186}
187
Jacob Dufaultffd9b0d2017-11-15 23:07:16188void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55189 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27190 return;
Evan Stade2e4c22e2019-06-07 02:13:55191 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27192}
193
Jacob Dufaultffd9b0d2017-11-15 23:07:16194void LoginScreenController::OnNoPodFocused() {
Evan Stade2e4c22e2019-06-07 02:13:55195 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27196 return;
Evan Stade2e4c22e2019-06-07 02:13:55197 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27198}
199
Jacob Dufaultffd9b0d2017-11-15 23:07:16200void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55201 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27202 return;
Evan Stade2e4c22e2019-06-07 02:13:55203 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27204}
205
Jacob Dufaultffd9b0d2017-11-15 23:07:16206void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55207 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27208 return;
Evan Stade2e4c22e2019-06-07 02:13:55209 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27210}
211
Jacob Dufaultffd9b0d2017-11-15 23:07:16212void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55213 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30214 return;
Evan Stade2e4c22e2019-06-07 02:13:55215 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30216}
217
Aga Wronska6a32f9872018-01-06 00:16:10218void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55219 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10220 return;
Evan Stade2e4c22e2019-06-07 02:13:55221 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10222}
223
Jacob Dufaultffd9b0d2017-11-15 23:07:16224void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27225 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55226 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27227 return;
Evan Stade2e4c22e2019-06-07 02:13:55228 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27229}
230
Jacob Dufaultffd9b0d2017-11-15 23:07:16231void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55232 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48233 return;
Evan Stade2e4c22e2019-06-07 02:13:55234 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48235}
236
Roman Sorokin26d7e9662020-02-24 17:52:18237void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Evan Stade2e4c22e2019-06-07 02:13:55238 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09239 return;
Roman Sorokin26d7e9662020-02-24 17:52:18240 client_->ShowGaiaSignin(prefilled_account);
241}
242
Jacob Dufaultfc31c742018-03-20 17:32:19243void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55244 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19245 return;
Evan Stade2e4c22e2019-06-07 02:13:55246 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19247}
248
249void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55250 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19251 return;
Evan Stade2e4c22e2019-06-07 02:13:55252 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19253}
254
Sarah Hu3fcf9f82018-03-22 20:32:54255void LoginScreenController::LaunchPublicSession(
256 const AccountId& account_id,
257 const std::string& locale,
258 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55259 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54260 return;
Evan Stade2e4c22e2019-06-07 02:13:55261 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54262}
263
Sarah Huf9affb122018-04-27 21:36:36264void LoginScreenController::RequestPublicSessionKeyboardLayouts(
265 const AccountId& account_id,
266 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55267 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36268 return;
Evan Stade2e4c22e2019-06-07 02:13:55269 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36270}
271
Evan Stade2e4c22e2019-06-07 02:13:55272void LoginScreenController::SetClient(LoginScreenClient* client) {
273 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48274}
275
Evan Stadeb153f822019-05-23 19:14:43276LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31277 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43278}
279
Evan Stade9fe9cbe2019-06-03 23:05:55280void LoginScreenController::ShowKioskAppError(const std::string& message) {
281 ToastData toast_data(
282 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
283 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
284 true /*visible_on_lock_screen*/);
285 Shell::Get()->toast_manager()->Show(toast_data);
286}
287
288void LoginScreenController::FocusLoginShelf(bool reverse) {
289 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
290 // Tell the focus direction to the status area or the shelf so they can focus
291 // the correct child view.
Danila Kuzmin5b97e32f2020-08-20 16:34:12292 if (reverse || !shelf->shelf_widget()->login_shelf_view()->IsFocusable()) {
Evan Stade9fe9cbe2019-06-03 23:05:55293 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
294 return;
295 shelf->GetStatusAreaWidget()
296 ->status_area_widget_delegate()
297 ->set_default_last_focusable_child(reverse);
298 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
299 } else {
300 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
301 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
302 }
303}
304
305bool LoginScreenController::IsReadyForPassword() {
306 return LockScreen::HasInstance() && !IsAuthenticating();
307}
308
309void LoginScreenController::EnableAddUserButton(bool enable) {
310 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
311 ->shelf_widget()
312 ->login_shelf_view()
313 ->SetAddUserButtonEnabled(enable);
314}
315
316void LoginScreenController::EnableShutdownButton(bool enable) {
317 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
318 ->shelf_widget()
319 ->login_shelf_view()
320 ->SetShutdownButtonEnabled(enable);
321}
322
Ossama Mahmouda06399d2020-10-05 12:25:34323void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34324 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
325 ->shelf_widget()
326 ->login_shelf_view()
Ossama Mahmouda06399d2020-10-05 12:25:34327 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34328}
329
330void LoginScreenController::ShowParentAccessButton(bool show) {
331 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
332 ->shelf_widget()
333 ->login_shelf_view()
334 ->ShowParentAccessButton(show);
335}
336
Evan Stade9fe9cbe2019-06-03 23:05:55337void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
338 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
339 ->shelf_widget()
340 ->login_shelf_view()
341 ->SetAllowLoginAsGuest(allow_guest);
342}
343
Alexander Alekseev7020c6b52019-07-25 03:25:48344std::unique_ptr<ScopedGuestButtonBlocker>
345LoginScreenController::GetScopedGuestButtonBlocker() {
346 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
347 ->shelf_widget()
348 ->login_shelf_view()
349 ->GetScopedGuestButtonBlocker();
350}
351
Maksim Ivanovdbd9ade72019-08-09 15:34:16352void LoginScreenController::RequestSecurityTokenPin(
353 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33354 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16355}
356
357void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33358 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16359}
Toni Barzic4ebccb502020-02-28 16:00:40360bool LoginScreenController::SetLoginShelfGestureHandler(
361 const base::string16& nudge_text,
362 const base::RepeatingClosure& fling_callback,
363 base::OnceClosure exit_callback) {
364 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
365 ->shelf_widget()
366 ->SetLoginShelfSwipeHandler(nudge_text, fling_callback,
367 std::move(exit_callback));
368}
369
370void LoginScreenController::ClearLoginShelfGestureHandler() {
371 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
372 ->shelf_widget()
373 ->ClearLoginShelfSwipeHandler();
374}
Maksim Ivanovdbd9ade72019-08-09 15:34:16375
Evan Stade2e4c22e2019-06-07 02:13:55376void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47377 OnShow();
Evan Stade98b718e2019-06-03 17:15:34378 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47379}
380
Evan Stade2e4c22e2019-06-07 02:13:55381void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47382 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39383 session_manager::SessionState session_state =
384 Shell::Get()->session_controller()->GetSessionState();
385 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
386 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55387 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39388 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47389
390 OnShow();
Evan Stade98b718e2019-06-03 17:15:34391 // TODO(jdufault): rename LockScreen to LoginScreen.
392 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47393}
394
Evan Stade9c07ab42019-05-13 21:21:56395void LoginScreenController::SetKioskApps(
396 const std::vector<KioskAppMenuEntry>& kiosk_apps,
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25397 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
398 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56399 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
400 ->shelf_widget()
401 ->login_shelf_view()
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25402 ->SetKioskApps(kiosk_apps, launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56403}
404
Denis Kuznetsovad5a97c2020-07-09 10:45:35405void LoginScreenController::HandleAccelerator(
406 ash::LoginAcceleratorAction action) {
407 if (!client_)
408 return;
409 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44410}
411
Roman Sorokin925cddec2020-01-23 08:19:02412void LoginScreenController::ShowAccountAccessHelpApp(
413 gfx::NativeWindow parent_window) {
414 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11415}
416
Roman Sorokin925cddec2020-01-23 08:19:02417void LoginScreenController::ShowParentAccessHelpApp(
418 gfx::NativeWindow parent_window) {
419 client_->ShowParentAccessHelpApp(parent_window);
Aga Wronska7fef27e92019-08-22 17:51:27420}
421
Evan Stade3c971bc2019-06-11 22:12:44422void LoginScreenController::ShowLockScreenNotificationSettings() {
423 client_->ShowLockScreenNotificationSettings();
424}
425
Quan Nguyen3d7a0f02018-09-04 23:53:55426void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55427 if (!client_)
Tony de Luna46801932019-03-11 18:02:01428 return;
Evan Stade2e4c22e2019-06-07 02:13:55429 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55430}
431
Quan Nguyene377eb62019-02-11 23:02:25432void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55433 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48434 return;
Evan Stade2e4c22e2019-06-07 02:13:55435 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25436}
437
Jacob Dufaultb7a2d842017-12-01 23:21:15438void LoginScreenController::OnAuthenticateComplete(
439 OnAuthenticateCallback callback,
440 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43441 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46442 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43443 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33444
445 // During smart card login flow, multiple security token requests can be made.
446 // If the user cancels one, all others should also be canceled.
447 // At this point, the flow is ending and new security token requests are
448 // displayed again.
449 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42450}
451
Jacob Dufaultcbc1ee02018-02-28 18:38:54452void LoginScreenController::OnShow() {
453 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17454 if (authentication_stage_ != AuthenticationStage::kIdle) {
455 AuthenticationStage authentication_stage = authentication_stage_;
456 base::debug::Alias(&authentication_stage);
457 LOG(FATAL) << "Unexpected authentication stage "
458 << static_cast<int>(authentication_stage_);
459 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54460}
461
Jun Mukai5c7b5b42018-11-30 00:08:50462void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55463 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50464 return;
Evan Stade2e4c22e2019-06-07 02:13:55465 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50466}
467
Thomas Tellier0389c242020-08-27 11:44:45468void LoginScreenController::NotifyLoginScreenShown() {
469 if (!client_)
470 return;
471 client_->OnLoginScreenShown();
472}
473
xiaoyinh2bbdd102017-05-18 23:29:42474} // namespace ash