[go: nahoru, domu]

blob: e7dabf5d06437a51c3bc394feadc89fcbea2db8f [file] [log] [blame]
Avi Drissman3a215d1e2022-09-07 19:43:091// Copyright 2017 The Chromium Authors
xiaoyinh2bbdd102017-05-18 23:29:422// 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
Yunke Zhouf819ab92022-10-27 18:25:32134 if (authenticated_by_pin)
135 DCHECK(base::ContainsOnlyChars(password, "0123456789"));
136
Evan Stade2e4c22e2019-06-07 02:13:55137 client_->AuthenticateUserWithPasswordOrPin(
Yunke Zhouf819ab92022-10-27 18:25:32138 account_id, password, authenticated_by_pin,
Quan Nguyenf5224352018-11-06 02:03:34139 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
Jan Wilken Dörried76713f2020-03-31 12:12:11140 weak_factory_.GetWeakPtr(), std::move(callback)));
xiaoyinh9f6fa0e2017-06-07 19:22:32141}
142
Jacob Dufault2d20ae62018-09-20 22:19:52143void LoginScreenController::AuthenticateUserWithEasyUnlock(
144 const AccountId& account_id) {
145 // TODO(jdufault): integrate this into authenticate stage after mojom is
146 // refactored to use a callback.
Evan Stade2e4c22e2019-06-07 02:13:55147 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32148 return;
Evan Stade2e4c22e2019-06-07 02:13:55149 client_->AuthenticateUserWithEasyUnlock(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32150}
151
Maksim Ivanov675dd762019-07-29 18:31:10152void LoginScreenController::AuthenticateUserWithChallengeResponse(
153 const AccountId& account_id,
154 OnAuthenticateCallback callback) {
155 LOG_IF(FATAL, IsAuthenticating())
156 << "Duplicate authentication attempt; current authentication stage is "
157 << static_cast<int>(authentication_stage_);
158
159 if (!client_) {
Anton Bikineev43cee28e2021-05-14 23:35:33160 std::move(callback).Run(/*success=*/absl::nullopt);
Maksim Ivanov675dd762019-07-29 18:31:10161 return;
162 }
163
164 authentication_stage_ = AuthenticationStage::kDoAuthenticate;
165 client_->AuthenticateUserWithChallengeResponse(
166 account_id,
167 base::BindOnce(&LoginScreenController::OnAuthenticateComplete,
168 weak_factory_.GetWeakPtr(), std::move(callback)));
169}
170
Aga Wronska660503d2021-03-24 03:21:11171ParentCodeValidationResult LoginScreenController::ValidateParentAccessCode(
Henrique Grandinetti4eb2eae2019-05-31 16:31:17172 const AccountId& account_id,
Fabian Sommerdcb675c2020-02-12 09:31:05173 base::Time validation_time,
174 const std::string& code) {
175 DCHECK(!validation_time.is_null());
176
Evan Stade2e4c22e2019-06-07 02:13:55177 if (!client_)
Aga Wronska660503d2021-03-24 03:21:11178 return ParentCodeValidationResult::kInternalError;
Aga Wronskaac6cf362019-02-26 21:36:55179
Henrique Grandinetti914c34b62019-08-12 14:03:19180 return client_->ValidateParentAccessCode(account_id, code, validation_time);
Aga Wronskaac6cf362019-02-26 21:36:55181}
182
Fabian Sommer4e0fc3d2020-02-27 14:16:33183bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
184 return security_token_request_controller_.request_canceled();
Fabian Sommer502d7a8b2020-02-04 14:37:45185}
186
Jacob Dufaultffd9b0d2017-11-15 23:07:16187void LoginScreenController::HardlockPod(const AccountId& account_id) {
Roman Sorokin5d610382022-04-05 08:30:58188 GetModel()->NotifyFocusPod(account_id);
Evan Stade2e4c22e2019-06-07 02:13:55189 if (!client_)
xiaoyinh9f6fa0e2017-06-07 19:22:32190 return;
Evan Stade2e4c22e2019-06-07 02:13:55191 client_->HardlockPod(account_id);
xiaoyinh9f6fa0e2017-06-07 19:22:32192}
193
Jacob Dufaultffd9b0d2017-11-15 23:07:16194void LoginScreenController::OnFocusPod(const AccountId& account_id) {
Roman Sorokin5d610382022-04-05 08:30:58195 GetModel()->NotifyFocusPod(account_id);
Evan Stade2e4c22e2019-06-07 02:13:55196 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27197 return;
Evan Stade2e4c22e2019-06-07 02:13:55198 client_->OnFocusPod(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27199}
200
Jacob Dufaultffd9b0d2017-11-15 23:07:16201void LoginScreenController::OnNoPodFocused() {
Roman Sorokin5d610382022-04-05 08:30:58202 GetModel()->NotifyFocusPod(EmptyAccountId());
Evan Stade2e4c22e2019-06-07 02:13:55203 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27204 return;
Evan Stade2e4c22e2019-06-07 02:13:55205 client_->OnNoPodFocused();
xiaoyinhf534c4f2017-06-13 20:50:27206}
207
Jacob Dufaultffd9b0d2017-11-15 23:07:16208void LoginScreenController::LoadWallpaper(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55209 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27210 return;
Evan Stade2e4c22e2019-06-07 02:13:55211 client_->LoadWallpaper(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27212}
213
Jacob Dufaultffd9b0d2017-11-15 23:07:16214void LoginScreenController::SignOutUser() {
Evan Stade2e4c22e2019-06-07 02:13:55215 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27216 return;
Evan Stade2e4c22e2019-06-07 02:13:55217 client_->SignOutUser();
xiaoyinhf534c4f2017-06-13 20:50:27218}
219
Jacob Dufaultffd9b0d2017-11-15 23:07:16220void LoginScreenController::CancelAddUser() {
Evan Stade2e4c22e2019-06-07 02:13:55221 if (!client_)
Wenzhao Zang16e7ea722017-09-16 01:27:30222 return;
Evan Stade2e4c22e2019-06-07 02:13:55223 client_->CancelAddUser();
Wenzhao Zang16e7ea722017-09-16 01:27:30224}
225
Aga Wronska6a32f9872018-01-06 00:16:10226void LoginScreenController::LoginAsGuest() {
Evan Stade2e4c22e2019-06-07 02:13:55227 if (!client_)
Aga Wronska6a32f9872018-01-06 00:16:10228 return;
Evan Stade2e4c22e2019-06-07 02:13:55229 client_->LoginAsGuest();
Aga Wronska6a32f9872018-01-06 00:16:10230}
231
Ossama Mahmoud8fa195f2021-09-30 19:51:25232void LoginScreenController::ShowGuestTosScreen() {
233 if (!client_)
234 return;
235 client_->ShowGuestTosScreen();
236}
237
Jacob Dufaultffd9b0d2017-11-15 23:07:16238void LoginScreenController::OnMaxIncorrectPasswordAttempted(
xiaoyinhf534c4f2017-06-13 20:50:27239 const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55240 if (!client_)
xiaoyinhf534c4f2017-06-13 20:50:27241 return;
Evan Stade2e4c22e2019-06-07 02:13:55242 client_->OnMaxIncorrectPasswordAttempted(account_id);
xiaoyinhf534c4f2017-06-13 20:50:27243}
244
Jacob Dufaultffd9b0d2017-11-15 23:07:16245void LoginScreenController::FocusLockScreenApps(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55246 if (!client_)
Toni Barzicf61c4452017-10-05 03:57:48247 return;
Evan Stade2e4c22e2019-06-07 02:13:55248 client_->FocusLockScreenApps(reverse);
Toni Barzicf61c4452017-10-05 03:57:48249}
250
Roman Sorokin26d7e9662020-02-24 17:52:18251void LoginScreenController::ShowGaiaSignin(const AccountId& prefilled_account) {
Evan Stade2e4c22e2019-06-07 02:13:55252 if (!client_)
Sarah Hu9fba0e752018-02-07 01:41:09253 return;
Roman Sorokin26d7e9662020-02-24 17:52:18254 client_->ShowGaiaSignin(prefilled_account);
255}
256
Ossama Mahmoud95164772021-06-30 14:18:14257void LoginScreenController::ShowOsInstallScreen() {
258 if (!client_)
259 return;
260 client_->ShowOsInstallScreen();
261}
262
Jacob Dufaultfc31c742018-03-20 17:32:19263void LoginScreenController::OnRemoveUserWarningShown() {
Evan Stade2e4c22e2019-06-07 02:13:55264 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19265 return;
Evan Stade2e4c22e2019-06-07 02:13:55266 client_->OnRemoveUserWarningShown();
Jacob Dufaultfc31c742018-03-20 17:32:19267}
268
269void LoginScreenController::RemoveUser(const AccountId& account_id) {
Evan Stade2e4c22e2019-06-07 02:13:55270 if (!client_)
Jacob Dufaultfc31c742018-03-20 17:32:19271 return;
Evan Stade2e4c22e2019-06-07 02:13:55272 client_->RemoveUser(account_id);
Jacob Dufaultfc31c742018-03-20 17:32:19273}
274
Sarah Hu3fcf9f82018-03-22 20:32:54275void LoginScreenController::LaunchPublicSession(
276 const AccountId& account_id,
277 const std::string& locale,
278 const std::string& input_method) {
Evan Stade2e4c22e2019-06-07 02:13:55279 if (!client_)
Sarah Hu3fcf9f82018-03-22 20:32:54280 return;
Evan Stade2e4c22e2019-06-07 02:13:55281 client_->LaunchPublicSession(account_id, locale, input_method);
Sarah Hu3fcf9f82018-03-22 20:32:54282}
283
Sarah Huf9affb122018-04-27 21:36:36284void LoginScreenController::RequestPublicSessionKeyboardLayouts(
285 const AccountId& account_id,
286 const std::string& locale) {
Evan Stade2e4c22e2019-06-07 02:13:55287 if (!client_)
Sarah Huf9affb122018-04-27 21:36:36288 return;
Evan Stade2e4c22e2019-06-07 02:13:55289 client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
Sarah Huf9affb122018-04-27 21:36:36290}
291
Evan Stade2e4c22e2019-06-07 02:13:55292void LoginScreenController::SetClient(LoginScreenClient* client) {
293 client_ = client;
Toni Barzicf61c4452017-10-05 03:57:48294}
295
Evan Stadeb153f822019-05-23 19:14:43296LoginScreenModel* LoginScreenController::GetModel() {
Evan Stadeddde2b22019-05-24 20:51:31297 return &login_data_dispatcher_;
Evan Stadeb153f822019-05-23 19:14:43298}
299
Evan Stade9fe9cbe2019-06-03 23:05:55300void LoginScreenController::ShowKioskAppError(const std::string& message) {
Kevin Radtke11d1599e2022-01-18 21:04:11301 ToastData toast_data("KioskAppError", ToastCatalogName::kKioskAppError,
302 base::UTF8ToUTF16(message), ToastData::kInfiniteDuration,
Ben Franzef7fab22022-04-06 16:13:16303 /*visible_on_lock_screen=*/true,
Kevin Radtke9e9e6a962022-04-18 18:16:23304 /*has_dismiss_button=*/true);
Ben Beckere1807312022-11-14 20:25:08305 Shell::Get()->toast_manager()->Show(std::move(toast_data));
Evan Stade9fe9cbe2019-06-03 23:05:55306}
307
308void LoginScreenController::FocusLoginShelf(bool reverse) {
309 Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow());
310 // Tell the focus direction to the status area or the shelf so they can focus
311 // the correct child view.
Danila Kuzmin35f80082020-11-25 12:26:17312 if (Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible() &&
Andrew Xub6a52a12022-07-12 21:02:18313 (reverse || !shelf->shelf_widget()->GetLoginShelfView()->IsFocusable())) {
Danila Kuzmin35f80082020-11-25 12:26:17314 // Focus goes to system tray (status area) if one of the following is true:
315 // - system tray is visible and tab is in reverse order;
316 // - system tray is visible and there is no visible shelf buttons before.
Evan Stade9fe9cbe2019-06-03 23:05:55317 shelf->GetStatusAreaWidget()
318 ->status_area_widget_delegate()
319 ->set_default_last_focusable_child(reverse);
320 Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget());
Andrew Xub6a52a12022-07-12 21:02:18321 } else if (shelf->shelf_widget()->GetLoginShelfView()->IsFocusable()) {
Andrew Xu25ff1212022-08-17 20:25:11322 // Otherwise focus goes to login shelf buttons when there is any.
323 if (features::IsUseLoginShelfWidgetEnabled()) {
324 LoginShelfWidget* login_shelf_widget = shelf->login_shelf_widget();
325 login_shelf_widget->SetDefaultLastFocusableChild(reverse);
326 Shell::Get()->focus_cycler()->FocusWidget(login_shelf_widget);
327 } else {
328 shelf->shelf_widget()->set_default_last_focusable_child(reverse);
329 Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget());
330 }
Danila Kuzmin35f80082020-11-25 12:26:17331 } else {
332 // No elements to focus on the shelf.
333 NOTREACHED();
Evan Stade9fe9cbe2019-06-03 23:05:55334 }
335}
336
337bool LoginScreenController::IsReadyForPassword() {
338 return LockScreen::HasInstance() && !IsAuthenticating();
339}
340
341void LoginScreenController::EnableAddUserButton(bool enable) {
342 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
343 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18344 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55345 ->SetAddUserButtonEnabled(enable);
346}
347
348void LoginScreenController::EnableShutdownButton(bool enable) {
349 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
350 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18351 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55352 ->SetShutdownButtonEnabled(enable);
353}
354
Yunke Zhou9319aab2020-12-01 07:34:42355void LoginScreenController::EnableShelfButtons(bool enable) {
356 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
357 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18358 ->GetLoginShelfView()
Yunke Zhou9319aab2020-12-01 07:34:42359 ->SetButtonEnabled(enable);
360}
361
Ossama Mahmouda06399d2020-10-05 12:25:34362void LoginScreenController::SetIsFirstSigninStep(bool is_first) {
Evan Stade98b718e2019-06-03 17:15:34363 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
364 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18365 ->GetLoginShelfView()
Ossama Mahmouda06399d2020-10-05 12:25:34366 ->SetIsFirstSigninStep(is_first);
Evan Stade98b718e2019-06-03 17:15:34367}
368
369void LoginScreenController::ShowParentAccessButton(bool show) {
370 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
371 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18372 ->GetLoginShelfView()
Evan Stade98b718e2019-06-03 17:15:34373 ->ShowParentAccessButton(show);
374}
375
Evan Stade9fe9cbe2019-06-03 23:05:55376void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
377 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
378 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18379 ->GetLoginShelfView()
Evan Stade9fe9cbe2019-06-03 23:05:55380 ->SetAllowLoginAsGuest(allow_guest);
381}
382
Alexander Alekseev7020c6b52019-07-25 03:25:48383std::unique_ptr<ScopedGuestButtonBlocker>
384LoginScreenController::GetScopedGuestButtonBlocker() {
385 return Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
386 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18387 ->GetLoginShelfView()
Alexander Alekseev7020c6b52019-07-25 03:25:48388 ->GetScopedGuestButtonBlocker();
389}
390
Maksim Ivanovdbd9ade72019-08-09 15:34:16391void LoginScreenController::RequestSecurityTokenPin(
392 SecurityTokenPinRequest request) {
Fabian Sommer4e0fc3d2020-02-27 14:16:33393 security_token_request_controller_.SetPinUiState(std::move(request));
Maksim Ivanovdbd9ade72019-08-09 15:34:16394}
395
396void LoginScreenController::ClearSecurityTokenPinRequest() {
Fabian Sommer4e0fc3d2020-02-27 14:16:33397 security_token_request_controller_.ClosePinUi();
Maksim Ivanovdbd9ade72019-08-09 15:34:16398}
399
Danila Kuzmin1546b88e2022-02-07 12:12:35400views::Widget* LoginScreenController::GetLoginWindowWidget() {
401 return client_ ? client_->GetLoginWindowWidget() : nullptr;
402}
403
Evan Stade2e4c22e2019-06-07 02:13:55404void LoginScreenController::ShowLockScreen() {
Roman Sorokin16faa372021-03-09 16:17:57405 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47406 OnShow();
Evan Stade98b718e2019-06-03 17:15:34407 LockScreen::Show(LockScreen::ScreenType::kLock);
Jacob Dufault589d9942018-03-27 20:28:47408}
409
Evan Stade2e4c22e2019-06-07 02:13:55410void LoginScreenController::ShowLoginScreen() {
Roman Sorokin16faa372021-03-09 16:17:57411 CHECK(!LockScreen::HasInstance());
Jacob Dufault589d9942018-03-27 20:28:47412 // Login screen can only be used during login.
Thomas Tellier818a4432020-07-02 15:14:39413 session_manager::SessionState session_state =
414 Shell::Get()->session_controller()->GetSessionState();
415 CHECK(session_state == session_manager::SessionState::LOGIN_PRIMARY ||
416 session_state == session_manager::SessionState::LOGIN_SECONDARY)
Evan Stade2e4c22e2019-06-07 02:13:55417 << "Not showing login screen since session state is "
Thomas Tellier818a4432020-07-02 15:14:39418 << static_cast<int>(session_state);
Jacob Dufault589d9942018-03-27 20:28:47419
420 OnShow();
Evan Stade98b718e2019-06-03 17:15:34421 // TODO(jdufault): rename LockScreen to LoginScreen.
422 LockScreen::Show(LockScreen::ScreenType::kLogin);
Jacob Dufault589d9942018-03-27 20:28:47423}
424
Evan Stade9c07ab42019-05-13 21:21:56425void LoginScreenController::SetKioskApps(
Sherri Lin51944b6f2022-04-21 21:32:53426 const std::vector<KioskAppMenuEntry>& kiosk_apps) {
427 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
428 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18429 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53430 ->SetKioskApps(kiosk_apps);
431}
432
433void LoginScreenController::ConfigureKioskCallbacks(
Anatoliy Potapchuk4c58f1f2020-06-23 10:01:25434 const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
435 const base::RepeatingClosure& on_show_menu) {
Evan Stade9c07ab42019-05-13 21:21:56436 Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
437 ->shelf_widget()
Andrew Xub6a52a12022-07-12 21:02:18438 ->GetLoginShelfView()
Sherri Lin51944b6f2022-04-21 21:32:53439 ->ConfigureKioskCallbacks(launch_app, on_show_menu);
Evan Stade9c07ab42019-05-13 21:21:56440}
441
Denis Kuznetsovad5a97c2020-07-09 10:45:35442void LoginScreenController::HandleAccelerator(
443 ash::LoginAcceleratorAction action) {
444 if (!client_)
445 return;
446 client_->HandleAccelerator(action);
Quan Nguyene3e1d252018-07-19 23:00:44447}
448
Roman Sorokin925cddec2020-01-23 08:19:02449void LoginScreenController::ShowAccountAccessHelpApp(
450 gfx::NativeWindow parent_window) {
451 client_->ShowAccountAccessHelpApp(parent_window);
Quan Nguyenff20e232018-08-02 21:34:11452}
453
Courtney Wong45cfc9fa62021-06-30 22:08:05454void LoginScreenController::ShowParentAccessHelpApp() {
455 client_->ShowParentAccessHelpApp();
Aga Wronska7fef27e92019-08-22 17:51:27456}
457
Evan Stade3c971bc2019-06-11 22:12:44458void LoginScreenController::ShowLockScreenNotificationSettings() {
459 client_->ShowLockScreenNotificationSettings();
460}
461
Quan Nguyen3d7a0f02018-09-04 23:53:55462void LoginScreenController::FocusOobeDialog() {
Evan Stade2e4c22e2019-06-07 02:13:55463 if (!client_)
Tony de Luna46801932019-03-11 18:02:01464 return;
Evan Stade2e4c22e2019-06-07 02:13:55465 client_->FocusOobeDialog();
Quan Nguyen3d7a0f02018-09-04 23:53:55466}
467
Quan Nguyene377eb62019-02-11 23:02:25468void LoginScreenController::NotifyUserActivity() {
Evan Stade2e4c22e2019-06-07 02:13:55469 if (!client_)
Xiyuan Xia5a8c4172019-05-13 16:23:48470 return;
Evan Stade2e4c22e2019-06-07 02:13:55471 client_->OnUserActivity();
Quan Nguyene377eb62019-02-11 23:02:25472}
473
Jacob Dufaultb7a2d842017-12-01 23:21:15474void LoginScreenController::OnAuthenticateComplete(
475 OnAuthenticateCallback callback,
476 bool success) {
Denis Kuznetsova22f07d2022-07-15 17:30:41477 LOG(WARNING) << "crbug.com/1339004 : authentication complete";
Jacob Dufault8876ba82018-03-27 22:55:43478 authentication_stage_ = AuthenticationStage::kUserCallback;
Anton Bikineev43cee28e2021-05-14 23:35:33479 std::move(callback).Run(absl::make_optional<bool>(success));
Denis Kuznetsova22f07d2022-07-15 17:30:41480 LOG(WARNING) << "crbug.com/1339004 : triggered callback";
Jacob Dufault8876ba82018-03-27 22:55:43481 authentication_stage_ = AuthenticationStage::kIdle;
Fabian Sommer4e0fc3d2020-02-27 14:16:33482
483 // During smart card login flow, multiple security token requests can be made.
484 // If the user cancels one, all others should also be canceled.
485 // At this point, the flow is ending and new security token requests are
486 // displayed again.
487 security_token_request_controller_.ResetRequestCanceled();
xiaoyinh2bbdd102017-05-18 23:29:42488}
489
Jacob Dufaultcbc1ee02018-02-28 18:38:54490void LoginScreenController::OnShow() {
491 SetSystemTrayVisibility(SystemTrayVisibility::kPrimary);
Jacob Dufaultc06d6ca2018-04-24 23:49:17492 if (authentication_stage_ != AuthenticationStage::kIdle) {
493 AuthenticationStage authentication_stage = authentication_stage_;
494 base::debug::Alias(&authentication_stage);
495 LOG(FATAL) << "Unexpected authentication stage "
496 << static_cast<int>(authentication_stage_);
497 }
Jacob Dufaultcbc1ee02018-02-28 18:38:54498}
499
Jun Mukai5c7b5b42018-11-30 00:08:50500void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) {
Evan Stade2e4c22e2019-06-07 02:13:55501 if (!client_)
Jun Mukai5c7b5b42018-11-30 00:08:50502 return;
Evan Stade2e4c22e2019-06-07 02:13:55503 client_->OnFocusLeavingSystemTray(reverse);
Jun Mukai5c7b5b42018-11-30 00:08:50504}
505
Akihiro Otab3543e32021-04-07 18:24:56506void LoginScreenController::OnSystemTrayBubbleShown() {
507 if (!client_)
508 return;
509 client_->OnSystemTrayBubbleShown();
510}
511
Roman Sorokin16faa372021-03-09 16:17:57512void LoginScreenController::OnLockScreenDestroyed() {
513 DCHECK_EQ(authentication_stage_, AuthenticationStage::kIdle);
514
515 // Still handle it to avoid crashes during Login/Lock/Unlock flows.
516 authentication_stage_ = AuthenticationStage::kIdle;
Alex Newcomer9f730e292021-04-01 21:46:15517 SetSystemTrayVisibility(SystemTrayVisibility::kAll);
Roman Sorokin16faa372021-03-09 16:17:57518}
519
Thomas Tellier0389c242020-08-27 11:44:45520void LoginScreenController::NotifyLoginScreenShown() {
521 if (!client_)
522 return;
523 client_->OnLoginScreenShown();
524}
525
xiaoyinh2bbdd102017-05-18 23:29:42526} // namespace ash