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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 26 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 28 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
29 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 29 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
30 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 30 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
32 #include "components/signin/core/browser/about_signin_internals.h" | 32 #include "components/signin/core/browser/about_signin_internals.h" |
33 #include "components/signin/core/browser/account_tracker_service.h" | 33 #include "components/signin/core/browser/account_tracker_service.h" |
34 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 34 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
35 #include "components/signin/core/browser/signin_error_controller.h" | 35 #include "components/signin/core/browser/signin_error_controller.h" |
| 36 #include "components/signin/core/browser/signin_oauth_helper.h" |
36 #include "components/signin/core/common/profile_management_switches.h" | 37 #include "components/signin/core/common/profile_management_switches.h" |
37 #include "content/public/browser/storage_partition.h" | 38 #include "content/public/browser/storage_partition.h" |
38 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
39 #include "google_apis/gaia/gaia_auth_consumer.h" | |
40 #include "google_apis/gaia/gaia_auth_fetcher.h" | 40 #include "google_apis/gaia/gaia_auth_fetcher.h" |
41 #include "google_apis/gaia/gaia_auth_util.h" | 41 #include "google_apis/gaia/gaia_auth_util.h" |
42 #include "google_apis/gaia/gaia_constants.h" | 42 #include "google_apis/gaia/gaia_constants.h" |
43 #include "google_apis/gaia/gaia_urls.h" | 43 #include "google_apis/gaia/gaia_urls.h" |
44 #include "net/base/url_util.h" | 44 #include "net/base/url_util.h" |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 class InlineSigninHelper : public GaiaAuthConsumer { | 48 class InlineSigninHelper : public SigninOAuthHelper::Consumer { |
49 public: | 49 public: |
50 InlineSigninHelper( | 50 InlineSigninHelper( |
51 base::WeakPtr<InlineLoginHandlerImpl> handler, | 51 base::WeakPtr<InlineLoginHandlerImpl> handler, |
52 net::URLRequestContextGetter* getter, | 52 net::URLRequestContextGetter* getter, |
53 Profile* profile, | 53 Profile* profile, |
54 const GURL& current_url, | 54 const GURL& current_url, |
55 const std::string& email, | 55 const std::string& email, |
56 const std::string& gaia_id, | |
57 const std::string& password, | 56 const std::string& password, |
58 const std::string& session_index, | 57 const std::string& session_index, |
59 const std::string& signin_scoped_device_id, | 58 const std::string& signin_scoped_device_id, |
60 bool choose_what_to_sync, | 59 bool choose_what_to_sync, |
61 bool confirm_untrusted_signin); | 60 bool confirm_untrusted_signin); |
62 | 61 |
63 private: | 62 private: |
64 // Overridden from GaiaAuthConsumer. | 63 // Overriden from SigninOAuthHelper::Consumer. |
65 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; | 64 void OnSigninOAuthInformationAvailable( |
66 void OnClientOAuthFailure(const GoogleServiceAuthError& error) | 65 const std::string& email, |
67 override; | 66 const std::string& display_email, |
| 67 const std::string& refresh_token) override; |
| 68 void OnSigninOAuthInformationFailure( |
| 69 const GoogleServiceAuthError& error) override; |
68 | 70 |
69 GaiaAuthFetcher gaia_auth_fetcher_; | 71 SigninOAuthHelper signin_oauth_helper_; |
70 base::WeakPtr<InlineLoginHandlerImpl> handler_; | 72 base::WeakPtr<InlineLoginHandlerImpl> handler_; |
71 Profile* profile_; | 73 Profile* profile_; |
72 GURL current_url_; | 74 GURL current_url_; |
73 std::string email_; | 75 std::string email_; |
74 std::string gaia_id_; | |
75 std::string password_; | 76 std::string password_; |
76 std::string session_index_; | 77 std::string session_index_; |
77 bool choose_what_to_sync_; | 78 bool choose_what_to_sync_; |
78 bool confirm_untrusted_signin_; | 79 bool confirm_untrusted_signin_; |
79 | 80 |
80 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); | 81 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); |
81 }; | 82 }; |
82 | 83 |
83 InlineSigninHelper::InlineSigninHelper( | 84 InlineSigninHelper::InlineSigninHelper( |
84 base::WeakPtr<InlineLoginHandlerImpl> handler, | 85 base::WeakPtr<InlineLoginHandlerImpl> handler, |
85 net::URLRequestContextGetter* getter, | 86 net::URLRequestContextGetter* getter, |
86 Profile* profile, | 87 Profile* profile, |
87 const GURL& current_url, | 88 const GURL& current_url, |
88 const std::string& email, | 89 const std::string& email, |
89 const std::string& gaia_id, | |
90 const std::string& password, | 90 const std::string& password, |
91 const std::string& session_index, | 91 const std::string& session_index, |
92 const std::string& signin_scoped_device_id, | 92 const std::string& signin_scoped_device_id, |
93 bool choose_what_to_sync, | 93 bool choose_what_to_sync, |
94 bool confirm_untrusted_signin) | 94 bool confirm_untrusted_signin) |
95 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), | 95 : signin_oauth_helper_(getter, session_index, signin_scoped_device_id, |
| 96 this), |
96 handler_(handler), | 97 handler_(handler), |
97 profile_(profile), | 98 profile_(profile), |
98 current_url_(current_url), | 99 current_url_(current_url), |
99 email_(email), | 100 email_(email), |
100 gaia_id_(gaia_id), | |
101 password_(password), | 101 password_(password), |
102 session_index_(session_index), | 102 session_index_(session_index), |
103 choose_what_to_sync_(choose_what_to_sync), | 103 choose_what_to_sync_(choose_what_to_sync), |
104 confirm_untrusted_signin_(confirm_untrusted_signin) { | 104 confirm_untrusted_signin_(confirm_untrusted_signin) { |
105 DCHECK(profile_); | 105 DCHECK(profile_); |
106 DCHECK(!email_.empty()); | 106 DCHECK(!email_.empty()); |
107 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( | |
108 session_index, signin_scoped_device_id); | |
109 } | 107 } |
110 | 108 |
111 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { | 109 void InlineSigninHelper::OnSigninOAuthInformationAvailable( |
| 110 const std::string& email, |
| 111 const std::string& display_email, |
| 112 const std::string& refresh_token) { |
112 content::WebContents* contents = NULL; | 113 content::WebContents* contents = NULL; |
113 Browser* browser = NULL; | 114 Browser* browser = NULL; |
114 if (handler_) { | 115 if (handler_) { |
115 contents = handler_->web_ui()->GetWebContents(); | 116 contents = handler_->web_ui()->GetWebContents(); |
116 browser = handler_->GetDesktopBrowser(); | 117 browser = handler_->GetDesktopBrowser(); |
117 } | 118 } |
118 | 119 |
119 AboutSigninInternals* about_signin_internals = | 120 AboutSigninInternals* about_signin_internals = |
120 AboutSigninInternalsFactory::GetForProfile(profile_); | 121 AboutSigninInternalsFactory::GetForProfile(profile_); |
121 about_signin_internals->OnRefreshTokenReceived("Successful"); | 122 about_signin_internals->OnRefreshTokenReceived("Successful"); |
122 | 123 |
123 AccountTrackerService* account_tracker = | |
124 AccountTrackerServiceFactory::GetForProfile(profile_); | |
125 std::string account_id = | |
126 account_tracker->PickAccountIdForAccount(gaia_id_, email_); | |
127 | |
128 // Prime the account tracker with this combination of gaia id/display email. | |
129 account_tracker->SeedAccountInfo(gaia_id_, email_); | |
130 | |
131 signin::Source source = signin::GetSourceForPromoURL(current_url_); | 124 signin::Source source = signin::GetSourceForPromoURL(current_url_); |
132 | 125 |
133 std::string primary_email = | 126 std::string primary_email = |
134 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername(); | 127 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername(); |
135 if (gaia::AreEmailsSame(email_, primary_email) && | 128 if (gaia::AreEmailsSame(email, primary_email) && |
136 source == signin::SOURCE_REAUTH && | 129 source == signin::SOURCE_REAUTH && |
137 switches::IsNewProfileManagement()) { | 130 switches::IsNewProfileManagement()) { |
138 chrome::SetLocalAuthCredentials(profile_, password_); | 131 chrome::SetLocalAuthCredentials(profile_, password_); |
139 } | 132 } |
140 | 133 |
141 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 134 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
142 source == signin::SOURCE_REAUTH) { | 135 source == signin::SOURCE_REAUTH) { |
| 136 // TODO(rogerta): the javascript code will need to pass in the gaia-id |
| 137 // of the account instead of the email when chrome uses gaia-id as key. |
| 138 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
| 139 AccountTrackerServiceFactory::GetForProfile(profile_)-> |
| 140 GetMigrationState()); |
| 141 const std::string account_id = gaia::CanonicalizeEmail(email); |
143 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 142 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
144 UpdateCredentials(account_id, result.refresh_token); | 143 UpdateCredentials(account_id, refresh_token); |
145 | 144 |
146 if (signin::IsAutoCloseEnabledInURL(current_url_)) { | 145 if (signin::IsAutoCloseEnabledInURL(current_url_)) { |
147 // Close the gaia sign in tab via a task to make sure we aren't in the | 146 // Close the gaia sign in tab via a task to make sure we aren't in the |
148 // middle of any webui handler code. | 147 // middle of any webui handler code. |
149 base::MessageLoop::current()->PostTask( | 148 base::MessageLoop::current()->PostTask( |
150 FROM_HERE, | 149 FROM_HERE, |
151 base::Bind(&InlineLoginHandlerImpl::CloseTab, | 150 base::Bind(&InlineLoginHandlerImpl::CloseTab, |
152 handler_, | 151 handler_, |
153 signin::ShouldShowAccountManagement(current_url_))); | 152 signin::ShouldShowAccountManagement(current_url_))); |
154 } | 153 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 confirmation_required = | 185 confirmation_required = |
187 source == signin::SOURCE_SETTINGS || | 186 source == signin::SOURCE_SETTINGS || |
188 choose_what_to_sync_ ? | 187 choose_what_to_sync_ ? |
189 OneClickSigninSyncStarter::NO_CONFIRMATION : | 188 OneClickSigninSyncStarter::NO_CONFIRMATION : |
190 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 189 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
191 } | 190 } |
192 | 191 |
193 bool start_signin = | 192 bool start_signin = |
194 !OneClickSigninHelper::HandleCrossAccountError( | 193 !OneClickSigninHelper::HandleCrossAccountError( |
195 profile_, "", | 194 profile_, "", |
196 email_, password_, result.refresh_token, | 195 email, password_, refresh_token, |
197 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, | 196 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, |
198 source, start_mode, | 197 source, start_mode, |
199 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, | 198 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, |
200 handler_)); | 199 handler_)); |
201 if (start_signin) { | 200 if (start_signin) { |
202 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. | 201 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. |
203 // OneClickSigninSyncStarter will delete itself once the job is done. | 202 // OneClickSigninSyncStarter will delete itself once the job is done. |
204 new OneClickSigninSyncStarter( | 203 new OneClickSigninSyncStarter( |
205 profile_, browser, | 204 profile_, browser, |
206 account_id, password_, result.refresh_token, | 205 email, password_, refresh_token, |
207 start_mode, | 206 start_mode, |
208 contents, | 207 contents, |
209 confirmation_required, | 208 confirmation_required, |
210 signin::GetNextPageURLForPromoURL(current_url_), | 209 signin::GetNextPageURLForPromoURL(current_url_), |
211 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | 210 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); |
212 } | 211 } |
213 } | 212 } |
214 | 213 |
215 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 214 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
216 } | 215 } |
217 | 216 |
218 void InlineSigninHelper::OnClientOAuthFailure( | 217 void InlineSigninHelper::OnSigninOAuthInformationFailure( |
219 const GoogleServiceAuthError& error) { | 218 const GoogleServiceAuthError& error) { |
220 if (handler_) | 219 if (handler_) |
221 handler_->HandleLoginError(error.ToString()); | 220 handler_->HandleLoginError(error.ToString()); |
222 | 221 |
223 AboutSigninInternals* about_signin_internals = | 222 AboutSigninInternals* about_signin_internals = |
224 AboutSigninInternalsFactory::GetForProfile(profile_); | 223 AboutSigninInternalsFactory::GetForProfile(profile_); |
225 about_signin_internals->OnRefreshTokenReceived("Failure"); | 224 about_signin_internals->OnRefreshTokenReceived("Failure"); |
226 | 225 |
227 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 226 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
228 } | 227 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 305 |
307 base::string16 email_string16; | 306 base::string16 email_string16; |
308 dict->GetString("email", &email_string16); | 307 dict->GetString("email", &email_string16); |
309 DCHECK(!email_string16.empty()); | 308 DCHECK(!email_string16.empty()); |
310 std::string email(base::UTF16ToASCII(email_string16)); | 309 std::string email(base::UTF16ToASCII(email_string16)); |
311 | 310 |
312 base::string16 password_string16; | 311 base::string16 password_string16; |
313 dict->GetString("password", &password_string16); | 312 dict->GetString("password", &password_string16); |
314 std::string password(base::UTF16ToASCII(password_string16)); | 313 std::string password(base::UTF16ToASCII(password_string16)); |
315 | 314 |
316 base::string16 gaia_id_string16; | |
317 dict->GetString("gaiaId", &gaia_id_string16); | |
318 DCHECK(!gaia_id_string16.empty()); | |
319 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); | |
320 | |
321 // When doing a SAML sign in, this email check may result in a false | 315 // When doing a SAML sign in, this email check may result in a false |
322 // positive. This happens when the user types one email address in the | 316 // positive. This happens when the user types one email address in the |
323 // gaia sign in page, but signs in to a different account in the SAML sign in | 317 // gaia sign in page, but signs in to a different account in the SAML sign in |
324 // page. | 318 // page. |
325 std::string default_email; | 319 std::string default_email; |
326 std::string validate_email; | 320 std::string validate_email; |
327 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && | 321 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && |
328 net::GetValueForKeyInQuery(current_url, "validateEmail", | 322 net::GetValueForKeyInQuery(current_url, "validateEmail", |
329 &validate_email) && | 323 &validate_email) && |
330 validate_email == "1") { | 324 validate_email == "1") { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 contents->GetBrowserContext(), | 383 contents->GetBrowserContext(), |
390 GURL(chrome::kChromeUIChromeSigninURL)); | 384 GURL(chrome::kChromeUIChromeSigninURL)); |
391 | 385 |
392 SigninClient* signin_client = | 386 SigninClient* signin_client = |
393 ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 387 ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
394 std::string signin_scoped_device_id = | 388 std::string signin_scoped_device_id = |
395 signin_client->GetSigninScopedDeviceId(); | 389 signin_client->GetSigninScopedDeviceId(); |
396 // InlineSigninHelper will delete itself. | 390 // InlineSigninHelper will delete itself. |
397 new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(), | 391 new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(), |
398 Profile::FromWebUI(web_ui()), current_url, | 392 Profile::FromWebUI(web_ui()), current_url, |
399 email, gaia_id, password, session_index, | 393 email, password, session_index, |
400 signin_scoped_device_id, choose_what_to_sync, | 394 signin_scoped_device_id, choose_what_to_sync, |
401 confirm_untrusted_signin_); | 395 confirm_untrusted_signin_); |
402 | 396 |
403 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | 397 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
404 } | 398 } |
405 | 399 |
406 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { | 400 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { |
407 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 401 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
408 | 402 |
409 Browser* browser = GetDesktopBrowser(); | 403 Browser* browser = GetDesktopBrowser(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 458 } |
465 } | 459 } |
466 | 460 |
467 if (show_account_management) { | 461 if (show_account_management) { |
468 browser->window()->ShowAvatarBubbleFromAvatarButton( | 462 browser->window()->ShowAvatarBubbleFromAvatarButton( |
469 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 463 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
470 signin::ManageAccountsParams()); | 464 signin::ManageAccountsParams()); |
471 } | 465 } |
472 } | 466 } |
473 } | 467 } |
OLD | NEW |