Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/lock/views_screen_locker.h" | 5 #include "chrome/browser/chromeos/login/lock/views_screen_locker.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/i18n/time_formatting.h" | |
| 7 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/chromeos/login/lock_screen_utils.h" | |
| 13 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" | |
| 14 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" | |
| 8 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h" | 15 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h" |
| 9 #include "chrome/browser/chromeos/login/user_selection_screen_proxy.h" | 16 #include "chrome/browser/chromeos/login/user_selection_screen_proxy.h" |
| 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | |
| 18 #include "chrome/browser/chromeos/system/system_clock.h" | |
| 19 #include "chrome/browser/ui/ash/session_controller_client.h" | |
| 20 #include "chrome/common/pref_names.h" | |
| 21 #include "components/proximity_auth/screenlock_bridge.h" | |
| 22 #include "components/user_manager/known_user.h" | |
| 23 #include "components/user_manager/user_manager.h" | |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | |
| 25 #include "ui/base/ime/chromeos/ime_keyboard.h" | |
| 10 | 26 |
| 11 namespace chromeos { | 27 namespace chromeos { |
| 12 | 28 |
| 13 namespace { | 29 namespace { |
| 14 constexpr char kLockDisplay[] = "lock"; | 30 constexpr char kLockDisplay[] = "lock"; |
| 15 } // namespace | 31 } // namespace |
| 16 | 32 |
| 17 ViewsScreenLocker::ViewsScreenLocker(ScreenLocker* screen_locker) | 33 ViewsScreenLocker::ViewsScreenLocker(ScreenLocker* screen_locker) |
| 18 : screen_locker_(screen_locker), weak_factory_(this) { | 34 : screen_locker_(screen_locker), weak_factory_(this) { |
| 19 LockScreenClient::Get()->SetDelegate(this); | 35 LockScreenClient::Get()->SetDelegate(this); |
| 20 user_selection_screen_proxy_ = base::MakeUnique<UserSelectionScreenProxy>(); | 36 user_selection_screen_proxy_ = base::MakeUnique<UserSelectionScreenProxy>(); |
| 21 user_selection_screen_ = | 37 user_selection_screen_ = |
| 22 base::MakeUnique<ChromeUserSelectionScreen>(kLockDisplay); | 38 base::MakeUnique<ChromeUserSelectionScreen>(kLockDisplay); |
| 23 user_selection_screen_->SetView(user_selection_screen_proxy_.get()); | 39 user_selection_screen_->SetView(user_selection_screen_proxy_.get()); |
| 40 | |
| 41 allowed_input_methods_subscription_ = | |
| 42 CrosSettings::Get()->AddSettingsObserver( | |
| 43 kDeviceLoginScreenInputMethods, | |
| 44 base::Bind(&ViewsScreenLocker::OnAllowedInputMethodsChanged, | |
| 45 base::Unretained(this))); | |
| 24 } | 46 } |
| 25 | 47 |
| 26 ViewsScreenLocker::~ViewsScreenLocker() { | 48 ViewsScreenLocker::~ViewsScreenLocker() { |
| 27 LockScreenClient::Get()->SetDelegate(nullptr); | 49 LockScreenClient::Get()->SetDelegate(nullptr); |
| 28 } | 50 } |
| 29 | 51 |
| 52 void ViewsScreenLocker::Init() { | |
| 53 lock_time_ = base::TimeTicks::Now(); | |
| 54 user_selection_screen_->Init(screen_locker_->users()); | |
| 55 LockScreenClient::Get()->LoadUsers(user_selection_screen_->PrepareUserList(), | |
| 56 false /* show_guests */); | |
| 57 if (!ime_state_.get()) | |
| 58 ime_state_ = input_method::InputMethodManager::Get()->GetActiveIMEState(); | |
| 59 | |
| 60 // Reset Caps Lock state when lock screen is shown. | |
| 61 input_method::InputMethodManager::Get()->GetImeKeyboard()->SetCapsLockEnabled( | |
| 62 false); | |
| 63 | |
| 64 // Enable pin for any users who can use it. | |
| 65 if (user_manager::UserManager::IsInitialized()) { | |
| 66 for (user_manager::User* user : | |
| 67 user_manager::UserManager::Get()->GetLoggedInUsers()) { | |
| 68 UpdatePinKeyboardState(user->GetAccountId()); | |
| 69 } | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 void ViewsScreenLocker::OnLockScreenReady() { | |
| 74 lock_screen_ready_ = true; | |
| 75 user_selection_screen_->InitEasyUnlock(); | |
| 76 UMA_HISTOGRAM_TIMES("LockScreen.LockReady", | |
| 77 base::TimeTicks::Now() - lock_time_); | |
| 78 screen_locker_->ScreenLockReady(); | |
| 79 OnAllowedInputMethodsChanged(); | |
| 80 } | |
| 81 | |
| 30 void ViewsScreenLocker::SetPasswordInputEnabled(bool enabled) { | 82 void ViewsScreenLocker::SetPasswordInputEnabled(bool enabled) { |
| 31 NOTIMPLEMENTED(); | 83 NOTIMPLEMENTED(); |
| 32 } | 84 } |
| 33 | 85 |
| 34 void ViewsScreenLocker::ShowErrorMessage( | 86 void ViewsScreenLocker::ShowErrorMessage( |
| 35 int error_msg_id, | 87 int error_msg_id, |
| 36 HelpAppLauncher::HelpTopic help_topic_id) { | 88 HelpAppLauncher::HelpTopic help_topic_id) { |
| 37 // TODO(xiaoyinh): Complete the implementation here. | 89 // TODO(xiaoyinh): Complete the implementation here. |
| 38 LockScreenClient::Get()->ShowErrorMessage(0 /* login_attempts */, | 90 LockScreenClient::Get()->ShowErrorMessage(0 /* login_attempts */, |
| 39 std::string(), std::string(), | 91 std::string(), std::string(), |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 67 void ViewsScreenLocker::SetFingerprintState( | 119 void ViewsScreenLocker::SetFingerprintState( |
| 68 const AccountId& account_id, | 120 const AccountId& account_id, |
| 69 ScreenLocker::FingerprintState state) { | 121 ScreenLocker::FingerprintState state) { |
| 70 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
| 71 } | 123 } |
| 72 | 124 |
| 73 content::WebContents* ViewsScreenLocker::GetWebContents() { | 125 content::WebContents* ViewsScreenLocker::GetWebContents() { |
| 74 return nullptr; | 126 return nullptr; |
| 75 } | 127 } |
| 76 | 128 |
| 77 void ViewsScreenLocker::Init() { | 129 void ViewsScreenLocker::HandleAuthenticateUser( |
| 78 lock_time_ = base::TimeTicks::Now(); | 130 const AccountId& account_id, |
| 79 user_selection_screen_->Init(screen_locker_->users()); | 131 const std::string& hashed_password, |
| 80 LockScreenClient::Get()->LoadUsers(user_selection_screen_->PrepareUserList(), | 132 bool authenticated_by_pin, |
| 81 false /* show_guests */); | 133 AuthenticateUserCallback callback) { |
| 82 } | 134 DCHECK_EQ(account_id.GetUserEmail(), |
| 135 gaia::SanitizeEmail(account_id.GetUserEmail())); | |
| 136 quick_unlock::QuickUnlockStorage* quick_unlock_storage = | |
| 137 quick_unlock::QuickUnlockFactory::GetForAccountId(account_id); | |
| 138 // If pin storage is unavailable, |authenticated_by_pin| must be false. | |
| 139 DCHECK(!quick_unlock_storage || | |
| 140 quick_unlock_storage->IsPinAuthenticationAvailable() || | |
| 141 !authenticated_by_pin); | |
| 83 | 142 |
| 84 void ViewsScreenLocker::OnLockScreenReady() { | 143 UserContext user_context(account_id); |
| 85 user_selection_screen_->InitEasyUnlock(); | 144 Key key(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, std::string(), hashed_password); |
| 86 UMA_HISTOGRAM_TIMES("LockScreen.LockReady", | 145 user_context.SetKey(key); |
|
jdufault
2017/06/12 18:05:49
nit: construct the key inline without a temporary
xiaoyinh(OOO Sep 11-29)
2017/06/12 21:53:53
Done.
| |
| 87 base::TimeTicks::Now() - lock_time_); | 146 user_context.SetIsUsingPin(authenticated_by_pin); |
| 88 screen_locker_->ScreenLockReady(); | 147 if (account_id.GetAccountType() == AccountType::ACTIVE_DIRECTORY) |
| 148 user_context.SetUserType(user_manager::USER_TYPE_ACTIVE_DIRECTORY); | |
| 149 ScreenLocker::default_screen_locker()->Authenticate(user_context, | |
| 150 std::move(callback)); | |
| 151 UpdatePinKeyboardState(account_id); | |
| 89 } | 152 } |
| 90 | 153 |
| 91 void ViewsScreenLocker::HandleAttemptUnlock(const AccountId& account_id) { | 154 void ViewsScreenLocker::HandleAttemptUnlock(const AccountId& account_id) { |
| 92 user_selection_screen_->AttemptEasyUnlock(account_id); | 155 user_selection_screen_->AttemptEasyUnlock(account_id); |
| 93 } | 156 } |
| 94 | 157 |
| 95 void ViewsScreenLocker::HandleHardlockPod(const AccountId& account_id) { | 158 void ViewsScreenLocker::HandleHardlockPod(const AccountId& account_id) { |
| 96 user_selection_screen_->HardLockPod(account_id); | 159 user_selection_screen_->HardLockPod(account_id); |
| 97 } | 160 } |
| 98 | 161 |
| 99 void ViewsScreenLocker::HandleRecordClickOnLockIcon( | 162 void ViewsScreenLocker::HandleRecordClickOnLockIcon( |
| 100 const AccountId& account_id) { | 163 const AccountId& account_id) { |
| 101 user_selection_screen_->RecordClickOnLockIcon(account_id); | 164 user_selection_screen_->RecordClickOnLockIcon(account_id); |
| 102 } | 165 } |
| 103 | 166 |
| 167 void ViewsScreenLocker::HandleFocusPod(const AccountId& account_id) { | |
| 168 proximity_auth::ScreenlockBridge::Get()->SetFocusedUser(account_id); | |
| 169 if (user_selection_screen_) | |
| 170 user_selection_screen_->CheckUserStatus(account_id); | |
| 171 | |
| 172 focused_pod_account_id_ = base::Optional<AccountId>(account_id); | |
| 173 | |
| 174 const user_manager::User* user = | |
| 175 user_manager::UserManager::Get()->FindUser(account_id); | |
| 176 // |user| may be null in kiosk mode or unit tests. | |
| 177 if (user && user->is_logged_in() && !user->is_active()) { | |
| 178 SessionControllerClient::DoSwitchActiveUser(account_id); | |
| 179 } else { | |
| 180 lock_screen_utils::SetUserInputMethod(account_id.GetUserEmail(), | |
| 181 ime_state_.get()); | |
| 182 lock_screen_utils::SetKeyboardSettings(account_id); | |
| 183 WallpaperManager::Get()->SetUserWallpaperDelayed(account_id); | |
| 184 | |
| 185 bool use_24hour_clock = false; | |
| 186 if (user_manager::known_user::GetBooleanPref( | |
| 187 account_id, prefs::kUse24HourClock, &use_24hour_clock)) { | |
| 188 g_browser_process->platform_part() | |
| 189 ->GetSystemClock() | |
| 190 ->SetLastFocusedPodHourClockType( | |
| 191 use_24hour_clock ? base::k24HourClock : base::k12HourClock); | |
| 192 } | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 void ViewsScreenLocker::HandleNoPodFocused() { | |
| 197 lock_screen_utils::EnforcePolicyInputMethods(std::string()); | |
|
xiyuan
2017/06/12 18:17:13
reset |focused_pod_account_id_| ?
xiaoyinh(OOO Sep 11-29)
2017/06/12 21:53:53
Missed this... Thanks!
| |
| 198 } | |
| 199 | |
| 200 void ViewsScreenLocker::SuspendDone(const base::TimeDelta& sleep_duration) { | |
| 201 for (user_manager::User* user : | |
| 202 user_manager::UserManager::Get()->GetUnlockUsers()) { | |
| 203 UpdatePinKeyboardState(user->GetAccountId()); | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 void ViewsScreenLocker::UpdatePinKeyboardState(const AccountId& account_id) { | |
| 208 quick_unlock::QuickUnlockStorage* quick_unlock_storage = | |
| 209 quick_unlock::QuickUnlockFactory::GetForAccountId(account_id); | |
| 210 if (!quick_unlock_storage) | |
| 211 return; | |
| 212 | |
| 213 bool is_enabled = quick_unlock_storage->IsPinAuthenticationAvailable(); | |
| 214 LockScreenClient::Get()->SetPinEnabledForUser(account_id, is_enabled); | |
| 215 } | |
| 216 | |
| 217 void ViewsScreenLocker::OnAllowedInputMethodsChanged() { | |
| 218 if (!lock_screen_ready_) | |
| 219 return; | |
| 220 | |
| 221 if (focused_pod_account_id_) { | |
| 222 std::string user_input_method = lock_screen_utils::GetUserLastInputMethod( | |
| 223 focused_pod_account_id_->GetUserEmail()); | |
| 224 lock_screen_utils::EnforcePolicyInputMethods(user_input_method); | |
| 225 } else { | |
| 226 lock_screen_utils::EnforcePolicyInputMethods(std::string()); | |
| 227 } | |
| 228 } | |
| 229 | |
| 104 } // namespace chromeos | 230 } // namespace chromeos |
| OLD | NEW |