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

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

Issue 18856014: We should switch the keyboard layout to the layout the user set according to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix clang build. Created 7 years, 5 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 "base/callback.h" 7 #include "base/callback.h"
8 #include "base/chromeos/chromeos_version.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
14 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_process_platform_part_chromeos.h" 21 #include "chrome/browser/browser_process_platform_part_chromeos.h"
20 #include "chrome/browser/browser_shutdown.h" 22 #include "chrome/browser/browser_shutdown.h"
21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
24 #include "chrome/browser/chromeos/input_method/input_method_util.h"
22 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" 25 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
23 #include "chrome/browser/chromeos/login/hwid_checker.h" 26 #include "chrome/browser/chromeos/login/hwid_checker.h"
24 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 27 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
25 #include "chrome/browser/chromeos/login/screen_locker.h" 28 #include "chrome/browser/chromeos/login/screen_locker.h"
26 #include "chrome/browser/chromeos/login/user.h" 29 #include "chrome/browser/chromeos/login/user.h"
27 #include "chrome/browser/chromeos/login/webui_login_display.h" 30 #include "chrome/browser/chromeos/login/webui_login_display.h"
28 #include "chrome/browser/chromeos/login/wizard_controller.h" 31 #include "chrome/browser/chromeos/login/wizard_controller.h"
29 #include "chrome/browser/chromeos/net/network_portal_detector.h" 32 #include "chrome/browser/chromeos/net/network_portal_detector.h"
30 #include "chrome/browser/chromeos/profiles/profile_helper.h" 33 #include "chrome/browser/chromeos/profiles/profile_helper.h"
31 #include "chrome/browser/chromeos/settings/cros_settings.h" 34 #include "chrome/browser/chromeos/settings/cros_settings.h"
32 #include "chrome/browser/io_thread.h" 35 #include "chrome/browser/io_thread.h"
33 #include "chrome/browser/policy/browser_policy_connector.h" 36 #include "chrome/browser/policy/browser_policy_connector.h"
37 #include "chrome/browser/prefs/scoped_user_pref_update.h"
34 #include "chrome/browser/profiles/profile.h" 38 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h" 39 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h"
36 #include "chrome/browser/ui/webui/chromeos/login/native_window_delegate.h" 40 #include "chrome/browser/ui/webui/chromeos/login/native_window_delegate.h"
37 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" 41 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
38 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 42 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
39 #include "chrome/common/chrome_notification_types.h" 43 #include "chrome/common/chrome_notification_types.h"
40 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
41 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
42 #include "chrome/common/url_constants.h" 46 #include "chrome/common/url_constants.h"
43 #include "chromeos/chromeos_switches.h" 47 #include "chromeos/chromeos_switches.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // The Task posted to PostTaskAndReply in StartClearingDnsCache on the IO 100 // The Task posted to PostTaskAndReply in StartClearingDnsCache on the IO
97 // thread. 101 // thread.
98 void ClearDnsCache(IOThread* io_thread) { 102 void ClearDnsCache(IOThread* io_thread) {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
100 if (browser_shutdown::IsTryingToQuit()) 104 if (browser_shutdown::IsTryingToQuit())
101 return; 105 return;
102 106
103 io_thread->ClearHostCache(); 107 io_thread->ClearHostCache();
104 } 108 }
105 109
110 static bool Contains(const std::vector<std::string>& container,
Nikita (slow) 2013/07/15 12:56:38 nit: no need to mark function static. Usually such
Alexander Alekseev 2013/07/22 14:24:21 Both gcc/clang do not warn on unused non-static fu
111 const std::string& value) {
112 return std::find(container.begin(), container.end(), value) !=
113 container.end();
114 }
115
106 } // namespace 116 } // namespace
107 117
108 namespace chromeos { 118 namespace chromeos {
109 119
110 namespace { 120 namespace {
111 121
112 const char kNetworkStateOffline[] = "offline"; 122 const char kNetworkStateOffline[] = "offline";
113 const char kNetworkStateOnline[] = "online"; 123 const char kNetworkStateOnline[] = "online";
114 const char kNetworkStateCaptivePortal[] = "behind captive portal"; 124 const char kNetworkStateCaptivePortal[] = "behind captive portal";
115 const char kNetworkStateConnecting[] = "connecting"; 125 const char kNetworkStateConnecting[] = "connecting";
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 AddCallback("unlockOnLoginSuccess", 815 AddCallback("unlockOnLoginSuccess",
806 &SigninScreenHandler::HandleUnlockOnLoginSuccess); 816 &SigninScreenHandler::HandleUnlockOnLoginSuccess);
807 AddCallback("frameLoadingCompleted", 817 AddCallback("frameLoadingCompleted",
808 &SigninScreenHandler::HandleFrameLoadingCompleted); 818 &SigninScreenHandler::HandleFrameLoadingCompleted);
809 AddCallback("showLoadingTimeoutError", 819 AddCallback("showLoadingTimeoutError",
810 &SigninScreenHandler::HandleShowLoadingTimeoutError); 820 &SigninScreenHandler::HandleShowLoadingTimeoutError);
811 AddCallback("updateOfflineLogin", 821 AddCallback("updateOfflineLogin",
812 &SigninScreenHandler::HandleUpdateOfflineLogin); 822 &SigninScreenHandler::HandleUpdateOfflineLogin);
813 } 823 }
814 824
825 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
826 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
827 }
828
815 void SigninScreenHandler::HandleGetUsers() { 829 void SigninScreenHandler::HandleGetUsers() {
816 SendUserList(false); 830 SendUserList(false);
817 } 831 }
818 832
819 void SigninScreenHandler::ClearAndEnablePassword() { 833 void SigninScreenHandler::ClearAndEnablePassword() {
820 CallJS("cr.ui.Oobe.resetSigninUI", false); 834 CallJS("cr.ui.Oobe.resetSigninUI", false);
821 } 835 }
822 836
823 void SigninScreenHandler::ClearUserPodPassword() { 837 void SigninScreenHandler::ClearUserPodPassword() {
824 CallJS("cr.ui.Oobe.clearUserPodPassword"); 838 CallJS("cr.ui.Oobe.clearUserPodPassword");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } 975 }
962 } 976 }
963 977
964 void SigninScreenHandler::OnDnsCleared() { 978 void SigninScreenHandler::OnDnsCleared() {
965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
966 dns_clear_task_running_ = false; 980 dns_clear_task_running_ = false;
967 dns_cleared_ = true; 981 dns_cleared_ = true;
968 ShowSigninScreenIfReady(); 982 ShowSigninScreenIfReady();
969 } 983 }
970 984
985 void SigninScreenHandler::SetUserInputMethodHWDefault() {
986 chromeos::input_method::InputMethodManager* manager =
987 chromeos::input_method::InputMethodManager::Get();
988 manager->ChangeInputMethod(
989 manager->GetInputMethodUtil()->GetHardwareInputMethodId());
990 }
991
992 static bool SetUserInputMethodImpl(
Nikita (slow) 2013/07/15 12:56:38 Please move this helper method to unnamed namespac
Alexander Alekseev 2013/07/22 14:24:21 Moved to unnamed namespace and left it static, bec
993 const std::string& username,
994 chromeos::input_method::InputMethodManager* manager) {
995 PrefService* const local_state = g_browser_process->local_state();
996
997 const base::DictionaryValue* users_lru_input_methods =
998 local_state->GetDictionary(prefs::kUsersLRUInputMethod);
999
1000 if (users_lru_input_methods == NULL) {
1001 DLOG(WARNING) << "SetUserInputMethod('" << username
1002 << "'): no kUsersLRUInputMethod";
1003 return false;
1004 }
1005
1006 std::string input_method;
1007
1008 if (!users_lru_input_methods->GetStringWithoutPathExpansion(username,
1009 &input_method)) {
1010 DLOG(INFO) << "SetUserInputMethod('" << username
1011 << "'): no input method for this user";
1012 return false;
1013 }
1014
1015 if (input_method.empty())
1016 return false;
1017
1018 if (!manager->IsFullLatinKeyboard(input_method)) {
1019 LOG(WARNING) << "SetUserInputMethod('" << username
1020 << "'): stored user LRU input method '" << input_method
1021 << "' is no longer Full Latin Keyboard Language"
1022 << " (entry dropped). Use hardware default instead.";
1023
1024 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
1025
1026 base::DictionaryValue* const users_lru_input_methods = updater.Get();
1027 if (users_lru_input_methods != NULL) {
1028 users_lru_input_methods->SetStringWithoutPathExpansion(username, "");
1029 }
1030 return false;
1031 }
1032
1033 if (!Contains(manager->GetActiveInputMethodIds(), input_method)) {
1034 if (!manager->EnableInputMethod(input_method)) {
1035 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username
1036 << "'): user input method '" << input_method
1037 << "' is not enabled and enabling failed (ignored!).";
1038 }
1039 }
1040 manager->ChangeInputMethod(input_method);
1041
1042 return true;
1043 }
1044
1045 // Update keyboard layout to least recently used by the user.
1046 void SigninScreenHandler::SetUserInputMethod(const std::string& username) {
1047 chromeos::input_method::InputMethodManager* const manager =
1048 chromeos::input_method::InputMethodManager::Get();
1049
1050 const chromeos::input_method::InputMethodUtil& ime_util =
1051 *manager->GetInputMethodUtil();
1052
1053 const bool succeed = SetUserInputMethodImpl(username, manager);
1054
1055 // This is also a case when LRU layout is set only for a few local users,
1056 // thus others need to be switched to default locale.
1057 // Otherwise they will end up using another user's locale to log in.
1058 if (!succeed) {
1059 DLOG(INFO) << "SetUserInputMethod('" << username
1060 << "'): failed to set user layout. Switching to default '"
1061 << ime_util.GetHardwareInputMethodId() << "'";
1062
1063 SetUserInputMethodHWDefault();
1064 }
1065 }
1066
971 void SigninScreenHandler::ShowSigninScreenIfReady() { 1067 void SigninScreenHandler::ShowSigninScreenIfReady() {
972 if (!dns_cleared_ || !cookies_cleared_ || !delegate_) 1068 if (!dns_cleared_ || !cookies_cleared_ || !delegate_)
973 return; 1069 return;
974 1070
975 std::string active_network = 1071 std::string active_network =
976 network_state_informer_->active_network_service_path(); 1072 network_state_informer_->active_network_service_path();
977 if (gaia_silent_load_ && 1073 if (gaia_silent_load_ &&
978 (!network_state_informer_->is_online() || 1074 (!network_state_informer_->is_online() ||
979 gaia_silent_load_network_ != active_network)) { 1075 gaia_silent_load_network_ != active_network)) {
980 // Network has changed. Force Gaia reload. 1076 // Network has changed. Force Gaia reload.
981 gaia_silent_load_ = false; 1077 gaia_silent_load_ = false;
982 // Gaia page will be realoded, so focus isn't stolen anymore. 1078 // Gaia page will be realoded, so focus isn't stolen anymore.
983 focus_stolen_ = false; 1079 focus_stolen_ = false;
984 } 1080 }
985 1081
986 // Note that LoadAuthExtension clears |email_|. 1082 // Note that LoadAuthExtension clears |email_|.
987 if (email_.empty()) 1083 if (email_.empty())
988 delegate_->LoadSigninWallpaper(); 1084 delegate_->LoadSigninWallpaper();
989 else 1085 else
990 delegate_->LoadWallpaper(email_); 1086 delegate_->LoadWallpaper(email_);
991 1087
1088 // Set Least Recently Used input method for the user.
1089 if (!email_.empty())
1090 SetUserInputMethod(email_);
1091
992 LoadAuthExtension(!gaia_silent_load_, false, false); 1092 LoadAuthExtension(!gaia_silent_load_, false, false);
993 UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL); 1093 UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL);
994 1094
995 if (gaia_silent_load_) { 1095 if (gaia_silent_load_) {
996 // The variable is assigned to false because silently loaded Gaia page was 1096 // The variable is assigned to false because silently loaded Gaia page was
997 // used. 1097 // used.
998 gaia_silent_load_ = false; 1098 gaia_silent_load_ = false;
999 if (focus_stolen_) 1099 if (focus_stolen_)
1000 HandleLoginWebuiReady(); 1100 HandleLoginWebuiReady();
1001 } 1101 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 if (gaia_silent_load_ && email_.empty()) { 1294 if (gaia_silent_load_ && email_.empty()) {
1195 dns_cleared_ = true; 1295 dns_cleared_ = true;
1196 cookies_cleared_ = true; 1296 cookies_cleared_ = true;
1197 ShowSigninScreenIfReady(); 1297 ShowSigninScreenIfReady();
1198 } else { 1298 } else {
1199 StartClearingDnsCache(); 1299 StartClearingDnsCache();
1200 StartClearingCookies(base::Bind( 1300 StartClearingCookies(base::Bind(
1201 &SigninScreenHandler::ShowSigninScreenIfReady, 1301 &SigninScreenHandler::ShowSigninScreenIfReady,
1202 weak_factory_.GetWeakPtr())); 1302 weak_factory_.GetWeakPtr()));
1203 } 1303 }
1304 SetUserInputMethodHWDefault();
1204 } 1305 }
1205 1306
1206 void SigninScreenHandler::HandleToggleEnrollmentScreen() { 1307 void SigninScreenHandler::HandleToggleEnrollmentScreen() {
1207 if (delegate_) 1308 if (delegate_)
1208 delegate_->ShowEnterpriseEnrollmentScreen(); 1309 delegate_->ShowEnterpriseEnrollmentScreen();
1209 } 1310 }
1210 1311
1211 void SigninScreenHandler::HandleToggleKioskEnableScreen() { 1312 void SigninScreenHandler::HandleToggleKioskEnableScreen() {
1212 if (delegate_ && 1313 if (delegate_ &&
1213 !g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { 1314 !g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 rvh->ExecuteJavascriptInWebFrame( 1775 rvh->ExecuteJavascriptInWebFrame(
1675 ASCIIToUTF16("//iframe[@id='signin-frame']\n//iframe"), 1776 ASCIIToUTF16("//iframe[@id='signin-frame']\n//iframe"),
1676 ASCIIToUTF16(code)); 1777 ASCIIToUTF16(code));
1677 1778
1678 // Test properties are cleared in HandleCompleteLogin because the form 1779 // Test properties are cleared in HandleCompleteLogin because the form
1679 // submission might fail and login will not be attempted after reloading 1780 // submission might fail and login will not be attempted after reloading
1680 // if they are cleared here. 1781 // if they are cleared here.
1681 } 1782 }
1682 1783
1683 } // namespace chromeos 1784 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698