[go: nahoru, domu]

blob: a3d1851484b63880dc4897e1d3e29e67ea880f2d [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 Sommerdcb675c2020-02-12 09:31:0510#include "ash/login/parent_access_controller.h"
Fabian Sommer4e0fc3d2020-02-27 14:16:3311#include "ash/login/security_token_request_controller.h"
jdufaulteb4c9f1e2017-06-08 23:08:3012#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5313#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4014#include "ash/public/cpp/ash_pref_names.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) {
Jun Mukai5c7b5b42018-11-30 00:08:5069 system_tray_notifier_->AddSystemTrayFocusObserver(this);
70}
James Cook8f1e6062017-11-13 23:40:5971
Jun Mukai5c7b5b42018-11-30 00:08:5072LoginScreenController::~LoginScreenController() {
73 system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
74}
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
Evan Stade2e4c22e2019-06-07 02:13:55167bool 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_)
174 return false;
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
Sarah Hu0007c932018-06-18 20:21:04273void LoginScreenController::ShowFeedback() {
Evan Stade2e4c22e2019-06-07 02:13:55274 if (!client_)
Sarah Hu0007c932018-06-18 20:21:04275 return;
Evan Stade2e4c22e2019-06-07 02:13:55276 client_->ShowFeedback();
Sarah Hu0007c932018-06-18 20:21:04277}
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*/,
290 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
291 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.
Roman Sorokin981e9e92020-04-07 20:14:40299 if (reverse) {
Evan Stade9fe9cbe2019-06-03 23:05:55300 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
301 return;
302 shelf->GetStatusAreaWidget()
303 ->status_area_widget_delegate()
304 ->set_default_last_focusable_child(reverse);
305 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
306 } else {
307 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
308 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
309 }
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
Evan Stade98b718e2019-06-03 17:15:34330void LoginScreenController::ShowGuestButtonInOobe(bool show) {
331 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
332 ->shelf_widget()
333 ->login_shelf_view()
334 ->ShowGuestButtonInOobe(show);
335}
336
337void LoginScreenController::ShowParentAccessButton(bool show) {
338 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
339 ->shelf_widget()
340 ->login_shelf_view()
341 ->ShowParentAccessButton(show);
342}
343
Evan Stade9fe9cbe2019-06-03 23:05:55344void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
345 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
346 ->shelf_widget()
347 ->login_shelf_view()
348 ->SetAllowLoginAsGuest(allow_guest);
349}
350
Alexander Alekseev7020c6b52019-07-25 03:25:48351std::unique_ptr<ScopedGuestButtonBlocker>
352LoginScreenController::GetScopedGuestButtonBlocker() {
353 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
354 ->shelf_widget()
355 ->login_shelf_view()
356 ->GetScopedGuestButtonBlocker();
357}
358
Fabian Sommerdcb675c2020-02-12 09:31:05359void LoginScreenController::ShowParentAccessWidget(
360 const AccountId& child_account_id,
Fabian Sommer06c38092020-02-13 14:08:43361 base::OnceCallback<void(bool success)> callback,
Fabian Sommerdcb675c2020-02-12 09:31:05362 ParentAccessRequestReason reason,
363 bool extra_dimmer,
364 base::Time validation_time) {
Fabian Sommer06c38092020-02-13 14:08:43365 DCHECK(!PinRequestWidget::Get());
Fabian Sommerdcb675c2020-02-12 09:31:05366 Shell::Get()->parent_access_controller()->ShowWidget(
367 child_account_id, std::move(callback), reason, extra_dimmer,
368 validation_time);
369}
370
Maksim Ivanovdbd9ade72019-08-09 15:34:16371void LoginScreenController::RequestSecurityTokenPin(
372 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33373 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16374}
375
376void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33377 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16378}
Toni Barzic4ebccb502020-02-28 16:00:40379bool LoginScreenController::SetLoginShelfGestureHandler(
380 const base::string16& nudge_text,
381 const base::RepeatingClosure& fling_callback,
382 base::OnceClosure exit_callback) {
383 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
384 ->shelf_widget()
385 ->SetLoginShelfSwipeHandler(nudge_text, fling_callback,
386 std::move(exit_callback));
387}
388
389void LoginScreenController::ClearLoginShelfGestureHandler() {
390 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
391 ->shelf_widget()
392 ->ClearLoginShelfSwipeHandler();
393}
Maksim Ivanovdbd9ade72019-08-09 15:34:16394
Evan Stade2e4c22e2019-06-07 02:13:55395void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47396 OnShow();
Evan Stade98b718e2019-06-03 17:15:34397 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47398}
399
Evan Stade2e4c22e2019-06-07 02:13:55400void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47401 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39402 session_manager::SessionState session_state =
403 Shell::Get()->session_controller()->GetSessionState();
404 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
405 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55406 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39407 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47408
409 OnShow();
Evan Stade98b718e2019-06-03 17:15:34410 // TODO(jdufault): rename LockScreen to LoginScreen.
411 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47412}
413
Evan Stade9c07ab42019-05-13 21:21:56414void LoginScreenController::SetKioskApps(
415 const std::vector<KioskAppMenuEntry>& kiosk_apps,
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25416 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
417 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56418 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
419 ->shelf_widget()
420 ->login_shelf_view()
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25421 ->SetKioskApps(kiosk_apps, launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56422}
423
Quan Nguyene3e1d252018-07-19 23:00:44424void LoginScreenController::ShowResetScreen() {
Evan Stade2e4c22e2019-06-07 02:13:55425 client_->ShowResetScreen();
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
xiaoyinh2bbdd102017-05-18 23:29:42484} // namespace ash