OLD | NEW |
---|---|
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" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 // The Task posted to PostTaskAndReply in StartClearingDnsCache on the IO | 99 // The Task posted to PostTaskAndReply in StartClearingDnsCache on the IO |
97 // thread. | 100 // thread. |
98 void ClearDnsCache(IOThread* io_thread) { | 101 void ClearDnsCache(IOThread* io_thread) { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
100 if (browser_shutdown::IsTryingToQuit()) | 103 if (browser_shutdown::IsTryingToQuit()) |
101 return; | 104 return; |
102 | 105 |
103 io_thread->ClearHostCache(); | 106 io_thread->ClearHostCache(); |
104 } | 107 } |
105 | 108 |
109 static bool Contains(const std::vector<std::string>& container, | |
110 const std::string& value) { | |
111 return std::find(container.begin(), container.end(), value) != | |
112 container.end(); | |
113 } | |
114 | |
106 } // namespace | 115 } // namespace |
107 | 116 |
108 namespace chromeos { | 117 namespace chromeos { |
109 | 118 |
110 namespace { | 119 namespace { |
111 | 120 |
112 const char kNetworkStateOffline[] = "offline"; | 121 const char kNetworkStateOffline[] = "offline"; |
113 const char kNetworkStateOnline[] = "online"; | 122 const char kNetworkStateOnline[] = "online"; |
114 const char kNetworkStateCaptivePortal[] = "behind captive portal"; | 123 const char kNetworkStateCaptivePortal[] = "behind captive portal"; |
115 const char kNetworkStateConnecting[] = "connecting"; | 124 const char kNetworkStateConnecting[] = "connecting"; |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 AddCallback("unlockOnLoginSuccess", | 814 AddCallback("unlockOnLoginSuccess", |
806 &SigninScreenHandler::HandleUnlockOnLoginSuccess); | 815 &SigninScreenHandler::HandleUnlockOnLoginSuccess); |
807 AddCallback("frameLoadingCompleted", | 816 AddCallback("frameLoadingCompleted", |
808 &SigninScreenHandler::HandleFrameLoadingCompleted); | 817 &SigninScreenHandler::HandleFrameLoadingCompleted); |
809 AddCallback("showLoadingTimeoutError", | 818 AddCallback("showLoadingTimeoutError", |
810 &SigninScreenHandler::HandleShowLoadingTimeoutError); | 819 &SigninScreenHandler::HandleShowLoadingTimeoutError); |
811 AddCallback("updateOfflineLogin", | 820 AddCallback("updateOfflineLogin", |
812 &SigninScreenHandler::HandleUpdateOfflineLogin); | 821 &SigninScreenHandler::HandleUpdateOfflineLogin); |
813 } | 822 } |
814 | 823 |
824 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | |
825 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); | |
826 } | |
827 | |
815 void SigninScreenHandler::HandleGetUsers() { | 828 void SigninScreenHandler::HandleGetUsers() { |
816 SendUserList(false); | 829 SendUserList(false); |
817 } | 830 } |
818 | 831 |
819 void SigninScreenHandler::ClearAndEnablePassword() { | 832 void SigninScreenHandler::ClearAndEnablePassword() { |
820 CallJS("cr.ui.Oobe.resetSigninUI", false); | 833 CallJS("cr.ui.Oobe.resetSigninUI", false); |
821 } | 834 } |
822 | 835 |
823 void SigninScreenHandler::ClearUserPodPassword() { | 836 void SigninScreenHandler::ClearUserPodPassword() { |
824 CallJS("cr.ui.Oobe.clearUserPodPassword"); | 837 CallJS("cr.ui.Oobe.clearUserPodPassword"); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 } | 974 } |
962 } | 975 } |
963 | 976 |
964 void SigninScreenHandler::OnDnsCleared() { | 977 void SigninScreenHandler::OnDnsCleared() { |
965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 978 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
966 dns_clear_task_running_ = false; | 979 dns_clear_task_running_ = false; |
967 dns_cleared_ = true; | 980 dns_cleared_ = true; |
968 ShowSigninScreenIfReady(); | 981 ShowSigninScreenIfReady(); |
969 } | 982 } |
970 | 983 |
984 void SigninScreenHandler::SetUserInputMethodHWDefault() { | |
985 #if defined(OS_CHROMEOS) | |
Nikita (slow)
2013/07/11 09:13:54
No need for OS_CHROMEOS here as this class is alre
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
986 chromeos::input_method::InputMethodManager* manager = | |
987 chromeos::input_method::InputMethodManager::Get(); | |
988 manager->ChangeInputMethod( | |
989 manager->GetInputMethodUtil()->GetHardwareInputMethodId()); | |
990 #endif | |
991 } | |
992 | |
993 void SigninScreenHandler::SetUserInputMethod(const std::string& username) { | |
994 #if defined(OS_CHROMEOS) | |
Nikita (slow)
2013/07/11 09:13:54
nit: same here.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
995 // Update keyboard layout to least recently used by the user | |
996 if (g_browser_process == NULL) | |
Nikita (slow)
2013/07/11 09:13:54
nit: drop this check.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
997 return; | |
998 | |
999 if (!base::chromeos::IsRunningOnChromeOS()) | |
Nikita (slow)
2013/07/11 09:13:54
What about relying on stubs instead when not runni
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1000 return; | |
1001 | |
1002 PrefService* local_state = g_browser_process->local_state(); | |
1003 DCHECK(local_state); | |
Nikita (slow)
2013/07/11 09:13:54
nit: Drop this DCHECK.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1004 | |
1005 if (local_state == NULL) | |
Nikita (slow)
2013/07/11 09:13:54
nit: Drop this.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1006 return; | |
1007 | |
1008 chromeos::input_method::InputMethodManager* manager = | |
1009 chromeos::input_method::InputMethodManager::Get(); | |
1010 DCHECK(manager); | |
Nikita (slow)
2013/07/11 09:13:54
nit: Drop this DCHECK.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1011 | |
1012 bool succeed = false; | |
1013 do { | |
Nikita (slow)
2013/07/11 09:13:54
You should delete this loop it is not really neede
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1014 const base::DictionaryValue* users_lru_input_methods = | |
1015 local_state->GetDictionary(prefs::kUsersLRUInputMethod); | |
1016 | |
1017 if (users_lru_input_methods == NULL) { | |
1018 DLOG(WARNING) << "SetUserInputMethod('" << username | |
Nikita (slow)
2013/07/11 09:13:54
nit: I guess it is perfectly normal situation till
Alexander Alekseev
2013/07/12 20:10:49
Do all our users always have some latin input meth
| |
1019 << "'): no kUsersLRUInputMethod"; | |
1020 break; | |
1021 } | |
1022 | |
1023 std::string input_method; | |
1024 | |
1025 if (!users_lru_input_methods->GetStringWithoutPathExpansion( | |
1026 username, &input_method)) { | |
1027 DLOG(WARNING) << "SetUserInputMethod('" << username | |
Nikita (slow)
2013/07/11 09:13:54
nit: Same here. This looks like a perfectly normal
Alexander Alekseev
2013/07/12 20:10:49
But it's debug log, isn't it? I think I'd better h
| |
1028 << "'): no input method for this user"; | |
1029 break; | |
1030 } | |
1031 | |
1032 if (manager == NULL) | |
Nikita (slow)
2013/07/11 09:13:54
You don't have to check for manager not being NULL
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1033 break; | |
1034 | |
1035 const chromeos::input_method::InputMethodUtil* ime_util = | |
1036 manager->GetInputMethodUtil(); | |
1037 DCHECK(ime_util); | |
Nikita (slow)
2013/07/11 09:13:54
nit: Drop DCHECK
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1038 | |
1039 if (ime_util == NULL) | |
Nikita (slow)
2013/07/11 09:13:54
Same here.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1040 return; | |
1041 | |
1042 if (input_method.empty()) | |
1043 break; | |
1044 | |
1045 if (!manager->IsLanguageFullLatinKeyboard( | |
1046 ime_util->GetLanguageCodeFromInputMethodId(input_method))) { | |
1047 LOG(WARNING) << "SetUserInputMethod('" << username | |
Nikita (slow)
2013/07/11 09:13:54
nit: I propose dropping log message as well and ju
Alexander Alekseev
2013/07/12 20:10:49
It is probably dangerous to silently drop user pre
| |
1048 << "'): stored user LRU input method '" << input_method | |
1049 << "' is no longer Full Latin Keyboard Language." | |
1050 << " Use hardware default instead."; | |
1051 | |
1052 break; | |
1053 } | |
1054 | |
1055 if (!Contains(chromeos::input_method::InputMethodManager::Get() | |
1056 ->GetActiveInputMethodIds(), | |
Nikita (slow)
2013/07/11 09:13:54
nit: -> should be on the previous line
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1057 input_method)) { | |
1058 if (!chromeos::input_method::InputMethodManager::Get()->EnableInputMethod( | |
Nikita (slow)
2013/07/11 09:13:54
nit:
if (!chromeos::input_method::InputMethodMana
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1059 input_method)) { | |
1060 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username | |
1061 << "'): user input method '" << input_method | |
1062 << "' is not enabled and enabling failed (ignored!)."; | |
1063 } | |
1064 } | |
1065 chromeos::input_method::InputMethodManager::Get()->ChangeInputMethod( | |
Nikita (slow)
2013/07/11 09:13:54
nit: this looks more readable:
chromeos::input_me
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1066 input_method); | |
1067 | |
1068 succeed = true; | |
1069 } while (false); | |
1070 | |
1071 // This is also a case when LRU layout is set only for a few local users, | |
1072 // thus others need to be switched to default locale. | |
1073 // Otherwise they will end up using another user's locale to log in. | |
1074 if (!succeed) { | |
1075 DLOG(WARNING) | |
Nikita (slow)
2013/07/11 09:13:54
nit: No need for DLOG(WARNING), perfectly normal s
Alexander Alekseev
2013/07/12 20:10:49
But it's debug log. Let's leave traces of rare eve
| |
1076 << "SetUserInputMethod('" << username | |
1077 << "'): failed to set user layout. Switching to default '" | |
1078 << (manager != NULL | |
1079 ? manager->GetInputMethodUtil()->GetHardwareInputMethodId() | |
1080 : "NULL") << "'"; | |
1081 | |
1082 SetUserInputMethodHWDefault(); | |
1083 } | |
1084 #endif | |
1085 } | |
1086 | |
971 void SigninScreenHandler::ShowSigninScreenIfReady() { | 1087 void SigninScreenHandler::ShowSigninScreenIfReady() { |
972 if (!dns_cleared_ || !cookies_cleared_ || !delegate_) | 1088 if (!dns_cleared_ || !cookies_cleared_ || !delegate_) |
973 return; | 1089 return; |
974 | 1090 |
975 std::string active_network = | 1091 std::string active_network = |
976 network_state_informer_->active_network_service_path(); | 1092 network_state_informer_->active_network_service_path(); |
977 if (gaia_silent_load_ && | 1093 if (gaia_silent_load_ && |
978 (!network_state_informer_->is_online() || | 1094 (!network_state_informer_->is_online() || |
979 gaia_silent_load_network_ != active_network)) { | 1095 gaia_silent_load_network_ != active_network)) { |
980 // Network has changed. Force Gaia reload. | 1096 // Network has changed. Force Gaia reload. |
981 gaia_silent_load_ = false; | 1097 gaia_silent_load_ = false; |
982 // Gaia page will be realoded, so focus isn't stolen anymore. | 1098 // Gaia page will be realoded, so focus isn't stolen anymore. |
983 focus_stolen_ = false; | 1099 focus_stolen_ = false; |
984 } | 1100 } |
985 | 1101 |
986 // Note that LoadAuthExtension clears |email_|. | 1102 // Note that LoadAuthExtension clears |email_|. |
987 if (email_.empty()) | 1103 if (email_.empty()) |
988 delegate_->LoadSigninWallpaper(); | 1104 delegate_->LoadSigninWallpaper(); |
989 else | 1105 else |
990 delegate_->LoadWallpaper(email_); | 1106 delegate_->LoadWallpaper(email_); |
991 | 1107 |
1108 // Set Least Recently used input method for the user | |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
nit: missing period.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
1109 if (!email_.empty()) | |
1110 SetUserInputMethod(email_); | |
1111 | |
992 LoadAuthExtension(!gaia_silent_load_, false, false); | 1112 LoadAuthExtension(!gaia_silent_load_, false, false); |
993 UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL); | 1113 UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL); |
994 | 1114 |
995 if (gaia_silent_load_) { | 1115 if (gaia_silent_load_) { |
996 // The variable is assigned to false because silently loaded Gaia page was | 1116 // The variable is assigned to false because silently loaded Gaia page was |
997 // used. | 1117 // used. |
998 gaia_silent_load_ = false; | 1118 gaia_silent_load_ = false; |
999 if (focus_stolen_) | 1119 if (focus_stolen_) |
1000 HandleLoginWebuiReady(); | 1120 HandleLoginWebuiReady(); |
1001 } | 1121 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 if (gaia_silent_load_ && email_.empty()) { | 1314 if (gaia_silent_load_ && email_.empty()) { |
1195 dns_cleared_ = true; | 1315 dns_cleared_ = true; |
1196 cookies_cleared_ = true; | 1316 cookies_cleared_ = true; |
1197 ShowSigninScreenIfReady(); | 1317 ShowSigninScreenIfReady(); |
1198 } else { | 1318 } else { |
1199 StartClearingDnsCache(); | 1319 StartClearingDnsCache(); |
1200 StartClearingCookies(base::Bind( | 1320 StartClearingCookies(base::Bind( |
1201 &SigninScreenHandler::ShowSigninScreenIfReady, | 1321 &SigninScreenHandler::ShowSigninScreenIfReady, |
1202 weak_factory_.GetWeakPtr())); | 1322 weak_factory_.GetWeakPtr())); |
1203 } | 1323 } |
1324 SetUserInputMethodHWDefault(); | |
1204 } | 1325 } |
1205 | 1326 |
1206 void SigninScreenHandler::HandleToggleEnrollmentScreen() { | 1327 void SigninScreenHandler::HandleToggleEnrollmentScreen() { |
1207 if (delegate_) | 1328 if (delegate_) |
1208 delegate_->ShowEnterpriseEnrollmentScreen(); | 1329 delegate_->ShowEnterpriseEnrollmentScreen(); |
1209 } | 1330 } |
1210 | 1331 |
1211 void SigninScreenHandler::HandleToggleKioskEnableScreen() { | 1332 void SigninScreenHandler::HandleToggleKioskEnableScreen() { |
1212 if (delegate_ && | 1333 if (delegate_ && |
1213 !g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { | 1334 !g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 rvh->ExecuteJavascriptInWebFrame( | 1795 rvh->ExecuteJavascriptInWebFrame( |
1675 ASCIIToUTF16("//iframe[@id='signin-frame']\n//iframe"), | 1796 ASCIIToUTF16("//iframe[@id='signin-frame']\n//iframe"), |
1676 ASCIIToUTF16(code)); | 1797 ASCIIToUTF16(code)); |
1677 | 1798 |
1678 // Test properties are cleared in HandleCompleteLogin because the form | 1799 // Test properties are cleared in HandleCompleteLogin because the form |
1679 // submission might fail and login will not be attempted after reloading | 1800 // submission might fail and login will not be attempted after reloading |
1680 // if they are cleared here. | 1801 // if they are cleared here. |
1681 } | 1802 } |
1682 | 1803 |
1683 } // namespace chromeos | 1804 } // namespace chromeos |
OLD | NEW |