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