[go: nahoru, domu]

blob: 51efd83e7b5fa37ef88ab5d590f5b6d8305208e5 [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
Henrique Ferreirof9d1cb22021-07-13 01:32:479#include "ash/constants/ash_pref_names.h"
Kevin Radtke343b5c12022-06-10 20:05:3010#include "ash/constants/notifier_catalogs.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5511#include "ash/focus_cycler.h"
Fabian Sommer4e0fc3d2020-02-27 14:16:3312#include "ash/login/security_token_request_controller.h"
jdufaulteb4c9f1e2017-06-08 23:08:3013#include "ash/login/ui/lock_screen.h"
Jacob Dufault40623d52017-09-15 17:22:5314#include "ash/login/ui/login_data_dispatcher.h"
Aga Wronska660503d2021-03-24 03:21:1115#include "ash/public/cpp/child_accounts/parent_access_controller.h"
Evan Stade2e4c22e2019-06-07 02:13:5516#include "ash/public/cpp/login_screen_client.h"
Kevin Radtke11d1599e2022-01-18 21:04:1117#include "ash/public/cpp/system/toast_data.h"
Aga Wronska16abb432018-01-11 23:49:5918#include "ash/root_window_controller.h"
Xiyuan Xiae7b19542019-05-06 23:05:1819#include "ash/session/session_controller_impl.h"
Jacob Dufault5ac266ef2018-07-18 17:30:3020#include "ash/shelf/login_shelf_view.h"
Andrew Xu25ff1212022-08-17 20:25:1121#include "ash/shelf/login_shelf_widget.h"
Quan Nguyend09dd112018-06-19 19:20:3222#include "ash/shelf/shelf.h"
23#include "ash/shelf/shelf_widget.h"
Sarah Hu069eea12017-09-08 01:28:4024#include "ash/shell.h"
Aga Wronska16abb432018-01-11 23:49:5925#include "ash/system/status_area_widget.h"
Quan Nguyen3d7a0f02018-09-04 23:53:5526#include "ash/system/status_area_widget_delegate.h"
Anastasiia Nikolaienko8cdd7e62019-06-12 12:16:2427#include "ash/system/toast/toast_manager_impl.h"
Jun Mukai5c7b5b42018-11-30 00:08:5028#include "ash/system/tray/system_tray_notifier.h"
Quan Nguyen92f924a2018-10-18 18:36:4629#include "base/bind.h"
Maksim Ivanovdbd9ade72019-08-09 15:34:1630#include "base/callback.h"
Jacob Dufaultc06d6ca2018-04-24 23:49:1731#include "base/debug/alias.h"
Renato Silva0c0e1bb2019-09-11 13:04:1732#include "base/strings/string_util.h"
Jialiu Linf99b788b2018-01-17 23:01:2133#include "base/strings/utf_string_conversions.h"
Roman Sorokin5d610382022-04-05 08:30:5834#include "components/account_id/account_id.h"
Sarah Hu069eea12017-09-08 01:28:4035#include "components/prefs/pref_registry_simple.h"
Jacob Dufault957e0922017-12-06 19:16:0936#include "components/session_manager/session_manager_types.h"
xiaoyinh2bbdd102017-05-18 23:29:4237
38namespace ash {
39
Sarah Hu069eea12017-09-08 01:28:4040namespace {
xiaoyinh2bbdd102017-05-18 23:29:4241
Aga Wronskaa844cdcd12018-01-29 16:06:4442enum class SystemTrayVisibility {
43 kNone, // Tray not visible anywhere.
44 kPrimary, // Tray visible only on primary display.
45 kAll, // Tray visible on all displays.
46};
47
48void SetSystemTrayVisibility(SystemTrayVisibility visibility) {
49 RootWindowController* primary_window_controller =
50 Shell::GetPrimaryRootWindowController();
51 for (RootWindowController* window_controller :
52 Shell::GetAllRootWindowControllers()) {
53 StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget();
54 if (!status_area)
55 continue;
56 if (window_controller == primary_window_controller) {
57 status_area->SetSystemTrayVisibility(
58 visibility == SystemTrayVisibility::kPrimary ||
59 visibility == SystemTrayVisibility::kAll);
60 } else {
61 status_area->SetSystemTrayVisibility(visibility ==
62 SystemTrayVisibility::kAll);
63 }
64 }
Aga Wronska16abb432018-01-11 23:49:5965}
66
Sarah Hu069eea12017-09-08 01:28:4067} // namespace
68
Jun Mukai5c7b5b42018-11-30 00:08:5069LoginScreenController::LoginScreenController(
70 SystemTrayNotifier* system_tray_notifier)
Jeremy Roman47d432e2019-08-20 14:24:0071 : system_tray_notifier_(system_tray_notifier) {
Akihiro Otab3543e32021-04-07 18:24:5672 system_tray_notifier_->AddSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5073}
James Cook8f1e6062017-11-13 23:40:5974
Jun Mukai5c7b5b42018-11-30 00:08:5075LoginScreenController::~LoginScreenController() {
Akihiro Otab3543e32021-04-07 18:24:5676 system_tray_notifier_->RemoveSystemTrayObserver(this);
Jun Mukai5c7b5b42018-11-30 00:08:5077}
xiaoyinh2bbdd102017-05-18 23:29:4278
Sarah Hu069eea12017-09-08 01:28:4079// static
Jacob Dufaultffd9b0d2017-11-15 23:07:1680void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry,
81 bool for_test) {
Sarah Hu069eea12017-09-08 01:28:4082 if (for_test) {
83 // There is no remote pref service, so pretend that ash owns the pref.
84 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "");
85 return;
86 }
Sarah Hu069eea12017-09-08 01:28:4087}
88
Jacob Dufault2ca8c502018-06-25 19:12:1489bool LoginScreenController::IsAuthenticating() const {
90 return authentication_stage_ != AuthenticationStage::kIdle;
91}
92
Jacob Dufault2d20ae62018-09-20 22:19:5293void LoginScreenController::AuthenticateUserWithPasswordOrPin(
94 const AccountId& account_id,
95 const std::string& password,
96 bool authenticated_by_pin,
97 OnAuthenticateCallback callback) {
Jacob Dufault8876ba82018-03-27 22:55:4398 // It is an error to call this function while an authentication is in
99 // progress.
Jacob Dufault2d20ae62018-09-20 22:19:52100 LOG_IF(FATAL, IsAuthenticating())
Jacob Dufault58a1bf42018-07-10 17:44:56101 << "Duplicate authentication attempt; current authentication stage is "
102 << static_cast<int>(authentication_stage_);
Jacob Dufault8876ba82018-03-27 22:55:43103
Evan Stade2e4c22e2019-06-07 02:13:55104 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33105 std::move(callback).Run(absl::nullopt);
xiaoyinh9f6fa0e2017-06-07 19:22:32106 return;
Jacob Dufaultb7a2d842017-12-01 23:21:15107 }
xiaoyinh9f6fa0e2017-06-07 19:22:32108
Jacob Dufaulteafc6fe2017-10-11 21:16:52109 // If auth is disabled by the debug overlay bypass the mojo call entirely, as
110 // it will dismiss the lock screen if the password is correct.
Jacob Dufault0fbed9c02017-11-14 19:22:24111 switch (force_fail_auth_for_debug_overlay_) {
112 case ForceFailAuth::kOff:
113 break;
114 case ForceFailAuth::kImmediate:
Jacob Dufaultb7a2d842017-12-01 23:21:15115 OnAuthenticateComplete(std::move(callback), false /*success*/);
Jacob Dufault0fbed9c02017-11-14 19:22:24116 return;
117 case ForceFailAuth::kDelayed:
Jacob Dufault2ca8c502018-06-25 19:12:14118 // Set a dummy authentication stage so that |IsAuthenticating| returns
119 // true.
Denis Kuznetsova22f07d2022-07-15 17:30:41120 LOG(WARNING) << "crbug.com/1339004 : Dummy auth state";
Jacob Dufault2ca8c502018-06-25 19:12:14121 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,
Jan Wilken Dörried76713f2020-03-31 12:12:11125 weak_factory_.GetWeakPtr(), std::move(callback),
Jacob Dufaultb7a2d842017-12-01 23:21:15126 false),
Peter Kastinge5a38ed2021-10-02 03:06:35127 base::Seconds(1));
Jacob Dufault0fbed9c02017-11-14 19:22:24128 return;
Jacob Dufaulteafc6fe2017-10-11 21:16:52129 }
130
Denis Kuznetsova22f07d2022-07-15 17:30:41131 LOG(WARNING) << "crbug.com/1339004 : started authentication";
Quan Nguyenf5224352018-11-06 02:03:34132 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
133
Renato Silva0c0e1bb2019-09-11 13:04:17134 // Checking if the password is only formed of numbers with base::StringToInt
135 // will easily fail due to numeric limits. ContainsOnlyChars is used instead.
136 const bool is_pin =
137 authenticated_by_pin && base::ContainsOnlyChars(password, "0123456789");
Evan Stade2e4c22e2019-06-07 02:13:55138 client_->AuthenticateUserWithPasswordOrPin(
Quan Nguyenf5224352018-11-06 02:03:34139 account_id, password, is_pin,
140 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11141 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32142}
143
Jacob Dufault2d20ae62018-09-20 22:19:52144void LoginScreenController::AuthenticateUserWithEasyUnlock(
145 const AccountId& account_id) {
146 // TODO(jdufault): integrate this into authenticate stage after mojom is
147 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55148 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32149 return;
Evan Stade2e4c22e2019-06-07 02:13:55150 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32151}
152
Maksim Ivanov675dd762019-07-29 18:31:10153void LoginScreenController::AuthenticateUserWithChallengeResponse(
154 const AccountId& account_id,
155 OnAuthenticateCallback callback) {
156 LOG_IF(FATAL, IsAuthenticating())
157 << "Duplicate authentication attempt; current authentication stage is "
158 << static_cast<int>(authentication_stage_);
159
160 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33161 std::move(callback).Run(/*success=*/absl::nullopt);
Maksim Ivanov675dd762019-07-29 18:31:10162 return;
163 }
164
165 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
166 client_->AuthenticateUserWithChallengeResponse(
167 account_id,
168 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
169 weak_factory_.GetWeakPtr(), std::move(callback)));
170}
171
Aga Wronska660503d2021-03-24 03:21:11172ParentCodeValidationResult LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17173 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05174 base::Time validation_time,
175 const std::string& code) {
176 DCHECK(!validation_time.is_null());
177
Evan Stade2e4c22e2019-06-07 02:13:55178 if (!client_)
Aga Wronska660503d2021-03-24 03:21:11179 return ParentCodeValidationResult::kInternalError;
Aga Wronskaac6cf362019-02-26 21:36:55180
Henrique Grandinetti914c34b62019-08-12 14:03:19181 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55182}
183
Fabian Sommer4e0fc3d2020-02-27 14:16:33184bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
185 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45186}
187
Jacob Dufaultffd9b0d2017-11-15 23:07:16188void LoginScreenController::HardlockPod(const AccountId& account_id) {
Roman Sorokin5d610382022-04-05 08:30:58189 GetModel()->NotifyFocusPod(account_id);
Evan Stade2e4c22e2019-06-07 02:13:55190 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32191 return;
Evan Stade2e4c22e2019-06-07 02:13:55192 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32193}
194
Jacob Dufaultffd9b0d2017-11-15 23:07:16195void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Roman Sorokin5d610382022-04-05 08:30:58196 GetModel()->NotifyFocusPod(account_id);
Evan Stade2e4c22e2019-06-07 02:13:55197 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27198 return;
Evan Stade2e4c22e2019-06-07 02:13:55199 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27200}
201
Jacob Dufaultffd9b0d2017-11-15 23:07:16202void LoginScreenController::OnNoPodFocused() {
Roman Sorokin5d610382022-04-05 08:30:58203 GetModel()->NotifyFocusPod(EmptyAccountId());
Evan Stade2e4c22e2019-06-07 02:13:55204 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27205 return;
Evan Stade2e4c22e2019-06-07 02:13:55206 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27207}
208
Jacob Dufaultffd9b0d2017-11-15 23:07:16209void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55210 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27211 return;
Evan Stade2e4c22e2019-06-07 02:13:55212 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27213}
214
Jacob Dufaultffd9b0d2017-11-15 23:07:16215void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55216 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27217 return;
Evan Stade2e4c22e2019-06-07 02:13:55218 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27219}
220
Jacob Dufaultffd9b0d2017-11-15 23:07:16221void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55222 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30223 return;
Evan Stade2e4c22e2019-06-07 02:13:55224 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30225}
226
Aga Wronska6a32f9872018-01-06 00:16:10227void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55228 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10229 return;
Evan Stade2e4c22e2019-06-07 02:13:55230 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10231}
232
Ossama Mahmoud8fa195f2021-09-30 19:51:25233void LoginScreenController::ShowGuestTosScreen() {
234 if (!client_)
235 return;
236 client_->ShowGuestTosScreen();
237}
238
Jacob Dufaultffd9b0d2017-11-15 23:07:16239void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27240 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55241 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27242 return;
Evan Stade2e4c22e2019-06-07 02:13:55243 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27244}
245
Jacob Dufaultffd9b0d2017-11-15 23:07:16246void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55247 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48248 return;
Evan Stade2e4c22e2019-06-07 02:13:55249 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48250}
251
Roman Sorokin26d7e9662020-02-24 17:52:18252void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Evan Stade2e4c22e2019-06-07 02:13:55253 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09254 return;
Roman Sorokin26d7e9662020-02-24 17:52:18255 client_->ShowGaiaSignin(prefilled_account);
256}
257
Ossama Mahmoud95164772021-06-30 14:18:14258void LoginScreenController::ShowOsInstallScreen() {
259 if (!client_)
260 return;
261 client_->ShowOsInstallScreen();
262}
263
Jacob Dufaultfc31c742018-03-20 17:32:19264void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55265 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19266 return;
Evan Stade2e4c22e2019-06-07 02:13:55267 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19268}
269
270void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55271 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19272 return;
Evan Stade2e4c22e2019-06-07 02:13:55273 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19274}
275
Sarah Hu3fcf9f82018-03-22 20:32:54276void LoginScreenController::LaunchPublicSession(
277 const AccountId& account_id,
278 const std::string& locale,
279 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55280 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54281 return;
Evan Stade2e4c22e2019-06-07 02:13:55282 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54283}
284
Sarah Huf9affb122018-04-27 21:36:36285void LoginScreenController::RequestPublicSessionKeyboardLayouts(
286 const AccountId& account_id,
287 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55288 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36289 return;
Evan Stade2e4c22e2019-06-07 02:13:55290 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36291}
292
Evan Stade2e4c22e2019-06-07 02:13:55293void LoginScreenController::SetClient(LoginScreenClient* client) {
294 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48295}
296
Evan Stadeb153f822019-05-23 19:14:43297LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31298 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43299}
300
Evan Stade9fe9cbe2019-06-03 23:05:55301void LoginScreenController::ShowKioskAppError(const std::string& message) {
Kevin Radtke11d1599e2022-01-18 21:04:11302 ToastData toast_data("KioskAppError", ToastCatalogName::kKioskAppError,
303 base::UTF8ToUTF16(message), ToastData::kInfiniteDuration,
Ben Franzef7fab22022-04-06 16:13:16304 /*visible_on_lock_screen=*/true,
Kevin Radtke9e9e6a962022-04-18 18:16:23305 /*has_dismiss_button=*/true);
Evan Stade9fe9cbe2019-06-03 23:05:55306 Shell::Get()->toast_manager()->Show(toast_data);
307}
308
309void LoginScreenController::FocusLoginShelf(bool reverse) {
310 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
311 // Tell the focus direction to the status area or the shelf so they can focus
312 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17313 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
Andrew Xub6a52a12022-07-12 21:02:18314 (reverse || !shelf->shelf_widget()->GetLoginShelfView()->IsFocusable())) {
Danila Kuzmin35f80082020-11-25 12:26:17315 // Focus goes to system tray (status area) if one of the following is true:
316 // - system tray is visible and tab is in reverse order;
317 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55318 shelf->GetStatusAreaWidget()
319 ->status_area_widget_delegate()
320 ->set_default_last_focusable_child(reverse);
321 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Andrew Xub6a52a12022-07-12 21:02:18322 } else if (shelf->shelf_widget()->GetLoginShelfView()->IsFocusable()) {
Andrew Xu25ff1212022-08-17 20:25:11323 // Otherwise focus goes to login shelf buttons when there is any.
324 if (features::IsUseLoginShelfWidgetEnabled()) {
325 LoginShelfWidget* login_shelf_widget = shelf->login_shelf_widget();
326 login_shelf_widget->SetDefaultLastFocusableChild(reverse);
327 Shell::Get()->focus_cycler()->FocusWidget(login_shelf_widget);
328 } else {
329 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
330 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
331 }
Danila Kuzmin35f80082020-11-25 12:26:17332 } else {
333 // No elements to focus on the shelf.
334 NOTREACHED();
Evan Stade9fe9cbe2019-06-03 23:05:55335 }
336}
337
338bool LoginScreenController::IsReadyForPassword() {
339 return LockScreen::HasInstance() && !IsAuthenticating();
340}
341
342void LoginScreenController::EnableAddUserButton(bool enable) {
343 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
344 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18345 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55346 ->SetAddUserButtonEnabled(enable);
347}
348
349void LoginScreenController::EnableShutdownButton(bool enable) {
350 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
351 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18352 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55353 ->SetShutdownButtonEnabled(enable);
354}
355
Yunke Zhou9319aab2020-12-01 07:34:42356void LoginScreenController::EnableShelfButtons(bool enable) {
357 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
358 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18359 ->GetLoginShelfView()
Yunke Zhou9319aab2020-12-01 07:34:42360 ->SetButtonEnabled(enable);
361}
362
Ossama Mahmouda06399d2020-10-05 12:25:34363void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34364 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
365 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18366 ->GetLoginShelfView()
Ossama Mahmouda06399d2020-10-05 12:25:34367 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34368}
369
370void LoginScreenController::ShowParentAccessButton(bool show) {
371 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
372 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18373 ->GetLoginShelfView()
Evan Stade98b718e2019-06-03 17:15:34374 ->ShowParentAccessButton(show);
375}
376
Evan Stade9fe9cbe2019-06-03 23:05:55377void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
378 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
379 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18380 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55381 ->SetAllowLoginAsGuest(allow_guest);
382}
383
Alexander Alekseev7020c6b52019-07-25 03:25:48384std::unique_ptr<ScopedGuestButtonBlocker>
385LoginScreenController::GetScopedGuestButtonBlocker() {
386 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
387 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18388 ->GetLoginShelfView()
Alexander Alekseev7020c6b52019-07-25 03:25:48389 ->GetScopedGuestButtonBlocker();
390}
391
Maksim Ivanovdbd9ade72019-08-09 15:34:16392void LoginScreenController::RequestSecurityTokenPin(
393 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33394 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16395}
396
397void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33398 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16399}
400
Danila Kuzmin1546b88e2022-02-07 12:12:35401views::Widget* LoginScreenController::GetLoginWindowWidget() {
402 return client_ ? client_->GetLoginWindowWidget() : nullptr;
403}
404
Evan Stade2e4c22e2019-06-07 02:13:55405void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57406 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47407 OnShow();
Evan Stade98b718e2019-06-03 17:15:34408 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47409}
410
Evan Stade2e4c22e2019-06-07 02:13:55411void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57412 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47413 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39414 session_manager::SessionState session_state =
415 Shell::Get()->session_controller()->GetSessionState();
416 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
417 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55418 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39419 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47420
421 OnShow();
Evan Stade98b718e2019-06-03 17:15:34422 // TODO(jdufault): rename LockScreen to LoginScreen.
423 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47424}
425
Evan Stade9c07ab42019-05-13 21:21:56426void LoginScreenController::SetKioskApps(
Sherri Lin51944b6f2022-04-21 21:32:53427 const std::vector<KioskAppMenuEntry>& kiosk_apps) {
428 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
429 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18430 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53431 ->SetKioskApps(kiosk_apps);
432}
433
434void LoginScreenController::ConfigureKioskCallbacks(
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25435 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
436 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56437 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
438 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18439 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53440 ->ConfigureKioskCallbacks(launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56441}
442
Denis Kuznetsovad5a97c2020-07-09 10:45:35443void LoginScreenController::HandleAccelerator(
444 ash::LoginAcceleratorAction action) {
445 if (!client_)
446 return;
447 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44448}
449
Roman Sorokin925cddec2020-01-23 08:19:02450void LoginScreenController::ShowAccountAccessHelpApp(
451 gfx::NativeWindow parent_window) {
452 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11453}
454
Courtney Wong45cfc9fa62021-06-30 22:08:05455void LoginScreenController::ShowParentAccessHelpApp() {
456 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27457}
458
Evan Stade3c971bc2019-06-11 22:12:44459void LoginScreenController::ShowLockScreenNotificationSettings() {
460 client_->ShowLockScreenNotificationSettings();
461}
462
Quan Nguyen3d7a0f02018-09-04 23:53:55463void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55464 if (!client_)
Tony de Luna46801932019-03-11 18:02:01465 return;
Evan Stade2e4c22e2019-06-07 02:13:55466 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55467}
468
Quan Nguyene377eb62019-02-11 23:02:25469void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55470 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48471 return;
Evan Stade2e4c22e2019-06-07 02:13:55472 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25473}
474
Jacob Dufaultb7a2d842017-12-01 23:21:15475void LoginScreenController::OnAuthenticateComplete(
476 OnAuthenticateCallback callback,
477 bool success) {
Denis Kuznetsova22f07d2022-07-15 17:30:41478 LOG(WARNING) << "crbug.com/1339004 : authentication complete";
Jacob Dufault8876ba82018-03-27 22:55:43479 authentication_stage_ = AuthenticationStage::kUserCallback;
Anton Bikineev43cee28e2021-05-14 23:35:33480 std::move(callback).Run(absl::make_optional<bool>(success));
Denis Kuznetsova22f07d2022-07-15 17:30:41481 LOG(WARNING) << "crbug.com/1339004 : triggered callback";
Jacob Dufault8876ba82018-03-27 22:55:43482 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33483
484 // During smart card login flow, multiple security token requests can be made.
485 // If the user cancels one, all others should also be canceled.
486 // At this point, the flow is ending and new security token requests are
487 // displayed again.
488 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42489}
490
Jacob Dufaultcbc1ee02018-02-28 18:38:54491void LoginScreenController::OnShow() {
492 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17493 if (authentication_stage_ != AuthenticationStage::kIdle) {
494 AuthenticationStage authentication_stage = authentication_stage_;
495 base::debug::Alias(&authentication_stage);
496 LOG(FATAL) << "Unexpected authentication stage "
497 << static_cast<int>(authentication_stage_);
498 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54499}
500
Jun Mukai5c7b5b42018-11-30 00:08:50501void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55502 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50503 return;
Evan Stade2e4c22e2019-06-07 02:13:55504 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50505}
506
Akihiro Otab3543e32021-04-07 18:24:56507void LoginScreenController::OnSystemTrayBubbleShown() {
508 if (!client_)
509 return;
510 client_->OnSystemTrayBubbleShown();
511}
512
Roman Sorokin16faa372021-03-09 16:17:57513void LoginScreenController::OnLockScreenDestroyed() {
514 DCHECK_EQ(authentication_stage_, AuthenticationStage::kIdle);
515
516 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
517 authentication_stage_ = AuthenticationStage::kIdle;
Alex Newcomer9f730e292021-04-01 21:46:15518 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57519}
520
Thomas Tellier0389c242020-08-27 11:44:45521void LoginScreenController::NotifyLoginScreenShown() {
522 if (!client_)
523 return;
524 client_->OnLoginScreenShown();
525}
526
xiaoyinh2bbdd102017-05-18 23:29:42527} // namespace ash