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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 #if defined(USE_AURA) | 76 #if defined(USE_AURA) |
77 #include "ash/shell.h" | 77 #include "ash/shell.h" |
78 #include "ash/wm/lock_state_controller.h" | 78 #include "ash/wm/lock_state_controller.h" |
79 #endif | 79 #endif |
80 | 80 |
81 using content::BrowserThread; | 81 using content::BrowserThread; |
82 | 82 |
83 namespace { | 83 namespace { |
84 | 84 |
85 // User dictionary keys. | |
86 const char kKeyUsername[] = "username"; | |
87 const char kKeyDisplayName[] = "displayName"; | |
88 const char kKeyEmailAddress[] = "emailAddress"; | |
89 const char kKeyEnterpriseDomain[] = "enterpriseDomain"; | |
90 const char kKeyPublicAccount[] = "publicAccount"; | |
91 const char kKeyLocallyManagedUser[] = "locallyManagedUser"; | |
92 const char kKeySignedIn[] = "signedIn"; | |
93 const char kKeyCanRemove[] = "canRemove"; | |
94 const char kKeyIsOwner[] = "isOwner"; | |
95 const char kKeyInitialAuthType[] = "initialAuthType"; | |
96 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; | |
97 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; | |
98 | |
99 // Max number of users to show. | 85 // Max number of users to show. |
100 const size_t kMaxUsers = 18; | 86 const size_t kMaxUsers = 18; |
101 | 87 |
102 // Timeout to delay first notification about offline state for a | 88 // Timeout to delay first notification about offline state for a |
103 // current network. | 89 // current network. |
104 const int kOfflineTimeoutSec = 5; | 90 const int kOfflineTimeoutSec = 5; |
105 | 91 |
106 // Timeout used to prevent infinite connecting to a flaky network. | 92 // Timeout used to prevent infinite connecting to a flaky network. |
107 const int kConnectingTimeoutSec = 60; | 93 const int kConnectingTimeoutSec = 60; |
108 | 94 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 213 } |
228 manager->ChangeInputMethod(input_method); | 214 manager->ChangeInputMethod(input_method); |
229 | 215 |
230 return true; | 216 return true; |
231 } | 217 } |
232 | 218 |
233 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { | 219 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { |
234 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); | 220 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); |
235 } | 221 } |
236 | 222 |
237 bool ShouldForceOnlineSignIn(const User* user) { | |
238 // Public sessions are always allowed to log in offline. | |
239 // Supervised user are allowed to log in offline if their OAuth token status | |
240 // is unknown or valid. | |
241 // For all other users, force online sign in if: | |
242 // * The flag to force online sign-in is set for the user. | |
243 // * The user's OAuth token is invalid. | |
244 // * The user's OAuth token status is unknown (except supervised users, | |
245 // see above). | |
246 if (user->is_logged_in()) | |
247 return false; | |
248 | |
249 const User::OAuthTokenStatus token_status = user->oauth_token_status(); | |
250 const bool is_locally_managed_user = | |
251 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED; | |
252 const bool is_public_session = | |
253 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; | |
254 | |
255 if (is_locally_managed_user && | |
256 token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN) { | |
257 return false; | |
258 } | |
259 | |
260 if (is_public_session) | |
261 return false; | |
262 | |
263 return user->force_online_signin() || | |
264 (token_status == User::OAUTH2_TOKEN_STATUS_INVALID) || | |
265 (token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN); | |
266 } | |
267 | |
268 } // namespace | 223 } // namespace |
269 | 224 |
270 // LoginScreenContext implementation ------------------------------------------ | 225 // LoginScreenContext implementation ------------------------------------------ |
271 | 226 |
272 LoginScreenContext::LoginScreenContext() { | 227 LoginScreenContext::LoginScreenContext() { |
273 Init(); | 228 Init(); |
274 } | 229 } |
275 | 230 |
276 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { | 231 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { |
277 Init(); | 232 Init(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 show_on_init_ = true; | 472 show_on_init_ = true; |
518 return; | 473 return; |
519 } | 474 } |
520 | 475 |
521 if (oobe_ui_) { | 476 if (oobe_ui_) { |
522 // Shows new user sign-in for OOBE. | 477 // Shows new user sign-in for OOBE. |
523 OnShowAddUser(email_); | 478 OnShowAddUser(email_); |
524 } else { | 479 } else { |
525 // Populates account picker. Animation is turned off for now until we | 480 // Populates account picker. Animation is turned off for now until we |
526 // figure out how to make it fast enough. | 481 // figure out how to make it fast enough. |
527 SendUserList(false); | 482 delegate_->HandleGetUsers(); |
528 | 483 |
529 // Reset Caps Lock state when login screen is shown. | 484 // Reset Caps Lock state when login screen is shown. |
530 input_method::InputMethodManager::Get() | 485 input_method::InputMethodManager::Get() |
531 ->GetImeKeyboard() | 486 ->GetImeKeyboard() |
532 ->SetCapsLockEnabled(false); | 487 ->SetCapsLockEnabled(false); |
533 | 488 |
534 base::DictionaryValue params; | 489 base::DictionaryValue params; |
535 params.SetBoolean("disableAddUser", AllWhitelistedUsersPresent()); | 490 params.SetBoolean("disableAddUser", AllWhitelistedUsersPresent()); |
536 UpdateUIState(UI_STATE_ACCOUNT_PICKER, ¶ms); | 491 UpdateUIState(UI_STATE_ACCOUNT_PICKER, ¶ms); |
537 } | 492 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 // This message is sent by the kiosk app menu, but is handled here | 775 // This message is sent by the kiosk app menu, but is handled here |
821 // so we can tell the delegate to launch the app. | 776 // so we can tell the delegate to launch the app. |
822 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); | 777 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); |
823 } | 778 } |
824 | 779 |
825 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 780 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
826 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); | 781 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); |
827 } | 782 } |
828 | 783 |
829 void SigninScreenHandler::HandleGetUsers() { | 784 void SigninScreenHandler::HandleGetUsers() { |
830 SendUserList(false); | 785 if (delegate_) |
| 786 delegate_->HandleGetUsers(); |
831 } | 787 } |
832 | 788 |
833 void SigninScreenHandler::ClearAndEnablePassword() { | 789 void SigninScreenHandler::ClearAndEnablePassword() { |
834 core_oobe_actor_->ResetSignInUI(false); | 790 core_oobe_actor_->ResetSignInUI(false); |
835 } | 791 } |
836 | 792 |
837 void SigninScreenHandler::ClearUserPodPassword() { | 793 void SigninScreenHandler::ClearUserPodPassword() { |
838 core_oobe_actor_->ClearUserPodPassword(); | 794 core_oobe_actor_->ClearUserPodPassword(); |
839 } | 795 } |
840 | 796 |
(...skipping 17 matching lines...) Expand all Loading... |
858 // preferences update would be picked up next time it will be shown. | 814 // preferences update would be picked up next time it will be shown. |
859 if (!webui_visible_) { | 815 if (!webui_visible_) { |
860 LOG(WARNING) << "Login UI is not active - postponed prefs change."; | 816 LOG(WARNING) << "Login UI is not active - postponed prefs change."; |
861 preferences_changed_delayed_ = true; | 817 preferences_changed_delayed_ = true; |
862 return; | 818 return; |
863 } | 819 } |
864 | 820 |
865 if (delegate_ && !delegate_->IsShowUsers()) { | 821 if (delegate_ && !delegate_->IsShowUsers()) { |
866 HandleShowAddUser(NULL); | 822 HandleShowAddUser(NULL); |
867 } else { | 823 } else { |
868 SendUserList(false); | 824 if (delegate_) |
| 825 delegate_->HandleGetUsers(); |
869 UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL); | 826 UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL); |
870 } | 827 } |
871 preferences_changed_delayed_ = false; | 828 preferences_changed_delayed_ = false; |
872 } | 829 } |
873 | 830 |
874 void SigninScreenHandler::ResetSigninScreenHandlerDelegate() { | 831 void SigninScreenHandler::ResetSigninScreenHandlerDelegate() { |
875 SetDelegate(NULL); | 832 SetDelegate(NULL); |
876 } | 833 } |
877 | 834 |
878 void SigninScreenHandler::ShowError(int login_attempts, | 835 void SigninScreenHandler::ShowError(int login_attempts, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 969 |
1013 void SigninScreenHandler::EnableInput() { | 970 void SigninScreenHandler::EnableInput() { |
1014 // Only for lock screen at the moment. | 971 // Only for lock screen at the moment. |
1015 ScreenLocker::default_screen_locker()->EnableInput(); | 972 ScreenLocker::default_screen_locker()->EnableInput(); |
1016 } | 973 } |
1017 | 974 |
1018 void SigninScreenHandler::SetAuthType( | 975 void SigninScreenHandler::SetAuthType( |
1019 const std::string& username, | 976 const std::string& username, |
1020 ScreenlockBridge::LockHandler::AuthType auth_type, | 977 ScreenlockBridge::LockHandler::AuthType auth_type, |
1021 const std::string& initial_value) { | 978 const std::string& initial_value) { |
1022 user_auth_type_map_[username] = auth_type; | 979 delegate_->SetAuthType(username, auth_type); |
| 980 |
1023 CallJS("login.AccountPickerScreen.setAuthType", | 981 CallJS("login.AccountPickerScreen.setAuthType", |
1024 username, | 982 username, |
1025 static_cast<int>(auth_type), | 983 static_cast<int>(auth_type), |
1026 base::StringValue(initial_value)); | 984 base::StringValue(initial_value)); |
1027 } | 985 } |
1028 | 986 |
1029 ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType( | 987 ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType( |
1030 const std::string& username) const { | 988 const std::string& username) const { |
1031 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) | 989 return delegate_->GetAuthType(username); |
1032 return OFFLINE_PASSWORD; | |
1033 return user_auth_type_map_.find(username)->second; | |
1034 } | 990 } |
1035 | 991 |
1036 void SigninScreenHandler::Unlock(const std::string& user_email) { | 992 void SigninScreenHandler::Unlock(const std::string& user_email) { |
1037 DCHECK(ScreenLocker::default_screen_locker()); | 993 DCHECK(ScreenLocker::default_screen_locker()); |
1038 ScreenLocker::Hide(); | 994 ScreenLocker::Hide(); |
1039 } | 995 } |
1040 | 996 |
1041 void SigninScreenHandler::OnDnsCleared() { | 997 void SigninScreenHandler::OnDnsCleared() { |
1042 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 998 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1043 dns_clear_task_running_ = false; | 999 dns_clear_task_running_ = false; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 } | 1285 } |
1330 } | 1286 } |
1331 | 1287 |
1332 void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() { | 1288 void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() { |
1333 policy::BrowserPolicyConnectorChromeOS* connector = | 1289 policy::BrowserPolicyConnectorChromeOS* connector = |
1334 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 1290 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
1335 if (delegate_ && !connector->IsEnterpriseManaged()) | 1291 if (delegate_ && !connector->IsEnterpriseManaged()) |
1336 delegate_->ShowKioskAutolaunchScreen(); | 1292 delegate_->ShowKioskAutolaunchScreen(); |
1337 } | 1293 } |
1338 | 1294 |
1339 void SigninScreenHandler::FillUserDictionary( | 1295 void SigninScreenHandler::LoadUsers(const base::ListValue& users_list, |
1340 User* user, | 1296 bool animated, |
1341 bool is_owner, | 1297 bool showGuest) { |
1342 bool is_signin_to_add, | 1298 CallJS("login.AccountPickerScreen.loadUsers", |
1343 ScreenlockBridge::LockHandler::AuthType auth_type, | 1299 users_list, |
1344 base::DictionaryValue* user_dict) { | 1300 animated, |
1345 const std::string& email = user->email(); | |
1346 const bool is_public_account = | |
1347 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; | |
1348 const bool is_locally_managed_user = | |
1349 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED; | |
1350 | |
1351 user_dict->SetString(kKeyUsername, email); | |
1352 user_dict->SetString(kKeyEmailAddress, user->display_email()); | |
1353 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); | |
1354 user_dict->SetBoolean(kKeyPublicAccount, is_public_account); | |
1355 user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user); | |
1356 user_dict->SetInteger(kKeyInitialAuthType, auth_type); | |
1357 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); | |
1358 user_dict->SetBoolean(kKeyIsOwner, is_owner); | |
1359 | |
1360 // Fill in multi-profiles related fields. | |
1361 if (is_signin_to_add) { | |
1362 MultiProfileUserController* multi_profile_user_controller = | |
1363 UserManager::Get()->GetMultiProfileUserController(); | |
1364 std::string behavior = multi_profile_user_controller-> | |
1365 GetCachedValue(user->email()); | |
1366 user_dict->SetBoolean(kKeyMultiProfilesAllowed, | |
1367 multi_profile_user_controller->IsUserAllowedInSession(email) == | |
1368 MultiProfileUserController::ALLOWED); | |
1369 user_dict->SetString(kKeyMultiProfilesPolicy, behavior); | |
1370 } else { | |
1371 user_dict->SetBoolean(kKeyMultiProfilesAllowed, true); | |
1372 } | |
1373 | |
1374 if (is_public_account) { | |
1375 policy::BrowserPolicyConnectorChromeOS* policy_connector = | |
1376 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
1377 | |
1378 if (policy_connector->IsEnterpriseManaged()) { | |
1379 user_dict->SetString(kKeyEnterpriseDomain, | |
1380 policy_connector->GetEnterpriseDomain()); | |
1381 } | |
1382 } | |
1383 } | |
1384 | |
1385 void SigninScreenHandler::SendUserList(bool animated) { | |
1386 if (!delegate_) | |
1387 return; | |
1388 TRACE_EVENT_ASYNC_STEP_INTO0("ui", | |
1389 "ShowLoginWebUI", | |
1390 LoginDisplayHostImpl::kShowLoginWebUIid, | |
1391 "SendUserList"); | |
1392 BootTimesLoader::Get()->RecordCurrentStats("login-send-user-list"); | |
1393 | |
1394 base::ListValue users_list; | |
1395 const UserList& users = delegate_->GetUsers(); | |
1396 | |
1397 // TODO(nkostylev): Move to a separate method in UserManager. | |
1398 // http://crbug.com/230852 | |
1399 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && | |
1400 UserManager::Get()->IsUserLoggedIn(); | |
1401 | |
1402 user_auth_type_map_.clear(); | |
1403 | |
1404 bool single_user = users.size() == 1; | |
1405 std::string owner; | |
1406 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); | |
1407 bool has_owner = owner.size() > 0; | |
1408 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; | |
1409 size_t non_owner_count = 0; | |
1410 policy::BrowserPolicyConnectorChromeOS* connector = | |
1411 g_browser_process->platform_part()-> | |
1412 browser_policy_connector_chromeos(); | |
1413 bool is_enterprise_managed = connector->IsEnterpriseManaged(); | |
1414 | |
1415 | |
1416 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | |
1417 const std::string& email = (*it)->email(); | |
1418 bool is_owner = (email == owner); | |
1419 bool is_public_account = | |
1420 ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT); | |
1421 | |
1422 if ((is_public_account && !is_signin_to_add) || | |
1423 is_owner || | |
1424 (!is_public_account && non_owner_count < max_non_owner_users)) { | |
1425 AuthType initial_auth_type = | |
1426 ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN : OFFLINE_PASSWORD; | |
1427 user_auth_type_map_[email] = initial_auth_type; | |
1428 | |
1429 base::DictionaryValue* user_dict = new base::DictionaryValue(); | |
1430 FillUserDictionary( | |
1431 *it, is_owner, is_signin_to_add, initial_auth_type, user_dict); | |
1432 bool signed_in = (*it)->is_logged_in(); | |
1433 // Single user check here is necessary because owner info might not be | |
1434 // available when running into login screen on first boot. | |
1435 // See http://crosbug.com/12723 | |
1436 bool can_remove_user = ((!single_user || is_enterprise_managed) && | |
1437 !email.empty() && !is_owner && !is_public_account && | |
1438 !signed_in && !is_signin_to_add); | |
1439 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); | |
1440 | |
1441 if (!is_owner) | |
1442 ++non_owner_count; | |
1443 if (is_owner && users_list.GetSize() > kMaxUsers) { | |
1444 // Owner is always in the list. | |
1445 users_list.Insert(kMaxUsers - 1, user_dict); | |
1446 } else { | |
1447 users_list.Append(user_dict); | |
1448 } | |
1449 } | |
1450 } | |
1451 while (users_list.GetSize() > kMaxUsers) | |
1452 users_list.Remove(kMaxUsers, NULL); | |
1453 | |
1454 CallJS("login.AccountPickerScreen.loadUsers", users_list, animated, | |
1455 delegate_->IsShowGuest()); | 1301 delegate_->IsShowGuest()); |
1456 } | 1302 } |
1457 | 1303 |
1458 void SigninScreenHandler::HandleAccountPickerReady() { | 1304 void SigninScreenHandler::HandleAccountPickerReady() { |
1459 VLOG(0) << "Login WebUI >> AccountPickerReady"; | 1305 VLOG(0) << "Login WebUI >> AccountPickerReady"; |
1460 | 1306 |
1461 if (delegate_ && !ScreenLocker::default_screen_locker() && | 1307 if (delegate_ && !ScreenLocker::default_screen_locker() && |
1462 !chromeos::IsMachineHWIDCorrect() && | 1308 !chromeos::IsMachineHWIDCorrect() && |
1463 !oobe_ui_) { | 1309 !oobe_ui_) { |
1464 delegate_->ShowWrongHWIDScreen(); | 1310 delegate_->ShowWrongHWIDScreen(); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 return gaia_screen_handler_->frame_error(); | 1680 return gaia_screen_handler_->frame_error(); |
1835 } | 1681 } |
1836 | 1682 |
1837 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { | 1683 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { |
1838 caps_lock_enabled_ = enabled; | 1684 caps_lock_enabled_ = enabled; |
1839 if (page_is_ready()) | 1685 if (page_is_ready()) |
1840 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); | 1686 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); |
1841 } | 1687 } |
1842 | 1688 |
1843 } // namespace chromeos | 1689 } // namespace chromeos |
OLD | NEW |