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 #include "components/autofill/core/browser/credit_card.h" | 5 #include "components/autofill/core/browser/credit_card.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <ostream> | 9 #include <ostream> |
10 #include <string> | 10 #include <string> |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 if (type == kAmericanExpressCard) | 144 if (type == kAmericanExpressCard) |
145 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); | 145 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); |
146 if (type == kDinersCard) | 146 if (type == kDinersCard) |
147 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); | 147 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); |
148 if (type == kDiscoverCard) | 148 if (type == kDiscoverCard) |
149 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); | 149 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); |
150 if (type == kJCBCard) | 150 if (type == kJCBCard) |
151 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); | 151 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); |
152 if (type == kMasterCard) | 152 if (type == kMasterCard) |
153 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); | 153 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); |
| 154 if (type == kUnionPay) |
| 155 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY); |
154 if (type == kVisaCard) | 156 if (type == kVisaCard) |
155 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); | 157 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); |
156 | 158 |
157 // If you hit this DCHECK, the above list of cases needs to be updated to | 159 // If you hit this DCHECK, the above list of cases needs to be updated to |
158 // include a new card. | 160 // include a new card. |
159 DCHECK_EQ(kGenericCard, type); | 161 DCHECK_EQ(kGenericCard, type); |
160 return base::string16(); | 162 return base::string16(); |
161 } | 163 } |
162 | 164 |
163 // static | 165 // static |
164 int CreditCard::IconResourceId(const std::string& type) { | 166 int CreditCard::IconResourceId(const std::string& type) { |
165 if (type == kAmericanExpressCard) | 167 if (type == kAmericanExpressCard) |
166 return IDR_AUTOFILL_CC_AMEX; | 168 return IDR_AUTOFILL_CC_AMEX; |
167 if (type == kDinersCard) | 169 if (type == kDinersCard) |
168 return IDR_AUTOFILL_CC_DINERS; | 170 return IDR_AUTOFILL_CC_DINERS; |
169 if (type == kDiscoverCard) | 171 if (type == kDiscoverCard) |
170 return IDR_AUTOFILL_CC_DISCOVER; | 172 return IDR_AUTOFILL_CC_DISCOVER; |
171 if (type == kJCBCard) | 173 if (type == kJCBCard) |
172 return IDR_AUTOFILL_CC_JCB; | 174 return IDR_AUTOFILL_CC_JCB; |
173 if (type == kMasterCard) | 175 if (type == kMasterCard) |
174 return IDR_AUTOFILL_CC_MASTERCARD; | 176 return IDR_AUTOFILL_CC_MASTERCARD; |
| 177 if (type == kUnionPay) |
| 178 return IDR_AUTOFILL_CC_GENERIC; // Needs resource: http://crbug.com/259211 |
175 if (type == kVisaCard) | 179 if (type == kVisaCard) |
176 return IDR_AUTOFILL_CC_VISA; | 180 return IDR_AUTOFILL_CC_VISA; |
177 | 181 |
178 // If you hit this DCHECK, the above list of cases needs to be updated to | 182 // If you hit this DCHECK, the above list of cases needs to be updated to |
179 // include a new card. | 183 // include a new card. |
180 DCHECK_EQ(kGenericCard, type); | 184 DCHECK_EQ(kGenericCard, type); |
181 return IDR_AUTOFILL_CC_GENERIC; | 185 return IDR_AUTOFILL_CC_GENERIC; |
182 } | 186 } |
183 | 187 |
184 // static | 188 // static |
185 std::string CreditCard::GetCreditCardType(const base::string16& number) { | 189 std::string CreditCard::GetCreditCardType(const base::string16& number) { |
186 // Credit card number specifications taken from: | 190 // Credit card number specifications taken from: |
187 // http://en.wikipedia.org/wiki/Credit_card_numbers, | 191 // http://en.wikipedia.org/wiki/Credit_card_numbers, |
| 192 // http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers, |
188 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, | 193 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, |
189 // http://www.regular-expressions.info/creditcard.html, and | 194 // http://www.regular-expressions.info/creditcard.html, |
| 195 // http://developer.ean.com/general_info/Valid_Credit_Card_Types, |
| 196 // http://www.bincodes.com/, |
| 197 // http://www.fraudpractice.com/FL-binCC.html, and |
190 // http://www.beachnet.com/~hstiles/cardtype.html | 198 // http://www.beachnet.com/~hstiles/cardtype.html |
191 // | 199 // |
192 // The last site is currently unavailable, but a cached version remains at | 200 // The last site is currently unavailable, but a cached version remains at |
193 // http://web.archive.org/web/20120923111349/http://www.beachnet.com/~hstiles/
cardtype.html | 201 // http://web.archive.org/web/20120923111349/http://www.beachnet.com/~hstiles/
cardtype.html |
194 // | 202 // |
195 // Card Type Prefix(es) Length | 203 // Card Type Prefix(es) Length |
196 // --------------------------------------------------------------- | 204 // --------------------------------------------------------------- |
197 // Visa 4 13,16 | 205 // Visa 4 13,16 |
198 // American Express 34,37 15 | 206 // American Express 34,37 15 |
199 // Diners Club 300-305,3095,36,38-39 14 | 207 // Diners Club 300-305,3095,36,38-39 14 |
200 // Discover Card 6011,644-649,65 16 | 208 // Discover Card 6011,644-649,65 16 |
201 // JCB 3528-3589 16 | 209 // JCB 3528-3589 16 |
202 // MasterCard 51-55 16 | 210 // MasterCard 51-55 16 |
| 211 // UnionPay 62 16-19 |
203 | 212 |
204 // Check for prefixes of length 1. | 213 // Check for prefixes of length 1. |
205 if (number.empty()) | 214 if (number.empty()) |
206 return kGenericCard; | 215 return kGenericCard; |
207 | 216 |
208 if (number[0] == '4') | 217 if (number[0] == '4') |
209 return kVisaCard; | 218 return kVisaCard; |
210 | 219 |
211 // Check for prefixes of length 2. | 220 // Check for prefixes of length 2. |
212 if (number.size() < 2) | 221 if (number.size() < 2) |
213 return kGenericCard; | 222 return kGenericCard; |
214 | 223 |
215 int first_two_digits = 0; | 224 int first_two_digits = 0; |
216 if (!base::StringToInt(number.substr(0, 2), &first_two_digits)) | 225 if (!base::StringToInt(number.substr(0, 2), &first_two_digits)) |
217 return kGenericCard; | 226 return kGenericCard; |
218 | 227 |
219 if (first_two_digits == 34 || first_two_digits == 37) | 228 if (first_two_digits == 34 || first_two_digits == 37) |
220 return kAmericanExpressCard; | 229 return kAmericanExpressCard; |
221 | 230 |
222 if (first_two_digits == 36 || | 231 if (first_two_digits == 36 || |
223 first_two_digits == 38 || | 232 first_two_digits == 38 || |
224 first_two_digits == 39) | 233 first_two_digits == 39) |
225 return kDinersCard; | 234 return kDinersCard; |
226 | 235 |
227 if (first_two_digits >= 51 && first_two_digits <= 55) | 236 if (first_two_digits >= 51 && first_two_digits <= 55) |
228 return kMasterCard; | 237 return kMasterCard; |
229 | 238 |
| 239 if (first_two_digits == 62) |
| 240 return kUnionPay; |
| 241 |
230 if (first_two_digits == 65) | 242 if (first_two_digits == 65) |
231 return kDiscoverCard; | 243 return kDiscoverCard; |
232 | 244 |
233 // Check for prefixes of length 3. | 245 // Check for prefixes of length 3. |
234 if (number.size() < 3) | 246 if (number.size() < 3) |
235 return kGenericCard; | 247 return kGenericCard; |
236 | 248 |
237 int first_three_digits = 0; | 249 int first_three_digits = 0; |
238 if (!base::StringToInt(number.substr(0, 3), &first_three_digits)) | 250 if (!base::StringToInt(number.substr(0, 3), &first_three_digits)) |
239 return kGenericCard; | 251 return kGenericCard; |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 697 |
686 // These values must match the values in WebKitPlatformSupportImpl in | 698 // These values must match the values in WebKitPlatformSupportImpl in |
687 // webkit/glue. We send these strings to WebKit, which then asks | 699 // webkit/glue. We send these strings to WebKit, which then asks |
688 // WebKitPlatformSupportImpl to load the image data. | 700 // WebKitPlatformSupportImpl to load the image data. |
689 const char* const kAmericanExpressCard = "americanExpressCC"; | 701 const char* const kAmericanExpressCard = "americanExpressCC"; |
690 const char* const kDinersCard = "dinersCC"; | 702 const char* const kDinersCard = "dinersCC"; |
691 const char* const kDiscoverCard = "discoverCC"; | 703 const char* const kDiscoverCard = "discoverCC"; |
692 const char* const kGenericCard = "genericCC"; | 704 const char* const kGenericCard = "genericCC"; |
693 const char* const kJCBCard = "jcbCC"; | 705 const char* const kJCBCard = "jcbCC"; |
694 const char* const kMasterCard = "masterCardCC"; | 706 const char* const kMasterCard = "masterCardCC"; |
| 707 const char* const kUnionPay = "unionPayCC"; |
695 const char* const kVisaCard = "visaCC"; | 708 const char* const kVisaCard = "visaCC"; |
696 | 709 |
697 } // namespace autofill | 710 } // namespace autofill |
OLD | NEW |