diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-29 02:21:50 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-29 02:21:50 +0000 |
commit | 0a57c37b8f4f803f054ea722c0181896f81e8a67 (patch) | |
tree | f0fa50b66375d2a2f95751bca430334edc7934c0 /components | |
parent | 391cba93ec4810625581efc55c543e77cf8b2d2c (diff) | |
download | chromium_src-0a57c37b8f4f803f054ea722c0181896f81e8a67.zip chromium_src-0a57c37b8f4f803f054ea722c0181896f81e8a67.tar.gz chromium_src-0a57c37b8f4f803f054ea722c0181896f81e8a67.tar.bz2 |
Remove DataModelWrapper from android build.
BUG=none
Review URL: https://codereview.chromium.org/137723008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
5 files changed, 85 insertions, 34 deletions
diff --git a/components/autofill/content/browser/wallet/full_wallet.cc b/components/autofill/content/browser/wallet/full_wallet.cc index d4b390a..fda8811 100644 --- a/components/autofill/content/browser/wallet/full_wallet.cc +++ b/components/autofill/content/browser/wallet/full_wallet.cc @@ -154,16 +154,17 @@ scoped_ptr<FullWallet> return wallet.Pass(); } -base::string16 FullWallet::GetInfo(const AutofillType& type) { +base::string16 FullWallet::GetInfo(const std::string& app_locale, + const AutofillType& type) { switch (type.GetStorableType()) { case CREDIT_CARD_NUMBER: - return base::UTF8ToUTF16(GetPan()); + return base::ASCIIToUTF16(GetPan()); case CREDIT_CARD_NAME: return billing_address()->recipient_name(); case CREDIT_CARD_VERIFICATION_CODE: - return base::UTF8ToUTF16(GetCvn()); + return base::ASCIIToUTF16(GetCvn()); case CREDIT_CARD_EXP_MONTH: if (expiration_month() == 0) @@ -182,7 +183,7 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) { case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: if (expiration_month() == 0 || expiration_year() == 0) - return base::string16(); + return base::string16(); return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") + base::IntToString16(expiration_year() % 100); @@ -194,17 +195,27 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) { case CREDIT_CARD_TYPE: { std::string internal_type = - CreditCard::GetCreditCardType(base::UTF8ToUTF16(GetPan())); + CreditCard::GetCreditCardType(base::ASCIIToUTF16(GetPan())); if (internal_type == kGenericCard) return base::string16(); return CreditCard::TypeForDisplay(internal_type); } - default: - NOTREACHED(); - } + default: { + switch (type.group()) { + case NAME_BILLING: + case PHONE_BILLING: + case ADDRESS_BILLING: + return billing_address_->GetInfo(type, app_locale); - return base::string16(); + case CREDIT_CARD: + NOTREACHED(); + + default: + return shipping_address_->GetInfo(type, app_locale); + } + } + } } bool FullWallet::HasRequiredAction(RequiredAction action) const { @@ -216,11 +227,16 @@ bool FullWallet::HasRequiredAction(RequiredAction action) const { base::string16 FullWallet::TypeAndLastFourDigits() { CreditCard card; - card.SetRawInfo(CREDIT_CARD_NUMBER, - GetInfo(AutofillType(CREDIT_CARD_NUMBER))); + card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan())); return card.TypeAndLastFourDigits(); } +const std::string& FullWallet::GetPan() { + if (pan_.empty()) + DecryptCardInfo(); + return pan_; +} + bool FullWallet::operator==(const FullWallet& other) const { if (expiration_month_ != other.expiration_month_) return false; @@ -307,12 +323,6 @@ void FullWallet::DecryptCardInfo() { pan_ = iin_ + card_info.substr(0, split); } -const std::string& FullWallet::GetPan() { - if (pan_.empty()) - DecryptCardInfo(); - return pan_; -} - const std::string& FullWallet::GetCvn() { if (cvn_.empty()) DecryptCardInfo(); diff --git a/components/autofill/content/browser/wallet/full_wallet.h b/components/autofill/content/browser/wallet/full_wallet.h index e3d185d..9a8607b 100644 --- a/components/autofill/content/browser/wallet/full_wallet.h +++ b/components/autofill/content/browser/wallet/full_wallet.h @@ -52,7 +52,8 @@ class FullWallet { scoped_ptr<Address> shipping_address); // Returns corresponding data for |type|. - base::string16 GetInfo(const AutofillType& type); + base::string16 GetInfo(const std::string& app_locale, + const AutofillType& type); // Whether or not |action| is in |required_actions_|. bool HasRequiredAction(RequiredAction action) const; @@ -61,6 +62,10 @@ class FullWallet { // like this "Visa - 4111". base::string16 TypeAndLastFourDigits(); + // Decrypts and returns the primary account number (PAN) using the generated + // one time pad, |one_time_pad_|. + const std::string& GetPan(); + bool operator==(const FullWallet& other) const; bool operator!=(const FullWallet& other) const; @@ -103,10 +108,6 @@ class FullWallet { // Decrypts both |pan_| and |cvn_|. void DecryptCardInfo(); - // Decrypts and returns the primary account number (PAN) using the generated - // one time pad, |one_time_pad_|. - const std::string& GetPan(); - // Decrypts and returns the card verification number (CVN) using the generated // one time pad, |one_time_pad_|. const std::string& GetCvn(); diff --git a/components/autofill/content/browser/wallet/full_wallet_unittest.cc b/components/autofill/content/browser/wallet/full_wallet_unittest.cc index 3d156a8..cf5dc6a 100644 --- a/components/autofill/content/browser/wallet/full_wallet_unittest.cc +++ b/components/autofill/content/browser/wallet/full_wallet_unittest.cc @@ -456,9 +456,10 @@ TEST_F(FullWalletTest, RestLengthCorrectDecryptionTest) { EXPECT_TRUE(base::HexStringToBytes("5F04A8704183", &one_time_pad)); full_wallet.set_one_time_pad(one_time_pad); EXPECT_EQ(ASCIIToUTF16("5285121925598459"), - full_wallet.GetInfo(AutofillType(CREDIT_CARD_NUMBER))); + full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER))); EXPECT_EQ(ASCIIToUTF16("989"), - full_wallet.GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE))); + full_wallet.GetInfo( + "", AutofillType(CREDIT_CARD_VERIFICATION_CODE))); } TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) { @@ -474,9 +475,10 @@ TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) { EXPECT_TRUE(base::HexStringToBytes("063AD35324BF", &one_time_pad)); full_wallet.set_one_time_pad(one_time_pad); EXPECT_EQ(ASCIIToUTF16("5285127106109719"), - full_wallet.GetInfo(AutofillType(CREDIT_CARD_NUMBER))); + full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER))); EXPECT_EQ(ASCIIToUTF16("385"), - full_wallet.GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE))); + full_wallet.GetInfo( + "", AutofillType(CREDIT_CARD_VERIFICATION_CODE))); } TEST_F(FullWalletTest, GetCreditCardInfo) { @@ -490,21 +492,22 @@ TEST_F(FullWalletTest, GetCreditCardInfo) { required_actions); EXPECT_EQ(ASCIIToUTF16("15"), - full_wallet.GetInfo(AutofillType(CREDIT_CARD_EXP_2_DIGIT_YEAR))); + full_wallet.GetInfo( + "", AutofillType(CREDIT_CARD_EXP_2_DIGIT_YEAR))); EXPECT_EQ(ASCIIToUTF16("12/15"), full_wallet.GetInfo( - AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))); + "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))); EXPECT_EQ(ASCIIToUTF16("12/2015"), full_wallet.GetInfo( - AutofillType(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR))); + "", AutofillType(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR))); std::vector<uint8> one_time_pad; EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad)); full_wallet.set_one_time_pad(one_time_pad); EXPECT_EQ(ASCIIToUTF16("MasterCard"), - full_wallet.GetInfo(AutofillType(CREDIT_CARD_TYPE))); + full_wallet.GetInfo("", AutofillType(CREDIT_CARD_TYPE))); } TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) { @@ -514,14 +517,15 @@ TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) { "5555555555554444", "123", GetTestAddress(), GetTestShippingAddress()); EXPECT_EQ(ASCIIToUTF16("5555555555554444"), - full_wallet->GetInfo(AutofillType(CREDIT_CARD_NUMBER))); + full_wallet->GetInfo("", AutofillType(CREDIT_CARD_NUMBER))); EXPECT_EQ(ASCIIToUTF16("MasterCard"), - full_wallet->GetInfo(AutofillType(CREDIT_CARD_TYPE))); + full_wallet->GetInfo("", AutofillType(CREDIT_CARD_TYPE))); EXPECT_EQ(ASCIIToUTF16("123"), - full_wallet->GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE))); + full_wallet->GetInfo( + "", AutofillType(CREDIT_CARD_VERIFICATION_CODE))); EXPECT_EQ(ASCIIToUTF16("11/12"), full_wallet->GetInfo( - AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))); + "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))); EXPECT_TRUE(GetTestAddress()->EqualsIgnoreID( *full_wallet->billing_address())); EXPECT_TRUE(GetTestShippingAddress()->EqualsIgnoreID( diff --git a/components/autofill/core/browser/form_structure.cc b/components/autofill/core/browser/form_structure.cc index a953798..aa42b4f 100644 --- a/components/autofill/core/browser/form_structure.cc +++ b/components/autofill/core/browser/form_structure.cc @@ -1150,6 +1150,27 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes( } } +bool FormStructure::FillFields( + const std::vector<ServerFieldType>& types, + const InputFieldComparator& matches, + const base::Callback<base::string16(const AutofillType&)>& get_info, + const std::string& app_locale) { + bool filled_something = false; + for (size_t i = 0; i < field_count(); ++i) { + for (size_t j = 0; j < types.size(); ++j) { + if (matches.Run(types[j], *field(i))) { + AutofillField::FillFormField(*field(i), + get_info.Run(field(i)->Type()), + app_locale, + field(i)); + filled_something = true; + break; + } + } + } + return filled_something; +} + void FormStructure::IdentifySections(bool has_author_specified_sections) { if (fields_.empty()) return; diff --git a/components/autofill/core/browser/form_structure.h b/components/autofill/core/browser/form_structure.h index 6382c20..578c413 100644 --- a/components/autofill/core/browser/form_structure.h +++ b/components/autofill/core/browser/form_structure.h @@ -8,9 +8,11 @@ #include <string> #include <vector> +#include "base/callback.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" +#include "base/strings/string16.h" #include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/field_types.h" @@ -136,6 +138,19 @@ class FormStructure { void ParseFieldTypesFromAutocompleteAttributes(bool* found_types, bool* found_sections); + // Determines whether |type| and |field| match. + typedef base::Callback<bool(ServerFieldType type, + const AutofillField& field)> + InputFieldComparator; + + // Fills in |fields_| that match |types| (via |matches|) with info from + // |get_info|. + bool FillFields( + const std::vector<ServerFieldType>& types, + const InputFieldComparator& matches, + const base::Callback<base::string16(const AutofillType&)>& get_info, + const std::string& app_locale); + const AutofillField* field(size_t index) const; AutofillField* field(size_t index); size_t field_count() const; |