[go: nahoru, domu]

blob: 3572029f13a0c02c59a8e8d45a29847a826677c0 [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"
jdufaulteb4c9f1e2017-06-08 23:08:3010#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5311#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4012#include "ash/public/cpp/ash_pref_names.h"
Evan Stade2e4c22e2019-06-07 02:13:5513#include "ash/public/cpp/login_screen_client.h"
Anastasiia Nikolaienko94f9f7d2019-06-11 08:12:0714#include "ash/public/cpp/toast_data.h"
Aga Wronska16abb432018-01-11 23:49:5915#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1816#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3017#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3218#include "ash/shelf/shelf.h"
19#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4020#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5921#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5522#include "ash/system/status_area_widget_delegate.h"
Anastasiia Nikolaienko8cdd7e62019-06-12 12:16:2423#include "ash/system/toast/toast_manager_impl.h"
Jun Mukai5c7b5b42018-11-30 00:08:5024#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4625#include "base/bind.h"
Maksim Ivanovdbd9ade72019-08-09 15:34:1626#include "base/callback.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1727#include "base/debug/alias.h"
Renato Silva0c0e1bb2019-09-11 13:04:1728#include "base/strings/string_util.h"
Jialiu Linf99b788b2018-01-17 23:01:2129#include "base/strings/utf_string_conversions.h"
Sarah Hu069eea12017-09-08 01:28:4030#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0931#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4232
33namespace ash {
34
Sarah Hu069eea12017-09-08 01:28:4035namespace {
xiaoyinh2bbdd102017-05-18 23:29:4236
Aga Wronskaa844cdcd12018-01-29 16:06:4437enum class SystemTrayVisibility {
38 kNone, // Tray not visible anywhere.
39 kPrimary, // Tray visible only on primary display.
40 kAll, // Tray visible on all displays.
41};
42
43void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
44 RootWindowController* primary_window_controller =
45 Shell::GetPrimaryRootWindowController();
46 for (RootWindowController* window_controller :
47 Shell::GetAllRootWindowControllers()) {
48 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
49 if (!status_area)
50 continue;
51 if (window_controller == primary_window_controller) {
52 status_area->SetSystemTrayVisibility(
53 visibility == SystemTrayVisibility::kPrimary ||
54 visibility == SystemTrayVisibility::kAll);
55 } else {
56 status_area->SetSystemTrayVisibility(visibility ==
57 SystemTrayVisibility::kAll);
58 }
59 }
Aga Wronska16abb432018-01-11 23:49:5960}
61
Sarah Hu069eea12017-09-08 01:28:4062} // namespace
63
Jun Mukai5c7b5b42018-11-30 00:08:5064LoginScreenController::LoginScreenController(
65 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0066 : system_tray_notifier_(system_tray_notifier) {
Jun Mukai5c7b5b42018-11-30 00:08:5067 system_tray_notifier_->AddSystemTrayFocusObserver(this);
68}
James Cook8f1e6062017-11-13 23:40:5969
Jun Mukai5c7b5b42018-11-30 00:08:5070LoginScreenController::~LoginScreenController() {
71 system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
72}
xiaoyinh2bbdd102017-05-18 23:29:4273
Sarah Hu069eea12017-09-08 01:28:4074// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1675void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
76 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4077 if (for_test) {
78 // There is no remote pref service, so pretend that ash owns the pref.
79 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
80 return;
81 }
Sarah Hu069eea12017-09-08 01:28:4082}
83
Jacob Dufault2ca8c502018-06-25 19:12:1484bool LoginScreenController::IsAuthenticating() const {
85 return authentication_stage_ != AuthenticationStage::kIdle;
86}
87
Jacob Dufault2d20ae62018-09-20 22:19:5288void LoginScreenController::AuthenticateUserWithPasswordOrPin(
89 const AccountId& account_id,
90 const std::string& password,
91 bool authenticated_by_pin,
92 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4393 // It is an error to call this function while an authentication is in
94 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:5295 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:5696 << "Duplicate authentication attempt; current authentication stage is "
97 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:4398
Evan Stade2e4c22e2019-06-07 02:13:5599 if (!client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:15100 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32101 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15102 }
xiaoyinh9f6fa0e2017-06-07 19:22:32103
Jacob Dufaulteafc6fe2017-10-11 21:16:52104 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
105 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24106 switch (force_fail_auth_for_debug_overlay_) {
107 case ForceFailAuth::kOff:
108 break;
109 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15110 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24111 return;
112 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14113 // Set a dummy authentication stage so that |IsAuthenticating| returns
114 // true.
115 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24116 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15117 FROM_HERE,
118 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
119 weak_factory_.GetWeakPtr(), base::Passed(&callback),
120 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24121 base::TimeDelta::FromSeconds(1));
122 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52123 }
124
Quan Nguyenf5224352018-11-06 02:03:34125 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
126
Renato Silva0c0e1bb2019-09-11 13:04:17127 // Checking if the password is only formed of numbers with base::StringToInt
128 // will easily fail due to numeric limits. ContainsOnlyChars is used instead.
129 const bool is_pin =
130 authenticated_by_pin && base::ContainsOnlyChars(password, "0123456789");
Evan Stade2e4c22e2019-06-07 02:13:55131 client_->AuthenticateUserWithPasswordOrPin(
Quan Nguyenf5224352018-11-06 02:03:34132 account_id, password, is_pin,
133 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
134 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32135}
136
Jacob Dufault2d20ae62018-09-20 22:19:52137void LoginScreenController::AuthenticateUserWithExternalBinary(
138 const AccountId& account_id,
139 OnAuthenticateCallback callback) {
140 // It is an error to call this function while an authentication is in
141 // progress.
142 LOG_IF(FATAL, IsAuthenticating())
143 << "Duplicate authentication attempt; current authentication stage is "
144 << static_cast<int>(authentication_stage_);
145
Evan Stade2e4c22e2019-06-07 02:13:55146 if (!client_) {
Jacob Dufault2d20ae62018-09-20 22:19:52147 std::move(callback).Run(base::nullopt);
148 return;
149 }
150
151 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Evan Stade2e4c22e2019-06-07 02:13:55152 client_->AuthenticateUserWithExternalBinary(
Jacob Dufault2d20ae62018-09-20 22:19:52153 account_id,
154 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
155 weak_factory_.GetWeakPtr(), std::move(callback)));
156}
157
Quan Nguyen92f924a2018-10-18 18:36:46158void LoginScreenController::EnrollUserWithExternalBinary(
159 OnAuthenticateCallback callback) {
Evan Stade2e4c22e2019-06-07 02:13:55160 if (!client_) {
Quan Nguyen92f924a2018-10-18 18:36:46161 std::move(callback).Run(base::nullopt);
162 return;
163 }
164
Evan Stade2e4c22e2019-06-07 02:13:55165 client_->EnrollUserWithExternalBinary(base::BindOnce(
Quan Nguyen92f924a2018-10-18 18:36:46166 [](OnAuthenticateCallback callback, bool success) {
167 std::move(callback).Run(base::make_optional<bool>(success));
168 },
169 std::move(callback)));
170}
171
Jacob Dufault2d20ae62018-09-20 22:19:52172void LoginScreenController::AuthenticateUserWithEasyUnlock(
173 const AccountId& account_id) {
174 // TODO(jdufault): integrate this into authenticate stage after mojom is
175 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55176 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32177 return;
Evan Stade2e4c22e2019-06-07 02:13:55178 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32179}
180
Maksim Ivanov675dd762019-07-29 18:31:10181void LoginScreenController::AuthenticateUserWithChallengeResponse(
182 const AccountId& account_id,
183 OnAuthenticateCallback callback) {
184 LOG_IF(FATAL, IsAuthenticating())
185 << "Duplicate authentication attempt; current authentication stage is "
186 << static_cast<int>(authentication_stage_);
187
188 if (!client_) {
189 std::move(callback).Run(/*success=*/base::nullopt);
190 return;
191 }
192
193 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
194 client_->AuthenticateUserWithChallengeResponse(
195 account_id,
196 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
197 weak_factory_.GetWeakPtr(), std::move(callback)));
198}
199
Evan Stade2e4c22e2019-06-07 02:13:55200bool LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17201 const AccountId& account_id,
Henrique Grandinetti914c34b62019-08-12 14:03:19202 const std::string& code,
203 base::Time validation_time) {
Evan Stade2e4c22e2019-06-07 02:13:55204 if (!client_)
205 return false;
Aga Wronskaac6cf362019-02-26 21:36:55206
Henrique Grandinetti914c34b62019-08-12 14:03:19207 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55208}
209
Jacob Dufaultffd9b0d2017-11-15 23:07:16210void LoginScreenController::HardlockPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55211 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32212 return;
Evan Stade2e4c22e2019-06-07 02:13:55213 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32214}
215
Jacob Dufaultffd9b0d2017-11-15 23:07:16216void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55217 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27218 return;
Evan Stade2e4c22e2019-06-07 02:13:55219 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27220}
221
Jacob Dufaultffd9b0d2017-11-15 23:07:16222void LoginScreenController::OnNoPodFocused() {
Evan Stade2e4c22e2019-06-07 02:13:55223 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27224 return;
Evan Stade2e4c22e2019-06-07 02:13:55225 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27226}
227
Jacob Dufaultffd9b0d2017-11-15 23:07:16228void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55229 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27230 return;
Evan Stade2e4c22e2019-06-07 02:13:55231 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27232}
233
Jacob Dufaultffd9b0d2017-11-15 23:07:16234void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55235 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27236 return;
Evan Stade2e4c22e2019-06-07 02:13:55237 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27238}
239
Jacob Dufaultffd9b0d2017-11-15 23:07:16240void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55241 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30242 return;
Evan Stade2e4c22e2019-06-07 02:13:55243 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30244}
245
Aga Wronska6a32f9872018-01-06 00:16:10246void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55247 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10248 return;
Evan Stade2e4c22e2019-06-07 02:13:55249 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10250}
251
Jacob Dufaultffd9b0d2017-11-15 23:07:16252void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27253 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55254 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27255 return;
Evan Stade2e4c22e2019-06-07 02:13:55256 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27257}
258
Jacob Dufaultffd9b0d2017-11-15 23:07:16259void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55260 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48261 return;
Evan Stade2e4c22e2019-06-07 02:13:55262 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48263}
264
Evan Stade2e4c22e2019-06-07 02:13:55265void LoginScreenController::ShowGaiaSignin(bool can_close,
266 const AccountId& prefilled_account) {
267 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09268 return;
Evan Stade2e4c22e2019-06-07 02:13:55269 client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09270}
271
Jacob Dufaultfc31c742018-03-20 17:32:19272void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55273 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19274 return;
Evan Stade2e4c22e2019-06-07 02:13:55275 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19276}
277
278void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55279 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19280 return;
Evan Stade2e4c22e2019-06-07 02:13:55281 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19282}
283
Sarah Hu3fcf9f82018-03-22 20:32:54284void LoginScreenController::LaunchPublicSession(
285 const AccountId& account_id,
286 const std::string& locale,
287 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55288 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54289 return;
Evan Stade2e4c22e2019-06-07 02:13:55290 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54291}
292
Sarah Huf9affb122018-04-27 21:36:36293void LoginScreenController::RequestPublicSessionKeyboardLayouts(
294 const AccountId& account_id,
295 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55296 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36297 return;
Evan Stade2e4c22e2019-06-07 02:13:55298 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36299}
300
Sarah Hu0007c932018-06-18 20:21:04301void LoginScreenController::ShowFeedback() {
Evan Stade2e4c22e2019-06-07 02:13:55302 if (!client_)
Sarah Hu0007c932018-06-18 20:21:04303 return;
Evan Stade2e4c22e2019-06-07 02:13:55304 client_->ShowFeedback();
Sarah Hu0007c932018-06-18 20:21:04305}
306
Evan Stade2e4c22e2019-06-07 02:13:55307void LoginScreenController::SetClient(LoginScreenClient* client) {
308 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48309}
310
Evan Stadeb153f822019-05-23 19:14:43311LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31312 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43313}
314
Evan Stade9fe9cbe2019-06-03 23:05:55315void LoginScreenController::ShowKioskAppError(const std::string& message) {
316 ToastData toast_data(
317 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
318 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
319 true /*visible_on_lock_screen*/);
320 Shell::Get()->toast_manager()->Show(toast_data);
321}
322
323void LoginScreenController::FocusLoginShelf(bool reverse) {
324 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
325 // Tell the focus direction to the status area or the shelf so they can focus
326 // the correct child view.
327 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
328 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
329 return;
330 shelf->GetStatusAreaWidget()
331 ->status_area_widget_delegate()
332 ->set_default_last_focusable_child(reverse);
333 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
334 } else {
335 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
336 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
337 }
338}
339
340bool LoginScreenController::IsReadyForPassword() {
341 return LockScreen::HasInstance() && !IsAuthenticating();
342}
343
344void LoginScreenController::EnableAddUserButton(bool enable) {
345 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
346 ->shelf_widget()
347 ->login_shelf_view()
348 ->SetAddUserButtonEnabled(enable);
349}
350
351void LoginScreenController::EnableShutdownButton(bool enable) {
352 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
353 ->shelf_widget()
354 ->login_shelf_view()
355 ->SetShutdownButtonEnabled(enable);
356}
357
Evan Stade98b718e2019-06-03 17:15:34358void LoginScreenController::ShowGuestButtonInOobe(bool show) {
359 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
360 ->shelf_widget()
361 ->login_shelf_view()
362 ->ShowGuestButtonInOobe(show);
363}
364
365void LoginScreenController::ShowParentAccessButton(bool show) {
366 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
367 ->shelf_widget()
368 ->login_shelf_view()
369 ->ShowParentAccessButton(show);
370}
371
Henrique Grandinetti4eb2eae2019-05-31 16:31:17372void LoginScreenController::ShowParentAccessWidget(
373 const AccountId& child_account_id,
Aga Wronska3e57877d2019-08-23 15:54:58374 ParentAccessWidget::OnExitCallback callback,
Henrique Grandinetti91da2552019-06-24 14:25:56375 ParentAccessRequestReason reason,
Henrique Grandinetti914c34b62019-08-12 14:03:19376 bool extra_dimmer,
377 base::Time validation_time) {
Aga Wronska3e57877d2019-08-23 15:54:58378 DCHECK(!ParentAccessWidget::Get());
379 ParentAccessWidget::Show(child_account_id, std::move(callback), reason,
380 extra_dimmer, validation_time);
Henrique Grandinetti4eb2eae2019-05-31 16:31:17381}
382
Evan Stade9fe9cbe2019-06-03 23:05:55383void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
384 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
385 ->shelf_widget()
386 ->login_shelf_view()
387 ->SetAllowLoginAsGuest(allow_guest);
388}
389
Alexander Alekseev7020c6b52019-07-25 03:25:48390std::unique_ptr<ScopedGuestButtonBlocker>
391LoginScreenController::GetScopedGuestButtonBlocker() {
392 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
393 ->shelf_widget()
394 ->login_shelf_view()
395 ->GetScopedGuestButtonBlocker();
396}
397
Maksim Ivanovdbd9ade72019-08-09 15:34:16398void LoginScreenController::RequestSecurityTokenPin(
399 SecurityTokenPinRequest request) {
400 if (!LockScreen::HasInstance()) {
401 // Corner case: the PIN request is made at inappropriate time, racing with
402 // the lock screen showing/hiding.
403 std::move(request.pin_ui_closed_callback).Run();
404 return;
405 }
406 LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
407}
408
409void LoginScreenController::ClearSecurityTokenPinRequest() {
410 if (!LockScreen::HasInstance()) {
411 // Corner case: the request is made at inappropriate time, racing with the
412 // lock screen showing/hiding.
413 return;
414 }
415 LockScreen::Get()->ClearSecurityTokenPinRequest();
416}
417
Evan Stade2e4c22e2019-06-07 02:13:55418void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47419 OnShow();
Evan Stade98b718e2019-06-03 17:15:34420 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47421}
422
Evan Stade2e4c22e2019-06-07 02:13:55423void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47424 // Login screen can only be used during login.
Evan Stade2e4c22e2019-06-07 02:13:55425 CHECK_EQ(session_manager::SessionState::LOGIN_PRIMARY,
426 Shell::Get()->session_controller()->GetSessionState())
427 << "Not showing login screen since session state is "
428 << static_cast<int>(
429 Shell::Get()->session_controller()->GetSessionState());
Jacob Dufault589d9942018-03-27 20:28:47430
431 OnShow();
Evan Stade98b718e2019-06-03 17:15:34432 // TODO(jdufault): rename LockScreen to LoginScreen.
433 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47434}
435
Evan Stade9c07ab42019-05-13 21:21:56436void LoginScreenController::SetKioskApps(
437 const std::vector<KioskAppMenuEntry>& kiosk_apps,
438 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
439 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
440 ->shelf_widget()
441 ->login_shelf_view()
442 ->SetKioskApps(kiosk_apps, launch_app);
443}
444
Quan Nguyene3e1d252018-07-19 23:00:44445void LoginScreenController::ShowResetScreen() {
Evan Stade2e4c22e2019-06-07 02:13:55446 client_->ShowResetScreen();
Quan Nguyene3e1d252018-07-19 23:00:44447}
448
Quan Nguyenff20e232018-08-02 21:34:11449void LoginScreenController::ShowAccountAccessHelpApp() {
Evan Stade2e4c22e2019-06-07 02:13:55450 client_->ShowAccountAccessHelpApp();
Quan Nguyenff20e232018-08-02 21:34:11451}
452
Aga Wronska7fef27e92019-08-22 17:51:27453void LoginScreenController::ShowParentAccessHelpApp() {
454 client_->ShowParentAccessHelpApp();
455}
456
Evan Stade3c971bc2019-06-11 22:12:44457void LoginScreenController::ShowLockScreenNotificationSettings() {
458 client_->ShowLockScreenNotificationSettings();
459}
460
Quan Nguyen3d7a0f02018-09-04 23:53:55461void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55462 if (!client_)
Tony de Luna46801932019-03-11 18:02:01463 return;
Evan Stade2e4c22e2019-06-07 02:13:55464 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55465}
466
Quan Nguyene377eb62019-02-11 23:02:25467void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55468 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48469 return;
Evan Stade2e4c22e2019-06-07 02:13:55470 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25471}
472
Jacob Dufaultb7a2d842017-12-01 23:21:15473void LoginScreenController::OnAuthenticateComplete(
474 OnAuthenticateCallback callback,
475 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43476 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46477 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43478 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42479}
480
Jacob Dufaultcbc1ee02018-02-28 18:38:54481void LoginScreenController::OnShow() {
482 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17483 if (authentication_stage_ != AuthenticationStage::kIdle) {
484 AuthenticationStage authentication_stage = authentication_stage_;
485 base::debug::Alias(&authentication_stage);
486 LOG(FATAL) << "Unexpected authentication stage "
487 << static_cast<int>(authentication_stage_);
488 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54489}
490
Jun Mukai5c7b5b42018-11-30 00:08:50491void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55492 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50493 return;
Evan Stade2e4c22e2019-06-07 02:13:55494 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50495}
496
xiaoyinh2bbdd102017-05-18 23:29:42497} // namespace ash