Index: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc |
diff --git a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc |
index 8f70109c21218609e14d23fc618dce8dfa4195ee..9c0041b1d1469aa5cc23236fb0a0efa53170f230 100644 |
--- a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc |
+++ b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc |
@@ -36,6 +36,7 @@ |
#include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "chrome/browser/ui/user_manager.h" |
#include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
#include "chrome/browser/ui/webui/signin/login_ui_service.h" |
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
@@ -495,7 +496,7 @@ void InlineLoginHandlerImpl::DidCommitProvisionalLoadForFrame( |
// Returns early if this is not a gaia iframe navigation. |
const GURL kGaiaExtOrigin( |
- "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/"); |
+ GaiaUrls::GetInstance()->signin_completed_continue_url().GetOrigin()); |
content::RenderFrameHost* gaia_frame = InlineLoginUI::GetAuthFrame( |
web_contents(), kGaiaExtOrigin, "signin-frame"); |
if (render_frame_host != gaia_frame) |
@@ -640,36 +641,101 @@ void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
DCHECK(!gaia_id_string16.empty()); |
std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); |
+ base::string16 session_index_string16; |
+ dict->GetString("sessionIndex", &session_index_string16); |
+ std::string session_index = base::UTF16ToASCII(session_index_string16); |
+ DCHECK(!session_index.empty()); |
+ |
+ bool choose_what_to_sync = false; |
+ dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); |
+ |
+ content::StoragePartition* partition = |
+ content::BrowserContext::GetStoragePartitionForSite( |
+ contents->GetBrowserContext(), signin::GetSigninPartitionURL()); |
+ |
+ // If this was called from the user manager to reauthenticate the profile, |
+ // the URL has a profile index parameter. In this case, the profile used with |
+ // FinishCompleteLogin() must not be taken from web_ui(). The profile may |
+ // not even be open, so may need to open it first. |
+ size_t profile_index = signin::GetProfileIndexForPromoURL(current_url); |
+ if (profile_index == std::string::npos) { |
+ FinishCompleteLogin( |
bcwhite
2015/07/21 13:28:39
Is this the "not called to reauthenticate" case?
Roger Tawa OOO till Jul 10th
2015/07/22 00:12:33
This is the "not called from the user manager to r
bcwhite
2015/07/22 13:42:21
The comment says "if A then B" but the code says "
Roger Tawa OOO till Jul 10th
2015/07/22 15:29:54
Switched order of code.
|
+ FinishCompleteLoginParams(this, partition, current_url, |
+ confirm_untrusted_signin_, email, gaia_id, |
+ password, session_index, choose_what_to_sync), |
+ Profile::FromWebUI(web_ui()), |
+ Profile::CREATE_STATUS_CREATED); |
+ } else { |
+ // Open the profile and finish the login. Don't pass a handler pointer |
+ // since it will be destroyed before the callback runs. |
+ ProfileManager* manager = g_browser_process->profile_manager(); |
+ const ProfileInfoCache& info_cache = manager->GetProfileInfoCache(); |
+ base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
+ FinishCompleteLoginParams params(NULL, partition, current_url, |
+ confirm_untrusted_signin_, email, gaia_id, |
+ password, session_index, |
+ choose_what_to_sync); |
+ ProfileManager::CreateCallback callback = base::Bind( |
+ &InlineLoginHandlerImpl::FinishCompleteLogin, params); |
+ profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, callback, |
+ ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
+ } |
+ |
+ web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
+} |
+ |
+InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( |
+ InlineLoginHandlerImpl* handler, |
+ content::StoragePartition* partition, |
+ const GURL& url, |
+ bool confirm_untrusted_signin, |
+ const std::string& email, |
+ const std::string& gaia_id, |
+ const std::string& password, |
+ const std::string& session_index, |
+ bool choose_what_to_sync) |
+ : handler(handler), |
+ partition(partition), |
+ url(url), |
+ confirm_untrusted_signin(confirm_untrusted_signin), |
+ email(email), |
+ gaia_id(gaia_id), |
+ password(password), |
+ session_index(session_index), |
+ choose_what_to_sync(choose_what_to_sync) {} |
+ |
+InlineLoginHandlerImpl:: |
+ FinishCompleteLoginParams::~FinishCompleteLoginParams() {} |
+ |
+// static |
+void InlineLoginHandlerImpl::FinishCompleteLogin( |
+ const FinishCompleteLoginParams& params, |
+ Profile* profile, |
+ Profile::CreateStatus) { |
// When doing a SAML sign in, this email check may result in a false |
// positive. This happens when the user types one email address in the |
// gaia sign in page, but signs in to a different account in the SAML sign in |
// page. |
std::string default_email; |
std::string validate_email; |
- if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && |
- net::GetValueForKeyInQuery(current_url, "validateEmail", |
+ if (net::GetValueForKeyInQuery(params.url, "email", &default_email) && |
+ net::GetValueForKeyInQuery(params.url, "validateEmail", |
&validate_email) && |
validate_email == "1") { |
- if (!gaia::AreEmailsSame(email, default_email)) { |
- HandleLoginError( |
- l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL, |
- base::UTF8ToUTF16(default_email))); |
+ if (!gaia::AreEmailsSame(params.email, default_email)) { |
+ if (params.handler) { |
+ params.handler->HandleLoginError( |
+ l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL, |
+ base::UTF8ToUTF16(default_email))); |
+ } |
return; |
} |
} |
- base::string16 session_index_string16; |
- dict->GetString("sessionIndex", &session_index_string16); |
- std::string session_index = base::UTF16ToASCII(session_index_string16); |
- DCHECK(!session_index.empty()); |
- |
- bool choose_what_to_sync = false; |
- dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); |
- |
- signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); |
+ signin_metrics::Source source = signin::GetSourceForPromoURL(params.url); |
LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); |
bool switch_to_advanced = |
- choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS); |
+ params.choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS); |
LogHistogramValue( |
switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED : |
signin_metrics::HISTOGRAM_WITH_DEFAULTS); |
@@ -681,8 +747,8 @@ void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
break; |
case signin_metrics::SOURCE_REAUTH: { |
std::string primary_username = |
- SigninManagerFactory::GetForProfile( |
- Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername(); |
+ SigninManagerFactory::GetForProfile(profile) |
+ ->GetAuthenticatedUsername(); |
if (!gaia::AreEmailsSame(default_email, primary_username)) |
can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; |
break; |
@@ -693,33 +759,46 @@ void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
} |
std::string error_msg; |
- bool can_offer = CanOffer(Profile::FromWebUI(web_ui()), can_offer_for, |
- gaia_id, email, &error_msg); |
+ bool can_offer = CanOffer(profile, can_offer_for, params.gaia_id, |
+ params.email, &error_msg); |
if (!can_offer) { |
- HandleLoginError(error_msg); |
+ if (params.handler) |
+ params.handler->HandleLoginError(error_msg); |
return; |
} |
AboutSigninInternals* about_signin_internals = |
- AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
+ AboutSigninInternalsFactory::GetForProfile(profile); |
about_signin_internals->OnAuthenticationResultReceived("Successful"); |
- content::StoragePartition* partition = |
- content::BrowserContext::GetStoragePartitionForSite( |
- contents->GetBrowserContext(), signin::GetSigninPartitionURL()); |
- |
SigninClient* signin_client = |
- ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
+ ChromeSigninClientFactory::GetForProfile(profile); |
std::string signin_scoped_device_id = |
signin_client->GetSigninScopedDeviceId(); |
- // InlineSigninHelper will delete itself. |
- new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(), |
- Profile::FromWebUI(web_ui()), current_url, |
- email, gaia_id, password, session_index, |
- signin_scoped_device_id, choose_what_to_sync, |
- confirm_untrusted_signin_); |
+ base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; |
+ if (params.handler) |
+ handler_weak_ptr = params.handler->GetWeakPtr(); |
- web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
+ // InlineSigninHelper will delete itself. |
+ new InlineSigninHelper(handler_weak_ptr, |
+ params.partition->GetURLRequestContext(), profile, |
+ params.url, |
+ params.email, params.gaia_id, params.password, |
+ params.session_index, signin_scoped_device_id, |
+ params.choose_what_to_sync, |
+ params.confirm_untrusted_signin); |
+ |
+ // If opened from user manager to reauthenticate, make sure the user manager |
+ // is closed and that the profile is marked as unlocked. |
+ size_t profile_index = signin::GetProfileIndexForPromoURL(params.url); |
+ if (profile_index != std::string::npos) { |
+ UserManager::Hide(); |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ if (profile_manager) { |
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
+ cache.SetProfileSigninRequiredAtIndex(profile_index, false); |
+ } |
+ } |
} |
void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { |