| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/timer.h" | 17 #include "base/timer.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | |
| 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" | |
| 21 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | |
| 22 #include "chrome/browser/chromeos/language_preferences.h" | |
| 23 #include "chrome/browser/chromeos/login/authenticator.h" | 19 #include "chrome/browser/chromeos/login/authenticator.h" |
| 24 #include "chrome/browser/chromeos/login/login_performer.h" | 20 #include "chrome/browser/chromeos/login/login_performer.h" |
| 25 #include "chrome/browser/chromeos/login/login_utils.h" | 21 #include "chrome/browser/chromeos/login/login_utils.h" |
| 26 #include "chrome/browser/chromeos/login/user_manager.h" | 22 #include "chrome/browser/chromeos/login/user_manager.h" |
| 27 #include "chrome/browser/chromeos/login/webui_screen_locker.h" | 23 #include "chrome/browser/chromeos/login/webui_screen_locker.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 30 #include "chrome/browser/signin/signin_manager.h" | 26 #include "chrome/browser/signin/signin_manager.h" |
| 31 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 32 #include "chrome/browser/sync/profile_sync_service.h" | 28 #include "chrome/browser/sync/profile_sync_service.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 83 } |
| 88 | 84 |
| 89 default: | 85 default: |
| 90 NOTREACHED(); | 86 NOTREACHED(); |
| 91 } | 87 } |
| 92 } | 88 } |
| 93 | 89 |
| 94 virtual void LockScreen() OVERRIDE { | 90 virtual void LockScreen() OVERRIDE { |
| 95 VLOG(1) << "In: ScreenLockObserver::LockScreen"; | 91 VLOG(1) << "In: ScreenLockObserver::LockScreen"; |
| 96 if (session_started_) { | 92 if (session_started_) { |
| 97 SetupInputMethodsForScreenLocker(); | |
| 98 chromeos::ScreenLocker::Show(); | 93 chromeos::ScreenLocker::Show(); |
| 99 } else { | 94 } else { |
| 100 // If the user has not completed the sign in we will log them out. This | 95 // If the user has not completed the sign in we will log them out. This |
| 101 // avoids complications with displaying the lock screen over the login | 96 // avoids complications with displaying the lock screen over the login |
| 102 // screen while remaining secure in the case that they walk away during | 97 // screen while remaining secure in the case that they walk away during |
| 103 // the signin steps. See crbug.com/112225 and crbug.com/110933. | 98 // the signin steps. See crbug.com/112225 and crbug.com/110933. |
| 104 chromeos::DBusThreadManager::Get()-> | 99 chromeos::DBusThreadManager::Get()-> |
| 105 GetSessionManagerClient()->StopSession(); | 100 GetSessionManagerClient()->StopSession(); |
| 106 } | 101 } |
| 107 } | 102 } |
| 108 | 103 |
| 109 virtual void UnlockScreen() OVERRIDE { | 104 virtual void UnlockScreen() OVERRIDE { |
| 110 RestoreInputMethods(); | |
| 111 chromeos::ScreenLocker::Hide(); | 105 chromeos::ScreenLocker::Hide(); |
| 112 } | 106 } |
| 113 | 107 |
| 114 virtual void UnlockScreenFailed() OVERRIDE { | 108 virtual void UnlockScreenFailed() OVERRIDE { |
| 115 chromeos::ScreenLocker::UnlockScreenFailed(); | 109 chromeos::ScreenLocker::UnlockScreenFailed(); |
| 116 } | 110 } |
| 117 | 111 |
| 118 private: | 112 private: |
| 119 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) | |
| 120 // since they are not necessary to input a login password. Users are still | |
| 121 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, | |
| 122 // French). | |
| 123 void SetupInputMethodsForScreenLocker() { | |
| 124 if (// The LockScreen function is also called when the OS is suspended, and | |
| 125 // in that case |saved_active_input_method_list_| might be non-empty. | |
| 126 saved_active_input_method_list_.empty()) { | |
| 127 chromeos::input_method::InputMethodManager* manager = | |
| 128 chromeos::input_method::InputMethodManager::GetInstance(); | |
| 129 | |
| 130 saved_previous_input_method_id_ = manager->GetPreviousInputMethod().id(); | |
| 131 saved_current_input_method_id_ = manager->GetCurrentInputMethod().id(); | |
| 132 scoped_ptr<chromeos::input_method::InputMethodDescriptors> | |
| 133 active_input_method_list(manager->GetActiveInputMethods()); | |
| 134 | |
| 135 const std::string hardware_keyboard_id = | |
| 136 manager->GetInputMethodUtil()->GetHardwareInputMethodId(); | |
| 137 // We'll add the hardware keyboard if it's not included in | |
| 138 // |active_input_method_list| so that the user can always use the hardware | |
| 139 // keyboard on the screen locker. | |
| 140 bool should_add_hardware_keyboard = true; | |
| 141 | |
| 142 chromeos::input_method::InputMethodConfigValue value; | |
| 143 value.type = | |
| 144 chromeos::input_method::InputMethodConfigValue::kValueTypeStringList; | |
| 145 for (size_t i = 0; i < active_input_method_list->size(); ++i) { | |
| 146 const std::string& input_method_id = | |
| 147 active_input_method_list->at(i).id(); | |
| 148 saved_active_input_method_list_.push_back(input_method_id); | |
| 149 // Skip if it's not a keyboard layout. | |
| 150 if (!chromeos::input_method::InputMethodUtil::IsKeyboardLayout( | |
| 151 input_method_id)) | |
| 152 continue; | |
| 153 value.string_list_value.push_back(input_method_id); | |
| 154 if (input_method_id == hardware_keyboard_id) { | |
| 155 should_add_hardware_keyboard = false; | |
| 156 } | |
| 157 } | |
| 158 if (should_add_hardware_keyboard) { | |
| 159 value.string_list_value.push_back(hardware_keyboard_id); | |
| 160 } | |
| 161 // We don't want to shut down the IME, even if the hardware layout is the | |
| 162 // only IME left. | |
| 163 manager->SetEnableAutoImeShutdown(false); | |
| 164 manager->SetEnableExtensionIMEs(false); | |
| 165 manager->SetInputMethodConfig( | |
| 166 chromeos::language_prefs::kGeneralSectionName, | |
| 167 chromeos::language_prefs::kPreloadEnginesConfigName, | |
| 168 value); | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 void RestoreInputMethods() { | |
| 173 if (!saved_active_input_method_list_.empty()) { | |
| 174 chromeos::input_method::InputMethodManager* manager = | |
| 175 chromeos::input_method::InputMethodManager::GetInstance(); | |
| 176 | |
| 177 chromeos::input_method::InputMethodConfigValue value; | |
| 178 value.type = | |
| 179 chromeos::input_method::InputMethodConfigValue::kValueTypeStringList; | |
| 180 value.string_list_value = saved_active_input_method_list_; | |
| 181 manager->SetEnableAutoImeShutdown(true); | |
| 182 manager->SetEnableExtensionIMEs(true); | |
| 183 manager->SetInputMethodConfig( | |
| 184 chromeos::language_prefs::kGeneralSectionName, | |
| 185 chromeos::language_prefs::kPreloadEnginesConfigName, | |
| 186 value); | |
| 187 // Send previous input method id first so Ctrl+space would work fine. | |
| 188 if (!saved_previous_input_method_id_.empty()) | |
| 189 manager->ChangeInputMethod(saved_previous_input_method_id_); | |
| 190 if (!saved_current_input_method_id_.empty()) | |
| 191 manager->ChangeInputMethod(saved_current_input_method_id_); | |
| 192 | |
| 193 saved_previous_input_method_id_.clear(); | |
| 194 saved_current_input_method_id_.clear(); | |
| 195 saved_active_input_method_list_.clear(); | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 bool session_started_; | 113 bool session_started_; |
| 200 content::NotificationRegistrar registrar_; | 114 content::NotificationRegistrar registrar_; |
| 201 std::string saved_previous_input_method_id_; | 115 std::string saved_previous_input_method_id_; |
| 202 std::string saved_current_input_method_id_; | 116 std::string saved_current_input_method_id_; |
| 203 std::vector<std::string> saved_active_input_method_list_; | 117 std::vector<std::string> saved_active_input_method_list_; |
| 204 | 118 |
| 205 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); | 119 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); |
| 206 }; | 120 }; |
| 207 | 121 |
| 208 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer = | 122 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer = |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 bool state = true; | 368 bool state = true; |
| 455 content::NotificationService::current()->Notify( | 369 content::NotificationService::current()->Notify( |
| 456 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 370 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 457 content::Source<ScreenLocker>(this), | 371 content::Source<ScreenLocker>(this), |
| 458 content::Details<bool>(&state)); | 372 content::Details<bool>(&state)); |
| 459 DBusThreadManager::Get()->GetPowerManagerClient()-> | 373 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 460 NotifyScreenLockCompleted(); | 374 NotifyScreenLockCompleted(); |
| 461 } | 375 } |
| 462 | 376 |
| 463 } // namespace chromeos | 377 } // namespace chromeos |
| OLD | NEW |