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