| 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/bind.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace | 148 } // namespace |
| 149 | 149 |
| 150 GaiaContext::GaiaContext() | 150 GaiaContext::GaiaContext() |
| 151 : force_reload(false), | 151 : force_reload(false), |
| 152 is_local(false), | 152 is_local(false), |
| 153 password_changed(false), | 153 password_changed(false), |
| 154 show_users(false), | 154 show_users(false), |
| 155 use_offline(false), | 155 use_offline(false), |
| 156 has_users(false), | 156 has_users(false) { |
| 157 session_is_ephemeral(false) { | |
| 158 } | 157 } |
| 159 | 158 |
| 160 GaiaScreenHandler::GaiaScreenHandler( | 159 GaiaScreenHandler::GaiaScreenHandler( |
| 161 CoreOobeActor* core_oobe_actor, | 160 CoreOobeActor* core_oobe_actor, |
| 162 const scoped_refptr<NetworkStateInformer>& network_state_informer, | 161 const scoped_refptr<NetworkStateInformer>& network_state_informer, |
| 163 policy::ConsumerManagementService* consumer_management) | 162 policy::ConsumerManagementService* consumer_management) |
| 164 : BaseScreenHandler(kJsScreenPath), | 163 : BaseScreenHandler(kJsScreenPath), |
| 165 frame_state_(FRAME_STATE_UNKNOWN), | 164 frame_state_(FRAME_STATE_UNKNOWN), |
| 166 frame_error_(net::OK), | 165 frame_error_(net::OK), |
| 167 network_state_informer_(network_state_informer), | 166 network_state_informer_(network_state_informer), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 210 |
| 212 params.SetBoolean("forceReload", context.force_reload); | 211 params.SetBoolean("forceReload", context.force_reload); |
| 213 params.SetBoolean("isLocal", context.is_local); | 212 params.SetBoolean("isLocal", context.is_local); |
| 214 params.SetBoolean("passwordChanged", context.password_changed); | 213 params.SetBoolean("passwordChanged", context.password_changed); |
| 215 params.SetBoolean("isShowUsers", context.show_users); | 214 params.SetBoolean("isShowUsers", context.show_users); |
| 216 params.SetBoolean("useOffline", context.use_offline); | 215 params.SetBoolean("useOffline", context.use_offline); |
| 217 params.SetString("gaiaId", context.gaia_id); | 216 params.SetString("gaiaId", context.gaia_id); |
| 218 params.SetString("email", context.email); | 217 params.SetString("email", context.email); |
| 219 params.SetBoolean("isEnrollingConsumerManagement", | 218 params.SetBoolean("isEnrollingConsumerManagement", |
| 220 is_enrolling_consumer_management); | 219 is_enrolling_consumer_management); |
| 221 if (StartupUtils::IsWebviewSigninEnabled()) { | |
| 222 params.SetString("deviceId", context.device_id); | |
| 223 params.SetBoolean("sessionIsEphemeral", context.session_is_ephemeral); | |
| 224 } | |
| 225 | 220 |
| 226 UpdateAuthParams(¶ms, | 221 UpdateAuthParams(¶ms, |
| 227 context.has_users, | 222 context.has_users, |
| 228 is_enrolling_consumer_management); | 223 is_enrolling_consumer_management); |
| 229 | 224 |
| 230 if (!context.use_offline) { | 225 if (!context.use_offline) { |
| 231 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 226 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 232 if (!app_locale.empty()) | 227 if (!app_locale.empty()) |
| 233 params.SetString("hl", app_locale); | 228 params.SetString("hl", app_locale); |
| 234 } else { | 229 } else { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 params.SetString("clientId", | 326 params.SetString("clientId", |
| 332 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); | 327 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); |
| 333 } | 328 } |
| 334 | 329 |
| 335 frame_state_ = FRAME_STATE_LOADING; | 330 frame_state_ = FRAME_STATE_LOADING; |
| 336 CallJS("loadAuthExtension", params); | 331 CallJS("loadAuthExtension", params); |
| 337 } | 332 } |
| 338 | 333 |
| 339 void GaiaScreenHandler::UpdateGaia(const GaiaContext& context) { | 334 void GaiaScreenHandler::UpdateGaia(const GaiaContext& context) { |
| 340 base::DictionaryValue params; | 335 base::DictionaryValue params; |
| 341 if (StartupUtils::IsWebviewSigninEnabled()) { | |
| 342 params.SetString("deviceId", context.device_id); | |
| 343 } | |
| 344 UpdateAuthParams(¶ms, context.has_users, | 336 UpdateAuthParams(¶ms, context.has_users, |
| 345 context.is_enrolling_consumer_management); | 337 context.is_enrolling_consumer_management); |
| 346 CallJS("updateAuthExtension", params); | 338 CallJS("updateAuthExtension", params); |
| 347 } | 339 } |
| 348 | 340 |
| 349 void GaiaScreenHandler::ReloadGaia(bool force_reload) { | 341 void GaiaScreenHandler::ReloadGaia(bool force_reload) { |
| 350 if (frame_state_ == FRAME_STATE_LOADING && !force_reload) { | 342 if (frame_state_ == FRAME_STATE_LOADING && !force_reload) { |
| 351 VLOG(1) << "Skipping reloading of Gaia since gaia is loading."; | 343 VLOG(1) << "Skipping reloading of Gaia since gaia is loading."; |
| 352 return; | 344 return; |
| 353 } | 345 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 AddCallback("usingSAMLAPI", &GaiaScreenHandler::HandleUsingSAMLAPI); | 423 AddCallback("usingSAMLAPI", &GaiaScreenHandler::HandleUsingSAMLAPI); |
| 432 AddCallback("scrapedPasswordCount", | 424 AddCallback("scrapedPasswordCount", |
| 433 &GaiaScreenHandler::HandleScrapedPasswordCount); | 425 &GaiaScreenHandler::HandleScrapedPasswordCount); |
| 434 AddCallback("scrapedPasswordVerificationFailed", | 426 AddCallback("scrapedPasswordVerificationFailed", |
| 435 &GaiaScreenHandler::HandleScrapedPasswordVerificationFailed); | 427 &GaiaScreenHandler::HandleScrapedPasswordVerificationFailed); |
| 436 AddCallback("loginWebuiReady", &GaiaScreenHandler::HandleGaiaUIReady); | 428 AddCallback("loginWebuiReady", &GaiaScreenHandler::HandleGaiaUIReady); |
| 437 AddCallback("toggleWebviewSignin", | 429 AddCallback("toggleWebviewSignin", |
| 438 &GaiaScreenHandler::HandleToggleWebviewSignin); | 430 &GaiaScreenHandler::HandleToggleWebviewSignin); |
| 439 AddCallback("toggleEasyBootstrap", | 431 AddCallback("toggleEasyBootstrap", |
| 440 &GaiaScreenHandler::HandleToggleEasyBootstrap); | 432 &GaiaScreenHandler::HandleToggleEasyBootstrap); |
| 441 AddCallback("attemptLogin", &GaiaScreenHandler::HandleAttemptLogin); | |
| 442 } | 433 } |
| 443 | 434 |
| 444 void GaiaScreenHandler::HandleFrameLoadingCompleted(int status) { | 435 void GaiaScreenHandler::HandleFrameLoadingCompleted(int status) { |
| 445 const net::Error frame_error = static_cast<net::Error>(-status); | 436 const net::Error frame_error = static_cast<net::Error>(-status); |
| 446 if (frame_error == net::ERR_ABORTED) { | 437 if (frame_error == net::ERR_ABORTED) { |
| 447 LOG(WARNING) << "Ignoring Gaia frame error: " << frame_error; | 438 LOG(WARNING) << "Ignoring Gaia frame error: " << frame_error; |
| 448 return; | 439 return; |
| 449 } | 440 } |
| 450 frame_error_ = frame_error; | 441 frame_error_ = frame_error; |
| 451 if (frame_error == net::OK) { | 442 if (frame_error == net::OK) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 NetworkError::ERROR_REASON_FRAME_ERROR; | 487 NetworkError::ERROR_REASON_FRAME_ERROR; |
| 497 frame_state_ = FRAME_STATE_ERROR; | 488 frame_state_ = FRAME_STATE_ERROR; |
| 498 UpdateState(error_reason); | 489 UpdateState(error_reason); |
| 499 } | 490 } |
| 500 | 491 |
| 501 void GaiaScreenHandler::HandleCompleteAuthentication( | 492 void GaiaScreenHandler::HandleCompleteAuthentication( |
| 502 const std::string& gaia_id, | 493 const std::string& gaia_id, |
| 503 const std::string& email, | 494 const std::string& email, |
| 504 const std::string& password, | 495 const std::string& password, |
| 505 const std::string& auth_code, | 496 const std::string& auth_code, |
| 506 bool using_saml, | 497 bool using_saml) { |
| 507 const std::string& device_id) { | |
| 508 if (!Delegate()) | 498 if (!Delegate()) |
| 509 return; | 499 return; |
| 510 | 500 |
| 511 RecordGAIAFlowTypeHistogram(); | 501 RecordGAIAFlowTypeHistogram(); |
| 512 | 502 |
| 513 DCHECK(!email.empty()); | 503 DCHECK(!email.empty()); |
| 514 DCHECK(!gaia_id.empty()); | 504 DCHECK(!gaia_id.empty()); |
| 515 const std::string sanitized_email = gaia::SanitizeEmail(email); | 505 const std::string sanitized_email = gaia::SanitizeEmail(email); |
| 516 Delegate()->SetDisplayEmail(sanitized_email); | 506 Delegate()->SetDisplayEmail(sanitized_email); |
| 517 UserContext user_context(sanitized_email); | 507 UserContext user_context(sanitized_email); |
| 518 user_context.SetGaiaID(gaia_id); | 508 user_context.SetGaiaID(gaia_id); |
| 519 user_context.SetKey(Key(password)); | 509 user_context.SetKey(Key(password)); |
| 520 user_context.SetAuthCode(auth_code); | 510 user_context.SetAuthCode(auth_code); |
| 521 user_context.SetAuthFlow(using_saml | 511 user_context.SetAuthFlow(using_saml |
| 522 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML | 512 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML |
| 523 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 513 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 524 user_context.SetDeviceId(device_id); | |
| 525 Delegate()->CompleteLogin(user_context); | 514 Delegate()->CompleteLogin(user_context); |
| 526 } | 515 } |
| 527 | 516 |
| 528 void GaiaScreenHandler::HandleCompleteAuthenticationAuthCodeOnly( | 517 void GaiaScreenHandler::HandleCompleteAuthenticationAuthCodeOnly( |
| 529 const std::string& auth_code) { | 518 const std::string& auth_code) { |
| 530 if (!Delegate()) | 519 if (!Delegate()) |
| 531 return; | 520 return; |
| 532 | 521 |
| 533 RecordGAIAFlowTypeHistogram(); | 522 RecordGAIAFlowTypeHistogram(); |
| 534 | 523 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 } | 583 } |
| 595 | 584 |
| 596 void GaiaScreenHandler::HandleToggleEasyBootstrap() { | 585 void GaiaScreenHandler::HandleToggleEasyBootstrap() { |
| 597 use_easy_bootstrap_ = !use_easy_bootstrap_; | 586 use_easy_bootstrap_ = !use_easy_bootstrap_; |
| 598 const bool kForceReload = true; | 587 const bool kForceReload = true; |
| 599 const bool kSilentLoad = true; | 588 const bool kSilentLoad = true; |
| 600 const bool kNoOfflineUI = false; | 589 const bool kNoOfflineUI = false; |
| 601 LoadAuthExtension(kForceReload, kSilentLoad, kNoOfflineUI); | 590 LoadAuthExtension(kForceReload, kSilentLoad, kNoOfflineUI); |
| 602 } | 591 } |
| 603 | 592 |
| 604 void GaiaScreenHandler::HandleAttemptLogin(const std::string& email) { | |
| 605 std::string device_id = | |
| 606 user_manager::UserManager::Get()->GetKnownUserDeviceId( | |
| 607 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email))); | |
| 608 | |
| 609 if (!device_id.empty() && StartupUtils::IsWebviewSigninEnabled()) { | |
| 610 base::DictionaryValue params; | |
| 611 params.SetString("deviceId", device_id); | |
| 612 CallJS("updateDeviceId", params); | |
| 613 } else { | |
| 614 // Mark current temporary device Id as used. | |
| 615 temporary_device_id_ = std::string(); | |
| 616 } | |
| 617 } | |
| 618 | |
| 619 void GaiaScreenHandler::HandleGaiaUIReady() { | 593 void GaiaScreenHandler::HandleGaiaUIReady() { |
| 620 if (focus_stolen_) { | 594 if (focus_stolen_) { |
| 621 // Set focus to the Gaia page. | 595 // Set focus to the Gaia page. |
| 622 // TODO(altimofeev): temporary solution, until focus parameters are | 596 // TODO(altimofeev): temporary solution, until focus parameters are |
| 623 // implemented on the Gaia side. | 597 // implemented on the Gaia side. |
| 624 // Do this only once. Any subsequent call would relod GAIA frame. | 598 // Do this only once. Any subsequent call would relod GAIA frame. |
| 625 focus_stolen_ = false; | 599 focus_stolen_ = false; |
| 626 const char code[] = | 600 const char code[] = |
| 627 "if (typeof gWindowOnLoad != 'undefined') gWindowOnLoad();"; | 601 "if (typeof gWindowOnLoad != 'undefined') gWindowOnLoad();"; |
| 628 content::RenderFrameHost* frame = InlineLoginUI::GetAuthFrame( | 602 content::RenderFrameHost* frame = InlineLoginUI::GetAuthFrame( |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 925 |
| 952 std::string gaia_id; | 926 std::string gaia_id; |
| 953 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) | 927 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) |
| 954 context.gaia_id = gaia_id; | 928 context.gaia_id = gaia_id; |
| 955 | 929 |
| 956 if (Delegate()) { | 930 if (Delegate()) { |
| 957 context.show_users = Delegate()->IsShowUsers(); | 931 context.show_users = Delegate()->IsShowUsers(); |
| 958 context.has_users = !Delegate()->GetUsers().empty(); | 932 context.has_users = !Delegate()->GetUsers().empty(); |
| 959 } | 933 } |
| 960 | 934 |
| 961 if (!context.email.empty()) { | |
| 962 context.device_id = user_manager::UserManager::Get()->GetKnownUserDeviceId( | |
| 963 gaia::CanonicalizeEmail(context.email)); | |
| 964 } | |
| 965 | |
| 966 if (context.device_id.empty()) | |
| 967 context.device_id = GetTemporaryDeviceId(); | |
| 968 | |
| 969 context.session_is_ephemeral = | |
| 970 ChromeUserManager::Get()->AreEphemeralUsersEnabled(); | |
| 971 | |
| 972 populated_email_.clear(); | 935 populated_email_.clear(); |
| 973 | 936 |
| 974 LoadGaia(context); | 937 LoadGaia(context); |
| 975 } | 938 } |
| 976 | 939 |
| 977 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { | 940 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { |
| 978 if (signin_screen_handler_) | 941 if (signin_screen_handler_) |
| 979 signin_screen_handler_->UpdateState(reason); | 942 signin_screen_handler_->UpdateState(reason); |
| 980 } | 943 } |
| 981 | 944 |
| 982 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { | 945 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { |
| 983 DCHECK(signin_screen_handler_); | 946 DCHECK(signin_screen_handler_); |
| 984 return signin_screen_handler_->delegate_; | 947 return signin_screen_handler_->delegate_; |
| 985 } | 948 } |
| 986 | 949 |
| 987 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { | 950 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { |
| 988 signin_screen_handler_ = handler; | 951 signin_screen_handler_ = handler; |
| 989 } | 952 } |
| 990 | 953 |
| 991 std::string GaiaScreenHandler::GetTemporaryDeviceId() { | |
| 992 if (temporary_device_id_.empty()) | |
| 993 temporary_device_id_ = base::GenerateGUID(); | |
| 994 | |
| 995 DCHECK(!temporary_device_id_.empty()); | |
| 996 return temporary_device_id_; | |
| 997 } | |
| 998 | |
| 999 } // namespace chromeos | 954 } // namespace chromeos |
| OLD | NEW |