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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc

Issue 484353005: ChromeOS: "Add New User" screen should enable all hardware keyboards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser test for login UI IM. Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/ui/webui/chromeos/login/signin_screen_handler.h" 5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 std::string GetNetworkName(const std::string& service_path) { 168 std::string GetNetworkName(const std::string& service_path) {
169 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 169 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
170 GetNetworkState(service_path); 170 GetNetworkState(service_path);
171 if (!network) 171 if (!network)
172 return std::string(); 172 return std::string();
173 return network->name(); 173 return network->name();
174 } 174 }
175 175
176 static bool SetUserInputMethodImpl( 176 static bool SetUserInputMethodImpl(
177 const std::string& username, 177 const std::string& username,
178 chromeos::input_method::InputMethodManager* manager) { 178 const std::string& user_input_method,
179 PrefService* const local_state = g_browser_process->local_state(); 179 input_method::InputMethodManager::State* ime_state) {
180 180 if (!chromeos::input_method::InputMethodManager::Get()->IsLoginKeyboard(
181 const base::DictionaryValue* users_lru_input_methods = 181 user_input_method)) {
182 local_state->GetDictionary(prefs::kUsersLRUInputMethod);
183
184 if (users_lru_input_methods == NULL) {
185 DLOG(WARNING) << "SetUserInputMethod('" << username
186 << "'): no kUsersLRUInputMethod";
187 return false;
188 }
189
190 std::string input_method;
191
192 if (!users_lru_input_methods->GetStringWithoutPathExpansion(username,
193 &input_method)) {
194 DVLOG(0) << "SetUserInputMethod('" << username
195 << "'): no input method for this user";
196 return false;
197 }
198
199 if (input_method.empty())
200 return false;
201
202 if (!manager->IsLoginKeyboard(input_method)) {
203 LOG(WARNING) << "SetUserInputMethod('" << username 182 LOG(WARNING) << "SetUserInputMethod('" << username
204 << "'): stored user LRU input method '" << input_method 183 << "'): stored user LRU input method '" << user_input_method
205 << "' is no longer Full Latin Keyboard Language" 184 << "' is no longer Full Latin Keyboard Language"
206 << " (entry dropped). Use hardware default instead."; 185 << " (entry dropped). Use hardware default instead.";
207 186
187 PrefService* const local_state = g_browser_process->local_state();
208 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); 188 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
209 189
210 base::DictionaryValue* const users_lru_input_methods = updater.Get(); 190 base::DictionaryValue* const users_lru_input_methods = updater.Get();
211 if (users_lru_input_methods != NULL) { 191 if (users_lru_input_methods != NULL) {
212 users_lru_input_methods->SetStringWithoutPathExpansion(username, ""); 192 users_lru_input_methods->SetStringWithoutPathExpansion(username, "");
213 } 193 }
214 return false; 194 return false;
215 } 195 }
216 196
217 if (!Contains(manager->GetActiveIMEState()->GetActiveInputMethodIds(), 197 if (!Contains(ime_state->GetActiveInputMethodIds(), user_input_method)) {
218 input_method)) { 198 if (!ime_state->EnableInputMethod(user_input_method)) {
219 if (!manager->GetActiveIMEState()->EnableInputMethod(input_method)) {
220 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username 199 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username
221 << "'): user input method '" << input_method 200 << "'): user input method '" << user_input_method
222 << "' is not enabled and enabling failed (ignored!)."; 201 << "' is not enabled and enabling failed (ignored!).";
223 } 202 }
224 } 203 }
225 manager->GetActiveIMEState()->ChangeInputMethod(input_method, 204 ime_state->ChangeInputMethod(user_input_method, false /* show_message */);
226 false /* show_message */);
227 205
228 return true; 206 return true;
229 } 207 }
230 208
231 } // namespace 209 } // namespace
232 210
233 // LoginScreenContext implementation ------------------------------------------ 211 // LoginScreenContext implementation ------------------------------------------
234 212
235 LoginScreenContext::LoginScreenContext() { 213 LoginScreenContext::LoginScreenContext() {
236 Init(); 214 Init();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 policy::ConsumerManagementService* consumer_management = 285 policy::ConsumerManagementService* consumer_management =
308 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> 286 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
309 GetConsumerManagementService(); 287 GetConsumerManagementService();
310 is_enrolling_consumer_management_ = 288 is_enrolling_consumer_management_ =
311 consumer_management && 289 consumer_management &&
312 consumer_management->GetEnrollmentStage() == 290 consumer_management->GetEnrollmentStage() ==
313 policy::ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED; 291 policy::ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED;
314 } 292 }
315 293
316 SigninScreenHandler::~SigninScreenHandler() { 294 SigninScreenHandler::~SigninScreenHandler() {
295 OobeUI* oobe_ui = GetOobeUI();
296 if (oobe_ui)
297 oobe_ui->RemoveObserver(this);
317 chromeos::input_method::ImeKeyboard* keyboard = 298 chromeos::input_method::ImeKeyboard* keyboard =
318 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); 299 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
319 if (keyboard) 300 if (keyboard)
320 keyboard->RemoveObserver(this); 301 keyboard->RemoveObserver(this);
321 weak_factory_.InvalidateWeakPtrs(); 302 weak_factory_.InvalidateWeakPtrs();
322 if (delegate_) 303 if (delegate_)
323 delegate_->SetWebUIHandler(NULL); 304 delegate_->SetWebUIHandler(NULL);
324 network_state_informer_->RemoveObserver(this); 305 network_state_informer_->RemoveObserver(this);
325 if (max_mode_delegate_) { 306 if (max_mode_delegate_) {
326 max_mode_delegate_->RemoveObserver(this); 307 max_mode_delegate_->RemoveObserver(this);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 459 }
479 460
480 // SigninScreenHandler, private: ----------------------------------------------- 461 // SigninScreenHandler, private: -----------------------------------------------
481 462
482 void SigninScreenHandler::ShowImpl() { 463 void SigninScreenHandler::ShowImpl() {
483 if (!page_is_ready()) { 464 if (!page_is_ready()) {
484 show_on_init_ = true; 465 show_on_init_ = true;
485 return; 466 return;
486 } 467 }
487 468
469 if (!ime_state_)
470 ime_state_ = input_method::InputMethodManager::Get()->GetActiveIMEState();
471
472 GetOobeUI()->AddObserver(this);
473
488 if (oobe_ui_ || is_enrolling_consumer_management_) { 474 if (oobe_ui_ || is_enrolling_consumer_management_) {
489 // Shows new user sign-in for OOBE. 475 // Shows new user sign-in for OOBE.
490 OnShowAddUser(); 476 OnShowAddUser();
491 } else { 477 } else {
492 // Populates account picker. Animation is turned off for now until we 478 // Populates account picker. Animation is turned off for now until we
493 // figure out how to make it fast enough. 479 // figure out how to make it fast enough.
494 delegate_->HandleGetUsers(); 480 delegate_->HandleGetUsers();
495 481
496 // Reset Caps Lock state when login screen is shown. 482 // Reset Caps Lock state when login screen is shown.
497 input_method::InputMethodManager::Get() 483 input_method::InputMethodManager::Get()
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 772
787 // This message is sent by the kiosk app menu, but is handled here 773 // This message is sent by the kiosk app menu, but is handled here
788 // so we can tell the delegate to launch the app. 774 // so we can tell the delegate to launch the app.
789 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); 775 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp);
790 } 776 }
791 777
792 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { 778 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
793 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); 779 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
794 } 780 }
795 781
782 void SigninScreenHandler::OnCurrentScreenChanged(OobeUI::Screen current_screen,
783 OobeUI::Screen new_screen) {
784 if (new_screen == OobeUI::SCREEN_ACCOUNT_PICKER) {
785 // Restore active IME state if returning to user pod row screen.
786 input_method::InputMethodManager::Get()->SetState(ime_state_);
787 }
788 }
789
790 std::string SigninScreenHandler::GetUserLRUInputMethod(
791 const std::string& username) const {
792 PrefService* const local_state = g_browser_process->local_state();
793 const base::DictionaryValue* users_lru_input_methods =
794 local_state->GetDictionary(prefs::kUsersLRUInputMethod);
795
796 if (users_lru_input_methods == NULL) {
797 DLOG(WARNING) << "GetUserLRUInputMethod('" << username
798 << "'): no kUsersLRUInputMethod";
799 return std::string();
800 }
801
802 std::string input_method;
803
804 if (!users_lru_input_methods->GetStringWithoutPathExpansion(username,
805 &input_method)) {
806 DVLOG(0) << "GetUserLRUInputMethod('" << username
807 << "'): no input method for this user";
808 return std::string();
809 }
810
811 return input_method;
812 }
813
796 void SigninScreenHandler::HandleGetUsers() { 814 void SigninScreenHandler::HandleGetUsers() {
797 if (delegate_) 815 if (delegate_)
798 delegate_->HandleGetUsers(); 816 delegate_->HandleGetUsers();
799 } 817 }
800 818
801 void SigninScreenHandler::ClearAndEnablePassword() { 819 void SigninScreenHandler::ClearAndEnablePassword() {
802 core_oobe_actor_->ResetSignInUI(false); 820 core_oobe_actor_->ResetSignInUI(false);
803 } 821 }
804 822
805 void SigninScreenHandler::ClearUserPodPassword() { 823 void SigninScreenHandler::ClearUserPodPassword() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 1010
993 bool SigninScreenHandler::ShouldLoadGaia() const { 1011 bool SigninScreenHandler::ShouldLoadGaia() const {
994 // Fetching of the extension is not started before account picker page is 1012 // Fetching of the extension is not started before account picker page is
995 // loaded because it can affect the loading speed. 1013 // loaded because it can affect the loading speed.
996 // Do not load the extension for the screen locker, see crosbug.com/25018. 1014 // Do not load the extension for the screen locker, see crosbug.com/25018.
997 return !ScreenLocker::default_screen_locker() && 1015 return !ScreenLocker::default_screen_locker() &&
998 is_account_picker_showing_first_time_; 1016 is_account_picker_showing_first_time_;
999 } 1017 }
1000 1018
1001 // Update keyboard layout to least recently used by the user. 1019 // Update keyboard layout to least recently used by the user.
1002 void SigninScreenHandler::SetUserInputMethod(const std::string& username) { 1020 void SigninScreenHandler::SetUserInputMethod(
1021 const std::string& username,
1022 input_method::InputMethodManager::State* ime_state) {
1003 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 1023 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
1004 if (user_manager->IsUserLoggedIn()) { 1024 if (user_manager->IsUserLoggedIn()) {
1005 // We are on sign-in screen inside user session (adding new user to 1025 // We are on sign-in screen inside user session (adding new user to
1006 // the session or on lock screen), don't switch input methods in this case. 1026 // the session or on lock screen), don't switch input methods in this case.
1007 // TODO(dpolukhin): adding user and sign-in should be consistent 1027 // TODO(dpolukhin): adding user and sign-in should be consistent
1008 // crbug.com/292774 1028 // crbug.com/292774
1009 return; 1029 return;
1010 } 1030 }
1011 1031
1012 chromeos::input_method::InputMethodManager* const manager = 1032 bool succeed = false;
1013 chromeos::input_method::InputMethodManager::Get();
1014 1033
1015 const bool succeed = SetUserInputMethodImpl(username, manager); 1034 const std::string input_method = GetUserLRUInputMethod(username);
1035
1036 if (!input_method.empty())
1037 succeed = SetUserInputMethodImpl(username, input_method, ime_state);
1016 1038
1017 // This is also a case when LRU layout is set only for a few local users, 1039 // This is also a case when LRU layout is set only for a few local users,
1018 // thus others need to be switched to default locale. 1040 // thus others need to be switched to default locale.
1019 // Otherwise they will end up using another user's locale to log in. 1041 // Otherwise they will end up using another user's locale to log in.
1020 if (!succeed) { 1042 if (!succeed) {
1021 DVLOG(0) << "SetUserInputMethod('" << username 1043 DVLOG(0) << "SetUserInputMethod('" << username
1022 << "'): failed to set user layout. Switching to default."; 1044 << "'): failed to set user layout. Switching to default.";
1023 1045
1024 manager->GetActiveIMEState()->SetInputMethodLoginDefault(); 1046 ime_state->SetInputMethodLoginDefault();
1025 } 1047 }
1026 } 1048 }
1027 1049
1028 1050
1029 void SigninScreenHandler::UserSettingsChanged() { 1051 void SigninScreenHandler::UserSettingsChanged() {
1030 DCHECK(gaia_screen_handler_); 1052 DCHECK(gaia_screen_handler_);
1031 GaiaContext context; 1053 GaiaContext context;
1032 if (delegate_) 1054 if (delegate_)
1033 context.has_users = !delegate_->GetUsers().empty(); 1055 context.has_users = !delegate_->GetUsers().empty();
1034 gaia_screen_handler_->UpdateGaia(context); 1056 gaia_screen_handler_->UpdateGaia(context);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 1339
1318 void SigninScreenHandler::HandleShowLoadingTimeoutError() { 1340 void SigninScreenHandler::HandleShowLoadingTimeoutError() {
1319 UpdateState(ErrorScreenActor::ERROR_REASON_LOADING_TIMEOUT); 1341 UpdateState(ErrorScreenActor::ERROR_REASON_LOADING_TIMEOUT);
1320 } 1342 }
1321 1343
1322 void SigninScreenHandler::HandleUpdateOfflineLogin(bool offline_login_active) { 1344 void SigninScreenHandler::HandleUpdateOfflineLogin(bool offline_login_active) {
1323 offline_login_active_ = offline_login_active; 1345 offline_login_active_ = offline_login_active;
1324 } 1346 }
1325 1347
1326 void SigninScreenHandler::HandleFocusPod(const std::string& user_id) { 1348 void SigninScreenHandler::HandleFocusPod(const std::string& user_id) {
1327 SetUserInputMethod(user_id); 1349 SetUserInputMethod(user_id, ime_state_.get());
1328 WallpaperManager::Get()->SetUserWallpaperDelayed(user_id); 1350 WallpaperManager::Get()->SetUserWallpaperDelayed(user_id);
1329 } 1351 }
1330 1352
1331 void SigninScreenHandler::HandleHardlockPod(const std::string& user_id) { 1353 void SigninScreenHandler::HandleHardlockPod(const std::string& user_id) {
1332 SetAuthType(user_id, 1354 SetAuthType(user_id,
1333 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 1355 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
1334 base::string16()); 1356 base::string16());
1335 HideUserPodCustomIcon(user_id); 1357 HideUserPodCustomIcon(user_id);
1336 } 1358 }
1337 1359
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 return true; 1441 return true;
1420 } 1442 }
1421 1443
1422 void SigninScreenHandler::CancelPasswordChangedFlowInternal() { 1444 void SigninScreenHandler::CancelPasswordChangedFlowInternal() {
1423 if (delegate_) { 1445 if (delegate_) {
1424 ShowImpl(); 1446 ShowImpl();
1425 delegate_->CancelPasswordChangedFlow(); 1447 delegate_->CancelPasswordChangedFlow();
1426 } 1448 }
1427 } 1449 }
1428 1450
1451 OobeUI* SigninScreenHandler::GetOobeUI() const {
1452 return static_cast<OobeUI*>(web_ui()->GetController());
1453 }
1454
1429 OobeUI::Screen SigninScreenHandler::GetCurrentScreen() const { 1455 OobeUI::Screen SigninScreenHandler::GetCurrentScreen() const {
1430 OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN; 1456 OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN;
1431 OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController()); 1457 OobeUI* oobe_ui = GetOobeUI();
1432 if (oobe_ui) 1458 if (oobe_ui)
1433 screen = oobe_ui->current_screen(); 1459 screen = oobe_ui->current_screen();
1434 return screen; 1460 return screen;
1435 } 1461 }
1436 1462
1437 bool SigninScreenHandler::IsGaiaVisible() const { 1463 bool SigninScreenHandler::IsGaiaVisible() const {
1438 return IsSigninScreen(GetCurrentScreen()) && 1464 return IsSigninScreen(GetCurrentScreen()) &&
1439 ui_state_ == UI_STATE_GAIA_SIGNIN; 1465 ui_state_ == UI_STATE_GAIA_SIGNIN;
1440 } 1466 }
1441 1467
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 return gaia_screen_handler_->frame_error(); 1538 return gaia_screen_handler_->frame_error();
1513 } 1539 }
1514 1540
1515 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { 1541 void SigninScreenHandler::OnCapsLockChanged(bool enabled) {
1516 caps_lock_enabled_ = enabled; 1542 caps_lock_enabled_ = enabled;
1517 if (page_is_ready()) 1543 if (page_is_ready())
1518 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); 1544 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_);
1519 } 1545 }
1520 1546
1521 } // namespace chromeos 1547 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698