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