[go: nahoru, domu]

blob: 25b81f6ace74b4f1d9267b381f68a057d3e25d1a [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"
jdufaulteb4c9f1e2017-06-08 23:08:3011#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5312#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4013#include "ash/public/cpp/ash_pref_names.h"
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"
Renato Silva0c0e1bb2019-09-11 13:04:1729#include "base/strings/string_util.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)
Jeremy Roman47d432e2019-08-20 14:24:0067 : system_tray_notifier_(system_tray_notifier) {
Jun Mukai5c7b5b42018-11-30 00:08:5068 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
Renato Silva0c0e1bb2019-09-11 13:04:17128 // Checking if the password is only formed of numbers with base::StringToInt
129 // will easily fail due to numeric limits. ContainsOnlyChars is used instead.
130 const bool is_pin =
131 authenticated_by_pin && base::ContainsOnlyChars(password, "0123456789");
Evan Stade2e4c22e2019-06-07 02:13:55132 client_->AuthenticateUserWithPasswordOrPin(
Quan Nguyenf5224352018-11-06 02:03:34133 account_id, password, is_pin,
134 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
135 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32136}
137
Jacob Dufault2d20ae62018-09-20 22:19:52138void LoginScreenController::AuthenticateUserWithExternalBinary(
139 const AccountId& account_id,
140 OnAuthenticateCallback callback) {
141 // It is an error to call this function while an authentication is in
142 // progress.
143 LOG_IF(FATAL, IsAuthenticating())
144 << "Duplicate authentication attempt; current authentication stage is "
145 << static_cast<int>(authentication_stage_);
146
Evan Stade2e4c22e2019-06-07 02:13:55147 if (!client_) {
Jacob Dufault2d20ae62018-09-20 22:19:52148 std::move(callback).Run(base::nullopt);
149 return;
150 }
151
152 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Evan Stade2e4c22e2019-06-07 02:13:55153 client_->AuthenticateUserWithExternalBinary(
Jacob Dufault2d20ae62018-09-20 22:19:52154 account_id,
155 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
156 weak_factory_.GetWeakPtr(), std::move(callback)));
157}
158
Quan Nguyen92f924a2018-10-18 18:36:46159void LoginScreenController::EnrollUserWithExternalBinary(
160 OnAuthenticateCallback callback) {
Evan Stade2e4c22e2019-06-07 02:13:55161 if (!client_) {
Quan Nguyen92f924a2018-10-18 18:36:46162 std::move(callback).Run(base::nullopt);
163 return;
164 }
165
Evan Stade2e4c22e2019-06-07 02:13:55166 client_->EnrollUserWithExternalBinary(base::BindOnce(
Quan Nguyen92f924a2018-10-18 18:36:46167 [](OnAuthenticateCallback callback, bool success) {
168 std::move(callback).Run(base::make_optional<bool>(success));
169 },
170 std::move(callback)));
171}
172
Jacob Dufault2d20ae62018-09-20 22:19:52173void LoginScreenController::AuthenticateUserWithEasyUnlock(
174 const AccountId& account_id) {
175 // TODO(jdufault): integrate this into authenticate stage after mojom is
176 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55177 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32178 return;
Evan Stade2e4c22e2019-06-07 02:13:55179 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32180}
181
Maksim Ivanov675dd762019-07-29 18:31:10182void LoginScreenController::AuthenticateUserWithChallengeResponse(
183 const AccountId& account_id,
184 OnAuthenticateCallback callback) {
185 LOG_IF(FATAL, IsAuthenticating())
186 << "Duplicate authentication attempt; current authentication stage is "
187 << static_cast<int>(authentication_stage_);
188
189 if (!client_) {
190 std::move(callback).Run(/*success=*/base::nullopt);
191 return;
192 }
193
194 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
195 client_->AuthenticateUserWithChallengeResponse(
196 account_id,
197 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
198 weak_factory_.GetWeakPtr(), std::move(callback)));
199}
200
Evan Stade2e4c22e2019-06-07 02:13:55201bool LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17202 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05203 base::Time validation_time,
204 const std::string& code) {
205 DCHECK(!validation_time.is_null());
206
Evan Stade2e4c22e2019-06-07 02:13:55207 if (!client_)
208 return false;
Aga Wronskaac6cf362019-02-26 21:36:55209
Henrique Grandinetti914c34b62019-08-12 14:03:19210 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55211}
212
Fabian Sommer502d7a8b2020-02-04 14:37:45213void LoginScreenController::OnSecurityTokenPinRequestCancelledByUser() {
214 security_token_pin_request_cancelled_ = true;
215 std::move(on_request_security_token_ui_closed_).Run();
216}
217
218bool LoginScreenController::GetSecurityTokenPinRequestCancelled() const {
219 return security_token_pin_request_cancelled_;
220}
221
Jacob Dufaultffd9b0d2017-11-15 23:07:16222void LoginScreenController::HardlockPod(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55223 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32224 return;
Evan Stade2e4c22e2019-06-07 02:13:55225 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32226}
227
Jacob Dufaultffd9b0d2017-11-15 23:07:16228void LoginScreenController::OnFocusPod(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_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27232}
233
Jacob Dufaultffd9b0d2017-11-15 23:07:16234void LoginScreenController::OnNoPodFocused() {
Evan Stade2e4c22e2019-06-07 02:13:55235 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27236 return;
Evan Stade2e4c22e2019-06-07 02:13:55237 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27238}
239
Jacob Dufaultffd9b0d2017-11-15 23:07:16240void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55241 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27242 return;
Evan Stade2e4c22e2019-06-07 02:13:55243 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27244}
245
Jacob Dufaultffd9b0d2017-11-15 23:07:16246void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55247 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27248 return;
Evan Stade2e4c22e2019-06-07 02:13:55249 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27250}
251
Jacob Dufaultffd9b0d2017-11-15 23:07:16252void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55253 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30254 return;
Evan Stade2e4c22e2019-06-07 02:13:55255 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30256}
257
Aga Wronska6a32f9872018-01-06 00:16:10258void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55259 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10260 return;
Evan Stade2e4c22e2019-06-07 02:13:55261 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10262}
263
Jacob Dufaultffd9b0d2017-11-15 23:07:16264void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27265 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55266 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27267 return;
Evan Stade2e4c22e2019-06-07 02:13:55268 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27269}
270
Jacob Dufaultffd9b0d2017-11-15 23:07:16271void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55272 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48273 return;
Evan Stade2e4c22e2019-06-07 02:13:55274 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48275}
276
Evan Stade2e4c22e2019-06-07 02:13:55277void LoginScreenController::ShowGaiaSignin(bool can_close,
278 const AccountId& prefilled_account) {
279 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09280 return;
Evan Stade2e4c22e2019-06-07 02:13:55281 client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09282}
283
Jacob Dufaultfc31c742018-03-20 17:32:19284void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55285 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19286 return;
Evan Stade2e4c22e2019-06-07 02:13:55287 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19288}
289
290void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55291 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19292 return;
Evan Stade2e4c22e2019-06-07 02:13:55293 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19294}
295
Sarah Hu3fcf9f82018-03-22 20:32:54296void LoginScreenController::LaunchPublicSession(
297 const AccountId& account_id,
298 const std::string& locale,
299 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55300 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54301 return;
Evan Stade2e4c22e2019-06-07 02:13:55302 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54303}
304
Sarah Huf9affb122018-04-27 21:36:36305void LoginScreenController::RequestPublicSessionKeyboardLayouts(
306 const AccountId& account_id,
307 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55308 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36309 return;
Evan Stade2e4c22e2019-06-07 02:13:55310 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36311}
312
Sarah Hu0007c932018-06-18 20:21:04313void LoginScreenController::ShowFeedback() {
Evan Stade2e4c22e2019-06-07 02:13:55314 if (!client_)
Sarah Hu0007c932018-06-18 20:21:04315 return;
Evan Stade2e4c22e2019-06-07 02:13:55316 client_->ShowFeedback();
Sarah Hu0007c932018-06-18 20:21:04317}
318
Evan Stade2e4c22e2019-06-07 02:13:55319void LoginScreenController::SetClient(LoginScreenClient* client) {
320 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48321}
322
Evan Stadeb153f822019-05-23 19:14:43323LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31324 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43325}
326
Evan Stade9fe9cbe2019-06-03 23:05:55327void LoginScreenController::ShowKioskAppError(const std::string& message) {
328 ToastData toast_data(
329 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
330 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
331 true /*visible_on_lock_screen*/);
332 Shell::Get()->toast_manager()->Show(toast_data);
333}
334
335void LoginScreenController::FocusLoginShelf(bool reverse) {
336 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
337 // Tell the focus direction to the status area or the shelf so they can focus
338 // the correct child view.
339 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
340 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
341 return;
342 shelf->GetStatusAreaWidget()
343 ->status_area_widget_delegate()
344 ->set_default_last_focusable_child(reverse);
345 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
346 } else {
347 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
348 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
349 }
350}
351
352bool LoginScreenController::IsReadyForPassword() {
353 return LockScreen::HasInstance() && !IsAuthenticating();
354}
355
356void LoginScreenController::EnableAddUserButton(bool enable) {
357 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
358 ->shelf_widget()
359 ->login_shelf_view()
360 ->SetAddUserButtonEnabled(enable);
361}
362
363void LoginScreenController::EnableShutdownButton(bool enable) {
364 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
365 ->shelf_widget()
366 ->login_shelf_view()
367 ->SetShutdownButtonEnabled(enable);
368}
369
Evan Stade98b718e2019-06-03 17:15:34370void LoginScreenController::ShowGuestButtonInOobe(bool show) {
371 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
372 ->shelf_widget()
373 ->login_shelf_view()
374 ->ShowGuestButtonInOobe(show);
375}
376
377void LoginScreenController::ShowParentAccessButton(bool show) {
378 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
379 ->shelf_widget()
380 ->login_shelf_view()
381 ->ShowParentAccessButton(show);
382}
383
Evan Stade9fe9cbe2019-06-03 23:05:55384void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
385 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
386 ->shelf_widget()
387 ->login_shelf_view()
388 ->SetAllowLoginAsGuest(allow_guest);
389}
390
Alexander Alekseev7020c6b52019-07-25 03:25:48391std::unique_ptr<ScopedGuestButtonBlocker>
392LoginScreenController::GetScopedGuestButtonBlocker() {
393 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
394 ->shelf_widget()
395 ->login_shelf_view()
396 ->GetScopedGuestButtonBlocker();
397}
398
Fabian Sommerdcb675c2020-02-12 09:31:05399void LoginScreenController::ShowParentAccessWidget(
400 const AccountId& child_account_id,
401 ParentAccessRequest::OnParentAccessDone callback,
402 ParentAccessRequestReason reason,
403 bool extra_dimmer,
404 base::Time validation_time) {
405 DCHECK(!ParentAccessWidget::Get());
406 Shell::Get()->parent_access_controller()->ShowWidget(
407 child_account_id, std::move(callback), reason, extra_dimmer,
408 validation_time);
409}
410
Maksim Ivanovdbd9ade72019-08-09 15:34:16411void LoginScreenController::RequestSecurityTokenPin(
412 SecurityTokenPinRequest request) {
Fabian Sommer502d7a8b2020-02-04 14:37:45413 if (LockScreen::HasInstance() && !security_token_pin_request_cancelled_) {
414 // The caller must ensure that there is no unresolved pin request currently
415 // in progress.
416 on_request_security_token_ui_closed_ =
417 std::move(request.pin_ui_closed_callback);
418 // base::Unretained(this) could lead to errors if this controller is
419 // destroyed before the callback happens. This will be fixed by
420 // crbug.com/1001288 by using a UI owned by the controller.
421 request.pin_ui_closed_callback = base::BindOnce(
422 &LoginScreenController::OnSecurityTokenPinRequestCancelledByUser,
423 base::Unretained(this));
424 LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
425 } else {
426 // The user closed the PIN UI on a previous request that was part of the
427 // same smart card login attempt, or the PIN request is made at an
428 // inappropriate time, racing with the lock screen showing/hiding.
Maksim Ivanovdbd9ade72019-08-09 15:34:16429 std::move(request.pin_ui_closed_callback).Run();
Maksim Ivanovdbd9ade72019-08-09 15:34:16430 }
Maksim Ivanovdbd9ade72019-08-09 15:34:16431}
432
433void LoginScreenController::ClearSecurityTokenPinRequest() {
434 if (!LockScreen::HasInstance()) {
435 // Corner case: the request is made at inappropriate time, racing with the
436 // lock screen showing/hiding.
437 return;
438 }
439 LockScreen::Get()->ClearSecurityTokenPinRequest();
440}
441
Evan Stade2e4c22e2019-06-07 02:13:55442void LoginScreenController::ShowLockScreen() {
Jacob Dufault589d9942018-03-27 20:28:47443 OnShow();
Evan Stade98b718e2019-06-03 17:15:34444 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47445}
446
Evan Stade2e4c22e2019-06-07 02:13:55447void LoginScreenController::ShowLoginScreen() {
Jacob Dufault589d9942018-03-27 20:28:47448 // Login screen can only be used during login.
Evan Stade2e4c22e2019-06-07 02:13:55449 CHECK_EQ(session_manager::SessionState::LOGIN_PRIMARY,
450 Shell::Get()->session_controller()->GetSessionState())
451 << "Not showing login screen since session state is "
452 << static_cast<int>(
453 Shell::Get()->session_controller()->GetSessionState());
Jacob Dufault589d9942018-03-27 20:28:47454
455 OnShow();
Evan Stade98b718e2019-06-03 17:15:34456 // TODO(jdufault): rename LockScreen to LoginScreen.
457 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47458}
459
Evan Stade9c07ab42019-05-13 21:21:56460void LoginScreenController::SetKioskApps(
461 const std::vector<KioskAppMenuEntry>& kiosk_apps,
462 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
463 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
464 ->shelf_widget()
465 ->login_shelf_view()
466 ->SetKioskApps(kiosk_apps, launch_app);
467}
468
Quan Nguyene3e1d252018-07-19 23:00:44469void LoginScreenController::ShowResetScreen() {
Evan Stade2e4c22e2019-06-07 02:13:55470 client_->ShowResetScreen();
Quan Nguyene3e1d252018-07-19 23:00:44471}
472
Roman Sorokin925cddec2020-01-23 08:19:02473void LoginScreenController::ShowAccountAccessHelpApp(
474 gfx::NativeWindow parent_window) {
475 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11476}
477
Roman Sorokin925cddec2020-01-23 08:19:02478void LoginScreenController::ShowParentAccessHelpApp(
479 gfx::NativeWindow parent_window) {
480 client_->ShowParentAccessHelpApp(parent_window);
Aga Wronska7fef27e92019-08-22 17:51:27481}
482
Evan Stade3c971bc2019-06-11 22:12:44483void LoginScreenController::ShowLockScreenNotificationSettings() {
484 client_->ShowLockScreenNotificationSettings();
485}
486
Quan Nguyen3d7a0f02018-09-04 23:53:55487void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55488 if (!client_)
Tony de Luna46801932019-03-11 18:02:01489 return;
Evan Stade2e4c22e2019-06-07 02:13:55490 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55491}
492
Quan Nguyene377eb62019-02-11 23:02:25493void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55494 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48495 return;
Evan Stade2e4c22e2019-06-07 02:13:55496 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25497}
498
Jacob Dufaultb7a2d842017-12-01 23:21:15499void LoginScreenController::OnAuthenticateComplete(
500 OnAuthenticateCallback callback,
501 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43502 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46503 std::move(callback).Run(base::make_optional<bool>(success));
Fabian Sommer502d7a8b2020-02-04 14:37:45504 security_token_pin_request_cancelled_ = false;
505 on_request_security_token_ui_closed_.Reset();
Jacob Dufault8876ba82018-03-27 22:55:43506 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42507}
508
Jacob Dufaultcbc1ee02018-02-28 18:38:54509void LoginScreenController::OnShow() {
510 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17511 if (authentication_stage_ != AuthenticationStage::kIdle) {
512 AuthenticationStage authentication_stage = authentication_stage_;
513 base::debug::Alias(&authentication_stage);
514 LOG(FATAL) << "Unexpected authentication stage "
515 << static_cast<int>(authentication_stage_);
516 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54517}
518
Jun Mukai5c7b5b42018-11-30 00:08:50519void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55520 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50521 return;
Evan Stade2e4c22e2019-06-07 02:13:55522 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50523}
524
xiaoyinh2bbdd102017-05-18 23:29:42525} // namespace ash