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

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc

Issue 1344443002: Implement new password separated sign in flow for chrome desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 2 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
OLDNEW
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
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
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 (!auth_code_.empty()) {
299 session_index, signin_scoped_device_id); 303 gaia_auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId(
304 auth_code, signin_scoped_device_id);
305 } else {
306 DCHECK(!session_index_.empty());
307 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId(
308 session_index_, signin_scoped_device_id);
309 }
300 } 310 }
301 311
302 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { 312 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) {
303 content::WebContents* contents = NULL; 313 content::WebContents* contents = NULL;
304 Browser* browser = NULL; 314 Browser* browser = NULL;
305 if (handler_) { 315 if (handler_) {
306 contents = handler_->web_ui()->GetWebContents(); 316 contents = handler_->web_ui()->GetWebContents();
307 browser = handler_->GetDesktopBrowser(); 317 browser = handler_->GetDesktopBrowser();
308 } 318 }
309 319
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 } 603 }
594 } 604 }
595 605
596 return true; 606 return true;
597 } 607 }
598 608
599 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { 609 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
600 params.SetString("service", "chromiumsync"); 610 params.SetString("service", "chromiumsync");
601 611
602 content::WebContents* contents = web_ui()->GetWebContents(); 612 content::WebContents* contents = web_ui()->GetWebContents();
613 const GURL& current_url = contents->GetURL();
614 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
615
616 std::string is_constrained;
617 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
618
619 // Use new embedded flow if in constrained window.
620 if (is_constrained == "1") {
621 const bool is_new_gaia_flow = switches::UsePasswordSeparatedSigninFlow();
622 const GURL url = is_new_gaia_flow
623 ? GaiaUrls::GetInstance()->embedded_signin_url()
624 : GaiaUrls::GetInstance()->password_combined_embedded_signin_url();
625 params.SetBoolean("isNewGaiaFlow", is_new_gaia_flow);
626 params.SetString("clientId",
627 GaiaUrls::GetInstance()->oauth2_chrome_client_id());
628 params.SetString("gaiaPath", url.path().substr(1));
629
630 std::string flow;
631 switch (source) {
632 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT:
633 flow = "addaccount";
634 break;
635 case signin_metrics::SOURCE_REAUTH:
636 flow = "reauth";
637 break;
638 default:
639 flow = "signin";
640 break;
641 }
642 params.SetString("flow", flow);
643 }
644
603 content::WebContentsObserver::Observe(contents); 645 content::WebContentsObserver::Observe(contents);
604 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); 646 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN);
605 } 647 }
606 648
607 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { 649 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
608 content::WebContents* contents = web_ui()->GetWebContents(); 650 content::WebContents* contents = web_ui()->GetWebContents();
609 const GURL& current_url = contents->GetURL(); 651 const GURL& current_url = contents->GetURL();
610 652
611 const base::DictionaryValue* dict = NULL; 653 const base::DictionaryValue* dict = NULL;
612 args->GetDictionary(0, &dict); 654 args->GetDictionary(0, &dict);
(...skipping 18 matching lines...) Expand all
631 673
632 base::string16 password_string16; 674 base::string16 password_string16;
633 dict->GetString("password", &password_string16); 675 dict->GetString("password", &password_string16);
634 std::string password(base::UTF16ToASCII(password_string16)); 676 std::string password(base::UTF16ToASCII(password_string16));
635 677
636 base::string16 gaia_id_string16; 678 base::string16 gaia_id_string16;
637 dict->GetString("gaiaId", &gaia_id_string16); 679 dict->GetString("gaiaId", &gaia_id_string16);
638 DCHECK(!gaia_id_string16.empty()); 680 DCHECK(!gaia_id_string16.empty());
639 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); 681 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16);
640 682
683 std::string is_constrained;
684 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
685 const bool is_password_separated_signin_flow = is_constrained == "1" &&
686 switches::UsePasswordSeparatedSigninFlow();
687
641 base::string16 session_index_string16; 688 base::string16 session_index_string16;
642 dict->GetString("sessionIndex", &session_index_string16); 689 dict->GetString("sessionIndex", &session_index_string16);
643 std::string session_index = base::UTF16ToASCII(session_index_string16); 690 std::string session_index = base::UTF16ToASCII(session_index_string16);
644 DCHECK(!session_index.empty()); 691 DCHECK(is_password_separated_signin_flow || !session_index.empty());
692
693 base::string16 auth_code_string16;
694 dict->GetString("authCode", &auth_code_string16);
695 std::string auth_code = base::UTF16ToASCII(auth_code_string16);
696 DCHECK(!is_password_separated_signin_flow || !auth_code.empty());
645 697
646 bool choose_what_to_sync = false; 698 bool choose_what_to_sync = false;
647 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); 699 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync);
648 700
649 content::StoragePartition* partition = 701 content::StoragePartition* partition =
650 content::BrowserContext::GetStoragePartitionForSite( 702 content::BrowserContext::GetStoragePartitionForSite(
651 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); 703 contents->GetBrowserContext(), signin::GetSigninPartitionURL());
652 704
653 // If this was called from the user manager to reauthenticate the profile, 705 // 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 706 // 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 707 // find the right profile to reauthenticate. Otherwise the profile can be
656 // taken from web_ui(). 708 // taken from web_ui().
657 Profile* profile = Profile::FromWebUI(web_ui()); 709 Profile* profile = Profile::FromWebUI(web_ui());
658 if (profile->GetOriginalProfile()->IsSystemProfile()) { 710 if (profile->GetOriginalProfile()->IsSystemProfile()) {
659 // Switch to the profile and finish the login. Don't pass a handler pointer 711 // Switch to the profile and finish the login. Don't pass a handler pointer
660 // since it will be destroyed before the callback runs. 712 // since it will be destroyed before the callback runs.
661 ProfileManager* manager = g_browser_process->profile_manager(); 713 ProfileManager* manager = g_browser_process->profile_manager();
662 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email); 714 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email);
663 if (!path.empty()) { 715 if (!path.empty()) {
664 FinishCompleteLoginParams params(nullptr, partition, current_url, path, 716 FinishCompleteLoginParams params(nullptr, partition, current_url, path,
665 confirm_untrusted_signin_, email, 717 confirm_untrusted_signin_, email,
666 gaia_id, password, session_index, 718 gaia_id, password, session_index,
667 choose_what_to_sync); 719 auth_code, choose_what_to_sync);
668 ProfileManager::CreateCallback callback = base::Bind( 720 ProfileManager::CreateCallback callback = base::Bind(
669 &InlineLoginHandlerImpl::FinishCompleteLogin, params); 721 &InlineLoginHandlerImpl::FinishCompleteLogin, params);
670 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, 722 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true,
671 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK); 723 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK);
672 } 724 }
673 } else { 725 } else {
674 FinishCompleteLogin( 726 FinishCompleteLogin(
675 FinishCompleteLoginParams(this, partition, current_url, 727 FinishCompleteLoginParams(this, partition, current_url,
676 base::FilePath(), confirm_untrusted_signin_, 728 base::FilePath(), confirm_untrusted_signin_,
677 email, gaia_id, password, session_index, 729 email, gaia_id, password, session_index,
678 choose_what_to_sync), 730 auth_code, choose_what_to_sync),
679 profile, 731 profile,
680 Profile::CREATE_STATUS_CREATED); 732 Profile::CREATE_STATUS_CREATED);
681 } 733 }
682 } 734 }
683 735
684 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( 736 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams(
685 InlineLoginHandlerImpl* handler, 737 InlineLoginHandlerImpl* handler,
686 content::StoragePartition* partition, 738 content::StoragePartition* partition,
687 const GURL& url, 739 const GURL& url,
688 const base::FilePath& profile_path, 740 const base::FilePath& profile_path,
689 bool confirm_untrusted_signin, 741 bool confirm_untrusted_signin,
690 const std::string& email, 742 const std::string& email,
691 const std::string& gaia_id, 743 const std::string& gaia_id,
692 const std::string& password, 744 const std::string& password,
693 const std::string& session_index, 745 const std::string& session_index,
746 const std::string& auth_code,
694 bool choose_what_to_sync) 747 bool choose_what_to_sync)
695 : handler(handler), 748 : handler(handler),
696 partition(partition), 749 partition(partition),
697 url(url), 750 url(url),
698 profile_path(profile_path), 751 profile_path(profile_path),
699 confirm_untrusted_signin(confirm_untrusted_signin), 752 confirm_untrusted_signin(confirm_untrusted_signin),
700 email(email), 753 email(email),
701 gaia_id(gaia_id), 754 gaia_id(gaia_id),
702 password(password), 755 password(password),
703 session_index(session_index), 756 session_index(session_index),
757 auth_code(auth_code),
704 choose_what_to_sync(choose_what_to_sync) {} 758 choose_what_to_sync(choose_what_to_sync) {}
705 759
706 InlineLoginHandlerImpl:: 760 InlineLoginHandlerImpl::
707 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} 761 FinishCompleteLoginParams::~FinishCompleteLoginParams() {}
708 762
709 // static 763 // static
710 void InlineLoginHandlerImpl::FinishCompleteLogin( 764 void InlineLoginHandlerImpl::FinishCompleteLogin(
711 const FinishCompleteLoginParams& params, 765 const FinishCompleteLoginParams& params,
712 Profile* profile, 766 Profile* profile,
713 Profile::CreateStatus status) { 767 Profile::CreateStatus status) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 signin_client->GetSigninScopedDeviceId(); 831 signin_client->GetSigninScopedDeviceId();
778 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; 832 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr;
779 if (params.handler) 833 if (params.handler)
780 handler_weak_ptr = params.handler->GetWeakPtr(); 834 handler_weak_ptr = params.handler->GetWeakPtr();
781 835
782 // InlineSigninHelper will delete itself. 836 // InlineSigninHelper will delete itself.
783 new InlineSigninHelper(handler_weak_ptr, 837 new InlineSigninHelper(handler_weak_ptr,
784 params.partition->GetURLRequestContext(), profile, 838 params.partition->GetURLRequestContext(), profile,
785 params.url, 839 params.url,
786 params.email, params.gaia_id, params.password, 840 params.email, params.gaia_id, params.password,
787 params.session_index, signin_scoped_device_id, 841 params.session_index, params.auth_code,
842 signin_scoped_device_id,
788 params.choose_what_to_sync, 843 params.choose_what_to_sync,
789 params.confirm_untrusted_signin); 844 params.confirm_untrusted_signin);
790 845
791 // If opened from user manager to reauthenticate, make sure the user manager 846 // If opened from user manager to reauthenticate, make sure the user manager
792 // is closed and that the profile is marked as unlocked. 847 // is closed and that the profile is marked as unlocked.
793 if (!params.profile_path.empty()) { 848 if (!params.profile_path.empty()) {
794 UserManager::Hide(); 849 UserManager::Hide();
795 ProfileManager* profile_manager = g_browser_process->profile_manager(); 850 ProfileManager* profile_manager = g_browser_process->profile_manager();
796 if (profile_manager) { 851 if (profile_manager) {
797 ProfileAttributesEntry* entry; 852 ProfileAttributesEntry* entry;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 } 923 }
869 } 924 }
870 925
871 if (show_account_management) { 926 if (show_account_management) {
872 browser->window()->ShowAvatarBubbleFromAvatarButton( 927 browser->window()->ShowAvatarBubbleFromAvatarButton(
873 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, 928 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
874 signin::ManageAccountsParams()); 929 signin::ManageAccountsParams());
875 } 930 }
876 } 931 }
877 } 932 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698