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