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

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

Issue 317243006: Revert 275046 "ChromeOS login webui refactoring: split user sele..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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
85 // Max number of users to show. 99 // Max number of users to show.
86 const size_t kMaxUsers = 18; 100 const size_t kMaxUsers = 18;
87 101
88 // Timeout to delay first notification about offline state for a 102 // Timeout to delay first notification about offline state for a
89 // current network. 103 // current network.
90 const int kOfflineTimeoutSec = 5; 104 const int kOfflineTimeoutSec = 5;
91 105
92 // Timeout used to prevent infinite connecting to a flaky network. 106 // Timeout used to prevent infinite connecting to a flaky network.
93 const int kConnectingTimeoutSec = 60; 107 const int kConnectingTimeoutSec = 60;
94 108
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 227 }
214 manager->ChangeInputMethod(input_method); 228 manager->ChangeInputMethod(input_method);
215 229
216 return true; 230 return true;
217 } 231 }
218 232
219 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { 233 void RecordSAMLScrapingVerificationResultInHistogram(bool success) {
220 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); 234 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success);
221 } 235 }
222 236
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
223 } // namespace 268 } // namespace
224 269
225 // LoginScreenContext implementation ------------------------------------------ 270 // LoginScreenContext implementation ------------------------------------------
226 271
227 LoginScreenContext::LoginScreenContext() { 272 LoginScreenContext::LoginScreenContext() {
228 Init(); 273 Init();
229 } 274 }
230 275
231 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { 276 LoginScreenContext::LoginScreenContext(const base::ListValue* args) {
232 Init(); 277 Init();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 show_on_init_ = true; 511 show_on_init_ = true;
467 return; 512 return;
468 } 513 }
469 514
470 if (oobe_ui_) { 515 if (oobe_ui_) {
471 // Shows new user sign-in for OOBE. 516 // Shows new user sign-in for OOBE.
472 OnShowAddUser(email_); 517 OnShowAddUser(email_);
473 } else { 518 } else {
474 // Populates account picker. Animation is turned off for now until we 519 // Populates account picker. Animation is turned off for now until we
475 // figure out how to make it fast enough. 520 // figure out how to make it fast enough.
476 delegate_->HandleGetUsers(); 521 SendUserList(false);
477 522
478 // Reset Caps Lock state when login screen is shown. 523 // Reset Caps Lock state when login screen is shown.
479 input_method::InputMethodManager::Get() 524 input_method::InputMethodManager::Get()
480 ->GetImeKeyboard() 525 ->GetImeKeyboard()
481 ->SetCapsLockEnabled(false); 526 ->SetCapsLockEnabled(false);
482 527
483 base::DictionaryValue params; 528 base::DictionaryValue params;
484 params.SetBoolean("disableAddUser", AllWhitelistedUsersPresent()); 529 params.SetBoolean("disableAddUser", AllWhitelistedUsersPresent());
485 UpdateUIState(UI_STATE_ACCOUNT_PICKER, &params); 530 UpdateUIState(UI_STATE_ACCOUNT_PICKER, &params);
486 } 531 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 // This message is sent by the kiosk app menu, but is handled here 814 // This message is sent by the kiosk app menu, but is handled here
770 // so we can tell the delegate to launch the app. 815 // so we can tell the delegate to launch the app.
771 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); 816 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp);
772 } 817 }
773 818
774 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { 819 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
775 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); 820 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
776 } 821 }
777 822
778 void SigninScreenHandler::HandleGetUsers() { 823 void SigninScreenHandler::HandleGetUsers() {
779 if (delegate_) 824 SendUserList(false);
780 delegate_->HandleGetUsers();
781 } 825 }
782 826
783 void SigninScreenHandler::ClearAndEnablePassword() { 827 void SigninScreenHandler::ClearAndEnablePassword() {
784 core_oobe_actor_->ResetSignInUI(false); 828 core_oobe_actor_->ResetSignInUI(false);
785 } 829 }
786 830
787 void SigninScreenHandler::ClearUserPodPassword() { 831 void SigninScreenHandler::ClearUserPodPassword() {
788 core_oobe_actor_->ClearUserPodPassword(); 832 core_oobe_actor_->ClearUserPodPassword();
789 } 833 }
790 834
(...skipping 17 matching lines...) Expand all
808 // preferences update would be picked up next time it will be shown. 852 // preferences update would be picked up next time it will be shown.
809 if (!webui_visible_) { 853 if (!webui_visible_) {
810 LOG(WARNING) << "Login UI is not active - postponed prefs change."; 854 LOG(WARNING) << "Login UI is not active - postponed prefs change.";
811 preferences_changed_delayed_ = true; 855 preferences_changed_delayed_ = true;
812 return; 856 return;
813 } 857 }
814 858
815 if (delegate_ && !delegate_->IsShowUsers()) { 859 if (delegate_ && !delegate_->IsShowUsers()) {
816 HandleShowAddUser(NULL); 860 HandleShowAddUser(NULL);
817 } else { 861 } else {
818 if (delegate_) 862 SendUserList(false);
819 delegate_->HandleGetUsers();
820 UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL); 863 UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL);
821 } 864 }
822 preferences_changed_delayed_ = false; 865 preferences_changed_delayed_ = false;
823 } 866 }
824 867
825 void SigninScreenHandler::ResetSigninScreenHandlerDelegate() { 868 void SigninScreenHandler::ResetSigninScreenHandlerDelegate() {
826 SetDelegate(NULL); 869 SetDelegate(NULL);
827 } 870 }
828 871
829 void SigninScreenHandler::ShowError(int login_attempts, 872 void SigninScreenHandler::ShowError(int login_attempts,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 994
952 void SigninScreenHandler::EnableInput() { 995 void SigninScreenHandler::EnableInput() {
953 // Only for lock screen at the moment. 996 // Only for lock screen at the moment.
954 ScreenLocker::default_screen_locker()->EnableInput(); 997 ScreenLocker::default_screen_locker()->EnableInput();
955 } 998 }
956 999
957 void SigninScreenHandler::SetAuthType( 1000 void SigninScreenHandler::SetAuthType(
958 const std::string& username, 1001 const std::string& username,
959 ScreenlockBridge::LockHandler::AuthType auth_type, 1002 ScreenlockBridge::LockHandler::AuthType auth_type,
960 const std::string& initial_value) { 1003 const std::string& initial_value) {
961 delegate_->SetAuthType(username, auth_type); 1004 user_auth_type_map_[username] = auth_type;
962
963 CallJS("login.AccountPickerScreen.setAuthType", 1005 CallJS("login.AccountPickerScreen.setAuthType",
964 username, 1006 username,
965 static_cast<int>(auth_type), 1007 static_cast<int>(auth_type),
966 base::StringValue(initial_value)); 1008 base::StringValue(initial_value));
967 } 1009 }
968 1010
969 ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType( 1011 ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType(
970 const std::string& username) const { 1012 const std::string& username) const {
971 return delegate_->GetAuthType(username); 1013 if (user_auth_type_map_.find(username) == user_auth_type_map_.end())
1014 return OFFLINE_PASSWORD;
1015 return user_auth_type_map_.find(username)->second;
972 } 1016 }
973 1017
974 void SigninScreenHandler::Unlock(const std::string& user_email) { 1018 void SigninScreenHandler::Unlock(const std::string& user_email) {
975 DCHECK(ScreenLocker::default_screen_locker()); 1019 DCHECK(ScreenLocker::default_screen_locker());
976 ScreenLocker::Hide(); 1020 ScreenLocker::Hide();
977 } 1021 }
978 1022
979 void SigninScreenHandler::OnDnsCleared() { 1023 void SigninScreenHandler::OnDnsCleared() {
980 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1024 DCHECK_CURRENTLY_ON(BrowserThread::UI);
981 dns_clear_task_running_ = false; 1025 dns_clear_task_running_ = false;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 } 1311 }
1268 } 1312 }
1269 1313
1270 void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() { 1314 void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() {
1271 policy::BrowserPolicyConnectorChromeOS* connector = 1315 policy::BrowserPolicyConnectorChromeOS* connector =
1272 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 1316 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1273 if (delegate_ && !connector->IsEnterpriseManaged()) 1317 if (delegate_ && !connector->IsEnterpriseManaged())
1274 delegate_->ShowKioskAutolaunchScreen(); 1318 delegate_->ShowKioskAutolaunchScreen();
1275 } 1319 }
1276 1320
1277 void SigninScreenHandler::LoadUsers(const base::ListValue& users_list, 1321 void SigninScreenHandler::FillUserDictionary(
1278 bool animated, 1322 User* user,
1279 bool showGuest) { 1323 bool is_owner,
1280 CallJS("login.AccountPickerScreen.loadUsers", 1324 bool is_signin_to_add,
1281 users_list, 1325 ScreenlockBridge::LockHandler::AuthType auth_type,
1282 animated, 1326 base::DictionaryValue* user_dict) {
1327 const std::string& email = user->email();
1328 const bool is_public_account =
1329 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
1330 const bool is_locally_managed_user =
1331 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
1332
1333 user_dict->SetString(kKeyUsername, email);
1334 user_dict->SetString(kKeyEmailAddress, user->display_email());
1335 user_dict->SetString(kKeyDisplayName, user->GetDisplayName());
1336 user_dict->SetBoolean(kKeyPublicAccount, is_public_account);
1337 user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user);
1338 user_dict->SetInteger(kKeyInitialAuthType, auth_type);
1339 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in());
1340 user_dict->SetBoolean(kKeyIsOwner, is_owner);
1341
1342 // Fill in multi-profiles related fields.
1343 if (is_signin_to_add) {
1344 MultiProfileUserController* multi_profile_user_controller =
1345 UserManager::Get()->GetMultiProfileUserController();
1346 std::string behavior = multi_profile_user_controller->
1347 GetCachedValue(user->email());
1348 user_dict->SetBoolean(kKeyMultiProfilesAllowed,
1349 multi_profile_user_controller->IsUserAllowedInSession(email) ==
1350 MultiProfileUserController::ALLOWED);
1351 user_dict->SetString(kKeyMultiProfilesPolicy, behavior);
1352 } else {
1353 user_dict->SetBoolean(kKeyMultiProfilesAllowed, true);
1354 }
1355
1356 if (is_public_account) {
1357 policy::BrowserPolicyConnectorChromeOS* policy_connector =
1358 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1359
1360 if (policy_connector->IsEnterpriseManaged()) {
1361 user_dict->SetString(kKeyEnterpriseDomain,
1362 policy_connector->GetEnterpriseDomain());
1363 }
1364 }
1365 }
1366
1367 void SigninScreenHandler::SendUserList(bool animated) {
1368 if (!delegate_)
1369 return;
1370 TRACE_EVENT_ASYNC_STEP_INTO0("ui",
1371 "ShowLoginWebUI",
1372 LoginDisplayHostImpl::kShowLoginWebUIid,
1373 "SendUserList");
1374 BootTimesLoader::Get()->RecordCurrentStats("login-send-user-list");
1375
1376 base::ListValue users_list;
1377 const UserList& users = delegate_->GetUsers();
1378
1379 // TODO(nkostylev): Move to a separate method in UserManager.
1380 // http://crbug.com/230852
1381 bool is_signin_to_add = LoginDisplayHostImpl::default_host() &&
1382 UserManager::Get()->IsUserLoggedIn();
1383
1384 user_auth_type_map_.clear();
1385
1386 bool single_user = users.size() == 1;
1387 std::string owner;
1388 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
1389 bool has_owner = owner.size() > 0;
1390 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers;
1391 size_t non_owner_count = 0;
1392 policy::BrowserPolicyConnectorChromeOS* connector =
1393 g_browser_process->platform_part()->
1394 browser_policy_connector_chromeos();
1395 bool is_enterprise_managed = connector->IsEnterpriseManaged();
1396
1397
1398 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
1399 const std::string& email = (*it)->email();
1400 bool is_owner = (email == owner);
1401 bool is_public_account =
1402 ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT);
1403
1404 if ((is_public_account && !is_signin_to_add) ||
1405 is_owner ||
1406 (!is_public_account && non_owner_count < max_non_owner_users)) {
1407 AuthType initial_auth_type =
1408 ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN : OFFLINE_PASSWORD;
1409 user_auth_type_map_[email] = initial_auth_type;
1410
1411 base::DictionaryValue* user_dict = new base::DictionaryValue();
1412 FillUserDictionary(
1413 *it, is_owner, is_signin_to_add, initial_auth_type, user_dict);
1414 bool signed_in = (*it)->is_logged_in();
1415 // Single user check here is necessary because owner info might not be
1416 // available when running into login screen on first boot.
1417 // See http://crosbug.com/12723
1418 bool can_remove_user = ((!single_user || is_enterprise_managed) &&
1419 !email.empty() && !is_owner && !is_public_account &&
1420 !signed_in && !is_signin_to_add);
1421 user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
1422
1423 if (!is_owner)
1424 ++non_owner_count;
1425 if (is_owner && users_list.GetSize() > kMaxUsers) {
1426 // Owner is always in the list.
1427 users_list.Insert(kMaxUsers - 1, user_dict);
1428 } else {
1429 users_list.Append(user_dict);
1430 }
1431 }
1432 }
1433 while (users_list.GetSize() > kMaxUsers)
1434 users_list.Remove(kMaxUsers, NULL);
1435
1436 CallJS("login.AccountPickerScreen.loadUsers", users_list, animated,
1283 delegate_->IsShowGuest()); 1437 delegate_->IsShowGuest());
1284 } 1438 }
1285 1439
1286 void SigninScreenHandler::HandleAccountPickerReady() { 1440 void SigninScreenHandler::HandleAccountPickerReady() {
1287 VLOG(0) << "Login WebUI >> AccountPickerReady"; 1441 VLOG(0) << "Login WebUI >> AccountPickerReady";
1288 1442
1289 if (delegate_ && !ScreenLocker::default_screen_locker() && 1443 if (delegate_ && !ScreenLocker::default_screen_locker() &&
1290 !chromeos::IsMachineHWIDCorrect() && 1444 !chromeos::IsMachineHWIDCorrect() &&
1291 !oobe_ui_) { 1445 !oobe_ui_) {
1292 delegate_->ShowWrongHWIDScreen(); 1446 delegate_->ShowWrongHWIDScreen();
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 return gaia_screen_handler_->frame_error(); 1816 return gaia_screen_handler_->frame_error();
1663 } 1817 }
1664 1818
1665 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { 1819 void SigninScreenHandler::OnCapsLockChanged(bool enabled) {
1666 caps_lock_enabled_ = enabled; 1820 caps_lock_enabled_ = enabled;
1667 if (page_is_ready()) 1821 if (page_is_ready())
1668 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); 1822 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_);
1669 } 1823 }
1670 1824
1671 } // namespace chromeos 1825 } // namespace chromeos
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698