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

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

Issue 319273002: Revert 275550 "Revert 275046 "ChromeOS login webui refactoring: ..." (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
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
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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 show_on_init_ = true; 466 show_on_init_ = true;
512 return; 467 return;
513 } 468 }
514 469
515 if (oobe_ui_) { 470 if (oobe_ui_) {
516 // Shows new user sign-in for OOBE. 471 // Shows new user sign-in for OOBE.
517 OnShowAddUser(email_); 472 OnShowAddUser(email_);
518 } else { 473 } else {
519 // Populates account picker. Animation is turned off for now until we 474 // Populates account picker. Animation is turned off for now until we
520 // figure out how to make it fast enough. 475 // figure out how to make it fast enough.
521 SendUserList(false); 476 delegate_->HandleGetUsers();
522 477
523 // Reset Caps Lock state when login screen is shown. 478 // Reset Caps Lock state when login screen is shown.
524 input_method::InputMethodManager::Get() 479 input_method::InputMethodManager::Get()
525 ->GetImeKeyboard() 480 ->GetImeKeyboard()
526 ->SetCapsLockEnabled(false); 481 ->SetCapsLockEnabled(false);
527 482
528 base::DictionaryValue params; 483 base::DictionaryValue params;
529 params.SetBoolean("disableAddUser", AllWhitelistedUsersPresent()); 484 params.SetBoolean("disableAddUser", AllWhitelistedUsersPresent());
530 UpdateUIState(UI_STATE_ACCOUNT_PICKER, &params); 485 UpdateUIState(UI_STATE_ACCOUNT_PICKER, &params);
531 } 486 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // This message is sent by the kiosk app menu, but is handled here 769 // This message is sent by the kiosk app menu, but is handled here
815 // so we can tell the delegate to launch the app. 770 // so we can tell the delegate to launch the app.
816 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); 771 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp);
817 } 772 }
818 773
819 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { 774 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
820 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); 775 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
821 } 776 }
822 777
823 void SigninScreenHandler::HandleGetUsers() { 778 void SigninScreenHandler::HandleGetUsers() {
824 SendUserList(false); 779 if (delegate_)
780 delegate_->HandleGetUsers();
825 } 781 }
826 782
827 void SigninScreenHandler::ClearAndEnablePassword() { 783 void SigninScreenHandler::ClearAndEnablePassword() {
828 core_oobe_actor_->ResetSignInUI(false); 784 core_oobe_actor_->ResetSignInUI(false);
829 } 785 }
830 786
831 void SigninScreenHandler::ClearUserPodPassword() { 787 void SigninScreenHandler::ClearUserPodPassword() {
832 core_oobe_actor_->ClearUserPodPassword(); 788 core_oobe_actor_->ClearUserPodPassword();
833 } 789 }
834 790
(...skipping 17 matching lines...) Expand all
852 // preferences update would be picked up next time it will be shown. 808 // preferences update would be picked up next time it will be shown.
853 if (!webui_visible_) { 809 if (!webui_visible_) {
854 LOG(WARNING) << "Login UI is not active - postponed prefs change."; 810 LOG(WARNING) << "Login UI is not active - postponed prefs change.";
855 preferences_changed_delayed_ = true; 811 preferences_changed_delayed_ = true;
856 return; 812 return;
857 } 813 }
858 814
859 if (delegate_ && !delegate_->IsShowUsers()) { 815 if (delegate_ && !delegate_->IsShowUsers()) {
860 HandleShowAddUser(NULL); 816 HandleShowAddUser(NULL);
861 } else { 817 } else {
862 SendUserList(false); 818 if (delegate_)
819 delegate_->HandleGetUsers();
863 UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL); 820 UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL);
864 } 821 }
865 preferences_changed_delayed_ = false; 822 preferences_changed_delayed_ = false;
866 } 823 }
867 824
868 void SigninScreenHandler::ResetSigninScreenHandlerDelegate() { 825 void SigninScreenHandler::ResetSigninScreenHandlerDelegate() {
869 SetDelegate(NULL); 826 SetDelegate(NULL);
870 } 827 }
871 828
872 void SigninScreenHandler::ShowError(int login_attempts, 829 void SigninScreenHandler::ShowError(int login_attempts,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 951
995 void SigninScreenHandler::EnableInput() { 952 void SigninScreenHandler::EnableInput() {
996 // Only for lock screen at the moment. 953 // Only for lock screen at the moment.
997 ScreenLocker::default_screen_locker()->EnableInput(); 954 ScreenLocker::default_screen_locker()->EnableInput();
998 } 955 }
999 956
1000 void SigninScreenHandler::SetAuthType( 957 void SigninScreenHandler::SetAuthType(
1001 const std::string& username, 958 const std::string& username,
1002 ScreenlockBridge::LockHandler::AuthType auth_type, 959 ScreenlockBridge::LockHandler::AuthType auth_type,
1003 const std::string& initial_value) { 960 const std::string& initial_value) {
1004 user_auth_type_map_[username] = auth_type; 961 delegate_->SetAuthType(username, auth_type);
962
1005 CallJS("login.AccountPickerScreen.setAuthType", 963 CallJS("login.AccountPickerScreen.setAuthType",
1006 username, 964 username,
1007 static_cast<int>(auth_type), 965 static_cast<int>(auth_type),
1008 base::StringValue(initial_value)); 966 base::StringValue(initial_value));
1009 } 967 }
1010 968
1011 ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType( 969 ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType(
1012 const std::string& username) const { 970 const std::string& username) const {
1013 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) 971 return delegate_->GetAuthType(username);
1014 return OFFLINE_PASSWORD;
1015 return user_auth_type_map_.find(username)->second;
1016 } 972 }
1017 973
1018 void SigninScreenHandler::Unlock(const std::string& user_email) { 974 void SigninScreenHandler::Unlock(const std::string& user_email) {
1019 DCHECK(ScreenLocker::default_screen_locker()); 975 DCHECK(ScreenLocker::default_screen_locker());
1020 ScreenLocker::Hide(); 976 ScreenLocker::Hide();
1021 } 977 }
1022 978
1023 void SigninScreenHandler::OnDnsCleared() { 979 void SigninScreenHandler::OnDnsCleared() {
1024 DCHECK_CURRENTLY_ON(BrowserThread::UI); 980 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1025 dns_clear_task_running_ = false; 981 dns_clear_task_running_ = false;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 } 1267 }
1312 } 1268 }
1313 1269
1314 void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() { 1270 void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() {
1315 policy::BrowserPolicyConnectorChromeOS* connector = 1271 policy::BrowserPolicyConnectorChromeOS* connector =
1316 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 1272 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1317 if (delegate_ && !connector->IsEnterpriseManaged()) 1273 if (delegate_ && !connector->IsEnterpriseManaged())
1318 delegate_->ShowKioskAutolaunchScreen(); 1274 delegate_->ShowKioskAutolaunchScreen();
1319 } 1275 }
1320 1276
1321 void SigninScreenHandler::FillUserDictionary( 1277 void SigninScreenHandler::LoadUsers(const base::ListValue& users_list,
1322 User* user, 1278 bool animated,
1323 bool is_owner, 1279 bool showGuest) {
1324 bool is_signin_to_add, 1280 CallJS("login.AccountPickerScreen.loadUsers",
1325 ScreenlockBridge::LockHandler::AuthType auth_type, 1281 users_list,
1326 base::DictionaryValue* user_dict) { 1282 animated,
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,
1437 delegate_->IsShowGuest()); 1283 delegate_->IsShowGuest());
1438 } 1284 }
1439 1285
1440 void SigninScreenHandler::HandleAccountPickerReady() { 1286 void SigninScreenHandler::HandleAccountPickerReady() {
1441 VLOG(0) << "Login WebUI >> AccountPickerReady"; 1287 VLOG(0) << "Login WebUI >> AccountPickerReady";
1442 1288
1443 if (delegate_ && !ScreenLocker::default_screen_locker() && 1289 if (delegate_ && !ScreenLocker::default_screen_locker() &&
1444 !chromeos::IsMachineHWIDCorrect() && 1290 !chromeos::IsMachineHWIDCorrect() &&
1445 !oobe_ui_) { 1291 !oobe_ui_) {
1446 delegate_->ShowWrongHWIDScreen(); 1292 delegate_->ShowWrongHWIDScreen();
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 return gaia_screen_handler_->frame_error(); 1662 return gaia_screen_handler_->frame_error();
1817 } 1663 }
1818 1664
1819 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { 1665 void SigninScreenHandler::OnCapsLockChanged(bool enabled) {
1820 caps_lock_enabled_ = enabled; 1666 caps_lock_enabled_ = enabled;
1821 if (page_is_ready()) 1667 if (page_is_ready())
1822 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); 1668 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_);
1823 } 1669 }
1824 1670
1825 } // namespace chromeos 1671 } // 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