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 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame] | 7 | #include "ash/login/ui/lock_screen.h" |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 8 | #include "ash/login/ui/lock_window.h" |
Jacob Dufault | 40623d5 | 2017-09-15 17:22:53 | [diff] [blame] | 9 | #include "ash/login/ui/login_data_dispatcher.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 10 | #include "ash/public/cpp/ash_pref_names.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 11 | #include "ash/root_window_controller.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 12 | #include "ash/session/session_controller.h" |
Jacob Dufault | 5ac266ef | 2018-07-18 17:30:30 | [diff] [blame^] | 13 | #include "ash/shelf/login_shelf_view.h" |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 14 | #include "ash/shelf/shelf.h" |
| 15 | #include "ash/shelf/shelf_widget.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 16 | #include "ash/shell.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 17 | #include "ash/system/status_area_widget.h" |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 18 | #include "base/debug/alias.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 19 | #include "base/strings/string_number_conversions.h" |
Jialiu Lin | f99b788b | 2018-01-17 23:01:21 | [diff] [blame] | 20 | #include "base/strings/utf_string_conversions.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 21 | #include "chromeos/cryptohome/system_salt_getter.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 22 | #include "components/prefs/pref_registry_simple.h" |
Jacob Dufault | 957e092 | 2017-12-06 19:16:09 | [diff] [blame] | 23 | #include "components/session_manager/session_manager_types.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 24 | |
| 25 | namespace ash { |
| 26 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 27 | namespace { |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 28 | |
Aga Wronska | a844cdcd1 | 2018-01-29 16:06:44 | [diff] [blame] | 29 | enum class SystemTrayVisibility { |
| 30 | kNone, // Tray not visible anywhere. |
| 31 | kPrimary, // Tray visible only on primary display. |
| 32 | kAll, // Tray visible on all displays. |
| 33 | }; |
| 34 | |
| 35 | void SetSystemTrayVisibility(SystemTrayVisibility visibility) { |
| 36 | RootWindowController* primary_window_controller = |
| 37 | Shell::GetPrimaryRootWindowController(); |
| 38 | for (RootWindowController* window_controller : |
| 39 | Shell::GetAllRootWindowControllers()) { |
| 40 | StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget(); |
| 41 | if (!status_area) |
| 42 | continue; |
| 43 | if (window_controller == primary_window_controller) { |
| 44 | status_area->SetSystemTrayVisibility( |
| 45 | visibility == SystemTrayVisibility::kPrimary || |
| 46 | visibility == SystemTrayVisibility::kAll); |
| 47 | } else { |
| 48 | status_area->SetSystemTrayVisibility(visibility == |
| 49 | SystemTrayVisibility::kAll); |
| 50 | } |
| 51 | } |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 52 | } |
| 53 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 54 | } // namespace |
| 55 | |
James Cook | ede316a | 2017-12-14 22:38:43 | [diff] [blame] | 56 | LoginScreenController::LoginScreenController() : weak_factory_(this) {} |
James Cook | 8f1e606 | 2017-11-13 23:40:59 | [diff] [blame] | 57 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 58 | LoginScreenController::~LoginScreenController() = default; |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 59 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 60 | // static |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 61 | void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry, |
| 62 | bool for_test) { |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 63 | if (for_test) { |
| 64 | // There is no remote pref service, so pretend that ash owns the pref. |
| 65 | registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, ""); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | // Pref is owned by chrome and flagged as PUBLIC. |
| 70 | registry->RegisterForeignPref(prefs::kQuickUnlockPinSalt); |
| 71 | } |
| 72 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 73 | void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) { |
James Cook | ede316a | 2017-12-14 22:38:43 | [diff] [blame] | 74 | bindings_.AddBinding(this, std::move(request)); |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 75 | } |
| 76 | |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 77 | bool LoginScreenController::IsAuthenticating() const { |
| 78 | return authentication_stage_ != AuthenticationStage::kIdle; |
| 79 | } |
| 80 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 81 | void LoginScreenController::AuthenticateUser(const AccountId& account_id, |
| 82 | const std::string& password, |
| 83 | bool authenticated_by_pin, |
| 84 | OnAuthenticateCallback callback) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 85 | // It is an error to call this function while an authentication is in |
| 86 | // progress. |
Jacob Dufault | 58a1bf4 | 2018-07-10 17:44:56 | [diff] [blame] | 87 | LOG_IF(ERROR, IsAuthenticating()) |
| 88 | << "Duplicate authentication attempt; current authentication stage is " |
| 89 | << static_cast<int>(authentication_stage_); |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 90 | CHECK(!IsAuthenticating()); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 91 | |
| 92 | if (!login_screen_client_) { |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 93 | std::move(callback).Run(base::nullopt); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 94 | return; |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 95 | } |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 96 | |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 97 | // If auth is disabled by the debug overlay bypass the mojo call entirely, as |
| 98 | // it will dismiss the lock screen if the password is correct. |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 99 | switch (force_fail_auth_for_debug_overlay_) { |
| 100 | case ForceFailAuth::kOff: |
| 101 | break; |
| 102 | case ForceFailAuth::kImmediate: |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 103 | OnAuthenticateComplete(std::move(callback), false /*success*/); |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 104 | return; |
| 105 | case ForceFailAuth::kDelayed: |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 106 | // Set a dummy authentication stage so that |IsAuthenticating| returns |
| 107 | // true. |
| 108 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 109 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 110 | FROM_HERE, |
| 111 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 112 | weak_factory_.GetWeakPtr(), base::Passed(&callback), |
| 113 | false), |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 114 | base::TimeDelta::FromSeconds(1)); |
| 115 | return; |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 116 | } |
| 117 | |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 118 | // |DoAuthenticateUser| requires the system salt. |
| 119 | authentication_stage_ = AuthenticationStage::kGetSystemSalt; |
| 120 | chromeos::SystemSaltGetter::Get()->GetSystemSalt( |
| 121 | base::AdaptCallbackForRepeating( |
| 122 | base::BindOnce(&LoginScreenController::DoAuthenticateUser, |
| 123 | weak_factory_.GetWeakPtr(), account_id, password, |
| 124 | authenticated_by_pin, std::move(callback)))); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 125 | } |
| 126 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 127 | void LoginScreenController::AttemptUnlock(const AccountId& account_id) { |
| 128 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 129 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 130 | login_screen_client_->AttemptUnlock(account_id); |
Sarah Hu | e0e01a5 | 2017-10-25 20:29:30 | [diff] [blame] | 131 | |
| 132 | Shell::Get()->metrics()->login_metrics_recorder()->SetAuthMethod( |
| 133 | LoginMetricsRecorder::AuthMethod::kSmartlock); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 134 | } |
| 135 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 136 | void LoginScreenController::HardlockPod(const AccountId& account_id) { |
| 137 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 138 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 139 | login_screen_client_->HardlockPod(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 140 | } |
| 141 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 142 | void LoginScreenController::RecordClickOnLockIcon(const AccountId& account_id) { |
| 143 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 144 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 145 | login_screen_client_->RecordClickOnLockIcon(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 146 | } |
| 147 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 148 | void LoginScreenController::OnFocusPod(const AccountId& account_id) { |
| 149 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 150 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 151 | login_screen_client_->OnFocusPod(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 152 | } |
| 153 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 154 | void LoginScreenController::OnNoPodFocused() { |
| 155 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 156 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 157 | login_screen_client_->OnNoPodFocused(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 158 | } |
| 159 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 160 | void LoginScreenController::LoadWallpaper(const AccountId& account_id) { |
| 161 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 162 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 163 | login_screen_client_->LoadWallpaper(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 164 | } |
| 165 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 166 | void LoginScreenController::SignOutUser() { |
| 167 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 168 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 169 | login_screen_client_->SignOutUser(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 170 | } |
| 171 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 172 | void LoginScreenController::CancelAddUser() { |
| 173 | if (!login_screen_client_) |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 174 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 175 | login_screen_client_->CancelAddUser(); |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 176 | } |
| 177 | |
Aga Wronska | 6a32f987 | 2018-01-06 00:16:10 | [diff] [blame] | 178 | void LoginScreenController::LoginAsGuest() { |
| 179 | if (!login_screen_client_) |
| 180 | return; |
| 181 | login_screen_client_->LoginAsGuest(); |
| 182 | } |
| 183 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 184 | void LoginScreenController::OnMaxIncorrectPasswordAttempted( |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 185 | const AccountId& account_id) { |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 186 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 187 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 188 | login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 189 | } |
| 190 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 191 | void LoginScreenController::FocusLockScreenApps(bool reverse) { |
| 192 | if (!login_screen_client_) |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 193 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 194 | login_screen_client_->FocusLockScreenApps(reverse); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 195 | } |
| 196 | |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 197 | void LoginScreenController::ShowGaiaSignin( |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 198 | bool can_close, |
| 199 | const base::Optional<AccountId>& prefilled_account) { |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 200 | if (!login_screen_client_) |
| 201 | return; |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 202 | login_screen_client_->ShowGaiaSignin(can_close, prefilled_account); |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 203 | } |
| 204 | |
Jacob Dufault | fc31c74 | 2018-03-20 17:32:19 | [diff] [blame] | 205 | void LoginScreenController::OnRemoveUserWarningShown() { |
| 206 | if (!login_screen_client_) |
| 207 | return; |
| 208 | login_screen_client_->OnRemoveUserWarningShown(); |
| 209 | } |
| 210 | |
| 211 | void LoginScreenController::RemoveUser(const AccountId& account_id) { |
| 212 | if (!login_screen_client_) |
| 213 | return; |
| 214 | login_screen_client_->RemoveUser(account_id); |
| 215 | } |
| 216 | |
Sarah Hu | 3fcf9f8 | 2018-03-22 20:32:54 | [diff] [blame] | 217 | void LoginScreenController::LaunchPublicSession( |
| 218 | const AccountId& account_id, |
| 219 | const std::string& locale, |
| 220 | const std::string& input_method) { |
| 221 | if (!login_screen_client_) |
| 222 | return; |
| 223 | login_screen_client_->LaunchPublicSession(account_id, locale, input_method); |
| 224 | } |
| 225 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 226 | void LoginScreenController::RequestPublicSessionKeyboardLayouts( |
| 227 | const AccountId& account_id, |
| 228 | const std::string& locale) { |
| 229 | if (!login_screen_client_) |
| 230 | return; |
| 231 | login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale); |
| 232 | } |
| 233 | |
Sarah Hu | 0007c93 | 2018-06-18 20:21:04 | [diff] [blame] | 234 | void LoginScreenController::ShowFeedback() { |
| 235 | if (!login_screen_client_) |
| 236 | return; |
| 237 | login_screen_client_->ShowFeedback(); |
| 238 | } |
| 239 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 240 | void LoginScreenController::AddObserver( |
| 241 | LoginScreenControllerObserver* observer) { |
| 242 | observers_.AddObserver(observer); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 243 | } |
| 244 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 245 | void LoginScreenController::RemoveObserver( |
| 246 | LoginScreenControllerObserver* observer) { |
| 247 | observers_.RemoveObserver(observer); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 248 | } |
| 249 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 250 | void LoginScreenController::FlushForTesting() { |
| 251 | login_screen_client_.FlushForTesting(); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 252 | } |
| 253 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 254 | void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) { |
| 255 | login_screen_client_ = std::move(client); |
| 256 | } |
| 257 | |
| 258 | void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) { |
| 259 | OnShow(); |
| 260 | ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock); |
| 261 | std::move(on_shown).Run(true); |
| 262 | } |
| 263 | |
| 264 | void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) { |
| 265 | // Login screen can only be used during login. |
| 266 | if (Shell::Get()->session_controller()->GetSessionState() != |
| 267 | session_manager::SessionState::LOGIN_PRIMARY) { |
| 268 | LOG(ERROR) << "Not showing login screen since session state is " |
| 269 | << static_cast<int>( |
| 270 | Shell::Get()->session_controller()->GetSessionState()); |
| 271 | std::move(on_shown).Run(false); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | OnShow(); |
| 276 | // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen. |
| 277 | ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin); |
| 278 | std::move(on_shown).Run(true); |
| 279 | } |
| 280 | |
| 281 | void LoginScreenController::ShowErrorMessage(int32_t login_attempts, |
| 282 | const std::string& error_text, |
| 283 | const std::string& help_link_text, |
| 284 | int32_t help_topic_id) { |
| 285 | NOTIMPLEMENTED(); |
| 286 | } |
| 287 | |
| 288 | void LoginScreenController::ClearErrors() { |
| 289 | NOTIMPLEMENTED(); |
| 290 | } |
| 291 | |
| 292 | void LoginScreenController::ShowUserPodCustomIcon( |
| 293 | const AccountId& account_id, |
| 294 | mojom::EasyUnlockIconOptionsPtr icon) { |
| 295 | DataDispatcher()->ShowEasyUnlockIcon(account_id, icon); |
| 296 | } |
| 297 | |
| 298 | void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) { |
| 299 | auto icon_options = mojom::EasyUnlockIconOptions::New(); |
| 300 | icon_options->icon = mojom::EasyUnlockIconId::NONE; |
| 301 | DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options); |
| 302 | } |
| 303 | |
| 304 | void LoginScreenController::SetAuthType( |
| 305 | const AccountId& account_id, |
| 306 | proximity_auth::mojom::AuthType auth_type, |
| 307 | const base::string16& initial_value) { |
| 308 | if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) { |
| 309 | DataDispatcher()->SetClickToUnlockEnabledForUser(account_id, |
| 310 | true /*enabled*/); |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 311 | } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) { |
| 312 | DataDispatcher()->SetForceOnlineSignInForUser(account_id); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 313 | } else { |
| 314 | NOTIMPLEMENTED(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void LoginScreenController::LoadUsers( |
| 319 | std::vector<mojom::LoginUserInfoPtr> users, |
| 320 | bool show_guest) { |
| 321 | DCHECK(DataDispatcher()); |
| 322 | |
| 323 | DataDispatcher()->NotifyUsers(users); |
Jacob Dufault | 5ac266ef | 2018-07-18 17:30:30 | [diff] [blame^] | 324 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 325 | ->shelf_widget() |
| 326 | ->login_shelf_view() |
| 327 | ->SetAllowLoginAsGuest(show_guest); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id, |
| 331 | bool is_enabled) { |
| 332 | // Chrome will update pin pod state every time user tries to authenticate. |
| 333 | // LockScreen is destroyed in the case of authentication success. |
| 334 | if (DataDispatcher()) |
| 335 | DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled); |
| 336 | } |
| 337 | |
Jacob Dufault | 77d75ce9 | 2018-04-13 18:20:09 | [diff] [blame] | 338 | void LoginScreenController::SetAvatarForUser(const AccountId& account_id, |
| 339 | mojom::UserAvatarPtr avatar) { |
| 340 | for (auto& observer : observers_) |
| 341 | observer.SetAvatarForUser(account_id, avatar); |
| 342 | } |
| 343 | |
Wenzhao Zang | e0c2ab2 | 2018-05-23 17:43:46 | [diff] [blame] | 344 | void LoginScreenController::SetAuthEnabledForUser( |
| 345 | const AccountId& account_id, |
| 346 | bool is_enabled, |
| 347 | base::Optional<base::Time> auth_reenabled_time) { |
| 348 | if (DataDispatcher()) { |
| 349 | DataDispatcher()->SetAuthEnabledForUser(account_id, is_enabled, |
| 350 | auth_reenabled_time); |
| 351 | } |
| 352 | } |
| 353 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 354 | void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) { |
| 355 | for (auto& observer : observers_) |
| 356 | observer.OnFocusLeavingLockScreenApps(reverse); |
| 357 | } |
| 358 | |
| 359 | void LoginScreenController::SetDevChannelInfo( |
| 360 | const std::string& os_version_label_text, |
| 361 | const std::string& enterprise_info_text, |
| 362 | const std::string& bluetooth_name) { |
| 363 | if (DataDispatcher()) { |
| 364 | DataDispatcher()->SetDevChannelInfo(os_version_label_text, |
| 365 | enterprise_info_text, bluetooth_name); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | void LoginScreenController::IsReadyForPassword( |
| 370 | IsReadyForPasswordCallback callback) { |
Jacob Dufault | 2ca8c50 | 2018-06-25 19:12:14 | [diff] [blame] | 371 | std::move(callback).Run(LockScreen::HasInstance() && !IsAuthenticating()); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void LoginScreenController::SetPublicSessionDisplayName( |
| 375 | const AccountId& account_id, |
| 376 | const std::string& display_name) { |
| 377 | if (DataDispatcher()) |
| 378 | DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name); |
| 379 | } |
| 380 | |
| 381 | void LoginScreenController::SetPublicSessionLocales( |
| 382 | const AccountId& account_id, |
Sarah Hu | e9cd613 | 2018-05-17 17:25:56 | [diff] [blame] | 383 | std::vector<mojom::LocaleItemPtr> locales, |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 384 | const std::string& default_locale, |
| 385 | bool show_advanced_view) { |
| 386 | if (DataDispatcher()) { |
| 387 | DataDispatcher()->SetPublicSessionLocales( |
Sarah Hu | e9cd613 | 2018-05-17 17:25:56 | [diff] [blame] | 388 | account_id, locales, default_locale, show_advanced_view); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 392 | void LoginScreenController::SetPublicSessionKeyboardLayouts( |
| 393 | const AccountId& account_id, |
| 394 | const std::string& locale, |
| 395 | std::vector<mojom::InputMethodItemPtr> keyboard_layouts) { |
| 396 | if (DataDispatcher()) { |
| 397 | DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale, |
| 398 | keyboard_layouts); |
| 399 | } |
| 400 | } |
| 401 | |
Sarah Hu | 1a7de56 | 2018-05-14 17:18:22 | [diff] [blame] | 402 | void LoginScreenController::SetFingerprintUnlockState( |
| 403 | const AccountId& account_id, |
| 404 | mojom::FingerprintUnlockState state) { |
| 405 | if (DataDispatcher()) |
| 406 | DataDispatcher()->SetFingerprintUnlockState(account_id, state); |
| 407 | } |
| 408 | |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 409 | void LoginScreenController::SetKioskApps( |
| 410 | std::vector<mojom::KioskAppInfoPtr> kiosk_apps) { |
| 411 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 412 | ->shelf_widget() |
Jacob Dufault | 5ac266ef | 2018-07-18 17:30:30 | [diff] [blame^] | 413 | ->login_shelf_view() |
| 414 | ->SetKioskApps(std::move(kiosk_apps)); |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 415 | } |
| 416 | |
Jacob Dufault | 883dcf7 | 2018-06-27 22:52:32 | [diff] [blame] | 417 | void LoginScreenController::NotifyOobeDialogVisibility(bool visible) { |
| 418 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 419 | ->shelf_widget() |
Jacob Dufault | 5ac266ef | 2018-07-18 17:30:30 | [diff] [blame^] | 420 | ->login_shelf_view() |
Jacob Dufault | 883dcf7 | 2018-06-27 22:52:32 | [diff] [blame] | 421 | ->SetLoginDialogVisible(visible); |
| 422 | } |
| 423 | |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame] | 424 | void LoginScreenController::LaunchKioskApp(const std::string& app_id) { |
| 425 | login_screen_client_->LaunchKioskApp(app_id); |
| 426 | } |
| 427 | |
Quan Nguyen | a3c54cf | 2018-07-03 17:56:50 | [diff] [blame] | 428 | void LoginScreenController::LaunchArcKioskApp(const AccountId& account_id) { |
| 429 | login_screen_client_->LaunchArcKioskApp(account_id); |
| 430 | } |
| 431 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 432 | void LoginScreenController::DoAuthenticateUser(const AccountId& account_id, |
| 433 | const std::string& password, |
| 434 | bool authenticated_by_pin, |
| 435 | OnAuthenticateCallback callback, |
| 436 | const std::string& system_salt) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 437 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
| 438 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 439 | int dummy_value; |
| 440 | bool is_pin = |
| 441 | authenticated_by_pin && base::StringToInt(password, &dummy_value); |
Roman Sorokin | c559001 | 2017-09-28 00:48:29 | [diff] [blame] | 442 | |
Sarah Hu | e0e01a5 | 2017-10-25 20:29:30 | [diff] [blame] | 443 | Shell::Get()->metrics()->login_metrics_recorder()->SetAuthMethod( |
| 444 | is_pin ? LoginMetricsRecorder::AuthMethod::kPin |
| 445 | : LoginMetricsRecorder::AuthMethod::kPassword); |
Jacob Dufault | 2be7100 | 2018-05-16 17:07:43 | [diff] [blame] | 446 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 447 | login_screen_client_->AuthenticateUser( |
Jacob Dufault | 2be7100 | 2018-05-16 17:07:43 | [diff] [blame] | 448 | account_id, password, is_pin, |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 449 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 450 | weak_factory_.GetWeakPtr(), base::Passed(&callback))); |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame] | 451 | } |
| 452 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 453 | void LoginScreenController::OnAuthenticateComplete( |
| 454 | OnAuthenticateCallback callback, |
| 455 | bool success) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 456 | authentication_stage_ = AuthenticationStage::kUserCallback; |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 457 | std::move(callback).Run(success); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 458 | authentication_stage_ = AuthenticationStage::kIdle; |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 459 | } |
| 460 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 461 | LoginDataDispatcher* LoginScreenController::DataDispatcher() const { |
Wenzhao Zang | 73349728 | 2018-06-12 16:53:10 | [diff] [blame] | 462 | if (!ash::LockScreen::HasInstance()) |
Jacob Dufault | 40623d5 | 2017-09-15 17:22:53 | [diff] [blame] | 463 | return nullptr; |
| 464 | return ash::LockScreen::Get()->data_dispatcher(); |
| 465 | } |
| 466 | |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 467 | void LoginScreenController::OnShow() { |
| 468 | SetSystemTrayVisibility(SystemTrayVisibility::kPrimary); |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 469 | if (authentication_stage_ != AuthenticationStage::kIdle) { |
| 470 | AuthenticationStage authentication_stage = authentication_stage_; |
| 471 | base::debug::Alias(&authentication_stage); |
| 472 | LOG(FATAL) << "Unexpected authentication stage " |
| 473 | << static_cast<int>(authentication_stage_); |
| 474 | } |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 475 | } |
| 476 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 477 | } // namespace ash |