Chromium Code Reviews| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 } | 174 } |
| 175 | 175 |
| 176 GURL origin = url.GetOrigin(); | 176 GURL origin = url.GetOrigin(); |
| 177 if (origin == GURL("https://accounts.youtube.com") || | 177 if (origin == GURL("https://accounts.youtube.com") || |
| 178 origin == GURL("https://accounts.blogger.com")) | 178 origin == GURL("https://accounts.blogger.com")) |
| 179 return true; | 179 return true; |
| 180 | 180 |
| 181 return false; | 181 return false; |
| 182 } | 182 } |
| 183 | 183 |
| 184 // This class is associated as user data with a given URLRequest object, in | |
| 185 // order to pass information from one response to another during the process | |
| 186 // of signing the user into their Gaia account. This class is only meant | |
| 187 // to be used from the IO thread. | |
| 188 class OneClickSigninRequestUserData : public base::SupportsUserData::Data { | |
| 189 public: | |
| 190 const std::string& email() const { return email_; } | |
| 191 | |
| 192 // Associates signin information with the request. Overwrites existing | |
| 193 // information if any. | |
| 194 static void AssociateWithRequest(base::SupportsUserData* request, | |
| 195 const std::string& email); | |
| 196 | |
| 197 // Gets the one-click sign in information associated with the request. | |
| 198 static OneClickSigninRequestUserData* FromRequest( | |
| 199 base::SupportsUserData* request); | |
| 200 | |
| 201 private: | |
| 202 // Key used when setting this object on the request. | |
| 203 static const void* const kUserDataKey; | |
| 204 | |
| 205 explicit OneClickSigninRequestUserData(const std::string& email) | |
| 206 : email_(email) { | |
| 207 } | |
| 208 | |
| 209 std::string email_; | |
| 210 | |
| 211 DISALLOW_COPY_AND_ASSIGN(OneClickSigninRequestUserData); | |
| 212 }; | |
| 213 | |
| 214 // static | |
| 215 void OneClickSigninRequestUserData::AssociateWithRequest( | |
| 216 base::SupportsUserData* request, | |
| 217 const std::string& email) { | |
| 218 request->SetUserData(kUserDataKey, new OneClickSigninRequestUserData(email)); | |
| 219 } | |
| 220 | |
| 221 // static | |
| 222 OneClickSigninRequestUserData* OneClickSigninRequestUserData::FromRequest( | |
| 223 base::SupportsUserData* request) { | |
| 224 return static_cast<OneClickSigninRequestUserData*>( | |
| 225 request->GetUserData(kUserDataKey)); | |
| 226 } | |
| 227 | |
| 228 const void* const OneClickSigninRequestUserData::kUserDataKey = | |
| 229 static_cast<const void* const>( | |
| 230 &OneClickSigninRequestUserData::kUserDataKey); | |
| 231 | |
| 232 } // namespace | 184 } // namespace |
| 233 | 185 |
| 234 // The infobar asking the user if they want to use one-click sign in. | 186 // The infobar asking the user if they want to use one-click sign in. |
| 235 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid | 187 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid |
| 236 // of this infobar. | 188 // of this infobar. |
| 237 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { | 189 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { |
| 238 public: | 190 public: |
| 239 // Creates a one click signin delegate and adds it to |infobar_service|. | 191 // Creates a one click signin delegate and adds it to |infobar_service|. |
| 240 static void Create(InfoBarService* infobar_service, | 192 static void Create(InfoBarService* infobar_service, |
| 241 const std::string& session_index, | 193 const std::string& session_index, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 354 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
| 403 : content::WebContentsObserver(web_contents), | 355 : content::WebContentsObserver(web_contents), |
| 404 auto_accept_(AUTO_ACCEPT_NONE), | 356 auto_accept_(AUTO_ACCEPT_NONE), |
| 405 source_(SyncPromoUI::SOURCE_UNKNOWN) { | 357 source_(SyncPromoUI::SOURCE_UNKNOWN) { |
| 406 } | 358 } |
| 407 | 359 |
| 408 OneClickSigninHelper::~OneClickSigninHelper() { | 360 OneClickSigninHelper::~OneClickSigninHelper() { |
| 409 } | 361 } |
| 410 | 362 |
| 411 // static | 363 // static |
| 412 void OneClickSigninHelper::AssociateWithRequestForTesting( | |
| 413 base::SupportsUserData* request, | |
| 414 const std::string& email) { | |
| 415 OneClickSigninRequestUserData::AssociateWithRequest(request, email); | |
| 416 } | |
| 417 | |
| 418 // static | |
| 419 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 364 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
| 420 CanOfferFor can_offer_for, | 365 CanOfferFor can_offer_for, |
| 421 const std::string& email, | 366 const std::string& email, |
| 422 int* error_message_id) { | 367 int* error_message_id) { |
| 423 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 368 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 424 VLOG(1) << "OneClickSigninHelper::CanOffer"; | 369 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
| 425 | 370 |
| 426 if (error_message_id) | 371 if (error_message_id) |
| 427 *error_message_id = 0; | 372 *error_message_id = 0; |
| 428 | 373 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 | 502 |
| 558 if (!SigninManager::AreSigninCookiesAllowed(io_data->GetCookieSettings())) | 503 if (!SigninManager::AreSigninCookiesAllowed(io_data->GetCookieSettings())) |
| 559 return DONT_OFFER; | 504 return DONT_OFFER; |
| 560 | 505 |
| 561 // The checks below depend on chrome already knowing what account the user | 506 // The checks below depend on chrome already knowing what account the user |
| 562 // signed in with. This happens only after receiving the response containing | 507 // signed in with. This happens only after receiving the response containing |
| 563 // the Google-Accounts-SignIn header. Until then, if there is even a chance | 508 // the Google-Accounts-SignIn header. Until then, if there is even a chance |
| 564 // that we want to connect the profile, chrome needs to tell Gaia that | 509 // that we want to connect the profile, chrome needs to tell Gaia that |
| 565 // it should offer the interstitial. Therefore missing one click data on | 510 // it should offer the interstitial. Therefore missing one click data on |
| 566 // the request means can offer is true. | 511 // the request means can offer is true. |
| 567 OneClickSigninRequestUserData* one_click_data = | 512 std::string pending_email = |
| 568 OneClickSigninRequestUserData::FromRequest(request); | 513 io_data->reverse_autologin_pending_email()->GetValue(); |
| 569 if (one_click_data) { | 514 if (!pending_email.empty()) { |
| 570 if (!SigninManager::IsAllowedUsername(one_click_data->email(), | 515 if (!SigninManager::IsAllowedUsername(pending_email, |
| 571 io_data->google_services_username_pattern()->GetValue())) { | 516 io_data->google_services_username_pattern()->GetValue())) { |
| 572 return DONT_OFFER; | 517 return DONT_OFFER; |
| 573 } | 518 } |
| 574 | 519 |
| 575 std::vector<std::string> rejected_emails = | 520 std::vector<std::string> rejected_emails = |
| 576 io_data->one_click_signin_rejected_email_list()->GetValue(); | 521 io_data->one_click_signin_rejected_email_list()->GetValue(); |
| 577 if (std::count_if(rejected_emails.begin(), rejected_emails.end(), | 522 if (std::count_if(rejected_emails.begin(), rejected_emails.end(), |
| 578 std::bind2nd(std::equal_to<std::string>(), | 523 std::bind2nd(std::equal_to<std::string>(), |
| 579 one_click_data->email())) > 0) { | 524 pending_email)) > 0) { |
| 580 return DONT_OFFER; | 525 return DONT_OFFER; |
| 581 } | 526 } |
| 582 | 527 |
| 583 if (io_data->signin_names()->GetEmails().count( | 528 if (io_data->signin_names()->GetEmails().count( |
| 584 UTF8ToUTF16(one_click_data->email())) > 0) { | 529 UTF8ToUTF16(pending_email)) > 0) { |
| 585 return DONT_OFFER; | 530 return DONT_OFFER; |
| 586 } | 531 } |
| 587 } | 532 } |
| 588 | 533 |
| 589 return CAN_OFFER; | 534 return CAN_OFFER; |
| 590 } | 535 } |
| 591 | 536 |
| 592 // static | 537 // static |
| 593 void OneClickSigninHelper::InitializeFieldTrial() { | 538 void OneClickSigninHelper::InitializeFieldTrial() { |
| 594 scoped_refptr<base::FieldTrial> trial( | 539 scoped_refptr<base::FieldTrial> trial( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 const std::pair<std::string, std::string>& pair = pairs[i]; | 585 const std::pair<std::string, std::string>& pair = pairs[i]; |
| 641 const std::string& key = pair.first; | 586 const std::string& key = pair.first; |
| 642 const std::string& value = pair.second; | 587 const std::string& value = pair.second; |
| 643 if (key == "email") { | 588 if (key == "email") { |
| 644 TrimString(value, "\"", &email); | 589 TrimString(value, "\"", &email); |
| 645 } else if (key == "sessionindex") { | 590 } else if (key == "sessionindex") { |
| 646 session_index = value; | 591 session_index = value; |
| 647 } | 592 } |
| 648 } | 593 } |
| 649 | 594 |
| 650 // Later in the chain of this request, we'll need to check the email address | |
| 651 // in the IO thread (see CanOfferOnIOThread). So save the email address as | |
| 652 // user data on the request (only for web-based flow). | |
| 653 if (SyncPromoUI::UseWebBasedSigninFlow() && !email.empty()) | |
| 654 OneClickSigninRequestUserData::AssociateWithRequest(request, email); | |
| 655 | |
| 656 if (!email.empty() || !session_index.empty()) { | 595 if (!email.empty() || !session_index.empty()) { |
| 657 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" | 596 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" |
| 658 << " email=" << email | 597 << " email=" << email |
| 659 << " sessionindex=" << session_index; | 598 << " sessionindex=" << session_index; |
| 660 } | 599 } |
| 661 | 600 |
| 662 // Parse Google-Chrome-SignIn. | 601 // Parse Google-Chrome-SignIn. |
| 663 AutoAccept auto_accept = AUTO_ACCEPT_NONE; | 602 AutoAccept auto_accept = AUTO_ACCEPT_NONE; |
| 664 SyncPromoUI::Source source = SyncPromoUI::SOURCE_UNKNOWN; | 603 SyncPromoUI::Source source = SyncPromoUI::SOURCE_UNKNOWN; |
| 665 GURL continue_url; | 604 GURL continue_url; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 | 662 |
| 724 // TODO(mathp): The appearance of this infobar should be tested using a | 663 // TODO(mathp): The appearance of this infobar should be tested using a |
| 725 // browser_test. | 664 // browser_test. |
| 726 OneClickSigninHelper* helper = | 665 OneClickSigninHelper* helper = |
| 727 OneClickSigninHelper::FromWebContents(web_contents); | 666 OneClickSigninHelper::FromWebContents(web_contents); |
| 728 if (!helper) | 667 if (!helper) |
| 729 return; | 668 return; |
| 730 | 669 |
| 731 int error_message_id = 0; | 670 int error_message_id = 0; |
| 732 | 671 |
| 672 // Save the email in the one-click signin manager. The manager may | |
| 673 // not exist if the contents is incognito or if the profile is already | |
| 674 // connected to a Google account. | |
| 675 if (!session_index.empty()) | |
| 676 helper->session_index_ = session_index; | |
| 677 | |
| 678 if (!email.empty()) { | |
| 679 helper->email_ = email; | |
| 680 Profile* profile = | |
| 681 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
|
erikwright (departed)
2013/01/18 03:06:54
This is a bit of an abuse (perhaps harmless) of Pr
Roger Tawa OOO till Jul 10th
2013/01/18 15:21:51
Are you suggesting I use an std::string member dir
erikwright (departed)
2013/01/18 15:36:28
That's basically what I'm suggesting. Here are a f
Roger Tawa OOO till Jul 10th
2013/01/21 15:26:45
Done.
| |
| 682 profile->GetPrefs()->SetString(prefs::kReverseAutologinPendingEmail, email); | |
| 683 } | |
| 684 | |
| 685 if (auto_accept != AUTO_ACCEPT_NONE) { | |
| 686 helper->auto_accept_ = auto_accept; | |
| 687 helper->source_ = source; | |
| 688 } | |
| 689 | |
| 733 CanOfferFor can_offer_for = | 690 CanOfferFor can_offer_for = |
| 734 (auto_accept != AUTO_ACCEPT_EXPLICIT && | 691 (auto_accept != AUTO_ACCEPT_EXPLICIT && |
| 735 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? | 692 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? |
| 736 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; | 693 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; |
| 737 | 694 |
| 738 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, | 695 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, |
| 739 &error_message_id)) { | 696 &error_message_id)) { |
| 740 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; | 697 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; |
| 741 if (helper && helper->error_message_.empty() && error_message_id != 0) | 698 if (helper && helper->error_message_.empty() && error_message_id != 0) |
| 742 helper->error_message_ = l10n_util::GetStringUTF8(error_message_id); | 699 helper->error_message_ = l10n_util::GetStringUTF8(error_message_id); |
| 743 | 700 |
| 744 return; | 701 return; |
| 745 } | 702 } |
| 746 | 703 |
| 747 // Save the email in the one-click signin manager. The manager may | |
| 748 // not exist if the contents is incognito or if the profile is already | |
| 749 // connected to a Google account. | |
| 750 if (!session_index.empty()) | |
| 751 helper->session_index_ = session_index; | |
| 752 | |
| 753 if (!email.empty()) | |
| 754 helper->email_ = email; | |
| 755 | |
| 756 if (auto_accept != AUTO_ACCEPT_NONE) { | |
| 757 helper->auto_accept_ = auto_accept; | |
| 758 helper->source_ = source; | |
| 759 } | |
| 760 | |
| 761 if (continue_url.is_valid()) { | 704 if (continue_url.is_valid()) { |
| 762 // When Gaia finally redirects to the continue URL, Gaia will add some | 705 // When Gaia finally redirects to the continue URL, Gaia will add some |
| 763 // extra query parameters. So ignore the parameters when checking to see | 706 // extra query parameters. So ignore the parameters when checking to see |
| 764 // if the user has continued. | 707 // if the user has continued. |
| 765 GURL::Replacements replacements; | 708 GURL::Replacements replacements; |
| 766 replacements.ClearQuery(); | 709 replacements.ClearQuery(); |
| 767 helper->continue_url_ = continue_url.ReplaceComponents(replacements); | 710 helper->continue_url_ = continue_url.ReplaceComponents(replacements); |
| 768 } | 711 } |
| 769 } | 712 } |
| 770 | 713 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 788 signin_tracker_.reset(); | 731 signin_tracker_.reset(); |
| 789 } | 732 } |
| 790 | 733 |
| 791 void OneClickSigninHelper::CleanTransientState() { | 734 void OneClickSigninHelper::CleanTransientState() { |
| 792 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 735 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
| 793 email_.clear(); | 736 email_.clear(); |
| 794 password_.clear(); | 737 password_.clear(); |
| 795 auto_accept_ = AUTO_ACCEPT_NONE; | 738 auto_accept_ = AUTO_ACCEPT_NONE; |
| 796 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 739 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
| 797 continue_url_ = GURL(); | 740 continue_url_ = GURL(); |
| 741 | |
| 742 Profile* profile = | |
| 743 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 744 profile->GetPrefs()->SetString(prefs::kReverseAutologinPendingEmail, ""); | |
| 798 } | 745 } |
| 799 | 746 |
| 800 void OneClickSigninHelper::DidNavigateAnyFrame( | 747 void OneClickSigninHelper::DidNavigateAnyFrame( |
| 801 const content::LoadCommittedDetails& details, | 748 const content::LoadCommittedDetails& details, |
| 802 const content::FrameNavigateParams& params) { | 749 const content::FrameNavigateParams& params) { |
| 803 // We only need to scrape the password for Gaia logins. | 750 // We only need to scrape the password for Gaia logins. |
| 804 const content::PasswordForm& form = params.password_form; | 751 const content::PasswordForm& form = params.password_form; |
| 805 if (form.origin.is_valid() && | 752 if (form.origin.is_valid() && |
| 806 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { | 753 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { |
| 807 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; | 754 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 break; | 918 break; |
| 972 } | 919 } |
| 973 } | 920 } |
| 974 | 921 |
| 975 RedirectToNTP(); | 922 RedirectToNTP(); |
| 976 } | 923 } |
| 977 | 924 |
| 978 void OneClickSigninHelper::SigninSuccess() { | 925 void OneClickSigninHelper::SigninSuccess() { |
| 979 RedirectToNTP(); | 926 RedirectToNTP(); |
| 980 } | 927 } |
| OLD | NEW |