[go: nahoru, domu]

blob: 1f3a4904450a02771f56fa1818b982f4c5291551 [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"
Henrique Grandinetti4eb2eae2019-05-31 16:31:1712#include "ash/login/ui/parent_access_widget.h"
Sarah Hu069eea12017-09-08 01:28:4013#include "ash/public/cpp/ash_pref_names.h"
Evan Stade2e4c22e2019-06-07 02:13:5514#include "ash/public/cpp/login_screen_client.h"
Anastasiia Nikolaienko94f9f7d2019-06-11 08:12:0715#include "ash/public/cpp/toast_data.h"
Aga Wronska16abb432018-01-11 23:49:5916#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1817#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3018#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3219#include "ash/shelf/shelf.h"
20#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4021#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5922#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5523#include "ash/system/status_area_widget_delegate.h"
Anastasiia Nikolaienko8cdd7e62019-06-12 12:16:2424#include "ash/system/toast/toast_manager_impl.h"
Jun Mukai5c7b5b42018-11-30 00:08:5025#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4626#include "base/bind.h"
Maksim Ivanovdbd9ade72019-08-09 15:34:1627#include "base/callback.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1728#include "base/debug/alias.h"
Sarah Hu069eea12017-09-08 01:28:4029#include "base/strings/string_number_conversions.h"
Jialiu Linf99b788b2018-01-17 23:01:2130#include "base/strings/utf_string_conversions.h"
Sarah Hu069eea12017-09-08 01:28:4031#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0932#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4233
34namespace ash {
35
Sarah Hu069eea12017-09-08 01:28:4036namespace {
xiaoyinh2bbdd102017-05-18 23:29:4237
Aga Wronskaa844cdcd12018-01-29 16:06:4438enum class SystemTrayVisibility {
39 kNone, // Tray not visible anywhere.
40 kPrimary, // Tray visible only on primary display.
41 kAll, // Tray visible on all displays.
42};
43
44void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
45 RootWindowController* primary_window_controller =
46 Shell::GetPrimaryRootWindowController();
47 for (RootWindowController* window_controller :
48 Shell::GetAllRootWindowControllers()) {
49 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
50 if (!status_area)
51 continue;
52 if (window_controller == primary_window_controller) {
53 status_area->SetSystemTrayVisibility(
54 visibility == SystemTrayVisibility::kPrimary ||
55 visibility == SystemTrayVisibility::kAll);
56 } else {
57 status_area->SetSystemTrayVisibility(visibility ==
58 SystemTrayVisibility::kAll);
59 }
60 }
Aga Wronska16abb432018-01-11 23:49:5961}
62
Sarah Hu069eea12017-09-08 01:28:4063} // namespace
64
Jun Mukai5c7b5b42018-11-30 00:08:5065LoginScreenController::LoginScreenController(
66 SystemTrayNotifier* system_tray_notifier)
67 : system_tray_notifier_(system_tray_notifier), weak_factory_(this) {
68 system_tray_notifier_->AddSystemTrayFocusObserver(this);
69}
James Cook8f1e6062017-11-13 23:40:5970
Jun Mukai5c7b5b42018-11-30 00:08:5071LoginScreenController::~LoginScreenController() {
72 system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
73}
xiaoyinh2bbdd102017-05-18 23:29:4274
Sarah Hu069eea12017-09-08 01:28:4075// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1676void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
77 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4078 if (for_test) {
79 // There is no remote pref service, so pretend that ash owns the pref.
80 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
81 return;
82 }
Sarah Hu069eea12017-09-08 01:28:4083}
84
Jacob Dufault2ca8c502018-06-25 19:12:1485bool LoginScreenController::IsAuthenticating() const {
86 return authentication_stage_ != AuthenticationStage::kIdle;
87}
88
Jacob Dufault2d20ae62018-09-20 22:19:5289void LoginScreenController::AuthenticateUserWithPasswordOrPin(
90 const AccountId& account_id,
91 const std::string& password,
92 bool authenticated_by_pin,
93 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4394 // It is an error to call this function while an authentication is in
95 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:5296 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:5697 << "Duplicate authentication attempt; current authentication stage is "
98 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:4399
Evan Stade2e4c22e2019-06-07 02:13:55100 if (!client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:15101 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32102 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15103 }
xiaoyinh9f6fa0e2017-06-07 19:22:32104
Jacob Dufaulteafc6fe2017-10-11 21:16:52105 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
106 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24107 switch (force_fail_auth_for_debug_overlay_) {
108 case ForceFailAuth::kOff:
109 break;
110 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15111 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24112 return;
113 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14114 // Set a dummy authentication stage so that |IsAuthenticating| returns
115 // true.
116 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24117 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15118 FROM_HERE,
119 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
120 weak_factory_.GetWeakPtr(), base::Passed(&callback),
121 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24122 base::TimeDelta::FromSeconds(1));
123 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52124 }
125
Quan Nguyenf5224352018-11-06 02:03:34126 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
127
128 int dummy_value;
129 bool is_pin =
130 authenticated_by_pin && base::StringToInt(password, &dummy_value);
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,
Henrique Grandinetti914c34b62019-08-12 14:03:19374 OnParentAccessWidgetFinished 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) {
Henrique Grandinetti98b31502019-06-11 18:06:09378 parent_access_widget_ = std::make_unique<ash::ParentAccessWidget>(
Henrique Grandinetti914c34b62019-08-12 14:03:19379 child_account_id, callback, reason, extra_dimmer, validation_time);
Henrique Grandinetti4eb2eae2019-05-31 16:31:17380}
381
Evan Stade9fe9cbe2019-06-03 23:05:55382void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
383 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
384 ->shelf_widget()
385 ->login_shelf_view()
386 ->SetAllowLoginAsGuest(allow_guest);
387}
388
Alexander Alekseev7020c6b52019-07-25 03:25:48389std::unique_ptr<ScopedGuestButtonBlocker>
390LoginScreenController::GetScopedGuestButtonBlocker() {
391 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
392 ->shelf_widget()
393 ->login_shelf_view()
394 ->GetScopedGuestButtonBlocker();
395}
396
Maksim Ivanovdbd9ade72019-08-09 15:34:16397void LoginScreenController::RequestSecurityTokenPin(
398 SecurityTokenPinRequest request) {
399 if (!LockScreen::HasInstance()) {
400 // Corner case: the PIN request is made at inappropriate time, racing with
401 // the lock screen showing/hiding.
402 std::move(request.pin_ui_closed_callback).Run();
403 return;
404 }
405 LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
406}
407
408void LoginScreenController::ClearSecurityTokenPinRequest() {
409 if (!LockScreen::HasInstance()) {
410 // Corner case: the request is made at inappropriate time, racing with the
411 // lock screen showing/hiding.
412 return;
413 }
414 LockScreen::Get()->ClearSecurityTokenPinRequest();
415}
416
Evan Stade2e4c22e2019-06-07 02:13:55417void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47418 OnShow();
Evan Stade98b718e2019-06-03 17:15:34419 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47420}
421
Evan Stade2e4c22e2019-06-07 02:13:55422void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47423 // Login screen can only be used during login.
Evan Stade2e4c22e2019-06-07 02:13:55424 CHECK_EQ(session_manager::SessionState::LOGIN_PRIMARY,
425 Shell::Get()->session_controller()->GetSessionState())
426 << "Not showing login screen since session state is "
427 << static_cast<int>(
428 Shell::Get()->session_controller()->GetSessionState());
Jacob Dufault589d9942018-03-27 20:28:47429
430 OnShow();
Evan Stade98b718e2019-06-03 17:15:34431 // TODO(jdufault): rename LockScreen to LoginScreen.
432 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47433}
434
Evan Stade9c07ab42019-05-13 21:21:56435void LoginScreenController::SetKioskApps(
436 const std::vector<KioskAppMenuEntry>& kiosk_apps,
437 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
438 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
439 ->shelf_widget()
440 ->login_shelf_view()
441 ->SetKioskApps(kiosk_apps, launch_app);
442}
443
Quan Nguyene3e1d252018-07-19 23:00:44444void LoginScreenController::ShowResetScreen() {
Evan Stade2e4c22e2019-06-07 02:13:55445 client_->ShowResetScreen();
Quan Nguyene3e1d252018-07-19 23:00:44446}
447
Quan Nguyenff20e232018-08-02 21:34:11448void LoginScreenController::ShowAccountAccessHelpApp() {
Evan Stade2e4c22e2019-06-07 02:13:55449 client_->ShowAccountAccessHelpApp();
Quan Nguyenff20e232018-08-02 21:34:11450}
451
Evan Stade3c971bc2019-06-11 22:12:44452void LoginScreenController::ShowLockScreenNotificationSettings() {
453 client_->ShowLockScreenNotificationSettings();
454}
455
Quan Nguyen3d7a0f02018-09-04 23:53:55456void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55457 if (!client_)
Tony de Luna46801932019-03-11 18:02:01458 return;
Evan Stade2e4c22e2019-06-07 02:13:55459 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55460}
461
Quan Nguyene377eb62019-02-11 23:02:25462void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55463 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48464 return;
Evan Stade2e4c22e2019-06-07 02:13:55465 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25466}
467
Jacob Dufaultb7a2d842017-12-01 23:21:15468void LoginScreenController::OnAuthenticateComplete(
469 OnAuthenticateCallback callback,
470 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43471 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46472 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43473 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42474}
475
Jacob Dufaultcbc1ee02018-02-28 18:38:54476void LoginScreenController::OnShow() {
477 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17478 if (authentication_stage_ != AuthenticationStage::kIdle) {
479 AuthenticationStage authentication_stage = authentication_stage_;
480 base::debug::Alias(&authentication_stage);
481 LOG(FATAL) << "Unexpected authentication stage "
482 << static_cast<int>(authentication_stage_);
483 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54484}
485
Jun Mukai5c7b5b42018-11-30 00:08:50486void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55487 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50488 return;
Evan Stade2e4c22e2019-06-07 02:13:55489 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50490}
491
xiaoyinh2bbdd102017-05-18 23:29:42492} // namespace ash