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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // User dictionary keys. | 80 // User dictionary keys. |
81 const char kKeyUsername[] = "username"; | 81 const char kKeyUsername[] = "username"; |
82 const char kKeyDisplayName[] = "displayName"; | 82 const char kKeyDisplayName[] = "displayName"; |
83 const char kKeyEmailAddress[] = "emailAddress"; | 83 const char kKeyEmailAddress[] = "emailAddress"; |
84 const char kKeyEnterpriseDomain[] = "enterpriseDomain"; | 84 const char kKeyEnterpriseDomain[] = "enterpriseDomain"; |
85 const char kKeyPublicAccount[] = "publicAccount"; | 85 const char kKeyPublicAccount[] = "publicAccount"; |
86 const char kKeyLocallyManagedUser[] = "locallyManagedUser"; | 86 const char kKeyLocallyManagedUser[] = "locallyManagedUser"; |
87 const char kKeySignedIn[] = "signedIn"; | 87 const char kKeySignedIn[] = "signedIn"; |
88 const char kKeyCanRemove[] = "canRemove"; | 88 const char kKeyCanRemove[] = "canRemove"; |
89 const char kKeyIsOwner[] = "isOwner"; | 89 const char kKeyIsOwner[] = "isOwner"; |
90 const char kKeyForceOnlineSignin[] = "forceOnlineSignin"; | 90 const char kKeyInitialAuthType[] = "initialAuthType"; |
91 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; | 91 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; |
92 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; | 92 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; |
93 | 93 |
94 // Max number of users to show. | 94 // Max number of users to show. |
95 const size_t kMaxUsers = 18; | 95 const size_t kMaxUsers = 18; |
96 | 96 |
97 // Timeout to delay first notification about offline state for a | 97 // Timeout to delay first notification about offline state for a |
98 // current network. | 98 // current network. |
99 const int kOfflineTimeoutSec = 5; | 99 const int kOfflineTimeoutSec = 5; |
100 | 100 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 222 } |
223 manager->ChangeInputMethod(input_method); | 223 manager->ChangeInputMethod(input_method); |
224 | 224 |
225 return true; | 225 return true; |
226 } | 226 } |
227 | 227 |
228 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { | 228 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { |
229 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); | 229 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); |
230 } | 230 } |
231 | 231 |
| 232 bool ShouldForceOnlineSignIn(const User* user) { |
| 233 // Force online sign-in if the user is not logged in and at least one of the |
| 234 // following is true: |
| 235 // * The flag to force online sign-in is set for the user. |
| 236 // * The user's oauth token is invalid. |
| 237 // * The user's oauth token status is unknown. This condition does not apply |
| 238 // to supervised users: A supervised user whose oauth token status is |
| 239 // unknown may still log in offline. The token will be invalidated inside |
| 240 // the session in case it has been revoked. |
| 241 if (user->is_logged_in()) |
| 242 return false; |
| 243 const bool is_locally_managed_user = |
| 244 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED; |
| 245 const User::OAuthTokenStatus token_status = user->oauth_token_status(); |
| 246 return user->force_online_signin() || |
| 247 (token_status == User::OAUTH2_TOKEN_STATUS_INVALID) || |
| 248 (!is_locally_managed_user && |
| 249 token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN); |
| 250 } |
| 251 |
232 } // namespace | 252 } // namespace |
233 | 253 |
234 // LoginScreenContext implementation ------------------------------------------ | 254 // LoginScreenContext implementation ------------------------------------------ |
235 | 255 |
236 LoginScreenContext::LoginScreenContext() { | 256 LoginScreenContext::LoginScreenContext() { |
237 Init(); | 257 Init(); |
238 } | 258 } |
239 | 259 |
240 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { | 260 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { |
241 Init(); | 261 Init(); |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 } | 852 } |
833 | 853 |
834 void SigninScreenHandler::ShowUserPodButton( | 854 void SigninScreenHandler::ShowUserPodButton( |
835 const std::string& username, | 855 const std::string& username, |
836 const std::string& iconURL, | 856 const std::string& iconURL, |
837 const base::Closure& click_callback) { | 857 const base::Closure& click_callback) { |
838 user_pod_button_callback_map_[username] = click_callback; | 858 user_pod_button_callback_map_[username] = click_callback; |
839 CallJS("login.AccountPickerScreen.showUserPodButton", username, iconURL); | 859 CallJS("login.AccountPickerScreen.showUserPodButton", username, iconURL); |
840 } | 860 } |
841 | 861 |
| 862 void SigninScreenHandler::HideUserPodButton(const std::string& username) { |
| 863 CallJS("login.AccountPickerScreen.hideUserPodButton", username); |
| 864 } |
| 865 |
| 866 void SigninScreenHandler::SetAuthType(const std::string& username, |
| 867 LoginDisplay::AuthType auth_type, |
| 868 const std::string& initial_value) { |
| 869 user_auth_type_map_[username] = auth_type; |
| 870 CallJS("login.AccountPickerScreen.setAuthType", |
| 871 username, |
| 872 static_cast<int>(auth_type), |
| 873 base::StringValue(initial_value)); |
| 874 } |
| 875 |
| 876 LoginDisplay::AuthType SigninScreenHandler::GetAuthType( |
| 877 const std::string& username) const { |
| 878 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) |
| 879 return LoginDisplay::OFFLINE_PASSWORD; |
| 880 return user_auth_type_map_.find(username)->second; |
| 881 } |
| 882 |
842 void SigninScreenHandler::ShowError(int login_attempts, | 883 void SigninScreenHandler::ShowError(int login_attempts, |
843 const std::string& error_text, | 884 const std::string& error_text, |
844 const std::string& help_link_text, | 885 const std::string& help_link_text, |
845 HelpAppLauncher::HelpTopic help_topic_id) { | 886 HelpAppLauncher::HelpTopic help_topic_id) { |
846 core_oobe_actor_->ShowSignInError(login_attempts, error_text, help_link_text, | 887 core_oobe_actor_->ShowSignInError(login_attempts, error_text, help_link_text, |
847 help_topic_id); | 888 help_topic_id); |
848 } | 889 } |
849 | 890 |
850 void SigninScreenHandler::ShowErrorScreen(LoginDisplay::SigninError error_id) { | 891 void SigninScreenHandler::ShowErrorScreen(LoginDisplay::SigninError error_id) { |
851 switch (error_id) { | 892 switch (error_id) { |
852 case LoginDisplay::TPM_ERROR: | 893 case LoginDisplay::TPM_ERROR: |
853 core_oobe_actor_->ShowTpmError(); | 894 core_oobe_actor_->ShowTpmError(); |
854 break; | 895 break; |
855 default: | 896 default: |
856 NOTREACHED() << "Unknown sign in error"; | 897 NOTREACHED() << "Unknown sign in error"; |
857 break; | 898 break; |
858 } | 899 } |
859 } | 900 } |
860 | 901 |
861 void SigninScreenHandler::ShowSigninUI(const std::string& email) { | 902 void SigninScreenHandler::ShowSigninUI(const std::string& email) { |
862 core_oobe_actor_->ShowSignInUI(email); | 903 core_oobe_actor_->ShowSignInUI(email); |
863 } | 904 } |
864 | 905 |
865 void SigninScreenHandler::ShowGaiaPasswordChanged(const std::string& username) { | 906 void SigninScreenHandler::ShowGaiaPasswordChanged(const std::string& username) { |
866 email_ = username; | 907 email_ = username; |
867 password_changed_for_.insert(email_); | 908 password_changed_for_.insert(email_); |
868 core_oobe_actor_->ShowSignInUI(email_); | 909 core_oobe_actor_->ShowSignInUI(email_); |
869 CallJS("login.AccountPickerScreen.forceOnlineSignin", email_); | 910 CallJS("login.setAuthType", |
| 911 username, |
| 912 static_cast<int>(LoginDisplay::ONLINE_SIGN_IN), |
| 913 base::StringValue("")); |
870 } | 914 } |
871 | 915 |
872 void SigninScreenHandler::ShowPasswordChangedDialog(bool show_password_error) { | 916 void SigninScreenHandler::ShowPasswordChangedDialog(bool show_password_error) { |
873 core_oobe_actor_->ShowPasswordChangedScreen(show_password_error); | 917 core_oobe_actor_->ShowPasswordChangedScreen(show_password_error); |
874 } | 918 } |
875 | 919 |
876 void SigninScreenHandler::ShowSigninScreenForCreds( | 920 void SigninScreenHandler::ShowSigninScreenForCreds( |
877 const std::string& username, | 921 const std::string& username, |
878 const std::string& password) { | 922 const std::string& password) { |
879 VLOG(2) << "ShowSigninScreenForCreds for user " << username | 923 VLOG(2) << "ShowSigninScreenForCreds for user " << username |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 return; | 1262 return; |
1219 if (!help_app_.get()) | 1263 if (!help_app_.get()) |
1220 help_app_ = new HelpAppLauncher(GetNativeWindow()); | 1264 help_app_ = new HelpAppLauncher(GetNativeWindow()); |
1221 help_app_->ShowHelpTopic( | 1265 help_app_->ShowHelpTopic( |
1222 static_cast<HelpAppLauncher::HelpTopic>(help_topic_id)); | 1266 static_cast<HelpAppLauncher::HelpTopic>(help_topic_id)); |
1223 } | 1267 } |
1224 | 1268 |
1225 void SigninScreenHandler::FillUserDictionary(User* user, | 1269 void SigninScreenHandler::FillUserDictionary(User* user, |
1226 bool is_owner, | 1270 bool is_owner, |
1227 bool is_signin_to_add, | 1271 bool is_signin_to_add, |
| 1272 LoginDisplay::AuthType auth_type, |
1228 base::DictionaryValue* user_dict) { | 1273 base::DictionaryValue* user_dict) { |
1229 const std::string& email = user->email(); | 1274 const std::string& email = user->email(); |
1230 const bool is_public_account = | 1275 const bool is_public_account = |
1231 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; | 1276 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; |
1232 const bool is_locally_managed_user = | 1277 const bool is_locally_managed_user = |
1233 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED; | 1278 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED; |
1234 const User::OAuthTokenStatus token_status = user->oauth_token_status(); | |
1235 | |
1236 // Force online sign-in if at least one of the following is true: | |
1237 // * The flag to force online sign-in is set for the user. | |
1238 // * The user's oauth token is invalid. | |
1239 // * The user's oauth token status is unknown. This condition does not apply | |
1240 // to supervised users: A supervised user whose oauth token status is | |
1241 // unknown may still log in offline. The token will be invalidated inside | |
1242 // the session in case it has been revoked. | |
1243 const bool force_online_signin = | |
1244 user->force_online_signin() || | |
1245 (token_status == User::OAUTH2_TOKEN_STATUS_INVALID) || | |
1246 (!is_locally_managed_user && | |
1247 token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN); | |
1248 | 1279 |
1249 user_dict->SetString(kKeyUsername, email); | 1280 user_dict->SetString(kKeyUsername, email); |
1250 user_dict->SetString(kKeyEmailAddress, user->display_email()); | 1281 user_dict->SetString(kKeyEmailAddress, user->display_email()); |
1251 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); | 1282 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); |
1252 user_dict->SetBoolean(kKeyPublicAccount, is_public_account); | 1283 user_dict->SetBoolean(kKeyPublicAccount, is_public_account); |
1253 user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user); | 1284 user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user); |
1254 user_dict->SetInteger(kKeyForceOnlineSignin, force_online_signin); | 1285 user_dict->SetInteger(kKeyInitialAuthType, auth_type); |
1255 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); | 1286 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); |
1256 user_dict->SetBoolean(kKeyIsOwner, is_owner); | 1287 user_dict->SetBoolean(kKeyIsOwner, is_owner); |
1257 | 1288 |
1258 // Fill in multi-profiles related fields. | 1289 // Fill in multi-profiles related fields. |
1259 if (is_signin_to_add) { | 1290 if (is_signin_to_add) { |
1260 MultiProfileUserController* multi_profile_user_controller = | 1291 MultiProfileUserController* multi_profile_user_controller = |
1261 UserManager::Get()->GetMultiProfileUserController(); | 1292 UserManager::Get()->GetMultiProfileUserController(); |
1262 std::string behavior = multi_profile_user_controller-> | 1293 std::string behavior = multi_profile_user_controller-> |
1263 GetCachedValue(user->email()); | 1294 GetCachedValue(user->email()); |
1264 user_dict->SetBoolean(kKeyMultiProfilesAllowed, | 1295 user_dict->SetBoolean(kKeyMultiProfilesAllowed, |
(...skipping 25 matching lines...) Expand all Loading... |
1290 BootTimesLoader::Get()->RecordCurrentStats("login-send-user-list"); | 1321 BootTimesLoader::Get()->RecordCurrentStats("login-send-user-list"); |
1291 | 1322 |
1292 base::ListValue users_list; | 1323 base::ListValue users_list; |
1293 const UserList& users = delegate_->GetUsers(); | 1324 const UserList& users = delegate_->GetUsers(); |
1294 | 1325 |
1295 // TODO(nkostylev): Move to a separate method in UserManager. | 1326 // TODO(nkostylev): Move to a separate method in UserManager. |
1296 // http://crbug.com/230852 | 1327 // http://crbug.com/230852 |
1297 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && | 1328 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && |
1298 UserManager::Get()->IsUserLoggedIn(); | 1329 UserManager::Get()->IsUserLoggedIn(); |
1299 | 1330 |
| 1331 user_pod_button_callback_map_.clear(); |
| 1332 user_auth_type_map_.clear(); |
| 1333 |
1300 bool single_user = users.size() == 1; | 1334 bool single_user = users.size() == 1; |
1301 std::string owner; | 1335 std::string owner; |
1302 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); | 1336 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); |
1303 bool has_owner = owner.size() > 0; | 1337 bool has_owner = owner.size() > 0; |
1304 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; | 1338 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; |
1305 size_t non_owner_count = 0; | 1339 size_t non_owner_count = 0; |
1306 | 1340 |
1307 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 1341 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
1308 const std::string& email = (*it)->email(); | 1342 const std::string& email = (*it)->email(); |
1309 bool is_owner = (email == owner); | 1343 bool is_owner = (email == owner); |
1310 bool is_public_account = | 1344 bool is_public_account = |
1311 ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT); | 1345 ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT); |
1312 | 1346 |
1313 if (is_public_account || non_owner_count < max_non_owner_users || | 1347 if (is_public_account || non_owner_count < max_non_owner_users || |
1314 is_owner) { | 1348 is_owner) { |
| 1349 LoginDisplay::AuthType initial_auth_type = |
| 1350 ShouldForceOnlineSignIn(*it) ? LoginDisplay::ONLINE_SIGN_IN |
| 1351 : LoginDisplay::OFFLINE_PASSWORD; |
| 1352 user_auth_type_map_[email] = initial_auth_type; |
| 1353 |
1315 base::DictionaryValue* user_dict = new base::DictionaryValue(); | 1354 base::DictionaryValue* user_dict = new base::DictionaryValue(); |
1316 FillUserDictionary(*it, is_owner, is_signin_to_add, user_dict); | 1355 FillUserDictionary( |
| 1356 *it, is_owner, is_signin_to_add, initial_auth_type, user_dict); |
1317 bool signed_in = (*it)->is_logged_in(); | 1357 bool signed_in = (*it)->is_logged_in(); |
1318 // Single user check here is necessary because owner info might not be | 1358 // Single user check here is necessary because owner info might not be |
1319 // available when running into login screen on first boot. | 1359 // available when running into login screen on first boot. |
1320 // See http://crosbug.com/12723 | 1360 // See http://crosbug.com/12723 |
1321 bool can_remove_user = !single_user && !email.empty() && !is_owner && | 1361 bool can_remove_user = !single_user && !email.empty() && !is_owner && |
1322 !is_public_account && !signed_in && !is_signin_to_add; | 1362 !is_public_account && !signed_in && !is_signin_to_add; |
1323 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); | 1363 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); |
1324 | 1364 |
1325 if (!is_owner) | 1365 if (!is_owner) |
1326 ++non_owner_count; | 1366 ++non_owner_count; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 DCHECK(gaia_screen_handler_); | 1762 DCHECK(gaia_screen_handler_); |
1723 return gaia_screen_handler_->frame_state(); | 1763 return gaia_screen_handler_->frame_state(); |
1724 } | 1764 } |
1725 | 1765 |
1726 net::Error SigninScreenHandler::FrameError() const { | 1766 net::Error SigninScreenHandler::FrameError() const { |
1727 DCHECK(gaia_screen_handler_); | 1767 DCHECK(gaia_screen_handler_); |
1728 return gaia_screen_handler_->frame_error(); | 1768 return gaia_screen_handler_->frame_error(); |
1729 } | 1769 } |
1730 | 1770 |
1731 } // namespace chromeos | 1771 } // namespace chromeos |
OLD | NEW |