Chromium Code Reviews| 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, |
| 188 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, | 192 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, |
| 189 // http://www.regular-expressions.info/creditcard.html, and | 193 // http://www.regular-expressions.info/creditcard.html, and |
| 190 // http://www.beachnet.com/~hstiles/cardtype.html | 194 // http://www.beachnet.com/~hstiles/cardtype.html |
| 191 // | 195 // |
| 192 // The last site is currently unavailable, but a cached version remains at | 196 // 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 | 197 // http://web.archive.org/web/20120923111349/http://www.beachnet.com/~hstiles/ cardtype.html |
| 194 // | 198 // |
| 195 // Card Type Prefix(es) Length | 199 // Card Type Prefix(es) Length |
| 196 // --------------------------------------------------------------- | 200 // --------------------------------------------------------------- |
| 197 // Visa 4 13,16 | 201 // Visa 4 13,16 |
| 198 // American Express 34,37 15 | 202 // American Express 34,37 15 |
| 199 // Diners Club 300-305,3095,36,38-39 14 | 203 // Diners Club 300-305,3095,36,38-39 14 |
| 200 // Discover Card 6011,644-649,65 16 | 204 // Discover Card 6011,644-649,65 16 |
| 201 // JCB 3528-3589 16 | 205 // JCB 3528-3589 16 |
| 202 // MasterCard 51-55 16 | 206 // MasterCard 51-55 16 |
| 207 // UnionPay 62 16 | |
|
Albert Bodenhamer
2013/07/11 16:28:42
Wikipedia claims 62 or 88 with a length of 16-19 h
Ilya Sherman
2013/07/12 01:06:47
AFAICT, 62 is the only prefix that most places ten
| |
| 203 | 208 |
| 204 // Check for prefixes of length 1. | 209 // Check for prefixes of length 1. |
| 205 if (number.empty()) | 210 if (number.empty()) |
| 206 return kGenericCard; | 211 return kGenericCard; |
| 207 | 212 |
| 208 if (number[0] == '4') | 213 if (number[0] == '4') |
| 209 return kVisaCard; | 214 return kVisaCard; |
| 210 | 215 |
| 211 // Check for prefixes of length 2. | 216 // Check for prefixes of length 2. |
| 212 if (number.size() < 2) | 217 if (number.size() < 2) |
| 213 return kGenericCard; | 218 return kGenericCard; |
| 214 | 219 |
| 215 int first_two_digits = 0; | 220 int first_two_digits = 0; |
| 216 if (!base::StringToInt(number.substr(0, 2), &first_two_digits)) | 221 if (!base::StringToInt(number.substr(0, 2), &first_two_digits)) |
| 217 return kGenericCard; | 222 return kGenericCard; |
| 218 | 223 |
| 219 if (first_two_digits == 34 || first_two_digits == 37) | 224 if (first_two_digits == 34 || first_two_digits == 37) |
| 220 return kAmericanExpressCard; | 225 return kAmericanExpressCard; |
| 221 | 226 |
| 222 if (first_two_digits == 36 || | 227 if (first_two_digits == 36 || |
| 223 first_two_digits == 38 || | 228 first_two_digits == 38 || |
| 224 first_two_digits == 39) | 229 first_two_digits == 39) |
| 225 return kDinersCard; | 230 return kDinersCard; |
| 226 | 231 |
| 227 if (first_two_digits >= 51 && first_two_digits <= 55) | 232 if (first_two_digits >= 51 && first_two_digits <= 55) |
| 228 return kMasterCard; | 233 return kMasterCard; |
| 229 | 234 |
| 235 if (first_two_digits == 62) | |
| 236 return kUnionPay; | |
| 237 | |
| 230 if (first_two_digits == 65) | 238 if (first_two_digits == 65) |
| 231 return kDiscoverCard; | 239 return kDiscoverCard; |
| 232 | 240 |
| 233 // Check for prefixes of length 3. | 241 // Check for prefixes of length 3. |
| 234 if (number.size() < 3) | 242 if (number.size() < 3) |
| 235 return kGenericCard; | 243 return kGenericCard; |
| 236 | 244 |
| 237 int first_three_digits = 0; | 245 int first_three_digits = 0; |
| 238 if (!base::StringToInt(number.substr(0, 3), &first_three_digits)) | 246 if (!base::StringToInt(number.substr(0, 3), &first_three_digits)) |
| 239 return kGenericCard; | 247 return kGenericCard; |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 | 693 |
| 686 // These values must match the values in WebKitPlatformSupportImpl in | 694 // These values must match the values in WebKitPlatformSupportImpl in |
| 687 // webkit/glue. We send these strings to WebKit, which then asks | 695 // webkit/glue. We send these strings to WebKit, which then asks |
| 688 // WebKitPlatformSupportImpl to load the image data. | 696 // WebKitPlatformSupportImpl to load the image data. |
| 689 const char* const kAmericanExpressCard = "americanExpressCC"; | 697 const char* const kAmericanExpressCard = "americanExpressCC"; |
| 690 const char* const kDinersCard = "dinersCC"; | 698 const char* const kDinersCard = "dinersCC"; |
| 691 const char* const kDiscoverCard = "discoverCC"; | 699 const char* const kDiscoverCard = "discoverCC"; |
| 692 const char* const kGenericCard = "genericCC"; | 700 const char* const kGenericCard = "genericCC"; |
| 693 const char* const kJCBCard = "jcbCC"; | 701 const char* const kJCBCard = "jcbCC"; |
| 694 const char* const kMasterCard = "masterCardCC"; | 702 const char* const kMasterCard = "masterCardCC"; |
| 703 const char* const kUnionPay = "unionPayCC"; | |
| 695 const char* const kVisaCard = "visaCC"; | 704 const char* const kVisaCard = "visaCC"; |
| 696 | 705 |
| 697 } // namespace autofill | 706 } // namespace autofill |
| OLD | NEW |