[go: nahoru, domu]

blob: df05495380db1634c307b1c68ffbea5476403d49 [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"
Quan Nguyend09dd112018-06-19 19:20:3211#include "ash/login/ui/lock_window.h"
Jacob Dufault40623d52017-09-15 17:22:5312#include "ash/login/ui/login_data_dispatcher.h"
Sarah Hu069eea12017-09-08 01:28:4013#include "ash/public/cpp/ash_pref_names.h"
Aga Wronska16abb432018-01-11 23:49:5914#include "ash/root_window_controller.h"
Sarah Hu069eea12017-09-08 01:28:4015#include "ash/session/session_controller.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3016#include "ash/shelf/login_shelf_view.h"
Quan Nguyend09dd112018-06-19 19:20:3217#include "ash/shelf/shelf.h"
18#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4019#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5920#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5521#include "ash/system/status_area_widget_delegate.h"
Quan Nguyenb7c2ea22018-09-10 17:44:1822#include "ash/system/toast/toast_data.h"
23#include "ash/system/toast/toast_manager.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"
xiaoyinh2bbdd102017-05-18 23:29:4228#include "chromeos/cryptohome/system_salt_getter.h"
Sarah Hu069eea12017-09-08 01:28:4029#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0930#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4231
32namespace ash {
33
Sarah Hu069eea12017-09-08 01:28:4034namespace {
xiaoyinh2bbdd102017-05-18 23:29:4235
Aga Wronskaa844cdcd12018-01-29 16:06:4436enum class SystemTrayVisibility {
37 kNone, // Tray not visible anywhere.
38 kPrimary, // Tray visible only on primary display.
39 kAll, // Tray visible on all displays.
40};
41
42void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
43 RootWindowController* primary_window_controller =
44 Shell::GetPrimaryRootWindowController();
45 for (RootWindowController* window_controller :
46 Shell::GetAllRootWindowControllers()) {
47 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
48 if (!status_area)
49 continue;
50 if (window_controller == primary_window_controller) {
51 status_area->SetSystemTrayVisibility(
52 visibility == SystemTrayVisibility::kPrimary ||
53 visibility == SystemTrayVisibility::kAll);
54 } else {
55 status_area->SetSystemTrayVisibility(visibility ==
56 SystemTrayVisibility::kAll);
57 }
58 }
Aga Wronska16abb432018-01-11 23:49:5959}
60
Sarah Hu069eea12017-09-08 01:28:4061} // namespace
62
James Cookede316a2017-12-14 22:38:4363LoginScreenController::LoginScreenController() : weak_factory_(this) {}
James Cook8f1e6062017-11-13 23:40:5964
Jacob Dufaultffd9b0d2017-11-15 23:07:1665LoginScreenController::~LoginScreenController() = default;
xiaoyinh2bbdd102017-05-18 23:29:4266
Sarah Hu069eea12017-09-08 01:28:4067// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1668void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
69 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4070 if (for_test) {
71 // There is no remote pref service, so pretend that ash owns the pref.
72 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
73 return;
74 }
75
76 // Pref is owned by chrome and flagged as PUBLIC.
77 registry->RegisterForeignPref(prefs::kQuickUnlockPinSalt);
78}
79
Jacob Dufaultffd9b0d2017-11-15 23:07:1680void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) {
James Cookede316a2017-12-14 22:38:4381 bindings_.AddBinding(this, std::move(request));
xiaoyinh2bbdd102017-05-18 23:29:4282}
83
Jacob Dufault2ca8c502018-06-25 19:12:1484bool LoginScreenController::IsAuthenticating() const {
85 return authentication_stage_ != AuthenticationStage::kIdle;
86}
87
Jacob Dufault2d20ae62018-09-20 22:19:5288void LoginScreenController::AuthenticateUserWithPasswordOrPin(
89 const AccountId& account_id,
90 const std::string& password,
91 bool authenticated_by_pin,
92 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4393 // It is an error to call this function while an authentication is in
94 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:5295 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:5696 << "Duplicate authentication attempt; current authentication stage is "
97 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:4398
99 if (!login_screen_client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:15100 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32101 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15102 }
xiaoyinh9f6fa0e2017-06-07 19:22:32103
Jacob Dufaulteafc6fe2017-10-11 21:16:52104 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
105 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24106 switch (force_fail_auth_for_debug_overlay_) {
107 case ForceFailAuth::kOff:
108 break;
109 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15110 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24111 return;
112 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14113 // Set a dummy authentication stage so that |IsAuthenticating| returns
114 // true.
115 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24116 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15117 FROM_HERE,
118 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
119 weak_factory_.GetWeakPtr(), base::Passed(&callback),
120 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24121 base::TimeDelta::FromSeconds(1));
122 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52123 }
124
Jacob Dufault8876ba82018-03-27 22:55:43125 // |DoAuthenticateUser| requires the system salt.
126 authentication_stage_ = AuthenticationStage::kGetSystemSalt;
127 chromeos::SystemSaltGetter::Get()->GetSystemSalt(
128 base::AdaptCallbackForRepeating(
129 base::BindOnce(&LoginScreenController::DoAuthenticateUser,
130 weak_factory_.GetWeakPtr(), account_id, password,
131 authenticated_by_pin, std::move(callback))));
xiaoyinh9f6fa0e2017-06-07 19:22:32132}
133
Jacob Dufault2d20ae62018-09-20 22:19:52134void LoginScreenController::AuthenticateUserWithExternalBinary(
135 const AccountId& account_id,
136 OnAuthenticateCallback callback) {
137 // It is an error to call this function while an authentication is in
138 // progress.
139 LOG_IF(FATAL, IsAuthenticating())
140 << "Duplicate authentication attempt; current authentication stage is "
141 << static_cast<int>(authentication_stage_);
142
143 if (!login_screen_client_) {
144 std::move(callback).Run(base::nullopt);
145 return;
146 }
147
148 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
149 login_screen_client_->AuthenticateUserWithExternalBinary(
150 account_id,
151 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
152 weak_factory_.GetWeakPtr(), std::move(callback)));
153}
154
Quan Nguyen92f924a2018-10-18 18:36:46155void LoginScreenController::EnrollUserWithExternalBinary(
156 OnAuthenticateCallback callback) {
157 if (!login_screen_client_) {
158 std::move(callback).Run(base::nullopt);
159 return;
160 }
161
162 login_screen_client_->EnrollUserWithExternalBinary(base::BindOnce(
163 [](OnAuthenticateCallback callback, bool success) {
164 std::move(callback).Run(base::make_optional<bool>(success));
165 },
166 std::move(callback)));
167}
168
Jacob Dufault2d20ae62018-09-20 22:19:52169void LoginScreenController::AuthenticateUserWithEasyUnlock(
170 const AccountId& account_id) {
171 // TODO(jdufault): integrate this into authenticate stage after mojom is
172 // refactored to use a callback.
Jacob Dufaultffd9b0d2017-11-15 23:07:16173 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32174 return;
Jacob Dufault2d20ae62018-09-20 22:19:52175 login_screen_client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32176}
177
Jacob Dufaultffd9b0d2017-11-15 23:07:16178void LoginScreenController::HardlockPod(const AccountId& account_id) {
179 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32180 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16181 login_screen_client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32182}
183
Jacob Dufaultffd9b0d2017-11-15 23:07:16184void LoginScreenController::RecordClickOnLockIcon(const AccountId& account_id) {
185 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32186 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16187 login_screen_client_->RecordClickOnLockIcon(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32188}
189
Jacob Dufaultffd9b0d2017-11-15 23:07:16190void LoginScreenController::OnFocusPod(const AccountId& account_id) {
191 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27192 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16193 login_screen_client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27194}
195
Jacob Dufaultffd9b0d2017-11-15 23:07:16196void LoginScreenController::OnNoPodFocused() {
197 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27198 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16199 login_screen_client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27200}
201
Jacob Dufaultffd9b0d2017-11-15 23:07:16202void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
203 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27204 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16205 login_screen_client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27206}
207
Jacob Dufaultffd9b0d2017-11-15 23:07:16208void LoginScreenController::SignOutUser() {
209 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27210 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16211 login_screen_client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27212}
213
Jacob Dufaultffd9b0d2017-11-15 23:07:16214void LoginScreenController::CancelAddUser() {
215 if (!login_screen_client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30216 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16217 login_screen_client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30218}
219
Aga Wronska6a32f9872018-01-06 00:16:10220void LoginScreenController::LoginAsGuest() {
221 if (!login_screen_client_)
222 return;
223 login_screen_client_->LoginAsGuest();
224}
225
Jacob Dufaultffd9b0d2017-11-15 23:07:16226void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27227 const AccountId& account_id) {
Jacob Dufaultffd9b0d2017-11-15 23:07:16228 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27229 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16230 login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27231}
232
Jacob Dufaultffd9b0d2017-11-15 23:07:16233void LoginScreenController::FocusLockScreenApps(bool reverse) {
234 if (!login_screen_client_)
Toni Barzicf61c4452017-10-05 03:57:48235 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16236 login_screen_client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48237}
238
Wenzhao Zang767a9f32018-05-02 21:20:55239void LoginScreenController::ShowGaiaSignin(
Jacob Dufaultfb72607d2018-06-12 19:50:33240 bool can_close,
241 const base::Optional<AccountId>& prefilled_account) {
Sarah Hu9fba0e752018-02-07 01:41:09242 if (!login_screen_client_)
243 return;
Jacob Dufaultfb72607d2018-06-12 19:50:33244 login_screen_client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09245}
246
Jacob Dufaultfc31c742018-03-20 17:32:19247void LoginScreenController::OnRemoveUserWarningShown() {
248 if (!login_screen_client_)
249 return;
250 login_screen_client_->OnRemoveUserWarningShown();
251}
252
253void LoginScreenController::RemoveUser(const AccountId& account_id) {
254 if (!login_screen_client_)
255 return;
256 login_screen_client_->RemoveUser(account_id);
257}
258
Sarah Hu3fcf9f82018-03-22 20:32:54259void LoginScreenController::LaunchPublicSession(
260 const AccountId& account_id,
261 const std::string& locale,
262 const std::string& input_method) {
263 if (!login_screen_client_)
264 return;
265 login_screen_client_->LaunchPublicSession(account_id, locale, input_method);
266}
267
Sarah Huf9affb122018-04-27 21:36:36268void LoginScreenController::RequestPublicSessionKeyboardLayouts(
269 const AccountId& account_id,
270 const std::string& locale) {
271 if (!login_screen_client_)
272 return;
273 login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
274}
275
Sarah Hu0007c932018-06-18 20:21:04276void LoginScreenController::ShowFeedback() {
277 if (!login_screen_client_)
278 return;
279 login_screen_client_->ShowFeedback();
280}
281
Jacob Dufault589d9942018-03-27 20:28:47282void LoginScreenController::AddObserver(
283 LoginScreenControllerObserver* observer) {
284 observers_.AddObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48285}
286
Jacob Dufault589d9942018-03-27 20:28:47287void LoginScreenController::RemoveObserver(
288 LoginScreenControllerObserver* observer) {
289 observers_.RemoveObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48290}
291
Jacob Dufaultffd9b0d2017-11-15 23:07:16292void LoginScreenController::FlushForTesting() {
293 login_screen_client_.FlushForTesting();
Toni Barzicf61c4452017-10-05 03:57:48294}
295
Jacob Dufault589d9942018-03-27 20:28:47296void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) {
297 login_screen_client_ = std::move(client);
298}
299
300void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
301 OnShow();
302 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock);
303 std::move(on_shown).Run(true);
304}
305
306void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) {
307 // Login screen can only be used during login.
308 if (Shell::Get()->session_controller()->GetSessionState() !=
309 session_manager::SessionState::LOGIN_PRIMARY) {
310 LOG(ERROR) << "Not showing login screen since session state is "
311 << static_cast<int>(
312 Shell::Get()->session_controller()->GetSessionState());
313 std::move(on_shown).Run(false);
314 return;
315 }
316
317 OnShow();
318 // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen.
319 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin);
320 std::move(on_shown).Run(true);
321}
322
323void LoginScreenController::ShowErrorMessage(int32_t login_attempts,
324 const std::string& error_text,
325 const std::string& help_link_text,
326 int32_t help_topic_id) {
327 NOTIMPLEMENTED();
328}
329
Naoki Fukino00a14cbc2018-08-08 05:27:22330void LoginScreenController::ShowWarningBanner(const base::string16& message) {
331 if (DataDispatcher())
332 DataDispatcher()->ShowWarningBanner(message);
333}
334
335void LoginScreenController::HideWarningBanner() {
336 if (DataDispatcher())
337 DataDispatcher()->HideWarningBanner();
338}
339
Jacob Dufault589d9942018-03-27 20:28:47340void LoginScreenController::ClearErrors() {
341 NOTIMPLEMENTED();
342}
343
344void LoginScreenController::ShowUserPodCustomIcon(
345 const AccountId& account_id,
346 mojom::EasyUnlockIconOptionsPtr icon) {
347 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon);
348}
349
350void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
351 auto icon_options = mojom::EasyUnlockIconOptions::New();
352 icon_options->icon = mojom::EasyUnlockIconId::NONE;
353 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options);
354}
355
356void LoginScreenController::SetAuthType(
357 const AccountId& account_id,
358 proximity_auth::mojom::AuthType auth_type,
359 const base::string16& initial_value) {
360 if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
Jacob Dufault21cd5662018-08-07 18:04:33361 DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
362 true /*enabled*/);
Wenzhao Zang767a9f32018-05-02 21:20:55363 } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
364 DataDispatcher()->SetForceOnlineSignInForUser(account_id);
Jacob Dufault589d9942018-03-27 20:28:47365 } else {
366 NOTIMPLEMENTED();
367 }
368}
369
Sarah Hu51d19d32018-08-27 19:41:50370void LoginScreenController::SetUserList(
371 std::vector<mojom::LoginUserInfoPtr> users) {
Jacob Dufault589d9942018-03-27 20:28:47372 DCHECK(DataDispatcher());
373
374 DataDispatcher()->NotifyUsers(users);
375}
376
377void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
378 bool is_enabled) {
379 // Chrome will update pin pod state every time user tries to authenticate.
380 // LockScreen is destroyed in the case of authentication success.
381 if (DataDispatcher())
382 DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled);
383}
384
Jacob Dufault77d75ce92018-04-13 18:20:09385void LoginScreenController::SetAvatarForUser(const AccountId& account_id,
386 mojom::UserAvatarPtr avatar) {
387 for (auto& observer : observers_)
388 observer.SetAvatarForUser(account_id, avatar);
389}
390
Wenzhao Zange0c2ab22018-05-23 17:43:46391void LoginScreenController::SetAuthEnabledForUser(
392 const AccountId& account_id,
393 bool is_enabled,
394 base::Optional<base::Time> auth_reenabled_time) {
395 if (DataDispatcher()) {
396 DataDispatcher()->SetAuthEnabledForUser(account_id, is_enabled,
397 auth_reenabled_time);
398 }
399}
400
Jacob Dufault589d9942018-03-27 20:28:47401void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) {
402 for (auto& observer : observers_)
403 observer.OnFocusLeavingLockScreenApps(reverse);
404}
405
Jacob Dufault5fc31392018-10-03 22:15:02406void LoginScreenController::SetSystemInfo(
407 bool show_if_hidden,
Jacob Dufault589d9942018-03-27 20:28:47408 const std::string& os_version_label_text,
409 const std::string& enterprise_info_text,
410 const std::string& bluetooth_name) {
411 if (DataDispatcher()) {
Jacob Dufault5fc31392018-10-03 22:15:02412 DataDispatcher()->SetSystemInfo(show_if_hidden, os_version_label_text,
413 enterprise_info_text, bluetooth_name);
Jacob Dufault589d9942018-03-27 20:28:47414 }
415}
416
417void LoginScreenController::IsReadyForPassword(
418 IsReadyForPasswordCallback callback) {
Jacob Dufault2ca8c502018-06-25 19:12:14419 std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating());
Jacob Dufault589d9942018-03-27 20:28:47420}
421
422void LoginScreenController::SetPublicSessionDisplayName(
423 const AccountId& account_id,
424 const std::string& display_name) {
425 if (DataDispatcher())
426 DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name);
427}
428
429void LoginScreenController::SetPublicSessionLocales(
430 const AccountId& account_id,
Sarah Hue9cd6132018-05-17 17:25:56431 std::vector<mojom::LocaleItemPtr> locales,
Jacob Dufault589d9942018-03-27 20:28:47432 const std::string& default_locale,
433 bool show_advanced_view) {
434 if (DataDispatcher()) {
435 DataDispatcher()->SetPublicSessionLocales(
Sarah Hue9cd6132018-05-17 17:25:56436 account_id, locales, default_locale, show_advanced_view);
Jacob Dufault589d9942018-03-27 20:28:47437 }
438}
439
Sarah Huf9affb122018-04-27 21:36:36440void LoginScreenController::SetPublicSessionKeyboardLayouts(
441 const AccountId& account_id,
442 const std::string& locale,
443 std::vector<mojom::InputMethodItemPtr> keyboard_layouts) {
444 if (DataDispatcher()) {
445 DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale,
446 keyboard_layouts);
447 }
448}
449
Sarah Hu1a7de562018-05-14 17:18:22450void LoginScreenController::SetFingerprintUnlockState(
451 const AccountId& account_id,
452 mojom::FingerprintUnlockState state) {
453 if (DataDispatcher())
454 DataDispatcher()->SetFingerprintUnlockState(account_id, state);
455}
456
Quan Nguyend09dd112018-06-19 19:20:32457void LoginScreenController::SetKioskApps(
458 std::vector<mojom::KioskAppInfoPtr> kiosk_apps) {
459 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
460 ->shelf_widget()
Jacob Dufault5ac266ef2018-07-18 17:30:30461 ->login_shelf_view()
462 ->SetKioskApps(std::move(kiosk_apps));
Quan Nguyend09dd112018-06-19 19:20:32463}
464
Quan Nguyenb7c2ea22018-09-10 17:44:18465void LoginScreenController::ShowKioskAppError(const std::string& message) {
466 ToastData toast_data(
467 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
468 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
469 true /*visible_on_lock_screen*/);
470 Shell::Get()->toast_manager()->Show(toast_data);
471}
472
Sarah Hu51d19d32018-08-27 19:41:50473void LoginScreenController::NotifyOobeDialogState(
474 mojom::OobeDialogState state) {
Quan Nguyenc6ff3152018-08-07 20:00:37475 for (auto& observer : observers_)
Sarah Hu51d19d32018-08-27 19:41:50476 observer.OnOobeDialogStateChanged(state);
477}
478
479void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
480 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
481 ->shelf_widget()
482 ->login_shelf_view()
483 ->SetAllowLoginAsGuest(allow_guest);
484}
485
486void LoginScreenController::SetShowGuestButtonForGaiaScreen(bool can_show) {
487 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
488 ->shelf_widget()
489 ->login_shelf_view()
490 ->SetShowGuestButtonForGaiaScreen(can_show);
Jacob Dufault883dcf72018-06-27 22:52:32491}
492
Quan Nguyen3d7a0f02018-09-04 23:53:55493void LoginScreenController::FocusLoginShelf(bool reverse) {
494 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
495 // Tell the focus direction to the status area or the shelf so they can focus
496 // the correct child view.
497 if (reverse) {
498 shelf->GetStatusAreaWidget()
499 ->status_area_widget_delegate()
500 ->set_default_last_focusable_child(reverse);
501 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
502 } else {
503 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
504 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
505 }
506}
507
Sarah Hu4976046e2018-07-19 23:47:47508void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
509 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
510 ->shelf_widget()
511 ->login_shelf_view()
512 ->SetAddUserButtonEnabled(enable);
513}
514
Quan Nguyend09dd112018-06-19 19:20:32515void LoginScreenController::LaunchKioskApp(const std::string& app_id) {
516 login_screen_client_->LaunchKioskApp(app_id);
517}
518
Quan Nguyena3c54cf2018-07-03 17:56:50519void LoginScreenController::LaunchArcKioskApp(const AccountId& account_id) {
520 login_screen_client_->LaunchArcKioskApp(account_id);
521}
522
Quan Nguyene3e1d252018-07-19 23:00:44523void LoginScreenController::ShowResetScreen() {
524 login_screen_client_->ShowResetScreen();
525}
526
Quan Nguyenff20e232018-08-02 21:34:11527void LoginScreenController::ShowAccountAccessHelpApp() {
528 login_screen_client_->ShowAccountAccessHelpApp();
529}
530
Quan Nguyen3d7a0f02018-09-04 23:53:55531void LoginScreenController::FocusOobeDialog() {
532 login_screen_client_->FocusOobeDialog();
533}
534
Jacob Dufaultb7a2d842017-12-01 23:21:15535void LoginScreenController::DoAuthenticateUser(const AccountId& account_id,
536 const std::string& password,
537 bool authenticated_by_pin,
538 OnAuthenticateCallback callback,
539 const std::string& system_salt) {
Jacob Dufault2d20ae62018-09-20 22:19:52540 // TODO(jdufault): Simplify this, system_salt is no longer used so fetching
541 // the system salt can be skipped.
Jacob Dufault8876ba82018-03-27 22:55:43542 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
543
Sarah Hu069eea12017-09-08 01:28:40544 int dummy_value;
545 bool is_pin =
546 authenticated_by_pin && base::StringToInt(password, &dummy_value);
Jacob Dufault2d20ae62018-09-20 22:19:52547 login_screen_client_->AuthenticateUserWithPasswordOrPin(
Jacob Dufault2be71002018-05-16 17:07:43548 account_id, password, is_pin,
Jacob Dufaultb7a2d842017-12-01 23:21:15549 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
550 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
jdufaulteb4c9f1e2017-06-08 23:08:30551}
552
Jacob Dufaultb7a2d842017-12-01 23:21:15553void LoginScreenController::OnAuthenticateComplete(
554 OnAuthenticateCallback callback,
555 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43556 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46557 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43558 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42559}
560
Jacob Dufaultffd9b0d2017-11-15 23:07:16561LoginDataDispatcher* LoginScreenController::DataDispatcher() const {
Wenzhao Zang733497282018-06-12 16:53:10562 if (!ash::LockScreen::HasInstance())
Jacob Dufault40623d52017-09-15 17:22:53563 return nullptr;
564 return ash::LockScreen::Get()->data_dispatcher();
565}
566
Jacob Dufaultcbc1ee02018-02-28 18:38:54567void LoginScreenController::OnShow() {
568 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17569 if (authentication_stage_ != AuthenticationStage::kIdle) {
570 AuthenticationStage authentication_stage = authentication_stage_;
571 base::debug::Alias(&authentication_stage);
572 LOG(FATAL) << "Unexpected authentication stage "
573 << static_cast<int>(authentication_stage_);
574 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54575}
576
xiaoyinh2bbdd102017-05-18 23:29:42577} // namespace ash