| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 Profile* profile, | 155 Profile* profile, |
| 156 Profile::CreateStatus create_status, | 156 Profile::CreateStatus create_status, |
| 157 const GURL& current_url, | 157 const GURL& current_url, |
| 158 const std::string& email, | 158 const std::string& email, |
| 159 const std::string& gaia_id, | 159 const std::string& gaia_id, |
| 160 const std::string& password, | 160 const std::string& password, |
| 161 const std::string& session_index, | 161 const std::string& session_index, |
| 162 const std::string& auth_code, | 162 const std::string& auth_code, |
| 163 const std::string& signin_scoped_device_id, | 163 const std::string& signin_scoped_device_id, |
| 164 bool choose_what_to_sync, | 164 bool choose_what_to_sync, |
| 165 bool confirm_untrusted_signin) | 165 bool confirm_untrusted_signin, |
| 166 bool is_force_sign_in_with_usermanager) |
| 166 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), | 167 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), |
| 167 handler_(handler), | 168 handler_(handler), |
| 168 profile_(profile), | 169 profile_(profile), |
| 169 create_status_(create_status), | 170 create_status_(create_status), |
| 170 current_url_(current_url), | 171 current_url_(current_url), |
| 171 email_(email), | 172 email_(email), |
| 172 gaia_id_(gaia_id), | 173 gaia_id_(gaia_id), |
| 173 password_(password), | 174 password_(password), |
| 174 session_index_(session_index), | 175 session_index_(session_index), |
| 175 auth_code_(auth_code), | 176 auth_code_(auth_code), |
| 176 choose_what_to_sync_(choose_what_to_sync), | 177 choose_what_to_sync_(choose_what_to_sync), |
| 177 confirm_untrusted_signin_(confirm_untrusted_signin) { | 178 confirm_untrusted_signin_(confirm_untrusted_signin), |
| 179 is_force_sign_in_with_usermanager_(is_force_sign_in_with_usermanager) { |
| 178 DCHECK(profile_); | 180 DCHECK(profile_); |
| 179 DCHECK(!email_.empty()); | 181 DCHECK(!email_.empty()); |
| 180 if (!auth_code_.empty()) { | 182 if (!auth_code_.empty()) { |
| 181 gaia_auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId( | 183 gaia_auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId( |
| 182 auth_code, signin_scoped_device_id); | 184 auth_code, signin_scoped_device_id); |
| 183 } else { | 185 } else { |
| 184 DCHECK(!session_index_.empty()); | 186 DCHECK(!session_index_.empty()); |
| 185 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( | 187 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( |
| 186 session_index_, signin_scoped_device_id); | 188 session_index_, signin_scoped_device_id); |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 | 191 |
| 190 InlineSigninHelper::~InlineSigninHelper() {} | 192 InlineSigninHelper::~InlineSigninHelper() {} |
| 191 | 193 |
| 192 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { | 194 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { |
| 193 if (signin::IsForceSigninEnabled()) { | 195 if (is_force_sign_in_with_usermanager_) { |
| 194 // With force sign in enabled, the browser window won't be opened until now. | 196 // If user sign in in UserManager with force sign in enabled, the browser |
| 197 // window won't be opened until now. |
| 195 profiles::OpenBrowserWindowForProfile( | 198 profiles::OpenBrowserWindowForProfile( |
| 196 base::Bind(&InlineSigninHelper::OnClientOAuthSuccessAndBrowserOpened, | 199 base::Bind(&InlineSigninHelper::OnClientOAuthSuccessAndBrowserOpened, |
| 197 base::Unretained(this), result), | 200 base::Unretained(this), result), |
| 198 true, false, profile_, create_status_); | 201 true, false, profile_, create_status_); |
| 199 } else { | 202 } else { |
| 200 OnClientOAuthSuccessAndBrowserOpened(result, profile_, create_status_); | 203 OnClientOAuthSuccessAndBrowserOpened(result, profile_, create_status_); |
| 201 } | 204 } |
| 202 } | 205 } |
| 203 | 206 |
| 204 void InlineSigninHelper::OnClientOAuthSuccessAndBrowserOpened( | 207 void InlineSigninHelper::OnClientOAuthSuccessAndBrowserOpened( |
| 205 const ClientOAuthResult& result, | 208 const ClientOAuthResult& result, |
| 206 Profile* profile, | 209 Profile* profile, |
| 207 Profile::CreateStatus status) { | 210 Profile::CreateStatus status) { |
| 208 if (signin::IsForceSigninEnabled()) | 211 if (is_force_sign_in_with_usermanager_) |
| 209 UnlockProfileAndHideLoginUI(profile_->GetPath(), handler_.get()); | 212 UnlockProfileAndHideLoginUI(profile_->GetPath(), handler_.get()); |
| 210 content::WebContents* contents = NULL; | 213 content::WebContents* contents = NULL; |
| 211 Browser* browser = NULL; | 214 Browser* browser = NULL; |
| 212 if (handler_) { | 215 if (handler_) { |
| 213 contents = handler_->web_ui()->GetWebContents(); | 216 contents = handler_->web_ui()->GetWebContents(); |
| 214 browser = handler_->GetDesktopBrowser(); | 217 browser = handler_->GetDesktopBrowser(); |
| 215 } | 218 } |
| 216 | 219 |
| 217 AboutSigninInternals* about_signin_internals = | 220 AboutSigninInternals* about_signin_internals = |
| 218 AboutSigninInternalsFactory::GetForProfile(profile_); | 221 AboutSigninInternalsFactory::GetForProfile(profile_); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 profile_, browser, gaia_id_, email_, password_, refresh_token, | 312 profile_, browser, gaia_id_, email_, password_, refresh_token, |
| 310 profile_mode, start_mode, contents, confirmation_required, current_url, | 313 profile_mode, start_mode, contents, confirmation_required, current_url, |
| 311 continue_url, | 314 continue_url, |
| 312 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | 315 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); |
| 313 } | 316 } |
| 314 | 317 |
| 315 bool InlineSigninHelper::HandleCrossAccountError( | 318 bool InlineSigninHelper::HandleCrossAccountError( |
| 316 const std::string& refresh_token, | 319 const std::string& refresh_token, |
| 317 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | 320 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 318 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 321 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 319 // With force sign in enabled, cross account sign in will be rejected in the | 322 // With force sign in enabled, cross account |
| 320 // early stage so there is no need to show the warning page here. | 323 // sign in will be rejected in the early stage so there is no need to show the |
| 324 // warning page here. |
| 321 if (signin::IsForceSigninEnabled()) | 325 if (signin::IsForceSigninEnabled()) |
| 322 return false; | 326 return false; |
| 323 | 327 |
| 324 std::string last_email = | 328 std::string last_email = |
| 325 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 329 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 326 | 330 |
| 327 // TODO(skym): Warn for high risk upgrade scenario, crbug.com/572754. | 331 // TODO(skym): Warn for high risk upgrade scenario, crbug.com/572754. |
| 328 if (!IsCrossAccountError(profile_, email_, gaia_id_)) | 332 if (!IsCrossAccountError(profile_, email_, gaia_id_)) |
| 329 return false; | 333 return false; |
| 330 | 334 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 642 } |
| 639 if (!path.empty()) { | 643 if (!path.empty()) { |
| 640 signin_metrics::Reason reason = | 644 signin_metrics::Reason reason = |
| 641 signin::GetSigninReasonForPromoURL(current_url); | 645 signin::GetSigninReasonForPromoURL(current_url); |
| 642 // If we are only reauthenticating a profile in the user manager (and not | 646 // If we are only reauthenticating a profile in the user manager (and not |
| 643 // unlocking it), load the profile and finish the login. | 647 // unlocking it), load the profile and finish the login. |
| 644 if (reason == signin_metrics::Reason::REASON_REAUTHENTICATION) { | 648 if (reason == signin_metrics::Reason::REASON_REAUTHENTICATION) { |
| 645 FinishCompleteLoginParams params( | 649 FinishCompleteLoginParams params( |
| 646 this, partition, current_url, base::FilePath(), | 650 this, partition, current_url, base::FilePath(), |
| 647 confirm_untrusted_signin_, email, gaia_id, password, session_index, | 651 confirm_untrusted_signin_, email, gaia_id, password, session_index, |
| 648 auth_code, choose_what_to_sync); | 652 auth_code, choose_what_to_sync, false); |
| 649 ProfileManager::CreateCallback callback = | 653 ProfileManager::CreateCallback callback = |
| 650 base::Bind(&InlineLoginHandlerImpl::FinishCompleteLogin, params); | 654 base::Bind(&InlineLoginHandlerImpl::FinishCompleteLogin, params); |
| 651 profiles::LoadProfileAsync(path, callback); | 655 profiles::LoadProfileAsync(path, callback); |
| 652 } else { | 656 } else { |
| 653 // Otherwise, switch to the profile and finish the login. Pass the | 657 // Otherwise, switch to the profile and finish the login. Pass the |
| 654 // profile path so it can be marked as unlocked. Don't pass a handler | 658 // profile path so it can be marked as unlocked. Don't pass a handler |
| 655 // pointer since it will be destroyed before the callback runs. | 659 // pointer since it will be destroyed before the callback runs. |
| 656 bool is_force_signin_enabled = signin::IsForceSigninEnabled(); | 660 bool is_force_signin_enabled = signin::IsForceSigninEnabled(); |
| 657 InlineLoginHandlerImpl* handler = nullptr; | 661 InlineLoginHandlerImpl* handler = nullptr; |
| 658 if (is_force_signin_enabled) | 662 if (is_force_signin_enabled) |
| 659 handler = this; | 663 handler = this; |
| 660 FinishCompleteLoginParams params(handler, partition, current_url, path, | 664 FinishCompleteLoginParams params( |
| 661 confirm_untrusted_signin_, email, | 665 handler, partition, current_url, path, confirm_untrusted_signin_, |
| 662 gaia_id, password, session_index, | 666 email, gaia_id, password, session_index, auth_code, |
| 663 auth_code, choose_what_to_sync); | 667 choose_what_to_sync, is_force_signin_enabled); |
| 664 ProfileManager::CreateCallback callback = | 668 ProfileManager::CreateCallback callback = |
| 665 base::Bind(&InlineLoginHandlerImpl::FinishCompleteLogin, params); | 669 base::Bind(&InlineLoginHandlerImpl::FinishCompleteLogin, params); |
| 666 if (is_force_signin_enabled) { | 670 if (is_force_signin_enabled) { |
| 667 // Browser window will be opened after ClientOAuthSuccess. | 671 // Browser window will be opened after ClientOAuthSuccess. |
| 668 profiles::LoadProfileAsync(path, callback); | 672 profiles::LoadProfileAsync(path, callback); |
| 669 } else { | 673 } else { |
| 670 profiles::SwitchToProfile(path, true, callback, | 674 profiles::SwitchToProfile(path, true, callback, |
| 671 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 675 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 672 } | 676 } |
| 673 } | 677 } |
| 674 } | 678 } |
| 675 } else { | 679 } else { |
| 676 FinishCompleteLogin( | 680 FinishCompleteLogin( |
| 677 FinishCompleteLoginParams(this, partition, current_url, | 681 FinishCompleteLoginParams(this, partition, current_url, |
| 678 base::FilePath(), confirm_untrusted_signin_, | 682 base::FilePath(), confirm_untrusted_signin_, |
| 679 email, gaia_id, password, session_index, | 683 email, gaia_id, password, session_index, |
| 680 auth_code, choose_what_to_sync), | 684 auth_code, choose_what_to_sync, false), |
| 681 profile, | 685 profile, Profile::CREATE_STATUS_CREATED); |
| 682 Profile::CREATE_STATUS_CREATED); | |
| 683 } | 686 } |
| 684 } | 687 } |
| 685 | 688 |
| 686 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( | 689 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( |
| 687 InlineLoginHandlerImpl* handler, | 690 InlineLoginHandlerImpl* handler, |
| 688 content::StoragePartition* partition, | 691 content::StoragePartition* partition, |
| 689 const GURL& url, | 692 const GURL& url, |
| 690 const base::FilePath& profile_path, | 693 const base::FilePath& profile_path, |
| 691 bool confirm_untrusted_signin, | 694 bool confirm_untrusted_signin, |
| 692 const std::string& email, | 695 const std::string& email, |
| 693 const std::string& gaia_id, | 696 const std::string& gaia_id, |
| 694 const std::string& password, | 697 const std::string& password, |
| 695 const std::string& session_index, | 698 const std::string& session_index, |
| 696 const std::string& auth_code, | 699 const std::string& auth_code, |
| 697 bool choose_what_to_sync) | 700 bool choose_what_to_sync, |
| 701 bool is_force_sign_in_with_usermanager) |
| 698 : handler(handler), | 702 : handler(handler), |
| 699 partition(partition), | 703 partition(partition), |
| 700 url(url), | 704 url(url), |
| 701 profile_path(profile_path), | 705 profile_path(profile_path), |
| 702 confirm_untrusted_signin(confirm_untrusted_signin), | 706 confirm_untrusted_signin(confirm_untrusted_signin), |
| 703 email(email), | 707 email(email), |
| 704 gaia_id(gaia_id), | 708 gaia_id(gaia_id), |
| 705 password(password), | 709 password(password), |
| 706 session_index(session_index), | 710 session_index(session_index), |
| 707 auth_code(auth_code), | 711 auth_code(auth_code), |
| 708 choose_what_to_sync(choose_what_to_sync) {} | 712 choose_what_to_sync(choose_what_to_sync), |
| 713 is_force_sign_in_with_usermanager(is_force_sign_in_with_usermanager) {} |
| 709 | 714 |
| 710 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( | 715 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( |
| 711 const FinishCompleteLoginParams& other) = default; | 716 const FinishCompleteLoginParams& other) = default; |
| 712 | 717 |
| 713 InlineLoginHandlerImpl:: | 718 InlineLoginHandlerImpl:: |
| 714 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} | 719 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} |
| 715 | 720 |
| 716 // static | 721 // static |
| 717 void InlineLoginHandlerImpl::FinishCompleteLogin( | 722 void InlineLoginHandlerImpl::FinishCompleteLogin( |
| 718 const FinishCompleteLoginParams& params, | 723 const FinishCompleteLoginParams& params, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 signin_client->GetSigninScopedDeviceId(); | 797 signin_client->GetSigninScopedDeviceId(); |
| 793 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; | 798 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; |
| 794 if (params.handler) | 799 if (params.handler) |
| 795 handler_weak_ptr = params.handler->GetWeakPtr(); | 800 handler_weak_ptr = params.handler->GetWeakPtr(); |
| 796 | 801 |
| 797 // InlineSigninHelper will delete itself. | 802 // InlineSigninHelper will delete itself. |
| 798 new InlineSigninHelper( | 803 new InlineSigninHelper( |
| 799 handler_weak_ptr, params.partition->GetURLRequestContext(), profile, | 804 handler_weak_ptr, params.partition->GetURLRequestContext(), profile, |
| 800 status, params.url, params.email, params.gaia_id, params.password, | 805 status, params.url, params.email, params.gaia_id, params.password, |
| 801 params.session_index, params.auth_code, signin_scoped_device_id, | 806 params.session_index, params.auth_code, signin_scoped_device_id, |
| 802 params.choose_what_to_sync, params.confirm_untrusted_signin); | 807 params.choose_what_to_sync, params.confirm_untrusted_signin, |
| 808 params.is_force_sign_in_with_usermanager); |
| 803 | 809 |
| 804 // If opened from user manager to unlock a profile, make sure the user manager | 810 // If opened from user manager to unlock a profile, make sure the user manager |
| 805 // is closed and that the profile is marked as unlocked. | 811 // is closed and that the profile is marked as unlocked. |
| 806 if (!signin::IsForceSigninEnabled()) { | 812 if (!params.is_force_sign_in_with_usermanager) { |
| 807 UnlockProfileAndHideLoginUI(params.profile_path, params.handler); | 813 UnlockProfileAndHideLoginUI(params.profile_path, params.handler); |
| 808 } | 814 } |
| 809 } | 815 } |
| 810 | 816 |
| 811 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg, | 817 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg, |
| 812 const base::string16& email) { | 818 const base::string16& email) { |
| 813 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 819 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 814 Browser* browser = GetDesktopBrowser(); | 820 Browser* browser = GetDesktopBrowser(); |
| 815 Profile* profile = Profile::FromWebUI(web_ui()); | 821 Profile* profile = Profile::FromWebUI(web_ui()); |
| 816 | 822 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 | 882 |
| 877 if (show_account_management) { | 883 if (show_account_management) { |
| 878 browser->window()->ShowAvatarBubbleFromAvatarButton( | 884 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 879 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 885 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
| 880 signin::ManageAccountsParams(), | 886 signin::ManageAccountsParams(), |
| 881 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, | 887 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, |
| 882 false); | 888 false); |
| 883 } | 889 } |
| 884 } | 890 } |
| 885 } | 891 } |
| OLD | NEW |