OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CORE_BROWSER_CREDIT_CARD_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_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/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "components/autofill/core/browser/autofill_data_model.h" | 14 #include "components/autofill/core/browser/autofill_data_model.h" |
15 | 15 |
16 namespace autofill { | 16 namespace autofill { |
17 | 17 |
18 // A form group that stores credit card information. | 18 // A form group that stores credit card information. |
19 class CreditCard : public AutofillDataModel { | 19 class CreditCard : public AutofillDataModel { |
20 public: | 20 public: |
21 CreditCard(const std::string& guid, const std::string& origin); | 21 CreditCard(const std::string& guid, const std::string& origin); |
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 ~CreditCard() override; |
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 base::string16 StripSeparators(const base::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 base::string16 TypeForDisplay(const std::string& type); | 32 static base::string16 TypeForDisplay(const std::string& type); |
33 | 33 |
34 // The ResourceBundle ID for the appropriate credit card image. | 34 // The ResourceBundle ID for the appropriate credit card image. |
35 static int IconResourceId(const std::string& type); | 35 static int IconResourceId(const std::string& type); |
36 | 36 |
37 // Returns the internal representation of credit card type corresponding to | 37 // Returns the internal representation of credit card type corresponding to |
38 // the given |number|. The credit card type is determined purely according to | 38 // the given |number|. The credit card type is determined purely according to |
39 // the Issuer Identification Number (IIN), a.k.a. the "Bank Identification | 39 // the Issuer Identification Number (IIN), a.k.a. the "Bank Identification |
40 // Number (BIN)", which is parsed from the relevant prefix of the |number|. | 40 // Number (BIN)", which is parsed from the relevant prefix of the |number|. |
41 // This function performs no additional validation checks on the |number|. | 41 // This function performs no additional validation checks on the |number|. |
42 // Hence, the returned type for both the valid card "4111-1111-1111-1111" and | 42 // Hence, the returned type for both the valid card "4111-1111-1111-1111" and |
43 // the invalid card "4garbage" will be Visa, which has an IIN of 4. | 43 // the invalid card "4garbage" will be Visa, which has an IIN of 4. |
44 static const char* GetCreditCardType(const base::string16& number); | 44 static const char* GetCreditCardType(const base::string16& number); |
45 | 45 |
46 // FormGroup: | 46 // FormGroup: |
47 virtual void GetMatchingTypes( | 47 void GetMatchingTypes(const base::string16& text, |
48 const base::string16& text, | 48 const std::string& app_locale, |
49 const std::string& app_locale, | 49 ServerFieldTypeSet* matching_types) const override; |
50 ServerFieldTypeSet* matching_types) const override; | 50 base::string16 GetRawInfo(ServerFieldType type) const override; |
51 virtual base::string16 GetRawInfo(ServerFieldType type) const override; | 51 void SetRawInfo(ServerFieldType type, const base::string16& value) override; |
52 virtual void SetRawInfo(ServerFieldType type, | 52 base::string16 GetInfo(const AutofillType& type, |
53 const base::string16& value) override; | 53 const std::string& app_locale) const override; |
54 virtual base::string16 GetInfo(const AutofillType& type, | 54 bool SetInfo(const AutofillType& type, |
55 const std::string& app_locale) const override; | 55 const base::string16& value, |
56 virtual bool SetInfo(const AutofillType& type, | 56 const std::string& app_locale) override; |
57 const base::string16& value, | |
58 const std::string& app_locale) override; | |
59 | 57 |
60 // Credit card preview summary, for example: ******1234, Exp: 01/2020 | 58 // Credit card preview summary, for example: ******1234, Exp: 01/2020 |
61 const base::string16 Label() const; | 59 const base::string16 Label() const; |
62 | 60 |
63 // Special method to set value for HTML5 month input type. | 61 // Special method to set value for HTML5 month input type. |
64 void SetInfoForMonthInputType(const base::string16& value); | 62 void SetInfoForMonthInputType(const base::string16& value); |
65 | 63 |
66 // The number altered for display, for example: ******1234 | 64 // The number altered for display, for example: ******1234 |
67 base::string16 ObfuscatedNumber() const; | 65 base::string16 ObfuscatedNumber() const; |
68 // The last four digits of the credit card number. | 66 // The last four digits of the credit card number. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 105 |
108 // Returns true if all field types have valid values set and the card is not | 106 // Returns true if all field types have valid values set and the card is not |
109 // expired. | 107 // expired. |
110 bool IsValid() const; | 108 bool IsValid() const; |
111 | 109 |
112 // Returns the credit card number. | 110 // Returns the credit card number. |
113 const base::string16& number() const { return number_; } | 111 const base::string16& number() const { return number_; } |
114 | 112 |
115 private: | 113 private: |
116 // FormGroup: | 114 // FormGroup: |
117 virtual void GetSupportedTypes( | 115 void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override; |
118 ServerFieldTypeSet* supported_types) const override; | |
119 | 116 |
120 // The month and year are zero if not present. | 117 // The month and year are zero if not present. |
121 int Expiration4DigitYear() const { return expiration_year_; } | 118 int Expiration4DigitYear() const { return expiration_year_; } |
122 int Expiration2DigitYear() const { return expiration_year_ % 100; } | 119 int Expiration2DigitYear() const { return expiration_year_ % 100; } |
123 base::string16 ExpirationMonthAsString() const; | 120 base::string16 ExpirationMonthAsString() const; |
124 base::string16 Expiration4DigitYearAsString() const; | 121 base::string16 Expiration4DigitYearAsString() const; |
125 base::string16 Expiration2DigitYearAsString() const; | 122 base::string16 Expiration2DigitYearAsString() const; |
126 | 123 |
127 // Sets |expiration_month_| to the integer conversion of |text|. | 124 // Sets |expiration_month_| to the integer conversion of |text|. |
128 void SetExpirationMonthFromString(const base::string16& text, | 125 void SetExpirationMonthFromString(const base::string16& text, |
(...skipping 28 matching lines...) Expand all Loading... |
157 extern const char* const kDiscoverCard; | 154 extern const char* const kDiscoverCard; |
158 extern const char* const kGenericCard; | 155 extern const char* const kGenericCard; |
159 extern const char* const kJCBCard; | 156 extern const char* const kJCBCard; |
160 extern const char* const kMasterCard; | 157 extern const char* const kMasterCard; |
161 extern const char* const kUnionPay; | 158 extern const char* const kUnionPay; |
162 extern const char* const kVisaCard; | 159 extern const char* const kVisaCard; |
163 | 160 |
164 } // namespace autofill | 161 } // namespace autofill |
165 | 162 |
166 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ | 163 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ |
OLD | NEW |