[go: nahoru, domu]

blob: dc31cb6905a363d7dcb050932e09abbe7e4c1874 [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"
Quan Nguyenb7c2ea22018-09-10 17:44:1820#include "ash/system/toast/toast_data.h"
21#include "ash/system/toast/toast_manager.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1722#include "base/debug/alias.h"
Sarah Hu069eea12017-09-08 01:28:4023#include "base/strings/string_number_conversions.h"
Jialiu Linf99b788b2018-01-17 23:01:2124#include "base/strings/utf_string_conversions.h"
xiaoyinh2bbdd102017-05-18 23:29:4225#include "chromeos/cryptohome/system_salt_getter.h"
Sarah Hu069eea12017-09-08 01:28:4026#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0927#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4228
29namespace ash {
30
Sarah Hu069eea12017-09-08 01:28:4031namespace {
xiaoyinh2bbdd102017-05-18 23:29:4232
Aga Wronskaa844cdcd12018-01-29 16:06:4433enum class SystemTrayVisibility {
34 kNone, // Tray not visible anywhere.
35 kPrimary, // Tray visible only on primary display.
36 kAll, // Tray visible on all displays.
37};
38
39void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
40 RootWindowController* primary_window_controller =
41 Shell::GetPrimaryRootWindowController();
42 for (RootWindowController* window_controller :
43 Shell::GetAllRootWindowControllers()) {
44 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
45 if (!status_area)
46 continue;
47 if (window_controller == primary_window_controller) {
48 status_area->SetSystemTrayVisibility(
49 visibility == SystemTrayVisibility::kPrimary ||
50 visibility == SystemTrayVisibility::kAll);
51 } else {
52 status_area->SetSystemTrayVisibility(visibility ==
53 SystemTrayVisibility::kAll);
54 }
55 }
Aga Wronska16abb432018-01-11 23:49:5956}
57
Sarah Hu069eea12017-09-08 01:28:4058} // namespace
59
James Cookede316a2017-12-14 22:38:4360LoginScreenController::LoginScreenController() : weak_factory_(this) {}
James Cook8f1e6062017-11-13 23:40:5961
Jacob Dufaultffd9b0d2017-11-15 23:07:1662LoginScreenController::~LoginScreenController() = default;
xiaoyinh2bbdd102017-05-18 23:29:4263
Sarah Hu069eea12017-09-08 01:28:4064// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1665void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
66 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4067 if (for_test) {
68 // There is no remote pref service, so pretend that ash owns the pref.
69 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
70 return;
71 }
72
73 // Pref is owned by chrome and flagged as PUBLIC.
74 registry->RegisterForeignPref(prefs::kQuickUnlockPinSalt);
75}
76
Jacob Dufaultffd9b0d2017-11-15 23:07:1677void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) {
James Cookede316a2017-12-14 22:38:4378 bindings_.AddBinding(this, std::move(request));
xiaoyinh2bbdd102017-05-18 23:29:4279}
80
Jacob Dufault2ca8c502018-06-25 19:12:1481bool LoginScreenController::IsAuthenticating() const {
82 return authentication_stage_ != AuthenticationStage::kIdle;
83}
84
Jacob Dufault2d20ae62018-09-20 22:19:5285void LoginScreenController::AuthenticateUserWithPasswordOrPin(
86 const AccountId& account_id,
87 const std::string& password,
88 bool authenticated_by_pin,
89 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4390 // It is an error to call this function while an authentication is in
91 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:5292 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:5693 << "Duplicate authentication attempt; current authentication stage is "
94 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:4395
96 if (!login_screen_client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:1597 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:3298 return;
Jacob Dufaultb7a2d842017-12-01 23:21:1599 }
xiaoyinh9f6fa0e2017-06-07 19:22:32100
Jacob Dufaulteafc6fe2017-10-11 21:16:52101 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
102 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24103 switch (force_fail_auth_for_debug_overlay_) {
104 case ForceFailAuth::kOff:
105 break;
106 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15107 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24108 return;
109 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14110 // Set a dummy authentication stage so that |IsAuthenticating| returns
111 // true.
112 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24113 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15114 FROM_HERE,
115 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
116 weak_factory_.GetWeakPtr(), base::Passed(&callback),
117 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24118 base::TimeDelta::FromSeconds(1));
119 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52120 }
121
Jacob Dufault8876ba82018-03-27 22:55:43122 // |DoAuthenticateUser| requires the system salt.
123 authentication_stage_ = AuthenticationStage::kGetSystemSalt;
124 chromeos::SystemSaltGetter::Get()->GetSystemSalt(
125 base::AdaptCallbackForRepeating(
126 base::BindOnce(&LoginScreenController::DoAuthenticateUser,
127 weak_factory_.GetWeakPtr(), account_id, password,
128 authenticated_by_pin, std::move(callback))));
xiaoyinh9f6fa0e2017-06-07 19:22:32129}
130
Jacob Dufault2d20ae62018-09-20 22:19:52131void LoginScreenController::AuthenticateUserWithExternalBinary(
132 const AccountId& account_id,
133 OnAuthenticateCallback callback) {
134 // It is an error to call this function while an authentication is in
135 // progress.
136 LOG_IF(FATAL, IsAuthenticating())
137 << "Duplicate authentication attempt; current authentication stage is "
138 << static_cast<int>(authentication_stage_);
139
140 if (!login_screen_client_) {
141 std::move(callback).Run(base::nullopt);
142 return;
143 }
144
145 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
146 login_screen_client_->AuthenticateUserWithExternalBinary(
147 account_id,
148 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
149 weak_factory_.GetWeakPtr(), std::move(callback)));
150}
151
152void LoginScreenController::AuthenticateUserWithEasyUnlock(
153 const AccountId& account_id) {
154 // TODO(jdufault): integrate this into authenticate stage after mojom is
155 // refactored to use a callback.
Jacob Dufaultffd9b0d2017-11-15 23:07:16156 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32157 return;
Jacob Dufault2d20ae62018-09-20 22:19:52158 login_screen_client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32159}
160
Jacob Dufaultffd9b0d2017-11-15 23:07:16161void LoginScreenController::HardlockPod(const AccountId& account_id) {
162 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32163 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16164 login_screen_client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32165}
166
Jacob Dufaultffd9b0d2017-11-15 23:07:16167void LoginScreenController::RecordClickOnLockIcon(const AccountId& account_id) {
168 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32169 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16170 login_screen_client_->RecordClickOnLockIcon(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32171}
172
Jacob Dufaultffd9b0d2017-11-15 23:07:16173void LoginScreenController::OnFocusPod(const AccountId& account_id) {
174 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27175 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16176 login_screen_client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27177}
178
Jacob Dufaultffd9b0d2017-11-15 23:07:16179void LoginScreenController::OnNoPodFocused() {
180 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27181 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16182 login_screen_client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27183}
184
Jacob Dufaultffd9b0d2017-11-15 23:07:16185void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
186 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27187 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16188 login_screen_client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27189}
190
Jacob Dufaultffd9b0d2017-11-15 23:07:16191void LoginScreenController::SignOutUser() {
192 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27193 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16194 login_screen_client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27195}
196
Jacob Dufaultffd9b0d2017-11-15 23:07:16197void LoginScreenController::CancelAddUser() {
198 if (!login_screen_client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30199 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16200 login_screen_client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30201}
202
Aga Wronska6a32f9872018-01-06 00:16:10203void LoginScreenController::LoginAsGuest() {
204 if (!login_screen_client_)
205 return;
206 login_screen_client_->LoginAsGuest();
207}
208
Jacob Dufaultffd9b0d2017-11-15 23:07:16209void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27210 const AccountId& account_id) {
Jacob Dufaultffd9b0d2017-11-15 23:07:16211 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27212 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16213 login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27214}
215
Jacob Dufaultffd9b0d2017-11-15 23:07:16216void LoginScreenController::FocusLockScreenApps(bool reverse) {
217 if (!login_screen_client_)
Toni Barzicf61c4452017-10-05 03:57:48218 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16219 login_screen_client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48220}
221
Wenzhao Zang767a9f32018-05-02 21:20:55222void LoginScreenController::ShowGaiaSignin(
Jacob Dufaultfb72607d2018-06-12 19:50:33223 bool can_close,
224 const base::Optional<AccountId>& prefilled_account) {
Sarah Hu9fba0e752018-02-07 01:41:09225 if (!login_screen_client_)
226 return;
Jacob Dufaultfb72607d2018-06-12 19:50:33227 login_screen_client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09228}
229
Jacob Dufaultfc31c742018-03-20 17:32:19230void LoginScreenController::OnRemoveUserWarningShown() {
231 if (!login_screen_client_)
232 return;
233 login_screen_client_->OnRemoveUserWarningShown();
234}
235
236void LoginScreenController::RemoveUser(const AccountId& account_id) {
237 if (!login_screen_client_)
238 return;
239 login_screen_client_->RemoveUser(account_id);
240}
241
Sarah Hu3fcf9f82018-03-22 20:32:54242void LoginScreenController::LaunchPublicSession(
243 const AccountId& account_id,
244 const std::string& locale,
245 const std::string& input_method) {
246 if (!login_screen_client_)
247 return;
248 login_screen_client_->LaunchPublicSession(account_id, locale, input_method);
249}
250
Sarah Huf9affb122018-04-27 21:36:36251void LoginScreenController::RequestPublicSessionKeyboardLayouts(
252 const AccountId& account_id,
253 const std::string& locale) {
254 if (!login_screen_client_)
255 return;
256 login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
257}
258
Sarah Hu0007c932018-06-18 20:21:04259void LoginScreenController::ShowFeedback() {
260 if (!login_screen_client_)
261 return;
262 login_screen_client_->ShowFeedback();
263}
264
Jacob Dufault589d9942018-03-27 20:28:47265void LoginScreenController::AddObserver(
266 LoginScreenControllerObserver* observer) {
267 observers_.AddObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48268}
269
Jacob Dufault589d9942018-03-27 20:28:47270void LoginScreenController::RemoveObserver(
271 LoginScreenControllerObserver* observer) {
272 observers_.RemoveObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48273}
274
Jacob Dufaultffd9b0d2017-11-15 23:07:16275void LoginScreenController::FlushForTesting() {
276 login_screen_client_.FlushForTesting();
Toni Barzicf61c4452017-10-05 03:57:48277}
278
Jacob Dufault589d9942018-03-27 20:28:47279void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) {
280 login_screen_client_ = std::move(client);
281}
282
283void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
284 OnShow();
285 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock);
286 std::move(on_shown).Run(true);
287}
288
289void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) {
290 // Login screen can only be used during login.
291 if (Shell::Get()->session_controller()->GetSessionState() !=
292 session_manager::SessionState::LOGIN_PRIMARY) {
293 LOG(ERROR) << "Not showing login screen since session state is "
294 << static_cast<int>(
295 Shell::Get()->session_controller()->GetSessionState());
296 std::move(on_shown).Run(false);
297 return;
298 }
299
300 OnShow();
301 // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen.
302 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin);
303 std::move(on_shown).Run(true);
304}
305
306void LoginScreenController::ShowErrorMessage(int32_t login_attempts,
307 const std::string& error_text,
308 const std::string& help_link_text,
309 int32_t help_topic_id) {
310 NOTIMPLEMENTED();
311}
312
Naoki Fukino00a14cbc2018-08-08 05:27:22313void LoginScreenController::ShowWarningBanner(const base::string16& message) {
314 if (DataDispatcher())
315 DataDispatcher()->ShowWarningBanner(message);
316}
317
318void LoginScreenController::HideWarningBanner() {
319 if (DataDispatcher())
320 DataDispatcher()->HideWarningBanner();
321}
322
Jacob Dufault589d9942018-03-27 20:28:47323void LoginScreenController::ClearErrors() {
324 NOTIMPLEMENTED();
325}
326
327void LoginScreenController::ShowUserPodCustomIcon(
328 const AccountId& account_id,
329 mojom::EasyUnlockIconOptionsPtr icon) {
330 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon);
331}
332
333void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
334 auto icon_options = mojom::EasyUnlockIconOptions::New();
335 icon_options->icon = mojom::EasyUnlockIconId::NONE;
336 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options);
337}
338
339void LoginScreenController::SetAuthType(
340 const AccountId& account_id,
341 proximity_auth::mojom::AuthType auth_type,
342 const base::string16& initial_value) {
343 if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
Jacob Dufault21cd5662018-08-07 18:04:33344 DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
345 true /*enabled*/);
Wenzhao Zang767a9f32018-05-02 21:20:55346 } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
347 DataDispatcher()->SetForceOnlineSignInForUser(account_id);
Jacob Dufault589d9942018-03-27 20:28:47348 } else {
349 NOTIMPLEMENTED();
350 }
351}
352
Sarah Hu51d19d32018-08-27 19:41:50353void LoginScreenController::SetUserList(
354 std::vector<mojom::LoginUserInfoPtr> users) {
Jacob Dufault589d9942018-03-27 20:28:47355 DCHECK(DataDispatcher());
356
357 DataDispatcher()->NotifyUsers(users);
358}
359
360void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
361 bool is_enabled) {
362 // Chrome will update pin pod state every time user tries to authenticate.
363 // LockScreen is destroyed in the case of authentication success.
364 if (DataDispatcher())
365 DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled);
366}
367
Jacob Dufault77d75ce92018-04-13 18:20:09368void LoginScreenController::SetAvatarForUser(const AccountId& account_id,
369 mojom::UserAvatarPtr avatar) {
370 for (auto& observer : observers_)
371 observer.SetAvatarForUser(account_id, avatar);
372}
373
Wenzhao Zange0c2ab22018-05-23 17:43:46374void LoginScreenController::SetAuthEnabledForUser(
375 const AccountId& account_id,
376 bool is_enabled,
377 base::Optional<base::Time> auth_reenabled_time) {
378 if (DataDispatcher()) {
379 DataDispatcher()->SetAuthEnabledForUser(account_id, is_enabled,
380 auth_reenabled_time);
381 }
382}
383
Jacob Dufault589d9942018-03-27 20:28:47384void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) {
385 for (auto& observer : observers_)
386 observer.OnFocusLeavingLockScreenApps(reverse);
387}
388
389void LoginScreenController::SetDevChannelInfo(
390 const std::string& os_version_label_text,
391 const std::string& enterprise_info_text,
392 const std::string& bluetooth_name) {
393 if (DataDispatcher()) {
394 DataDispatcher()->SetDevChannelInfo(os_version_label_text,
395 enterprise_info_text, bluetooth_name);
396 }
397}
398
399void LoginScreenController::IsReadyForPassword(
400 IsReadyForPasswordCallback callback) {
Jacob Dufault2ca8c502018-06-25 19:12:14401 std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating());
Jacob Dufault589d9942018-03-27 20:28:47402}
403
404void LoginScreenController::SetPublicSessionDisplayName(
405 const AccountId& account_id,
406 const std::string& display_name) {
407 if (DataDispatcher())
408 DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name);
409}
410
411void LoginScreenController::SetPublicSessionLocales(
412 const AccountId& account_id,
Sarah Hue9cd6132018-05-17 17:25:56413 std::vector<mojom::LocaleItemPtr> locales,
Jacob Dufault589d9942018-03-27 20:28:47414 const std::string& default_locale,
415 bool show_advanced_view) {
416 if (DataDispatcher()) {
417 DataDispatcher()->SetPublicSessionLocales(
Sarah Hue9cd6132018-05-17 17:25:56418 account_id, locales, default_locale, show_advanced_view);
Jacob Dufault589d9942018-03-27 20:28:47419 }
420}
421
Sarah Huf9affb122018-04-27 21:36:36422void LoginScreenController::SetPublicSessionKeyboardLayouts(
423 const AccountId& account_id,
424 const std::string& locale,
425 std::vector<mojom::InputMethodItemPtr> keyboard_layouts) {
426 if (DataDispatcher()) {
427 DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale,
428 keyboard_layouts);
429 }
430}
431
Sarah Hu1a7de562018-05-14 17:18:22432void LoginScreenController::SetFingerprintUnlockState(
433 const AccountId& account_id,
434 mojom::FingerprintUnlockState state) {
435 if (DataDispatcher())
436 DataDispatcher()->SetFingerprintUnlockState(account_id, state);
437}
438
Quan Nguyend09dd112018-06-19 19:20:32439void LoginScreenController::SetKioskApps(
440 std::vector<mojom::KioskAppInfoPtr> kiosk_apps) {
441 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
442 ->shelf_widget()
Jacob Dufault5ac266ef2018-07-18 17:30:30443 ->login_shelf_view()
444 ->SetKioskApps(std::move(kiosk_apps));
Quan Nguyend09dd112018-06-19 19:20:32445}
446
Quan Nguyenb7c2ea22018-09-10 17:44:18447void LoginScreenController::ShowKioskAppError(const std::string& message) {
448 ToastData toast_data(
449 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
450 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
451 true /*visible_on_lock_screen*/);
452 Shell::Get()->toast_manager()->Show(toast_data);
453}
454
Sarah Hu51d19d32018-08-27 19:41:50455void LoginScreenController::NotifyOobeDialogState(
456 mojom::OobeDialogState state) {
Quan Nguyenc6ff3152018-08-07 20:00:37457 for (auto& observer : observers_)
Sarah Hu51d19d32018-08-27 19:41:50458 observer.OnOobeDialogStateChanged(state);
459}
460
461void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
462 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
463 ->shelf_widget()
464 ->login_shelf_view()
465 ->SetAllowLoginAsGuest(allow_guest);
466}
467
468void LoginScreenController::SetShowGuestButtonForGaiaScreen(bool can_show) {
469 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
470 ->shelf_widget()
471 ->login_shelf_view()
472 ->SetShowGuestButtonForGaiaScreen(can_show);
Jacob Dufault883dcf72018-06-27 22:52:32473}
474
Quan Nguyen3d7a0f02018-09-04 23:53:55475void LoginScreenController::FocusLoginShelf(bool reverse) {
476 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
477 // Tell the focus direction to the status area or the shelf so they can focus
478 // the correct child view.
479 if (reverse) {
480 shelf->GetStatusAreaWidget()
481 ->status_area_widget_delegate()
482 ->set_default_last_focusable_child(reverse);
483 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
484 } else {
485 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
486 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
487 }
488}
489
Sarah Hu4976046e2018-07-19 23:47:47490void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
491 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
492 ->shelf_widget()
493 ->login_shelf_view()
494 ->SetAddUserButtonEnabled(enable);
495}
496
Quan Nguyend09dd112018-06-19 19:20:32497void LoginScreenController::LaunchKioskApp(const std::string& app_id) {
498 login_screen_client_->LaunchKioskApp(app_id);
499}
500
Quan Nguyena3c54cf2018-07-03 17:56:50501void LoginScreenController::LaunchArcKioskApp(const AccountId& account_id) {
502 login_screen_client_->LaunchArcKioskApp(account_id);
503}
504
Quan Nguyene3e1d252018-07-19 23:00:44505void LoginScreenController::ShowResetScreen() {
506 login_screen_client_->ShowResetScreen();
507}
508
Quan Nguyenff20e232018-08-02 21:34:11509void LoginScreenController::ShowAccountAccessHelpApp() {
510 login_screen_client_->ShowAccountAccessHelpApp();
511}
512
Quan Nguyen3d7a0f02018-09-04 23:53:55513void LoginScreenController::FocusOobeDialog() {
514 login_screen_client_->FocusOobeDialog();
515}
516
Jacob Dufaultb7a2d842017-12-01 23:21:15517void LoginScreenController::DoAuthenticateUser(const AccountId& account_id,
518 const std::string& password,
519 bool authenticated_by_pin,
520 OnAuthenticateCallback callback,
521 const std::string& system_salt) {
Jacob Dufault2d20ae62018-09-20 22:19:52522 // TODO(jdufault): Simplify this, system_salt is no longer used so fetching
523 // the system salt can be skipped.
Jacob Dufault8876ba82018-03-27 22:55:43524 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
525
Sarah Hu069eea12017-09-08 01:28:40526 int dummy_value;
527 bool is_pin =
528 authenticated_by_pin && base::StringToInt(password, &dummy_value);
Jacob Dufault2d20ae62018-09-20 22:19:52529 login_screen_client_->AuthenticateUserWithPasswordOrPin(
Jacob Dufault2be71002018-05-16 17:07:43530 account_id, password, is_pin,
Jacob Dufaultb7a2d842017-12-01 23:21:15531 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
532 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
jdufaulteb4c9f1e2017-06-08 23:08:30533}
534
Jacob Dufaultb7a2d842017-12-01 23:21:15535void LoginScreenController::OnAuthenticateComplete(
536 OnAuthenticateCallback callback,
537 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43538 authentication_stage_ = AuthenticationStage::kUserCallback;
Jacob Dufaultb7a2d842017-12-01 23:21:15539 std::move(callback).Run(success);
Jacob Dufault8876ba82018-03-27 22:55:43540 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42541}
542
Jacob Dufaultffd9b0d2017-11-15 23:07:16543LoginDataDispatcher* LoginScreenController::DataDispatcher() const {
Wenzhao Zang733497282018-06-12 16:53:10544 if (!ash::LockScreen::HasInstance())
Jacob Dufault40623d52017-09-15 17:22:53545 return nullptr;
546 return ash::LockScreen::Get()->data_dispatcher();
547}
548
Jacob Dufaultcbc1ee02018-02-28 18:38:54549void LoginScreenController::OnShow() {
550 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17551 if (authentication_stage_ != AuthenticationStage::kIdle) {
552 AuthenticationStage authentication_stage = authentication_stage_;
553 base::debug::Alias(&authentication_stage);
554 LOG(FATAL) << "Unexpected authentication stage "
555 << static_cast<int>(authentication_stage_);
556 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54557}
558
xiaoyinh2bbdd102017-05-18 23:29:42559} // namespace ash