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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/signin/about_signin_internals_factory.h" | 15 #include "chrome/browser/signin/about_signin_internals_factory.h" |
| 16 #include "chrome/browser/signin/account_tracker_service_factory.h" |
16 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 17 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
17 #include "chrome/browser/signin/local_auth.h" | 18 #include "chrome/browser/signin/local_auth.h" |
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
19 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
20 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
21 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
22 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 25 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
25 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 26 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
27 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 28 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
28 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 29 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
29 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 30 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #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" |
32 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 34 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
33 #include "components/signin/core/browser/signin_error_controller.h" | 35 #include "components/signin/core/browser/signin_error_controller.h" |
34 #include "components/signin/core/browser/signin_oauth_helper.h" | 36 #include "components/signin/core/browser/signin_oauth_helper.h" |
35 #include "components/signin/core/common/profile_management_switches.h" | 37 #include "components/signin/core/common/profile_management_switches.h" |
36 #include "content/public/browser/storage_partition.h" | 38 #include "content/public/browser/storage_partition.h" |
37 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
38 #include "google_apis/gaia/gaia_auth_fetcher.h" | 40 #include "google_apis/gaia/gaia_auth_fetcher.h" |
39 #include "google_apis/gaia/gaia_auth_util.h" | 41 #include "google_apis/gaia/gaia_auth_util.h" |
40 #include "google_apis/gaia/gaia_constants.h" | 42 #include "google_apis/gaia/gaia_constants.h" |
41 #include "google_apis/gaia/gaia_urls.h" | 43 #include "google_apis/gaia/gaia_urls.h" |
42 #include "net/base/url_util.h" | 44 #include "net/base/url_util.h" |
43 | 45 |
44 namespace { | 46 namespace { |
45 | 47 |
46 class InlineSigninHelper : public SigninOAuthHelper::Consumer { | 48 class InlineSigninHelper : public SigninOAuthHelper::Consumer { |
47 public: | 49 public: |
48 InlineSigninHelper( | 50 InlineSigninHelper( |
49 base::WeakPtr<InlineLoginHandlerImpl> handler, | 51 base::WeakPtr<InlineLoginHandlerImpl> handler, |
50 net::URLRequestContextGetter* getter, | 52 net::URLRequestContextGetter* getter, |
51 Profile* profile, | 53 Profile* profile, |
52 const GURL& current_url, | 54 const GURL& current_url, |
53 const std::string& email, | 55 const std::string& email, |
| 56 const std::string& gaia_id, |
54 const std::string& password, | 57 const std::string& password, |
55 const std::string& session_index, | 58 const std::string& session_index, |
56 const std::string& signin_scoped_device_id, | 59 const std::string& signin_scoped_device_id, |
57 bool choose_what_to_sync, | 60 bool choose_what_to_sync, |
58 bool confirm_untrusted_signin); | 61 bool confirm_untrusted_signin); |
59 | 62 |
60 private: | 63 private: |
61 // Overriden from SigninOAuthHelper::Consumer. | 64 // Overriden from SigninOAuthHelper::Consumer. |
62 virtual void OnSigninOAuthInformationAvailable( | 65 virtual void OnSigninOAuthInformationAvailable( |
63 const std::string& email, | 66 const std::string& email, |
64 const std::string& display_email, | 67 const std::string& display_email, |
65 const std::string& refresh_token) OVERRIDE; | 68 const std::string& refresh_token) OVERRIDE; |
66 virtual void OnSigninOAuthInformationFailure( | 69 virtual void OnSigninOAuthInformationFailure( |
67 const GoogleServiceAuthError& error) OVERRIDE; | 70 const GoogleServiceAuthError& error) OVERRIDE; |
68 | 71 |
69 SigninOAuthHelper signin_oauth_helper_; | 72 SigninOAuthHelper signin_oauth_helper_; |
70 base::WeakPtr<InlineLoginHandlerImpl> handler_; | 73 base::WeakPtr<InlineLoginHandlerImpl> handler_; |
71 Profile* profile_; | 74 Profile* profile_; |
72 GURL current_url_; | 75 GURL current_url_; |
73 std::string email_; | 76 std::string email_; |
| 77 std::string gaia_id_; |
74 std::string password_; | 78 std::string password_; |
75 std::string session_index_; | 79 std::string session_index_; |
76 bool choose_what_to_sync_; | 80 bool choose_what_to_sync_; |
77 bool confirm_untrusted_signin_; | 81 bool confirm_untrusted_signin_; |
78 | 82 |
79 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); | 83 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); |
80 }; | 84 }; |
81 | 85 |
82 InlineSigninHelper::InlineSigninHelper( | 86 InlineSigninHelper::InlineSigninHelper( |
83 base::WeakPtr<InlineLoginHandlerImpl> handler, | 87 base::WeakPtr<InlineLoginHandlerImpl> handler, |
84 net::URLRequestContextGetter* getter, | 88 net::URLRequestContextGetter* getter, |
85 Profile* profile, | 89 Profile* profile, |
86 const GURL& current_url, | 90 const GURL& current_url, |
87 const std::string& email, | 91 const std::string& email, |
| 92 const std::string& gaia_id, |
88 const std::string& password, | 93 const std::string& password, |
89 const std::string& session_index, | 94 const std::string& session_index, |
90 const std::string& signin_scoped_device_id, | 95 const std::string& signin_scoped_device_id, |
91 bool choose_what_to_sync, | 96 bool choose_what_to_sync, |
92 bool confirm_untrusted_signin) | 97 bool confirm_untrusted_signin) |
93 : signin_oauth_helper_(getter, session_index, signin_scoped_device_id, | 98 : signin_oauth_helper_(getter, session_index, signin_scoped_device_id, |
94 this), | 99 this), |
95 handler_(handler), | 100 handler_(handler), |
96 profile_(profile), | 101 profile_(profile), |
97 current_url_(current_url), | 102 current_url_(current_url), |
98 email_(email), | 103 email_(email), |
| 104 gaia_id_(gaia_id), |
99 password_(password), | 105 password_(password), |
100 session_index_(session_index), | 106 session_index_(session_index), |
101 choose_what_to_sync_(choose_what_to_sync), | 107 choose_what_to_sync_(choose_what_to_sync), |
102 confirm_untrusted_signin_(confirm_untrusted_signin) { | 108 confirm_untrusted_signin_(confirm_untrusted_signin) { |
103 DCHECK(profile_); | 109 DCHECK(profile_); |
104 DCHECK(!email_.empty()); | 110 DCHECK(!email_.empty()); |
105 } | 111 } |
106 | 112 |
107 void InlineSigninHelper::OnSigninOAuthInformationAvailable( | 113 void InlineSigninHelper::OnSigninOAuthInformationAvailable( |
108 const std::string& email, | 114 const std::string& email, |
109 const std::string& display_email, | 115 const std::string& display_email, |
110 const std::string& refresh_token) { | 116 const std::string& refresh_token) { |
111 content::WebContents* contents = NULL; | 117 content::WebContents* contents = NULL; |
112 Browser* browser = NULL; | 118 Browser* browser = NULL; |
113 if (handler_) { | 119 if (handler_) { |
114 contents = handler_->web_ui()->GetWebContents(); | 120 contents = handler_->web_ui()->GetWebContents(); |
115 browser = handler_->GetDesktopBrowser(); | 121 browser = handler_->GetDesktopBrowser(); |
116 } | 122 } |
117 | 123 |
118 AboutSigninInternals* about_signin_internals = | 124 AboutSigninInternals* about_signin_internals = |
119 AboutSigninInternalsFactory::GetForProfile(profile_); | 125 AboutSigninInternalsFactory::GetForProfile(profile_); |
120 about_signin_internals->OnRefreshTokenReceived("Successful"); | 126 about_signin_internals->OnRefreshTokenReceived("Successful"); |
121 | 127 |
| 128 AccountTrackerService* account_tracker = |
| 129 AccountTrackerServiceFactory::GetForProfile(profile_); |
| 130 std::string account_id = |
| 131 account_tracker->PickAccountIdForAccount(gaia_id_, email); |
| 132 |
| 133 // Prime the account tracker with this combination of gaia id/display email. |
| 134 account_tracker->SeedAccountInfo(account_id, gaia_id_, email_); |
| 135 |
122 signin::Source source = signin::GetSourceForPromoURL(current_url_); | 136 signin::Source source = signin::GetSourceForPromoURL(current_url_); |
123 | 137 |
124 std::string primary_email = | 138 std::string primary_email = |
125 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername(); | 139 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername(); |
126 if (gaia::AreEmailsSame(email, primary_email) && | 140 if (gaia::AreEmailsSame(email, primary_email) && |
127 source == signin::SOURCE_REAUTH && | 141 source == signin::SOURCE_REAUTH && |
128 switches::IsNewProfileManagement()) { | 142 switches::IsNewProfileManagement()) { |
129 chrome::SetLocalAuthCredentials(profile_, password_); | 143 chrome::SetLocalAuthCredentials(profile_, password_); |
130 } | 144 } |
131 | 145 |
132 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 146 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
133 source == signin::SOURCE_REAUTH) { | 147 source == signin::SOURCE_REAUTH) { |
134 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 148 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
135 UpdateCredentials(email, refresh_token); | 149 UpdateCredentials(account_id, refresh_token); |
136 | 150 |
137 if (signin::IsAutoCloseEnabledInURL(current_url_)) { | 151 if (signin::IsAutoCloseEnabledInURL(current_url_)) { |
138 // Close the gaia sign in tab via a task to make sure we aren't in the | 152 // Close the gaia sign in tab via a task to make sure we aren't in the |
139 // middle of any webui handler code. | 153 // middle of any webui handler code. |
140 base::MessageLoop::current()->PostTask( | 154 base::MessageLoop::current()->PostTask( |
141 FROM_HERE, | 155 FROM_HERE, |
142 base::Bind(&InlineLoginHandlerImpl::CloseTab, | 156 base::Bind(&InlineLoginHandlerImpl::CloseTab, |
143 handler_, | 157 handler_, |
144 signin::ShouldShowAccountManagement(current_url_))); | 158 signin::ShouldShowAccountManagement(current_url_))); |
145 } | 159 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 email, password_, refresh_token, | 202 email, password_, refresh_token, |
189 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, | 203 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, |
190 source, start_mode, | 204 source, start_mode, |
191 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, | 205 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, |
192 handler_)); | 206 handler_)); |
193 if (start_signin) { | 207 if (start_signin) { |
194 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. | 208 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. |
195 // OneClickSigninSyncStarter will delete itself once the job is done. | 209 // OneClickSigninSyncStarter will delete itself once the job is done. |
196 new OneClickSigninSyncStarter( | 210 new OneClickSigninSyncStarter( |
197 profile_, browser, | 211 profile_, browser, |
198 email, password_, refresh_token, | 212 account_id, password_, refresh_token, |
199 start_mode, | 213 start_mode, |
200 contents, | 214 contents, |
201 confirmation_required, | 215 confirmation_required, |
202 signin::GetNextPageURLForPromoURL(current_url_), | 216 signin::GetNextPageURLForPromoURL(current_url_), |
203 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | 217 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); |
204 } | 218 } |
205 } | 219 } |
206 | 220 |
207 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 221 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
208 } | 222 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 312 |
299 base::string16 email_string16; | 313 base::string16 email_string16; |
300 dict->GetString("email", &email_string16); | 314 dict->GetString("email", &email_string16); |
301 DCHECK(!email_string16.empty()); | 315 DCHECK(!email_string16.empty()); |
302 std::string email(base::UTF16ToASCII(email_string16)); | 316 std::string email(base::UTF16ToASCII(email_string16)); |
303 | 317 |
304 base::string16 password_string16; | 318 base::string16 password_string16; |
305 dict->GetString("password", &password_string16); | 319 dict->GetString("password", &password_string16); |
306 std::string password(base::UTF16ToASCII(password_string16)); | 320 std::string password(base::UTF16ToASCII(password_string16)); |
307 | 321 |
| 322 base::string16 gaia_id_string16; |
| 323 dict->GetString("gaiaId", &gaia_id_string16); |
| 324 DCHECK(!gaia_id_string16.empty()); |
| 325 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); |
| 326 |
308 // When doing a SAML sign in, this email check may result in a false | 327 // When doing a SAML sign in, this email check may result in a false |
309 // positive. This happens when the user types one email address in the | 328 // positive. This happens when the user types one email address in the |
310 // gaia sign in page, but signs in to a different account in the SAML sign in | 329 // gaia sign in page, but signs in to a different account in the SAML sign in |
311 // page. | 330 // page. |
312 std::string default_email; | 331 std::string default_email; |
313 std::string validate_email; | 332 std::string validate_email; |
314 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && | 333 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && |
315 net::GetValueForKeyInQuery(current_url, "validateEmail", | 334 net::GetValueForKeyInQuery(current_url, "validateEmail", |
316 &validate_email) && | 335 &validate_email) && |
317 validate_email == "1") { | 336 validate_email == "1") { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 contents->GetBrowserContext(), | 395 contents->GetBrowserContext(), |
377 GURL(chrome::kChromeUIChromeSigninURL)); | 396 GURL(chrome::kChromeUIChromeSigninURL)); |
378 | 397 |
379 SigninClient* signin_client = | 398 SigninClient* signin_client = |
380 ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 399 ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
381 std::string signin_scoped_device_id = | 400 std::string signin_scoped_device_id = |
382 signin_client->GetSigninScopedDeviceId(); | 401 signin_client->GetSigninScopedDeviceId(); |
383 // InlineSigninHelper will delete itself. | 402 // InlineSigninHelper will delete itself. |
384 new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(), | 403 new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(), |
385 Profile::FromWebUI(web_ui()), current_url, | 404 Profile::FromWebUI(web_ui()), current_url, |
386 email, password, session_index, | 405 email, gaia_id, password, session_index, |
387 signin_scoped_device_id, choose_what_to_sync, | 406 signin_scoped_device_id, choose_what_to_sync, |
388 confirm_untrusted_signin_); | 407 confirm_untrusted_signin_); |
389 | 408 |
390 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | 409 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
391 } | 410 } |
392 | 411 |
393 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { | 412 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { |
394 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 413 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
395 | 414 |
396 Browser* browser = GetDesktopBrowser(); | 415 Browser* browser = GetDesktopBrowser(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 } | 470 } |
452 } | 471 } |
453 | 472 |
454 if (show_account_management) { | 473 if (show_account_management) { |
455 browser->window()->ShowAvatarBubbleFromAvatarButton( | 474 browser->window()->ShowAvatarBubbleFromAvatarButton( |
456 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 475 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
457 signin::ManageAccountsParams()); | 476 signin::ManageAccountsParams()); |
458 } | 477 } |
459 } | 478 } |
460 } | 479 } |
OLD | NEW |