[go: nahoru, domu]

blob: 8cbd71f0495a0886dcd4453e5a64477340b88e3f [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"
Avi Drissman4de6dab2023-01-06 23:17:3530#include "base/functional/bind.h"
31#include "base/functional/callback.h"
Renato Silva0c0e1bb2019-09-11 13:04:1732#include "base/strings/string_util.h"
Jialiu Linf99b788b2018-01-17 23:01:2133#include "base/strings/utf_string_conversions.h"
Sean Mahere672a662023-01-09 21:42:2834#include "base/task/single_thread_task_runner.h"
Roman Sorokin5d610382022-04-05 08:30:5835#include "components/account_id/account_id.h"
Sarah Hu069eea12017-09-08 01:28:4036#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0937#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4238
39namespace ash {
40
Sarah Hu069eea12017-09-08 01:28:4041namespace {
xiaoyinh2bbdd102017-05-18 23:29:4242
Aga Wronskaa844cdcd12018-01-29 16:06:4443enum class SystemTrayVisibility {
44 kNone, // Tray not visible anywhere.
45 kPrimary, // Tray visible only on primary display.
46 kAll, // Tray visible on all displays.
47};
48
49void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
50 RootWindowController* primary_window_controller =
51 Shell::GetPrimaryRootWindowController();
52 for (RootWindowController* window_controller :
53 Shell::GetAllRootWindowControllers()) {
54 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
Denis Kuznetsov29772ae2022-12-23 15:17:0255 if (!status_area) {
Aga Wronskaa844cdcd12018-01-29 16:06:4456 continue;
Denis Kuznetsov29772ae2022-12-23 15:17:0257 }
Aga Wronskaa844cdcd12018-01-29 16:06:4458 if (window_controller == primary_window_controller) {
59 status_area->SetSystemTrayVisibility(
60 visibility == SystemTrayVisibility::kPrimary ||
61 visibility == SystemTrayVisibility::kAll);
62 } else {
63 status_area->SetSystemTrayVisibility(visibility ==
64 SystemTrayVisibility::kAll);
65 }
66 }
Aga Wronska16abb432018-01-11 23:49:5967}
68
Sarah Hu069eea12017-09-08 01:28:4069} // namespace
70
Jun Mukai5c7b5b42018-11-30 00:08:5071LoginScreenController::LoginScreenController(
72 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0073 : system_tray_notifier_(system_tray_notifier) {
Akihiro Otab3543e32021-04-07 18:24:5674 system_tray_notifier_->AddSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5075}
James Cook8f1e6062017-11-13 23:40:5976
Jun Mukai5c7b5b42018-11-30 00:08:5077LoginScreenController::~LoginScreenController() {
Akihiro Otab3543e32021-04-07 18:24:5678 system_tray_notifier_->RemoveSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5079}
xiaoyinh2bbdd102017-05-18 23:29:4280
Sarah Hu069eea12017-09-08 01:28:4081// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1682void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
83 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4084 if (for_test) {
85 // There is no remote pref service, so pretend that ash owns the pref.
86 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
87 return;
88 }
Sarah Hu069eea12017-09-08 01:28:4089}
90
Jacob Dufault2ca8c502018-06-25 19:12:1491bool LoginScreenController::IsAuthenticating() const {
92 return authentication_stage_ != AuthenticationStage::kIdle;
93}
94
Jacob Dufault2d20ae62018-09-20 22:19:5295void LoginScreenController::AuthenticateUserWithPasswordOrPin(
96 const AccountId& account_id,
97 const std::string& password,
98 bool authenticated_by_pin,
99 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:43100 // It is an error to call this function while an authentication is in
101 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:52102 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:56103 << "Duplicate authentication attempt; current authentication stage is "
104 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:43105
Evan Stade2e4c22e2019-06-07 02:13:55106 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33107 std::move(callback).Run(absl::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32108 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15109 }
xiaoyinh9f6fa0e2017-06-07 19:22:32110
Jacob Dufaulteafc6fe2017-10-11 21:16:52111 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
112 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24113 switch (force_fail_auth_for_debug_overlay_) {
114 case ForceFailAuth::kOff:
115 break;
116 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15117 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24118 return;
119 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14120 // Set a dummy authentication stage so that |IsAuthenticating| returns
121 // true.
Denis Kuznetsova22f07d2022-07-15 17:30:41122 LOG(WARNING) << "crbug.com/1339004 : Dummy auth state";
Jacob Dufault2ca8c502018-06-25 19:12:14123 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Sean Maher5b9af51f2022-11-21 15:32:47124 base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15125 FROM_HERE,
126 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11127 weak_factory_.GetWeakPtr(), std::move(callback),
Jacob Dufaultb7a2d842017-12-01 23:21:15128 false),
Peter Kastinge5a38ed2021-10-02 03:06:35129 base::Seconds(1));
Jacob Dufault0fbed9c02017-11-14 19:22:24130 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52131 }
132
Denis Kuznetsova22f07d2022-07-15 17:30:41133 LOG(WARNING) << "crbug.com/1339004 : started authentication";
Quan Nguyenf5224352018-11-06 02:03:34134 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
135
Denis Kuznetsov29772ae2022-12-23 15:17:02136 if (authenticated_by_pin) {
Yunke Zhouf819ab92022-10-27 18:25:32137 DCHECK(base::ContainsOnlyChars(password, "0123456789"));
Denis Kuznetsov29772ae2022-12-23 15:17:02138 }
Yunke Zhouf819ab92022-10-27 18:25:32139
Evan Stade2e4c22e2019-06-07 02:13:55140 client_->AuthenticateUserWithPasswordOrPin(
Yunke Zhouf819ab92022-10-27 18:25:32141 account_id, password, authenticated_by_pin,
Quan Nguyenf5224352018-11-06 02:03:34142 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11143 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32144}
145
Jacob Dufault2d20ae62018-09-20 22:19:52146void LoginScreenController::AuthenticateUserWithEasyUnlock(
147 const AccountId& account_id) {
148 // TODO(jdufault): integrate this into authenticate stage after mojom is
149 // refactored to use a callback.
Denis Kuznetsov29772ae2022-12-23 15:17:02150 if (!client_) {
xiaoyinh9f6fa0e2017-06-07 19:22:32151 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02152 }
Evan Stade2e4c22e2019-06-07 02:13:55153 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32154}
155
Maksim Ivanov675dd762019-07-29 18:31:10156void LoginScreenController::AuthenticateUserWithChallengeResponse(
157 const AccountId& account_id,
158 OnAuthenticateCallback callback) {
159 LOG_IF(FATAL, IsAuthenticating())
160 << "Duplicate authentication attempt; current authentication stage is "
161 << static_cast<int>(authentication_stage_);
162
163 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33164 std::move(callback).Run(/*success=*/absl::nullopt);
Maksim Ivanov675dd762019-07-29 18:31:10165 return;
166 }
167
168 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
169 client_->AuthenticateUserWithChallengeResponse(
170 account_id,
171 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
172 weak_factory_.GetWeakPtr(), std::move(callback)));
173}
174
Aga Wronska660503d2021-03-24 03:21:11175ParentCodeValidationResult LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17176 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05177 base::Time validation_time,
178 const std::string& code) {
179 DCHECK(!validation_time.is_null());
180
Denis Kuznetsov29772ae2022-12-23 15:17:02181 if (!client_) {
Aga Wronska660503d2021-03-24 03:21:11182 return ParentCodeValidationResult::kInternalError;
Denis Kuznetsov29772ae2022-12-23 15:17:02183 }
Aga Wronskaac6cf362019-02-26 21:36:55184
Henrique Grandinetti914c34b62019-08-12 14:03:19185 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55186}
187
Fabian Sommer4e0fc3d2020-02-27 14:16:33188bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
189 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45190}
191
Jacob Dufaultffd9b0d2017-11-15 23:07:16192void LoginScreenController::HardlockPod(const AccountId& account_id) {
Roman Sorokin5d610382022-04-05 08:30:58193 GetModel()->NotifyFocusPod(account_id);
Denis Kuznetsov29772ae2022-12-23 15:17:02194 if (!client_) {
xiaoyinh9f6fa0e2017-06-07 19:22:32195 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02196 }
Evan Stade2e4c22e2019-06-07 02:13:55197 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32198}
199
Jacob Dufaultffd9b0d2017-11-15 23:07:16200void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Roman Sorokin5d610382022-04-05 08:30:58201 GetModel()->NotifyFocusPod(account_id);
Denis Kuznetsov29772ae2022-12-23 15:17:02202 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27203 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02204 }
Evan Stade2e4c22e2019-06-07 02:13:55205 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27206}
207
Jacob Dufaultffd9b0d2017-11-15 23:07:16208void LoginScreenController::OnNoPodFocused() {
Roman Sorokin5d610382022-04-05 08:30:58209 GetModel()->NotifyFocusPod(EmptyAccountId());
Denis Kuznetsov29772ae2022-12-23 15:17:02210 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27211 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02212 }
Evan Stade2e4c22e2019-06-07 02:13:55213 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27214}
215
Jacob Dufaultffd9b0d2017-11-15 23:07:16216void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02217 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27218 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02219 }
Evan Stade2e4c22e2019-06-07 02:13:55220 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27221}
222
Jacob Dufaultffd9b0d2017-11-15 23:07:16223void LoginScreenController::SignOutUser() {
Denis Kuznetsov29772ae2022-12-23 15:17:02224 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27225 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02226 }
Evan Stade2e4c22e2019-06-07 02:13:55227 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27228}
229
Jacob Dufaultffd9b0d2017-11-15 23:07:16230void LoginScreenController::CancelAddUser() {
Denis Kuznetsov29772ae2022-12-23 15:17:02231 if (!client_) {
Wenzhao Zang16e7ea722017-09-16 01:27:30232 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02233 }
Evan Stade2e4c22e2019-06-07 02:13:55234 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30235}
236
Aga Wronska6a32f9872018-01-06 00:16:10237void LoginScreenController::LoginAsGuest() {
Denis Kuznetsov29772ae2022-12-23 15:17:02238 if (!client_) {
Aga Wronska6a32f9872018-01-06 00:16:10239 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02240 }
Evan Stade2e4c22e2019-06-07 02:13:55241 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10242}
243
Ossama Mahmoud8fa195f2021-09-30 19:51:25244void LoginScreenController::ShowGuestTosScreen() {
Denis Kuznetsov29772ae2022-12-23 15:17:02245 if (!client_) {
Ossama Mahmoud8fa195f2021-09-30 19:51:25246 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02247 }
Ossama Mahmoud8fa195f2021-09-30 19:51:25248 client_->ShowGuestTosScreen();
249}
250
Jacob Dufaultffd9b0d2017-11-15 23:07:16251void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27252 const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02253 if (!client_) {
xiaoyinhf534c4f2017-06-13 20:50:27254 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02255 }
Evan Stade2e4c22e2019-06-07 02:13:55256 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27257}
258
Jacob Dufaultffd9b0d2017-11-15 23:07:16259void LoginScreenController::FocusLockScreenApps(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02260 if (!client_) {
Toni Barzicf61c4452017-10-05 03:57:48261 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02262 }
Evan Stade2e4c22e2019-06-07 02:13:55263 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48264}
265
Roman Sorokin26d7e9662020-02-24 17:52:18266void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Denis Kuznetsov29772ae2022-12-23 15:17:02267 if (!client_) {
Sarah Hu9fba0e752018-02-07 01:41:09268 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02269 }
Roman Sorokin26d7e9662020-02-24 17:52:18270 client_->ShowGaiaSignin(prefilled_account);
271}
272
Ossama Mahmoud95164772021-06-30 14:18:14273void LoginScreenController::ShowOsInstallScreen() {
Denis Kuznetsov29772ae2022-12-23 15:17:02274 if (!client_) {
Ossama Mahmoud95164772021-06-30 14:18:14275 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02276 }
Ossama Mahmoud95164772021-06-30 14:18:14277 client_->ShowOsInstallScreen();
278}
279
Jacob Dufaultfc31c742018-03-20 17:32:19280void LoginScreenController::OnRemoveUserWarningShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02281 if (!client_) {
Jacob Dufaultfc31c742018-03-20 17:32:19282 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02283 }
Evan Stade2e4c22e2019-06-07 02:13:55284 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19285}
286
287void LoginScreenController::RemoveUser(const AccountId& account_id) {
Denis Kuznetsov29772ae2022-12-23 15:17:02288 if (!client_) {
Jacob Dufaultfc31c742018-03-20 17:32:19289 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02290 }
Evan Stade2e4c22e2019-06-07 02:13:55291 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19292}
293
Sarah Hu3fcf9f82018-03-22 20:32:54294void LoginScreenController::LaunchPublicSession(
295 const AccountId& account_id,
296 const std::string& locale,
297 const std::string& input_method) {
Denis Kuznetsov29772ae2022-12-23 15:17:02298 if (!client_) {
Sarah Hu3fcf9f82018-03-22 20:32:54299 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02300 }
Evan Stade2e4c22e2019-06-07 02:13:55301 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54302}
303
Sarah Huf9affb122018-04-27 21:36:36304void LoginScreenController::RequestPublicSessionKeyboardLayouts(
305 const AccountId& account_id,
306 const std::string& locale) {
Denis Kuznetsov29772ae2022-12-23 15:17:02307 if (!client_) {
Sarah Huf9affb122018-04-27 21:36:36308 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02309 }
Evan Stade2e4c22e2019-06-07 02:13:55310 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36311}
312
Evan Stade2e4c22e2019-06-07 02:13:55313void LoginScreenController::SetClient(LoginScreenClient* client) {
314 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48315}
316
Evan Stadeb153f822019-05-23 19:14:43317LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31318 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43319}
320
Evan Stade9fe9cbe2019-06-03 23:05:55321void LoginScreenController::ShowKioskAppError(const std::string& message) {
Kevin Radtke11d1599e2022-01-18 21:04:11322 ToastData toast_data("KioskAppError", ToastCatalogName::kKioskAppError,
323 base::UTF8ToUTF16(message), ToastData::kInfiniteDuration,
Ben Franzef7fab22022-04-06 16:13:16324 /*visible_on_lock_screen=*/true,
Kevin Radtke9e9e6a962022-04-18 18:16:23325 /*has_dismiss_button=*/true);
Ben Beckere1807312022-11-14 20:25:08326 Shell::Get()->toast_manager()->Show(std::move(toast_data));
Evan Stade9fe9cbe2019-06-03 23:05:55327}
328
329void LoginScreenController::FocusLoginShelf(bool reverse) {
330 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
331 // Tell the focus direction to the status area or the shelf so they can focus
332 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17333 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
Andrew Xub6a52a12022-07-12 21:02:18334 (reverse || !shelf->shelf_widget()->GetLoginShelfView()->IsFocusable())) {
Danila Kuzmin35f80082020-11-25 12:26:17335 // Focus goes to system tray (status area) if one of the following is true:
336 // - system tray is visible and tab is in reverse order;
337 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55338 shelf->GetStatusAreaWidget()
339 ->status_area_widget_delegate()
340 ->set_default_last_focusable_child(reverse);
341 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Andrew Xub6a52a12022-07-12 21:02:18342 } else if (shelf->shelf_widget()->GetLoginShelfView()->IsFocusable()) {
Andrew Xu25ff1212022-08-17 20:25:11343 // Otherwise focus goes to login shelf buttons when there is any.
344 if (features::IsUseLoginShelfWidgetEnabled()) {
345 LoginShelfWidget* login_shelf_widget = shelf->login_shelf_widget();
346 login_shelf_widget->SetDefaultLastFocusableChild(reverse);
347 Shell::Get()->focus_cycler()->FocusWidget(login_shelf_widget);
348 } else {
349 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
350 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
351 }
Danila Kuzmin35f80082020-11-25 12:26:17352 } else {
353 // No elements to focus on the shelf.
354 NOTREACHED();
Evan Stade9fe9cbe2019-06-03 23:05:55355 }
356}
357
358bool LoginScreenController::IsReadyForPassword() {
359 return LockScreen::HasInstance() && !IsAuthenticating();
360}
361
362void LoginScreenController::EnableAddUserButton(bool enable) {
363 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
364 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18365 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55366 ->SetAddUserButtonEnabled(enable);
367}
368
369void LoginScreenController::EnableShutdownButton(bool enable) {
370 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
371 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18372 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55373 ->SetShutdownButtonEnabled(enable);
374}
375
Yunke Zhou9319aab2020-12-01 07:34:42376void LoginScreenController::EnableShelfButtons(bool enable) {
377 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
378 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18379 ->GetLoginShelfView()
Yunke Zhou9319aab2020-12-01 07:34:42380 ->SetButtonEnabled(enable);
381}
382
Ossama Mahmouda06399d2020-10-05 12:25:34383void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34384 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
385 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18386 ->GetLoginShelfView()
Ossama Mahmouda06399d2020-10-05 12:25:34387 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34388}
389
390void LoginScreenController::ShowParentAccessButton(bool show) {
391 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
392 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18393 ->GetLoginShelfView()
Evan Stade98b718e2019-06-03 17:15:34394 ->ShowParentAccessButton(show);
395}
396
Evan Stade9fe9cbe2019-06-03 23:05:55397void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
398 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
399 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18400 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55401 ->SetAllowLoginAsGuest(allow_guest);
402}
403
Alexander Alekseev7020c6b52019-07-25 03:25:48404std::unique_ptr<ScopedGuestButtonBlocker>
405LoginScreenController::GetScopedGuestButtonBlocker() {
406 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
407 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18408 ->GetLoginShelfView()
Alexander Alekseev7020c6b52019-07-25 03:25:48409 ->GetScopedGuestButtonBlocker();
410}
411
Maksim Ivanovdbd9ade72019-08-09 15:34:16412void LoginScreenController::RequestSecurityTokenPin(
413 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33414 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16415}
416
417void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33418 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16419}
420
Danila Kuzmin1546b88e2022-02-07 12:12:35421views::Widget* LoginScreenController::GetLoginWindowWidget() {
422 return client_ ? client_->GetLoginWindowWidget() : nullptr;
423}
424
Evan Stade2e4c22e2019-06-07 02:13:55425void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57426 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47427 OnShow();
Evan Stade98b718e2019-06-03 17:15:34428 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47429}
430
Evan Stade2e4c22e2019-06-07 02:13:55431void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57432 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47433 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39434 session_manager::SessionState session_state =
435 Shell::Get()->session_controller()->GetSessionState();
436 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
437 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55438 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39439 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47440
441 OnShow();
Evan Stade98b718e2019-06-03 17:15:34442 // TODO(jdufault): rename LockScreen to LoginScreen.
443 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47444}
445
Evan Stade9c07ab42019-05-13 21:21:56446void LoginScreenController::SetKioskApps(
Sherri Lin51944b6f2022-04-21 21:32:53447 const std::vector<KioskAppMenuEntry>& kiosk_apps) {
448 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
449 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18450 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53451 ->SetKioskApps(kiosk_apps);
452}
453
454void LoginScreenController::ConfigureKioskCallbacks(
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25455 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
456 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56457 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
458 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18459 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53460 ->ConfigureKioskCallbacks(launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56461}
462
Denis Kuznetsovad5a97c2020-07-09 10:45:35463void LoginScreenController::HandleAccelerator(
464 ash::LoginAcceleratorAction action) {
Denis Kuznetsov29772ae2022-12-23 15:17:02465 if (!client_) {
Denis Kuznetsovad5a97c2020-07-09 10:45:35466 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02467 }
Denis Kuznetsovad5a97c2020-07-09 10:45:35468 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44469}
470
Roman Sorokin925cddec2020-01-23 08:19:02471void LoginScreenController::ShowAccountAccessHelpApp(
472 gfx::NativeWindow parent_window) {
473 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11474}
475
Courtney Wong45cfc9fa62021-06-30 22:08:05476void LoginScreenController::ShowParentAccessHelpApp() {
477 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27478}
479
Evan Stade3c971bc2019-06-11 22:12:44480void LoginScreenController::ShowLockScreenNotificationSettings() {
481 client_->ShowLockScreenNotificationSettings();
482}
483
Quan Nguyen3d7a0f02018-09-04 23:53:55484void LoginScreenController::FocusOobeDialog() {
Denis Kuznetsov29772ae2022-12-23 15:17:02485 if (!client_) {
Tony de Luna46801932019-03-11 18:02:01486 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02487 }
Evan Stade2e4c22e2019-06-07 02:13:55488 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55489}
490
Quan Nguyene377eb62019-02-11 23:02:25491void LoginScreenController::NotifyUserActivity() {
Denis Kuznetsov29772ae2022-12-23 15:17:02492 if (!client_) {
Xiyuan Xia5a8c4172019-05-13 16:23:48493 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02494 }
Evan Stade2e4c22e2019-06-07 02:13:55495 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25496}
497
Jacob Dufaultb7a2d842017-12-01 23:21:15498void LoginScreenController::OnAuthenticateComplete(
499 OnAuthenticateCallback callback,
500 bool success) {
Denis Kuznetsova22f07d2022-07-15 17:30:41501 LOG(WARNING) << "crbug.com/1339004 : authentication complete";
Jacob Dufault8876ba82018-03-27 22:55:43502 authentication_stage_ = AuthenticationStage::kUserCallback;
Anton Bikineev43cee28e2021-05-14 23:35:33503 std::move(callback).Run(absl::make_optional<bool>(success));
Denis Kuznetsova22f07d2022-07-15 17:30:41504 LOG(WARNING) << "crbug.com/1339004 : triggered callback";
Jacob Dufault8876ba82018-03-27 22:55:43505 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33506
507 // During smart card login flow, multiple security token requests can be made.
508 // If the user cancels one, all others should also be canceled.
509 // At this point, the flow is ending and new security token requests are
510 // displayed again.
511 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42512}
513
Jacob Dufaultcbc1ee02018-02-28 18:38:54514void LoginScreenController::OnShow() {
515 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17516 if (authentication_stage_ != AuthenticationStage::kIdle) {
517 AuthenticationStage authentication_stage = authentication_stage_;
518 base::debug::Alias(&authentication_stage);
519 LOG(FATAL) << "Unexpected authentication stage "
520 << static_cast<int>(authentication_stage_);
521 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54522}
523
Jun Mukai5c7b5b42018-11-30 00:08:50524void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Denis Kuznetsov29772ae2022-12-23 15:17:02525 if (!client_) {
Jun Mukai5c7b5b42018-11-30 00:08:50526 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02527 }
Evan Stade2e4c22e2019-06-07 02:13:55528 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50529}
530
Akihiro Otab3543e32021-04-07 18:24:56531void LoginScreenController::OnSystemTrayBubbleShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02532 if (!client_) {
Akihiro Otab3543e32021-04-07 18:24:56533 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02534 }
Akihiro Otab3543e32021-04-07 18:24:56535 client_->OnSystemTrayBubbleShown();
536}
537
Roman Sorokin16faa372021-03-09 16:17:57538void LoginScreenController::OnLockScreenDestroyed() {
539 DCHECK_EQ(authentication_stage_, AuthenticationStage::kIdle);
540
541 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
542 authentication_stage_ = AuthenticationStage::kIdle;
Alex Newcomer9f730e292021-04-01 21:46:15543 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57544}
545
Thomas Tellier0389c242020-08-27 11:44:45546void LoginScreenController::NotifyLoginScreenShown() {
Denis Kuznetsov29772ae2022-12-23 15:17:02547 if (!client_) {
Thomas Tellier0389c242020-08-27 11:44:45548 return;
Denis Kuznetsov29772ae2022-12-23 15:17:02549 }
Thomas Tellier0389c242020-08-27 11:44:45550 client_->OnLoginScreenShown();
551}
552
xiaoyinh2bbdd102017-05-18 23:29:42553} // namespace ash