[go: nahoru, domu]

blob: 671ec86b68abe85e164ee1594fd8e47c4854bf9c [file] [log] [blame]
xiaoyinh2bbdd102017-05-18 23:29:421// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Jacob Dufaultffd9b0d2017-11-15 23:07:165#include "ash/login/login_screen_controller.h"
xiaoyinh2bbdd102017-05-18 23:29:426
Quan Nguyen92f924a2018-10-18 18:36:467#include <utility>
8
Quan Nguyen3d7a0f02018-09-04 23:53:559#include "ash/focus_cycler.h"
Fabian Sommer4e0fc3d2020-02-27 14:16:3310#include "ash/login/security_token_request_controller.h"
jdufaulteb4c9f1e2017-06-08 23:08:3011#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5312#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4013#include "ash/public/cpp/ash_pref_names.h"
Aga Wronska660503d2021-03-24 03:21:1114#include "ash/public/cpp/child_accounts/parent_access_controller.h"
Evan Stade2e4c22e2019-06-07 02:13:5515#include "ash/public/cpp/login_screen_client.h"
Anastasiia Nikolaienko94f9f7d2019-06-11 08:12:0716#include "ash/public/cpp/toast_data.h"
Aga Wronska16abb432018-01-11 23:49:5917#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1818#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3019#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3220#include "ash/shelf/shelf.h"
21#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4022#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5923#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5524#include "ash/system/status_area_widget_delegate.h"
Anastasiia Nikolaienko8cdd7e62019-06-12 12:16:2425#include "ash/system/toast/toast_manager_impl.h"
Jun Mukai5c7b5b42018-11-30 00:08:5026#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4627#include "base/bind.h"
Maksim Ivanovdbd9ade72019-08-09 15:34:1628#include "base/callback.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1729#include "base/debug/alias.h"
Renato Silva0c0e1bb2019-09-11 13:04:1730#include "base/strings/string_util.h"
Jialiu Linf99b788b2018-01-17 23:01:2131#include "base/strings/utf_string_conversions.h"
Sarah Hu069eea12017-09-08 01:28:4032#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0933#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4234
35namespace ash {
36
Sarah Hu069eea12017-09-08 01:28:4037namespace {
xiaoyinh2bbdd102017-05-18 23:29:4238
Aga Wronskaa844cdcd12018-01-29 16:06:4439enum class SystemTrayVisibility {
40 kNone, // Tray not visible anywhere.
41 kPrimary, // Tray visible only on primary display.
42 kAll, // Tray visible on all displays.
43};
44
45void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
46 RootWindowController* primary_window_controller =
47 Shell::GetPrimaryRootWindowController();
48 for (RootWindowController* window_controller :
49 Shell::GetAllRootWindowControllers()) {
50 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
51 if (!status_area)
52 continue;
53 if (window_controller == primary_window_controller) {
54 status_area->SetSystemTrayVisibility(
55 visibility == SystemTrayVisibility::kPrimary ||
56 visibility == SystemTrayVisibility::kAll);
57 } else {
58 status_area->SetSystemTrayVisibility(visibility ==
59 SystemTrayVisibility::kAll);
60 }
61 }
Aga Wronska16abb432018-01-11 23:49:5962}
63
Sarah Hu069eea12017-09-08 01:28:4064} // namespace
65
Jun Mukai5c7b5b42018-11-30 00:08:5066LoginScreenController::LoginScreenController(
67 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0068 : system_tray_notifier_(system_tray_notifier) {
Akihiro Otab3543e32021-04-07 18:24:5669 system_tray_notifier_->AddSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5070}
James Cook8f1e6062017-11-13 23:40:5971
Jun Mukai5c7b5b42018-11-30 00:08:5072LoginScreenController::~LoginScreenController() {
Akihiro Otab3543e32021-04-07 18:24:5673 system_tray_notifier_->RemoveSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5074}
xiaoyinh2bbdd102017-05-18 23:29:4275
Sarah Hu069eea12017-09-08 01:28:4076// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1677void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
78 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4079 if (for_test) {
80 // There is no remote pref service, so pretend that ash owns the pref.
81 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
82 return;
83 }
Sarah Hu069eea12017-09-08 01:28:4084}
85
Jacob Dufault2ca8c502018-06-25 19:12:1486bool LoginScreenController::IsAuthenticating() const {
87 return authentication_stage_ != AuthenticationStage::kIdle;
88}
89
Jacob Dufault2d20ae62018-09-20 22:19:5290void LoginScreenController::AuthenticateUserWithPasswordOrPin(
91 const AccountId& account_id,
92 const std::string& password,
93 bool authenticated_by_pin,
94 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4395 // It is an error to call this function while an authentication is in
96 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:5297 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:5698 << "Duplicate authentication attempt; current authentication stage is "
99 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:43100
Evan Stade2e4c22e2019-06-07 02:13:55101 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33102 std::move(callback).Run(absl::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32103 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15104 }
xiaoyinh9f6fa0e2017-06-07 19:22:32105
Jacob Dufaulteafc6fe2017-10-11 21:16:52106 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
107 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24108 switch (force_fail_auth_for_debug_overlay_) {
109 case ForceFailAuth::kOff:
110 break;
111 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15112 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24113 return;
114 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14115 // Set a dummy authentication stage so that |IsAuthenticating| returns
116 // true.
117 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24118 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15119 FROM_HERE,
120 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11121 weak_factory_.GetWeakPtr(), std::move(callback),
Jacob Dufaultb7a2d842017-12-01 23:21:15122 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24123 base::TimeDelta::FromSeconds(1));
124 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52125 }
126
Quan Nguyenf5224352018-11-06 02:03:34127 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
128
Renato Silva0c0e1bb2019-09-11 13:04:17129 // Checking if the password is only formed of numbers with base::StringToInt
130 // will easily fail due to numeric limits. ContainsOnlyChars is used instead.
131 const bool is_pin =
132 authenticated_by_pin && base::ContainsOnlyChars(password, "0123456789");
Evan Stade2e4c22e2019-06-07 02:13:55133 client_->AuthenticateUserWithPasswordOrPin(
Quan Nguyenf5224352018-11-06 02:03:34134 account_id, password, is_pin,
135 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11136 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32137}
138
Jacob Dufault2d20ae62018-09-20 22:19:52139void LoginScreenController::AuthenticateUserWithEasyUnlock(
140 const AccountId& account_id) {
141 // TODO(jdufault): integrate this into authenticate stage after mojom is
142 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55143 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32144 return;
Evan Stade2e4c22e2019-06-07 02:13:55145 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32146}
147
Maksim Ivanov675dd762019-07-29 18:31:10148void LoginScreenController::AuthenticateUserWithChallengeResponse(
149 const AccountId& account_id,
150 OnAuthenticateCallback callback) {
151 LOG_IF(FATAL, IsAuthenticating())
152 << "Duplicate authentication attempt; current authentication stage is "
153 << static_cast<int>(authentication_stage_);
154
155 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33156 std::move(callback).Run(/*success=*/absl::nullopt);
Maksim Ivanov675dd762019-07-29 18:31:10157 return;
158 }
159
160 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
161 client_->AuthenticateUserWithChallengeResponse(
162 account_id,
163 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
164 weak_factory_.GetWeakPtr(), std::move(callback)));
165}
166
Aga Wronska660503d2021-03-24 03:21:11167ParentCodeValidationResult LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17168 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05169 base::Time validation_time,
170 const std::string& code) {
171 DCHECK(!validation_time.is_null());
172
Evan Stade2e4c22e2019-06-07 02:13:55173 if (!client_)
Aga Wronska660503d2021-03-24 03:21:11174 return ParentCodeValidationResult::kInternalError;
Aga Wronskaac6cf362019-02-26 21:36:55175
Henrique Grandinetti914c34b62019-08-12 14:03:19176 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55177}
178
Fabian Sommer4e0fc3d2020-02-27 14:16:33179bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
180 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45181}
182
Jacob Dufaultffd9b0d2017-11-15 23:07:16183void LoginScreenController::HardlockPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55184 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32185 return;
Evan Stade2e4c22e2019-06-07 02:13:55186 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32187}
188
Jacob Dufaultffd9b0d2017-11-15 23:07:16189void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55190 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27191 return;
Evan Stade2e4c22e2019-06-07 02:13:55192 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27193}
194
Jacob Dufaultffd9b0d2017-11-15 23:07:16195void LoginScreenController::OnNoPodFocused() {
Evan Stade2e4c22e2019-06-07 02:13:55196 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27197 return;
Evan Stade2e4c22e2019-06-07 02:13:55198 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27199}
200
Jacob Dufaultffd9b0d2017-11-15 23:07:16201void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55202 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27203 return;
Evan Stade2e4c22e2019-06-07 02:13:55204 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27205}
206
Jacob Dufaultffd9b0d2017-11-15 23:07:16207void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55208 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27209 return;
Evan Stade2e4c22e2019-06-07 02:13:55210 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27211}
212
Jacob Dufaultffd9b0d2017-11-15 23:07:16213void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55214 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30215 return;
Evan Stade2e4c22e2019-06-07 02:13:55216 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30217}
218
Aga Wronska6a32f9872018-01-06 00:16:10219void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55220 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10221 return;
Evan Stade2e4c22e2019-06-07 02:13:55222 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10223}
224
Jacob Dufaultffd9b0d2017-11-15 23:07:16225void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27226 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55227 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27228 return;
Evan Stade2e4c22e2019-06-07 02:13:55229 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27230}
231
Jacob Dufaultffd9b0d2017-11-15 23:07:16232void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55233 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48234 return;
Evan Stade2e4c22e2019-06-07 02:13:55235 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48236}
237
Roman Sorokin26d7e9662020-02-24 17:52:18238void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Evan Stade2e4c22e2019-06-07 02:13:55239 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09240 return;
Roman Sorokin26d7e9662020-02-24 17:52:18241 client_->ShowGaiaSignin(prefilled_account);
242}
243
Ossama Mahmoud95164772021-06-30 14:18:14244void LoginScreenController::ShowOsInstallScreen() {
245 if (!client_)
246 return;
247 client_->ShowOsInstallScreen();
248}
249
Jacob Dufaultfc31c742018-03-20 17:32:19250void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55251 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19252 return;
Evan Stade2e4c22e2019-06-07 02:13:55253 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19254}
255
256void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55257 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19258 return;
Evan Stade2e4c22e2019-06-07 02:13:55259 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19260}
261
Sarah Hu3fcf9f82018-03-22 20:32:54262void LoginScreenController::LaunchPublicSession(
263 const AccountId& account_id,
264 const std::string& locale,
265 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55266 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54267 return;
Evan Stade2e4c22e2019-06-07 02:13:55268 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54269}
270
Sarah Huf9affb122018-04-27 21:36:36271void LoginScreenController::RequestPublicSessionKeyboardLayouts(
272 const AccountId& account_id,
273 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55274 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36275 return;
Evan Stade2e4c22e2019-06-07 02:13:55276 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36277}
278
Evan Stade2e4c22e2019-06-07 02:13:55279void LoginScreenController::SetClient(LoginScreenClient* client) {
280 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48281}
282
Evan Stadeb153f822019-05-23 19:14:43283LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31284 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43285}
286
Evan Stade9fe9cbe2019-06-03 23:05:55287void LoginScreenController::ShowKioskAppError(const std::string& message) {
288 ToastData toast_data(
289 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
Anton Bikineev43cee28e2021-05-14 23:35:33290 absl::optional<std::u16string>(std::u16string()) /*dismiss_text*/,
Evan Stade9fe9cbe2019-06-03 23:05:55291 true /*visible_on_lock_screen*/);
292 Shell::Get()->toast_manager()->Show(toast_data);
293}
294
295void LoginScreenController::FocusLoginShelf(bool reverse) {
296 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
297 // Tell the focus direction to the status area or the shelf so they can focus
298 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17299 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
300 (reverse || !shelf->shelf_widget()->login_shelf_view()->IsFocusable())) {
301 // Focus goes to system tray (status area) if one of the following is true:
302 // - system tray is visible and tab is in reverse order;
303 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55304 shelf->GetStatusAreaWidget()
305 ->status_area_widget_delegate()
306 ->set_default_last_focusable_child(reverse);
307 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Danila Kuzmin35f80082020-11-25 12:26:17308 } else if (shelf->shelf_widget()->login_shelf_view()->IsFocusable()) {
309 // Otherwise focus goes to shelf buttons when there is any.
Evan Stade9fe9cbe2019-06-03 23:05:55310 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
311 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
Danila Kuzmin35f80082020-11-25 12:26:17312 } else {
313 // No elements to focus on the shelf.
314 NOTREACHED();
Evan Stade9fe9cbe2019-06-03 23:05:55315 }
316}
317
318bool LoginScreenController::IsReadyForPassword() {
319 return LockScreen::HasInstance() && !IsAuthenticating();
320}
321
322void LoginScreenController::EnableAddUserButton(bool enable) {
323 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
324 ->shelf_widget()
325 ->login_shelf_view()
326 ->SetAddUserButtonEnabled(enable);
327}
328
329void LoginScreenController::EnableShutdownButton(bool enable) {
330 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
331 ->shelf_widget()
332 ->login_shelf_view()
333 ->SetShutdownButtonEnabled(enable);
334}
335
Yunke Zhou9319aab2020-12-01 07:34:42336void LoginScreenController::EnableShelfButtons(bool enable) {
337 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
338 ->shelf_widget()
339 ->login_shelf_view()
340 ->SetButtonEnabled(enable);
341}
342
Ossama Mahmouda06399d2020-10-05 12:25:34343void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34344 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
345 ->shelf_widget()
346 ->login_shelf_view()
Ossama Mahmouda06399d2020-10-05 12:25:34347 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34348}
349
350void LoginScreenController::ShowParentAccessButton(bool show) {
351 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
352 ->shelf_widget()
353 ->login_shelf_view()
354 ->ShowParentAccessButton(show);
355}
356
Evan Stade9fe9cbe2019-06-03 23:05:55357void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
358 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
359 ->shelf_widget()
360 ->login_shelf_view()
361 ->SetAllowLoginAsGuest(allow_guest);
362}
363
Alexander Alekseev7020c6b52019-07-25 03:25:48364std::unique_ptr<ScopedGuestButtonBlocker>
365LoginScreenController::GetScopedGuestButtonBlocker() {
366 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
367 ->shelf_widget()
368 ->login_shelf_view()
369 ->GetScopedGuestButtonBlocker();
370}
371
Maksim Ivanovdbd9ade72019-08-09 15:34:16372void LoginScreenController::RequestSecurityTokenPin(
373 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33374 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16375}
376
377void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33378 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16379}
Toni Barzic4ebccb502020-02-28 16:00:40380bool LoginScreenController::SetLoginShelfGestureHandler(
Jan Wilken Dörrie85285b02021-03-11 23:38:47381 const std::u16string& nudge_text,
Toni Barzic4ebccb502020-02-28 16:00:40382 const base::RepeatingClosure& fling_callback,
383 base::OnceClosure exit_callback) {
384 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
385 ->shelf_widget()
386 ->SetLoginShelfSwipeHandler(nudge_text, fling_callback,
387 std::move(exit_callback));
388}
389
390void LoginScreenController::ClearLoginShelfGestureHandler() {
391 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
392 ->shelf_widget()
393 ->ClearLoginShelfSwipeHandler();
394}
Maksim Ivanovdbd9ade72019-08-09 15:34:16395
Evan Stade2e4c22e2019-06-07 02:13:55396void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57397 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47398 OnShow();
Evan Stade98b718e2019-06-03 17:15:34399 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47400}
401
Evan Stade2e4c22e2019-06-07 02:13:55402void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57403 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47404 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39405 session_manager::SessionState session_state =
406 Shell::Get()->session_controller()->GetSessionState();
407 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
408 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55409 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39410 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47411
412 OnShow();
Evan Stade98b718e2019-06-03 17:15:34413 // TODO(jdufault): rename LockScreen to LoginScreen.
414 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47415}
416
Evan Stade9c07ab42019-05-13 21:21:56417void LoginScreenController::SetKioskApps(
418 const std::vector<KioskAppMenuEntry>& kiosk_apps,
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25419 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
420 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56421 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
422 ->shelf_widget()
423 ->login_shelf_view()
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25424 ->SetKioskApps(kiosk_apps, launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56425}
426
Denis Kuznetsovad5a97c2020-07-09 10:45:35427void LoginScreenController::HandleAccelerator(
428 ash::LoginAcceleratorAction action) {
429 if (!client_)
430 return;
431 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44432}
433
Roman Sorokin925cddec2020-01-23 08:19:02434void LoginScreenController::ShowAccountAccessHelpApp(
435 gfx::NativeWindow parent_window) {
436 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11437}
438
Courtney Wong45cfc9fa62021-06-30 22:08:05439void LoginScreenController::ShowParentAccessHelpApp() {
440 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27441}
442
Evan Stade3c971bc2019-06-11 22:12:44443void LoginScreenController::ShowLockScreenNotificationSettings() {
444 client_->ShowLockScreenNotificationSettings();
445}
446
Quan Nguyen3d7a0f02018-09-04 23:53:55447void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55448 if (!client_)
Tony de Luna46801932019-03-11 18:02:01449 return;
Evan Stade2e4c22e2019-06-07 02:13:55450 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55451}
452
Quan Nguyene377eb62019-02-11 23:02:25453void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55454 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48455 return;
Evan Stade2e4c22e2019-06-07 02:13:55456 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25457}
458
Jacob Dufaultb7a2d842017-12-01 23:21:15459void LoginScreenController::OnAuthenticateComplete(
460 OnAuthenticateCallback callback,
461 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43462 authentication_stage_ = AuthenticationStage::kUserCallback;
Anton Bikineev43cee28e2021-05-14 23:35:33463 std::move(callback).Run(absl::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43464 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33465
466 // During smart card login flow, multiple security token requests can be made.
467 // If the user cancels one, all others should also be canceled.
468 // At this point, the flow is ending and new security token requests are
469 // displayed again.
470 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42471}
472
Jacob Dufaultcbc1ee02018-02-28 18:38:54473void LoginScreenController::OnShow() {
474 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17475 if (authentication_stage_ != AuthenticationStage::kIdle) {
476 AuthenticationStage authentication_stage = authentication_stage_;
477 base::debug::Alias(&authentication_stage);
478 LOG(FATAL) << "Unexpected authentication stage "
479 << static_cast<int>(authentication_stage_);
480 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54481}
482
Jun Mukai5c7b5b42018-11-30 00:08:50483void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55484 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50485 return;
Evan Stade2e4c22e2019-06-07 02:13:55486 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50487}
488
Akihiro Otab3543e32021-04-07 18:24:56489void LoginScreenController::OnSystemTrayBubbleShown() {
490 if (!client_)
491 return;
492 client_->OnSystemTrayBubbleShown();
493}
494
Roman Sorokin16faa372021-03-09 16:17:57495void LoginScreenController::OnLockScreenDestroyed() {
496 DCHECK_EQ(authentication_stage_, AuthenticationStage::kIdle);
497
498 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
499 authentication_stage_ = AuthenticationStage::kIdle;
Alex Newcomer9f730e292021-04-01 21:46:15500 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57501}
502
Thomas Tellier0389c242020-08-27 11:44:45503void LoginScreenController::NotifyLoginScreenShown() {
504 if (!client_)
505 return;
506 client_->OnLoginScreenShown();
507}
508
xiaoyinh2bbdd102017-05-18 23:29:42509} // namespace ash