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" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 12 | #include "ash/public/cpp/ash_pref_names.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 13 | #include "ash/root_window_controller.h" |
Xiyuan Xia | e7b1954 | 2019-05-06 23:05:18 | [diff] [blame] | 14 | #include "ash/session/session_controller_impl.h" |
Jacob Dufault | 5ac266ef | 2018-07-18 17:30:30 | [diff] [blame] | 15 | #include "ash/shelf/login_shelf_view.h" |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 16 | #include "ash/shelf/shelf.h" |
| 17 | #include "ash/shelf/shelf_widget.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 18 | #include "ash/shell.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 19 | #include "ash/system/status_area_widget.h" |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 20 | #include "ash/system/status_area_widget_delegate.h" |
Quan Nguyen | b7c2ea2 | 2018-09-10 17:44:18 | [diff] [blame] | 21 | #include "ash/system/toast/toast_data.h" |
| 22 | #include "ash/system/toast/toast_manager.h" |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 23 | #include "ash/system/tray/system_tray_notifier.h" |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 24 | #include "base/bind.h" |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 25 | #include "base/debug/alias.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 26 | #include "base/strings/string_number_conversions.h" |
Jialiu Lin | f99b788b | 2018-01-17 23:01:21 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 28 | #include "components/prefs/pref_registry_simple.h" |
Jacob Dufault | 957e092 | 2017-12-06 19:16:09 | [diff] [blame] | 29 | #include "components/session_manager/session_manager_types.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 30 | |
| 31 | namespace ash { |
| 32 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 33 | namespace { |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 34 | |
Aga Wronska | a844cdcd1 | 2018-01-29 16:06:44 | [diff] [blame] | 35 | enum class SystemTrayVisibility { |
| 36 | kNone, // Tray not visible anywhere. |
| 37 | kPrimary, // Tray visible only on primary display. |
| 38 | kAll, // Tray visible on all displays. |
| 39 | }; |
| 40 | |
| 41 | void SetSystemTrayVisibility(SystemTrayVisibility visibility) { |
| 42 | RootWindowController* primary_window_controller = |
| 43 | Shell::GetPrimaryRootWindowController(); |
| 44 | for (RootWindowController* window_controller : |
| 45 | Shell::GetAllRootWindowControllers()) { |
| 46 | StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget(); |
| 47 | if (!status_area) |
| 48 | continue; |
| 49 | if (window_controller == primary_window_controller) { |
| 50 | status_area->SetSystemTrayVisibility( |
| 51 | visibility == SystemTrayVisibility::kPrimary || |
| 52 | visibility == SystemTrayVisibility::kAll); |
| 53 | } else { |
| 54 | status_area->SetSystemTrayVisibility(visibility == |
| 55 | SystemTrayVisibility::kAll); |
| 56 | } |
| 57 | } |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 58 | } |
| 59 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 60 | } // namespace |
| 61 | |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 62 | LoginScreenController::LoginScreenController( |
| 63 | SystemTrayNotifier* system_tray_notifier) |
| 64 | : system_tray_notifier_(system_tray_notifier), weak_factory_(this) { |
| 65 | system_tray_notifier_->AddSystemTrayFocusObserver(this); |
| 66 | } |
James Cook | 8f1e606 | 2017-11-13 23:40:59 | [diff] [blame] | 67 | |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 68 | LoginScreenController::~LoginScreenController() { |
| 69 | system_tray_notifier_->RemoveSystemTrayFocusObserver(this); |
| 70 | } |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 71 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 72 | // static |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 73 | void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry, |
| 74 | bool for_test) { |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 75 | if (for_test) { |
| 76 | // There is no remote pref service, so pretend that ash owns the pref. |
| 77 | registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, ""); |
| 78 | return; |
| 79 | } |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 80 | } |
| 81 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 82 | void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) { |
James Cook | ede316a | 2017-12-14 22:38:43 | [diff] [blame] | 83 | bindings_.AddBinding(this, std::move(request)); |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 84 | } |
| 85 | |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 86 | bool LoginScreenController::IsAuthenticating() const { |
| 87 | return authentication_stage_ != AuthenticationStage::kIdle; |
| 88 | } |
| 89 | |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 90 | void LoginScreenController::AuthenticateUserWithPasswordOrPin( |
| 91 | const AccountId& account_id, |
| 92 | const std::string& password, |
| 93 | bool authenticated_by_pin, |
| 94 | OnAuthenticateCallback callback) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 95 | // It is an error to call this function while an authentication is in |
| 96 | // progress. |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 97 | LOG_IF(FATAL, IsAuthenticating()) |
Jacob Dufault | 58a1bf4 | 2018-07-10 17:44:56 | [diff] [blame] | 98 | << "Duplicate authentication attempt; current authentication stage is " |
| 99 | << static_cast<int>(authentication_stage_); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 100 | |
| 101 | if (!login_screen_client_) { |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 102 | std::move(callback).Run(base::nullopt); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 103 | return; |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 104 | } |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 105 | |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 106 | // If auth is disabled by the debug overlay bypass the mojo call entirely, as |
| 107 | // it will dismiss the lock screen if the password is correct. |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 108 | switch (force_fail_auth_for_debug_overlay_) { |
| 109 | case ForceFailAuth::kOff: |
| 110 | break; |
| 111 | case ForceFailAuth::kImmediate: |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 112 | OnAuthenticateComplete(std::move(callback), false /*success*/); |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 113 | return; |
| 114 | case ForceFailAuth::kDelayed: |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 115 | // Set a dummy authentication stage so that |IsAuthenticating| returns |
| 116 | // true. |
| 117 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 118 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 119 | FROM_HERE, |
| 120 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 121 | weak_factory_.GetWeakPtr(), base::Passed(&callback), |
| 122 | false), |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 123 | base::TimeDelta::FromSeconds(1)); |
| 124 | return; |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 125 | } |
| 126 | |
Quan Nguyen | f522435 | 2018-11-06 02:03:34 | [diff] [blame] | 127 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
| 128 | |
| 129 | int dummy_value; |
| 130 | bool is_pin = |
| 131 | authenticated_by_pin && base::StringToInt(password, &dummy_value); |
| 132 | login_screen_client_->AuthenticateUserWithPasswordOrPin( |
| 133 | account_id, password, is_pin, |
| 134 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 135 | weak_factory_.GetWeakPtr(), base::Passed(&callback))); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 136 | } |
| 137 | |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 138 | void LoginScreenController::AuthenticateUserWithExternalBinary( |
| 139 | const AccountId& account_id, |
| 140 | OnAuthenticateCallback callback) { |
| 141 | // It is an error to call this function while an authentication is in |
| 142 | // progress. |
| 143 | LOG_IF(FATAL, IsAuthenticating()) |
| 144 | << "Duplicate authentication attempt; current authentication stage is " |
| 145 | << static_cast<int>(authentication_stage_); |
| 146 | |
| 147 | if (!login_screen_client_) { |
| 148 | std::move(callback).Run(base::nullopt); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
| 153 | login_screen_client_->AuthenticateUserWithExternalBinary( |
| 154 | account_id, |
| 155 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 156 | weak_factory_.GetWeakPtr(), std::move(callback))); |
| 157 | } |
| 158 | |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 159 | void LoginScreenController::EnrollUserWithExternalBinary( |
| 160 | OnAuthenticateCallback callback) { |
| 161 | if (!login_screen_client_) { |
| 162 | std::move(callback).Run(base::nullopt); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | login_screen_client_->EnrollUserWithExternalBinary(base::BindOnce( |
| 167 | [](OnAuthenticateCallback callback, bool success) { |
| 168 | std::move(callback).Run(base::make_optional<bool>(success)); |
| 169 | }, |
| 170 | std::move(callback))); |
| 171 | } |
| 172 | |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 173 | void LoginScreenController::AuthenticateUserWithEasyUnlock( |
| 174 | const AccountId& account_id) { |
| 175 | // TODO(jdufault): integrate this into authenticate stage after mojom is |
| 176 | // refactored to use a callback. |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 177 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 178 | return; |
Jacob Dufault | 2d20ae6 | 2018-09-20 22:19:52 | [diff] [blame] | 179 | login_screen_client_->AuthenticateUserWithEasyUnlock(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 180 | } |
| 181 | |
Aga Wronska | ac6cf36 | 2019-02-26 21:36:55 | [diff] [blame] | 182 | void LoginScreenController::ValidateParentAccessCode( |
| 183 | const AccountId& account_id, |
| 184 | const std::string& code, |
| 185 | OnParentAccessValidation callback) { |
| 186 | if (!login_screen_client_) { |
| 187 | std::move(callback).Run(base::nullopt); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | login_screen_client_->ValidateParentAccessCode( |
| 192 | account_id, code, |
| 193 | base::BindOnce(&LoginScreenController::OnParentAccessValidationComplete, |
| 194 | weak_factory_.GetWeakPtr(), std::move(callback))); |
| 195 | } |
| 196 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 197 | void LoginScreenController::HardlockPod(const AccountId& account_id) { |
| 198 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 199 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 200 | login_screen_client_->HardlockPod(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 201 | } |
| 202 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 203 | void LoginScreenController::OnFocusPod(const AccountId& account_id) { |
| 204 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 205 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 206 | login_screen_client_->OnFocusPod(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 207 | } |
| 208 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 209 | void LoginScreenController::OnNoPodFocused() { |
| 210 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 211 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 212 | login_screen_client_->OnNoPodFocused(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 213 | } |
| 214 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 215 | void LoginScreenController::LoadWallpaper(const AccountId& account_id) { |
| 216 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 217 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 218 | login_screen_client_->LoadWallpaper(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 219 | } |
| 220 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 221 | void LoginScreenController::SignOutUser() { |
| 222 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 223 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 224 | login_screen_client_->SignOutUser(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 225 | } |
| 226 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 227 | void LoginScreenController::CancelAddUser() { |
| 228 | if (!login_screen_client_) |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 229 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 230 | login_screen_client_->CancelAddUser(); |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 231 | } |
| 232 | |
Aga Wronska | 6a32f987 | 2018-01-06 00:16:10 | [diff] [blame] | 233 | void LoginScreenController::LoginAsGuest() { |
| 234 | if (!login_screen_client_) |
| 235 | return; |
| 236 | login_screen_client_->LoginAsGuest(); |
| 237 | } |
| 238 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 239 | void LoginScreenController::OnMaxIncorrectPasswordAttempted( |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 240 | const AccountId& account_id) { |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 241 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 242 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 243 | login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 244 | } |
| 245 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 246 | void LoginScreenController::FocusLockScreenApps(bool reverse) { |
| 247 | if (!login_screen_client_) |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 248 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 249 | login_screen_client_->FocusLockScreenApps(reverse); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 250 | } |
| 251 | |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 252 | void LoginScreenController::ShowGaiaSignin( |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 253 | bool can_close, |
| 254 | const base::Optional<AccountId>& prefilled_account) { |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 255 | if (!login_screen_client_) |
| 256 | return; |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 257 | login_screen_client_->ShowGaiaSignin(can_close, prefilled_account); |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 258 | } |
| 259 | |
Jacob Dufault | fc31c74 | 2018-03-20 17:32:19 | [diff] [blame] | 260 | void LoginScreenController::OnRemoveUserWarningShown() { |
| 261 | if (!login_screen_client_) |
| 262 | return; |
| 263 | login_screen_client_->OnRemoveUserWarningShown(); |
| 264 | } |
| 265 | |
| 266 | void LoginScreenController::RemoveUser(const AccountId& account_id) { |
| 267 | if (!login_screen_client_) |
| 268 | return; |
| 269 | login_screen_client_->RemoveUser(account_id); |
| 270 | } |
| 271 | |
Sarah Hu | 3fcf9f8 | 2018-03-22 20:32:54 | [diff] [blame] | 272 | void LoginScreenController::LaunchPublicSession( |
| 273 | const AccountId& account_id, |
| 274 | const std::string& locale, |
| 275 | const std::string& input_method) { |
| 276 | if (!login_screen_client_) |
| 277 | return; |
| 278 | login_screen_client_->LaunchPublicSession(account_id, locale, input_method); |
| 279 | } |
| 280 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 281 | void LoginScreenController::RequestPublicSessionKeyboardLayouts( |
| 282 | const AccountId& account_id, |
| 283 | const std::string& locale) { |
| 284 | if (!login_screen_client_) |
| 285 | return; |
| 286 | login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale); |
| 287 | } |
| 288 | |
Sarah Hu | 0007c93 | 2018-06-18 20:21:04 | [diff] [blame] | 289 | void LoginScreenController::ShowFeedback() { |
| 290 | if (!login_screen_client_) |
| 291 | return; |
| 292 | login_screen_client_->ShowFeedback(); |
| 293 | } |
| 294 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 295 | void LoginScreenController::AddObserver( |
| 296 | LoginScreenControllerObserver* observer) { |
| 297 | observers_.AddObserver(observer); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 298 | } |
| 299 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 300 | void LoginScreenController::RemoveObserver( |
| 301 | LoginScreenControllerObserver* observer) { |
| 302 | observers_.RemoveObserver(observer); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 303 | } |
| 304 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 305 | void LoginScreenController::FlushForTesting() { |
| 306 | login_screen_client_.FlushForTesting(); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 307 | } |
| 308 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 309 | void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) { |
| 310 | login_screen_client_ = std::move(client); |
| 311 | } |
| 312 | |
| 313 | void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) { |
| 314 | OnShow(); |
| 315 | ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock); |
| 316 | std::move(on_shown).Run(true); |
| 317 | } |
| 318 | |
| 319 | void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) { |
| 320 | // Login screen can only be used during login. |
| 321 | if (Shell::Get()->session_controller()->GetSessionState() != |
| 322 | session_manager::SessionState::LOGIN_PRIMARY) { |
| 323 | LOG(ERROR) << "Not showing login screen since session state is " |
| 324 | << static_cast<int>( |
| 325 | Shell::Get()->session_controller()->GetSessionState()); |
| 326 | std::move(on_shown).Run(false); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | OnShow(); |
| 331 | // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen. |
| 332 | ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin); |
| 333 | std::move(on_shown).Run(true); |
| 334 | } |
| 335 | |
| 336 | void LoginScreenController::ShowErrorMessage(int32_t login_attempts, |
| 337 | const std::string& error_text, |
| 338 | const std::string& help_link_text, |
| 339 | int32_t help_topic_id) { |
| 340 | NOTIMPLEMENTED(); |
| 341 | } |
| 342 | |
Naoki Fukino | 00a14cbc | 2018-08-08 05:27:22 | [diff] [blame] | 343 | void LoginScreenController::ShowWarningBanner(const base::string16& message) { |
| 344 | if (DataDispatcher()) |
| 345 | DataDispatcher()->ShowWarningBanner(message); |
| 346 | } |
| 347 | |
| 348 | void LoginScreenController::HideWarningBanner() { |
| 349 | if (DataDispatcher()) |
| 350 | DataDispatcher()->HideWarningBanner(); |
| 351 | } |
| 352 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 353 | void LoginScreenController::ClearErrors() { |
| 354 | NOTIMPLEMENTED(); |
| 355 | } |
| 356 | |
| 357 | void LoginScreenController::ShowUserPodCustomIcon( |
| 358 | const AccountId& account_id, |
| 359 | mojom::EasyUnlockIconOptionsPtr icon) { |
| 360 | DataDispatcher()->ShowEasyUnlockIcon(account_id, icon); |
| 361 | } |
| 362 | |
| 363 | void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) { |
| 364 | auto icon_options = mojom::EasyUnlockIconOptions::New(); |
| 365 | icon_options->icon = mojom::EasyUnlockIconId::NONE; |
| 366 | DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options); |
| 367 | } |
| 368 | |
| 369 | void LoginScreenController::SetAuthType( |
| 370 | const AccountId& account_id, |
| 371 | proximity_auth::mojom::AuthType auth_type, |
| 372 | const base::string16& initial_value) { |
| 373 | if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) { |
Jacob Dufault | 21cd566 | 2018-08-07 18:04:33 | [diff] [blame] | 374 | DataDispatcher()->SetTapToUnlockEnabledForUser(account_id, |
| 375 | true /*enabled*/); |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 376 | } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) { |
| 377 | DataDispatcher()->SetForceOnlineSignInForUser(account_id); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 378 | } else { |
| 379 | NOTIMPLEMENTED(); |
| 380 | } |
| 381 | } |
| 382 | |
Sarah Hu | 51d19d3 | 2018-08-27 19:41:50 | [diff] [blame] | 383 | void LoginScreenController::SetUserList( |
| 384 | std::vector<mojom::LoginUserInfoPtr> users) { |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 385 | DCHECK(DataDispatcher()); |
| 386 | |
| 387 | DataDispatcher()->NotifyUsers(users); |
| 388 | } |
| 389 | |
| 390 | void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id, |
| 391 | bool is_enabled) { |
| 392 | // Chrome will update pin pod state every time user tries to authenticate. |
| 393 | // LockScreen is destroyed in the case of authentication success. |
| 394 | if (DataDispatcher()) |
| 395 | DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled); |
| 396 | } |
| 397 | |
Jacob Dufault | 947f247 | 2018-10-24 21:08:16 | [diff] [blame] | 398 | void LoginScreenController::SetFingerprintState(const AccountId& account_id, |
| 399 | mojom::FingerprintState state) { |
| 400 | if (DataDispatcher()) |
| 401 | DataDispatcher()->SetFingerprintState(account_id, state); |
| 402 | } |
| 403 | |
| 404 | void LoginScreenController::NotifyFingerprintAuthResult( |
| 405 | const AccountId& account_id, |
| 406 | bool successful) { |
| 407 | if (DataDispatcher()) |
| 408 | DataDispatcher()->NotifyFingerprintAuthResult(account_id, successful); |
| 409 | } |
| 410 | |
Jacob Dufault | 77d75ce9 | 2018-04-13 18:20:09 | [diff] [blame] | 411 | void LoginScreenController::SetAvatarForUser(const AccountId& account_id, |
| 412 | mojom::UserAvatarPtr avatar) { |
| 413 | for (auto& observer : observers_) |
| 414 | observer.SetAvatarForUser(account_id, avatar); |
| 415 | } |
| 416 | |
Henrique Grandinetti | d8951be | 2019-03-15 21:04:05 | [diff] [blame] | 417 | void LoginScreenController::EnableAuthForUser(const AccountId& account_id) { |
| 418 | if (DataDispatcher()) |
| 419 | DataDispatcher()->EnableAuthForUser(account_id); |
| 420 | } |
| 421 | |
| 422 | void LoginScreenController::DisableAuthForUser( |
Wenzhao Zang | e0c2ab2 | 2018-05-23 17:43:46 | [diff] [blame] | 423 | const AccountId& account_id, |
Henrique Grandinetti | d8951be | 2019-03-15 21:04:05 | [diff] [blame] | 424 | ash::mojom::AuthDisabledDataPtr auth_disabled_data) { |
Wenzhao Zang | e0c2ab2 | 2018-05-23 17:43:46 | [diff] [blame] | 425 | if (DataDispatcher()) { |
Henrique Grandinetti | d8951be | 2019-03-15 21:04:05 | [diff] [blame] | 426 | DataDispatcher()->DisableAuthForUser(account_id, |
| 427 | std::move(auth_disabled_data)); |
Wenzhao Zang | e0c2ab2 | 2018-05-23 17:43:46 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 431 | void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) { |
| 432 | for (auto& observer : observers_) |
| 433 | observer.OnFocusLeavingLockScreenApps(reverse); |
| 434 | } |
| 435 | |
Jacob Dufault | 5fc3139 | 2018-10-03 22:15:02 | [diff] [blame] | 436 | void LoginScreenController::SetSystemInfo( |
| 437 | bool show_if_hidden, |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 438 | const std::string& os_version_label_text, |
| 439 | const std::string& enterprise_info_text, |
| 440 | const std::string& bluetooth_name) { |
| 441 | if (DataDispatcher()) { |
Jacob Dufault | 5fc3139 | 2018-10-03 22:15:02 | [diff] [blame] | 442 | DataDispatcher()->SetSystemInfo(show_if_hidden, os_version_label_text, |
| 443 | enterprise_info_text, bluetooth_name); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | void LoginScreenController::IsReadyForPassword( |
| 448 | IsReadyForPasswordCallback callback) { |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 449 | std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating()); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | void LoginScreenController::SetPublicSessionDisplayName( |
| 453 | const AccountId& account_id, |
| 454 | const std::string& display_name) { |
| 455 | if (DataDispatcher()) |
| 456 | DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name); |
| 457 | } |
| 458 | |
| 459 | void LoginScreenController::SetPublicSessionLocales( |
| 460 | const AccountId& account_id, |
Sarah Hu | e9cd613 | 2018-05-17 17:25:56 | [diff] [blame] | 461 | std::vector<mojom::LocaleItemPtr> locales, |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 462 | const std::string& default_locale, |
| 463 | bool show_advanced_view) { |
| 464 | if (DataDispatcher()) { |
| 465 | DataDispatcher()->SetPublicSessionLocales( |
Sarah Hu | e9cd613 | 2018-05-17 17:25:56 | [diff] [blame] | 466 | account_id, locales, default_locale, show_advanced_view); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 470 | void LoginScreenController::SetPublicSessionKeyboardLayouts( |
| 471 | const AccountId& account_id, |
| 472 | const std::string& locale, |
| 473 | std::vector<mojom::InputMethodItemPtr> keyboard_layouts) { |
| 474 | if (DataDispatcher()) { |
| 475 | DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale, |
| 476 | keyboard_layouts); |
| 477 | } |
| 478 | } |
| 479 | |
Zakhar Voit | f99f63b | 2018-12-04 00:37:33 | [diff] [blame] | 480 | void LoginScreenController::SetPublicSessionShowFullManagementDisclosure( |
| 481 | bool is_full_management_disclosure_needed) { |
| 482 | if (DataDispatcher()) { |
| 483 | DataDispatcher()->SetPublicSessionShowFullManagementDisclosure( |
| 484 | is_full_management_disclosure_needed); |
| 485 | } |
| 486 | } |
| 487 | |
Quan Nguyen | b7c2ea2 | 2018-09-10 17:44:18 | [diff] [blame] | 488 | void LoginScreenController::ShowKioskAppError(const std::string& message) { |
| 489 | ToastData toast_data( |
| 490 | "KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/, |
| 491 | base::Optional<base::string16>(base::string16()) /*dismiss_text*/, |
| 492 | true /*visible_on_lock_screen*/); |
| 493 | Shell::Get()->toast_manager()->Show(toast_data); |
| 494 | } |
| 495 | |
Sarah Hu | 51d19d3 | 2018-08-27 19:41:50 | [diff] [blame] | 496 | void LoginScreenController::NotifyOobeDialogState( |
| 497 | mojom::OobeDialogState state) { |
Quan Nguyen | c6ff315 | 2018-08-07 20:00:37 | [diff] [blame] | 498 | for (auto& observer : observers_) |
Sarah Hu | 51d19d3 | 2018-08-27 19:41:50 | [diff] [blame] | 499 | observer.OnOobeDialogStateChanged(state); |
| 500 | } |
| 501 | |
| 502 | void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) { |
| 503 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 504 | ->shelf_widget() |
| 505 | ->login_shelf_view() |
| 506 | ->SetAllowLoginAsGuest(allow_guest); |
| 507 | } |
| 508 | |
Quan Nguyen | cb8acab | 2018-12-05 20:39:08 | [diff] [blame] | 509 | void LoginScreenController::SetShowGuestButtonInOobe(bool show) { |
Sarah Hu | 51d19d3 | 2018-08-27 19:41:50 | [diff] [blame] | 510 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 511 | ->shelf_widget() |
| 512 | ->login_shelf_view() |
Quan Nguyen | cb8acab | 2018-12-05 20:39:08 | [diff] [blame] | 513 | ->SetShowGuestButtonInOobe(show); |
Jacob Dufault | 883dcf7 | 2018-06-27 22:52:32 | [diff] [blame] | 514 | } |
| 515 | |
Aga Wronska | 49827d3 | 2019-02-01 03:36:39 | [diff] [blame] | 516 | void LoginScreenController::SetShowParentAccessButton(bool show) { |
Aga Wronska | 850597a | 2019-01-02 22:07:23 | [diff] [blame] | 517 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 518 | ->shelf_widget() |
| 519 | ->login_shelf_view() |
Aga Wronska | 49827d3 | 2019-02-01 03:36:39 | [diff] [blame] | 520 | ->SetShowParentAccessButton(show); |
Aga Wronska | 850597a | 2019-01-02 22:07:23 | [diff] [blame] | 521 | } |
| 522 | |
Aga Wronska | 143a18a | 2019-02-13 23:07:17 | [diff] [blame] | 523 | void LoginScreenController::SetShowParentAccessDialog(bool show) { |
| 524 | if (DataDispatcher()) |
| 525 | DataDispatcher()->SetShowParentAccessDialog(show); |
| 526 | } |
| 527 | |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 528 | void LoginScreenController::FocusLoginShelf(bool reverse) { |
| 529 | Shelf* shelf = Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()); |
| 530 | // Tell the focus direction to the status area or the shelf so they can focus |
| 531 | // the correct child view. |
Jun Mukai | 103f57b | 2018-11-15 01:03:01 | [diff] [blame] | 532 | if (reverse || !ShelfWidget::IsUsingViewsShelf()) { |
| 533 | if (!Shell::GetPrimaryRootWindowController()->IsSystemTrayVisible()) |
Jun Mukai | d96b4d745 | 2018-11-09 00:37:23 | [diff] [blame] | 534 | return; |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 535 | shelf->GetStatusAreaWidget() |
| 536 | ->status_area_widget_delegate() |
| 537 | ->set_default_last_focusable_child(reverse); |
| 538 | Shell::Get()->focus_cycler()->FocusWidget(shelf->GetStatusAreaWidget()); |
| 539 | } else { |
| 540 | shelf->shelf_widget()->set_default_last_focusable_child(reverse); |
| 541 | Shell::Get()->focus_cycler()->FocusWidget(shelf->shelf_widget()); |
| 542 | } |
| 543 | } |
| 544 | |
Evan Stade | 9c07ab4 | 2019-05-13 21:21:56 | [diff] [blame^] | 545 | void LoginScreenController::SetKioskApps( |
| 546 | const std::vector<KioskAppMenuEntry>& kiosk_apps, |
| 547 | const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) { |
| 548 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 549 | ->shelf_widget() |
| 550 | ->login_shelf_view() |
| 551 | ->SetKioskApps(kiosk_apps, launch_app); |
| 552 | } |
| 553 | |
Sarah Hu | 4976046e | 2018-07-19 23:47:47 | [diff] [blame] | 554 | void LoginScreenController::SetAddUserButtonEnabled(bool enable) { |
| 555 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 556 | ->shelf_widget() |
| 557 | ->login_shelf_view() |
| 558 | ->SetAddUserButtonEnabled(enable); |
| 559 | } |
| 560 | |
Bruno Santos | cf9d9cc | 2018-12-14 13:18:45 | [diff] [blame] | 561 | void LoginScreenController::SetShutdownButtonEnabled(bool enable) { |
| 562 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 563 | ->shelf_widget() |
| 564 | ->login_shelf_view() |
| 565 | ->SetShutdownButtonEnabled(enable); |
| 566 | } |
| 567 | |
Quan Nguyen | e3e1d25 | 2018-07-19 23:00:44 | [diff] [blame] | 568 | void LoginScreenController::ShowResetScreen() { |
| 569 | login_screen_client_->ShowResetScreen(); |
| 570 | } |
| 571 | |
Quan Nguyen | ff20e23 | 2018-08-02 21:34:11 | [diff] [blame] | 572 | void LoginScreenController::ShowAccountAccessHelpApp() { |
| 573 | login_screen_client_->ShowAccountAccessHelpApp(); |
| 574 | } |
| 575 | |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 576 | void LoginScreenController::FocusOobeDialog() { |
Tony de Luna | 4680193 | 2019-03-11 18:02:01 | [diff] [blame] | 577 | if (!login_screen_client_) |
| 578 | return; |
Quan Nguyen | 3d7a0f0 | 2018-09-04 23:53:55 | [diff] [blame] | 579 | login_screen_client_->FocusOobeDialog(); |
| 580 | } |
| 581 | |
Quan Nguyen | e377eb6 | 2019-02-11 23:02:25 | [diff] [blame] | 582 | void LoginScreenController::NotifyUserActivity() { |
Xiyuan Xia | 5a8c417 | 2019-05-13 16:23:48 | [diff] [blame] | 583 | if (!login_screen_client_) |
| 584 | return; |
Quan Nguyen | e377eb6 | 2019-02-11 23:02:25 | [diff] [blame] | 585 | login_screen_client_->OnUserActivity(); |
| 586 | } |
| 587 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 588 | void LoginScreenController::OnAuthenticateComplete( |
| 589 | OnAuthenticateCallback callback, |
| 590 | bool success) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 591 | authentication_stage_ = AuthenticationStage::kUserCallback; |
Quan Nguyen | 92f924a | 2018-10-18 18:36:46 | [diff] [blame] | 592 | std::move(callback).Run(base::make_optional<bool>(success)); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 593 | authentication_stage_ = AuthenticationStage::kIdle; |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 594 | } |
| 595 | |
Aga Wronska | ac6cf36 | 2019-02-26 21:36:55 | [diff] [blame] | 596 | void LoginScreenController::OnParentAccessValidationComplete( |
| 597 | OnParentAccessValidation callback, |
| 598 | bool success) { |
| 599 | std::move(callback).Run(base::make_optional<bool>(success)); |
| 600 | } |
| 601 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 602 | LoginDataDispatcher* LoginScreenController::DataDispatcher() const { |
Wenzhao Zang | 73349728 | 2018-06-12 16:53:10 | [diff] [blame] | 603 | if (!ash::LockScreen::HasInstance()) |
Jacob Dufault | 40623d5 | 2017-09-15 17:22:53 | [diff] [blame] | 604 | return nullptr; |
| 605 | return ash::LockScreen::Get()->data_dispatcher(); |
| 606 | } |
| 607 | |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 608 | void LoginScreenController::OnShow() { |
| 609 | SetSystemTrayVisibility(SystemTrayVisibility::kPrimary); |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 610 | if (authentication_stage_ != AuthenticationStage::kIdle) { |
| 611 | AuthenticationStage authentication_stage = authentication_stage_; |
| 612 | base::debug::Alias(&authentication_stage); |
| 613 | LOG(FATAL) << "Unexpected authentication stage " |
| 614 | << static_cast<int>(authentication_stage_); |
| 615 | } |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 616 | } |
| 617 | |
Jun Mukai | 5c7b5b4 | 2018-11-30 00:08:50 | [diff] [blame] | 618 | void LoginScreenController::OnFocusLeavingSystemTray(bool reverse) { |
| 619 | if (!login_screen_client_) |
| 620 | return; |
| 621 | login_screen_client_->OnFocusLeavingSystemTray(reverse); |
| 622 | } |
| 623 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 624 | } // namespace ash |