[go: nahoru, domu]

blob: 485a96be15b7941a61930bcd5a3a5614d044fe7c [file] [log] [blame]
Avi Drissman3a215d1e2022-09-07 19:43:091// Copyright 2017 The Chromium Authors
xiaoyinh2bbdd102017-05-18 23:29:422// 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
Henrique Ferreirof9d1cb22021-07-13 01:32:479#include "ash/constants/ash_pref_names.h"
Kevin Radtke343b5c12022-06-10 20:05:3010#include "ash/constants/notifier_catalogs.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5511#include "ash/focus_cycler.h"
Fabian Sommer4e0fc3d2020-02-27 14:16:3312#include "ash/login/security_token_request_controller.h"
jdufaulteb4c9f1e2017-06-08 23:08:3013#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5314#include "ash/login/ui/login_data_dispatcher.h"
Aga Wronska660503d2021-03-24 03:21:1115#include "ash/public/cpp/child_accounts/parent_access_controller.h"
Evan Stade2e4c22e2019-06-07 02:13:5516#include "ash/public/cpp/login_screen_client.h"
Kevin Radtke11d1599e2022-01-18 21:04:1117#include "ash/public/cpp/system/toast_data.h"
Aga Wronska16abb432018-01-11 23:49:5918#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1819#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3020#include "ash/shelf/login_shelf_view.h"
Andrew Xu25ff1212022-08-17 20:25:1121#include "ash/shelf/login_shelf_widget.h"
Quan Nguyend09dd112018-06-19 19:20:3222#include "ash/shelf/shelf.h"
23#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4024#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5925#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5526#include "ash/system/status_area_widget_delegate.h"
Anastasiia Nikolaienko8cdd7e62019-06-12 12:16:2427#include "ash/system/toast/toast_manager_impl.h"
Jun Mukai5c7b5b42018-11-30 00:08:5028#include "ash/system/tray/system_tray_notifier.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1729#include "base/debug/alias.h"
Martin Bidlingmaier07420b52023-06-12 07:45:0530#include "base/debug/dump_without_crashing.h"
Avi Drissman4de6dab2023-01-06 23:17:3531#include "base/functional/bind.h"
32#include "base/functional/callback.h"
Renato Silva0c0e1bb2019-09-11 13:04:1733#include "base/strings/string_util.h"
Jialiu Linf99b788b2018-01-17 23:01:2134#include "base/strings/utf_string_conversions.h"
Sean Mahere672a662023-01-09 21:42:2835#include "base/task/single_thread_task_runner.h"
Roman Sorokin5d610382022-04-05 08:30:5836#include "components/account_id/account_id.h"
Sarah Hu069eea12017-09-08 01:28:4037#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0938#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4239
40namespace ash {
41
Sarah Hu069eea12017-09-08 01:28:4042namespace {
xiaoyinh2bbdd102017-05-18 23:29:4243
Aga Wronskaa844cdcd12018-01-29 16:06:4444enum class SystemTrayVisibility {
45 kNone, // Tray not visible anywhere.
46 kPrimary, // Tray visible only on primary display.
47 kAll, // Tray visible on all displays.
48};
49
50void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
51 RootWindowController* primary_window_controller =
52 Shell::GetPrimaryRootWindowController();
53 for (RootWindowController* window_controller :
54 Shell::GetAllRootWindowControllers()) {
55 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
Denis Kuznetsov29772ae2022-12-23 15:17:0256 if (!status_area) {
Aga Wronskaa844cdcd12018-01-29 16:06:4457 continue;
Denis Kuznetsov29772ae2022-12-23 15:17:0258 }
Aga Wronskaa844cdcd12018-01-29 16:06:4459 if (window_controller == primary_window_controller) {
60 status_area->SetSystemTrayVisibility(
61 visibility == SystemTrayVisibility::kPrimary ||
62 visibility == SystemTrayVisibility::kAll);
63 } else {
64 status_area->SetSystemTrayVisibility(visibility ==
65 SystemTrayVisibility::kAll);
66 }
67 }
Aga Wronska16abb432018-01-11 23:49:5968}
69
Sarah Hu069eea12017-09-08 01:28:4070} // namespace
71
Jun Mukai5c7b5b42018-11-30 00:08:5072LoginScreenController::LoginScreenController(
73 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0074 : system_tray_notifier_(system_tray_notifier) {
Akihiro Otab3543e32021-04-07 18:24:5675 system_tray_notifier_->AddSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5076}
James Cook8f1e6062017-11-13 23:40:5977
Jun Mukai5c7b5b42018-11-30 00:08:5078LoginScreenController::~LoginScreenController() {
Akihiro Otab3543e32021-04-07 18:24:5679 system_tray_notifier_->RemoveSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5080}
xiaoyinh2bbdd102017-05-18 23:29:4281
Sarah Hu069eea12017-09-08 01:28:4082// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1683void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
84 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4085 if (for_test) {
86 // There is no remote pref service, so pretend that ash owns the pref.
87 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
88 return;
89 }
Sarah Hu069eea12017-09-08 01:28:4090}
91
Jacob Dufault2ca8c502018-06-25 19:12:1492bool LoginScreenController::IsAuthenticating() const {
93 return authentication_stage_ != AuthenticationStage::kIdle;
94}
95
Istvan Nagyc58bfd3a2023-06-30 17:15:3496bool LoginScreenController::IsAuthenticationCallbackExecuting() const {
97 return authentication_stage_ == AuthenticationStage::kUserCallback;
98}
99
Jacob Dufault2d20ae62018-09-20 22:19:52100void LoginScreenController::AuthenticateUserWithPasswordOrPin(
101 const AccountId& account_id,
102 const std::string& password,
103 bool authenticated_by_pin,
104 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:43105 // It is an error to call this function while an authentication is in
106 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:52107 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:56108 << "Duplicate authentication attempt; current authentication stage is "
109 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:43110
Evan Stade2e4c22e2019-06-07 02:13:55111 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33112 std::move(callback).Run(absl::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32113 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15114 }
xiaoyinh9f6fa0e2017-06-07 19:22:32115
Jacob Dufaulteafc6fe2017-10-11 21:16:52116 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
117 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24118 switch (force_fail_auth_for_debug_overlay_) {
119 case ForceFailAuth::kOff:
120 break;
121 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15122 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24123 return;
124 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14125 // Set a dummy authentication stage so that |IsAuthenticating| returns
126 // true.
Denis Kuznetsova22f07d2022-07-15 17:30:41127 LOG(WARNING) << "crbug.com/1339004 : Dummy auth state";
Jacob Dufault2ca8c502018-06-25 19:12:14128 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Sean Maher5b9af51f2022-11-21 15:32:47129 base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15130 FROM_HERE,
131 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11132 weak_factory_.GetWeakPtr(), std::move(callback),
Jacob Dufaultb7a2d842017-12-01 23:21:15133 false),
Peter Kastinge5a38ed2021-10-02 03:06:35134 base::Seconds(1));
Jacob Dufault0fbed9c02017-11-14 19:22:24135 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52136 }
137
Denis Kuznetsova22f07d2022-07-15 17:30:41138 LOG(WARNING) << "crbug.com/1339004 : started authentication";
Quan Nguyenf5224352018-11-06 02:03:34139 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
140
Denis Kuznetsov29772ae2022-12-23 15:17:02141 if (authenticated_by_pin) {
Yunke Zhouf819ab92022-10-27 18:25:32142 DCHECK(base::ContainsOnlyChars(password, "0123456789"));
Denis Kuznetsov29772ae2022-12-23 15:17:02143 }
Yunke Zhouf819ab92022-10-27 18:25:32144
Evan Stade2e4c22e2019-06-07 02:13:55145 client_->AuthenticateUserWithPasswordOrPin(
Yunke Zhouf819ab92022-10-27 18:25:32146 account_id, password, authenticated_by_pin,
Quan Nguyenf5224352018-11-06 02:03:34147 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11148 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32149}
150
Jacob Dufault2d20ae62018-09-20 22:19:52151void LoginScreenController::AuthenticateUserWithEasyUnlock(
152 const AccountId& account_id) {
153 // TODO(jdufault): integrate this into authenticate stage after mojom is
154 // refactored to use a callback.
Denis Kuznetsov29772ae2022-12-23 15:17:02155 if (!client_) {
xiaoyinh9f6fa0e2017-06-07 19:22:32156 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02157 }
Evan Stade2e4c22e2019-06-07 02:13:55158 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32159}
160
Maksim Ivanov675dd762019-07-29 18:31:10161void LoginScreenController::AuthenticateUserWithChallengeResponse(
162 const AccountId& account_id,
163 OnAuthenticateCallback callback) {
164 LOG_IF(FATAL, IsAuthenticating())
165 << "Duplicate authentication attempt; current authentication stage is "
166 << static_cast<int>(authentication_stage_);
167
168 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33169 std::move(callback).Run(/*success=*/absl::nullopt);
Maksim Ivanov675dd762019-07-29 18:31:10170 return;
171 }
172
173 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
174 client_->AuthenticateUserWithChallengeResponse(
175 account_id,
176 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
177 weak_factory_.GetWeakPtr(), std::move(callback)));
178}
179
Aga Wronska660503d2021-03-24 03:21:11180ParentCodeValidationResult LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17181 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05182 base::Time validation_time,
183 const std::string& code) {
184 DCHECK(!validation_time.is_null());
185
Denis Kuznetsov29772ae2022-12-23 15:17:02186 if (!client_) {
Aga Wronska660503d2021-03-24 03:21:11187 return ParentCodeValidationResult::kInternalError;
Denis Kuznetsov29772ae2022-12-23 15:17:02188 }
Aga Wronskaac6cf362019-02-26 21:36:55189
Henrique Grandinetti914c34b62019-08-12 14:03:19190 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55191}
192
Fabian Sommer4e0fc3d2020-02-27 14:16:33193bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
194 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45195}
196
Jacob Dufaultffd9b0d2017-11-15 23:07:16197void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Jeffrey Young22ff81f2023-11-07 20:44:45198 session_manager::SessionState session_state =
199 Shell::Get()->session_controller()->GetSessionState();
200 if (session_state == session_manager::SessionState::LOGGED_IN_NOT_ACTIVE) {
201 // b/308840749 do not propagate OnFocusPod while a user is mid login.
202 return;
203 }
Roman Sorokin5d610382022-04-05 08:30:58204 GetModel()->NotifyFocusPod(account_id);
Denis Kuznetsov29772ae2022-12-23 15:17:02205 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27206 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02207 }
Evan Stade2e4c22e2019-06-07 02:13:55208 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27209}
210
Jacob Dufaultffd9b0d2017-11-15 23:07:16211void LoginScreenController::CancelAddUser() {
Denis Kuznetsov29772ae2022-12-23 15:17:02212 if (!client_) {
Wenzhao Zang16e7ea722017-09-16 01:27:30213 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02214 }
Evan Stade2e4c22e2019-06-07 02:13:55215 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30216}
217
Ossama Mahmoud8fa195f2021-09-30 19:51:25218void LoginScreenController::ShowGuestTosScreen() {
Denis Kuznetsov29772ae2022-12-23 15:17:02219 if (!client_) {
Ossama Mahmoud8fa195f2021-09-30 19:51:25220 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02221 }
Ossama Mahmoud8fa195f2021-09-30 19:51:25222 client_->ShowGuestTosScreen();
223}
224
Jacob Dufaultffd9b0d2017-11-15 23:07:16225void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27226 const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02227 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27228 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02229 }
Evan Stade2e4c22e2019-06-07 02:13:55230 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27231}
232
Jacob Dufaultffd9b0d2017-11-15 23:07:16233void LoginScreenController::FocusLockScreenApps(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02234 if (!client_) {
Toni Barzicf61c4452017-10-05 03:57:48235 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02236 }
Evan Stade2e4c22e2019-06-07 02:13:55237 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48238}
239
Roman Sorokin26d7e9662020-02-24 17:52:18240void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Denis Kuznetsov29772ae2022-12-23 15:17:02241 if (!client_) {
Sarah Hu9fba0e752018-02-07 01:41:09242 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02243 }
Roman Sorokin26d7e9662020-02-24 17:52:18244 client_->ShowGaiaSignin(prefilled_account);
245}
246
Denis Kuznetsov55c97be2023-11-09 18:29:38247void LoginScreenController::StartUserRecovery(
248 const AccountId& account_to_recover) {
249 if (!client_) {
250 return;
251 }
252 client_->StartUserRecovery(account_to_recover);
253}
254
Ossama Mahmoud95164772021-06-30 14:18:14255void LoginScreenController::ShowOsInstallScreen() {
Denis Kuznetsov29772ae2022-12-23 15:17:02256 if (!client_) {
Ossama Mahmoud95164772021-06-30 14:18:14257 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02258 }
Ossama Mahmoud95164772021-06-30 14:18:14259 client_->ShowOsInstallScreen();
260}
261
Jacob Dufaultfc31c742018-03-20 17:32:19262void LoginScreenController::OnRemoveUserWarningShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02263 if (!client_) {
Jacob Dufaultfc31c742018-03-20 17:32:19264 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02265 }
Evan Stade2e4c22e2019-06-07 02:13:55266 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19267}
268
269void LoginScreenController::RemoveUser(const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02270 if (!client_) {
Jacob Dufaultfc31c742018-03-20 17:32:19271 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02272 }
Evan Stade2e4c22e2019-06-07 02:13:55273 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19274}
275
Sarah Hu3fcf9f82018-03-22 20:32:54276void LoginScreenController::LaunchPublicSession(
277 const AccountId& account_id,
278 const std::string& locale,
279 const std::string& input_method) {
Denis Kuznetsov29772ae2022-12-23 15:17:02280 if (!client_) {
Sarah Hu3fcf9f82018-03-22 20:32:54281 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02282 }
Evan Stade2e4c22e2019-06-07 02:13:55283 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54284}
285
Sarah Huf9affb122018-04-27 21:36:36286void LoginScreenController::RequestPublicSessionKeyboardLayouts(
287 const AccountId& account_id,
288 const std::string& locale) {
Denis Kuznetsov29772ae2022-12-23 15:17:02289 if (!client_) {
Sarah Huf9affb122018-04-27 21:36:36290 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02291 }
Evan Stade2e4c22e2019-06-07 02:13:55292 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36293}
294
Evan Stade2e4c22e2019-06-07 02:13:55295void LoginScreenController::SetClient(LoginScreenClient* client) {
296 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48297}
298
Evan Stadeb153f822019-05-23 19:14:43299LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31300 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43301}
302
Evan Stade9fe9cbe2019-06-03 23:05:55303void LoginScreenController::ShowKioskAppError(const std::string& message) {
Kevin Radtke11d1599e2022-01-18 21:04:11304 ToastData toast_data("KioskAppError", ToastCatalogName::kKioskAppError,
305 base::UTF8ToUTF16(message), ToastData::kInfiniteDuration,
Ben Franzef7fab22022-04-06 16:13:16306 /*visible_on_lock_screen=*/true,
Kevin Radtke9e9e6a962022-04-18 18:16:23307 /*has_dismiss_button=*/true);
Ben Beckere1807312022-11-14 20:25:08308 Shell::Get()->toast_manager()->Show(std::move(toast_data));
Evan Stade9fe9cbe2019-06-03 23:05:55309}
310
311void LoginScreenController::FocusLoginShelf(bool reverse) {
312 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
313 // Tell the focus direction to the status area or the shelf so they can focus
314 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17315 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
Andrew Xub6a52a12022-07-12 21:02:18316 (reverse || !shelf->shelf_widget()->GetLoginShelfView()->IsFocusable())) {
Danila Kuzmin35f80082020-11-25 12:26:17317 // Focus goes to system tray (status area) if one of the following is true:
318 // - system tray is visible and tab is in reverse order;
319 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55320 shelf->GetStatusAreaWidget()
321 ->status_area_widget_delegate()
322 ->set_default_last_focusable_child(reverse);
323 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Andrew Xub6a52a12022-07-12 21:02:18324 } else if (shelf->shelf_widget()->GetLoginShelfView()->IsFocusable()) {
Andrew Xu25ff1212022-08-17 20:25:11325 // Otherwise focus goes to login shelf buttons when there is any.
326 if (features::IsUseLoginShelfWidgetEnabled()) {
327 LoginShelfWidget* login_shelf_widget = shelf->login_shelf_widget();
328 login_shelf_widget->SetDefaultLastFocusableChild(reverse);
329 Shell::Get()->focus_cycler()->FocusWidget(login_shelf_widget);
330 } else {
331 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
332 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
333 }
Danila Kuzmin35f80082020-11-25 12:26:17334 } else {
335 // No elements to focus on the shelf.
Martin Bidlingmaier07420b52023-06-12 07:45:05336 //
337 // TODO(b/261774910): This is reachable apparently.
338 // Reaching this and not doing anything probably means that no view element
339 // is focused, but this is preferable to crashing via NOTREACHED().
340 base::debug::DumpWithoutCrashing();
Evan Stade9fe9cbe2019-06-03 23:05:55341 }
342}
343
344bool LoginScreenController::IsReadyForPassword() {
345 return LockScreen::HasInstance() && !IsAuthenticating();
346}
347
348void LoginScreenController::EnableAddUserButton(bool enable) {
349 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
350 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18351 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55352 ->SetAddUserButtonEnabled(enable);
353}
354
355void LoginScreenController::EnableShutdownButton(bool enable) {
356 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
357 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18358 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55359 ->SetShutdownButtonEnabled(enable);
360}
361
Yunke Zhou9319aab2020-12-01 07:34:42362void LoginScreenController::EnableShelfButtons(bool enable) {
363 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
364 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18365 ->GetLoginShelfView()
Yunke Zhou9319aab2020-12-01 07:34:42366 ->SetButtonEnabled(enable);
367}
368
Ossama Mahmouda06399d2020-10-05 12:25:34369void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34370 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
371 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18372 ->GetLoginShelfView()
Ossama Mahmouda06399d2020-10-05 12:25:34373 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34374}
375
376void LoginScreenController::ShowParentAccessButton(bool show) {
377 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
378 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18379 ->GetLoginShelfView()
Evan Stade98b718e2019-06-03 17:15:34380 ->ShowParentAccessButton(show);
381}
382
Evan Stade9fe9cbe2019-06-03 23:05:55383void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
384 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
385 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18386 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55387 ->SetAllowLoginAsGuest(allow_guest);
388}
389
Alexander Alekseev7020c6b52019-07-25 03:25:48390std::unique_ptr<ScopedGuestButtonBlocker>
391LoginScreenController::GetScopedGuestButtonBlocker() {
392 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
393 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18394 ->GetLoginShelfView()
Alexander Alekseev7020c6b52019-07-25 03:25:48395 ->GetScopedGuestButtonBlocker();
396}
397
Maksim Ivanovdbd9ade72019-08-09 15:34:16398void LoginScreenController::RequestSecurityTokenPin(
399 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33400 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16401}
402
403void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33404 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16405}
406
Danila Kuzmin1546b88e2022-02-07 12:12:35407views::Widget* LoginScreenController::GetLoginWindowWidget() {
408 return client_ ? client_->GetLoginWindowWidget() : nullptr;
409}
410
Evan Stade2e4c22e2019-06-07 02:13:55411void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57412 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47413 OnShow();
Evan Stade98b718e2019-06-03 17:15:34414 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47415}
416
Evan Stade2e4c22e2019-06-07 02:13:55417void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57418 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47419 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39420 session_manager::SessionState session_state =
421 Shell::Get()->session_controller()->GetSessionState();
422 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
423 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55424 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39425 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47426
427 OnShow();
Evan Stade98b718e2019-06-03 17:15:34428 // TODO(jdufault): rename LockScreen to LoginScreen.
429 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47430}
431
Evan Stade9c07ab42019-05-13 21:21:56432void LoginScreenController::SetKioskApps(
Sherri Lin51944b6f2022-04-21 21:32:53433 const std::vector<KioskAppMenuEntry>& kiosk_apps) {
434 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
435 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18436 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53437 ->SetKioskApps(kiosk_apps);
438}
439
440void LoginScreenController::ConfigureKioskCallbacks(
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25441 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
442 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56443 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
444 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18445 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53446 ->ConfigureKioskCallbacks(launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56447}
448
Denis Kuznetsovad5a97c2020-07-09 10:45:35449void LoginScreenController::HandleAccelerator(
450 ash::LoginAcceleratorAction action) {
Denis Kuznetsov29772ae2022-12-23 15:17:02451 if (!client_) {
Denis Kuznetsovad5a97c2020-07-09 10:45:35452 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02453 }
Denis Kuznetsovad5a97c2020-07-09 10:45:35454 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44455}
456
Roman Sorokin925cddec2020-01-23 08:19:02457void LoginScreenController::ShowAccountAccessHelpApp(
458 gfx::NativeWindow parent_window) {
459 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11460}
461
Courtney Wong45cfc9fa62021-06-30 22:08:05462void LoginScreenController::ShowParentAccessHelpApp() {
463 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27464}
465
Evan Stade3c971bc2019-06-11 22:12:44466void LoginScreenController::ShowLockScreenNotificationSettings() {
467 client_->ShowLockScreenNotificationSettings();
468}
469
Quan Nguyen3d7a0f02018-09-04 23:53:55470void LoginScreenController::FocusOobeDialog() {
Denis Kuznetsov29772ae2022-12-23 15:17:02471 if (!client_) {
Tony de Luna46801932019-03-11 18:02:01472 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02473 }
Evan Stade2e4c22e2019-06-07 02:13:55474 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55475}
476
Jacob Dufaultb7a2d842017-12-01 23:21:15477void LoginScreenController::OnAuthenticateComplete(
478 OnAuthenticateCallback callback,
479 bool success) {
Denis Kuznetsova22f07d2022-07-15 17:30:41480 LOG(WARNING) << "crbug.com/1339004 : authentication complete";
Jacob Dufault8876ba82018-03-27 22:55:43481 authentication_stage_ = AuthenticationStage::kUserCallback;
Anton Bikineev43cee28e2021-05-14 23:35:33482 std::move(callback).Run(absl::make_optional<bool>(success));
Denis Kuznetsova22f07d2022-07-15 17:30:41483 LOG(WARNING) << "crbug.com/1339004 : triggered callback";
Jacob Dufault8876ba82018-03-27 22:55:43484 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33485
486 // During smart card login flow, multiple security token requests can be made.
487 // If the user cancels one, all others should also be canceled.
488 // At this point, the flow is ending and new security token requests are
489 // displayed again.
490 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42491}
492
Jacob Dufaultcbc1ee02018-02-28 18:38:54493void LoginScreenController::OnShow() {
494 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17495 if (authentication_stage_ != AuthenticationStage::kIdle) {
496 AuthenticationStage authentication_stage = authentication_stage_;
497 base::debug::Alias(&authentication_stage);
498 LOG(FATAL) << "Unexpected authentication stage "
499 << static_cast<int>(authentication_stage_);
500 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54501}
502
Jun Mukai5c7b5b42018-11-30 00:08:50503void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02504 if (!client_) {
Jun Mukai5c7b5b42018-11-30 00:08:50505 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02506 }
Evan Stade2e4c22e2019-06-07 02:13:55507 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50508}
509
Akihiro Otab3543e32021-04-07 18:24:56510void LoginScreenController::OnSystemTrayBubbleShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02511 if (!client_) {
Akihiro Otab3543e32021-04-07 18:24:56512 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02513 }
Akihiro Otab3543e32021-04-07 18:24:56514 client_->OnSystemTrayBubbleShown();
515}
516
Roman Sorokin16faa372021-03-09 16:17:57517void LoginScreenController::OnLockScreenDestroyed() {
Eriko Kurimoto2cc98342023-08-04 04:23:31518 // TODO(b/280250064): Make sure allowing this condition won't break
519 // LoginScreenController logic.
520 if (authentication_stage_ != AuthenticationStage::kIdle) {
521 LOG(WARNING) << "Lock screen is destroyed while the authentication stage: "
522 << authentication_stage_;
523 }
Roman Sorokin16faa372021-03-09 16:17:57524
525 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
526 authentication_stage_ = AuthenticationStage::kIdle;
Alex Newcomer9f730e292021-04-01 21:46:15527 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57528}
529
Thomas Tellier0389c242020-08-27 11:44:45530void LoginScreenController::NotifyLoginScreenShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02531 if (!client_) {
Thomas Tellier0389c242020-08-27 11:44:45532 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02533 }
Thomas Tellier0389c242020-08-27 11:44:45534 client_->OnLoginScreenShown();
535}
536
Eriko Kurimoto2cc98342023-08-04 04:23:31537std::ostream& operator<<(std::ostream& ostream,
538 LoginScreenController::AuthenticationStage stage) {
539 switch (stage) {
540 case LoginScreenController::AuthenticationStage::kIdle:
541 return ostream << "kIdle";
542 case LoginScreenController::AuthenticationStage::kDoAuthenticate:
543 return ostream << "kDoAuthenticate";
544 case LoginScreenController::AuthenticationStage::kUserCallback:
545 return ostream << "kUserCallback";
546 }
547}
548
xiaoyinh2bbdd102017-05-18 23:29:42549} // namespace ash