| 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 #ifndef COMPONENTS_AUTOFILL_BROWSER_CREDIT_CARD_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_CREDIT_CARD_H_ |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_CREDIT_CARD_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_CREDIT_CARD_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "components/autofill/browser/field_types.h" | 13 #include "components/autofill/browser/field_types.h" |
| 14 #include "components/autofill/browser/form_group.h" | 14 #include "components/autofill/browser/form_group.h" |
| 15 | 15 |
| 16 struct FormFieldData; | 16 struct FormFieldData; |
| 17 | 17 |
| 18 // A form group that stores credit card information. | 18 // A form group that stores credit card information. |
| 19 class CreditCard : public FormGroup { | 19 class CreditCard : public FormGroup { |
| 20 public: | 20 public: |
| 21 explicit CreditCard(const std::string& guid); | 21 explicit CreditCard(const std::string& guid); |
| 22 | 22 |
| 23 // For use in STL containers. | 23 // For use in STL containers. |
| 24 CreditCard(); | 24 CreditCard(); |
| 25 CreditCard(const CreditCard& credit_card); | 25 CreditCard(const CreditCard& credit_card); |
| 26 virtual ~CreditCard(); | 26 virtual ~CreditCard(); |
| 27 | 27 |
| 28 // Returns a version of |number| that has any separator characters removed. | 28 // Returns a version of |number| that has any separator characters removed. |
| 29 static const string16 StripSeparators(const string16& number); | 29 static const base::string16 StripSeparators(const base::string16& number); |
| 30 | 30 |
| 31 // The user-visible type of the card, e.g. 'Mastercard'. | 31 // The user-visible type of the card, e.g. 'Mastercard'. |
| 32 static string16 TypeForDisplay(const std::string& type); | 32 static base::string16 TypeForDisplay(const std::string& type); |
| 33 | 33 |
| 34 // FormGroup implementation: | 34 // FormGroup implementation: |
| 35 virtual std::string GetGUID() const OVERRIDE; | 35 virtual std::string GetGUID() const OVERRIDE; |
| 36 virtual void GetMatchingTypes(const string16& text, | 36 virtual void GetMatchingTypes(const base::string16& text, |
| 37 const std::string& app_locale, | 37 const std::string& app_locale, |
| 38 FieldTypeSet* matching_types) const OVERRIDE; | 38 FieldTypeSet* matching_types) const OVERRIDE; |
| 39 virtual string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; | 39 virtual base::string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; |
| 40 virtual void SetRawInfo(AutofillFieldType type, | 40 virtual void SetRawInfo(AutofillFieldType type, |
| 41 const string16& value) OVERRIDE; | 41 const base::string16& value) OVERRIDE; |
| 42 virtual string16 GetInfo(AutofillFieldType type, | 42 virtual base::string16 GetInfo(AutofillFieldType type, |
| 43 const std::string& app_locale) const OVERRIDE; | 43 const std::string& app_locale) const OVERRIDE; |
| 44 virtual bool SetInfo(AutofillFieldType type, | 44 virtual bool SetInfo(AutofillFieldType type, |
| 45 const string16& value, | 45 const base::string16& value, |
| 46 const std::string& app_locale) OVERRIDE; | 46 const std::string& app_locale) OVERRIDE; |
| 47 virtual void FillFormField(const AutofillField& field, | 47 virtual void FillFormField(const AutofillField& field, |
| 48 size_t variant, | 48 size_t variant, |
| 49 const std::string& app_locale, | 49 const std::string& app_locale, |
| 50 FormFieldData* field_data) const OVERRIDE; | 50 FormFieldData* field_data) const OVERRIDE; |
| 51 | 51 |
| 52 // Credit card preview summary, for example: ******1234, Exp: 01/2020 | 52 // Credit card preview summary, for example: ******1234, Exp: 01/2020 |
| 53 const string16 Label() const; | 53 const base::string16 Label() const; |
| 54 | 54 |
| 55 // Special method to set value for HTML5 month input type. | 55 // Special method to set value for HTML5 month input type. |
| 56 void SetInfoForMonthInputType(const string16& value); | 56 void SetInfoForMonthInputType(const base::string16& value); |
| 57 | 57 |
| 58 // The number altered for display, for example: ******1234 | 58 // The number altered for display, for example: ******1234 |
| 59 string16 ObfuscatedNumber() const; | 59 base::string16 ObfuscatedNumber() const; |
| 60 // The last four digits of the credit card number. | 60 // The last four digits of the credit card number. |
| 61 string16 LastFourDigits() const; | 61 base::string16 LastFourDigits() const; |
| 62 // The user-visible type of the card, e.g. 'Mastercard'. | 62 // The user-visible type of the card, e.g. 'Mastercard'. |
| 63 string16 TypeForDisplay() const; | 63 base::string16 TypeForDisplay() const; |
| 64 // A label for this credit card formatted as 'Cardname - 2345'. | 64 // A label for this credit card formatted as 'Cardname - 2345'. |
| 65 string16 TypeAndLastFourDigits() const; | 65 base::string16 TypeAndLastFourDigits() const; |
| 66 // The ResourceBundle ID for the appropriate credit card image. | 66 // The ResourceBundle ID for the appropriate credit card image. |
| 67 int IconResourceId() const; | 67 int IconResourceId() const; |
| 68 | 68 |
| 69 const std::string& type() const { return type_; } | 69 const std::string& type() const { return type_; } |
| 70 | 70 |
| 71 int expiration_month() const { return expiration_month_; } | 71 int expiration_month() const { return expiration_month_; } |
| 72 int expiration_year() const { return expiration_year_; } | 72 int expiration_year() const { return expiration_year_; } |
| 73 | 73 |
| 74 // The guid is the primary identifier for |CreditCard| objects. | 74 // The guid is the primary identifier for |CreditCard| objects. |
| 75 // TODO(estade): remove this and just use GetGUID(). | 75 // TODO(estade): remove this and just use GetGUID(). |
| (...skipping 21 matching lines...) Expand all Loading... |
| 97 bool operator==(const CreditCard& credit_card) const; | 97 bool operator==(const CreditCard& credit_card) const; |
| 98 bool operator!=(const CreditCard& credit_card) const; | 98 bool operator!=(const CreditCard& credit_card) const; |
| 99 | 99 |
| 100 // Returns true if there are no values (field types) set. | 100 // Returns true if there are no values (field types) set. |
| 101 bool IsEmpty(const std::string& app_locale) const; | 101 bool IsEmpty(const std::string& app_locale) const; |
| 102 | 102 |
| 103 // Returns true if all field types have valid values set. | 103 // Returns true if all field types have valid values set. |
| 104 bool IsComplete() const; | 104 bool IsComplete() const; |
| 105 | 105 |
| 106 // Returns the credit card number. | 106 // Returns the credit card number. |
| 107 const string16& number() const { return number_; } | 107 const base::string16& number() const { return number_; } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 // FormGroup: | 110 // FormGroup: |
| 111 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; | 111 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; |
| 112 | 112 |
| 113 // The month and year are zero if not present. | 113 // The month and year are zero if not present. |
| 114 int Expiration4DigitYear() const { return expiration_year_; } | 114 int Expiration4DigitYear() const { return expiration_year_; } |
| 115 int Expiration2DigitYear() const { return expiration_year_ % 100; } | 115 int Expiration2DigitYear() const { return expiration_year_ % 100; } |
| 116 string16 ExpirationMonthAsString() const; | 116 base::string16 ExpirationMonthAsString() const; |
| 117 string16 Expiration4DigitYearAsString() const; | 117 base::string16 Expiration4DigitYearAsString() const; |
| 118 string16 Expiration2DigitYearAsString() const; | 118 base::string16 Expiration2DigitYearAsString() const; |
| 119 | 119 |
| 120 // Sets |expiration_month_| to the integer conversion of |text|. | 120 // Sets |expiration_month_| to the integer conversion of |text|. |
| 121 void SetExpirationMonthFromString(const string16& text, | 121 void SetExpirationMonthFromString(const base::string16& text, |
| 122 const std::string& app_locale); | 122 const std::string& app_locale); |
| 123 | 123 |
| 124 // Sets |expiration_year_| to the integer conversion of |text|. | 124 // Sets |expiration_year_| to the integer conversion of |text|. |
| 125 void SetExpirationYearFromString(const string16& text); | 125 void SetExpirationYearFromString(const base::string16& text); |
| 126 | 126 |
| 127 // Sets |number_| to |number| and computes the appropriate card |type_|. | 127 // Sets |number_| to |number| and computes the appropriate card |type_|. |
| 128 void SetNumber(const string16& number); | 128 void SetNumber(const base::string16& number); |
| 129 | 129 |
| 130 // These setters verify that the month and year are within appropriate | 130 // These setters verify that the month and year are within appropriate |
| 131 // ranges. | 131 // ranges. |
| 132 void SetExpirationMonth(int expiration_month); | 132 void SetExpirationMonth(int expiration_month); |
| 133 void SetExpirationYear(int expiration_year); | 133 void SetExpirationYear(int expiration_year); |
| 134 | 134 |
| 135 string16 number_; // The credit card number. | 135 base::string16 number_; // The credit card number. |
| 136 string16 name_on_card_; // The cardholder's name. | 136 base::string16 name_on_card_; // The cardholder's name. |
| 137 std::string type_; // The type of the card. | 137 std::string type_; // The type of the card. |
| 138 | 138 |
| 139 // These members are zero if not present. | 139 // These members are zero if not present. |
| 140 int expiration_month_; | 140 int expiration_month_; |
| 141 int expiration_year_; | 141 int expiration_year_; |
| 142 | 142 |
| 143 // The guid of this credit card. | 143 // The guid of this credit card. |
| 144 std::string guid_; | 144 std::string guid_; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 // So we can compare CreditCards with EXPECT_EQ(). | 147 // So we can compare CreditCards with EXPECT_EQ(). |
| 148 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card); | 148 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card); |
| 149 | 149 |
| 150 // The string identifiers for credit card icon resources. | 150 // The string identifiers for credit card icon resources. |
| 151 extern const char* const kAmericanExpressCard; | 151 extern const char* const kAmericanExpressCard; |
| 152 extern const char* const kDinersCard; | 152 extern const char* const kDinersCard; |
| 153 extern const char* const kDiscoverCard; | 153 extern const char* const kDiscoverCard; |
| 154 extern const char* const kGenericCard; | 154 extern const char* const kGenericCard; |
| 155 extern const char* const kJCBCard; | 155 extern const char* const kJCBCard; |
| 156 extern const char* const kMasterCard; | 156 extern const char* const kMasterCard; |
| 157 extern const char* const kSoloCard; | 157 extern const char* const kSoloCard; |
| 158 extern const char* const kVisaCard; | 158 extern const char* const kVisaCard; |
| 159 | 159 |
| 160 #endif // COMPONENTS_AUTOFILL_BROWSER_CREDIT_CARD_H_ | 160 #endif // COMPONENTS_AUTOFILL_BROWSER_CREDIT_CARD_H_ |
| OLD | NEW |