[go: nahoru, domu]

blob: d085b0afcc1682a0ebc6c3a656a350887c14b63c [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::AuthenticateUserWithExternalBinary(
140 const AccountId& account_id,
141 OnAuthenticateCallback callback) {
142 // It is an error to call this function while an authentication is in
143 // progress.
144 LOG_IF(FATAL, IsAuthenticating())
145 << "Duplicate authentication attempt; current authentication stage is "
146 << static_cast<int>(authentication_stage_);
147
Evan Stade2e4c22e2019-06-07 02:13:55148 if (!client_) {
Jacob Dufault2d20ae62018-09-20 22:19:52149 std::move(callback).Run(base::nullopt);
150 return;
151 }
152
153 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Evan Stade2e4c22e2019-06-07 02:13:55154 client_->AuthenticateUserWithExternalBinary(
Jacob Dufault2d20ae62018-09-20 22:19:52155 account_id,
156 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
157 weak_factory_.GetWeakPtr(), std::move(callback)));
158}
159
Quan Nguyen92f924a2018-10-18 18:36:46160void LoginScreenController::EnrollUserWithExternalBinary(
161 OnAuthenticateCallback callback) {
Evan Stade2e4c22e2019-06-07 02:13:55162 if (!client_) {
Quan Nguyen92f924a2018-10-18 18:36:46163 std::move(callback).Run(base::nullopt);
164 return;
165 }
166
Evan Stade2e4c22e2019-06-07 02:13:55167 client_->EnrollUserWithExternalBinary(base::BindOnce(
Quan Nguyen92f924a2018-10-18 18:36:46168 [](OnAuthenticateCallback callback, bool success) {
169 std::move(callback).Run(base::make_optional<bool>(success));
170 },
171 std::move(callback)));
172}
173
Jacob Dufault2d20ae62018-09-20 22:19:52174void LoginScreenController::AuthenticateUserWithEasyUnlock(
175 const AccountId& account_id) {
176 // TODO(jdufault): integrate this into authenticate stage after mojom is
177 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55178 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32179 return;
Evan Stade2e4c22e2019-06-07 02:13:55180 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32181}
182
Maksim Ivanov675dd762019-07-29 18:31:10183void LoginScreenController::AuthenticateUserWithChallengeResponse(
184 const AccountId& account_id,
185 OnAuthenticateCallback callback) {
186 LOG_IF(FATAL, IsAuthenticating())
187 << "Duplicate authentication attempt; current authentication stage is "
188 << static_cast<int>(authentication_stage_);
189
190 if (!client_) {
191 std::move(callback).Run(/*success=*/base::nullopt);
192 return;
193 }
194
195 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
196 client_->AuthenticateUserWithChallengeResponse(
197 account_id,
198 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
199 weak_factory_.GetWeakPtr(), std::move(callback)));
200}
201
Evan Stade2e4c22e2019-06-07 02:13:55202bool LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17203 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05204 base::Time validation_time,
205 const std::string& code) {
206 DCHECK(!validation_time.is_null());
207
Evan Stade2e4c22e2019-06-07 02:13:55208 if (!client_)
209 return false;
Aga Wronskaac6cf362019-02-26 21:36:55210
Henrique Grandinetti914c34b62019-08-12 14:03:19211 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55212}
213
Fabian Sommer4e0fc3d2020-02-27 14:16:33214bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
215 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45216}
217
Jacob Dufaultffd9b0d2017-11-15 23:07:16218void LoginScreenController::HardlockPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55219 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32220 return;
Evan Stade2e4c22e2019-06-07 02:13:55221 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32222}
223
Jacob Dufaultffd9b0d2017-11-15 23:07:16224void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55225 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27226 return;
Evan Stade2e4c22e2019-06-07 02:13:55227 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27228}
229
Jacob Dufaultffd9b0d2017-11-15 23:07:16230void LoginScreenController::OnNoPodFocused() {
Evan Stade2e4c22e2019-06-07 02:13:55231 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27232 return;
Evan Stade2e4c22e2019-06-07 02:13:55233 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27234}
235
Jacob Dufaultffd9b0d2017-11-15 23:07:16236void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55237 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27238 return;
Evan Stade2e4c22e2019-06-07 02:13:55239 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27240}
241
Jacob Dufaultffd9b0d2017-11-15 23:07:16242void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55243 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27244 return;
Evan Stade2e4c22e2019-06-07 02:13:55245 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27246}
247
Jacob Dufaultffd9b0d2017-11-15 23:07:16248void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55249 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30250 return;
Evan Stade2e4c22e2019-06-07 02:13:55251 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30252}
253
Aga Wronska6a32f9872018-01-06 00:16:10254void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55255 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10256 return;
Evan Stade2e4c22e2019-06-07 02:13:55257 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10258}
259
Jacob Dufaultffd9b0d2017-11-15 23:07:16260void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27261 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55262 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27263 return;
Evan Stade2e4c22e2019-06-07 02:13:55264 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27265}
266
Jacob Dufaultffd9b0d2017-11-15 23:07:16267void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55268 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48269 return;
Evan Stade2e4c22e2019-06-07 02:13:55270 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48271}
272
Roman Sorokin26d7e9662020-02-24 17:52:18273void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Evan Stade2e4c22e2019-06-07 02:13:55274 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09275 return;
Roman Sorokin26d7e9662020-02-24 17:52:18276 client_->ShowGaiaSignin(prefilled_account);
277}
278
279void LoginScreenController::HideGaiaSignin() {
280 if (!client_)
281 return;
282 client_->HideGaiaSignin();
Sarah Hu9fba0e752018-02-07 01:41:09283}
284
Jacob Dufaultfc31c742018-03-20 17:32:19285void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55286 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19287 return;
Evan Stade2e4c22e2019-06-07 02:13:55288 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19289}
290
291void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55292 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19293 return;
Evan Stade2e4c22e2019-06-07 02:13:55294 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19295}
296
Sarah Hu3fcf9f82018-03-22 20:32:54297void LoginScreenController::LaunchPublicSession(
298 const AccountId& account_id,
299 const std::string& locale,
300 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55301 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54302 return;
Evan Stade2e4c22e2019-06-07 02:13:55303 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54304}
305
Sarah Huf9affb122018-04-27 21:36:36306void LoginScreenController::RequestPublicSessionKeyboardLayouts(
307 const AccountId& account_id,
308 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55309 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36310 return;
Evan Stade2e4c22e2019-06-07 02:13:55311 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36312}
313
Sarah Hu0007c932018-06-18 20:21:04314void LoginScreenController::ShowFeedback() {
Evan Stade2e4c22e2019-06-07 02:13:55315 if (!client_)
Sarah Hu0007c932018-06-18 20:21:04316 return;
Evan Stade2e4c22e2019-06-07 02:13:55317 client_->ShowFeedback();
Sarah Hu0007c932018-06-18 20:21:04318}
319
Evan Stade2e4c22e2019-06-07 02:13:55320void LoginScreenController::SetClient(LoginScreenClient* client) {
321 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48322}
323
Evan Stadeb153f822019-05-23 19:14:43324LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31325 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43326}
327
Evan Stade9fe9cbe2019-06-03 23:05:55328void LoginScreenController::ShowKioskAppError(const std::string& message) {
329 ToastData toast_data(
330 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
331 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
332 true /*visible_on_lock_screen*/);
333 Shell::Get()->toast_manager()->Show(toast_data);
334}
335
336void LoginScreenController::FocusLoginShelf(bool reverse) {
337 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
338 // Tell the focus direction to the status area or the shelf so they can focus
339 // the correct child view.
340 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
341 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
342 return;
343 shelf->GetStatusAreaWidget()
344 ->status_area_widget_delegate()
345 ->set_default_last_focusable_child(reverse);
346 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
347 } else {
348 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
349 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
350 }
351}
352
353bool LoginScreenController::IsReadyForPassword() {
354 return LockScreen::HasInstance() && !IsAuthenticating();
355}
356
357void LoginScreenController::EnableAddUserButton(bool enable) {
358 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
359 ->shelf_widget()
360 ->login_shelf_view()
361 ->SetAddUserButtonEnabled(enable);
362}
363
364void LoginScreenController::EnableShutdownButton(bool enable) {
365 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
366 ->shelf_widget()
367 ->login_shelf_view()
368 ->SetShutdownButtonEnabled(enable);
369}
370
Evan Stade98b718e2019-06-03 17:15:34371void LoginScreenController::ShowGuestButtonInOobe(bool show) {
372 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
373 ->shelf_widget()
374 ->login_shelf_view()
375 ->ShowGuestButtonInOobe(show);
376}
377
378void LoginScreenController::ShowParentAccessButton(bool show) {
379 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
380 ->shelf_widget()
381 ->login_shelf_view()
382 ->ShowParentAccessButton(show);
383}
384
Evan Stade9fe9cbe2019-06-03 23:05:55385void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
386 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
387 ->shelf_widget()
388 ->login_shelf_view()
389 ->SetAllowLoginAsGuest(allow_guest);
390}
391
Alexander Alekseev7020c6b52019-07-25 03:25:48392std::unique_ptr<ScopedGuestButtonBlocker>
393LoginScreenController::GetScopedGuestButtonBlocker() {
394 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
395 ->shelf_widget()
396 ->login_shelf_view()
397 ->GetScopedGuestButtonBlocker();
398}
399
Fabian Sommerdcb675c2020-02-12 09:31:05400void LoginScreenController::ShowParentAccessWidget(
401 const AccountId& child_account_id,
Fabian Sommer06c38092020-02-13 14:08:43402 base::OnceCallback<void(bool success)> callback,
Fabian Sommerdcb675c2020-02-12 09:31:05403 ParentAccessRequestReason reason,
404 bool extra_dimmer,
405 base::Time validation_time) {
Fabian Sommer06c38092020-02-13 14:08:43406 DCHECK(!PinRequestWidget::Get());
Fabian Sommerdcb675c2020-02-12 09:31:05407 Shell::Get()->parent_access_controller()->ShowWidget(
408 child_account_id, std::move(callback), reason, extra_dimmer,
409 validation_time);
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}
Toni Barzic4ebccb502020-02-28 16:00:40420bool LoginScreenController::SetLoginShelfGestureHandler(
421 const base::string16& nudge_text,
422 const base::RepeatingClosure& fling_callback,
423 base::OnceClosure exit_callback) {
424 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
425 ->shelf_widget()
426 ->SetLoginShelfSwipeHandler(nudge_text, fling_callback,
427 std::move(exit_callback));
428}
429
430void LoginScreenController::ClearLoginShelfGestureHandler() {
431 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
432 ->shelf_widget()
433 ->ClearLoginShelfSwipeHandler();
434}
Maksim Ivanovdbd9ade72019-08-09 15:34:16435
Evan Stade2e4c22e2019-06-07 02:13:55436void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47437 OnShow();
Evan Stade98b718e2019-06-03 17:15:34438 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47439}
440
Evan Stade2e4c22e2019-06-07 02:13:55441void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47442 // Login screen can only be used during login.
Evan Stade2e4c22e2019-06-07 02:13:55443 CHECK_EQ(session_manager::SessionState::LOGIN_PRIMARY,
444 Shell::Get()->session_controller()->GetSessionState())
445 << "Not showing login screen since session state is "
446 << static_cast<int>(
447 Shell::Get()->session_controller()->GetSessionState());
Jacob Dufault589d9942018-03-27 20:28:47448
449 OnShow();
Evan Stade98b718e2019-06-03 17:15:34450 // TODO(jdufault): rename LockScreen to LoginScreen.
451 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47452}
453
Evan Stade9c07ab42019-05-13 21:21:56454void LoginScreenController::SetKioskApps(
455 const std::vector<KioskAppMenuEntry>& kiosk_apps,
456 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
457 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
458 ->shelf_widget()
459 ->login_shelf_view()
460 ->SetKioskApps(kiosk_apps, launch_app);
461}
462
Quan Nguyene3e1d252018-07-19 23:00:44463void LoginScreenController::ShowResetScreen() {
Evan Stade2e4c22e2019-06-07 02:13:55464 client_->ShowResetScreen();
Quan Nguyene3e1d252018-07-19 23:00:44465}
466
Roman Sorokin925cddec2020-01-23 08:19:02467void LoginScreenController::ShowAccountAccessHelpApp(
468 gfx::NativeWindow parent_window) {
469 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11470}
471
Roman Sorokin925cddec2020-01-23 08:19:02472void LoginScreenController::ShowParentAccessHelpApp(
473 gfx::NativeWindow parent_window) {
474 client_->ShowParentAccessHelpApp(parent_window);
Aga Wronska7fef27e92019-08-22 17:51:27475}
476
Evan Stade3c971bc2019-06-11 22:12:44477void LoginScreenController::ShowLockScreenNotificationSettings() {
478 client_->ShowLockScreenNotificationSettings();
479}
480
Quan Nguyen3d7a0f02018-09-04 23:53:55481void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55482 if (!client_)
Tony de Luna46801932019-03-11 18:02:01483 return;
Evan Stade2e4c22e2019-06-07 02:13:55484 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55485}
486
Quan Nguyene377eb62019-02-11 23:02:25487void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55488 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48489 return;
Evan Stade2e4c22e2019-06-07 02:13:55490 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25491}
492
Jacob Dufaultb7a2d842017-12-01 23:21:15493void LoginScreenController::OnAuthenticateComplete(
494 OnAuthenticateCallback callback,
495 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43496 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46497 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43498 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33499
500 // During smart card login flow, multiple security token requests can be made.
501 // If the user cancels one, all others should also be canceled.
502 // At this point, the flow is ending and new security token requests are
503 // displayed again.
504 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42505}
506
Jacob Dufaultcbc1ee02018-02-28 18:38:54507void LoginScreenController::OnShow() {
508 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17509 if (authentication_stage_ != AuthenticationStage::kIdle) {
510 AuthenticationStage authentication_stage = authentication_stage_;
511 base::debug::Alias(&authentication_stage);
512 LOG(FATAL) << "Unexpected authentication stage "
513 << static_cast<int>(authentication_stage_);
514 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54515}
516
Jun Mukai5c7b5b42018-11-30 00:08:50517void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55518 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50519 return;
Evan Stade2e4c22e2019-06-07 02:13:55520 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50521}
522
xiaoyinh2bbdd102017-05-18 23:29:42523} // namespace ash