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