| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/gaia_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_shutdown.h" | 13 #include "chrome/browser/browser_shutdown.h" |
| 13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 14 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 14 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 15 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 15 #include "chrome/browser/chromeos/login/users/user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 17 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 18 #include "chrome/browser/io_thread.h" | 20 #include "chrome/browser/io_thread.h" |
| 19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 21 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 20 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/settings/cros_settings_names.h" | 23 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | 26 #include "google_apis/gaia/gaia_auth_util.h" |
| 25 #include "google_apis/gaia/gaia_switches.h" | 27 #include "google_apis/gaia/gaia_switches.h" |
| 26 #include "google_apis/gaia/gaia_urls.h" | 28 #include "google_apis/gaia/gaia_urls.h" |
| 27 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 30 | 32 |
| 31 using content::BrowserThread; | 33 using content::BrowserThread; |
| 32 | 34 |
| 33 namespace chromeos { | 35 namespace chromeos { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 const char kJsScreenPath[] = "login.GaiaSigninScreen"; | 39 const char kJsScreenPath[] = "login.GaiaSigninScreen"; |
| 38 | 40 |
| 39 void UpdateAuthParams(base::DictionaryValue* params, bool has_users, | 41 void UpdateAuthParams(base::DictionaryValue* params, |
| 42 bool has_users, |
| 40 bool is_enrolling_consumer_management) { | 43 bool is_enrolling_consumer_management) { |
| 41 CrosSettings* cros_settings = CrosSettings::Get(); | 44 CrosSettings* cros_settings = CrosSettings::Get(); |
| 42 bool allow_new_user = true; | 45 bool allow_new_user = true; |
| 43 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 46 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 44 bool allow_guest = true; | 47 bool allow_guest = true; |
| 45 cros_settings->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); | 48 cros_settings->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); |
| 46 // Account creation depends on Guest sign-in (http://crosbug.com/24570). | 49 // Account creation depends on Guest sign-in (http://crosbug.com/24570). |
| 47 params->SetBoolean("createAccount", allow_new_user && allow_guest); | 50 params->SetBoolean("createAccount", allow_new_user && allow_guest); |
| 48 params->SetBoolean("guestSignin", allow_guest); | 51 params->SetBoolean("guestSignin", allow_guest); |
| 49 | 52 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 105 |
| 103 GaiaContext::GaiaContext() | 106 GaiaContext::GaiaContext() |
| 104 : force_reload(false), | 107 : force_reload(false), |
| 105 is_local(false), | 108 is_local(false), |
| 106 password_changed(false), | 109 password_changed(false), |
| 107 show_users(false), | 110 show_users(false), |
| 108 use_offline(false), | 111 use_offline(false), |
| 109 has_users(false) {} | 112 has_users(false) {} |
| 110 | 113 |
| 111 GaiaScreenHandler::GaiaScreenHandler( | 114 GaiaScreenHandler::GaiaScreenHandler( |
| 112 const scoped_refptr<NetworkStateInformer>& network_state_informer) | 115 const scoped_refptr<NetworkStateInformer>& network_state_informer, |
| 116 policy::ConsumerManagementService* consumer_management) |
| 113 : BaseScreenHandler(kJsScreenPath), | 117 : BaseScreenHandler(kJsScreenPath), |
| 114 frame_state_(FRAME_STATE_UNKNOWN), | 118 frame_state_(FRAME_STATE_UNKNOWN), |
| 115 frame_error_(net::OK), | 119 frame_error_(net::OK), |
| 116 network_state_informer_(network_state_informer), | 120 network_state_informer_(network_state_informer), |
| 121 consumer_management_(consumer_management), |
| 117 dns_cleared_(false), | 122 dns_cleared_(false), |
| 118 dns_clear_task_running_(false), | 123 dns_clear_task_running_(false), |
| 119 cookies_cleared_(false), | 124 cookies_cleared_(false), |
| 120 focus_stolen_(false), | 125 focus_stolen_(false), |
| 121 gaia_silent_load_(false), | 126 gaia_silent_load_(false), |
| 122 using_saml_api_(false), | 127 using_saml_api_(false), |
| 123 is_enrolling_consumer_management_(false), | 128 is_enrolling_consumer_management_(false), |
| 124 test_expects_complete_login_(false), | 129 test_expects_complete_login_(false), |
| 125 signin_screen_handler_(NULL), | 130 signin_screen_handler_(NULL), |
| 126 weak_factory_(this) { | 131 weak_factory_(this) { |
| 127 DCHECK(network_state_informer_.get()); | 132 DCHECK(network_state_informer_.get()); |
| 128 } | 133 } |
| 129 | 134 |
| 130 GaiaScreenHandler::~GaiaScreenHandler() { | 135 GaiaScreenHandler::~GaiaScreenHandler() { |
| 131 } | 136 } |
| 132 | 137 |
| 133 void GaiaScreenHandler::LoadGaia(const GaiaContext& context) { | 138 void GaiaScreenHandler::LoadGaia(const GaiaContext& context) { |
| 134 base::DictionaryValue params; | 139 base::DictionaryValue params; |
| 140 const bool is_enrolling_consumer_management = |
| 141 context.is_enrolling_consumer_management; |
| 135 | 142 |
| 136 params.SetBoolean("forceReload", context.force_reload); | 143 params.SetBoolean("forceReload", context.force_reload); |
| 137 params.SetBoolean("isLocal", context.is_local); | 144 params.SetBoolean("isLocal", context.is_local); |
| 138 params.SetBoolean("passwordChanged", context.password_changed); | 145 params.SetBoolean("passwordChanged", context.password_changed); |
| 139 params.SetBoolean("isShowUsers", context.show_users); | 146 params.SetBoolean("isShowUsers", context.show_users); |
| 140 params.SetBoolean("useOffline", context.use_offline); | 147 params.SetBoolean("useOffline", context.use_offline); |
| 141 params.SetString("email", context.email); | 148 params.SetString("email", context.email); |
| 142 params.SetBoolean("isEnrollingConsumerManagement", | 149 params.SetBoolean("isEnrollingConsumerManagement", |
| 143 context.is_enrolling_consumer_management); | 150 is_enrolling_consumer_management); |
| 144 | 151 |
| 145 UpdateAuthParams(¶ms, context.has_users, | 152 UpdateAuthParams(¶ms, |
| 146 context.is_enrolling_consumer_management); | 153 context.has_users, |
| 154 is_enrolling_consumer_management); |
| 147 | 155 |
| 148 if (!context.use_offline) { | 156 if (!context.use_offline) { |
| 149 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 157 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 150 if (!app_locale.empty()) | 158 if (!app_locale.empty()) |
| 151 params.SetString("hl", app_locale); | 159 params.SetString("hl", app_locale); |
| 152 } else { | 160 } else { |
| 153 base::DictionaryValue* localized_strings = new base::DictionaryValue(); | 161 base::DictionaryValue* localized_strings = new base::DictionaryValue(); |
| 154 localized_strings->SetString( | 162 localized_strings->SetString( |
| 155 "stringEmail", l10n_util::GetStringUTF16(IDS_LOGIN_OFFLINE_EMAIL)); | 163 "stringEmail", l10n_util::GetStringUTF16(IDS_LOGIN_OFFLINE_EMAIL)); |
| 156 localized_strings->SetString( | 164 localized_strings->SetString( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 Delegate()->SetDisplayEmail(gaia::SanitizeEmail(email)); | 290 Delegate()->SetDisplayEmail(gaia::SanitizeEmail(email)); |
| 283 UserContext user_context(email); | 291 UserContext user_context(email); |
| 284 user_context.SetKey(Key(password)); | 292 user_context.SetKey(Key(password)); |
| 285 user_context.SetAuthCode(auth_code); | 293 user_context.SetAuthCode(auth_code); |
| 286 Delegate()->CompleteLogin(user_context); | 294 Delegate()->CompleteLogin(user_context); |
| 287 } | 295 } |
| 288 | 296 |
| 289 void GaiaScreenHandler::HandleCompleteLogin(const std::string& typed_email, | 297 void GaiaScreenHandler::HandleCompleteLogin(const std::string& typed_email, |
| 290 const std::string& password, | 298 const std::string& password, |
| 291 bool using_saml) { | 299 bool using_saml) { |
| 292 std::string owner_email = UserManager::Get()->GetOwnerEmail(); | 300 if (!is_enrolling_consumer_management_) { |
| 293 if (is_enrolling_consumer_management_ && typed_email != owner_email) { | 301 DoCompleteLogin(typed_email, password, using_saml); |
| 294 // Show Gaia signin page again since we only allow the owner to sign in. | 302 return; |
| 303 } |
| 304 |
| 305 // Consumer management enrollment is in progress. |
| 306 const std::string owner_email = UserManager::Get()->GetOwnerEmail(); |
| 307 if (typed_email != owner_email) { |
| 308 // Show Gaia sign-in screen again, since we only allow the owner to sign |
| 309 // in. |
| 295 populated_email_ = owner_email; | 310 populated_email_ = owner_email; |
| 296 ShowGaia(is_enrolling_consumer_management_); | 311 ShowGaia(is_enrolling_consumer_management_); |
| 297 return; | 312 return; |
| 298 } | 313 } |
| 299 | 314 |
| 300 if (!Delegate()) | 315 CHECK(consumer_management_); |
| 301 return; | 316 consumer_management_->SetOwner(owner_email, |
| 302 | 317 base::Bind(&GaiaScreenHandler::OnSetOwnerDone, |
| 303 if (using_saml && !using_saml_api_) | 318 weak_factory_.GetWeakPtr(), |
| 304 RecordSAMLScrapingVerificationResultInHistogram(true); | 319 typed_email, |
| 305 | 320 password, |
| 306 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); | 321 using_saml)); |
| 307 Delegate()->SetDisplayEmail(sanitized_email); | |
| 308 UserContext user_context(sanitized_email); | |
| 309 user_context.SetKey(Key(password)); | |
| 310 user_context.SetAuthFlow(using_saml | |
| 311 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML | |
| 312 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | |
| 313 Delegate()->CompleteLogin(user_context); | |
| 314 | |
| 315 if (test_expects_complete_login_) { | |
| 316 VLOG(2) << "Complete test login for " << typed_email | |
| 317 << ", requested=" << test_user_; | |
| 318 | |
| 319 test_expects_complete_login_ = false; | |
| 320 test_user_.clear(); | |
| 321 test_pass_.clear(); | |
| 322 } | |
| 323 } | 322 } |
| 324 | 323 |
| 325 void GaiaScreenHandler::HandleUsingSAMLAPI() { | 324 void GaiaScreenHandler::HandleUsingSAMLAPI() { |
| 326 SetSAMLPrincipalsAPIUsed(true); | 325 SetSAMLPrincipalsAPIUsed(true); |
| 327 } | 326 } |
| 328 | 327 |
| 329 void GaiaScreenHandler::HandleScrapedPasswordCount(int password_count) { | 328 void GaiaScreenHandler::HandleScrapedPasswordCount(int password_count) { |
| 330 SetSAMLPrincipalsAPIUsed(false); | 329 SetSAMLPrincipalsAPIUsed(false); |
| 331 // Use a histogram that has 11 buckets, one for each of the values in [0, 9] | 330 // Use a histogram that has 11 buckets, one for each of the values in [0, 9] |
| 332 // and an overflow bucket at the end. | 331 // and an overflow bucket at the end. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // focus to current pod (see crbug/175243). | 368 // focus to current pod (see crbug/175243). |
| 370 DCHECK(signin_screen_handler_); | 369 DCHECK(signin_screen_handler_); |
| 371 signin_screen_handler_->RefocusCurrentPod(); | 370 signin_screen_handler_->RefocusCurrentPod(); |
| 372 } | 371 } |
| 373 HandleFrameLoadingCompleted(0); | 372 HandleFrameLoadingCompleted(0); |
| 374 | 373 |
| 375 if (test_expects_complete_login_) | 374 if (test_expects_complete_login_) |
| 376 SubmitLoginFormForTest(); | 375 SubmitLoginFormForTest(); |
| 377 } | 376 } |
| 378 | 377 |
| 378 void GaiaScreenHandler::OnSetOwnerDone(const std::string& typed_email, |
| 379 const std::string& password, |
| 380 bool using_saml, |
| 381 bool success) { |
| 382 if (!success) { |
| 383 LOG(ERROR) << "Failed to write owner e-mail to boot lockbox."; |
| 384 CHECK(consumer_management_); |
| 385 consumer_management_->SetEnrollmentState( |
| 386 policy::ConsumerManagementService::ENROLLMENT_BOOT_LOCKBOX_FAILED); |
| 387 // We should continue loggin in the user, as there's not much we can do |
| 388 // here. |
| 389 } |
| 390 DoCompleteLogin(typed_email, password, using_saml); |
| 391 } |
| 392 |
| 393 void GaiaScreenHandler::DoCompleteLogin(const std::string& typed_email, |
| 394 const std::string& password, |
| 395 bool using_saml) { |
| 396 if (!Delegate()) |
| 397 return; |
| 398 |
| 399 if (using_saml && !using_saml_api_) |
| 400 RecordSAMLScrapingVerificationResultInHistogram(true); |
| 401 |
| 402 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); |
| 403 Delegate()->SetDisplayEmail(sanitized_email); |
| 404 UserContext user_context(sanitized_email); |
| 405 user_context.SetKey(Key(password)); |
| 406 user_context.SetAuthFlow(using_saml |
| 407 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML |
| 408 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 409 Delegate()->CompleteLogin(user_context); |
| 410 |
| 411 if (test_expects_complete_login_) { |
| 412 VLOG(2) << "Complete test login for " << typed_email |
| 413 << ", requested=" << test_user_; |
| 414 |
| 415 test_expects_complete_login_ = false; |
| 416 test_user_.clear(); |
| 417 test_pass_.clear(); |
| 418 } |
| 419 } |
| 420 |
| 379 void GaiaScreenHandler::PopulateEmail(const std::string& user_id) { | 421 void GaiaScreenHandler::PopulateEmail(const std::string& user_id) { |
| 380 populated_email_ = user_id; | 422 populated_email_ = user_id; |
| 381 } | 423 } |
| 382 | 424 |
| 383 void GaiaScreenHandler::PasswordChangedFor(const std::string& user_id) { | 425 void GaiaScreenHandler::PasswordChangedFor(const std::string& user_id) { |
| 384 password_changed_for_.insert(user_id); | 426 password_changed_for_.insert(user_id); |
| 385 } | 427 } |
| 386 | 428 |
| 387 void GaiaScreenHandler::StartClearingDnsCache() { | 429 void GaiaScreenHandler::StartClearingDnsCache() { |
| 388 if (dns_clear_task_running_ || !g_browser_process->io_thread()) | 430 if (dns_clear_task_running_ || !g_browser_process->io_thread()) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 | 603 |
| 562 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { | 604 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { |
| 563 DCHECK(signin_screen_handler_); | 605 DCHECK(signin_screen_handler_); |
| 564 return signin_screen_handler_->delegate_; | 606 return signin_screen_handler_->delegate_; |
| 565 } | 607 } |
| 566 | 608 |
| 567 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { | 609 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { |
| 568 signin_screen_handler_ = handler; | 610 signin_screen_handler_ = handler; |
| 569 } | 611 } |
| 570 } // namespace chromeos | 612 } // namespace chromeos |
| OLD | NEW |