[go: nahoru, domu]

blob: 32bfd4802f9f8861007c74464609a878eda95dd6 [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) {
Tim Sergeant5acaeb6e2021-03-25 00:56:3269 system_tray_notifier_->AddSystemTrayFocusObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5070}
James Cook8f1e6062017-11-13 23:40:5971
Jun Mukai5c7b5b42018-11-30 00:08:5072LoginScreenController::~LoginScreenController() {
Tim Sergeant5acaeb6e2021-03-25 00:56:3273 system_tray_notifier_->RemoveSystemTrayFocusObserver(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_) {
Jacob Dufaultb7a2d842017-12-01 23:21:15102 std::move(callback).Run(base::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_) {
156 std::move(callback).Run(/*success=*/base::nullopt);
157 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
Jacob Dufaultfc31c742018-03-20 17:32:19244void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55245 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19246 return;
Evan Stade2e4c22e2019-06-07 02:13:55247 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19248}
249
250void LoginScreenController::RemoveUser(const AccountId& account_id) {
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_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19254}
255
Sarah Hu3fcf9f82018-03-22 20:32:54256void LoginScreenController::LaunchPublicSession(
257 const AccountId& account_id,
258 const std::string& locale,
259 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55260 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54261 return;
Evan Stade2e4c22e2019-06-07 02:13:55262 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54263}
264
Sarah Huf9affb122018-04-27 21:36:36265void LoginScreenController::RequestPublicSessionKeyboardLayouts(
266 const AccountId& account_id,
267 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55268 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36269 return;
Evan Stade2e4c22e2019-06-07 02:13:55270 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36271}
272
Evan Stade2e4c22e2019-06-07 02:13:55273void LoginScreenController::SetClient(LoginScreenClient* client) {
274 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48275}
276
Evan Stadeb153f822019-05-23 19:14:43277LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31278 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43279}
280
Evan Stade9fe9cbe2019-06-03 23:05:55281void LoginScreenController::ShowKioskAppError(const std::string& message) {
282 ToastData toast_data(
283 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
Jan Wilken Dörrie85285b02021-03-11 23:38:47284 base::Optional<std::u16string>(std::u16string()) /*dismiss_text*/,
Evan Stade9fe9cbe2019-06-03 23:05:55285 true /*visible_on_lock_screen*/);
286 Shell::Get()->toast_manager()->Show(toast_data);
287}
288
289void LoginScreenController::FocusLoginShelf(bool reverse) {
290 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
291 // Tell the focus direction to the status area or the shelf so they can focus
292 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17293 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
294 (reverse || !shelf->shelf_widget()->login_shelf_view()->IsFocusable())) {
295 // Focus goes to system tray (status area) if one of the following is true:
296 // - system tray is visible and tab is in reverse order;
297 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55298 shelf->GetStatusAreaWidget()
299 ->status_area_widget_delegate()
300 ->set_default_last_focusable_child(reverse);
301 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Danila Kuzmin35f80082020-11-25 12:26:17302 } else if (shelf->shelf_widget()->login_shelf_view()->IsFocusable()) {
303 // Otherwise focus goes to shelf buttons when there is any.
Evan Stade9fe9cbe2019-06-03 23:05:55304 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
305 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
Danila Kuzmin35f80082020-11-25 12:26:17306 } else {
307 // No elements to focus on the shelf.
308 NOTREACHED();
Evan Stade9fe9cbe2019-06-03 23:05:55309 }
310}
311
312bool LoginScreenController::IsReadyForPassword() {
313 return LockScreen::HasInstance() && !IsAuthenticating();
314}
315
316void LoginScreenController::EnableAddUserButton(bool enable) {
317 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
318 ->shelf_widget()
319 ->login_shelf_view()
320 ->SetAddUserButtonEnabled(enable);
321}
322
323void LoginScreenController::EnableShutdownButton(bool enable) {
324 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
325 ->shelf_widget()
326 ->login_shelf_view()
327 ->SetShutdownButtonEnabled(enable);
328}
329
Yunke Zhou9319aab2020-12-01 07:34:42330void LoginScreenController::EnableShelfButtons(bool enable) {
331 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
332 ->shelf_widget()
333 ->login_shelf_view()
334 ->SetButtonEnabled(enable);
335}
336
Ossama Mahmouda06399d2020-10-05 12:25:34337void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34338 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
339 ->shelf_widget()
340 ->login_shelf_view()
Ossama Mahmouda06399d2020-10-05 12:25:34341 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34342}
343
344void LoginScreenController::ShowParentAccessButton(bool show) {
345 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
346 ->shelf_widget()
347 ->login_shelf_view()
348 ->ShowParentAccessButton(show);
349}
350
Evan Stade9fe9cbe2019-06-03 23:05:55351void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
352 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
353 ->shelf_widget()
354 ->login_shelf_view()
355 ->SetAllowLoginAsGuest(allow_guest);
356}
357
Alexander Alekseev7020c6b52019-07-25 03:25:48358std::unique_ptr<ScopedGuestButtonBlocker>
359LoginScreenController::GetScopedGuestButtonBlocker() {
360 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
361 ->shelf_widget()
362 ->login_shelf_view()
363 ->GetScopedGuestButtonBlocker();
364}
365
Maksim Ivanovdbd9ade72019-08-09 15:34:16366void LoginScreenController::RequestSecurityTokenPin(
367 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33368 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16369}
370
371void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33372 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16373}
Toni Barzic4ebccb502020-02-28 16:00:40374bool LoginScreenController::SetLoginShelfGestureHandler(
Jan Wilken Dörrie85285b02021-03-11 23:38:47375 const std::u16string& nudge_text,
Toni Barzic4ebccb502020-02-28 16:00:40376 const base::RepeatingClosure& fling_callback,
377 base::OnceClosure exit_callback) {
378 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
379 ->shelf_widget()
380 ->SetLoginShelfSwipeHandler(nudge_text, fling_callback,
381 std::move(exit_callback));
382}
383
384void LoginScreenController::ClearLoginShelfGestureHandler() {
385 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
386 ->shelf_widget()
387 ->ClearLoginShelfSwipeHandler();
388}
Maksim Ivanovdbd9ade72019-08-09 15:34:16389
Evan Stade2e4c22e2019-06-07 02:13:55390void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57391 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47392 OnShow();
Evan Stade98b718e2019-06-03 17:15:34393 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47394}
395
Evan Stade2e4c22e2019-06-07 02:13:55396void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57397 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47398 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39399 session_manager::SessionState session_state =
400 Shell::Get()->session_controller()->GetSessionState();
401 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
402 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55403 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39404 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47405
406 OnShow();
Evan Stade98b718e2019-06-03 17:15:34407 // TODO(jdufault): rename LockScreen to LoginScreen.
408 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47409}
410
Evan Stade9c07ab42019-05-13 21:21:56411void LoginScreenController::SetKioskApps(
412 const std::vector<KioskAppMenuEntry>& kiosk_apps,
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25413 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
414 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56415 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
416 ->shelf_widget()
417 ->login_shelf_view()
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25418 ->SetKioskApps(kiosk_apps, launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56419}
420
Denis Kuznetsovad5a97c2020-07-09 10:45:35421void LoginScreenController::HandleAccelerator(
422 ash::LoginAcceleratorAction action) {
423 if (!client_)
424 return;
425 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44426}
427
Roman Sorokin925cddec2020-01-23 08:19:02428void LoginScreenController::ShowAccountAccessHelpApp(
429 gfx::NativeWindow parent_window) {
430 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11431}
432
Roman Sorokin925cddec2020-01-23 08:19:02433void LoginScreenController::ShowParentAccessHelpApp(
434 gfx::NativeWindow parent_window) {
435 client_->ShowParentAccessHelpApp(parent_window);
Aga Wronska7fef27e92019-08-22 17:51:27436}
437
Evan Stade3c971bc2019-06-11 22:12:44438void LoginScreenController::ShowLockScreenNotificationSettings() {
439 client_->ShowLockScreenNotificationSettings();
440}
441
Quan Nguyen3d7a0f02018-09-04 23:53:55442void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55443 if (!client_)
Tony de Luna46801932019-03-11 18:02:01444 return;
Evan Stade2e4c22e2019-06-07 02:13:55445 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55446}
447
Quan Nguyene377eb62019-02-11 23:02:25448void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55449 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48450 return;
Evan Stade2e4c22e2019-06-07 02:13:55451 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25452}
453
Jacob Dufaultb7a2d842017-12-01 23:21:15454void LoginScreenController::OnAuthenticateComplete(
455 OnAuthenticateCallback callback,
456 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43457 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46458 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43459 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33460
461 // During smart card login flow, multiple security token requests can be made.
462 // If the user cancels one, all others should also be canceled.
463 // At this point, the flow is ending and new security token requests are
464 // displayed again.
465 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42466}
467
Jacob Dufaultcbc1ee02018-02-28 18:38:54468void LoginScreenController::OnShow() {
469 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17470 if (authentication_stage_ != AuthenticationStage::kIdle) {
471 AuthenticationStage authentication_stage = authentication_stage_;
472 base::debug::Alias(&authentication_stage);
473 LOG(FATAL) << "Unexpected authentication stage "
474 << static_cast<int>(authentication_stage_);
475 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54476}
477
Jun Mukai5c7b5b42018-11-30 00:08:50478void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55479 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50480 return;
Evan Stade2e4c22e2019-06-07 02:13:55481 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50482}
483
Roman Sorokin16faa372021-03-09 16:17:57484void LoginScreenController::OnLockScreenDestroyed() {
485 DCHECK_EQ(authentication_stage_, AuthenticationStage::kIdle);
486
487 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
488 authentication_stage_ = AuthenticationStage::kIdle;
Alex Newcomer9f730e292021-04-01 21:46:15489 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57490}
491
Thomas Tellier0389c242020-08-27 11:44:45492void LoginScreenController::NotifyLoginScreenShown() {
493 if (!client_)
494 return;
495 client_->OnLoginScreenShown();
496}
497
xiaoyinh2bbdd102017-05-18 23:29:42498} // namespace ash