[go: nahoru, domu]

blob: f0d33b57897ad3ff78e9d9765593747193c20e42 [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(
183 const AccountId& account_id,
184 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
Jacob Dufault589d9942018-03-27 20:28:47309void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) {
310 login_screen_client_ = std::move(client);
311}
312
313void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
314 OnShow();
315 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock);
316 std::move(on_shown).Run(true);
317}
318
319void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) {
320 // Login screen can only be used during login.
321 if (Shell::Get()->session_controller()->GetSessionState() !=
322 session_manager::SessionState::LOGIN_PRIMARY) {
323 LOG(ERROR) << "Not showing login screen since session state is "
324 << static_cast<int>(
325 Shell::Get()->session_controller()->GetSessionState());
326 std::move(on_shown).Run(false);
327 return;
328 }
329
330 OnShow();
331 // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen.
332 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin);
333 std::move(on_shown).Run(true);
334}
335
336void LoginScreenController::ShowErrorMessage(int32_t login_attempts,
337 const std::string& error_text,
338 const std::string& help_link_text,
339 int32_t help_topic_id) {
340 NOTIMPLEMENTED();
341}
342
Naoki Fukino00a14cbc2018-08-08 05:27:22343void LoginScreenController::ShowWarningBanner(const base::string16& message) {
344 if (DataDispatcher())
345 DataDispatcher()->ShowWarningBanner(message);
346}
347
348void LoginScreenController::HideWarningBanner() {
349 if (DataDispatcher())
350 DataDispatcher()->HideWarningBanner();
351}
352
Jacob Dufault589d9942018-03-27 20:28:47353void LoginScreenController::ClearErrors() {
354 NOTIMPLEMENTED();
355}
356
357void LoginScreenController::ShowUserPodCustomIcon(
358 const AccountId& account_id,
359 mojom::EasyUnlockIconOptionsPtr icon) {
360 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon);
361}
362
363void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
364 auto icon_options = mojom::EasyUnlockIconOptions::New();
365 icon_options->icon = mojom::EasyUnlockIconId::NONE;
366 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options);
367}
368
369void LoginScreenController::SetAuthType(
370 const AccountId& account_id,
371 proximity_auth::mojom::AuthType auth_type,
372 const base::string16& initial_value) {
373 if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
Jacob Dufault21cd5662018-08-07 18:04:33374 DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
375 true /*enabled*/);
Wenzhao Zang767a9f32018-05-02 21:20:55376 } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
377 DataDispatcher()->SetForceOnlineSignInForUser(account_id);
Jacob Dufault589d9942018-03-27 20:28:47378 } else {
379 NOTIMPLEMENTED();
380 }
381}
382
Sarah Hu51d19d32018-08-27 19:41:50383void LoginScreenController::SetUserList(
384 std::vector<mojom::LoginUserInfoPtr> users) {
Jacob Dufault589d9942018-03-27 20:28:47385 DCHECK(DataDispatcher());
386
387 DataDispatcher()->NotifyUsers(users);
388}
389
390void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
391 bool is_enabled) {
392 // Chrome will update pin pod state every time user tries to authenticate.
393 // LockScreen is destroyed in the case of authentication success.
394 if (DataDispatcher())
395 DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled);
396}
397
Jacob Dufault947f2472018-10-24 21:08:16398void LoginScreenController::SetFingerprintState(const AccountId& account_id,
399 mojom::FingerprintState state) {
400 if (DataDispatcher())
401 DataDispatcher()->SetFingerprintState(account_id, state);
402}
403
404void LoginScreenController::NotifyFingerprintAuthResult(
405 const AccountId& account_id,
406 bool successful) {
407 if (DataDispatcher())
408 DataDispatcher()->NotifyFingerprintAuthResult(account_id, successful);
409}
410
Jacob Dufault77d75ce92018-04-13 18:20:09411void LoginScreenController::SetAvatarForUser(const AccountId& account_id,
412 mojom::UserAvatarPtr avatar) {
413 for (auto& observer : observers_)
414 observer.SetAvatarForUser(account_id, avatar);
415}
416
Henrique Grandinettid8951be2019-03-15 21:04:05417void LoginScreenController::EnableAuthForUser(const AccountId& account_id) {
418 if (DataDispatcher())
419 DataDispatcher()->EnableAuthForUser(account_id);
420}
421
422void LoginScreenController::DisableAuthForUser(
Wenzhao Zange0c2ab22018-05-23 17:43:46423 const AccountId& account_id,
Henrique Grandinettid8951be2019-03-15 21:04:05424 ash::mojom::AuthDisabledDataPtr auth_disabled_data) {
Wenzhao Zange0c2ab22018-05-23 17:43:46425 if (DataDispatcher()) {
Henrique Grandinettid8951be2019-03-15 21:04:05426 DataDispatcher()->DisableAuthForUser(account_id,
427 std::move(auth_disabled_data));
Wenzhao Zange0c2ab22018-05-23 17:43:46428 }
429}
430
Jacob Dufault589d9942018-03-27 20:28:47431void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) {
432 for (auto& observer : observers_)
433 observer.OnFocusLeavingLockScreenApps(reverse);
434}
435
Jacob Dufault5fc31392018-10-03 22:15:02436void LoginScreenController::SetSystemInfo(
437 bool show_if_hidden,
Jacob Dufault589d9942018-03-27 20:28:47438 const std::string& os_version_label_text,
439 const std::string& enterprise_info_text,
440 const std::string& bluetooth_name) {
441 if (DataDispatcher()) {
Jacob Dufault5fc31392018-10-03 22:15:02442 DataDispatcher()->SetSystemInfo(show_if_hidden, os_version_label_text,
443 enterprise_info_text, bluetooth_name);
Jacob Dufault589d9942018-03-27 20:28:47444 }
445}
446
447void LoginScreenController::IsReadyForPassword(
448 IsReadyForPasswordCallback callback) {
Jacob Dufault2ca8c502018-06-25 19:12:14449 std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating());
Jacob Dufault589d9942018-03-27 20:28:47450}
451
452void LoginScreenController::SetPublicSessionDisplayName(
453 const AccountId& account_id,
454 const std::string& display_name) {
455 if (DataDispatcher())
456 DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name);
457}
458
459void LoginScreenController::SetPublicSessionLocales(
460 const AccountId& account_id,
Sarah Hue9cd6132018-05-17 17:25:56461 std::vector<mojom::LocaleItemPtr> locales,
Jacob Dufault589d9942018-03-27 20:28:47462 const std::string& default_locale,
463 bool show_advanced_view) {
464 if (DataDispatcher()) {
465 DataDispatcher()->SetPublicSessionLocales(
Sarah Hue9cd6132018-05-17 17:25:56466 account_id, locales, default_locale, show_advanced_view);
Jacob Dufault589d9942018-03-27 20:28:47467 }
468}
469
Sarah Huf9affb122018-04-27 21:36:36470void LoginScreenController::SetPublicSessionKeyboardLayouts(
471 const AccountId& account_id,
472 const std::string& locale,
473 std::vector<mojom::InputMethodItemPtr> keyboard_layouts) {
474 if (DataDispatcher()) {
475 DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale,
476 keyboard_layouts);
477 }
478}
479
Zakhar Voitf99f63b2018-12-04 00:37:33480void LoginScreenController::SetPublicSessionShowFullManagementDisclosure(
481 bool is_full_management_disclosure_needed) {
482 if (DataDispatcher()) {
483 DataDispatcher()->SetPublicSessionShowFullManagementDisclosure(
484 is_full_management_disclosure_needed);
485 }
486}
487
Quan Nguyenb7c2ea22018-09-10 17:44:18488void LoginScreenController::ShowKioskAppError(const std::string& message) {
489 ToastData toast_data(
490 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
491 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
492 true /*visible_on_lock_screen*/);
493 Shell::Get()->toast_manager()->Show(toast_data);
494}
495
Sarah Hu51d19d32018-08-27 19:41:50496void LoginScreenController::NotifyOobeDialogState(
497 mojom::OobeDialogState state) {
Quan Nguyenc6ff3152018-08-07 20:00:37498 for (auto& observer : observers_)
Sarah Hu51d19d32018-08-27 19:41:50499 observer.OnOobeDialogStateChanged(state);
500}
501
502void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
503 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
504 ->shelf_widget()
505 ->login_shelf_view()
506 ->SetAllowLoginAsGuest(allow_guest);
507}
508
Quan Nguyencb8acab2018-12-05 20:39:08509void LoginScreenController::SetShowGuestButtonInOobe(bool show) {
Sarah Hu51d19d32018-08-27 19:41:50510 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
511 ->shelf_widget()
512 ->login_shelf_view()
Quan Nguyencb8acab2018-12-05 20:39:08513 ->SetShowGuestButtonInOobe(show);
Jacob Dufault883dcf72018-06-27 22:52:32514}
515
Aga Wronska49827d32019-02-01 03:36:39516void LoginScreenController::SetShowParentAccessButton(bool show) {
Aga Wronska850597a2019-01-02 22:07:23517 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
518 ->shelf_widget()
519 ->login_shelf_view()
Aga Wronska49827d32019-02-01 03:36:39520 ->SetShowParentAccessButton(show);
Aga Wronska850597a2019-01-02 22:07:23521}
522
Aga Wronska143a18a2019-02-13 23:07:17523void LoginScreenController::SetShowParentAccessDialog(bool show) {
524 if (DataDispatcher())
525 DataDispatcher()->SetShowParentAccessDialog(show);
526}
527
Quan Nguyen3d7a0f02018-09-04 23:53:55528void LoginScreenController::FocusLoginShelf(bool reverse) {
529 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
530 // Tell the focus direction to the status area or the shelf so they can focus
531 // the correct child view.
Jun Mukai103f57b2018-11-15 01:03:01532 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
533 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
Jun Mukaid96b4d7452018-11-09 00:37:23534 return;
Quan Nguyen3d7a0f02018-09-04 23:53:55535 shelf->GetStatusAreaWidget()
536 ->status_area_widget_delegate()
537 ->set_default_last_focusable_child(reverse);
538 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
539 } else {
540 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
541 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
542 }
543}
544
Evan Stade9c07ab42019-05-13 21:21:56545void LoginScreenController::SetKioskApps(
546 const std::vector<KioskAppMenuEntry>& kiosk_apps,
547 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
548 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
549 ->shelf_widget()
550 ->login_shelf_view()
551 ->SetKioskApps(kiosk_apps, launch_app);
552}
553
Sarah Hu4976046e2018-07-19 23:47:47554void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
555 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
556 ->shelf_widget()
557 ->login_shelf_view()
558 ->SetAddUserButtonEnabled(enable);
559}
560
Bruno Santoscf9d9cc2018-12-14 13:18:45561void LoginScreenController::SetShutdownButtonEnabled(bool enable) {
562 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
563 ->shelf_widget()
564 ->login_shelf_view()
565 ->SetShutdownButtonEnabled(enable);
566}
567
Quan Nguyene3e1d252018-07-19 23:00:44568void LoginScreenController::ShowResetScreen() {
569 login_screen_client_->ShowResetScreen();
570}
571
Quan Nguyenff20e232018-08-02 21:34:11572void LoginScreenController::ShowAccountAccessHelpApp() {
573 login_screen_client_->ShowAccountAccessHelpApp();
574}
575
Quan Nguyen3d7a0f02018-09-04 23:53:55576void LoginScreenController::FocusOobeDialog() {
Tony de Luna46801932019-03-11 18:02:01577 if (!login_screen_client_)
578 return;
Quan Nguyen3d7a0f02018-09-04 23:53:55579 login_screen_client_->FocusOobeDialog();
580}
581
Quan Nguyene377eb62019-02-11 23:02:25582void LoginScreenController::NotifyUserActivity() {
Xiyuan Xia5a8c4172019-05-13 16:23:48583 if (!login_screen_client_)
584 return;
Quan Nguyene377eb62019-02-11 23:02:25585 login_screen_client_->OnUserActivity();
586}
587
Jacob Dufaultb7a2d842017-12-01 23:21:15588void LoginScreenController::OnAuthenticateComplete(
589 OnAuthenticateCallback callback,
590 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43591 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46592 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43593 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42594}
595
Aga Wronskaac6cf362019-02-26 21:36:55596void LoginScreenController::OnParentAccessValidationComplete(
597 OnParentAccessValidation callback,
598 bool success) {
599 std::move(callback).Run(base::make_optional<bool>(success));
600}
601
Jacob Dufaultffd9b0d2017-11-15 23:07:16602LoginDataDispatcher* LoginScreenController::DataDispatcher() const {
Wenzhao Zang733497282018-06-12 16:53:10603 if (!ash::LockScreen::HasInstance())
Jacob Dufault40623d52017-09-15 17:22:53604 return nullptr;
605 return ash::LockScreen::Get()->data_dispatcher();
606}
607
Jacob Dufaultcbc1ee02018-02-28 18:38:54608void LoginScreenController::OnShow() {
609 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17610 if (authentication_stage_ != AuthenticationStage::kIdle) {
611 AuthenticationStage authentication_stage = authentication_stage_;
612 base::debug::Alias(&authentication_stage);
613 LOG(FATAL) << "Unexpected authentication stage "
614 << static_cast<int>(authentication_stage_);
615 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54616}
617
Jun Mukai5c7b5b42018-11-30 00:08:50618void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
619 if (!login_screen_client_)
620 return;
621 login_screen_client_->OnFocusLeavingSystemTray(reverse);
622}
623
xiaoyinh2bbdd102017-05-18 23:29:42624} // namespace ash