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