xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 1 | // 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 Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 5 | #include "ash/login/login_screen_controller.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 6 | |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 9 | #include "ash/focus_cycler.h" |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame] | 10 | #include "ash/login/ui/lock_screen.h" |
Jacob Dufault | 40623d5 | 2017-09-15 17:22:53 | [diff] [blame] | 11 | #include "ash/login/ui/login_data_dispatcher.h" |
Henrique Grandinetti | 4eb2eae | 2019-05-31 16:31:17 | [diff] [blame] | 12 | #include "ash/login/ui/parent_access_widget.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 13 | #include "ash/public/cpp/ash_pref_names.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 14 | #include "ash/root_window_controller.h" |
Xiyuan Xia | e7b1954 | 2019-05-06 23:05:18 | [diff] [blame] | 15 | #include "ash/session/session_controller_impl.h" |
Jacob Dufault | 5ac266ef | 2018-07-18 17:30:30 | [diff] [blame] | 16 | #include "ash/shelf/login_shelf_view.h" |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 17 | #include "ash/shelf/shelf.h" |
| 18 | #include "ash/shelf/shelf_widget.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 19 | #include "ash/shell.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 20 | #include "ash/system/status_area_widget.h" |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 21 | #include "ash/system/status_area_widget_delegate.h" |
Quan Nguyen | b7c2ea2 | 2018-09-10 17:44:18 | [diff] [blame] | 22 | #include "ash/system/toast/toast_data.h" |
| 23 | #include "ash/system/toast/toast_manager.h" |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 24 | #include "ash/system/tray/system_tray_notifier.h" |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 25 | #include "base/bind.h" |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 26 | #include "base/debug/alias.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 27 | #include "base/strings/string_number_conversions.h" |
Jialiu Lin | f99b788b | 2018-01-17 23:01:21 | [diff] [blame] | 28 | #include "base/strings/utf_string_conversions.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 29 | #include "components/prefs/pref_registry_simple.h" |
Jacob Dufault | 957e092 | 2017-12-06 19:16:09 | [diff] [blame] | 30 | #include "components/session_manager/session_manager_types.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 31 | |
| 32 | namespace ash { |
| 33 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 34 | namespace { |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 35 | |
Aga Wronska | a844cdcd1 | 2018-01-29 16:06:44 | [diff] [blame] | 36 | enum 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 | |
| 42 | void 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 Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 59 | } |
| 60 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 61 | } // namespace |
| 62 | |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 63 | LoginScreenController::LoginScreenController( |
| 64 | SystemTrayNotifier* system_tray_notifier) |
| 65 | : system_tray_notifier_(system_tray_notifier), weak_factory_(this) { |
| 66 | system_tray_notifier_->AddSystemTrayFocusObserver(this); |
| 67 | } |
James Cook | 8f1e606 | 2017-11-13 23:40:59 | [diff] [blame] | 68 | |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 69 | LoginScreenController::~LoginScreenController() { |
| 70 | system_tray_notifier_->RemoveSystemTrayFocusObserver(this); |
| 71 | } |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 72 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 73 | // static |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 74 | void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry, |
| 75 | bool for_test) { |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 76 | 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 | } |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 81 | } |
| 82 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 83 | void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) { |
James Cook | ede316a | 2017-12-14 22:38:43 | [diff] [blame] | 84 | bindings_.AddBinding(this, std::move(request)); |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 85 | } |
| 86 | |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 87 | bool LoginScreenController::IsAuthenticating() const { |
| 88 | return authentication_stage_ != AuthenticationStage::kIdle; |
| 89 | } |
| 90 | |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 91 | void LoginScreenController::AuthenticateUserWithPasswordOrPin( |
| 92 | const AccountId& account_id, |
| 93 | const std::string& password, |
| 94 | bool authenticated_by_pin, |
| 95 | OnAuthenticateCallback callback) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 96 | // It is an error to call this function while an authentication is in |
| 97 | // progress. |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 98 | LOG_IF(FATAL, IsAuthenticating()) |
Jacob Dufault | 58a1bf4 | 2018-07-10 17:44:56 | [diff] [blame] | 99 | << "Duplicate authentication attempt; current authentication stage is " |
| 100 | << static_cast<int>(authentication_stage_); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 101 | |
| 102 | if (!login_screen_client_) { |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 103 | std::move(callback).Run(base::nullopt); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 104 | return; |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 105 | } |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 106 | |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 107 | // If auth is disabled by the debug overlay bypass the mojo call entirely, as |
| 108 | // it will dismiss the lock screen if the password is correct. |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 109 | switch (force_fail_auth_for_debug_overlay_) { |
| 110 | case ForceFailAuth::kOff: |
| 111 | break; |
| 112 | case ForceFailAuth::kImmediate: |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 113 | OnAuthenticateComplete(std::move(callback), false /*success*/); |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 114 | return; |
| 115 | case ForceFailAuth::kDelayed: |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 116 | // Set a dummy authentication stage so that |IsAuthenticating| returns |
| 117 | // true. |
| 118 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 119 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 120 | FROM_HERE, |
| 121 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 122 | weak_factory_.GetWeakPtr(), base::Passed(&callback), |
| 123 | false), |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 124 | base::TimeDelta::FromSeconds(1)); |
| 125 | return; |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 126 | } |
| 127 | |
Quan Nguyen | f522435 | 2018-11-06 02:03:34 | [diff] [blame] | 128 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
| 129 | |
| 130 | int dummy_value; |
| 131 | bool is_pin = |
| 132 | authenticated_by_pin && base::StringToInt(password, &dummy_value); |
| 133 | login_screen_client_->AuthenticateUserWithPasswordOrPin( |
| 134 | account_id, password, is_pin, |
| 135 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 136 | weak_factory_.GetWeakPtr(), base::Passed(&callback))); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 137 | } |
| 138 | |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 139 | void LoginScreenController::AuthenticateUserWithExternalBinary( |
| 140 | const AccountId& account_id, |
| 141 | OnAuthenticateCallback callback) { |
| 142 | // It is an error to call this function while an authentication is in |
| 143 | // progress. |
| 144 | LOG_IF(FATAL, IsAuthenticating()) |
| 145 | << "Duplicate authentication attempt; current authentication stage is " |
| 146 | << static_cast<int>(authentication_stage_); |
| 147 | |
| 148 | if (!login_screen_client_) { |
| 149 | std::move(callback).Run(base::nullopt); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
| 154 | login_screen_client_->AuthenticateUserWithExternalBinary( |
| 155 | account_id, |
| 156 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 157 | weak_factory_.GetWeakPtr(), std::move(callback))); |
| 158 | } |
| 159 | |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 160 | void LoginScreenController::EnrollUserWithExternalBinary( |
| 161 | OnAuthenticateCallback callback) { |
| 162 | if (!login_screen_client_) { |
| 163 | std::move(callback).Run(base::nullopt); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | login_screen_client_->EnrollUserWithExternalBinary(base::BindOnce( |
| 168 | [](OnAuthenticateCallback callback, bool success) { |
| 169 | std::move(callback).Run(base::make_optional<bool>(success)); |
| 170 | }, |
| 171 | std::move(callback))); |
| 172 | } |
| 173 | |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 174 | void LoginScreenController::AuthenticateUserWithEasyUnlock( |
| 175 | const AccountId& account_id) { |
| 176 | // TODO(jdufault): integrate this into authenticate stage after mojom is |
| 177 | // refactored to use a callback. |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 178 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 179 | return; |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 180 | login_screen_client_->AuthenticateUserWithEasyUnlock(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 181 | } |
| 182 | |
Aga Wronska | ac6cf36 | 2019-02-26 21:36:55 | [diff] [blame] | 183 | void LoginScreenController::ValidateParentAccessCode( |
Henrique Grandinetti | 4eb2eae | 2019-05-31 16:31:17 | [diff] [blame] | 184 | const AccountId& account_id, |
Aga Wronska | ac6cf36 | 2019-02-26 21:36:55 | [diff] [blame] | 185 | const std::string& code, |
| 186 | OnParentAccessValidation callback) { |
| 187 | if (!login_screen_client_) { |
| 188 | std::move(callback).Run(base::nullopt); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | login_screen_client_->ValidateParentAccessCode( |
| 193 | account_id, code, |
| 194 | base::BindOnce(&LoginScreenController::OnParentAccessValidationComplete, |
| 195 | weak_factory_.GetWeakPtr(), std::move(callback))); |
| 196 | } |
| 197 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 198 | void LoginScreenController::HardlockPod(const AccountId& account_id) { |
| 199 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 200 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 201 | login_screen_client_->HardlockPod(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 202 | } |
| 203 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 204 | void LoginScreenController::OnFocusPod(const AccountId& account_id) { |
| 205 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 206 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 207 | login_screen_client_->OnFocusPod(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 208 | } |
| 209 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 210 | void LoginScreenController::OnNoPodFocused() { |
| 211 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 212 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 213 | login_screen_client_->OnNoPodFocused(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 214 | } |
| 215 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 216 | void LoginScreenController::LoadWallpaper(const AccountId& account_id) { |
| 217 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 218 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 219 | login_screen_client_->LoadWallpaper(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 220 | } |
| 221 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 222 | void LoginScreenController::SignOutUser() { |
| 223 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 224 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 225 | login_screen_client_->SignOutUser(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 226 | } |
| 227 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 228 | void LoginScreenController::CancelAddUser() { |
| 229 | if (!login_screen_client_) |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 230 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 231 | login_screen_client_->CancelAddUser(); |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 232 | } |
| 233 | |
Aga Wronska | 6a32f987 | 2018-01-06 00:16:10 | [diff] [blame] | 234 | void LoginScreenController::LoginAsGuest() { |
| 235 | if (!login_screen_client_) |
| 236 | return; |
| 237 | login_screen_client_->LoginAsGuest(); |
| 238 | } |
| 239 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 240 | void LoginScreenController::OnMaxIncorrectPasswordAttempted( |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 241 | const AccountId& account_id) { |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 242 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 243 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 244 | login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 245 | } |
| 246 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 247 | void LoginScreenController::FocusLockScreenApps(bool reverse) { |
| 248 | if (!login_screen_client_) |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 249 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 250 | login_screen_client_->FocusLockScreenApps(reverse); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 251 | } |
| 252 | |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 253 | void LoginScreenController::ShowGaiaSignin( |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 254 | bool can_close, |
| 255 | const base::Optional<AccountId>& prefilled_account) { |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 256 | if (!login_screen_client_) |
| 257 | return; |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 258 | login_screen_client_->ShowGaiaSignin(can_close, prefilled_account); |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 259 | } |
| 260 | |
Jacob Dufault | fc31c74 | 2018-03-20 17:32:19 | [diff] [blame] | 261 | void LoginScreenController::OnRemoveUserWarningShown() { |
| 262 | if (!login_screen_client_) |
| 263 | return; |
| 264 | login_screen_client_->OnRemoveUserWarningShown(); |
| 265 | } |
| 266 | |
| 267 | void LoginScreenController::RemoveUser(const AccountId& account_id) { |
| 268 | if (!login_screen_client_) |
| 269 | return; |
| 270 | login_screen_client_->RemoveUser(account_id); |
| 271 | } |
| 272 | |
Sarah Hu | 3fcf9f8 | 2018-03-22 20:32:54 | [diff] [blame] | 273 | void LoginScreenController::LaunchPublicSession( |
| 274 | const AccountId& account_id, |
| 275 | const std::string& locale, |
| 276 | const std::string& input_method) { |
| 277 | if (!login_screen_client_) |
| 278 | return; |
| 279 | login_screen_client_->LaunchPublicSession(account_id, locale, input_method); |
| 280 | } |
| 281 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 282 | void LoginScreenController::RequestPublicSessionKeyboardLayouts( |
| 283 | const AccountId& account_id, |
| 284 | const std::string& locale) { |
| 285 | if (!login_screen_client_) |
| 286 | return; |
| 287 | login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale); |
| 288 | } |
| 289 | |
Sarah Hu | 0007c93 | 2018-06-18 20:21:04 | [diff] [blame] | 290 | void LoginScreenController::ShowFeedback() { |
| 291 | if (!login_screen_client_) |
| 292 | return; |
| 293 | login_screen_client_->ShowFeedback(); |
| 294 | } |
| 295 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 296 | void LoginScreenController::FlushForTesting() { |
| 297 | login_screen_client_.FlushForTesting(); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 298 | } |
| 299 | |
Evan Stade | b153f82 | 2019-05-23 19:14:43 | [diff] [blame] | 300 | LoginScreenModel* LoginScreenController::GetModel() { |
Evan Stade | ddde2b2 | 2019-05-24 20:51:31 | [diff] [blame] | 301 | return &login_data_dispatcher_; |
Evan Stade | b153f82 | 2019-05-23 19:14:43 | [diff] [blame] | 302 | } |
| 303 | |
Evan Stade | 98b718e | 2019-06-03 17:15:34 | [diff] [blame^] | 304 | void LoginScreenController::ShowGuestButtonInOobe(bool show) { |
| 305 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 306 | ->shelf_widget() |
| 307 | ->login_shelf_view() |
| 308 | ->ShowGuestButtonInOobe(show); |
| 309 | } |
| 310 | |
| 311 | void LoginScreenController::ShowParentAccessButton(bool show) { |
| 312 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 313 | ->shelf_widget() |
| 314 | ->login_shelf_view() |
| 315 | ->ShowParentAccessButton(show); |
| 316 | } |
| 317 | |
Henrique Grandinetti | 4eb2eae | 2019-05-31 16:31:17 | [diff] [blame] | 318 | void LoginScreenController::ShowParentAccessWidget( |
| 319 | const AccountId& child_account_id, |
| 320 | base::RepeatingCallback<void(bool success)> callback) { |
| 321 | parent_access_widget_ = |
| 322 | std::make_unique<ash::ParentAccessWidget>(child_account_id, callback); |
| 323 | } |
| 324 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 325 | void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) { |
| 326 | login_screen_client_ = std::move(client); |
| 327 | } |
| 328 | |
| 329 | void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) { |
| 330 | OnShow(); |
Evan Stade | 98b718e | 2019-06-03 17:15:34 | [diff] [blame^] | 331 | LockScreen::Show(LockScreen::ScreenType::kLock); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 332 | std::move(on_shown).Run(true); |
| 333 | } |
| 334 | |
| 335 | void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) { |
| 336 | // Login screen can only be used during login. |
| 337 | if (Shell::Get()->session_controller()->GetSessionState() != |
| 338 | session_manager::SessionState::LOGIN_PRIMARY) { |
| 339 | LOG(ERROR) << "Not showing login screen since session state is " |
| 340 | << static_cast<int>( |
| 341 | Shell::Get()->session_controller()->GetSessionState()); |
| 342 | std::move(on_shown).Run(false); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | OnShow(); |
Evan Stade | 98b718e | 2019-06-03 17:15:34 | [diff] [blame^] | 347 | // TODO(jdufault): rename LockScreen to LoginScreen. |
| 348 | LockScreen::Show(LockScreen::ScreenType::kLogin); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 349 | std::move(on_shown).Run(true); |
| 350 | } |
| 351 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 352 | void LoginScreenController::IsReadyForPassword( |
| 353 | IsReadyForPasswordCallback callback) { |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 354 | std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating()); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 355 | } |
| 356 | |
Quan Nguyen | b7c2ea2 | 2018-09-10 17:44:18 | [diff] [blame] | 357 | void LoginScreenController::ShowKioskAppError(const std::string& message) { |
| 358 | ToastData toast_data( |
| 359 | "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/, |
| 360 | base::Optional<base::string16>(base::string16()) /*dismiss_text*/, |
| 361 | true /*visible_on_lock_screen*/); |
| 362 | Shell::Get()->toast_manager()->Show(toast_data); |
| 363 | } |
| 364 | |
Sarah Hu | 51d19d3 | 2018-08-27 19:41:50 | [diff] [blame] | 365 | void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) { |
| 366 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 367 | ->shelf_widget() |
| 368 | ->login_shelf_view() |
| 369 | ->SetAllowLoginAsGuest(allow_guest); |
| 370 | } |
| 371 | |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 372 | void LoginScreenController::FocusLoginShelf(bool reverse) { |
| 373 | Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()); |
| 374 | // Tell the focus direction to the status area or the shelf so they can focus |
| 375 | // the correct child view. |
Jun Mukai | 103f57b | 2018-11-15 01:03:01 | [diff] [blame] | 376 | if (reverse || !ShelfWidget::IsUsingViewsShelf()) { |
| 377 | if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible()) |
Jun Mukai | d96b4d745 | 2018-11-09 00:37:23 | [diff] [blame] | 378 | return; |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 379 | shelf->GetStatusAreaWidget() |
| 380 | ->status_area_widget_delegate() |
| 381 | ->set_default_last_focusable_child(reverse); |
| 382 | Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget()); |
| 383 | } else { |
| 384 | shelf->shelf_widget()->set_default_last_focusable_child(reverse); |
| 385 | Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget()); |
| 386 | } |
| 387 | } |
| 388 | |
Evan Stade | 9c07ab4 | 2019-05-13 21:21:56 | [diff] [blame] | 389 | void LoginScreenController::SetKioskApps( |
| 390 | const std::vector<KioskAppMenuEntry>& kiosk_apps, |
| 391 | const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) { |
| 392 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 393 | ->shelf_widget() |
| 394 | ->login_shelf_view() |
| 395 | ->SetKioskApps(kiosk_apps, launch_app); |
| 396 | } |
| 397 | |
Sarah Hu | 4976046e | 2018-07-19 23:47:47 | [diff] [blame] | 398 | void LoginScreenController::SetAddUserButtonEnabled(bool enable) { |
| 399 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 400 | ->shelf_widget() |
| 401 | ->login_shelf_view() |
| 402 | ->SetAddUserButtonEnabled(enable); |
| 403 | } |
| 404 | |
Bruno Santos | cf9d9cc | 2018-12-14 13:18:45 | [diff] [blame] | 405 | void LoginScreenController::SetShutdownButtonEnabled(bool enable) { |
| 406 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 407 | ->shelf_widget() |
| 408 | ->login_shelf_view() |
| 409 | ->SetShutdownButtonEnabled(enable); |
| 410 | } |
| 411 | |
Quan Nguyen | e3e1d25 | 2018-07-19 23:00:44 | [diff] [blame] | 412 | void LoginScreenController::ShowResetScreen() { |
| 413 | login_screen_client_->ShowResetScreen(); |
| 414 | } |
| 415 | |
Quan Nguyen | ff20e23 | 2018-08-02 21:34:11 | [diff] [blame] | 416 | void LoginScreenController::ShowAccountAccessHelpApp() { |
| 417 | login_screen_client_->ShowAccountAccessHelpApp(); |
| 418 | } |
| 419 | |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 420 | void LoginScreenController::FocusOobeDialog() { |
Tony de Luna | 4680193 | 2019-03-11 18:02:01 | [diff] [blame] | 421 | if (!login_screen_client_) |
| 422 | return; |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 423 | login_screen_client_->FocusOobeDialog(); |
| 424 | } |
| 425 | |
Quan Nguyen | e377eb6 | 2019-02-11 23:02:25 | [diff] [blame] | 426 | void LoginScreenController::NotifyUserActivity() { |
Xiyuan Xia | 5a8c417 | 2019-05-13 16:23:48 | [diff] [blame] | 427 | if (!login_screen_client_) |
| 428 | return; |
Quan Nguyen | e377eb6 | 2019-02-11 23:02:25 | [diff] [blame] | 429 | login_screen_client_->OnUserActivity(); |
| 430 | } |
| 431 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 432 | void LoginScreenController::OnAuthenticateComplete( |
| 433 | OnAuthenticateCallback callback, |
| 434 | bool success) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 435 | authentication_stage_ = AuthenticationStage::kUserCallback; |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 436 | std::move(callback).Run(base::make_optional<bool>(success)); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 437 | authentication_stage_ = AuthenticationStage::kIdle; |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 438 | } |
| 439 | |
Aga Wronska | ac6cf36 | 2019-02-26 21:36:55 | [diff] [blame] | 440 | void LoginScreenController::OnParentAccessValidationComplete( |
| 441 | OnParentAccessValidation callback, |
| 442 | bool success) { |
| 443 | std::move(callback).Run(base::make_optional<bool>(success)); |
| 444 | } |
| 445 | |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 446 | void LoginScreenController::OnShow() { |
| 447 | SetSystemTrayVisibility(SystemTrayVisibility::kPrimary); |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 448 | if (authentication_stage_ != AuthenticationStage::kIdle) { |
| 449 | AuthenticationStage authentication_stage = authentication_stage_; |
| 450 | base::debug::Alias(&authentication_stage); |
| 451 | LOG(FATAL) << "Unexpected authentication stage " |
| 452 | << static_cast<int>(authentication_stage_); |
| 453 | } |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 454 | } |
| 455 | |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 456 | void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) { |
| 457 | if (!login_screen_client_) |
| 458 | return; |
| 459 | login_screen_client_->OnFocusLeavingSystemTray(reverse); |
| 460 | } |
| 461 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 462 | } // namespace ash |