[go: nahoru, domu]

blob: 169b9c404902e56400e2a9e4f759761b50fac791 [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"
Aga Wronska16abb432018-01-11 23:49:5913#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1814#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3015#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3216#include "ash/shelf/shelf.h"
17#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4018#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5919#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5520#include "ash/system/status_area_widget_delegate.h"
Quan Nguyenb7c2ea22018-09-10 17:44:1821#include "ash/system/toast/toast_data.h"
22#include "ash/system/toast/toast_manager.h"
Jun Mukai5c7b5b42018-11-30 00:08:5023#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4624#include "base/bind.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1725#include "base/debug/alias.h"
Sarah Hu069eea12017-09-08 01:28:4026#include "base/strings/string_number_conversions.h"
Jialiu Linf99b788b2018-01-17 23:01:2127#include "base/strings/utf_string_conversions.h"
Sarah Hu069eea12017-09-08 01:28:4028#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0929#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4230
31namespace ash {
32
Sarah Hu069eea12017-09-08 01:28:4033namespace {
xiaoyinh2bbdd102017-05-18 23:29:4234
Aga Wronskaa844cdcd12018-01-29 16:06:4435enum class SystemTrayVisibility {
36 kNone, // Tray not visible anywhere.
37 kPrimary, // Tray visible only on primary display.
38 kAll, // Tray visible on all displays.
39};
40
41void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
42 RootWindowController* primary_window_controller =
43 Shell::GetPrimaryRootWindowController();
44 for (RootWindowController* window_controller :
45 Shell::GetAllRootWindowControllers()) {
46 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
47 if (!status_area)
48 continue;
49 if (window_controller == primary_window_controller) {
50 status_area->SetSystemTrayVisibility(
51 visibility == SystemTrayVisibility::kPrimary ||
52 visibility == SystemTrayVisibility::kAll);
53 } else {
54 status_area->SetSystemTrayVisibility(visibility ==
55 SystemTrayVisibility::kAll);
56 }
57 }
Aga Wronska16abb432018-01-11 23:49:5958}
59
Sarah Hu069eea12017-09-08 01:28:4060} // namespace
61
Jun Mukai5c7b5b42018-11-30 00:08:5062LoginScreenController::LoginScreenController(
63 SystemTrayNotifier* system_tray_notifier)
64 : system_tray_notifier_(system_tray_notifier), weak_factory_(this) {
65 system_tray_notifier_->AddSystemTrayFocusObserver(this);
66}
James Cook8f1e6062017-11-13 23:40:5967
Jun Mukai5c7b5b42018-11-30 00:08:5068LoginScreenController::~LoginScreenController() {
69 system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
70}
xiaoyinh2bbdd102017-05-18 23:29:4271
Sarah Hu069eea12017-09-08 01:28:4072// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1673void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
74 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4075 if (for_test) {
76 // There is no remote pref service, so pretend that ash owns the pref.
77 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
78 return;
79 }
Sarah Hu069eea12017-09-08 01:28:4080}
81
Jacob Dufaultffd9b0d2017-11-15 23:07:1682void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) {
James Cookede316a2017-12-14 22:38:4383 bindings_.AddBinding(this, std::move(request));
xiaoyinh2bbdd102017-05-18 23:29:4284}
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
101 if (!login_screen_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,
121 weak_factory_.GetWeakPtr(), base::Passed(&callback),
122 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
129 int dummy_value;
130 bool is_pin =
131 authenticated_by_pin && base::StringToInt(password, &dummy_value);
132 login_screen_client_->AuthenticateUserWithPasswordOrPin(
133 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
147 if (!login_screen_client_) {
148 std::move(callback).Run(base::nullopt);
149 return;
150 }
151
152 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
153 login_screen_client_->AuthenticateUserWithExternalBinary(
154 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) {
161 if (!login_screen_client_) {
162 std::move(callback).Run(base::nullopt);
163 return;
164 }
165
166 login_screen_client_->EnrollUserWithExternalBinary(base::BindOnce(
167 [](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.
Jacob Dufaultffd9b0d2017-11-15 23:07:16177 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32178 return;
Jacob Dufault2d20ae62018-09-20 22:19:52179 login_screen_client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32180}
181
Aga Wronskaac6cf362019-02-26 21:36:55182void LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti88a6a712019-05-17 22:31:13183 const base::Optional<AccountId>& account_id,
Aga Wronskaac6cf362019-02-26 21:36:55184 const std::string& code,
185 OnParentAccessValidation callback) {
186 if (!login_screen_client_) {
187 std::move(callback).Run(base::nullopt);
188 return;
189 }
190
191 login_screen_client_->ValidateParentAccessCode(
192 account_id, code,
193 base::BindOnce(&LoginScreenController::OnParentAccessValidationComplete,
194 weak_factory_.GetWeakPtr(), std::move(callback)));
195}
196
Jacob Dufaultffd9b0d2017-11-15 23:07:16197void LoginScreenController::HardlockPod(const AccountId& account_id) {
198 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32199 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16200 login_screen_client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32201}
202
Jacob Dufaultffd9b0d2017-11-15 23:07:16203void LoginScreenController::OnFocusPod(const AccountId& account_id) {
204 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27205 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16206 login_screen_client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27207}
208
Jacob Dufaultffd9b0d2017-11-15 23:07:16209void LoginScreenController::OnNoPodFocused() {
210 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27211 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16212 login_screen_client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27213}
214
Jacob Dufaultffd9b0d2017-11-15 23:07:16215void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
216 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27217 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16218 login_screen_client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27219}
220
Jacob Dufaultffd9b0d2017-11-15 23:07:16221void LoginScreenController::SignOutUser() {
222 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27223 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16224 login_screen_client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27225}
226
Jacob Dufaultffd9b0d2017-11-15 23:07:16227void LoginScreenController::CancelAddUser() {
228 if (!login_screen_client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30229 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16230 login_screen_client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30231}
232
Aga Wronska6a32f9872018-01-06 00:16:10233void LoginScreenController::LoginAsGuest() {
234 if (!login_screen_client_)
235 return;
236 login_screen_client_->LoginAsGuest();
237}
238
Jacob Dufaultffd9b0d2017-11-15 23:07:16239void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27240 const AccountId& account_id) {
Jacob Dufaultffd9b0d2017-11-15 23:07:16241 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27242 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16243 login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27244}
245
Jacob Dufaultffd9b0d2017-11-15 23:07:16246void LoginScreenController::FocusLockScreenApps(bool reverse) {
247 if (!login_screen_client_)
Toni Barzicf61c4452017-10-05 03:57:48248 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16249 login_screen_client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48250}
251
Wenzhao Zang767a9f32018-05-02 21:20:55252void LoginScreenController::ShowGaiaSignin(
Jacob Dufaultfb72607d2018-06-12 19:50:33253 bool can_close,
254 const base::Optional<AccountId>& prefilled_account) {
Sarah Hu9fba0e752018-02-07 01:41:09255 if (!login_screen_client_)
256 return;
Jacob Dufaultfb72607d2018-06-12 19:50:33257 login_screen_client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09258}
259
Jacob Dufaultfc31c742018-03-20 17:32:19260void LoginScreenController::OnRemoveUserWarningShown() {
261 if (!login_screen_client_)
262 return;
263 login_screen_client_->OnRemoveUserWarningShown();
264}
265
266void LoginScreenController::RemoveUser(const AccountId& account_id) {
267 if (!login_screen_client_)
268 return;
269 login_screen_client_->RemoveUser(account_id);
270}
271
Sarah Hu3fcf9f82018-03-22 20:32:54272void LoginScreenController::LaunchPublicSession(
273 const AccountId& account_id,
274 const std::string& locale,
275 const std::string& input_method) {
276 if (!login_screen_client_)
277 return;
278 login_screen_client_->LaunchPublicSession(account_id, locale, input_method);
279}
280
Sarah Huf9affb122018-04-27 21:36:36281void LoginScreenController::RequestPublicSessionKeyboardLayouts(
282 const AccountId& account_id,
283 const std::string& locale) {
284 if (!login_screen_client_)
285 return;
286 login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
287}
288
Sarah Hu0007c932018-06-18 20:21:04289void LoginScreenController::ShowFeedback() {
290 if (!login_screen_client_)
291 return;
292 login_screen_client_->ShowFeedback();
293}
294
Jacob Dufault589d9942018-03-27 20:28:47295void LoginScreenController::AddObserver(
296 LoginScreenControllerObserver* observer) {
297 observers_.AddObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48298}
299
Jacob Dufault589d9942018-03-27 20:28:47300void LoginScreenController::RemoveObserver(
301 LoginScreenControllerObserver* observer) {
302 observers_.RemoveObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48303}
304
Jacob Dufaultffd9b0d2017-11-15 23:07:16305void LoginScreenController::FlushForTesting() {
306 login_screen_client_.FlushForTesting();
Toni Barzicf61c4452017-10-05 03:57:48307}
308
Evan Stadeb153f822019-05-23 19:14:43309LoginScreenModel* LoginScreenController::GetModel() {
310 return DataDispatcher();
311}
312
Jacob Dufault589d9942018-03-27 20:28:47313void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) {
314 login_screen_client_ = std::move(client);
315}
316
317void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
318 OnShow();
319 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock);
320 std::move(on_shown).Run(true);
321}
322
323void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) {
324 // Login screen can only be used during login.
325 if (Shell::Get()->session_controller()->GetSessionState() !=
326 session_manager::SessionState::LOGIN_PRIMARY) {
327 LOG(ERROR) << "Not showing login screen since session state is "
328 << static_cast<int>(
329 Shell::Get()->session_controller()->GetSessionState());
330 std::move(on_shown).Run(false);
331 return;
332 }
333
334 OnShow();
335 // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen.
336 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin);
337 std::move(on_shown).Run(true);
338}
339
340void LoginScreenController::ShowErrorMessage(int32_t login_attempts,
341 const std::string& error_text,
342 const std::string& help_link_text,
343 int32_t help_topic_id) {
344 NOTIMPLEMENTED();
345}
346
Naoki Fukino00a14cbc2018-08-08 05:27:22347void LoginScreenController::ShowWarningBanner(const base::string16& message) {
348 if (DataDispatcher())
349 DataDispatcher()->ShowWarningBanner(message);
350}
351
352void LoginScreenController::HideWarningBanner() {
353 if (DataDispatcher())
354 DataDispatcher()->HideWarningBanner();
355}
356
Jacob Dufault589d9942018-03-27 20:28:47357void LoginScreenController::ClearErrors() {
358 NOTIMPLEMENTED();
359}
360
Jacob Dufault589d9942018-03-27 20:28:47361void LoginScreenController::SetAuthType(
362 const AccountId& account_id,
363 proximity_auth::mojom::AuthType auth_type,
364 const base::string16& initial_value) {
365 if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
Jacob Dufault21cd5662018-08-07 18:04:33366 DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
367 true /*enabled*/);
Wenzhao Zang767a9f32018-05-02 21:20:55368 } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
369 DataDispatcher()->SetForceOnlineSignInForUser(account_id);
Jacob Dufault589d9942018-03-27 20:28:47370 } else {
371 NOTIMPLEMENTED();
372 }
373}
374
Jacob Dufault589d9942018-03-27 20:28:47375void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
376 bool is_enabled) {
377 // Chrome will update pin pod state every time user tries to authenticate.
378 // LockScreen is destroyed in the case of authentication success.
379 if (DataDispatcher())
380 DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled);
381}
382
Jacob Dufault947f2472018-10-24 21:08:16383void LoginScreenController::NotifyFingerprintAuthResult(
384 const AccountId& account_id,
385 bool successful) {
386 if (DataDispatcher())
387 DataDispatcher()->NotifyFingerprintAuthResult(account_id, successful);
388}
389
Henrique Grandinettid8951be2019-03-15 21:04:05390void LoginScreenController::EnableAuthForUser(const AccountId& account_id) {
391 if (DataDispatcher())
392 DataDispatcher()->EnableAuthForUser(account_id);
393}
394
395void LoginScreenController::DisableAuthForUser(
Wenzhao Zange0c2ab22018-05-23 17:43:46396 const AccountId& account_id,
Henrique Grandinettid8951be2019-03-15 21:04:05397 ash::mojom::AuthDisabledDataPtr auth_disabled_data) {
Wenzhao Zange0c2ab22018-05-23 17:43:46398 if (DataDispatcher()) {
Henrique Grandinettid8951be2019-03-15 21:04:05399 DataDispatcher()->DisableAuthForUser(account_id,
400 std::move(auth_disabled_data));
Wenzhao Zange0c2ab22018-05-23 17:43:46401 }
402}
403
Jacob Dufault589d9942018-03-27 20:28:47404void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) {
405 for (auto& observer : observers_)
406 observer.OnFocusLeavingLockScreenApps(reverse);
407}
408
Jacob Dufault5fc31392018-10-03 22:15:02409void LoginScreenController::SetSystemInfo(
410 bool show_if_hidden,
Jacob Dufault589d9942018-03-27 20:28:47411 const std::string& os_version_label_text,
412 const std::string& enterprise_info_text,
413 const std::string& bluetooth_name) {
414 if (DataDispatcher()) {
Jacob Dufault5fc31392018-10-03 22:15:02415 DataDispatcher()->SetSystemInfo(show_if_hidden, os_version_label_text,
416 enterprise_info_text, bluetooth_name);
Jacob Dufault589d9942018-03-27 20:28:47417 }
418}
419
420void LoginScreenController::IsReadyForPassword(
421 IsReadyForPasswordCallback callback) {
Jacob Dufault2ca8c502018-06-25 19:12:14422 std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating());
Jacob Dufault589d9942018-03-27 20:28:47423}
424
425void LoginScreenController::SetPublicSessionDisplayName(
426 const AccountId& account_id,
427 const std::string& display_name) {
428 if (DataDispatcher())
429 DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name);
430}
431
Zakhar Voitf99f63b2018-12-04 00:37:33432void LoginScreenController::SetPublicSessionShowFullManagementDisclosure(
433 bool is_full_management_disclosure_needed) {
434 if (DataDispatcher()) {
435 DataDispatcher()->SetPublicSessionShowFullManagementDisclosure(
436 is_full_management_disclosure_needed);
437 }
438}
439
Quan Nguyenb7c2ea22018-09-10 17:44:18440void LoginScreenController::ShowKioskAppError(const std::string& message) {
441 ToastData toast_data(
442 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
443 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
444 true /*visible_on_lock_screen*/);
445 Shell::Get()->toast_manager()->Show(toast_data);
446}
447
Sarah Hu51d19d32018-08-27 19:41:50448void LoginScreenController::NotifyOobeDialogState(
449 mojom::OobeDialogState state) {
Quan Nguyenc6ff3152018-08-07 20:00:37450 for (auto& observer : observers_)
Sarah Hu51d19d32018-08-27 19:41:50451 observer.OnOobeDialogStateChanged(state);
452}
453
454void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
455 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
456 ->shelf_widget()
457 ->login_shelf_view()
458 ->SetAllowLoginAsGuest(allow_guest);
459}
460
Quan Nguyencb8acab2018-12-05 20:39:08461void LoginScreenController::SetShowGuestButtonInOobe(bool show) {
Sarah Hu51d19d32018-08-27 19:41:50462 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
463 ->shelf_widget()
464 ->login_shelf_view()
Quan Nguyencb8acab2018-12-05 20:39:08465 ->SetShowGuestButtonInOobe(show);
Jacob Dufault883dcf72018-06-27 22:52:32466}
467
Aga Wronska49827d32019-02-01 03:36:39468void LoginScreenController::SetShowParentAccessButton(bool show) {
Aga Wronska850597a2019-01-02 22:07:23469 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
470 ->shelf_widget()
471 ->login_shelf_view()
Aga Wronska49827d32019-02-01 03:36:39472 ->SetShowParentAccessButton(show);
Aga Wronska850597a2019-01-02 22:07:23473}
474
Aga Wronska143a18a2019-02-13 23:07:17475void LoginScreenController::SetShowParentAccessDialog(bool show) {
476 if (DataDispatcher())
477 DataDispatcher()->SetShowParentAccessDialog(show);
478}
479
Quan Nguyen3d7a0f02018-09-04 23:53:55480void LoginScreenController::FocusLoginShelf(bool reverse) {
481 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
482 // Tell the focus direction to the status area or the shelf so they can focus
483 // the correct child view.
Jun Mukai103f57b2018-11-15 01:03:01484 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
485 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
Jun Mukaid96b4d7452018-11-09 00:37:23486 return;
Quan Nguyen3d7a0f02018-09-04 23:53:55487 shelf->GetStatusAreaWidget()
488 ->status_area_widget_delegate()
489 ->set_default_last_focusable_child(reverse);
490 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
491 } else {
492 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
493 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
494 }
495}
496
Evan Stade9c07ab42019-05-13 21:21:56497void LoginScreenController::SetKioskApps(
498 const std::vector<KioskAppMenuEntry>& kiosk_apps,
499 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
500 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
501 ->shelf_widget()
502 ->login_shelf_view()
503 ->SetKioskApps(kiosk_apps, launch_app);
504}
505
Sarah Hu4976046e2018-07-19 23:47:47506void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
507 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
508 ->shelf_widget()
509 ->login_shelf_view()
510 ->SetAddUserButtonEnabled(enable);
511}
512
Bruno Santoscf9d9cc2018-12-14 13:18:45513void LoginScreenController::SetShutdownButtonEnabled(bool enable) {
514 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
515 ->shelf_widget()
516 ->login_shelf_view()
517 ->SetShutdownButtonEnabled(enable);
518}
519
Quan Nguyene3e1d252018-07-19 23:00:44520void LoginScreenController::ShowResetScreen() {
521 login_screen_client_->ShowResetScreen();
522}
523
Quan Nguyenff20e232018-08-02 21:34:11524void LoginScreenController::ShowAccountAccessHelpApp() {
525 login_screen_client_->ShowAccountAccessHelpApp();
526}
527
Quan Nguyen3d7a0f02018-09-04 23:53:55528void LoginScreenController::FocusOobeDialog() {
Tony de Luna46801932019-03-11 18:02:01529 if (!login_screen_client_)
530 return;
Quan Nguyen3d7a0f02018-09-04 23:53:55531 login_screen_client_->FocusOobeDialog();
532}
533
Quan Nguyene377eb62019-02-11 23:02:25534void LoginScreenController::NotifyUserActivity() {
Xiyuan Xia5a8c4172019-05-13 16:23:48535 if (!login_screen_client_)
536 return;
Quan Nguyene377eb62019-02-11 23:02:25537 login_screen_client_->OnUserActivity();
538}
539
Jacob Dufaultb7a2d842017-12-01 23:21:15540void LoginScreenController::OnAuthenticateComplete(
541 OnAuthenticateCallback callback,
542 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43543 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46544 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43545 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42546}
547
Aga Wronskaac6cf362019-02-26 21:36:55548void LoginScreenController::OnParentAccessValidationComplete(
549 OnParentAccessValidation callback,
550 bool success) {
551 std::move(callback).Run(base::make_optional<bool>(success));
552}
553
Jacob Dufaultffd9b0d2017-11-15 23:07:16554LoginDataDispatcher* LoginScreenController::DataDispatcher() const {
Wenzhao Zang733497282018-06-12 16:53:10555 if (!ash::LockScreen::HasInstance())
Jacob Dufault40623d52017-09-15 17:22:53556 return nullptr;
557 return ash::LockScreen::Get()->data_dispatcher();
558}
559
Jacob Dufaultcbc1ee02018-02-28 18:38:54560void LoginScreenController::OnShow() {
561 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17562 if (authentication_stage_ != AuthenticationStage::kIdle) {
563 AuthenticationStage authentication_stage = authentication_stage_;
564 base::debug::Alias(&authentication_stage);
565 LOG(FATAL) << "Unexpected authentication stage "
566 << static_cast<int>(authentication_stage_);
567 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54568}
569
Jun Mukai5c7b5b42018-11-30 00:08:50570void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
571 if (!login_screen_client_)
572 return;
573 login_screen_client_->OnFocusLeavingSystemTray(reverse);
574}
575
xiaoyinh2bbdd102017-05-18 23:29:42576} // namespace ash