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

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

Issue 1344443002: Implement new password separated sign in flow for chrome desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged Created 5 years, 2 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
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/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "components/signin/core/browser/about_signin_internals.h" 46 #include "components/signin/core/browser/about_signin_internals.h"
47 #include "components/signin/core/browser/account_tracker_service.h" 47 #include "components/signin/core/browser/account_tracker_service.h"
48 #include "components/signin/core/browser/profile_oauth2_token_service.h" 48 #include "components/signin/core/browser/profile_oauth2_token_service.h"
49 #include "components/signin/core/browser/signin_error_controller.h" 49 #include "components/signin/core/browser/signin_error_controller.h"
50 #include "components/signin/core/browser/signin_header_helper.h" 50 #include "components/signin/core/browser/signin_header_helper.h"
51 #include "components/signin/core/browser/signin_metrics.h" 51 #include "components/signin/core/browser/signin_metrics.h"
52 #include "components/signin/core/common/profile_management_switches.h" 52 #include "components/signin/core/common/profile_management_switches.h"
53 #include "components/signin/core/common/signin_pref_names.h" 53 #include "components/signin/core/common/signin_pref_names.h"
54 #include "content/public/browser/storage_partition.h" 54 #include "content/public/browser/storage_partition.h"
55 #include "content/public/browser/web_ui.h" 55 #include "content/public/browser/web_ui.h"
56 #include "google_apis/gaia/gaia_auth_consumer.h"
57 #include "google_apis/gaia/gaia_auth_fetcher.h" 56 #include "google_apis/gaia/gaia_auth_fetcher.h"
58 #include "google_apis/gaia/gaia_auth_util.h" 57 #include "google_apis/gaia/gaia_auth_util.h"
59 #include "google_apis/gaia/gaia_constants.h" 58 #include "google_apis/gaia/gaia_constants.h"
60 #include "google_apis/gaia/gaia_urls.h" 59 #include "google_apis/gaia/gaia_urls.h"
61 #include "grit/components_strings.h" 60 #include "grit/components_strings.h"
62 #include "net/base/url_util.h" 61 #include "net/base/url_util.h"
63 #include "ui/base/l10n/l10n_util.h" 62 #include "ui/base/l10n/l10n_util.h"
64 63
65 namespace { 64 namespace {
66 65
(...skipping 28 matching lines...) Expand all
95 } 94 }
96 95
97 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents, 96 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents,
98 signin_metrics::Source source) { 97 signin_metrics::Source source) {
99 if (source != signin_metrics::SOURCE_SETTINGS) 98 if (source != signin_metrics::SOURCE_SETTINGS)
100 RedirectToNtpOrAppsPage(contents, source); 99 RedirectToNtpOrAppsPage(contents, source);
101 } 100 }
102 101
103 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { 102 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate {
104 public: 103 public:
105 enum Action {
106 CREATE_NEW_USER,
107 START_SYNC,
108 CLOSE
109 };
110
111 // Callback indicating action performed by the user. 104 // Callback indicating action performed by the user.
112 typedef base::Callback<void(Action)> Callback; 105 typedef base::Callback<void(InlineSigninHelper::Action)> Callback;
113 106
114 // Ask the user for confirmation before starting to sync. 107 // Ask the user for confirmation before starting to sync.
115 static void AskForConfirmation(content::WebContents* contents, 108 static void AskForConfirmation(content::WebContents* contents,
116 const std::string& last_email, 109 const std::string& last_email,
117 const std::string& email, 110 const std::string& email,
118 Callback callback); 111 Callback callback);
119 112
120 private: 113 private:
121 ConfirmEmailDialogDelegate(content::WebContents* contents, 114 ConfirmEmailDialogDelegate(content::WebContents* contents,
122 const std::string& last_email, 115 const std::string& last_email,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 base::string16 ConfirmEmailDialogDelegate::GetCancelButtonTitle() { 183 base::string16 ConfirmEmailDialogDelegate::GetCancelButtonTitle() {
191 return l10n_util::GetStringUTF16( 184 return l10n_util::GetStringUTF16(
192 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); 185 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON);
193 } 186 }
194 187
195 base::string16 ConfirmEmailDialogDelegate::GetLinkText() const { 188 base::string16 ConfirmEmailDialogDelegate::GetLinkText() const {
196 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 189 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
197 } 190 }
198 191
199 void ConfirmEmailDialogDelegate::OnAccepted() { 192 void ConfirmEmailDialogDelegate::OnAccepted() {
200 base::ResetAndReturn(&callback_).Run(CREATE_NEW_USER); 193 base::ResetAndReturn(&callback_).Run(InlineSigninHelper::CREATE_NEW_USER);
201 } 194 }
202 195
203 void ConfirmEmailDialogDelegate::OnCanceled() { 196 void ConfirmEmailDialogDelegate::OnCanceled() {
204 base::ResetAndReturn(&callback_).Run(START_SYNC); 197 base::ResetAndReturn(&callback_).Run(InlineSigninHelper::START_SYNC);
205 } 198 }
206 199
207 void ConfirmEmailDialogDelegate::OnClosed() { 200 void ConfirmEmailDialogDelegate::OnClosed() {
208 base::ResetAndReturn(&callback_).Run(CLOSE); 201 base::ResetAndReturn(&callback_).Run(InlineSigninHelper::CLOSE);
209 } 202 }
210 203
211 void ConfirmEmailDialogDelegate::OnLinkClicked( 204 void ConfirmEmailDialogDelegate::OnLinkClicked(
212 WindowOpenDisposition disposition) { 205 WindowOpenDisposition disposition) {
213 content::OpenURLParams params( 206 content::OpenURLParams params(
214 GURL(chrome::kChromeSyncMergeTroubleshootingURL), 207 GURL(chrome::kChromeSyncMergeTroubleshootingURL),
215 content::Referrer(), 208 content::Referrer(),
216 NEW_POPUP, 209 NEW_POPUP,
217 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 210 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
218 false); 211 false);
219 // It is guaranteed that |web_contents_| is valid here because when it's 212 // It is guaranteed that |web_contents_| is valid here because when it's
220 // deleted, the dialog is immediately closed and no further action can be 213 // deleted, the dialog is immediately closed and no further action can be
221 // performed. 214 // performed.
222 web_contents_->OpenURL(params); 215 web_contents_->OpenURL(params);
223 } 216 }
224 217
225 class InlineSigninHelper : public GaiaAuthConsumer { 218 } // namespace
226 public:
227 InlineSigninHelper(
228 base::WeakPtr<InlineLoginHandlerImpl> handler,
229 net::URLRequestContextGetter* getter,
230 Profile* profile,
231 const GURL& current_url,
232 const std::string& email,
233 const std::string& gaia_id,
234 const std::string& password,
235 const std::string& session_index,
236 const std::string& signin_scoped_device_id,
237 bool choose_what_to_sync,
238 bool confirm_untrusted_signin);
239
240 private:
241 // Handles cross account sign in error. If the supplied |email| does not match
242 // the last signed in email of the current profile, then Chrome will show a
243 // confirmation dialog before starting sync. It returns true if there is a
244 // cross account error, and false otherwise.
245 bool HandleCrossAccountError(
246 const std::string& refresh_token,
247 signin_metrics::Source source,
248 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
249 OneClickSigninSyncStarter::StartSyncMode start_mode);
250
251 // Callback used with ConfirmEmailDialogDelegate.
252 void ConfirmEmailAction(
253 content::WebContents* web_contents,
254 const std::string& refresh_token,
255 signin_metrics::Source source,
256 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
257 OneClickSigninSyncStarter::StartSyncMode start_mode,
258 ConfirmEmailDialogDelegate::Action action);
259
260 // Overridden from GaiaAuthConsumer.
261 void OnClientOAuthSuccess(const ClientOAuthResult& result) override;
262 void OnClientOAuthFailure(const GoogleServiceAuthError& error)
263 override;
264
265 GaiaAuthFetcher gaia_auth_fetcher_;
266 base::WeakPtr<InlineLoginHandlerImpl> handler_;
267 Profile* profile_;
268 GURL current_url_;
269 std::string email_;
270 std::string gaia_id_;
271 std::string password_;
272 std::string session_index_;
273 bool choose_what_to_sync_;
274 bool confirm_untrusted_signin_;
275
276 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper);
277 };
278 219
279 InlineSigninHelper::InlineSigninHelper( 220 InlineSigninHelper::InlineSigninHelper(
280 base::WeakPtr<InlineLoginHandlerImpl> handler, 221 base::WeakPtr<InlineLoginHandlerImpl> handler,
281 net::URLRequestContextGetter* getter, 222 net::URLRequestContextGetter* getter,
282 Profile* profile, 223 Profile* profile,
283 const GURL& current_url, 224 const GURL& current_url,
284 const std::string& email, 225 const std::string& email,
285 const std::string& gaia_id, 226 const std::string& gaia_id,
286 const std::string& password, 227 const std::string& password,
287 const std::string& session_index, 228 const std::string& session_index,
229 const std::string& auth_code,
288 const std::string& signin_scoped_device_id, 230 const std::string& signin_scoped_device_id,
289 bool choose_what_to_sync, 231 bool choose_what_to_sync,
290 bool confirm_untrusted_signin) 232 bool confirm_untrusted_signin)
291 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), 233 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter),
292 handler_(handler), 234 handler_(handler),
293 profile_(profile), 235 profile_(profile),
294 current_url_(current_url), 236 current_url_(current_url),
295 email_(email), 237 email_(email),
296 gaia_id_(gaia_id), 238 gaia_id_(gaia_id),
297 password_(password), 239 password_(password),
298 session_index_(session_index), 240 session_index_(session_index),
241 auth_code_(auth_code),
299 choose_what_to_sync_(choose_what_to_sync), 242 choose_what_to_sync_(choose_what_to_sync),
300 confirm_untrusted_signin_(confirm_untrusted_signin) { 243 confirm_untrusted_signin_(confirm_untrusted_signin) {
301 DCHECK(profile_); 244 DCHECK(profile_);
302 DCHECK(!email_.empty()); 245 DCHECK(!email_.empty());
303 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( 246 if (!auth_code_.empty()) {
304 session_index, signin_scoped_device_id); 247 gaia_auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId(
248 auth_code, signin_scoped_device_id);
249 } else {
250 DCHECK(!session_index_.empty());
251 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId(
252 session_index_, signin_scoped_device_id);
253 }
305 } 254 }
306 255
256 InlineSigninHelper::~InlineSigninHelper() {}
257
307 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { 258 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) {
308 content::WebContents* contents = NULL; 259 content::WebContents* contents = NULL;
309 Browser* browser = NULL; 260 Browser* browser = NULL;
310 if (handler_) { 261 if (handler_) {
311 contents = handler_->web_ui()->GetWebContents(); 262 contents = handler_->web_ui()->GetWebContents();
312 browser = handler_->GetDesktopBrowser(); 263 browser = handler_->GetDesktopBrowser();
313 } 264 }
314 265
315 AboutSigninInternals* about_signin_internals = 266 AboutSigninInternals* about_signin_internals =
316 AboutSigninInternalsFactory::GetForProfile(profile_); 267 AboutSigninInternalsFactory::GetForProfile(profile_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 320 }
370 321
371 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required = 322 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required =
372 confirm_untrusted_signin_ ? 323 confirm_untrusted_signin_ ?
373 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN : 324 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN :
374 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; 325 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
375 326
376 bool start_signin = !HandleCrossAccountError(result.refresh_token, source, 327 bool start_signin = !HandleCrossAccountError(result.refresh_token, source,
377 confirmation_required, start_mode); 328 confirmation_required, start_mode);
378 if (start_signin) { 329 if (start_signin) {
379 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. 330 CreateSyncStarter(browser,
380 // OneClickSigninSyncStarter will delete itself once the job is done. 331 contents,
381 new OneClickSigninSyncStarter( 332 signin::GetNextPageURLForPromoURL(current_url_),
382 profile_, browser, 333 result.refresh_token,
383 gaia_id_, email_, password_, result.refresh_token, 334 start_mode,
384 start_mode, 335 confirmation_required);
385 contents,
386 confirmation_required,
387 signin::GetNextPageURLForPromoURL(current_url_),
388 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
389 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 336 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
390 } 337 }
391 } 338 }
392 } 339 }
393 340
341 void InlineSigninHelper::CreateSyncStarter(
342 Browser* browser,
343 content::WebContents* contents,
344 const GURL& url,
345 const std::string& refresh_token,
346 OneClickSigninSyncStarter::StartSyncMode start_mode,
347 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required) {
348 // OneClickSigninSyncStarter will delete itself once the job is done.
349 new OneClickSigninSyncStarter(
350 profile_, browser,
351 gaia_id_, email_, password_, refresh_token,
352 start_mode,
353 contents,
354 confirmation_required,
355 url,
356 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
357 }
358
394 bool InlineSigninHelper::HandleCrossAccountError( 359 bool InlineSigninHelper::HandleCrossAccountError(
395 const std::string& refresh_token, 360 const std::string& refresh_token,
396 signin_metrics::Source source, 361 signin_metrics::Source source,
397 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, 362 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
398 OneClickSigninSyncStarter::StartSyncMode start_mode) { 363 OneClickSigninSyncStarter::StartSyncMode start_mode) {
399 std::string last_email = 364 std::string last_email =
400 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); 365 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername);
401 366
402 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_)) 367 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_))
403 return false; 368 return false;
(...skipping 16 matching lines...) Expand all
420 start_mode)); 385 start_mode));
421 return true; 386 return true;
422 } 387 }
423 388
424 void InlineSigninHelper::ConfirmEmailAction( 389 void InlineSigninHelper::ConfirmEmailAction(
425 content::WebContents* web_contents, 390 content::WebContents* web_contents,
426 const std::string& refresh_token, 391 const std::string& refresh_token,
427 signin_metrics::Source source, 392 signin_metrics::Source source,
428 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, 393 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
429 OneClickSigninSyncStarter::StartSyncMode start_mode, 394 OneClickSigninSyncStarter::StartSyncMode start_mode,
430 ConfirmEmailDialogDelegate::Action action) { 395 InlineSigninHelper::Action action) {
431 Browser* browser = chrome::FindLastActiveWithProfile( 396 Browser* browser = chrome::FindLastActiveWithProfile(
432 profile_, chrome::GetActiveDesktop()); 397 profile_, chrome::GetActiveDesktop());
433 switch (action) { 398 switch (action) {
434 case ConfirmEmailDialogDelegate::CREATE_NEW_USER: 399 case InlineSigninHelper::CREATE_NEW_USER:
435 if (handler_) { 400 if (handler_) {
436 handler_->SyncStarterCallback( 401 handler_->SyncStarterCallback(
437 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); 402 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
438 } 403 }
439 chrome::ShowSettingsSubPage(browser, 404 chrome::ShowSettingsSubPage(browser,
440 std::string(chrome::kCreateProfileSubPage)); 405 std::string(chrome::kCreateProfileSubPage));
441 break; 406 break;
442 case ConfirmEmailDialogDelegate::START_SYNC: 407 case InlineSigninHelper::START_SYNC:
443 new OneClickSigninSyncStarter( 408 CreateSyncStarter(browser, web_contents, GURL(), refresh_token,
444 profile_, browser, gaia_id_, email_, password_, refresh_token, 409 start_mode, confirmation_required);
445 start_mode, web_contents, confirmation_required, GURL(),
446 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
447 break; 410 break;
448 case ConfirmEmailDialogDelegate::CLOSE: 411 case InlineSigninHelper::CLOSE:
449 if (handler_) { 412 if (handler_) {
450 handler_->SyncStarterCallback( 413 handler_->SyncStarterCallback(
451 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); 414 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
452 } 415 }
453 break; 416 break;
454 default: 417 default:
455 DCHECK(false) << "Invalid action"; 418 DCHECK(false) << "Invalid action";
456 } 419 }
457 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 420 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
458 } 421 }
459 422
460 void InlineSigninHelper::OnClientOAuthFailure( 423 void InlineSigninHelper::OnClientOAuthFailure(
461 const GoogleServiceAuthError& error) { 424 const GoogleServiceAuthError& error) {
462 if (handler_) 425 if (handler_)
463 handler_->HandleLoginError(error.ToString()); 426 handler_->HandleLoginError(error.ToString());
464 427
465 AboutSigninInternals* about_signin_internals = 428 AboutSigninInternals* about_signin_internals =
466 AboutSigninInternalsFactory::GetForProfile(profile_); 429 AboutSigninInternalsFactory::GetForProfile(profile_);
467 about_signin_internals->OnRefreshTokenReceived("Failure"); 430 about_signin_internals->OnRefreshTokenReceived("Failure");
468 431
469 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 432 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
470 } 433 }
471 434
472 } // namespace
473
474 InlineLoginHandlerImpl::InlineLoginHandlerImpl() 435 InlineLoginHandlerImpl::InlineLoginHandlerImpl()
475 : confirm_untrusted_signin_(false), 436 : confirm_untrusted_signin_(false),
476 weak_factory_(this) { 437 weak_factory_(this) {
477 } 438 }
478 439
479 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} 440 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {}
480 441
481 // This method is not called with webview sign in enabled. 442 // This method is not called with webview sign in enabled.
482 void InlineLoginHandlerImpl::DidCommitProvisionalLoadForFrame( 443 void InlineLoginHandlerImpl::DidCommitProvisionalLoadForFrame(
483 content::RenderFrameHost* render_frame_host, 444 content::RenderFrameHost* render_frame_host,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { 551 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
591 params.SetString("service", "chromiumsync"); 552 params.SetString("service", "chromiumsync");
592 553
593 // If this was called from the user manager to reauthenticate the profile, 554 // If this was called from the user manager to reauthenticate the profile,
594 // make sure the webui is aware. 555 // make sure the webui is aware.
595 Profile* profile = Profile::FromWebUI(web_ui()); 556 Profile* profile = Profile::FromWebUI(web_ui());
596 if (IsSystemProfile(profile)) 557 if (IsSystemProfile(profile))
597 params.SetBoolean("dontResizeNonEmbeddedPages", true); 558 params.SetBoolean("dontResizeNonEmbeddedPages", true);
598 559
599 content::WebContents* contents = web_ui()->GetWebContents(); 560 content::WebContents* contents = web_ui()->GetWebContents();
561 const GURL& current_url = contents->GetURL();
562 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
563
564 std::string is_constrained;
565 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
566
567 // Use new embedded flow if in constrained window.
568 if (is_constrained == "1") {
569 const bool is_new_gaia_flow = switches::UsePasswordSeparatedSigninFlow();
570 const GURL& url = is_new_gaia_flow
571 ? GaiaUrls::GetInstance()->embedded_signin_url()
572 : GaiaUrls::GetInstance()->password_combined_embedded_signin_url();
573 params.SetBoolean("isNewGaiaFlow", is_new_gaia_flow);
574 params.SetString("clientId",
575 GaiaUrls::GetInstance()->oauth2_chrome_client_id());
576 params.SetString("gaiaPath", url.path().substr(1));
577
578 std::string flow;
579 switch (source) {
580 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT:
581 flow = "addaccount";
582 break;
583 case signin_metrics::SOURCE_REAUTH:
584 flow = "reauth";
585 break;
586 default:
587 flow = "signin";
588 break;
589 }
590 params.SetString("flow", flow);
591 }
592
600 content::WebContentsObserver::Observe(contents); 593 content::WebContentsObserver::Observe(contents);
601 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); 594 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN);
602 } 595 }
603 596
604 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { 597 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
605 content::WebContents* contents = web_ui()->GetWebContents(); 598 content::WebContents* contents = web_ui()->GetWebContents();
606 const GURL& current_url = contents->GetURL(); 599 const GURL& current_url = contents->GetURL();
607 600
608 const base::DictionaryValue* dict = NULL; 601 const base::DictionaryValue* dict = NULL;
609 args->GetDictionary(0, &dict); 602 args->GetDictionary(0, &dict);
(...skipping 18 matching lines...) Expand all
628 621
629 base::string16 password_string16; 622 base::string16 password_string16;
630 dict->GetString("password", &password_string16); 623 dict->GetString("password", &password_string16);
631 std::string password(base::UTF16ToASCII(password_string16)); 624 std::string password(base::UTF16ToASCII(password_string16));
632 625
633 base::string16 gaia_id_string16; 626 base::string16 gaia_id_string16;
634 dict->GetString("gaiaId", &gaia_id_string16); 627 dict->GetString("gaiaId", &gaia_id_string16);
635 DCHECK(!gaia_id_string16.empty()); 628 DCHECK(!gaia_id_string16.empty());
636 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); 629 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16);
637 630
631 std::string is_constrained;
632 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
633 const bool is_password_separated_signin_flow = is_constrained == "1" &&
634 switches::UsePasswordSeparatedSigninFlow();
635
638 base::string16 session_index_string16; 636 base::string16 session_index_string16;
639 dict->GetString("sessionIndex", &session_index_string16); 637 dict->GetString("sessionIndex", &session_index_string16);
640 std::string session_index = base::UTF16ToASCII(session_index_string16); 638 std::string session_index = base::UTF16ToASCII(session_index_string16);
641 DCHECK(!session_index.empty()); 639 DCHECK(is_password_separated_signin_flow || !session_index.empty());
640
641 base::string16 auth_code_string16;
642 dict->GetString("authCode", &auth_code_string16);
643 std::string auth_code = base::UTF16ToASCII(auth_code_string16);
644 DCHECK(!is_password_separated_signin_flow || !auth_code.empty());
642 645
643 bool choose_what_to_sync = false; 646 bool choose_what_to_sync = false;
644 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); 647 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync);
645 648
646 content::StoragePartition* partition = 649 content::StoragePartition* partition =
647 content::BrowserContext::GetStoragePartitionForSite( 650 content::BrowserContext::GetStoragePartitionForSite(
648 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); 651 contents->GetBrowserContext(), signin::GetSigninPartitionURL());
649 652
650 // If this was called from the user manager to reauthenticate the profile, 653 // If this was called from the user manager to reauthenticate the profile,
651 // the current profile is the system profile. In this case, use the email to 654 // the current profile is the system profile. In this case, use the email to
652 // find the right profile to reauthenticate. Otherwise the profile can be 655 // find the right profile to reauthenticate. Otherwise the profile can be
653 // taken from web_ui(). 656 // taken from web_ui().
654 Profile* profile = Profile::FromWebUI(web_ui()); 657 Profile* profile = Profile::FromWebUI(web_ui());
655 if (IsSystemProfile(profile)) { 658 if (IsSystemProfile(profile)) {
656 // Switch to the profile and finish the login. Don't pass a handler pointer 659 // Switch to the profile and finish the login. Don't pass a handler pointer
657 // since it will be destroyed before the callback runs. 660 // since it will be destroyed before the callback runs.
658 ProfileManager* manager = g_browser_process->profile_manager(); 661 ProfileManager* manager = g_browser_process->profile_manager();
659 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email); 662 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email);
660 if (!path.empty()) { 663 if (!path.empty()) {
661 FinishCompleteLoginParams params(nullptr, partition, current_url, path, 664 FinishCompleteLoginParams params(nullptr, partition, current_url, path,
662 confirm_untrusted_signin_, email, 665 confirm_untrusted_signin_, email,
663 gaia_id, password, session_index, 666 gaia_id, password, session_index,
664 choose_what_to_sync); 667 auth_code, choose_what_to_sync);
665 ProfileManager::CreateCallback callback = base::Bind( 668 ProfileManager::CreateCallback callback = base::Bind(
666 &InlineLoginHandlerImpl::FinishCompleteLogin, params); 669 &InlineLoginHandlerImpl::FinishCompleteLogin, params);
667 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, 670 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true,
668 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK); 671 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK);
669 } 672 }
670 } else { 673 } else {
671 FinishCompleteLogin( 674 FinishCompleteLogin(
672 FinishCompleteLoginParams(this, partition, current_url, 675 FinishCompleteLoginParams(this, partition, current_url,
673 base::FilePath(), confirm_untrusted_signin_, 676 base::FilePath(), confirm_untrusted_signin_,
674 email, gaia_id, password, session_index, 677 email, gaia_id, password, session_index,
675 choose_what_to_sync), 678 auth_code, choose_what_to_sync),
676 profile, 679 profile,
677 Profile::CREATE_STATUS_CREATED); 680 Profile::CREATE_STATUS_CREATED);
678 } 681 }
679 } 682 }
680 683
681 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( 684 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams(
682 InlineLoginHandlerImpl* handler, 685 InlineLoginHandlerImpl* handler,
683 content::StoragePartition* partition, 686 content::StoragePartition* partition,
684 const GURL& url, 687 const GURL& url,
685 const base::FilePath& profile_path, 688 const base::FilePath& profile_path,
686 bool confirm_untrusted_signin, 689 bool confirm_untrusted_signin,
687 const std::string& email, 690 const std::string& email,
688 const std::string& gaia_id, 691 const std::string& gaia_id,
689 const std::string& password, 692 const std::string& password,
690 const std::string& session_index, 693 const std::string& session_index,
694 const std::string& auth_code,
691 bool choose_what_to_sync) 695 bool choose_what_to_sync)
692 : handler(handler), 696 : handler(handler),
693 partition(partition), 697 partition(partition),
694 url(url), 698 url(url),
695 profile_path(profile_path), 699 profile_path(profile_path),
696 confirm_untrusted_signin(confirm_untrusted_signin), 700 confirm_untrusted_signin(confirm_untrusted_signin),
697 email(email), 701 email(email),
698 gaia_id(gaia_id), 702 gaia_id(gaia_id),
699 password(password), 703 password(password),
700 session_index(session_index), 704 session_index(session_index),
705 auth_code(auth_code),
701 choose_what_to_sync(choose_what_to_sync) {} 706 choose_what_to_sync(choose_what_to_sync) {}
702 707
703 InlineLoginHandlerImpl:: 708 InlineLoginHandlerImpl::
704 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} 709 FinishCompleteLoginParams::~FinishCompleteLoginParams() {}
705 710
706 // static 711 // static
707 void InlineLoginHandlerImpl::FinishCompleteLogin( 712 void InlineLoginHandlerImpl::FinishCompleteLogin(
708 const FinishCompleteLoginParams& params, 713 const FinishCompleteLoginParams& params,
709 Profile* profile, 714 Profile* profile,
710 Profile::CreateStatus status) { 715 Profile::CreateStatus status) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 signin_client->GetSigninScopedDeviceId(); 779 signin_client->GetSigninScopedDeviceId();
775 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; 780 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr;
776 if (params.handler) 781 if (params.handler)
777 handler_weak_ptr = params.handler->GetWeakPtr(); 782 handler_weak_ptr = params.handler->GetWeakPtr();
778 783
779 // InlineSigninHelper will delete itself. 784 // InlineSigninHelper will delete itself.
780 new InlineSigninHelper(handler_weak_ptr, 785 new InlineSigninHelper(handler_weak_ptr,
781 params.partition->GetURLRequestContext(), profile, 786 params.partition->GetURLRequestContext(), profile,
782 params.url, 787 params.url,
783 params.email, params.gaia_id, params.password, 788 params.email, params.gaia_id, params.password,
784 params.session_index, signin_scoped_device_id, 789 params.session_index, params.auth_code,
790 signin_scoped_device_id,
785 params.choose_what_to_sync, 791 params.choose_what_to_sync,
786 params.confirm_untrusted_signin); 792 params.confirm_untrusted_signin);
787 793
788 // If opened from user manager to reauthenticate, make sure the user manager 794 // If opened from user manager to reauthenticate, make sure the user manager
789 // is closed and that the profile is marked as unlocked. 795 // is closed and that the profile is marked as unlocked.
790 if (!params.profile_path.empty()) { 796 if (!params.profile_path.empty()) {
791 UserManager::Hide(); 797 UserManager::Hide();
792 ProfileManager* profile_manager = g_browser_process->profile_manager(); 798 ProfileManager* profile_manager = g_browser_process->profile_manager();
793 if (profile_manager) { 799 if (profile_manager) {
794 ProfileAttributesEntry* entry; 800 ProfileAttributesEntry* entry;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 871 }
866 } 872 }
867 873
868 if (show_account_management) { 874 if (show_account_management) {
869 browser->window()->ShowAvatarBubbleFromAvatarButton( 875 browser->window()->ShowAvatarBubbleFromAvatarButton(
870 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, 876 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
871 signin::ManageAccountsParams()); 877 signin::ManageAccountsParams());
872 } 878 }
873 } 879 }
874 } 880 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698