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