Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Side by Side Diff: chrome/browser/chromeos/login/screen_locker.cc

Issue 9999018: chrome/browser/chromeos/input_method/ refactoring [part 6 of 6] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 81 }
86 82
87 default: 83 default:
88 NOTREACHED(); 84 NOTREACHED();
89 } 85 }
90 } 86 }
91 87
92 virtual void LockScreen() OVERRIDE { 88 virtual void LockScreen() OVERRIDE {
93 VLOG(1) << "In: ScreenLockObserver::LockScreen"; 89 VLOG(1) << "In: ScreenLockObserver::LockScreen";
94 if (session_started_) { 90 if (session_started_) {
95 SetupInputMethodsForScreenLocker();
96 chromeos::ScreenLocker::Show(); 91 chromeos::ScreenLocker::Show();
97 } else { 92 } else {
98 // If the user has not completed the sign in we will log them out. This 93 // If the user has not completed the sign in we will log them out. This
99 // avoids complications with displaying the lock screen over the login 94 // avoids complications with displaying the lock screen over the login
100 // screen while remaining secure in the case that they walk away during 95 // screen while remaining secure in the case that they walk away during
101 // the signin steps. See crbug.com/112225 and crbug.com/110933. 96 // the signin steps. See crbug.com/112225 and crbug.com/110933.
102 chromeos::DBusThreadManager::Get()-> 97 chromeos::DBusThreadManager::Get()->
103 GetSessionManagerClient()->StopSession(); 98 GetSessionManagerClient()->StopSession();
104 } 99 }
105 } 100 }
106 101
107 virtual void UnlockScreen() OVERRIDE { 102 virtual void UnlockScreen() OVERRIDE {
108 RestoreInputMethods();
109 chromeos::ScreenLocker::Hide(); 103 chromeos::ScreenLocker::Hide();
110 } 104 }
111 105
112 virtual void UnlockScreenFailed() OVERRIDE { 106 virtual void UnlockScreenFailed() OVERRIDE {
113 chromeos::ScreenLocker::UnlockScreenFailed(); 107 chromeos::ScreenLocker::UnlockScreenFailed();
114 } 108 }
115 109
116 private: 110 private:
117 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic)
118 // since they are not necessary to input a login password. Users are still
119 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak,
120 // French).
121 void SetupInputMethodsForScreenLocker() {
122 if (// The LockScreen function is also called when the OS is suspended, and
123 // in that case |saved_active_input_method_list_| might be non-empty.
124 saved_active_input_method_list_.empty()) {
125 chromeos::input_method::InputMethodManager* manager =
126 chromeos::input_method::InputMethodManager::GetInstance();
127
128 saved_previous_input_method_id_ = manager->GetPreviousInputMethod().id();
129 saved_current_input_method_id_ = manager->GetCurrentInputMethod().id();
130 scoped_ptr<chromeos::input_method::InputMethodDescriptors>
131 active_input_method_list(manager->GetActiveInputMethods());
132
133 const std::string hardware_keyboard_id =
134 manager->GetInputMethodUtil()->GetHardwareInputMethodId();
135 // We'll add the hardware keyboard if it's not included in
136 // |active_input_method_list| so that the user can always use the hardware
137 // keyboard on the screen locker.
138 bool should_add_hardware_keyboard = true;
139
140 chromeos::input_method::InputMethodConfigValue value;
141 value.type =
142 chromeos::input_method::InputMethodConfigValue::kValueTypeStringList;
143 for (size_t i = 0; i < active_input_method_list->size(); ++i) {
144 const std::string& input_method_id =
145 active_input_method_list->at(i).id();
146 saved_active_input_method_list_.push_back(input_method_id);
147 // Skip if it's not a keyboard layout.
148 if (!chromeos::input_method::InputMethodUtil::IsKeyboardLayout(
149 input_method_id))
150 continue;
151 value.string_list_value.push_back(input_method_id);
152 if (input_method_id == hardware_keyboard_id) {
153 should_add_hardware_keyboard = false;
154 }
155 }
156 if (should_add_hardware_keyboard) {
157 value.string_list_value.push_back(hardware_keyboard_id);
158 }
159 // We don't want to shut down the IME, even if the hardware layout is the
160 // only IME left.
161 manager->SetEnableAutoImeShutdown(false);
162 manager->SetEnableExtensionIMEs(false);
163 manager->SetInputMethodConfig(
164 chromeos::language_prefs::kGeneralSectionName,
165 chromeos::language_prefs::kPreloadEnginesConfigName,
166 value);
167 }
168 }
169
170 void RestoreInputMethods() {
171 if (!saved_active_input_method_list_.empty()) {
172 chromeos::input_method::InputMethodManager* manager =
173 chromeos::input_method::InputMethodManager::GetInstance();
174
175 chromeos::input_method::InputMethodConfigValue value;
176 value.type =
177 chromeos::input_method::InputMethodConfigValue::kValueTypeStringList;
178 value.string_list_value = saved_active_input_method_list_;
179 manager->SetEnableAutoImeShutdown(true);
180 manager->SetEnableExtensionIMEs(true);
181 manager->SetInputMethodConfig(
182 chromeos::language_prefs::kGeneralSectionName,
183 chromeos::language_prefs::kPreloadEnginesConfigName,
184 value);
185 // Send previous input method id first so Ctrl+space would work fine.
186 if (!saved_previous_input_method_id_.empty())
187 manager->ChangeInputMethod(saved_previous_input_method_id_);
188 if (!saved_current_input_method_id_.empty())
189 manager->ChangeInputMethod(saved_current_input_method_id_);
190
191 saved_previous_input_method_id_.clear();
192 saved_current_input_method_id_.clear();
193 saved_active_input_method_list_.clear();
194 }
195 }
196
197 bool session_started_; 111 bool session_started_;
198 content::NotificationRegistrar registrar_; 112 content::NotificationRegistrar registrar_;
199 std::string saved_previous_input_method_id_; 113 std::string saved_previous_input_method_id_;
200 std::string saved_current_input_method_id_; 114 std::string saved_current_input_method_id_;
201 std::vector<std::string> saved_active_input_method_list_; 115 std::vector<std::string> saved_active_input_method_list_;
202 116
203 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); 117 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver);
204 }; 118 };
205 119
206 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer = 120 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer =
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 bool state = true; 366 bool state = true;
453 content::NotificationService::current()->Notify( 367 content::NotificationService::current()->Notify(
454 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 368 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
455 content::Source<ScreenLocker>(this), 369 content::Source<ScreenLocker>(this),
456 content::Details<bool>(&state)); 370 content::Details<bool>(&state));
457 DBusThreadManager::Get()->GetPowerManagerClient()-> 371 DBusThreadManager::Get()->GetPowerManagerClient()->
458 NotifyScreenLockCompleted(); 372 NotifyScreenLockCompleted();
459 } 373 }
460 374
461 } // namespace chromeos 375 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils_browsertest.cc ('k') | chrome/browser/chromeos/preferences.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698