[go: nahoru, domu]

blob: ee062bcb1ee66d2a26f888522104bc73c3918c36 [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.
329 if (features::IsUseLoginShelfWidgetEnabled()) {
330 LoginShelfWidget* login_shelf_widget = shelf->login_shelf_widget();
331 login_shelf_widget->SetDefaultLastFocusableChild(reverse);
332 Shell::Get()->focus_cycler()->FocusWidget(login_shelf_widget);
333 } else {
334 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
335 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
336 }
Danila Kuzmin35f80082020-11-25 12:26:17337 } else {
338 // No elements to focus on the shelf.
Martin Bidlingmaier07420b52023-06-12 07:45:05339 //
340 // TODO(b/261774910): This is reachable apparently.
341 // Reaching this and not doing anything probably means that no view element
342 // is focused, but this is preferable to crashing via NOTREACHED().
343 base::debug::DumpWithoutCrashing();
Evan Stade9fe9cbe2019-06-03 23:05:55344 }
345}
346
347bool LoginScreenController::IsReadyForPassword() {
348 return LockScreen::HasInstance() && !IsAuthenticating();
349}
350
351void LoginScreenController::EnableAddUserButton(bool enable) {
352 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
353 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18354 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55355 ->SetAddUserButtonEnabled(enable);
356}
357
358void LoginScreenController::EnableShutdownButton(bool enable) {
359 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
360 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18361 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55362 ->SetShutdownButtonEnabled(enable);
363}
364
Yunke Zhou9319aab2020-12-01 07:34:42365void LoginScreenController::EnableShelfButtons(bool enable) {
366 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
367 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18368 ->GetLoginShelfView()
Yunke Zhou9319aab2020-12-01 07:34:42369 ->SetButtonEnabled(enable);
370}
371
Ossama Mahmouda06399d2020-10-05 12:25:34372void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34373 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
374 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18375 ->GetLoginShelfView()
Ossama Mahmouda06399d2020-10-05 12:25:34376 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34377}
378
379void LoginScreenController::ShowParentAccessButton(bool show) {
380 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
381 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18382 ->GetLoginShelfView()
Evan Stade98b718e2019-06-03 17:15:34383 ->ShowParentAccessButton(show);
384}
385
Evan Stade9fe9cbe2019-06-03 23:05:55386void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
387 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
388 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18389 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55390 ->SetAllowLoginAsGuest(allow_guest);
391}
392
Alexander Alekseev7020c6b52019-07-25 03:25:48393std::unique_ptr<ScopedGuestButtonBlocker>
394LoginScreenController::GetScopedGuestButtonBlocker() {
395 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
396 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18397 ->GetLoginShelfView()
Alexander Alekseev7020c6b52019-07-25 03:25:48398 ->GetScopedGuestButtonBlocker();
399}
400
Maksim Ivanovdbd9ade72019-08-09 15:34:16401void LoginScreenController::RequestSecurityTokenPin(
402 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33403 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16404}
405
406void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33407 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16408}
409
Danila Kuzmin1546b88e2022-02-07 12:12:35410views::Widget* LoginScreenController::GetLoginWindowWidget() {
411 return client_ ? client_->GetLoginWindowWidget() : nullptr;
412}
413
Evan Stade2e4c22e2019-06-07 02:13:55414void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57415 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47416 OnShow();
Evan Stade98b718e2019-06-03 17:15:34417 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47418}
419
Evan Stade2e4c22e2019-06-07 02:13:55420void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57421 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47422 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39423 session_manager::SessionState session_state =
424 Shell::Get()->session_controller()->GetSessionState();
425 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
426 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55427 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39428 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47429
430 OnShow();
Evan Stade98b718e2019-06-03 17:15:34431 // TODO(jdufault): rename LockScreen to LoginScreen.
432 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47433}
434
Evan Stade9c07ab42019-05-13 21:21:56435void LoginScreenController::SetKioskApps(
Sherri Lin51944b6f2022-04-21 21:32:53436 const std::vector<KioskAppMenuEntry>& kiosk_apps) {
437 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
438 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18439 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53440 ->SetKioskApps(kiosk_apps);
441}
442
443void LoginScreenController::ConfigureKioskCallbacks(
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25444 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
445 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56446 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
447 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18448 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53449 ->ConfigureKioskCallbacks(launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56450}
451
Istvan Nagy16b2f0822023-11-24 16:11:59452void LoginScreenController::SetAuthenticationStage(
453 AuthenticationStage authentication_stage) {
454 if (authentication_stage == authentication_stage_) {
455 return;
456 }
457 authentication_stage_ = authentication_stage;
458 login_data_dispatcher_.AuthenticationStageChange(authentication_stage);
459}
460
Denis Kuznetsovad5a97c2020-07-09 10:45:35461void LoginScreenController::HandleAccelerator(
462 ash::LoginAcceleratorAction action) {
Denis Kuznetsov29772ae2022-12-23 15:17:02463 if (!client_) {
Denis Kuznetsovad5a97c2020-07-09 10:45:35464 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02465 }
Denis Kuznetsovad5a97c2020-07-09 10:45:35466 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44467}
468
Roman Sorokin925cddec2020-01-23 08:19:02469void LoginScreenController::ShowAccountAccessHelpApp(
470 gfx::NativeWindow parent_window) {
471 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11472}
473
Courtney Wong45cfc9fa62021-06-30 22:08:05474void LoginScreenController::ShowParentAccessHelpApp() {
475 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27476}
477
Evan Stade3c971bc2019-06-11 22:12:44478void LoginScreenController::ShowLockScreenNotificationSettings() {
479 client_->ShowLockScreenNotificationSettings();
480}
481
Quan Nguyen3d7a0f02018-09-04 23:53:55482void LoginScreenController::FocusOobeDialog() {
Denis Kuznetsov29772ae2022-12-23 15:17:02483 if (!client_) {
Tony de Luna46801932019-03-11 18:02:01484 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02485 }
Evan Stade2e4c22e2019-06-07 02:13:55486 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55487}
488
Jacob Dufaultb7a2d842017-12-01 23:21:15489void LoginScreenController::OnAuthenticateComplete(
490 OnAuthenticateCallback callback,
491 bool success) {
Denis Kuznetsova22f07d2022-07-15 17:30:41492 LOG(WARNING) << "crbug.com/1339004 : authentication complete";
Istvan Nagy16b2f0822023-11-24 16:11:59493 SetAuthenticationStage(AuthenticationStage::kUserCallback);
Arthur Sonzognia98e4432023-11-28 18:15:01494 std::move(callback).Run(std::make_optional<bool>(success));
Denis Kuznetsova22f07d2022-07-15 17:30:41495 LOG(WARNING) << "crbug.com/1339004 : triggered callback";
Istvan Nagy16b2f0822023-11-24 16:11:59496 SetAuthenticationStage(AuthenticationStage::kIdle);
Fabian Sommer4e0fc3d2020-02-27 14:16:33497
498 // During smart card login flow, multiple security token requests can be made.
499 // If the user cancels one, all others should also be canceled.
500 // At this point, the flow is ending and new security token requests are
501 // displayed again.
502 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42503}
504
Jacob Dufaultcbc1ee02018-02-28 18:38:54505void LoginScreenController::OnShow() {
506 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17507 if (authentication_stage_ != AuthenticationStage::kIdle) {
508 AuthenticationStage authentication_stage = authentication_stage_;
509 base::debug::Alias(&authentication_stage);
510 LOG(FATAL) << "Unexpected authentication stage "
511 << static_cast<int>(authentication_stage_);
512 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54513}
514
Jun Mukai5c7b5b42018-11-30 00:08:50515void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02516 if (!client_) {
Jun Mukai5c7b5b42018-11-30 00:08:50517 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02518 }
Evan Stade2e4c22e2019-06-07 02:13:55519 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50520}
521
Akihiro Otab3543e32021-04-07 18:24:56522void LoginScreenController::OnSystemTrayBubbleShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02523 if (!client_) {
Akihiro Otab3543e32021-04-07 18:24:56524 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02525 }
Akihiro Otab3543e32021-04-07 18:24:56526 client_->OnSystemTrayBubbleShown();
527}
528
Roman Sorokin16faa372021-03-09 16:17:57529void LoginScreenController::OnLockScreenDestroyed() {
Eriko Kurimoto2cc98342023-08-04 04:23:31530 // TODO(b/280250064): Make sure allowing this condition won't break
531 // LoginScreenController logic.
532 if (authentication_stage_ != AuthenticationStage::kIdle) {
533 LOG(WARNING) << "Lock screen is destroyed while the authentication stage: "
534 << authentication_stage_;
535 }
Roman Sorokin16faa372021-03-09 16:17:57536
Edman Anjos4f04c3d82024-01-25 15:38:09537 // Dismiss the toast created by `ShowKioskAppError`, if any.
Edman Anjos82d376f2024-01-04 10:26:15538 Shell::Get()->toast_manager()->Cancel(kKioskToastId);
539
Roman Sorokin16faa372021-03-09 16:17:57540 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
Istvan Nagy16b2f0822023-11-24 16:11:59541 SetAuthenticationStage(AuthenticationStage::kIdle);
Alex Newcomer9f730e292021-04-01 21:46:15542 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57543}
544
Thomas Tellier0389c242020-08-27 11:44:45545void LoginScreenController::NotifyLoginScreenShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02546 if (!client_) {
Thomas Tellier0389c242020-08-27 11:44:45547 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02548 }
Thomas Tellier0389c242020-08-27 11:44:45549 client_->OnLoginScreenShown();
550}
551
Istvan Nagy16b2f0822023-11-24 16:11:59552std::ostream& operator<<(std::ostream& ostream, AuthenticationStage stage) {
Eriko Kurimoto2cc98342023-08-04 04:23:31553 switch (stage) {
Istvan Nagy16b2f0822023-11-24 16:11:59554 case AuthenticationStage::kIdle:
Eriko Kurimoto2cc98342023-08-04 04:23:31555 return ostream << "kIdle";
Istvan Nagy16b2f0822023-11-24 16:11:59556 case AuthenticationStage::kDoAuthenticate:
Eriko Kurimoto2cc98342023-08-04 04:23:31557 return ostream << "kDoAuthenticate";
Istvan Nagy16b2f0822023-11-24 16:11:59558 case AuthenticationStage::kUserCallback:
Eriko Kurimoto2cc98342023-08-04 04:23:31559 return ostream << "kUserCallback";
560 }
561}
562
xiaoyinh2bbdd102017-05-18 23:29:42563} // namespace ash