[go: nahoru, domu]

blob: 7c97190d83e16eb6e8c2dca2f1350cc0c8adb968 [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 Nguyen3d7a0f02018-09-04 23:53:557#include "ash/focus_cycler.h"
jdufaulteb4c9f1e2017-06-08 23:08:308#include "ash/login/ui/lock_screen.h"
Quan Nguyend09dd112018-06-19 19:20:329#include "ash/login/ui/lock_window.h"
Jacob Dufault40623d52017-09-15 17:22:5310#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4011#include "ash/public/cpp/ash_pref_names.h"
Aga Wronska16abb432018-01-11 23:49:5912#include "ash/root_window_controller.h"
Sarah Hu069eea12017-09-08 01:28:4013#include "ash/session/session_controller.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3014#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3215#include "ash/shelf/shelf.h"
16#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4017#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5918#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5519#include "ash/system/status_area_widget_delegate.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1720#include "base/debug/alias.h"
Sarah Hu069eea12017-09-08 01:28:4021#include "base/strings/string_number_conversions.h"
Jialiu Linf99b788b2018-01-17 23:01:2122#include "base/strings/utf_string_conversions.h"
xiaoyinh2bbdd102017-05-18 23:29:4223#include "chromeos/cryptohome/system_salt_getter.h"
Sarah Hu069eea12017-09-08 01:28:4024#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0925#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4226
27namespace ash {
28
Sarah Hu069eea12017-09-08 01:28:4029namespace {
xiaoyinh2bbdd102017-05-18 23:29:4230
Aga Wronskaa844cdcd12018-01-29 16:06:4431enum class SystemTrayVisibility {
32 kNone, // Tray not visible anywhere.
33 kPrimary, // Tray visible only on primary display.
34 kAll, // Tray visible on all displays.
35};
36
37void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
38 RootWindowController* primary_window_controller =
39 Shell::GetPrimaryRootWindowController();
40 for (RootWindowController* window_controller :
41 Shell::GetAllRootWindowControllers()) {
42 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
43 if (!status_area)
44 continue;
45 if (window_controller == primary_window_controller) {
46 status_area->SetSystemTrayVisibility(
47 visibility == SystemTrayVisibility::kPrimary ||
48 visibility == SystemTrayVisibility::kAll);
49 } else {
50 status_area->SetSystemTrayVisibility(visibility ==
51 SystemTrayVisibility::kAll);
52 }
53 }
Aga Wronska16abb432018-01-11 23:49:5954}
55
Sarah Hu069eea12017-09-08 01:28:4056} // namespace
57
James Cookede316a2017-12-14 22:38:4358LoginScreenController::LoginScreenController() : weak_factory_(this) {}
James Cook8f1e6062017-11-13 23:40:5959
Jacob Dufaultffd9b0d2017-11-15 23:07:1660LoginScreenController::~LoginScreenController() = default;
xiaoyinh2bbdd102017-05-18 23:29:4261
Sarah Hu069eea12017-09-08 01:28:4062// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1663void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
64 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4065 if (for_test) {
66 // There is no remote pref service, so pretend that ash owns the pref.
67 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
68 return;
69 }
70
71 // Pref is owned by chrome and flagged as PUBLIC.
72 registry->RegisterForeignPref(prefs::kQuickUnlockPinSalt);
73}
74
Jacob Dufaultffd9b0d2017-11-15 23:07:1675void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) {
James Cookede316a2017-12-14 22:38:4376 bindings_.AddBinding(this, std::move(request));
xiaoyinh2bbdd102017-05-18 23:29:4277}
78
Jacob Dufault2ca8c502018-06-25 19:12:1479bool LoginScreenController::IsAuthenticating() const {
80 return authentication_stage_ != AuthenticationStage::kIdle;
81}
82
Jacob Dufaultb7a2d842017-12-01 23:21:1583void LoginScreenController::AuthenticateUser(const AccountId& account_id,
84 const std::string& password,
85 bool authenticated_by_pin,
86 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4387 // It is an error to call this function while an authentication is in
88 // progress.
Jacob Dufault58a1bf42018-07-10 17:44:5689 LOG_IF(ERROR, IsAuthenticating())
90 << "Duplicate authentication attempt; current authentication stage is "
91 << static_cast<int>(authentication_stage_);
Jacob Dufault2ca8c502018-06-25 19:12:1492 CHECK(!IsAuthenticating());
Jacob Dufault8876ba82018-03-27 22:55:4393
94 if (!login_screen_client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:1595 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:3296 return;
Jacob Dufaultb7a2d842017-12-01 23:21:1597 }
xiaoyinh9f6fa0e2017-06-07 19:22:3298
Jacob Dufaulteafc6fe2017-10-11 21:16:5299 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
100 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24101 switch (force_fail_auth_for_debug_overlay_) {
102 case ForceFailAuth::kOff:
103 break;
104 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15105 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24106 return;
107 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14108 // Set a dummy authentication stage so that |IsAuthenticating| returns
109 // true.
110 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24111 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15112 FROM_HERE,
113 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
114 weak_factory_.GetWeakPtr(), base::Passed(&callback),
115 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24116 base::TimeDelta::FromSeconds(1));
117 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52118 }
119
Jacob Dufault8876ba82018-03-27 22:55:43120 // |DoAuthenticateUser| requires the system salt.
121 authentication_stage_ = AuthenticationStage::kGetSystemSalt;
122 chromeos::SystemSaltGetter::Get()->GetSystemSalt(
123 base::AdaptCallbackForRepeating(
124 base::BindOnce(&LoginScreenController::DoAuthenticateUser,
125 weak_factory_.GetWeakPtr(), account_id, password,
126 authenticated_by_pin, std::move(callback))));
xiaoyinh9f6fa0e2017-06-07 19:22:32127}
128
Jacob Dufaultffd9b0d2017-11-15 23:07:16129void LoginScreenController::AttemptUnlock(const AccountId& account_id) {
130 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32131 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16132 login_screen_client_->AttemptUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32133}
134
Jacob Dufaultffd9b0d2017-11-15 23:07:16135void LoginScreenController::HardlockPod(const AccountId& account_id) {
136 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32137 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16138 login_screen_client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32139}
140
Jacob Dufaultffd9b0d2017-11-15 23:07:16141void LoginScreenController::RecordClickOnLockIcon(const AccountId& account_id) {
142 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32143 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16144 login_screen_client_->RecordClickOnLockIcon(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32145}
146
Jacob Dufaultffd9b0d2017-11-15 23:07:16147void LoginScreenController::OnFocusPod(const AccountId& account_id) {
148 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27149 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16150 login_screen_client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27151}
152
Jacob Dufaultffd9b0d2017-11-15 23:07:16153void LoginScreenController::OnNoPodFocused() {
154 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27155 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16156 login_screen_client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27157}
158
Jacob Dufaultffd9b0d2017-11-15 23:07:16159void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
160 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27161 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16162 login_screen_client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27163}
164
Jacob Dufaultffd9b0d2017-11-15 23:07:16165void LoginScreenController::SignOutUser() {
166 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27167 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16168 login_screen_client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27169}
170
Jacob Dufaultffd9b0d2017-11-15 23:07:16171void LoginScreenController::CancelAddUser() {
172 if (!login_screen_client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30173 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16174 login_screen_client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30175}
176
Aga Wronska6a32f9872018-01-06 00:16:10177void LoginScreenController::LoginAsGuest() {
178 if (!login_screen_client_)
179 return;
180 login_screen_client_->LoginAsGuest();
181}
182
Jacob Dufaultffd9b0d2017-11-15 23:07:16183void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27184 const AccountId& account_id) {
Jacob Dufaultffd9b0d2017-11-15 23:07:16185 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27186 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16187 login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27188}
189
Jacob Dufaultffd9b0d2017-11-15 23:07:16190void LoginScreenController::FocusLockScreenApps(bool reverse) {
191 if (!login_screen_client_)
Toni Barzicf61c4452017-10-05 03:57:48192 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16193 login_screen_client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48194}
195
Wenzhao Zang767a9f32018-05-02 21:20:55196void LoginScreenController::ShowGaiaSignin(
Jacob Dufaultfb72607d2018-06-12 19:50:33197 bool can_close,
198 const base::Optional<AccountId>& prefilled_account) {
Sarah Hu9fba0e752018-02-07 01:41:09199 if (!login_screen_client_)
200 return;
Jacob Dufaultfb72607d2018-06-12 19:50:33201 login_screen_client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09202}
203
Jacob Dufaultfc31c742018-03-20 17:32:19204void LoginScreenController::OnRemoveUserWarningShown() {
205 if (!login_screen_client_)
206 return;
207 login_screen_client_->OnRemoveUserWarningShown();
208}
209
210void LoginScreenController::RemoveUser(const AccountId& account_id) {
211 if (!login_screen_client_)
212 return;
213 login_screen_client_->RemoveUser(account_id);
214}
215
Sarah Hu3fcf9f82018-03-22 20:32:54216void LoginScreenController::LaunchPublicSession(
217 const AccountId& account_id,
218 const std::string& locale,
219 const std::string& input_method) {
220 if (!login_screen_client_)
221 return;
222 login_screen_client_->LaunchPublicSession(account_id, locale, input_method);
223}
224
Sarah Huf9affb122018-04-27 21:36:36225void LoginScreenController::RequestPublicSessionKeyboardLayouts(
226 const AccountId& account_id,
227 const std::string& locale) {
228 if (!login_screen_client_)
229 return;
230 login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
231}
232
Sarah Hu0007c932018-06-18 20:21:04233void LoginScreenController::ShowFeedback() {
234 if (!login_screen_client_)
235 return;
236 login_screen_client_->ShowFeedback();
237}
238
Jacob Dufault589d9942018-03-27 20:28:47239void LoginScreenController::AddObserver(
240 LoginScreenControllerObserver* observer) {
241 observers_.AddObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48242}
243
Jacob Dufault589d9942018-03-27 20:28:47244void LoginScreenController::RemoveObserver(
245 LoginScreenControllerObserver* observer) {
246 observers_.RemoveObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48247}
248
Jacob Dufaultffd9b0d2017-11-15 23:07:16249void LoginScreenController::FlushForTesting() {
250 login_screen_client_.FlushForTesting();
Toni Barzicf61c4452017-10-05 03:57:48251}
252
Jacob Dufault589d9942018-03-27 20:28:47253void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) {
254 login_screen_client_ = std::move(client);
255}
256
257void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
258 OnShow();
259 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock);
260 std::move(on_shown).Run(true);
261}
262
263void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) {
264 // Login screen can only be used during login.
265 if (Shell::Get()->session_controller()->GetSessionState() !=
266 session_manager::SessionState::LOGIN_PRIMARY) {
267 LOG(ERROR) << "Not showing login screen since session state is "
268 << static_cast<int>(
269 Shell::Get()->session_controller()->GetSessionState());
270 std::move(on_shown).Run(false);
271 return;
272 }
273
274 OnShow();
275 // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen.
276 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin);
277 std::move(on_shown).Run(true);
278}
279
280void LoginScreenController::ShowErrorMessage(int32_t login_attempts,
281 const std::string& error_text,
282 const std::string& help_link_text,
283 int32_t help_topic_id) {
284 NOTIMPLEMENTED();
285}
286
Naoki Fukino00a14cbc2018-08-08 05:27:22287void LoginScreenController::ShowWarningBanner(const base::string16& message) {
288 if (DataDispatcher())
289 DataDispatcher()->ShowWarningBanner(message);
290}
291
292void LoginScreenController::HideWarningBanner() {
293 if (DataDispatcher())
294 DataDispatcher()->HideWarningBanner();
295}
296
Jacob Dufault589d9942018-03-27 20:28:47297void LoginScreenController::ClearErrors() {
298 NOTIMPLEMENTED();
299}
300
301void LoginScreenController::ShowUserPodCustomIcon(
302 const AccountId& account_id,
303 mojom::EasyUnlockIconOptionsPtr icon) {
304 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon);
305}
306
307void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
308 auto icon_options = mojom::EasyUnlockIconOptions::New();
309 icon_options->icon = mojom::EasyUnlockIconId::NONE;
310 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options);
311}
312
313void LoginScreenController::SetAuthType(
314 const AccountId& account_id,
315 proximity_auth::mojom::AuthType auth_type,
316 const base::string16& initial_value) {
317 if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
Jacob Dufault21cd5662018-08-07 18:04:33318 DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
319 true /*enabled*/);
Wenzhao Zang767a9f32018-05-02 21:20:55320 } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
321 DataDispatcher()->SetForceOnlineSignInForUser(account_id);
Jacob Dufault589d9942018-03-27 20:28:47322 } else {
323 NOTIMPLEMENTED();
324 }
325}
326
Sarah Hu51d19d32018-08-27 19:41:50327void LoginScreenController::SetUserList(
328 std::vector<mojom::LoginUserInfoPtr> users) {
Jacob Dufault589d9942018-03-27 20:28:47329 DCHECK(DataDispatcher());
330
331 DataDispatcher()->NotifyUsers(users);
332}
333
334void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
335 bool is_enabled) {
336 // Chrome will update pin pod state every time user tries to authenticate.
337 // LockScreen is destroyed in the case of authentication success.
338 if (DataDispatcher())
339 DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled);
340}
341
Jacob Dufault77d75ce92018-04-13 18:20:09342void LoginScreenController::SetAvatarForUser(const AccountId& account_id,
343 mojom::UserAvatarPtr avatar) {
344 for (auto& observer : observers_)
345 observer.SetAvatarForUser(account_id, avatar);
346}
347
Wenzhao Zange0c2ab22018-05-23 17:43:46348void LoginScreenController::SetAuthEnabledForUser(
349 const AccountId& account_id,
350 bool is_enabled,
351 base::Optional<base::Time> auth_reenabled_time) {
352 if (DataDispatcher()) {
353 DataDispatcher()->SetAuthEnabledForUser(account_id, is_enabled,
354 auth_reenabled_time);
355 }
356}
357
Jacob Dufault589d9942018-03-27 20:28:47358void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) {
359 for (auto& observer : observers_)
360 observer.OnFocusLeavingLockScreenApps(reverse);
361}
362
363void LoginScreenController::SetDevChannelInfo(
364 const std::string& os_version_label_text,
365 const std::string& enterprise_info_text,
366 const std::string& bluetooth_name) {
367 if (DataDispatcher()) {
368 DataDispatcher()->SetDevChannelInfo(os_version_label_text,
369 enterprise_info_text, bluetooth_name);
370 }
371}
372
373void LoginScreenController::IsReadyForPassword(
374 IsReadyForPasswordCallback callback) {
Jacob Dufault2ca8c502018-06-25 19:12:14375 std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating());
Jacob Dufault589d9942018-03-27 20:28:47376}
377
378void LoginScreenController::SetPublicSessionDisplayName(
379 const AccountId& account_id,
380 const std::string& display_name) {
381 if (DataDispatcher())
382 DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name);
383}
384
385void LoginScreenController::SetPublicSessionLocales(
386 const AccountId& account_id,
Sarah Hue9cd6132018-05-17 17:25:56387 std::vector<mojom::LocaleItemPtr> locales,
Jacob Dufault589d9942018-03-27 20:28:47388 const std::string& default_locale,
389 bool show_advanced_view) {
390 if (DataDispatcher()) {
391 DataDispatcher()->SetPublicSessionLocales(
Sarah Hue9cd6132018-05-17 17:25:56392 account_id, locales, default_locale, show_advanced_view);
Jacob Dufault589d9942018-03-27 20:28:47393 }
394}
395
Sarah Huf9affb122018-04-27 21:36:36396void LoginScreenController::SetPublicSessionKeyboardLayouts(
397 const AccountId& account_id,
398 const std::string& locale,
399 std::vector<mojom::InputMethodItemPtr> keyboard_layouts) {
400 if (DataDispatcher()) {
401 DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale,
402 keyboard_layouts);
403 }
404}
405
Sarah Hu1a7de562018-05-14 17:18:22406void LoginScreenController::SetFingerprintUnlockState(
407 const AccountId& account_id,
408 mojom::FingerprintUnlockState state) {
409 if (DataDispatcher())
410 DataDispatcher()->SetFingerprintUnlockState(account_id, state);
411}
412
Quan Nguyend09dd112018-06-19 19:20:32413void LoginScreenController::SetKioskApps(
414 std::vector<mojom::KioskAppInfoPtr> kiosk_apps) {
415 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
416 ->shelf_widget()
Jacob Dufault5ac266ef2018-07-18 17:30:30417 ->login_shelf_view()
418 ->SetKioskApps(std::move(kiosk_apps));
Quan Nguyend09dd112018-06-19 19:20:32419}
420
Sarah Hu51d19d32018-08-27 19:41:50421void LoginScreenController::NotifyOobeDialogState(
422 mojom::OobeDialogState state) {
Quan Nguyenc6ff3152018-08-07 20:00:37423 for (auto& observer : observers_)
Sarah Hu51d19d32018-08-27 19:41:50424 observer.OnOobeDialogStateChanged(state);
425}
426
427void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
428 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
429 ->shelf_widget()
430 ->login_shelf_view()
431 ->SetAllowLoginAsGuest(allow_guest);
432}
433
434void LoginScreenController::SetShowGuestButtonForGaiaScreen(bool can_show) {
435 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
436 ->shelf_widget()
437 ->login_shelf_view()
438 ->SetShowGuestButtonForGaiaScreen(can_show);
Jacob Dufault883dcf72018-06-27 22:52:32439}
440
Quan Nguyen3d7a0f02018-09-04 23:53:55441void LoginScreenController::FocusLoginShelf(bool reverse) {
442 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
443 // Tell the focus direction to the status area or the shelf so they can focus
444 // the correct child view.
445 if (reverse) {
446 shelf->GetStatusAreaWidget()
447 ->status_area_widget_delegate()
448 ->set_default_last_focusable_child(reverse);
449 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
450 } else {
451 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
452 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
453 }
454}
455
Sarah Hu4976046e2018-07-19 23:47:47456void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
457 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
458 ->shelf_widget()
459 ->login_shelf_view()
460 ->SetAddUserButtonEnabled(enable);
461}
462
Quan Nguyend09dd112018-06-19 19:20:32463void LoginScreenController::LaunchKioskApp(const std::string& app_id) {
464 login_screen_client_->LaunchKioskApp(app_id);
465}
466
Quan Nguyena3c54cf2018-07-03 17:56:50467void LoginScreenController::LaunchArcKioskApp(const AccountId& account_id) {
468 login_screen_client_->LaunchArcKioskApp(account_id);
469}
470
Quan Nguyene3e1d252018-07-19 23:00:44471void LoginScreenController::ShowResetScreen() {
472 login_screen_client_->ShowResetScreen();
473}
474
Quan Nguyenff20e232018-08-02 21:34:11475void LoginScreenController::ShowAccountAccessHelpApp() {
476 login_screen_client_->ShowAccountAccessHelpApp();
477}
478
Quan Nguyen3d7a0f02018-09-04 23:53:55479void LoginScreenController::FocusOobeDialog() {
480 login_screen_client_->FocusOobeDialog();
481}
482
Jacob Dufaultb7a2d842017-12-01 23:21:15483void LoginScreenController::DoAuthenticateUser(const AccountId& account_id,
484 const std::string& password,
485 bool authenticated_by_pin,
486 OnAuthenticateCallback callback,
487 const std::string& system_salt) {
Jacob Dufault8876ba82018-03-27 22:55:43488 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
489
Sarah Hu069eea12017-09-08 01:28:40490 int dummy_value;
491 bool is_pin =
492 authenticated_by_pin && base::StringToInt(password, &dummy_value);
Jacob Dufaultb7a2d842017-12-01 23:21:15493 login_screen_client_->AuthenticateUser(
Jacob Dufault2be71002018-05-16 17:07:43494 account_id, password, is_pin,
Jacob Dufaultb7a2d842017-12-01 23:21:15495 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
496 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
jdufaulteb4c9f1e2017-06-08 23:08:30497}
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;
Jacob Dufaultb7a2d842017-12-01 23:21:15503 std::move(callback).Run(success);
Jacob Dufault8876ba82018-03-27 22:55:43504 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42505}
506
Jacob Dufaultffd9b0d2017-11-15 23:07:16507LoginDataDispatcher* LoginScreenController::DataDispatcher() const {
Wenzhao Zang733497282018-06-12 16:53:10508 if (!ash::LockScreen::HasInstance())
Jacob Dufault40623d52017-09-15 17:22:53509 return nullptr;
510 return ash::LockScreen::Get()->data_dispatcher();
511}
512
Jacob Dufaultcbc1ee02018-02-28 18:38:54513void LoginScreenController::OnShow() {
514 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17515 if (authentication_stage_ != AuthenticationStage::kIdle) {
516 AuthenticationStage authentication_stage = authentication_stage_;
517 base::debug::Alias(&authentication_stage);
518 LOG(FATAL) << "Unexpected authentication stage "
519 << static_cast<int>(authentication_stage_);
520 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54521}
522
xiaoyinh2bbdd102017-05-18 23:29:42523} // namespace ash