Chromium Code Reviews| 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/signin/inline_login_handler_impl.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 public: | 221 public: |
| 222 InlineSigninHelper( | 222 InlineSigninHelper( |
| 223 base::WeakPtr<InlineLoginHandlerImpl> handler, | 223 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 224 net::URLRequestContextGetter* getter, | 224 net::URLRequestContextGetter* getter, |
| 225 Profile* profile, | 225 Profile* profile, |
| 226 const GURL& current_url, | 226 const GURL& current_url, |
| 227 const std::string& email, | 227 const std::string& email, |
| 228 const std::string& gaia_id, | 228 const std::string& gaia_id, |
| 229 const std::string& password, | 229 const std::string& password, |
| 230 const std::string& session_index, | 230 const std::string& session_index, |
| 231 const std::string& auth_code, | |
| 231 const std::string& signin_scoped_device_id, | 232 const std::string& signin_scoped_device_id, |
| 232 bool choose_what_to_sync, | 233 bool choose_what_to_sync, |
| 233 bool confirm_untrusted_signin); | 234 bool confirm_untrusted_signin); |
| 234 | 235 |
| 235 private: | 236 private: |
| 236 // Handles cross account sign in error. If the supplied |email| does not match | 237 // Handles cross account sign in error. If the supplied |email| does not match |
| 237 // the last signed in email of the current profile, then Chrome will show a | 238 // the last signed in email of the current profile, then Chrome will show a |
| 238 // confirmation dialog before starting sync. It returns true if there is a | 239 // confirmation dialog before starting sync. It returns true if there is a |
| 239 // cross account error, and false otherwise. | 240 // cross account error, and false otherwise. |
| 240 bool HandleCrossAccountError( | 241 bool HandleCrossAccountError( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 258 override; | 259 override; |
| 259 | 260 |
| 260 GaiaAuthFetcher gaia_auth_fetcher_; | 261 GaiaAuthFetcher gaia_auth_fetcher_; |
| 261 base::WeakPtr<InlineLoginHandlerImpl> handler_; | 262 base::WeakPtr<InlineLoginHandlerImpl> handler_; |
| 262 Profile* profile_; | 263 Profile* profile_; |
| 263 GURL current_url_; | 264 GURL current_url_; |
| 264 std::string email_; | 265 std::string email_; |
| 265 std::string gaia_id_; | 266 std::string gaia_id_; |
| 266 std::string password_; | 267 std::string password_; |
| 267 std::string session_index_; | 268 std::string session_index_; |
| 269 std::string auth_code_; | |
| 268 bool choose_what_to_sync_; | 270 bool choose_what_to_sync_; |
| 269 bool confirm_untrusted_signin_; | 271 bool confirm_untrusted_signin_; |
| 270 | 272 |
| 271 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); | 273 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); |
| 272 }; | 274 }; |
| 273 | 275 |
| 274 InlineSigninHelper::InlineSigninHelper( | 276 InlineSigninHelper::InlineSigninHelper( |
| 275 base::WeakPtr<InlineLoginHandlerImpl> handler, | 277 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 276 net::URLRequestContextGetter* getter, | 278 net::URLRequestContextGetter* getter, |
| 277 Profile* profile, | 279 Profile* profile, |
| 278 const GURL& current_url, | 280 const GURL& current_url, |
| 279 const std::string& email, | 281 const std::string& email, |
| 280 const std::string& gaia_id, | 282 const std::string& gaia_id, |
| 281 const std::string& password, | 283 const std::string& password, |
| 282 const std::string& session_index, | 284 const std::string& session_index, |
| 285 const std::string& auth_code, | |
| 283 const std::string& signin_scoped_device_id, | 286 const std::string& signin_scoped_device_id, |
| 284 bool choose_what_to_sync, | 287 bool choose_what_to_sync, |
| 285 bool confirm_untrusted_signin) | 288 bool confirm_untrusted_signin) |
| 286 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), | 289 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), |
| 287 handler_(handler), | 290 handler_(handler), |
| 288 profile_(profile), | 291 profile_(profile), |
| 289 current_url_(current_url), | 292 current_url_(current_url), |
| 290 email_(email), | 293 email_(email), |
| 291 gaia_id_(gaia_id), | 294 gaia_id_(gaia_id), |
| 292 password_(password), | 295 password_(password), |
| 293 session_index_(session_index), | 296 session_index_(session_index), |
| 297 auth_code_(auth_code), | |
| 294 choose_what_to_sync_(choose_what_to_sync), | 298 choose_what_to_sync_(choose_what_to_sync), |
| 295 confirm_untrusted_signin_(confirm_untrusted_signin) { | 299 confirm_untrusted_signin_(confirm_untrusted_signin) { |
| 296 DCHECK(profile_); | 300 DCHECK(profile_); |
| 297 DCHECK(!email_.empty()); | 301 DCHECK(!email_.empty()); |
| 298 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( | 302 if (switches::UseNewGaiaFlow()) { |
| 299 session_index, signin_scoped_device_id); | 303 DCHECK(!auth_code_.empty()); |
| 304 gaia_auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId( | |
| 305 auth_code, signin_scoped_device_id); | |
| 306 } else { | |
| 307 DCHECK(!session_index_.empty()); | |
| 308 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( | |
| 309 session_index_, signin_scoped_device_id); | |
| 310 } | |
| 300 } | 311 } |
| 301 | 312 |
| 302 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { | 313 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { |
| 303 content::WebContents* contents = NULL; | 314 content::WebContents* contents = NULL; |
| 304 Browser* browser = NULL; | 315 Browser* browser = NULL; |
| 305 if (handler_) { | 316 if (handler_) { |
| 306 contents = handler_->web_ui()->GetWebContents(); | 317 contents = handler_->web_ui()->GetWebContents(); |
| 307 browser = handler_->GetDesktopBrowser(); | 318 browser = handler_->GetDesktopBrowser(); |
| 308 } | 319 } |
| 309 | 320 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 } | 604 } |
| 594 } | 605 } |
| 595 | 606 |
| 596 return true; | 607 return true; |
| 597 } | 608 } |
| 598 | 609 |
| 599 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { | 610 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { |
| 600 params.SetString("service", "chromiumsync"); | 611 params.SetString("service", "chromiumsync"); |
| 601 | 612 |
| 602 content::WebContents* contents = web_ui()->GetWebContents(); | 613 content::WebContents* contents = web_ui()->GetWebContents(); |
| 614 const GURL& current_url = contents->GetURL(); | |
| 615 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); | |
| 616 | |
| 617 std::string is_constrained; | |
| 618 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | |
| 619 | |
| 620 // Use new embedded flow if in constrained window. | |
| 621 if (is_constrained == "1") { | |
| 622 const bool is_new_gaia_flow = switches::UseNewGaiaFlow(); | |
| 623 GURL url = is_new_gaia_flow | |
|
achuithb
2015/09/16 22:53:27
const
Roger Tawa OOO till Jul 10th
2015/09/24 05:54:18
Done.
| |
| 624 ? GaiaUrls::GetInstance()->embedded_signin_url() | |
| 625 : GaiaUrls::GetInstance()->old_embedded_signin_url(); | |
| 626 params.SetBoolean("isNewGaiaFlow", is_new_gaia_flow); | |
| 627 params.SetString("clientId", | |
| 628 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); | |
| 629 params.SetString("gaiaPath", url.path().substr(1)); | |
| 630 | |
| 631 std::string flow; | |
| 632 switch (source) { | |
| 633 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: | |
| 634 flow = "addaccount"; | |
| 635 break; | |
| 636 case signin_metrics::SOURCE_REAUTH: | |
| 637 flow = "reauth"; | |
| 638 break; | |
| 639 default: | |
| 640 flow = "signin"; | |
| 641 break; | |
| 642 } | |
| 643 params.SetString("flow", flow); | |
| 644 } | |
| 645 | |
| 603 content::WebContentsObserver::Observe(contents); | 646 content::WebContentsObserver::Observe(contents); |
| 604 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); | 647 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); |
| 605 } | 648 } |
| 606 | 649 |
| 607 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { | 650 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
| 608 content::WebContents* contents = web_ui()->GetWebContents(); | 651 content::WebContents* contents = web_ui()->GetWebContents(); |
| 609 const GURL& current_url = contents->GetURL(); | 652 const GURL& current_url = contents->GetURL(); |
| 610 | 653 |
| 611 const base::DictionaryValue* dict = NULL; | 654 const base::DictionaryValue* dict = NULL; |
| 612 args->GetDictionary(0, &dict); | 655 args->GetDictionary(0, &dict); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 631 | 674 |
| 632 base::string16 password_string16; | 675 base::string16 password_string16; |
| 633 dict->GetString("password", &password_string16); | 676 dict->GetString("password", &password_string16); |
| 634 std::string password(base::UTF16ToASCII(password_string16)); | 677 std::string password(base::UTF16ToASCII(password_string16)); |
| 635 | 678 |
| 636 base::string16 gaia_id_string16; | 679 base::string16 gaia_id_string16; |
| 637 dict->GetString("gaiaId", &gaia_id_string16); | 680 dict->GetString("gaiaId", &gaia_id_string16); |
| 638 DCHECK(!gaia_id_string16.empty()); | 681 DCHECK(!gaia_id_string16.empty()); |
| 639 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); | 682 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); |
| 640 | 683 |
| 684 const bool is_new_gaia_flow = switches::UseNewGaiaFlow(); | |
| 685 | |
| 641 base::string16 session_index_string16; | 686 base::string16 session_index_string16; |
| 642 dict->GetString("sessionIndex", &session_index_string16); | 687 dict->GetString("sessionIndex", &session_index_string16); |
| 643 std::string session_index = base::UTF16ToASCII(session_index_string16); | 688 std::string session_index = base::UTF16ToASCII(session_index_string16); |
| 644 DCHECK(!session_index.empty()); | 689 DCHECK(is_new_gaia_flow || !session_index.empty()); |
| 690 | |
| 691 base::string16 auth_code_string16; | |
| 692 dict->GetString("authCode", &auth_code_string16); | |
| 693 std::string auth_code = base::UTF16ToASCII(auth_code_string16); | |
| 694 DCHECK(!is_new_gaia_flow || !auth_code.empty()); | |
| 645 | 695 |
| 646 bool choose_what_to_sync = false; | 696 bool choose_what_to_sync = false; |
| 647 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); | 697 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); |
| 648 | 698 |
| 649 content::StoragePartition* partition = | 699 content::StoragePartition* partition = |
| 650 content::BrowserContext::GetStoragePartitionForSite( | 700 content::BrowserContext::GetStoragePartitionForSite( |
| 651 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); | 701 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); |
| 652 | 702 |
| 653 // If this was called from the user manager to reauthenticate the profile, | 703 // If this was called from the user manager to reauthenticate the profile, |
| 654 // the current profile is the system profile. In this case, use the email to | 704 // the current profile is the system profile. In this case, use the email to |
| 655 // find the right profile to reauthenticate. Otherwise the profile can be | 705 // find the right profile to reauthenticate. Otherwise the profile can be |
| 656 // taken from web_ui(). | 706 // taken from web_ui(). |
| 657 Profile* profile = Profile::FromWebUI(web_ui()); | 707 Profile* profile = Profile::FromWebUI(web_ui()); |
| 658 if (profile->GetOriginalProfile()->IsSystemProfile()) { | 708 if (profile->GetOriginalProfile()->IsSystemProfile()) { |
| 659 // Switch to the profile and finish the login. Don't pass a handler pointer | 709 // Switch to the profile and finish the login. Don't pass a handler pointer |
| 660 // since it will be destroyed before the callback runs. | 710 // since it will be destroyed before the callback runs. |
| 661 ProfileManager* manager = g_browser_process->profile_manager(); | 711 ProfileManager* manager = g_browser_process->profile_manager(); |
| 662 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email); | 712 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email); |
| 663 if (!path.empty()) { | 713 if (!path.empty()) { |
| 664 FinishCompleteLoginParams params(nullptr, partition, current_url, path, | 714 FinishCompleteLoginParams params(nullptr, partition, current_url, path, |
| 665 confirm_untrusted_signin_, email, | 715 confirm_untrusted_signin_, email, |
| 666 gaia_id, password, session_index, | 716 gaia_id, password, session_index, |
| 667 choose_what_to_sync); | 717 auth_code, choose_what_to_sync); |
| 668 ProfileManager::CreateCallback callback = base::Bind( | 718 ProfileManager::CreateCallback callback = base::Bind( |
| 669 &InlineLoginHandlerImpl::FinishCompleteLogin, params); | 719 &InlineLoginHandlerImpl::FinishCompleteLogin, params); |
| 670 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, | 720 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, |
| 671 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 721 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 672 } | 722 } |
| 673 } else { | 723 } else { |
| 674 FinishCompleteLogin( | 724 FinishCompleteLogin( |
| 675 FinishCompleteLoginParams(this, partition, current_url, | 725 FinishCompleteLoginParams(this, partition, current_url, |
| 676 base::FilePath(), confirm_untrusted_signin_, | 726 base::FilePath(), confirm_untrusted_signin_, |
| 677 email, gaia_id, password, session_index, | 727 email, gaia_id, password, session_index, |
| 678 choose_what_to_sync), | 728 auth_code, choose_what_to_sync), |
| 679 profile, | 729 profile, |
| 680 Profile::CREATE_STATUS_CREATED); | 730 Profile::CREATE_STATUS_CREATED); |
| 681 } | 731 } |
| 682 } | 732 } |
| 683 | 733 |
| 684 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( | 734 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( |
| 685 InlineLoginHandlerImpl* handler, | 735 InlineLoginHandlerImpl* handler, |
| 686 content::StoragePartition* partition, | 736 content::StoragePartition* partition, |
| 687 const GURL& url, | 737 const GURL& url, |
| 688 const base::FilePath& profile_path, | 738 const base::FilePath& profile_path, |
| 689 bool confirm_untrusted_signin, | 739 bool confirm_untrusted_signin, |
| 690 const std::string& email, | 740 const std::string& email, |
| 691 const std::string& gaia_id, | 741 const std::string& gaia_id, |
| 692 const std::string& password, | 742 const std::string& password, |
| 693 const std::string& session_index, | 743 const std::string& session_index, |
| 744 const std::string& auth_code, | |
| 694 bool choose_what_to_sync) | 745 bool choose_what_to_sync) |
| 695 : handler(handler), | 746 : handler(handler), |
| 696 partition(partition), | 747 partition(partition), |
| 697 url(url), | 748 url(url), |
| 698 profile_path(profile_path), | 749 profile_path(profile_path), |
| 699 confirm_untrusted_signin(confirm_untrusted_signin), | 750 confirm_untrusted_signin(confirm_untrusted_signin), |
| 700 email(email), | 751 email(email), |
| 701 gaia_id(gaia_id), | 752 gaia_id(gaia_id), |
| 702 password(password), | 753 password(password), |
| 703 session_index(session_index), | 754 session_index(session_index), |
| 755 auth_code(auth_code), | |
| 704 choose_what_to_sync(choose_what_to_sync) {} | 756 choose_what_to_sync(choose_what_to_sync) {} |
| 705 | 757 |
| 706 InlineLoginHandlerImpl:: | 758 InlineLoginHandlerImpl:: |
| 707 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} | 759 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} |
| 708 | 760 |
| 709 // static | 761 // static |
| 710 void InlineLoginHandlerImpl::FinishCompleteLogin( | 762 void InlineLoginHandlerImpl::FinishCompleteLogin( |
| 711 const FinishCompleteLoginParams& params, | 763 const FinishCompleteLoginParams& params, |
| 712 Profile* profile, | 764 Profile* profile, |
| 713 Profile::CreateStatus status) { | 765 Profile::CreateStatus status) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 signin_client->GetSigninScopedDeviceId(); | 829 signin_client->GetSigninScopedDeviceId(); |
| 778 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; | 830 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; |
| 779 if (params.handler) | 831 if (params.handler) |
| 780 handler_weak_ptr = params.handler->GetWeakPtr(); | 832 handler_weak_ptr = params.handler->GetWeakPtr(); |
| 781 | 833 |
| 782 // InlineSigninHelper will delete itself. | 834 // InlineSigninHelper will delete itself. |
| 783 new InlineSigninHelper(handler_weak_ptr, | 835 new InlineSigninHelper(handler_weak_ptr, |
| 784 params.partition->GetURLRequestContext(), profile, | 836 params.partition->GetURLRequestContext(), profile, |
| 785 params.url, | 837 params.url, |
| 786 params.email, params.gaia_id, params.password, | 838 params.email, params.gaia_id, params.password, |
| 787 params.session_index, signin_scoped_device_id, | 839 params.session_index, params.auth_code, |
| 840 signin_scoped_device_id, | |
| 788 params.choose_what_to_sync, | 841 params.choose_what_to_sync, |
| 789 params.confirm_untrusted_signin); | 842 params.confirm_untrusted_signin); |
| 790 | 843 |
| 791 // If opened from user manager to reauthenticate, make sure the user manager | 844 // If opened from user manager to reauthenticate, make sure the user manager |
| 792 // is closed and that the profile is marked as unlocked. | 845 // is closed and that the profile is marked as unlocked. |
| 793 if (!params.profile_path.empty()) { | 846 if (!params.profile_path.empty()) { |
| 794 UserManager::Hide(); | 847 UserManager::Hide(); |
| 795 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 848 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 796 if (profile_manager) { | 849 if (profile_manager) { |
| 797 ProfileAttributesEntry* entry; | 850 ProfileAttributesEntry* entry; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 } | 921 } |
| 869 } | 922 } |
| 870 | 923 |
| 871 if (show_account_management) { | 924 if (show_account_management) { |
| 872 browser->window()->ShowAvatarBubbleFromAvatarButton( | 925 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 873 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 926 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
| 874 signin::ManageAccountsParams()); | 927 signin::ManageAccountsParams()); |
| 875 } | 928 } |
| 876 } | 929 } |
| 877 } | 930 } |
| OLD | NEW |