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

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

Issue 473153002: Inline sign in extracts gaia id from HTTP header and seeds account tracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 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 | Annotate | Revision Log
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/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/profile_oauth2_token_service_factory.h" 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
18 #include "chrome/browser/signin/signin_manager_factory.h" 19 #include "chrome/browser/signin/signin_manager_factory.h"
19 #include "chrome/browser/sync/profile_sync_service.h" 20 #include "chrome/browser/sync/profile_sync_service.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h" 21 #include "chrome/browser/sync/profile_sync_service_factory.h"
21 #include "chrome/browser/ui/browser_finder.h" 22 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 24 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
24 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" 25 #include "chrome/browser/ui/sync/one_click_signin_histogram.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 27 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
27 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 28 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
28 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 29 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "components/signin/core/browser/about_signin_internals.h" 31 #include "components/signin/core/browser/about_signin_internals.h"
32 #include "components/signin/core/browser/account_tracker_service.h"
31 #include "components/signin/core/browser/profile_oauth2_token_service.h" 33 #include "components/signin/core/browser/profile_oauth2_token_service.h"
32 #include "components/signin/core/browser/signin_error_controller.h" 34 #include "components/signin/core/browser/signin_error_controller.h"
33 #include "components/signin/core/browser/signin_oauth_helper.h" 35 #include "components/signin/core/browser/signin_oauth_helper.h"
34 #include "components/signin/core/common/profile_management_switches.h" 36 #include "components/signin/core/common/profile_management_switches.h"
35 #include "content/public/browser/storage_partition.h" 37 #include "content/public/browser/storage_partition.h"
36 #include "content/public/browser/web_ui.h" 38 #include "content/public/browser/web_ui.h"
37 #include "google_apis/gaia/gaia_auth_fetcher.h" 39 #include "google_apis/gaia/gaia_auth_fetcher.h"
38 #include "google_apis/gaia/gaia_auth_util.h" 40 #include "google_apis/gaia/gaia_auth_util.h"
39 #include "google_apis/gaia/gaia_constants.h" 41 #include "google_apis/gaia/gaia_constants.h"
40 #include "google_apis/gaia/gaia_urls.h" 42 #include "google_apis/gaia/gaia_urls.h"
41 #include "net/base/url_util.h" 43 #include "net/base/url_util.h"
42 44
43 namespace { 45 namespace {
44 46
45 class InlineSigninHelper : public SigninOAuthHelper::Consumer { 47 class InlineSigninHelper : public SigninOAuthHelper::Consumer {
46 public: 48 public:
47 InlineSigninHelper( 49 InlineSigninHelper(
48 base::WeakPtr<InlineLoginHandlerImpl> handler, 50 base::WeakPtr<InlineLoginHandlerImpl> handler,
49 net::URLRequestContextGetter* getter, 51 net::URLRequestContextGetter* getter,
50 Profile* profile, 52 Profile* profile,
51 const GURL& current_url, 53 const GURL& current_url,
52 const std::string& email, 54 const std::string& email,
55 const std::string& gaia_id,
53 const std::string& password, 56 const std::string& password,
54 const std::string& session_index, 57 const std::string& session_index,
55 const std::string& signin_scoped_device_id, 58 const std::string& signin_scoped_device_id,
56 bool choose_what_to_sync, 59 bool choose_what_to_sync,
57 bool confirm_untrusted_signin); 60 bool confirm_untrusted_signin);
58 61
59 private: 62 private:
60 // Overriden from SigninOAuthHelper::Consumer. 63 // Overriden from SigninOAuthHelper::Consumer.
61 virtual void OnSigninOAuthInformationAvailable( 64 virtual void OnSigninOAuthInformationAvailable(
62 const std::string& email, 65 const std::string& email,
63 const std::string& display_email, 66 const std::string& display_email,
64 const std::string& refresh_token) OVERRIDE; 67 const std::string& refresh_token) OVERRIDE;
65 virtual void OnSigninOAuthInformationFailure( 68 virtual void OnSigninOAuthInformationFailure(
66 const GoogleServiceAuthError& error) OVERRIDE; 69 const GoogleServiceAuthError& error) OVERRIDE;
67 70
68 SigninOAuthHelper signin_oauth_helper_; 71 SigninOAuthHelper signin_oauth_helper_;
69 base::WeakPtr<InlineLoginHandlerImpl> handler_; 72 base::WeakPtr<InlineLoginHandlerImpl> handler_;
70 Profile* profile_; 73 Profile* profile_;
71 GURL current_url_; 74 GURL current_url_;
72 std::string email_; 75 std::string email_;
76 std::string gaia_id_;
73 std::string password_; 77 std::string password_;
74 std::string session_index_; 78 std::string session_index_;
75 bool choose_what_to_sync_; 79 bool choose_what_to_sync_;
76 bool confirm_untrusted_signin_; 80 bool confirm_untrusted_signin_;
77 81
78 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); 82 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper);
79 }; 83 };
80 84
81 InlineSigninHelper::InlineSigninHelper( 85 InlineSigninHelper::InlineSigninHelper(
82 base::WeakPtr<InlineLoginHandlerImpl> handler, 86 base::WeakPtr<InlineLoginHandlerImpl> handler,
83 net::URLRequestContextGetter* getter, 87 net::URLRequestContextGetter* getter,
84 Profile* profile, 88 Profile* profile,
85 const GURL& current_url, 89 const GURL& current_url,
86 const std::string& email, 90 const std::string& email,
91 const std::string& gaia_id,
87 const std::string& password, 92 const std::string& password,
88 const std::string& session_index, 93 const std::string& session_index,
89 const std::string& signin_scoped_device_id, 94 const std::string& signin_scoped_device_id,
90 bool choose_what_to_sync, 95 bool choose_what_to_sync,
91 bool confirm_untrusted_signin) 96 bool confirm_untrusted_signin)
92 : signin_oauth_helper_(getter, session_index, signin_scoped_device_id, 97 : signin_oauth_helper_(getter, session_index, signin_scoped_device_id,
93 this), 98 this),
94 handler_(handler), 99 handler_(handler),
95 profile_(profile), 100 profile_(profile),
96 current_url_(current_url), 101 current_url_(current_url),
97 email_(email), 102 email_(email),
103 gaia_id_(gaia_id),
98 password_(password), 104 password_(password),
99 session_index_(session_index), 105 session_index_(session_index),
100 choose_what_to_sync_(choose_what_to_sync), 106 choose_what_to_sync_(choose_what_to_sync),
101 confirm_untrusted_signin_(confirm_untrusted_signin) { 107 confirm_untrusted_signin_(confirm_untrusted_signin) {
102 DCHECK(profile_); 108 DCHECK(profile_);
103 DCHECK(!email_.empty()); 109 DCHECK(!email_.empty());
104 } 110 }
105 111
106 void InlineSigninHelper::OnSigninOAuthInformationAvailable( 112 void InlineSigninHelper::OnSigninOAuthInformationAvailable(
107 const std::string& email, 113 const std::string& email,
108 const std::string& display_email, 114 const std::string& display_email,
109 const std::string& refresh_token) { 115 const std::string& refresh_token) {
110 content::WebContents* contents = NULL; 116 content::WebContents* contents = NULL;
111 Browser* browser = NULL; 117 Browser* browser = NULL;
112 if (handler_) { 118 if (handler_) {
113 contents = handler_->web_ui()->GetWebContents(); 119 contents = handler_->web_ui()->GetWebContents();
114 browser = handler_->GetDesktopBrowser(); 120 browser = handler_->GetDesktopBrowser();
115 } 121 }
116 122
117 AboutSigninInternals* about_signin_internals = 123 AboutSigninInternals* about_signin_internals =
118 AboutSigninInternalsFactory::GetForProfile(profile_); 124 AboutSigninInternalsFactory::GetForProfile(profile_);
119 about_signin_internals->OnRefreshTokenReceived("Successful"); 125 about_signin_internals->OnRefreshTokenReceived("Successful");
120 126
127 AccountTrackerService* account_tracker =
128 AccountTrackerServiceFactory::GetForProfile(profile_);
129 std::string account_id =
130 account_tracker->PickAccountIdForAccount(gaia_id_, email);
131
132 // Prime the account tracker with this combination of gaia id/display email.
133 account_tracker->SeedAccountInfo(account_id, gaia_id_, email_);
guohui 2014/08/21 18:39:43 why do we use email_ here and email at line 130? A
Roger Tawa OOO till Jul 10th 2014/08/21 20:33:18 |email| and |email_| are not guaranteed to be the
134
121 signin::Source source = signin::GetSourceForPromoURL(current_url_); 135 signin::Source source = signin::GetSourceForPromoURL(current_url_);
122 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || 136 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ||
123 source == signin::SOURCE_REAUTH) { 137 source == signin::SOURCE_REAUTH) {
124 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 138 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
125 UpdateCredentials(email, refresh_token); 139 UpdateCredentials(account_id, refresh_token);
126 140
127 if (signin::IsAutoCloseEnabledInURL(current_url_)) { 141 if (signin::IsAutoCloseEnabledInURL(current_url_)) {
128 // Close the gaia sign in tab via a task to make sure we aren't in the 142 // Close the gaia sign in tab via a task to make sure we aren't in the
129 // middle of any webui handler code. 143 // middle of any webui handler code.
130 base::MessageLoop::current()->PostTask( 144 base::MessageLoop::current()->PostTask(
131 FROM_HERE, 145 FROM_HERE,
132 base::Bind(&InlineLoginHandlerImpl::CloseTab, 146 base::Bind(&InlineLoginHandlerImpl::CloseTab,
133 handler_, 147 handler_,
134 signin::ShouldShowAccountManagement(current_url_))); 148 signin::ShouldShowAccountManagement(current_url_)));
135 } 149 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 email, password_, refresh_token, 192 email, password_, refresh_token,
179 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, 193 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT,
180 source, start_mode, 194 source, start_mode,
181 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, 195 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback,
182 handler_)); 196 handler_));
183 if (start_signin) { 197 if (start_signin) {
184 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. 198 // Call OneClickSigninSyncStarter to exchange oauth code for tokens.
185 // OneClickSigninSyncStarter will delete itself once the job is done. 199 // OneClickSigninSyncStarter will delete itself once the job is done.
186 new OneClickSigninSyncStarter( 200 new OneClickSigninSyncStarter(
187 profile_, browser, 201 profile_, browser,
188 email, password_, refresh_token, 202 account_id, password_, refresh_token,
189 start_mode, 203 start_mode,
190 contents, 204 contents,
191 confirmation_required, 205 confirmation_required,
192 signin::GetNextPageURLForPromoURL(current_url_), 206 signin::GetNextPageURLForPromoURL(current_url_),
193 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); 207 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
194 } 208 }
195 } 209 }
196 210
197 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 211 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
198 } 212 }
199 213
200 void InlineSigninHelper::OnSigninOAuthInformationFailure( 214 void InlineSigninHelper::OnSigninOAuthInformationFailure(
201 const GoogleServiceAuthError& error) { 215 const GoogleServiceAuthError& error) {
202 if (handler_) 216 if (handler_)
203 handler_->HandleLoginError(error.ToString()); 217 handler_->HandleLoginError(error.ToString());
204 218
205 AboutSigninInternals* about_signin_internals = 219 AboutSigninInternals* about_signin_internals =
206 AboutSigninInternalsFactory::GetForProfile(profile_); 220 AboutSigninInternalsFactory::GetForProfile(profile_);
207 about_signin_internals->OnRefreshTokenReceived("Failure"); 221 about_signin_internals->OnRefreshTokenReceived("Failure");
208 222
209 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 223 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
210 } 224 }
211 225
212 } // namespace 226 } // namespace
213 227
214 InlineLoginHandlerImpl::InlineLoginHandlerImpl() 228 InlineLoginHandlerImpl::InlineLoginHandlerImpl()
215 : weak_factory_(this), 229 : weak_factory_(this), confirm_untrusted_signin_(false) {
216 confirm_untrusted_signin_(false) {
217 } 230 }
218 231
219 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} 232 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {}
220 233
221 bool InlineLoginHandlerImpl::HandleContextMenu( 234 bool InlineLoginHandlerImpl::HandleContextMenu(
222 const content::ContextMenuParams& params) { 235 const content::ContextMenuParams& params) {
223 #ifndef NDEBUG 236 #ifndef NDEBUG
224 return false; 237 return false;
225 #else 238 #else
226 return true; 239 return true;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 299
287 base::string16 email_string16; 300 base::string16 email_string16;
288 dict->GetString("email", &email_string16); 301 dict->GetString("email", &email_string16);
289 DCHECK(!email_string16.empty()); 302 DCHECK(!email_string16.empty());
290 std::string email(base::UTF16ToASCII(email_string16)); 303 std::string email(base::UTF16ToASCII(email_string16));
291 304
292 base::string16 password_string16; 305 base::string16 password_string16;
293 dict->GetString("password", &password_string16); 306 dict->GetString("password", &password_string16);
294 std::string password(base::UTF16ToASCII(password_string16)); 307 std::string password(base::UTF16ToASCII(password_string16));
295 308
309 base::string16 gaia_id_string16;
310 dict->GetString("gaiaId", &gaia_id_string16);
311 DCHECK(!gaia_id_string16.empty());
312 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16);
313
296 // When doing a SAML sign in, this email check may result in a false 314 // When doing a SAML sign in, this email check may result in a false
297 // positive. This happens when the user types one email address in the 315 // positive. This happens when the user types one email address in the
298 // gaia sign in page, but signs in to a different account in the SAML sign in 316 // gaia sign in page, but signs in to a different account in the SAML sign in
299 // page. 317 // page.
300 std::string default_email; 318 std::string default_email;
301 std::string validate_email; 319 std::string validate_email;
302 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && 320 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) &&
303 net::GetValueForKeyInQuery(current_url, "validateEmail", 321 net::GetValueForKeyInQuery(current_url, "validateEmail",
304 &validate_email) && 322 &validate_email) &&
305 validate_email == "1") { 323 validate_email == "1") {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 contents->GetBrowserContext(), 382 contents->GetBrowserContext(),
365 GURL(chrome::kChromeUIChromeSigninURL)); 383 GURL(chrome::kChromeUIChromeSigninURL));
366 384
367 SigninClient* signin_client = 385 SigninClient* signin_client =
368 ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui())); 386 ChromeSigninClientFactory::GetForProfile(Profile::FromWebUI(web_ui()));
369 std::string signin_scoped_device_id = 387 std::string signin_scoped_device_id =
370 signin_client->GetSigninScopedDeviceId(); 388 signin_client->GetSigninScopedDeviceId();
371 // InlineSigninHelper will delete itself. 389 // InlineSigninHelper will delete itself.
372 new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(), 390 new InlineSigninHelper(GetWeakPtr(), partition->GetURLRequestContext(),
373 Profile::FromWebUI(web_ui()), current_url, 391 Profile::FromWebUI(web_ui()), current_url,
374 email, password, session_index, 392 email, gaia_id, password, session_index,
375 signin_scoped_device_id, choose_what_to_sync, 393 signin_scoped_device_id, choose_what_to_sync,
376 confirm_untrusted_signin_); 394 confirm_untrusted_signin_);
377 395
378 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); 396 web_ui()->CallJavascriptFunction("inline.login.closeDialog");
379 } 397 }
380 398
381 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { 399 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) {
382 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); 400 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
383 401
384 Browser* browser = GetDesktopBrowser(); 402 Browser* browser = GetDesktopBrowser();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 457 }
440 } 458 }
441 459
442 if (show_account_management) { 460 if (show_account_management) {
443 browser->window()->ShowAvatarBubbleFromAvatarButton( 461 browser->window()->ShowAvatarBubbleFromAvatarButton(
444 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, 462 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
445 signin::ManageAccountsParams()); 463 signin::ManageAccountsParams());
446 } 464 }
447 } 465 }
448 } 466 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_handler_impl.h ('k') | components/signin/core/browser/account_tracker_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698