| 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/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 25 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 23 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 26 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
| 24 #include "chrome/browser/chromeos/login/hwid_checker.h" | 27 #include "chrome/browser/chromeos/login/hwid_checker.h" |
| 25 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 28 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| 26 #include "chrome/browser/chromeos/login/screen_locker.h" | 29 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 27 #include "chrome/browser/chromeos/login/user.h" | 30 #include "chrome/browser/chromeos/login/user.h" |
| 28 #include "chrome/browser/chromeos/login/webui_login_display.h" | 31 #include "chrome/browser/chromeos/login/webui_login_display.h" |
| 29 #include "chrome/browser/chromeos/login/wizard_controller.h" | 32 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 30 #include "chrome/browser/chromeos/net/network_portal_detector.h" | 33 #include "chrome/browser/chromeos/net/network_portal_detector.h" |
| 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 34 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 32 #include "chrome/browser/chromeos/settings/cros_settings.h" | 35 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 33 #include "chrome/browser/io_thread.h" | 36 #include "chrome/browser/io_thread.h" |
| 34 #include "chrome/browser/policy/browser_policy_connector.h" | 37 #include "chrome/browser/policy/browser_policy_connector.h" |
| 38 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h" | 40 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h" |
| 37 #include "chrome/browser/ui/webui/chromeos/login/native_window_delegate.h" | 41 #include "chrome/browser/ui/webui/chromeos/login/native_window_delegate.h" |
| 38 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" | 42 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" |
| 39 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 43 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.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" |
| 44 #include "chromeos/dbus/dbus_thread_manager.h" | 48 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, |
| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: | 315 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: |
| 306 if (network->connection_state() != flimflam::kStateOnline) | 316 if (network->connection_state() != flimflam::kStateOnline) |
| 307 RecordDiscrepancyWithShill(network, state.status); | 317 RecordDiscrepancyWithShill(network, state.status); |
| 308 break; | 318 break; |
| 309 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: | 319 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: |
| 310 NOTREACHED(); | 320 NOTREACHED(); |
| 311 break; | 321 break; |
| 312 } | 322 } |
| 313 } | 323 } |
| 314 | 324 |
| 325 static bool SetUserInputMethodImpl( |
| 326 const std::string& username, |
| 327 chromeos::input_method::InputMethodManager* manager) { |
| 328 PrefService* const local_state = g_browser_process->local_state(); |
| 329 |
| 330 const base::DictionaryValue* users_lru_input_methods = |
| 331 local_state->GetDictionary(prefs::kUsersLRUInputMethod); |
| 332 |
| 333 if (users_lru_input_methods == NULL) { |
| 334 DLOG(WARNING) << "SetUserInputMethod('" << username |
| 335 << "'): no kUsersLRUInputMethod"; |
| 336 return false; |
| 337 } |
| 338 |
| 339 std::string input_method; |
| 340 |
| 341 if (!users_lru_input_methods->GetStringWithoutPathExpansion(username, |
| 342 &input_method)) { |
| 343 DLOG(INFO) << "SetUserInputMethod('" << username |
| 344 << "'): no input method for this user"; |
| 345 return false; |
| 346 } |
| 347 |
| 348 if (input_method.empty()) |
| 349 return false; |
| 350 |
| 351 if (!manager->IsFullLatinKeyboard(input_method)) { |
| 352 LOG(WARNING) << "SetUserInputMethod('" << username |
| 353 << "'): stored user LRU input method '" << input_method |
| 354 << "' is no longer Full Latin Keyboard Language" |
| 355 << " (entry dropped). Use hardware default instead."; |
| 356 |
| 357 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); |
| 358 |
| 359 base::DictionaryValue* const users_lru_input_methods = updater.Get(); |
| 360 if (users_lru_input_methods != NULL) { |
| 361 users_lru_input_methods->SetStringWithoutPathExpansion(username, ""); |
| 362 } |
| 363 return false; |
| 364 } |
| 365 |
| 366 if (!Contains(manager->GetActiveInputMethodIds(), input_method)) { |
| 367 if (!manager->EnableInputMethod(input_method)) { |
| 368 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username |
| 369 << "'): user input method '" << input_method |
| 370 << "' is not enabled and enabling failed (ignored!)."; |
| 371 } |
| 372 } |
| 373 manager->ChangeInputMethod(input_method); |
| 374 |
| 375 return true; |
| 376 } |
| 377 |
| 315 } // namespace | 378 } // namespace |
| 316 | 379 |
| 317 // SigninScreenHandler implementation ------------------------------------------ | 380 // SigninScreenHandler implementation ------------------------------------------ |
| 318 | 381 |
| 319 SigninScreenHandler::SigninScreenHandler( | 382 SigninScreenHandler::SigninScreenHandler( |
| 320 const scoped_refptr<NetworkStateInformer>& network_state_informer, | 383 const scoped_refptr<NetworkStateInformer>& network_state_informer, |
| 321 ErrorScreenActor* error_screen_actor) | 384 ErrorScreenActor* error_screen_actor) |
| 322 : ui_state_(UI_STATE_UNKNOWN), | 385 : ui_state_(UI_STATE_UNKNOWN), |
| 323 frame_state_(FRAME_STATE_UNKNOWN), | 386 frame_state_(FRAME_STATE_UNKNOWN), |
| 324 frame_error_(net::OK), | 387 frame_error_(net::OK), |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 AddCallback("unlockOnLoginSuccess", | 870 AddCallback("unlockOnLoginSuccess", |
| 808 &SigninScreenHandler::HandleUnlockOnLoginSuccess); | 871 &SigninScreenHandler::HandleUnlockOnLoginSuccess); |
| 809 AddCallback("frameLoadingCompleted", | 872 AddCallback("frameLoadingCompleted", |
| 810 &SigninScreenHandler::HandleFrameLoadingCompleted); | 873 &SigninScreenHandler::HandleFrameLoadingCompleted); |
| 811 AddCallback("showLoadingTimeoutError", | 874 AddCallback("showLoadingTimeoutError", |
| 812 &SigninScreenHandler::HandleShowLoadingTimeoutError); | 875 &SigninScreenHandler::HandleShowLoadingTimeoutError); |
| 813 AddCallback("updateOfflineLogin", | 876 AddCallback("updateOfflineLogin", |
| 814 &SigninScreenHandler::HandleUpdateOfflineLogin); | 877 &SigninScreenHandler::HandleUpdateOfflineLogin); |
| 815 } | 878 } |
| 816 | 879 |
| 880 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
| 881 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); |
| 882 } |
| 883 |
| 817 void SigninScreenHandler::HandleGetUsers() { | 884 void SigninScreenHandler::HandleGetUsers() { |
| 818 SendUserList(false); | 885 SendUserList(false); |
| 819 } | 886 } |
| 820 | 887 |
| 821 void SigninScreenHandler::ClearAndEnablePassword() { | 888 void SigninScreenHandler::ClearAndEnablePassword() { |
| 822 CallJS("cr.ui.Oobe.resetSigninUI", false); | 889 CallJS("cr.ui.Oobe.resetSigninUI", false); |
| 823 } | 890 } |
| 824 | 891 |
| 825 void SigninScreenHandler::ClearUserPodPassword() { | 892 void SigninScreenHandler::ClearUserPodPassword() { |
| 826 CallJS("cr.ui.Oobe.clearUserPodPassword"); | 893 CallJS("cr.ui.Oobe.clearUserPodPassword"); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 } | 1030 } |
| 964 } | 1031 } |
| 965 | 1032 |
| 966 void SigninScreenHandler::OnDnsCleared() { | 1033 void SigninScreenHandler::OnDnsCleared() { |
| 967 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 968 dns_clear_task_running_ = false; | 1035 dns_clear_task_running_ = false; |
| 969 dns_cleared_ = true; | 1036 dns_cleared_ = true; |
| 970 ShowSigninScreenIfReady(); | 1037 ShowSigninScreenIfReady(); |
| 971 } | 1038 } |
| 972 | 1039 |
| 1040 void SigninScreenHandler::SetUserInputMethodHWDefault() { |
| 1041 chromeos::input_method::InputMethodManager* manager = |
| 1042 chromeos::input_method::InputMethodManager::Get(); |
| 1043 manager->ChangeInputMethod( |
| 1044 manager->GetInputMethodUtil()->GetHardwareInputMethodId()); |
| 1045 } |
| 1046 |
| 1047 // Update keyboard layout to least recently used by the user. |
| 1048 void SigninScreenHandler::SetUserInputMethod(const std::string& username) { |
| 1049 chromeos::input_method::InputMethodManager* const manager = |
| 1050 chromeos::input_method::InputMethodManager::Get(); |
| 1051 |
| 1052 const chromeos::input_method::InputMethodUtil& ime_util = |
| 1053 *manager->GetInputMethodUtil(); |
| 1054 |
| 1055 const bool succeed = SetUserInputMethodImpl(username, manager); |
| 1056 |
| 1057 // This is also a case when LRU layout is set only for a few local users, |
| 1058 // thus others need to be switched to default locale. |
| 1059 // Otherwise they will end up using another user's locale to log in. |
| 1060 if (!succeed) { |
| 1061 DLOG(INFO) << "SetUserInputMethod('" << username |
| 1062 << "'): failed to set user layout. Switching to default '" |
| 1063 << ime_util.GetHardwareInputMethodId() << "'"; |
| 1064 |
| 1065 SetUserInputMethodHWDefault(); |
| 1066 } |
| 1067 } |
| 1068 |
| 973 void SigninScreenHandler::ShowSigninScreenIfReady() { | 1069 void SigninScreenHandler::ShowSigninScreenIfReady() { |
| 974 if (!dns_cleared_ || !cookies_cleared_ || !delegate_) | 1070 if (!dns_cleared_ || !cookies_cleared_ || !delegate_) |
| 975 return; | 1071 return; |
| 976 | 1072 |
| 977 std::string active_network = | 1073 std::string active_network = |
| 978 network_state_informer_->active_network_service_path(); | 1074 network_state_informer_->active_network_service_path(); |
| 979 if (gaia_silent_load_ && | 1075 if (gaia_silent_load_ && |
| 980 (!network_state_informer_->is_online() || | 1076 (!network_state_informer_->is_online() || |
| 981 gaia_silent_load_network_ != active_network)) { | 1077 gaia_silent_load_network_ != active_network)) { |
| 982 // Network has changed. Force Gaia reload. | 1078 // Network has changed. Force Gaia reload. |
| 983 gaia_silent_load_ = false; | 1079 gaia_silent_load_ = false; |
| 984 // Gaia page will be realoded, so focus isn't stolen anymore. | 1080 // Gaia page will be realoded, so focus isn't stolen anymore. |
| 985 focus_stolen_ = false; | 1081 focus_stolen_ = false; |
| 986 } | 1082 } |
| 987 | 1083 |
| 988 // Note that LoadAuthExtension clears |email_|. | 1084 // Note that LoadAuthExtension clears |email_|. |
| 989 if (email_.empty()) | 1085 if (email_.empty()) |
| 990 delegate_->LoadSigninWallpaper(); | 1086 delegate_->LoadSigninWallpaper(); |
| 991 else | 1087 else |
| 992 delegate_->LoadWallpaper(email_); | 1088 delegate_->LoadWallpaper(email_); |
| 993 | 1089 |
| 1090 // Set Least Recently Used input method for the user. |
| 1091 if (!email_.empty()) |
| 1092 SetUserInputMethod(email_); |
| 1093 |
| 994 LoadAuthExtension(!gaia_silent_load_, false, false); | 1094 LoadAuthExtension(!gaia_silent_load_, false, false); |
| 995 UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL); | 1095 UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL); |
| 996 | 1096 |
| 997 if (gaia_silent_load_) { | 1097 if (gaia_silent_load_) { |
| 998 // The variable is assigned to false because silently loaded Gaia page was | 1098 // The variable is assigned to false because silently loaded Gaia page was |
| 999 // used. | 1099 // used. |
| 1000 gaia_silent_load_ = false; | 1100 gaia_silent_load_ = false; |
| 1001 if (focus_stolen_) | 1101 if (focus_stolen_) |
| 1002 HandleLoginWebuiReady(); | 1102 HandleLoginWebuiReady(); |
| 1003 } | 1103 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 if (gaia_silent_load_ && email_.empty()) { | 1295 if (gaia_silent_load_ && email_.empty()) { |
| 1196 dns_cleared_ = true; | 1296 dns_cleared_ = true; |
| 1197 cookies_cleared_ = true; | 1297 cookies_cleared_ = true; |
| 1198 ShowSigninScreenIfReady(); | 1298 ShowSigninScreenIfReady(); |
| 1199 } else { | 1299 } else { |
| 1200 StartClearingDnsCache(); | 1300 StartClearingDnsCache(); |
| 1201 StartClearingCookies(base::Bind( | 1301 StartClearingCookies(base::Bind( |
| 1202 &SigninScreenHandler::ShowSigninScreenIfReady, | 1302 &SigninScreenHandler::ShowSigninScreenIfReady, |
| 1203 weak_factory_.GetWeakPtr())); | 1303 weak_factory_.GetWeakPtr())); |
| 1204 } | 1304 } |
| 1305 SetUserInputMethodHWDefault(); |
| 1205 } | 1306 } |
| 1206 | 1307 |
| 1207 void SigninScreenHandler::HandleToggleEnrollmentScreen() { | 1308 void SigninScreenHandler::HandleToggleEnrollmentScreen() { |
| 1208 if (delegate_) | 1309 if (delegate_) |
| 1209 delegate_->ShowEnterpriseEnrollmentScreen(); | 1310 delegate_->ShowEnterpriseEnrollmentScreen(); |
| 1210 } | 1311 } |
| 1211 | 1312 |
| 1212 void SigninScreenHandler::HandleToggleKioskEnableScreen() { | 1313 void SigninScreenHandler::HandleToggleKioskEnableScreen() { |
| 1213 if (delegate_ && | 1314 if (delegate_ && |
| 1214 !g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { | 1315 !g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 rvh->ExecuteJavascriptInWebFrame( | 1771 rvh->ExecuteJavascriptInWebFrame( |
| 1671 ASCIIToUTF16("//iframe[@id='signin-frame']\n//iframe"), | 1772 ASCIIToUTF16("//iframe[@id='signin-frame']\n//iframe"), |
| 1672 ASCIIToUTF16(code)); | 1773 ASCIIToUTF16(code)); |
| 1673 | 1774 |
| 1674 // Test properties are cleared in HandleCompleteLogin because the form | 1775 // Test properties are cleared in HandleCompleteLogin because the form |
| 1675 // submission might fail and login will not be attempted after reloading | 1776 // submission might fail and login will not be attempted after reloading |
| 1676 // if they are cleared here. | 1777 // if they are cleared here. |
| 1677 } | 1778 } |
| 1678 | 1779 |
| 1679 } // namespace chromeos | 1780 } // namespace chromeos |
| OLD | NEW |