OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/one_click_signin_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 GaiaUrls::GetInstance()->service_login_url().ReplaceComponents( | 407 GaiaUrls::GetInstance()->service_login_url().ReplaceComponents( |
408 replacements); | 408 replacements); |
409 | 409 |
410 return (url.ReplaceComponents(replacements) == clean_login_url && | 410 return (url.ReplaceComponents(replacements) == clean_login_url && |
411 source != signin::SOURCE_UNKNOWN) || | 411 source != signin::SOURCE_UNKNOWN) || |
412 (IsValidGaiaSigninRedirectOrResponseURL(url) && | 412 (IsValidGaiaSigninRedirectOrResponseURL(url) && |
413 url.spec().find("ChromeLoginPrompt") != std::string::npos && | 413 url.spec().find("ChromeLoginPrompt") != std::string::npos && |
414 !email.empty()); | 414 !email.empty()); |
415 } | 415 } |
416 | 416 |
417 // Gets signin scoped device id from signin client if profile is valid. | 417 // If profile is valid then get signin scoped device id from signin client. |
418 // Otherwise returns empty string. | 418 // Otherwise returns empty string. |
419 std::string GetSigninScopedDeviceId(Profile* profile) { | 419 std::string GetSigninScopedDeviceId(Profile* profile) { |
420 std::string signin_scoped_device_id; | 420 std::string signin_scoped_device_id; |
421 SigninClient* signin_client = | 421 SigninClient* signin_client = |
422 profile ? ChromeSigninClientFactory::GetForProfile(profile) : NULL; | 422 profile ? ChromeSigninClientFactory::GetForProfile(profile) : NULL; |
423 if (signin_client) { | 423 if (signin_client) { |
424 signin_scoped_device_id = signin_client->GetSigninScopedDeviceId(); | 424 signin_scoped_device_id = signin_client->GetSigninScopedDeviceId(); |
425 } | 425 } |
426 return signin_scoped_device_id; | 426 return signin_scoped_device_id; |
427 } | 427 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 source(signin::SOURCE_UNKNOWN) {} | 509 source(signin::SOURCE_UNKNOWN) {} |
510 | 510 |
511 OneClickSigninHelper::StartSyncArgs::StartSyncArgs( | 511 OneClickSigninHelper::StartSyncArgs::StartSyncArgs( |
512 Profile* profile, | 512 Profile* profile, |
513 Browser* browser, | 513 Browser* browser, |
514 OneClickSigninHelper::AutoAccept auto_accept, | 514 OneClickSigninHelper::AutoAccept auto_accept, |
515 const std::string& session_index, | 515 const std::string& session_index, |
516 const std::string& email, | 516 const std::string& email, |
517 const std::string& password, | 517 const std::string& password, |
518 const std::string& refresh_token, | 518 const std::string& refresh_token, |
519 const std::string& signin_scoped_device_id, | |
520 content::WebContents* web_contents, | 519 content::WebContents* web_contents, |
521 bool untrusted_confirmation_required, | 520 bool untrusted_confirmation_required, |
522 signin::Source source, | 521 signin::Source source, |
523 OneClickSigninSyncStarter::Callback callback) | 522 OneClickSigninSyncStarter::Callback callback) |
524 : profile(profile), | 523 : profile(profile), |
525 browser(browser), | 524 browser(browser), |
526 auto_accept(auto_accept), | 525 auto_accept(auto_accept), |
527 session_index(session_index), | 526 session_index(session_index), |
528 email(email), | 527 email(email), |
529 password(password), | 528 password(password), |
530 refresh_token(refresh_token), | 529 refresh_token(refresh_token), |
531 signin_scoped_device_id(signin_scoped_device_id), | |
532 web_contents(web_contents), | 530 web_contents(web_contents), |
533 source(source), | 531 source(source), |
534 callback(callback) { | 532 callback(callback) { |
535 DCHECK(session_index.empty() != refresh_token.empty()); | 533 DCHECK(session_index.empty() != refresh_token.empty()); |
536 if (untrusted_confirmation_required) { | 534 if (untrusted_confirmation_required) { |
537 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; | 535 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; |
538 } else if (source == signin::SOURCE_SETTINGS || | 536 } else if (source == signin::SOURCE_SETTINGS || |
539 source == signin::SOURCE_WEBSTORE_INSTALL) { | 537 source == signin::SOURCE_WEBSTORE_INSTALL) { |
540 // Do not display a status confirmation for webstore installs or re-auth. | 538 // Do not display a status confirmation for webstore installs or re-auth. |
541 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; | 539 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 args_.browser, args_.profile, desktop_type_); | 652 args_.browser, args_.profile, desktop_type_); |
655 args_.browser->window()->ShowOneClickSigninBubble( | 653 args_.browser->window()->ShowOneClickSigninBubble( |
656 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 654 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
657 base::string16(), // No email required - this is not a SAML confirmation. | 655 base::string16(), // No email required - this is not a SAML confirmation. |
658 base::UTF8ToUTF16(error_message), | 656 base::UTF8ToUTF16(error_message), |
659 // Callback is ignored. | 657 // Callback is ignored. |
660 BrowserWindow::StartSyncCallback()); | 658 BrowserWindow::StartSyncCallback()); |
661 } | 659 } |
662 | 660 |
663 void OneClickSigninHelper::SyncStarterWrapper::StartSigninOAuthHelper() { | 661 void OneClickSigninHelper::SyncStarterWrapper::StartSigninOAuthHelper() { |
| 662 std::string signin_scoped_device_id = GetSigninScopedDeviceId(args_.profile); |
664 signin_oauth_helper_.reset( | 663 signin_oauth_helper_.reset( |
665 new SigninOAuthHelper(args_.profile->GetRequestContext(), | 664 new SigninOAuthHelper(args_.profile->GetRequestContext(), |
666 args_.session_index, | 665 args_.session_index, |
667 args_.signin_scoped_device_id, | 666 signin_scoped_device_id, |
668 this)); | 667 this)); |
669 } | 668 } |
670 | 669 |
671 void | 670 void |
672 OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( | 671 OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( |
673 const std::string& email, | 672 const std::string& email, |
674 const std::string& refresh_token) { | 673 const std::string& refresh_token) { |
675 // The starter deletes itself once it's done. | 674 // The starter deletes itself once it's done. |
676 new OneClickSigninSyncStarter(args_.profile, args_.browser, | 675 new OneClickSigninSyncStarter(args_.profile, args_.browser, |
677 email, args_.password, | 676 email, args_.password, |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 const std::string& password, | 1173 const std::string& password, |
1175 const std::string& refresh_token, | 1174 const std::string& refresh_token, |
1176 OneClickSigninHelper::AutoAccept auto_accept, | 1175 OneClickSigninHelper::AutoAccept auto_accept, |
1177 signin::Source source, | 1176 signin::Source source, |
1178 OneClickSigninSyncStarter::StartSyncMode start_mode, | 1177 OneClickSigninSyncStarter::StartSyncMode start_mode, |
1179 OneClickSigninSyncStarter::Callback sync_callback) { | 1178 OneClickSigninSyncStarter::Callback sync_callback) { |
1180 Profile* profile = | 1179 Profile* profile = |
1181 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1180 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1182 std::string last_email = | 1181 std::string last_email = |
1183 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1182 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
1184 std::string signin_scoped_device_id = GetSigninScopedDeviceId(profile); | |
1185 | 1183 |
1186 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) { | 1184 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) { |
1187 // If the new email address is different from the email address that | 1185 // If the new email address is different from the email address that |
1188 // just signed in, show a confirmation dialog. | 1186 // just signed in, show a confirmation dialog. |
1189 | 1187 |
1190 // No need to display a second confirmation so pass false below. | 1188 // No need to display a second confirmation so pass false below. |
1191 // TODO(atwilson): Move this into OneClickSigninSyncStarter. | 1189 // TODO(atwilson): Move this into OneClickSigninSyncStarter. |
1192 // The tab modal dialog always executes its callback before |contents| | 1190 // The tab modal dialog always executes its callback before |contents| |
1193 // is deleted. | 1191 // is deleted. |
1194 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1192 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
1195 ConfirmEmailDialogDelegate::AskForConfirmation( | 1193 ConfirmEmailDialogDelegate::AskForConfirmation( |
1196 contents, | 1194 contents, |
1197 last_email, | 1195 last_email, |
1198 email, | 1196 email, |
1199 base::Bind( | 1197 base::Bind( |
1200 &StartExplicitSync, | 1198 &StartExplicitSync, |
1201 StartSyncArgs(profile, browser, auto_accept, | 1199 StartSyncArgs(profile, browser, auto_accept, |
1202 session_index, email, password, | 1200 session_index, email, password, |
1203 refresh_token, signin_scoped_device_id, | 1201 refresh_token, |
1204 contents, false /* confirmation_required */, source, | 1202 contents, false /* confirmation_required */, source, |
1205 sync_callback), | 1203 sync_callback), |
1206 contents, | 1204 contents, |
1207 start_mode)); | 1205 start_mode)); |
1208 return true; | 1206 return true; |
1209 } | 1207 } |
1210 | 1208 |
1211 return false; | 1209 return false; |
1212 } | 1210 } |
1213 | 1211 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 switched_to_advanced_ = source == signin::SOURCE_SETTINGS; | 1478 switched_to_advanced_ = source == signin::SOURCE_SETTINGS; |
1481 } | 1479 } |
1482 } | 1480 } |
1483 | 1481 |
1484 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1482 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
1485 | 1483 |
1486 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." | 1484 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." |
1487 << " auto_accept=" << auto_accept_ | 1485 << " auto_accept=" << auto_accept_ |
1488 << " source=" << source_; | 1486 << " source=" << source_; |
1489 | 1487 |
1490 std::string signin_scoped_device_id = GetSigninScopedDeviceId(profile); | |
1491 switch (auto_accept_) { | 1488 switch (auto_accept_) { |
1492 case AUTO_ACCEPT_NONE: | 1489 case AUTO_ACCEPT_NONE: |
1493 if (showing_signin_) | 1490 if (showing_signin_) |
1494 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); | 1491 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); |
1495 break; | 1492 break; |
1496 case AUTO_ACCEPT_ACCEPTED: | 1493 case AUTO_ACCEPT_ACCEPTED: |
1497 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1494 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1498 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1495 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
1499 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); | 1496 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); |
1500 // Start syncing with the default settings - prompt the user to sign in | 1497 // Start syncing with the default settings - prompt the user to sign in |
1501 // first. | 1498 // first. |
1502 if (!do_not_start_sync_for_testing_) { | 1499 if (!do_not_start_sync_for_testing_) { |
1503 StartSync( | 1500 StartSync( |
1504 StartSyncArgs(profile, browser, auto_accept_, | 1501 StartSyncArgs(profile, browser, auto_accept_, |
1505 session_index_, email_, password_, | 1502 session_index_, email_, password_, "", |
1506 "", signin_scoped_device_id, | |
1507 NULL /* don't force sync setup in same tab */, | 1503 NULL /* don't force sync setup in same tab */, |
1508 true /* confirmation_required */, source_, | 1504 true /* confirmation_required */, source_, |
1509 CreateSyncStarterCallback()), | 1505 CreateSyncStarterCallback()), |
1510 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 1506 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
1511 } | 1507 } |
1512 break; | 1508 break; |
1513 case AUTO_ACCEPT_CONFIGURE: | 1509 case AUTO_ACCEPT_CONFIGURE: |
1514 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1510 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1515 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1511 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); |
1516 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); | 1512 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); |
1517 // Display the extra confirmation (even in the SAML case) in case this | 1513 // Display the extra confirmation (even in the SAML case) in case this |
1518 // was an untrusted renderer. | 1514 // was an untrusted renderer. |
1519 if (!do_not_start_sync_for_testing_) { | 1515 if (!do_not_start_sync_for_testing_) { |
1520 StartSync( | 1516 StartSync( |
1521 StartSyncArgs(profile, browser, auto_accept_, | 1517 StartSyncArgs(profile, browser, auto_accept_, |
1522 session_index_, email_, password_, | 1518 session_index_, email_, password_, "", |
1523 "", signin_scoped_device_id, | |
1524 NULL /* don't force sync setup in same tab */, | 1519 NULL /* don't force sync setup in same tab */, |
1525 true /* confirmation_required */, source_, | 1520 true /* confirmation_required */, source_, |
1526 CreateSyncStarterCallback()), | 1521 CreateSyncStarterCallback()), |
1527 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1522 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
1528 } | 1523 } |
1529 break; | 1524 break; |
1530 case AUTO_ACCEPT_EXPLICIT: { | 1525 case AUTO_ACCEPT_EXPLICIT: { |
1531 signin::Source original_source = | 1526 signin::Source original_source = |
1532 signin::GetSourceForPromoURL(original_continue_url_); | 1527 signin::GetSourceForPromoURL(original_continue_url_); |
1533 if (switched_to_advanced_) { | 1528 if (switched_to_advanced_) { |
(...skipping 25 matching lines...) Expand all Loading... |
1559 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : | 1554 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : |
1560 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1555 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
1561 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1556 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
1562 | 1557 |
1563 if (!HandleCrossAccountError(contents, session_index_, email_, password_, | 1558 if (!HandleCrossAccountError(contents, session_index_, email_, password_, |
1564 "", auto_accept_, source_, start_mode, | 1559 "", auto_accept_, source_, start_mode, |
1565 CreateSyncStarterCallback())) { | 1560 CreateSyncStarterCallback())) { |
1566 if (!do_not_start_sync_for_testing_) { | 1561 if (!do_not_start_sync_for_testing_) { |
1567 StartSync( | 1562 StartSync( |
1568 StartSyncArgs(profile, browser, auto_accept_, | 1563 StartSyncArgs(profile, browser, auto_accept_, |
1569 session_index_, email_, password_, | 1564 session_index_, email_, password_, "", |
1570 "", signin_scoped_device_id, | |
1571 contents, | 1565 contents, |
1572 untrusted_confirmation_required_, source_, | 1566 untrusted_confirmation_required_, source_, |
1573 CreateSyncStarterCallback()), | 1567 CreateSyncStarterCallback()), |
1574 start_mode); | 1568 start_mode); |
1575 } | 1569 } |
1576 | 1570 |
1577 // If this explicit sign in is not from settings page/webstore, show | 1571 // If this explicit sign in is not from settings page/webstore, show |
1578 // the NTP/Apps page after sign in completes. In the case of the | 1572 // the NTP/Apps page after sign in completes. In the case of the |
1579 // settings page, it will get auto-closed after sync setup. In the case | 1573 // settings page, it will get auto-closed after sync setup. In the case |
1580 // of webstore, it will redirect back to webstore. | 1574 // of webstore, it will redirect back to webstore. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 // If the web contents is showing a blank page and not about to be closed, | 1617 // If the web contents is showing a blank page and not about to be closed, |
1624 // redirect to the NTP or apps page. | 1618 // redirect to the NTP or apps page. |
1625 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1619 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1626 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1620 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1627 RedirectToNtpOrAppsPage( | 1621 RedirectToNtpOrAppsPage( |
1628 web_contents(), | 1622 web_contents(), |
1629 signin::GetSourceForPromoURL(original_continue_url_)); | 1623 signin::GetSourceForPromoURL(original_continue_url_)); |
1630 } | 1624 } |
1631 } | 1625 } |
1632 } | 1626 } |
OLD | NEW |