[go: nahoru, domu]

blob: d26d429d544fcf3496bc33c88361ac5c49e151a6 [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
Edman Anjos82d376f2024-01-04 10:26:1544constexpr std::string_view kKioskToastId = "KioskAppError";
45
Aga Wronskaa844cdcd12018-01-29 16:06:4446enum class SystemTrayVisibility {
47 kNone, // Tray not visible anywhere.
48 kPrimary, // Tray visible only on primary display.
49 kAll, // Tray visible on all displays.
50};
51
52void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
53 RootWindowController* primary_window_controller =
54 Shell::GetPrimaryRootWindowController();
55 for (RootWindowController* window_controller :
56 Shell::GetAllRootWindowControllers()) {
57 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
Denis Kuznetsov29772ae2022-12-23 15:17:0258 if (!status_area) {
Aga Wronskaa844cdcd12018-01-29 16:06:4459 continue;
Denis Kuznetsov29772ae2022-12-23 15:17:0260 }
Aga Wronskaa844cdcd12018-01-29 16:06:4461 if (window_controller == primary_window_controller) {
62 status_area->SetSystemTrayVisibility(
63 visibility == SystemTrayVisibility::kPrimary ||
64 visibility == SystemTrayVisibility::kAll);
65 } else {
66 status_area->SetSystemTrayVisibility(visibility ==
67 SystemTrayVisibility::kAll);
68 }
69 }
Aga Wronska16abb432018-01-11 23:49:5970}
71
Sarah Hu069eea12017-09-08 01:28:4072} // namespace
73
Jun Mukai5c7b5b42018-11-30 00:08:5074LoginScreenController::LoginScreenController(
75 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0076 : system_tray_notifier_(system_tray_notifier) {
Akihiro Otab3543e32021-04-07 18:24:5677 system_tray_notifier_->AddSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5078}
James Cook8f1e6062017-11-13 23:40:5979
Jun Mukai5c7b5b42018-11-30 00:08:5080LoginScreenController::~LoginScreenController() {
Akihiro Otab3543e32021-04-07 18:24:5681 system_tray_notifier_->RemoveSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5082}
xiaoyinh2bbdd102017-05-18 23:29:4283
Sarah Hu069eea12017-09-08 01:28:4084// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1685void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
86 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4087 if (for_test) {
88 // There is no remote pref service, so pretend that ash owns the pref.
89 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
90 return;
91 }
Sarah Hu069eea12017-09-08 01:28:4092}
93
Jacob Dufault2ca8c502018-06-25 19:12:1494bool LoginScreenController::IsAuthenticating() const {
95 return authentication_stage_ != AuthenticationStage::kIdle;
96}
97
Istvan Nagyc58bfd3a2023-06-30 17:15:3498bool LoginScreenController::IsAuthenticationCallbackExecuting() const {
99 return authentication_stage_ == AuthenticationStage::kUserCallback;
100}
101
Jacob Dufault2d20ae62018-09-20 22:19:52102void LoginScreenController::AuthenticateUserWithPasswordOrPin(
103 const AccountId& account_id,
104 const std::string& password,
105 bool authenticated_by_pin,
106 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:43107 // It is an error to call this function while an authentication is in
108 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:52109 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:56110 << "Duplicate authentication attempt; current authentication stage is "
111 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:43112
Evan Stade2e4c22e2019-06-07 02:13:55113 if (!client_) {
Arthur Sonzognia98e4432023-11-28 18:15:01114 std::move(callback).Run(std::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32115 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15116 }
xiaoyinh9f6fa0e2017-06-07 19:22:32117
Jacob Dufaulteafc6fe2017-10-11 21:16:52118 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
119 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24120 switch (force_fail_auth_for_debug_overlay_) {
121 case ForceFailAuth::kOff:
122 break;
123 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15124 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24125 return;
126 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14127 // Set a dummy authentication stage so that |IsAuthenticating| returns
128 // true.
Denis Kuznetsova22f07d2022-07-15 17:30:41129 LOG(WARNING) << "crbug.com/1339004 : Dummy auth state";
Istvan Nagy16b2f0822023-11-24 16:11:59130 SetAuthenticationStage(AuthenticationStage::kDoAuthenticate);
Sean Maher5b9af51f2022-11-21 15:32:47131 base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15132 FROM_HERE,
133 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11134 weak_factory_.GetWeakPtr(), std::move(callback),
Jacob Dufaultb7a2d842017-12-01 23:21:15135 false),
Peter Kastinge5a38ed2021-10-02 03:06:35136 base::Seconds(1));
Jacob Dufault0fbed9c02017-11-14 19:22:24137 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52138 }
139
Denis Kuznetsova22f07d2022-07-15 17:30:41140 LOG(WARNING) << "crbug.com/1339004 : started authentication";
Istvan Nagy16b2f0822023-11-24 16:11:59141 SetAuthenticationStage(AuthenticationStage::kDoAuthenticate);
Quan Nguyenf5224352018-11-06 02:03:34142
Denis Kuznetsov29772ae2022-12-23 15:17:02143 if (authenticated_by_pin) {
Yunke Zhouf819ab92022-10-27 18:25:32144 DCHECK(base::ContainsOnlyChars(password, "0123456789"));
Denis Kuznetsov29772ae2022-12-23 15:17:02145 }
Yunke Zhouf819ab92022-10-27 18:25:32146
Evan Stade2e4c22e2019-06-07 02:13:55147 client_->AuthenticateUserWithPasswordOrPin(
Yunke Zhouf819ab92022-10-27 18:25:32148 account_id, password, authenticated_by_pin,
Quan Nguyenf5224352018-11-06 02:03:34149 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11150 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32151}
152
Jacob Dufault2d20ae62018-09-20 22:19:52153void LoginScreenController::AuthenticateUserWithEasyUnlock(
154 const AccountId& account_id) {
155 // TODO(jdufault): integrate this into authenticate stage after mojom is
156 // refactored to use a callback.
Denis Kuznetsov29772ae2022-12-23 15:17:02157 if (!client_) {
xiaoyinh9f6fa0e2017-06-07 19:22:32158 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02159 }
Evan Stade2e4c22e2019-06-07 02:13:55160 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32161}
162
Maksim Ivanov675dd762019-07-29 18:31:10163void LoginScreenController::AuthenticateUserWithChallengeResponse(
164 const AccountId& account_id,
165 OnAuthenticateCallback callback) {
166 LOG_IF(FATAL, IsAuthenticating())
167 << "Duplicate authentication attempt; current authentication stage is "
168 << static_cast<int>(authentication_stage_);
169
170 if (!client_) {
Arthur Sonzognia98e4432023-11-28 18:15:01171 std::move(callback).Run(/*success=*/std::nullopt);
Maksim Ivanov675dd762019-07-29 18:31:10172 return;
173 }
174
Istvan Nagy16b2f0822023-11-24 16:11:59175 SetAuthenticationStage(AuthenticationStage::kDoAuthenticate);
Maksim Ivanov675dd762019-07-29 18:31:10176 client_->AuthenticateUserWithChallengeResponse(
177 account_id,
178 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
179 weak_factory_.GetWeakPtr(), std::move(callback)));
180}
181
Aga Wronska660503d2021-03-24 03:21:11182ParentCodeValidationResult LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17183 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05184 base::Time validation_time,
185 const std::string& code) {
186 DCHECK(!validation_time.is_null());
187
Denis Kuznetsov29772ae2022-12-23 15:17:02188 if (!client_) {
Aga Wronska660503d2021-03-24 03:21:11189 return ParentCodeValidationResult::kInternalError;
Denis Kuznetsov29772ae2022-12-23 15:17:02190 }
Aga Wronskaac6cf362019-02-26 21:36:55191
Henrique Grandinetti914c34b62019-08-12 14:03:19192 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55193}
194
Fabian Sommer4e0fc3d2020-02-27 14:16:33195bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
196 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45197}
198
Jacob Dufaultffd9b0d2017-11-15 23:07:16199void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Jeffrey Young22ff81f2023-11-07 20:44:45200 session_manager::SessionState session_state =
201 Shell::Get()->session_controller()->GetSessionState();
202 if (session_state == session_manager::SessionState::LOGGED_IN_NOT_ACTIVE) {
203 // b/308840749 do not propagate OnFocusPod while a user is mid login.
204 return;
205 }
Roman Sorokin5d610382022-04-05 08:30:58206 GetModel()->NotifyFocusPod(account_id);
Denis Kuznetsov29772ae2022-12-23 15:17:02207 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27208 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02209 }
Evan Stade2e4c22e2019-06-07 02:13:55210 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27211}
212
Jacob Dufaultffd9b0d2017-11-15 23:07:16213void LoginScreenController::CancelAddUser() {
Denis Kuznetsov29772ae2022-12-23 15:17:02214 if (!client_) {
Wenzhao Zang16e7ea722017-09-16 01:27:30215 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02216 }
Evan Stade2e4c22e2019-06-07 02:13:55217 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30218}
219
Ossama Mahmoud8fa195f2021-09-30 19:51:25220void LoginScreenController::ShowGuestTosScreen() {
Denis Kuznetsov29772ae2022-12-23 15:17:02221 if (!client_) {
Ossama Mahmoud8fa195f2021-09-30 19:51:25222 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02223 }
Ossama Mahmoud8fa195f2021-09-30 19:51:25224 client_->ShowGuestTosScreen();
225}
226
Jacob Dufaultffd9b0d2017-11-15 23:07:16227void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27228 const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02229 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27230 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02231 }
Evan Stade2e4c22e2019-06-07 02:13:55232 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27233}
234
Jacob Dufaultffd9b0d2017-11-15 23:07:16235void LoginScreenController::FocusLockScreenApps(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02236 if (!client_) {
Toni Barzicf61c4452017-10-05 03:57:48237 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02238 }
Evan Stade2e4c22e2019-06-07 02:13:55239 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48240}
241
Roman Sorokin26d7e9662020-02-24 17:52:18242void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Denis Kuznetsov29772ae2022-12-23 15:17:02243 if (!client_) {
Sarah Hu9fba0e752018-02-07 01:41:09244 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02245 }
Roman Sorokin26d7e9662020-02-24 17:52:18246 client_->ShowGaiaSignin(prefilled_account);
247}
248
Denis Kuznetsov55c97be2023-11-09 18:29:38249void LoginScreenController::StartUserRecovery(
250 const AccountId& account_to_recover) {
251 if (!client_) {
252 return;
253 }
254 client_->StartUserRecovery(account_to_recover);
255}
256
Ossama Mahmoud95164772021-06-30 14:18:14257void LoginScreenController::ShowOsInstallScreen() {
Denis Kuznetsov29772ae2022-12-23 15:17:02258 if (!client_) {
Ossama Mahmoud95164772021-06-30 14:18:14259 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02260 }
Ossama Mahmoud95164772021-06-30 14:18:14261 client_->ShowOsInstallScreen();
262}
263
Jacob Dufaultfc31c742018-03-20 17:32:19264void LoginScreenController::OnRemoveUserWarningShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02265 if (!client_) {
Jacob Dufaultfc31c742018-03-20 17:32:19266 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02267 }
Evan Stade2e4c22e2019-06-07 02:13:55268 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19269}
270
271void LoginScreenController::RemoveUser(const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02272 if (!client_) {
Jacob Dufaultfc31c742018-03-20 17:32:19273 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02274 }
Evan Stade2e4c22e2019-06-07 02:13:55275 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19276}
277
Sarah Hu3fcf9f82018-03-22 20:32:54278void LoginScreenController::LaunchPublicSession(
279 const AccountId& account_id,
280 const std::string& locale,
281 const std::string& input_method) {
Denis Kuznetsov29772ae2022-12-23 15:17:02282 if (!client_) {
Sarah Hu3fcf9f82018-03-22 20:32:54283 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02284 }
Evan Stade2e4c22e2019-06-07 02:13:55285 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54286}
287
Sarah Huf9affb122018-04-27 21:36:36288void LoginScreenController::RequestPublicSessionKeyboardLayouts(
289 const AccountId& account_id,
290 const std::string& locale) {
Denis Kuznetsov29772ae2022-12-23 15:17:02291 if (!client_) {
Sarah Huf9affb122018-04-27 21:36:36292 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02293 }
Evan Stade2e4c22e2019-06-07 02:13:55294 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36295}
296
Evan Stade2e4c22e2019-06-07 02:13:55297void LoginScreenController::SetClient(LoginScreenClient* client) {
298 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48299}
300
Evan Stadeb153f822019-05-23 19:14:43301LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31302 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43303}
304
Evan Stade9fe9cbe2019-06-03 23:05:55305void LoginScreenController::ShowKioskAppError(const std::string& message) {
Edman Anjos82d376f2024-01-04 10:26:15306 ToastData toast_data(std::string(kKioskToastId),
307 ToastCatalogName::kKioskAppError,
Kevin Radtke11d1599e2022-01-18 21:04:11308 base::UTF8ToUTF16(message), ToastData::kInfiniteDuration,
Ben Franzef7fab22022-04-06 16:13:16309 /*visible_on_lock_screen=*/true,
Kevin Radtke9e9e6a962022-04-18 18:16:23310 /*has_dismiss_button=*/true);
Ben Beckere1807312022-11-14 20:25:08311 Shell::Get()->toast_manager()->Show(std::move(toast_data));
Evan Stade9fe9cbe2019-06-03 23:05:55312}
313
314void LoginScreenController::FocusLoginShelf(bool reverse) {
315 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
316 // Tell the focus direction to the status area or the shelf so they can focus
317 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17318 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
Andrew Xub6a52a12022-07-12 21:02:18319 (reverse || !shelf->shelf_widget()->GetLoginShelfView()->IsFocusable())) {
Danila Kuzmin35f80082020-11-25 12:26:17320 // Focus goes to system tray (status area) if one of the following is true:
321 // - system tray is visible and tab is in reverse order;
322 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55323 shelf->GetStatusAreaWidget()
324 ->status_area_widget_delegate()
325 ->set_default_last_focusable_child(reverse);
326 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Andrew Xub6a52a12022-07-12 21:02:18327 } else if (shelf->shelf_widget()->GetLoginShelfView()->IsFocusable()) {
Andrew Xu25ff1212022-08-17 20:25:11328 // Otherwise focus goes to login shelf buttons when there is any.
James Cook3ae68b32024-02-06 18:12:10329 LoginShelfWidget* login_shelf_widget = shelf->login_shelf_widget();
330 login_shelf_widget->SetDefaultLastFocusableChild(reverse);
331 Shell::Get()->focus_cycler()->FocusWidget(login_shelf_widget);
Danila Kuzmin35f80082020-11-25 12:26:17332 } else {
333 // No elements to focus on the shelf.
Martin Bidlingmaier07420b52023-06-12 07:45:05334 //
335 // TODO(b/261774910): This is reachable apparently.
336 // Reaching this and not doing anything probably means that no view element
337 // is focused, but this is preferable to crashing via NOTREACHED().
338 base::debug::DumpWithoutCrashing();
Evan Stade9fe9cbe2019-06-03 23:05:55339 }
340}
341
342bool LoginScreenController::IsReadyForPassword() {
343 return LockScreen::HasInstance() && !IsAuthenticating();
344}
345
346void LoginScreenController::EnableAddUserButton(bool enable) {
347 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
348 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18349 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55350 ->SetAddUserButtonEnabled(enable);
351}
352
353void LoginScreenController::EnableShutdownButton(bool enable) {
354 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
355 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18356 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55357 ->SetShutdownButtonEnabled(enable);
358}
359
Yunke Zhou9319aab2020-12-01 07:34:42360void LoginScreenController::EnableShelfButtons(bool enable) {
361 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
362 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18363 ->GetLoginShelfView()
Yunke Zhou9319aab2020-12-01 07:34:42364 ->SetButtonEnabled(enable);
365}
366
Ossama Mahmouda06399d2020-10-05 12:25:34367void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34368 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
369 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18370 ->GetLoginShelfView()
Ossama Mahmouda06399d2020-10-05 12:25:34371 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34372}
373
374void LoginScreenController::ShowParentAccessButton(bool show) {
375 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
376 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18377 ->GetLoginShelfView()
Evan Stade98b718e2019-06-03 17:15:34378 ->ShowParentAccessButton(show);
379}
380
Evan Stade9fe9cbe2019-06-03 23:05:55381void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
382 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
383 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18384 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55385 ->SetAllowLoginAsGuest(allow_guest);
386}
387
Alexander Alekseev7020c6b52019-07-25 03:25:48388std::unique_ptr<ScopedGuestButtonBlocker>
389LoginScreenController::GetScopedGuestButtonBlocker() {
390 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
391 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18392 ->GetLoginShelfView()
Alexander Alekseev7020c6b52019-07-25 03:25:48393 ->GetScopedGuestButtonBlocker();
394}
395
Maksim Ivanovdbd9ade72019-08-09 15:34:16396void LoginScreenController::RequestSecurityTokenPin(
397 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33398 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16399}
400
401void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33402 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16403}
404
Danila Kuzmin1546b88e2022-02-07 12:12:35405views::Widget* LoginScreenController::GetLoginWindowWidget() {
406 return client_ ? client_->GetLoginWindowWidget() : nullptr;
407}
408
Evan Stade2e4c22e2019-06-07 02:13:55409void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57410 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47411 OnShow();
Evan Stade98b718e2019-06-03 17:15:34412 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47413}
414
Evan Stade2e4c22e2019-06-07 02:13:55415void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57416 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47417 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39418 session_manager::SessionState session_state =
419 Shell::Get()->session_controller()->GetSessionState();
420 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
421 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55422 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39423 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47424
425 OnShow();
Evan Stade98b718e2019-06-03 17:15:34426 // TODO(jdufault): rename LockScreen to LoginScreen.
427 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47428}
429
Evan Stade9c07ab42019-05-13 21:21:56430void LoginScreenController::SetKioskApps(
Sherri Lin51944b6f2022-04-21 21:32:53431 const std::vector<KioskAppMenuEntry>& kiosk_apps) {
432 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
433 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18434 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53435 ->SetKioskApps(kiosk_apps);
436}
437
438void LoginScreenController::ConfigureKioskCallbacks(
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25439 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
440 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56441 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
442 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18443 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53444 ->ConfigureKioskCallbacks(launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56445}
446
Istvan Nagy16b2f0822023-11-24 16:11:59447void LoginScreenController::SetAuthenticationStage(
448 AuthenticationStage authentication_stage) {
449 if (authentication_stage == authentication_stage_) {
450 return;
451 }
452 authentication_stage_ = authentication_stage;
453 login_data_dispatcher_.AuthenticationStageChange(authentication_stage);
454}
455
Denis Kuznetsovad5a97c2020-07-09 10:45:35456void LoginScreenController::HandleAccelerator(
457 ash::LoginAcceleratorAction action) {
Denis Kuznetsov29772ae2022-12-23 15:17:02458 if (!client_) {
Denis Kuznetsovad5a97c2020-07-09 10:45:35459 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02460 }
Denis Kuznetsovad5a97c2020-07-09 10:45:35461 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44462}
463
Roman Sorokin925cddec2020-01-23 08:19:02464void LoginScreenController::ShowAccountAccessHelpApp(
465 gfx::NativeWindow parent_window) {
466 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11467}
468
Courtney Wong45cfc9fa62021-06-30 22:08:05469void LoginScreenController::ShowParentAccessHelpApp() {
470 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27471}
472
Evan Stade3c971bc2019-06-11 22:12:44473void LoginScreenController::ShowLockScreenNotificationSettings() {
474 client_->ShowLockScreenNotificationSettings();
475}
476
Quan Nguyen3d7a0f02018-09-04 23:53:55477void LoginScreenController::FocusOobeDialog() {
Denis Kuznetsov29772ae2022-12-23 15:17:02478 if (!client_) {
Tony de Luna46801932019-03-11 18:02:01479 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02480 }
Evan Stade2e4c22e2019-06-07 02:13:55481 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55482}
483
Jacob Dufaultb7a2d842017-12-01 23:21:15484void LoginScreenController::OnAuthenticateComplete(
485 OnAuthenticateCallback callback,
486 bool success) {
Denis Kuznetsova22f07d2022-07-15 17:30:41487 LOG(WARNING) << "crbug.com/1339004 : authentication complete";
Istvan Nagy16b2f0822023-11-24 16:11:59488 SetAuthenticationStage(AuthenticationStage::kUserCallback);
Arthur Sonzognia98e4432023-11-28 18:15:01489 std::move(callback).Run(std::make_optional<bool>(success));
Denis Kuznetsova22f07d2022-07-15 17:30:41490 LOG(WARNING) << "crbug.com/1339004 : triggered callback";
Istvan Nagy16b2f0822023-11-24 16:11:59491 SetAuthenticationStage(AuthenticationStage::kIdle);
Fabian Sommer4e0fc3d2020-02-27 14:16:33492
493 // During smart card login flow, multiple security token requests can be made.
494 // If the user cancels one, all others should also be canceled.
495 // At this point, the flow is ending and new security token requests are
496 // displayed again.
497 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42498}
499
Jacob Dufaultcbc1ee02018-02-28 18:38:54500void LoginScreenController::OnShow() {
501 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17502 if (authentication_stage_ != AuthenticationStage::kIdle) {
503 AuthenticationStage authentication_stage = authentication_stage_;
504 base::debug::Alias(&authentication_stage);
505 LOG(FATAL) << "Unexpected authentication stage "
506 << static_cast<int>(authentication_stage_);
507 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54508}
509
Jun Mukai5c7b5b42018-11-30 00:08:50510void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02511 if (!client_) {
Jun Mukai5c7b5b42018-11-30 00:08:50512 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02513 }
Evan Stade2e4c22e2019-06-07 02:13:55514 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50515}
516
Akihiro Otab3543e32021-04-07 18:24:56517void LoginScreenController::OnSystemTrayBubbleShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02518 if (!client_) {
Akihiro Otab3543e32021-04-07 18:24:56519 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02520 }
Akihiro Otab3543e32021-04-07 18:24:56521 client_->OnSystemTrayBubbleShown();
522}
523
Roman Sorokin16faa372021-03-09 16:17:57524void LoginScreenController::OnLockScreenDestroyed() {
Eriko Kurimoto2cc98342023-08-04 04:23:31525 // TODO(b/280250064): Make sure allowing this condition won't break
526 // LoginScreenController logic.
527 if (authentication_stage_ != AuthenticationStage::kIdle) {
528 LOG(WARNING) << "Lock screen is destroyed while the authentication stage: "
529 << authentication_stage_;
530 }
Roman Sorokin16faa372021-03-09 16:17:57531
Edman Anjos4f04c3d82024-01-25 15:38:09532 // Dismiss the toast created by `ShowKioskAppError`, if any.
Edman Anjos82d376f2024-01-04 10:26:15533 Shell::Get()->toast_manager()->Cancel(kKioskToastId);
534
Roman Sorokin16faa372021-03-09 16:17:57535 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
Istvan Nagy16b2f0822023-11-24 16:11:59536 SetAuthenticationStage(AuthenticationStage::kIdle);
Alex Newcomer9f730e292021-04-01 21:46:15537 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57538}
539
Thomas Tellier0389c242020-08-27 11:44:45540void LoginScreenController::NotifyLoginScreenShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02541 if (!client_) {
Thomas Tellier0389c242020-08-27 11:44:45542 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02543 }
Thomas Tellier0389c242020-08-27 11:44:45544 client_->OnLoginScreenShown();
545}
546
Istvan Nagy16b2f0822023-11-24 16:11:59547std::ostream& operator<<(std::ostream& ostream, AuthenticationStage stage) {
Eriko Kurimoto2cc98342023-08-04 04:23:31548 switch (stage) {
Istvan Nagy16b2f0822023-11-24 16:11:59549 case AuthenticationStage::kIdle:
Eriko Kurimoto2cc98342023-08-04 04:23:31550 return ostream << "kIdle";
Istvan Nagy16b2f0822023-11-24 16:11:59551 case AuthenticationStage::kDoAuthenticate:
Eriko Kurimoto2cc98342023-08-04 04:23:31552 return ostream << "kDoAuthenticate";
Istvan Nagy16b2f0822023-11-24 16:11:59553 case AuthenticationStage::kUserCallback:
Eriko Kurimoto2cc98342023-08-04 04:23:31554 return ostream << "kUserCallback";
555 }
556}
557
xiaoyinh2bbdd102017-05-18 23:29:42558} // namespace ash