diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 06:22:41 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 06:22:41 +0000 |
commit | f6b577a30555b83946d9eac3680220b85ec46cad (patch) | |
tree | f1a431266294f7123c9d81a2bdb463d08896d72b /components/autofill/content/browser | |
parent | 5a615a4a3aed466512efcd4b504508adfc03d020 (diff) | |
download | chromium_src-f6b577a30555b83946d9eac3680220b85ec46cad.zip chromium_src-f6b577a30555b83946d9eac3680220b85ec46cad.tar.gz chromium_src-f6b577a30555b83946d9eac3680220b85ec46cad.tar.bz2 |
rAc: support multiple accounts
BUG=247755,259543
Review URL: https://codereview.chromium.org/69853002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236410 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/autofill/content/browser')
8 files changed, 99 insertions, 19 deletions
diff --git a/components/autofill/content/browser/wallet/wallet_items.cc b/components/autofill/content/browser/wallet/wallet_items.cc index a6d7de3..84e2ec8 100644 --- a/components/autofill/content/browser/wallet/wallet_items.cc +++ b/components/autofill/content/browser/wallet/wallet_items.cc @@ -417,6 +417,7 @@ WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions, const std::string& default_instrument_id, const std::string& default_address_id, const std::string& obfuscated_gaia_id, + size_t active_account_index, AmexPermission amex_permission, const std::vector<std::string>& gaia_accounts) : required_actions_(required_actions), @@ -424,6 +425,7 @@ WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions, default_instrument_id_(default_instrument_id), default_address_id_(default_address_id), obfuscated_gaia_id_(obfuscated_gaia_id), + active_account_index_(active_account_index), amex_permission_(amex_permission), gaia_accounts_(gaia_accounts) {} @@ -475,6 +477,7 @@ scoped_ptr<WalletItems> AmexPermission amex_permission = amex_disallowed ? AMEX_DISALLOWED : AMEX_ALLOWED; + size_t active_account_index = 0; std::vector<std::string> gaia_accounts; const base::ListValue* gaia_profiles; if (dictionary.GetList("gaia_profile", &gaia_profiles)) { @@ -484,6 +487,12 @@ scoped_ptr<WalletItems> if (gaia_profiles->GetDictionary(i, &account_dict) && account_dict->GetString("buyer_email", &email)) { gaia_accounts.push_back(email); + + std::string gaia_id; + if (account_dict->GetString("gaia_id", &gaia_id) && + gaia_id == obfuscated_gaia_id) { + active_account_index = i; + } } else { DVLOG(1) << "Response from Google Wallet has malformed GAIA profile."; } @@ -497,6 +506,7 @@ scoped_ptr<WalletItems> default_instrument_id, default_address_id, obfuscated_gaia_id, + active_account_index, amex_permission, gaia_accounts)); @@ -569,11 +579,15 @@ bool WalletItems::operator==(const WalletItems& other) const { default_address_id_ == other.default_address_id_ && required_actions_ == other.required_actions_ && obfuscated_gaia_id_ == other.obfuscated_gaia_id_ && + active_account_index() == other.active_account_index() && VectorsAreEqual<MaskedInstrument>(instruments(), - other.instruments()) && + other.instruments()) && VectorsAreEqual<Address>(addresses(), other.addresses()) && VectorsAreEqual<LegalDocument>(legal_documents(), - other.legal_documents()); + other.legal_documents()) && + gaia_accounts().size() == other.gaia_accounts().size() && + std::equal(gaia_accounts().begin(), gaia_accounts().end(), + other.gaia_accounts().begin()); } bool WalletItems::operator!=(const WalletItems& other) const { diff --git a/components/autofill/content/browser/wallet/wallet_items.h b/components/autofill/content/browser/wallet/wallet_items.h index 32f1118..eb3d526 100644 --- a/components/autofill/content/browser/wallet/wallet_items.h +++ b/components/autofill/content/browser/wallet/wallet_items.h @@ -259,6 +259,7 @@ class WalletItems { const std::vector<Address*>& addresses() const { return addresses_.get(); } const std::string& default_address_id() const { return default_address_id_; } const std::string& obfuscated_gaia_id() const { return obfuscated_gaia_id_; } + size_t active_account_index() const { return active_account_index_; } const std::vector<std::string>& gaia_accounts() const { return gaia_accounts_; } @@ -273,7 +274,8 @@ class WalletItems { const std::string&, const std::string&, AmexPermission, - const std::vector<std::string>&); + const std::vector<std::string>&, + size_t); friend scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( RequiredAction action); FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); @@ -285,6 +287,7 @@ class WalletItems { const std::string& default_instrument_id, const std::string& default_address_id, const std::string& obfuscated_gaia_id, + size_t active_account_index, AmexPermission amex_permission, const std::vector<std::string>& gaia_accounts); @@ -301,9 +304,14 @@ class WalletItems { // The id of the user's default address. std::string default_address_id_; - // The externalized Gaia id of the user. + // The externalized Gaia id of the user. TODO(estade): we can remove this + // if |gaia_accounts_| is made to hold more metadata about the accounts. std::string obfuscated_gaia_id_; + // The index into |gaia_accounts_| of the account for which this object + // holds data. + size_t active_account_index_; + // The user's backing instruments. ScopedVector<MaskedInstrument> instruments_; diff --git a/components/autofill/content/browser/wallet/wallet_items_unittest.cc b/components/autofill/content/browser/wallet/wallet_items_unittest.cc index 142c74a..7002630 100644 --- a/components/autofill/content/browser/wallet/wallet_items_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_items_unittest.cc @@ -363,7 +363,7 @@ const char kWalletItems[] = " {" " \"buyer_email\":\"user2@chromium.org\"," " \"gaia_index\":1," - " \"gaia_id\":\"123456789\"," + " \"gaia_id\":\"obfuscated_gaia_id\"," " \"buyer_name\":\"Jill Usecase\"," " \"is_active\":false," " \"avatar_url_27x27\":\"https://lh3.googleusercontent.com/27.jpg\"," @@ -513,6 +513,7 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), + 0, AMEX_DISALLOWED, std::vector<std::string>()); EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); @@ -524,6 +525,7 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), + 0, AMEX_DISALLOWED, std::vector<std::string>()); EXPECT_NE(expected, different_required_actions); @@ -560,6 +562,7 @@ TEST_F(WalletItemsTest, CreateWalletItems) { "default_instrument_id", "default_address_id", "obfuscated_gaia_id", + 1, AMEX_DISALLOWED, users); diff --git a/components/autofill/content/browser/wallet/wallet_service_url.cc b/components/autofill/content/browser/wallet/wallet_service_url.cc index bc888ba..4bb963a 100644 --- a/components/autofill/content/browser/wallet/wallet_service_url.cc +++ b/components/autofill/content/browser/wallet/wallet_service_url.cc @@ -9,6 +9,7 @@ #include "base/command_line.h" #include "base/format_macros.h" #include "base/metrics/field_trial.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "components/autofill/core/common/autofill_switches.h" #include "google_apis/gaia/gaia_urls.h" @@ -136,8 +137,7 @@ GURL GetPassiveAuthUrl() { } GURL GetSignInUrl() { - GURL url(GaiaUrls::GetInstance()->service_login_url()); - url = net::AppendQueryParameter(url, "service", "toolbar"); + GURL url(GaiaUrls::GetInstance()->add_account_url()); url = net::AppendQueryParameter(url, "nui", "1"); // Prevents promos from showing (see http://crbug.com/235227). url = net::AppendQueryParameter(url, "sarp", "1"); @@ -152,11 +152,29 @@ GURL GetSignInContinueUrl() { return GetPassiveAuthUrl(); } -bool IsSignInContinueUrl(const GURL& url) { +bool IsSignInContinueUrl(const GURL& url, size_t* user_index) { GURL final_url = wallet::GetSignInContinueUrl(); - return url.SchemeIsSecure() && - url.host() == final_url.host() && - url.path() == final_url.path(); + if (!url.SchemeIsSecure() || + url.host() != final_url.host() || + url.path() != final_url.path()) { + return false; + } + + *user_index = 0; + std::string query_str = url.query(); + url_parse::Component query(0, query_str.length()); + url_parse::Component key, value; + const char kUserIndexKey[] = "authuser"; + while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key, + &value)) { + if (key.is_nonempty() && + query_str.substr(key.begin, key.len) == kUserIndexKey) { + base::StringToSizeT(query_str.substr(value.begin, value.len), user_index); + break; + } + } + + return true; } bool IsUsingProd() { diff --git a/components/autofill/content/browser/wallet/wallet_service_url.h b/components/autofill/content/browser/wallet/wallet_service_url.h index c91e875..98909d2 100644 --- a/components/autofill/content/browser/wallet/wallet_service_url.h +++ b/components/autofill/content/browser/wallet/wallet_service_url.h @@ -34,8 +34,10 @@ GURL GetSignInUrl(); GURL GetSignInContinueUrl(); // Returns true if |url| is an acceptable variant of the sign-in continue -// url. Can be used for detection of navigation to the continue url. -bool IsSignInContinueUrl(const GURL& url); +// url. Can be used for detection of navigation to the continue url. If +// |url| is a sign-in url, |user_index| will also be filled in to indicate +// which user account just signed in. +bool IsSignInContinueUrl(const GURL& url, size_t* user_index); // Whether calls to Online Wallet are hitting the production server rather than // a sandbox or some malicious endpoint. diff --git a/components/autofill/content/browser/wallet/wallet_service_url_unittest.cc b/components/autofill/content/browser/wallet/wallet_service_url_unittest.cc index d16265f..584e638 100644 --- a/components/autofill/content/browser/wallet/wallet_service_url_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_service_url_unittest.cc @@ -101,5 +101,35 @@ TEST(WalletServiceUrl, IsUsingProd) { EXPECT_EQ(fake_service_url.GetOrigin(), flag_get_items_url.GetOrigin()); } +TEST(WalletServiceUrl, IsSignInContinueUrl) { + CommandLine* command_line = CommandLine::ForCurrentProcess(); + command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1"); + + // authuser query param is respected. + const char sign_in_url[] = "https://wallet-web.sandbox.google.com/online/v2/" + "u/0/passiveauth?isChromePayments=true&authuser=4"; + size_t user_index = 100; + EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url), &user_index)); + EXPECT_EQ(4U, user_index); + + // No authuser query param means 0 is assumed. + user_index = 101; + const char sign_in_url_no_user[] = "https://wallet-web.sandbox.google.com/" + "online/v2/u/0/passiveauth?isChromePayments=true"; + EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_no_user), &user_index)); + EXPECT_EQ(0U, user_index); + + // A authuser query param that doesn't parse means 0 is assumed. + user_index = 102; + const char sign_in_url_bad_user[] = "https://wallet-web.sandbox.google.com/" + "online/v2/u/0/passiveauth?isChromePayments=true&authuser=yolo"; + EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_bad_user), &user_index)); + EXPECT_EQ(0U, user_index); + + const char not_a_sign_in_url[] = "https://wallet-web.sandbox.google.com/" + "online/v2/u/0/example"; + EXPECT_FALSE(IsSignInContinueUrl(GURL(not_a_sign_in_url), &user_index)); +} + } // namespace wallet } // namespace autofill diff --git a/components/autofill/content/browser/wallet/wallet_test_util.cc b/components/autofill/content/browser/wallet/wallet_test_util.cc index d5e5af0..13d0622 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.cc +++ b/components/autofill/content/browser/wallet/wallet_test_util.cc @@ -236,13 +236,15 @@ scoped_ptr<WalletItems> GetTestWalletItems( const std::string& default_instrument_id, const std::string& default_address_id, AmexPermission amex_permission, - const std::vector<std::string>& users) { + const std::vector<std::string>& users, + size_t user_index) { return scoped_ptr<WalletItems>( new wallet::WalletItems(required_actions, "google_transaction_id", default_instrument_id, default_address_id, "obfuscated_gaia_id", + user_index, amex_permission, users)); } @@ -258,7 +260,8 @@ scoped_ptr<WalletItems> GetTestWalletItemsWithRequiredAction( "default_instrument_id", "default_address_id", AMEX_ALLOWED, - users); + users, + 0); } scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { @@ -269,12 +272,13 @@ scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { scoped_ptr<WalletItems> GetTestWalletItemsWithUsers( - std::vector<std::string>& users) { + const std::vector<std::string>& users, size_t user_index) { return GetTestWalletItems(std::vector<RequiredAction>(), "default_instrument_id", "default_address_id", AMEX_ALLOWED, - users); + users, + user_index); } scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( @@ -286,7 +290,8 @@ scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( default_instrument_id, default_address_id, amex_permission, - users); + users, + 0); } } // namespace wallet diff --git a/components/autofill/content/browser/wallet/wallet_test_util.h b/components/autofill/content/browser/wallet/wallet_test_util.h index e6d33f6..12ca6b5 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.h +++ b/components/autofill/content/browser/wallet/wallet_test_util.h @@ -51,7 +51,7 @@ scoped_ptr<WalletItems> GetTestWalletItemsWithRequiredAction( RequiredAction action); scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission); scoped_ptr<WalletItems> GetTestWalletItemsWithUsers( - const std::vector<std::string>& users); + const std::vector<std::string>& users, size_t user_index); scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( const std::string& default_instrument_id, const std::string& default_address_id, |