[go: nahoru, domu]

blob: 916c0e5b58aa22e0aa5ec07c570f2c2a0206b8e1 [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"
Jun Mukai5c7b5b42018-11-30 00:08:5024#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4625#include "base/bind.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1726#include "base/debug/alias.h"
Sarah Hu069eea12017-09-08 01:28:4027#include "base/strings/string_number_conversions.h"
Jialiu Linf99b788b2018-01-17 23:01:2128#include "base/strings/utf_string_conversions.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
Jun Mukai5c7b5b42018-11-30 00:08:5063LoginScreenController::LoginScreenController(
64 SystemTrayNotifier* system_tray_notifier)
65 : system_tray_notifier_(system_tray_notifier), weak_factory_(this) {
66 system_tray_notifier_->AddSystemTrayFocusObserver(this);
67}
James Cook8f1e6062017-11-13 23:40:5968
Jun Mukai5c7b5b42018-11-30 00:08:5069LoginScreenController::~LoginScreenController() {
70 system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
71}
xiaoyinh2bbdd102017-05-18 23:29:4272
Sarah Hu069eea12017-09-08 01:28:4073// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1674void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
75 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4076 if (for_test) {
77 // There is no remote pref service, so pretend that ash owns the pref.
78 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
79 return;
80 }
81
82 // Pref is owned by chrome and flagged as PUBLIC.
83 registry->RegisterForeignPref(prefs::kQuickUnlockPinSalt);
84}
85
Jacob Dufaultffd9b0d2017-11-15 23:07:1686void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) {
James Cookede316a2017-12-14 22:38:4387 bindings_.AddBinding(this, std::move(request));
xiaoyinh2bbdd102017-05-18 23:29:4288}
89
Jacob Dufault2ca8c502018-06-25 19:12:1490bool LoginScreenController::IsAuthenticating() const {
91 return authentication_stage_ != AuthenticationStage::kIdle;
92}
93
Jacob Dufault2d20ae62018-09-20 22:19:5294void LoginScreenController::AuthenticateUserWithPasswordOrPin(
95 const AccountId& account_id,
96 const std::string& password,
97 bool authenticated_by_pin,
98 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4399 // It is an error to call this function while an authentication is in
100 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:52101 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:56102 << "Duplicate authentication attempt; current authentication stage is "
103 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:43104
105 if (!login_screen_client_) {
Jacob Dufaultb7a2d842017-12-01 23:21:15106 std::move(callback).Run(base::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32107 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15108 }
xiaoyinh9f6fa0e2017-06-07 19:22:32109
Jacob Dufaulteafc6fe2017-10-11 21:16:52110 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
111 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24112 switch (force_fail_auth_for_debug_overlay_) {
113 case ForceFailAuth::kOff:
114 break;
115 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15116 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24117 return;
118 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14119 // Set a dummy authentication stage so that |IsAuthenticating| returns
120 // true.
121 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
Jacob Dufault0fbed9c02017-11-14 19:22:24122 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Jacob Dufaultb7a2d842017-12-01 23:21:15123 FROM_HERE,
124 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
125 weak_factory_.GetWeakPtr(), base::Passed(&callback),
126 false),
Jacob Dufault0fbed9c02017-11-14 19:22:24127 base::TimeDelta::FromSeconds(1));
128 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52129 }
130
Quan Nguyenf5224352018-11-06 02:03:34131 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
132
133 int dummy_value;
134 bool is_pin =
135 authenticated_by_pin && base::StringToInt(password, &dummy_value);
136 login_screen_client_->AuthenticateUserWithPasswordOrPin(
137 account_id, password, is_pin,
138 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
139 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32140}
141
Jacob Dufault2d20ae62018-09-20 22:19:52142void LoginScreenController::AuthenticateUserWithExternalBinary(
143 const AccountId& account_id,
144 OnAuthenticateCallback callback) {
145 // It is an error to call this function while an authentication is in
146 // progress.
147 LOG_IF(FATAL, IsAuthenticating())
148 << "Duplicate authentication attempt; current authentication stage is "
149 << static_cast<int>(authentication_stage_);
150
151 if (!login_screen_client_) {
152 std::move(callback).Run(base::nullopt);
153 return;
154 }
155
156 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
157 login_screen_client_->AuthenticateUserWithExternalBinary(
158 account_id,
159 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
160 weak_factory_.GetWeakPtr(), std::move(callback)));
161}
162
Quan Nguyen92f924a2018-10-18 18:36:46163void LoginScreenController::EnrollUserWithExternalBinary(
164 OnAuthenticateCallback callback) {
165 if (!login_screen_client_) {
166 std::move(callback).Run(base::nullopt);
167 return;
168 }
169
170 login_screen_client_->EnrollUserWithExternalBinary(base::BindOnce(
171 [](OnAuthenticateCallback callback, bool success) {
172 std::move(callback).Run(base::make_optional<bool>(success));
173 },
174 std::move(callback)));
175}
176
Jacob Dufault2d20ae62018-09-20 22:19:52177void LoginScreenController::AuthenticateUserWithEasyUnlock(
178 const AccountId& account_id) {
179 // TODO(jdufault): integrate this into authenticate stage after mojom is
180 // refactored to use a callback.
Jacob Dufaultffd9b0d2017-11-15 23:07:16181 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32182 return;
Jacob Dufault2d20ae62018-09-20 22:19:52183 login_screen_client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32184}
185
Jacob Dufaultffd9b0d2017-11-15 23:07:16186void LoginScreenController::HardlockPod(const AccountId& account_id) {
187 if (!login_screen_client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32188 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16189 login_screen_client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32190}
191
Jacob Dufaultffd9b0d2017-11-15 23:07:16192void LoginScreenController::OnFocusPod(const AccountId& account_id) {
193 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27194 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16195 login_screen_client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27196}
197
Jacob Dufaultffd9b0d2017-11-15 23:07:16198void LoginScreenController::OnNoPodFocused() {
199 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27200 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16201 login_screen_client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27202}
203
Jacob Dufaultffd9b0d2017-11-15 23:07:16204void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
205 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27206 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16207 login_screen_client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27208}
209
Jacob Dufaultffd9b0d2017-11-15 23:07:16210void LoginScreenController::SignOutUser() {
211 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27212 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16213 login_screen_client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27214}
215
Jacob Dufaultffd9b0d2017-11-15 23:07:16216void LoginScreenController::CancelAddUser() {
217 if (!login_screen_client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30218 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16219 login_screen_client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30220}
221
Aga Wronska6a32f9872018-01-06 00:16:10222void LoginScreenController::LoginAsGuest() {
223 if (!login_screen_client_)
224 return;
225 login_screen_client_->LoginAsGuest();
226}
227
Jacob Dufaultffd9b0d2017-11-15 23:07:16228void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27229 const AccountId& account_id) {
Jacob Dufaultffd9b0d2017-11-15 23:07:16230 if (!login_screen_client_)
xiaoyinhf534c4f2017-06-13 20:50:27231 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16232 login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27233}
234
Jacob Dufaultffd9b0d2017-11-15 23:07:16235void LoginScreenController::FocusLockScreenApps(bool reverse) {
236 if (!login_screen_client_)
Toni Barzicf61c4452017-10-05 03:57:48237 return;
Jacob Dufaultffd9b0d2017-11-15 23:07:16238 login_screen_client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48239}
240
Wenzhao Zang767a9f32018-05-02 21:20:55241void LoginScreenController::ShowGaiaSignin(
Jacob Dufaultfb72607d2018-06-12 19:50:33242 bool can_close,
243 const base::Optional<AccountId>& prefilled_account) {
Sarah Hu9fba0e752018-02-07 01:41:09244 if (!login_screen_client_)
245 return;
Jacob Dufaultfb72607d2018-06-12 19:50:33246 login_screen_client_->ShowGaiaSignin(can_close, prefilled_account);
Sarah Hu9fba0e752018-02-07 01:41:09247}
248
Jacob Dufaultfc31c742018-03-20 17:32:19249void LoginScreenController::OnRemoveUserWarningShown() {
250 if (!login_screen_client_)
251 return;
252 login_screen_client_->OnRemoveUserWarningShown();
253}
254
255void LoginScreenController::RemoveUser(const AccountId& account_id) {
256 if (!login_screen_client_)
257 return;
258 login_screen_client_->RemoveUser(account_id);
259}
260
Sarah Hu3fcf9f82018-03-22 20:32:54261void LoginScreenController::LaunchPublicSession(
262 const AccountId& account_id,
263 const std::string& locale,
264 const std::string& input_method) {
265 if (!login_screen_client_)
266 return;
267 login_screen_client_->LaunchPublicSession(account_id, locale, input_method);
268}
269
Sarah Huf9affb122018-04-27 21:36:36270void LoginScreenController::RequestPublicSessionKeyboardLayouts(
271 const AccountId& account_id,
272 const std::string& locale) {
273 if (!login_screen_client_)
274 return;
275 login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
276}
277
Sarah Hu0007c932018-06-18 20:21:04278void LoginScreenController::ShowFeedback() {
279 if (!login_screen_client_)
280 return;
281 login_screen_client_->ShowFeedback();
282}
283
Jacob Dufault589d9942018-03-27 20:28:47284void LoginScreenController::AddObserver(
285 LoginScreenControllerObserver* observer) {
286 observers_.AddObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48287}
288
Jacob Dufault589d9942018-03-27 20:28:47289void LoginScreenController::RemoveObserver(
290 LoginScreenControllerObserver* observer) {
291 observers_.RemoveObserver(observer);
Toni Barzicf61c4452017-10-05 03:57:48292}
293
Jacob Dufaultffd9b0d2017-11-15 23:07:16294void LoginScreenController::FlushForTesting() {
295 login_screen_client_.FlushForTesting();
Toni Barzicf61c4452017-10-05 03:57:48296}
297
Jacob Dufault589d9942018-03-27 20:28:47298void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) {
299 login_screen_client_ = std::move(client);
300}
301
302void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
303 OnShow();
304 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock);
305 std::move(on_shown).Run(true);
306}
307
308void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) {
309 // Login screen can only be used during login.
310 if (Shell::Get()->session_controller()->GetSessionState() !=
311 session_manager::SessionState::LOGIN_PRIMARY) {
312 LOG(ERROR) << "Not showing login screen since session state is "
313 << static_cast<int>(
314 Shell::Get()->session_controller()->GetSessionState());
315 std::move(on_shown).Run(false);
316 return;
317 }
318
319 OnShow();
320 // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen.
321 ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin);
322 std::move(on_shown).Run(true);
323}
324
325void LoginScreenController::ShowErrorMessage(int32_t login_attempts,
326 const std::string& error_text,
327 const std::string& help_link_text,
328 int32_t help_topic_id) {
329 NOTIMPLEMENTED();
330}
331
Naoki Fukino00a14cbc2018-08-08 05:27:22332void LoginScreenController::ShowWarningBanner(const base::string16& message) {
333 if (DataDispatcher())
334 DataDispatcher()->ShowWarningBanner(message);
335}
336
337void LoginScreenController::HideWarningBanner() {
338 if (DataDispatcher())
339 DataDispatcher()->HideWarningBanner();
340}
341
Jacob Dufault589d9942018-03-27 20:28:47342void LoginScreenController::ClearErrors() {
343 NOTIMPLEMENTED();
344}
345
346void LoginScreenController::ShowUserPodCustomIcon(
347 const AccountId& account_id,
348 mojom::EasyUnlockIconOptionsPtr icon) {
349 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon);
350}
351
352void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
353 auto icon_options = mojom::EasyUnlockIconOptions::New();
354 icon_options->icon = mojom::EasyUnlockIconId::NONE;
355 DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options);
356}
357
358void LoginScreenController::SetAuthType(
359 const AccountId& account_id,
360 proximity_auth::mojom::AuthType auth_type,
361 const base::string16& initial_value) {
362 if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
Jacob Dufault21cd5662018-08-07 18:04:33363 DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
364 true /*enabled*/);
Wenzhao Zang767a9f32018-05-02 21:20:55365 } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
366 DataDispatcher()->SetForceOnlineSignInForUser(account_id);
Jacob Dufault589d9942018-03-27 20:28:47367 } else {
368 NOTIMPLEMENTED();
369 }
370}
371
Sarah Hu51d19d32018-08-27 19:41:50372void LoginScreenController::SetUserList(
373 std::vector<mojom::LoginUserInfoPtr> users) {
Jacob Dufault589d9942018-03-27 20:28:47374 DCHECK(DataDispatcher());
375
376 DataDispatcher()->NotifyUsers(users);
377}
378
379void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
380 bool is_enabled) {
381 // Chrome will update pin pod state every time user tries to authenticate.
382 // LockScreen is destroyed in the case of authentication success.
383 if (DataDispatcher())
384 DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled);
385}
386
Jacob Dufault947f2472018-10-24 21:08:16387void LoginScreenController::SetFingerprintState(const AccountId& account_id,
388 mojom::FingerprintState state) {
389 if (DataDispatcher())
390 DataDispatcher()->SetFingerprintState(account_id, state);
391}
392
393void LoginScreenController::NotifyFingerprintAuthResult(
394 const AccountId& account_id,
395 bool successful) {
396 if (DataDispatcher())
397 DataDispatcher()->NotifyFingerprintAuthResult(account_id, successful);
398}
399
Jacob Dufault77d75ce92018-04-13 18:20:09400void LoginScreenController::SetAvatarForUser(const AccountId& account_id,
401 mojom::UserAvatarPtr avatar) {
402 for (auto& observer : observers_)
403 observer.SetAvatarForUser(account_id, avatar);
404}
405
Wenzhao Zange0c2ab22018-05-23 17:43:46406void LoginScreenController::SetAuthEnabledForUser(
407 const AccountId& account_id,
408 bool is_enabled,
409 base::Optional<base::Time> auth_reenabled_time) {
410 if (DataDispatcher()) {
411 DataDispatcher()->SetAuthEnabledForUser(account_id, is_enabled,
412 auth_reenabled_time);
413 }
414}
415
Jacob Dufault589d9942018-03-27 20:28:47416void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) {
417 for (auto& observer : observers_)
418 observer.OnFocusLeavingLockScreenApps(reverse);
419}
420
Jacob Dufault5fc31392018-10-03 22:15:02421void LoginScreenController::SetSystemInfo(
422 bool show_if_hidden,
Jacob Dufault589d9942018-03-27 20:28:47423 const std::string& os_version_label_text,
424 const std::string& enterprise_info_text,
425 const std::string& bluetooth_name) {
426 if (DataDispatcher()) {
Jacob Dufault5fc31392018-10-03 22:15:02427 DataDispatcher()->SetSystemInfo(show_if_hidden, os_version_label_text,
428 enterprise_info_text, bluetooth_name);
Jacob Dufault589d9942018-03-27 20:28:47429 }
430}
431
432void LoginScreenController::IsReadyForPassword(
433 IsReadyForPasswordCallback callback) {
Jacob Dufault2ca8c502018-06-25 19:12:14434 std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating());
Jacob Dufault589d9942018-03-27 20:28:47435}
436
437void LoginScreenController::SetPublicSessionDisplayName(
438 const AccountId& account_id,
439 const std::string& display_name) {
440 if (DataDispatcher())
441 DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name);
442}
443
444void LoginScreenController::SetPublicSessionLocales(
445 const AccountId& account_id,
Sarah Hue9cd6132018-05-17 17:25:56446 std::vector<mojom::LocaleItemPtr> locales,
Jacob Dufault589d9942018-03-27 20:28:47447 const std::string& default_locale,
448 bool show_advanced_view) {
449 if (DataDispatcher()) {
450 DataDispatcher()->SetPublicSessionLocales(
Sarah Hue9cd6132018-05-17 17:25:56451 account_id, locales, default_locale, show_advanced_view);
Jacob Dufault589d9942018-03-27 20:28:47452 }
453}
454
Sarah Huf9affb122018-04-27 21:36:36455void LoginScreenController::SetPublicSessionKeyboardLayouts(
456 const AccountId& account_id,
457 const std::string& locale,
458 std::vector<mojom::InputMethodItemPtr> keyboard_layouts) {
459 if (DataDispatcher()) {
460 DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale,
461 keyboard_layouts);
462 }
463}
464
Quan Nguyend09dd112018-06-19 19:20:32465void LoginScreenController::SetKioskApps(
466 std::vector<mojom::KioskAppInfoPtr> kiosk_apps) {
467 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
468 ->shelf_widget()
Jacob Dufault5ac266ef2018-07-18 17:30:30469 ->login_shelf_view()
470 ->SetKioskApps(std::move(kiosk_apps));
Quan Nguyend09dd112018-06-19 19:20:32471}
472
Quan Nguyenb7c2ea22018-09-10 17:44:18473void LoginScreenController::ShowKioskAppError(const std::string& message) {
474 ToastData toast_data(
475 "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
476 base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
477 true /*visible_on_lock_screen*/);
478 Shell::Get()->toast_manager()->Show(toast_data);
479}
480
Sarah Hu51d19d32018-08-27 19:41:50481void LoginScreenController::NotifyOobeDialogState(
482 mojom::OobeDialogState state) {
Quan Nguyenc6ff3152018-08-07 20:00:37483 for (auto& observer : observers_)
Sarah Hu51d19d32018-08-27 19:41:50484 observer.OnOobeDialogStateChanged(state);
485}
486
487void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
488 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
489 ->shelf_widget()
490 ->login_shelf_view()
491 ->SetAllowLoginAsGuest(allow_guest);
492}
493
494void LoginScreenController::SetShowGuestButtonForGaiaScreen(bool can_show) {
495 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
496 ->shelf_widget()
497 ->login_shelf_view()
498 ->SetShowGuestButtonForGaiaScreen(can_show);
Jacob Dufault883dcf72018-06-27 22:52:32499}
500
Quan Nguyen3d7a0f02018-09-04 23:53:55501void LoginScreenController::FocusLoginShelf(bool reverse) {
502 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
503 // Tell the focus direction to the status area or the shelf so they can focus
504 // the correct child view.
Jun Mukai103f57b2018-11-15 01:03:01505 if (reverse || !ShelfWidget::IsUsingViewsShelf()) {
506 if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible())
Jun Mukaid96b4d7452018-11-09 00:37:23507 return;
Quan Nguyen3d7a0f02018-09-04 23:53:55508 shelf->GetStatusAreaWidget()
509 ->status_area_widget_delegate()
510 ->set_default_last_focusable_child(reverse);
511 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
512 } else {
513 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
514 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
515 }
516}
517
Sarah Hu4976046e2018-07-19 23:47:47518void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
519 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
520 ->shelf_widget()
521 ->login_shelf_view()
522 ->SetAddUserButtonEnabled(enable);
523}
524
Quan Nguyend09dd112018-06-19 19:20:32525void LoginScreenController::LaunchKioskApp(const std::string& app_id) {
526 login_screen_client_->LaunchKioskApp(app_id);
527}
528
Quan Nguyena3c54cf2018-07-03 17:56:50529void LoginScreenController::LaunchArcKioskApp(const AccountId& account_id) {
530 login_screen_client_->LaunchArcKioskApp(account_id);
531}
532
Quan Nguyene3e1d252018-07-19 23:00:44533void LoginScreenController::ShowResetScreen() {
534 login_screen_client_->ShowResetScreen();
535}
536
Quan Nguyenff20e232018-08-02 21:34:11537void LoginScreenController::ShowAccountAccessHelpApp() {
538 login_screen_client_->ShowAccountAccessHelpApp();
539}
540
Quan Nguyen3d7a0f02018-09-04 23:53:55541void LoginScreenController::FocusOobeDialog() {
542 login_screen_client_->FocusOobeDialog();
543}
544
Jacob Dufaultb7a2d842017-12-01 23:21:15545void LoginScreenController::OnAuthenticateComplete(
546 OnAuthenticateCallback callback,
547 bool success) {
Jacob Dufault8876ba82018-03-27 22:55:43548 authentication_stage_ = AuthenticationStage::kUserCallback;
Quan Nguyen92f924a2018-10-18 18:36:46549 std::move(callback).Run(base::make_optional<bool>(success));
Jacob Dufault8876ba82018-03-27 22:55:43550 authentication_stage_ = AuthenticationStage::kIdle;
xiaoyinh2bbdd102017-05-18 23:29:42551}
552
Jacob Dufaultffd9b0d2017-11-15 23:07:16553LoginDataDispatcher* LoginScreenController::DataDispatcher() const {
Wenzhao Zang733497282018-06-12 16:53:10554 if (!ash::LockScreen::HasInstance())
Jacob Dufault40623d52017-09-15 17:22:53555 return nullptr;
556 return ash::LockScreen::Get()->data_dispatcher();
557}
558
Jacob Dufaultcbc1ee02018-02-28 18:38:54559void LoginScreenController::OnShow() {
560 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17561 if (authentication_stage_ != AuthenticationStage::kIdle) {
562 AuthenticationStage authentication_stage = authentication_stage_;
563 base::debug::Alias(&authentication_stage);
564 LOG(FATAL) << "Unexpected authentication stage "
565 << static_cast<int>(authentication_stage_);
566 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54567}
568
Jun Mukai5c7b5b42018-11-30 00:08:50569void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
570 if (!login_screen_client_)
571 return;
572 login_screen_client_->OnFocusLeavingSystemTray(reverse);
573}
574
xiaoyinh2bbdd102017-05-18 23:29:42575} // namespace ash