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