OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_ |
6 #define CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_ | 6 #define CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "chrome/browser/autofill/form_group.h" | 11 #include "chrome/browser/autofill/form_group.h" |
12 | 12 |
13 // A form group that stores credit card information. | 13 // A form group that stores credit card information. |
14 class CreditCard : public FormGroup { | 14 class CreditCard : public FormGroup { |
15 public: | 15 public: |
16 CreditCard(const string16& label, int unique_id); | 16 CreditCard(const string16& label, int unique_id); |
17 // For use in STL containers. | 17 // For use in STL containers. |
18 CreditCard(const CreditCard& card); | 18 CreditCard(const CreditCard& card); |
19 CreditCard(); | 19 CreditCard(); |
20 | 20 |
21 // FormGroup implementation: | 21 // FormGroup implementation: |
22 FormGroup* Clone() const; | 22 FormGroup* Clone() const; |
23 virtual void GetPossibleFieldTypes(const string16& text, | 23 virtual void GetPossibleFieldTypes(const string16& text, |
24 FieldTypeSet* possible_types) const; | 24 FieldTypeSet* possible_types) const; |
| 25 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; |
25 virtual void FindInfoMatches(const AutoFillType& type, | 26 virtual void FindInfoMatches(const AutoFillType& type, |
26 const string16& info, | 27 const string16& info, |
27 std::vector<string16>* matched_text) const; | 28 std::vector<string16>* matched_text) const; |
28 virtual string16 GetFieldText(const AutoFillType& type) const; | 29 virtual string16 GetFieldText(const AutoFillType& type) const; |
29 virtual string16 GetPreviewText(const AutoFillType& type) const; | 30 virtual string16 GetPreviewText(const AutoFillType& type) const; |
30 virtual void SetInfo(const AutoFillType& type, const string16& value); | 31 virtual void SetInfo(const AutoFillType& type, const string16& value); |
31 const string16& Label() const { return label_; } | 32 const string16& Label() const { return label_; } |
32 | 33 |
33 // The number altered for display, for example: ******1234 | 34 // The number altered for display, for example: ******1234 |
34 string16 ObfuscatedNumber() const; | 35 string16 ObfuscatedNumber() const; |
35 // Credit card preview summary, for example: ******1234, Exp: 01/2020 | 36 // Credit card preview summary, for example: ******1234, Exp: 01/2020 |
36 string16 PreviewSummary() const; | 37 string16 PreviewSummary() const; |
37 // The last four digits of the credit card number. | 38 // The last four digits of the credit card number. |
38 string16 LastFourDigits() const; | 39 string16 LastFourDigits() const; |
39 | 40 |
40 const string16& billing_address() const { return billing_address_; } | 41 const string16& billing_address() const { return billing_address_; } |
41 const string16& shipping_address() const { return shipping_address_; } | |
42 int unique_id() const { return unique_id_; } | 42 int unique_id() const { return unique_id_; } |
43 | 43 |
44 // The caller should verify that the corresponding AutoFillProfile exists. If | 44 // The caller should verify that the corresponding AutoFillProfile exists. |
45 // the shipping address should be the same as the billing address, send in an | |
46 // empty string to set_shipping_address. | |
47 void set_billing_address(const string16& address) { | 45 void set_billing_address(const string16& address) { |
48 billing_address_ = address; | 46 billing_address_ = address; |
49 } | 47 } |
50 void set_shipping_address(const string16& address) { | |
51 shipping_address_ = address; | |
52 } | |
53 void set_unique_id(int id) { unique_id_ = id; } | 48 void set_unique_id(int id) { unique_id_ = id; } |
54 | 49 |
55 // For use in STL containers. | 50 // For use in STL containers. |
56 void operator=(const CreditCard&); | 51 void operator=(const CreditCard&); |
57 | 52 |
58 // Used by tests. | 53 // Used by tests. |
59 bool operator==(const CreditCard& creditcard) const; | 54 bool operator==(const CreditCard& creditcard) const; |
60 bool operator!=(const CreditCard& creditcard) const; | 55 bool operator!=(const CreditCard& creditcard) const; |
61 void set_label(const string16& label) { label_ = label; } | 56 void set_label(const string16& label) { label_ = label; } |
62 | 57 |
(...skipping 11 matching lines...) Expand all Loading... |
74 | 69 |
75 // Sets |expiration_month_| to the integer conversion of |text|. | 70 // Sets |expiration_month_| to the integer conversion of |text|. |
76 void SetExpirationMonthFromString(const string16& text); | 71 void SetExpirationMonthFromString(const string16& text); |
77 | 72 |
78 // Sets |expiration_year_| to the integer conversion of |text|. | 73 // Sets |expiration_year_| to the integer conversion of |text|. |
79 void SetExpirationYearFromString(const string16& text); | 74 void SetExpirationYearFromString(const string16& text); |
80 | 75 |
81 const string16& number() const { return number_; } | 76 const string16& number() const { return number_; } |
82 const string16& name_on_card() const { return name_on_card_; } | 77 const string16& name_on_card() const { return name_on_card_; } |
83 const string16& type() const { return type_; } | 78 const string16& type() const { return type_; } |
84 const string16& verification_code() const { return verification_code_; } | |
85 const string16& last_four_digits() const { return last_four_digits_; } | 79 const string16& last_four_digits() const { return last_four_digits_; } |
86 int expiration_month() const { return expiration_month_; } | 80 int expiration_month() const { return expiration_month_; } |
87 int expiration_year() const { return expiration_year_; } | 81 int expiration_year() const { return expiration_year_; } |
88 | 82 |
89 void set_number(const string16& number) { number_ = number; } | 83 void set_number(const string16& number) { number_ = number; } |
90 void set_name_on_card(const string16& name_on_card) { | 84 void set_name_on_card(const string16& name_on_card) { |
91 name_on_card_ = name_on_card; | 85 name_on_card_ = name_on_card; |
92 } | 86 } |
93 void set_type(const string16& type) { type_ = type; } | 87 void set_type(const string16& type) { type_ = type; } |
94 void set_verification_code(const string16& verification_code) { | |
95 verification_code_ = verification_code; | |
96 } | |
97 void set_last_four_digits(const string16& last_four_digits) { | 88 void set_last_four_digits(const string16& last_four_digits) { |
98 last_four_digits_ = last_four_digits; | 89 last_four_digits_ = last_four_digits; |
99 } | 90 } |
100 | 91 |
101 // These setters verify that the month and year are within appropriate | 92 // These setters verify that the month and year are within appropriate |
102 // ranges. | 93 // ranges. |
103 void set_expiration_month(int expiration_month); | 94 void set_expiration_month(int expiration_month); |
104 void set_expiration_year(int expiration_year); | 95 void set_expiration_year(int expiration_year); |
105 | 96 |
106 // A helper function for FindInfoMatches that only handles matching the info | 97 // A helper function for FindInfoMatches that only handles matching the info |
107 // with the requested field type. | 98 // with the requested field type. |
108 bool FindInfoMatchesHelper(const AutoFillFieldType& field_type, | 99 bool FindInfoMatchesHelper(const AutoFillFieldType& field_type, |
109 const string16& info, | 100 const string16& info, |
110 string16* match) const; | 101 string16* match) const; |
111 | 102 |
112 // Returns true if |text| matches the name on the card. The comparison is | 103 // Returns true if |text| matches the name on the card. The comparison is |
113 // case-insensitive. | 104 // case-insensitive. |
114 bool IsNameOnCard(const string16& text) const; | 105 bool IsNameOnCard(const string16& text) const; |
115 | 106 |
116 // Returns true if |text| matches the expiration month of the card. | 107 // Returns true if |text| matches the expiration month of the card. |
117 bool IsExpirationMonth(const string16& text) const; | 108 bool IsExpirationMonth(const string16& text) const; |
118 | 109 |
119 // Returns true if |text| matches the CVV of the card. The comparison is | |
120 // case-insensitive. | |
121 bool IsVerificationCode(const string16& text) const; | |
122 | |
123 // Returns true if the integer value of |text| matches the 2-digit expiration | 110 // Returns true if the integer value of |text| matches the 2-digit expiration |
124 // year. | 111 // year. |
125 bool Is2DigitExpirationYear(const string16& text) const; | 112 bool Is2DigitExpirationYear(const string16& text) const; |
126 | 113 |
127 // Returns true if the integer value of |text| matches the 4-digit expiration | 114 // Returns true if the integer value of |text| matches the 4-digit expiration |
128 // year. | 115 // year. |
129 bool Is4DigitExpirationYear(const string16& text) const; | 116 bool Is4DigitExpirationYear(const string16& text) const; |
130 | 117 |
131 // Returns true if |text| matches the type of the card. The comparison is | 118 // Returns true if |text| matches the type of the card. The comparison is |
132 // case-insensitive. | 119 // case-insensitive. |
133 bool IsCardType(const string16& text) const; | 120 bool IsCardType(const string16& text) const; |
134 | 121 |
135 // Converts |date| to an integer form. Returns true if the conversion | 122 // Converts |date| to an integer form. Returns true if the conversion |
136 // succeeded. | 123 // succeeded. |
137 bool ConvertDate(const string16& date, int* num) const; | 124 bool ConvertDate(const string16& date, int* num) const; |
138 | 125 |
139 string16 number_; // The credit card number. | 126 string16 number_; // The credit card number. |
140 string16 name_on_card_; // The cardholder's name. | 127 string16 name_on_card_; // The cardholder's name. |
141 string16 type_; // The type of the card. | 128 string16 type_; // The type of the card. |
142 string16 verification_code_; // The CVV. | |
143 | 129 |
144 // Stores the last four digits of the credit card number. | 130 // Stores the last four digits of the credit card number. |
145 string16 last_four_digits_; | 131 string16 last_four_digits_; |
146 | 132 |
147 // These members are zero if not present. | 133 // These members are zero if not present. |
148 int expiration_month_; | 134 int expiration_month_; |
149 int expiration_year_; | 135 int expiration_year_; |
150 | 136 |
151 // This is the display name of the card set by the user, e.g., Amazon Visa. | 137 // This is the display name of the card set by the user, e.g., Amazon Visa. |
152 string16 label_; | 138 string16 label_; |
153 | 139 |
154 // The billing and shipping addresses. The are the labels of | 140 // The billing address. This is the label of the AutoFillProfile that contains |
155 // AutoFillProfiles that contain the corresponding address. If | 141 // the corresponding billing address. |
156 // |shipping_address_| is empty, the billing address is used for the shipping | |
157 // address. | |
158 string16 billing_address_; | 142 string16 billing_address_; |
159 string16 shipping_address_; | |
160 | 143 |
161 // The unique ID of this credit card. | 144 // The unique ID of this credit card. |
162 int unique_id_; | 145 int unique_id_; |
163 }; | 146 }; |
164 | 147 |
165 // So we can compare CreditCards with EXPECT_EQ(). | 148 // So we can compare CreditCards with EXPECT_EQ(). |
166 std::ostream& operator<<(std::ostream& os, const CreditCard& creditcard); | 149 std::ostream& operator<<(std::ostream& os, const CreditCard& creditcard); |
167 | 150 |
168 #endif // CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_ | 151 #endif // CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_ |
OLD | NEW |