| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <ostream> | 10 #include <ostream> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "components/autofill/core/browser/autofill_field.h" | 22 #include "components/autofill/core/browser/autofill_field.h" |
| 23 #include "components/autofill/core/browser/autofill_regexes.h" | 23 #include "components/autofill/core/browser/autofill_regexes.h" |
| 24 #include "components/autofill/core/browser/autofill_type.h" | 24 #include "components/autofill/core/browser/autofill_type.h" |
| 25 #include "components/autofill/core/browser/validation.h" | 25 #include "components/autofill/core/browser/validation.h" |
| 26 #include "components/autofill/core/common/form_field_data.h" | 26 #include "components/autofill/core/common/form_field_data.h" |
| 27 #include "grit/component_resources.h" |
| 27 #include "grit/component_strings.h" | 28 #include "grit/component_strings.h" |
| 28 #include "third_party/icu/source/common/unicode/uloc.h" | 29 #include "third_party/icu/source/common/unicode/uloc.h" |
| 29 #include "third_party/icu/source/i18n/unicode/dtfmtsym.h" | 30 #include "third_party/icu/source/i18n/unicode/dtfmtsym.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 31 | 32 |
| 32 // TODO(blundell): Eliminate the need for this conditional include. | |
| 33 // crbug.com/328150 | |
| 34 #if !defined(OS_IOS) | |
| 35 #include "grit/webkit_resources.h" | |
| 36 #endif | |
| 37 | |
| 38 namespace autofill { | 33 namespace autofill { |
| 39 | 34 |
| 40 namespace { | 35 namespace { |
| 41 | 36 |
| 42 const base::char16 kCreditCardObfuscationSymbol = '*'; | 37 const base::char16 kCreditCardObfuscationSymbol = '*'; |
| 43 | 38 |
| 44 // This is the maximum obfuscated symbols displayed. | 39 // This is the maximum obfuscated symbols displayed. |
| 45 // It is introduced to avoid rare cases where the credit card number is | 40 // It is introduced to avoid rare cases where the credit card number is |
| 46 // too large and fills the screen. | 41 // too large and fills the screen. |
| 47 const size_t kMaxObfuscationSize = 20; | 42 const size_t kMaxObfuscationSize = 20; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); | 157 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); |
| 163 | 158 |
| 164 // 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 |
| 165 // include a new card. | 160 // include a new card. |
| 166 DCHECK_EQ(kGenericCard, type); | 161 DCHECK_EQ(kGenericCard, type); |
| 167 return base::string16(); | 162 return base::string16(); |
| 168 } | 163 } |
| 169 | 164 |
| 170 // static | 165 // static |
| 171 int CreditCard::IconResourceId(const std::string& type) { | 166 int CreditCard::IconResourceId(const std::string& type) { |
| 172 // TODO(blundell): Either move these resources out of webkit_resources or | |
| 173 // this function into //components/autofill/content/browser to eliminate the | |
| 174 // need for this ifdef-ing. crbug.com/328150 | |
| 175 #if defined(OS_IOS) | |
| 176 return 0; | |
| 177 #else | |
| 178 if (type == kAmericanExpressCard) | 167 if (type == kAmericanExpressCard) |
| 179 return IDR_AUTOFILL_CC_AMEX; | 168 return IDR_AUTOFILL_CC_AMEX; |
| 180 if (type == kDinersCard) | 169 if (type == kDinersCard) |
| 181 return IDR_AUTOFILL_CC_DINERS; | 170 return IDR_AUTOFILL_CC_DINERS; |
| 182 if (type == kDiscoverCard) | 171 if (type == kDiscoverCard) |
| 183 return IDR_AUTOFILL_CC_DISCOVER; | 172 return IDR_AUTOFILL_CC_DISCOVER; |
| 184 if (type == kJCBCard) | 173 if (type == kJCBCard) |
| 185 return IDR_AUTOFILL_CC_JCB; | 174 return IDR_AUTOFILL_CC_JCB; |
| 186 if (type == kMasterCard) | 175 if (type == kMasterCard) |
| 187 return IDR_AUTOFILL_CC_MASTERCARD; | 176 return IDR_AUTOFILL_CC_MASTERCARD; |
| 188 if (type == kUnionPay) | 177 if (type == kUnionPay) |
| 189 return IDR_AUTOFILL_CC_GENERIC; // Needs resource: http://crbug.com/259211 | 178 return IDR_AUTOFILL_CC_GENERIC; // Needs resource: http://crbug.com/259211 |
| 190 if (type == kVisaCard) | 179 if (type == kVisaCard) |
| 191 return IDR_AUTOFILL_CC_VISA; | 180 return IDR_AUTOFILL_CC_VISA; |
| 192 | 181 |
| 193 // 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 |
| 194 // include a new card. | 183 // include a new card. |
| 195 DCHECK_EQ(kGenericCard, type); | 184 DCHECK_EQ(kGenericCard, type); |
| 196 return IDR_AUTOFILL_CC_GENERIC; | 185 return IDR_AUTOFILL_CC_GENERIC; |
| 197 #endif // defined(OS_IOS) | |
| 198 } | 186 } |
| 199 | 187 |
| 200 // static | 188 // static |
| 201 std::string CreditCard::GetCreditCardType(const base::string16& number) { | 189 std::string CreditCard::GetCreditCardType(const base::string16& number) { |
| 202 // Credit card number specifications taken from: | 190 // Credit card number specifications taken from: |
| 203 // http://en.wikipedia.org/wiki/Credit_card_numbers, | 191 // http://en.wikipedia.org/wiki/Credit_card_numbers, |
| 204 // http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers, | 192 // http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers, |
| 205 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, | 193 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, |
| 206 // http://www.regular-expressions.info/creditcard.html, | 194 // http://www.regular-expressions.info/creditcard.html, |
| 207 // http://developer.ean.com/general_info/Valid_Credit_Card_Types, | 195 // http://developer.ean.com/general_info/Valid_Credit_Card_Types, |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 const char* const kAmericanExpressCard = "americanExpressCC"; | 686 const char* const kAmericanExpressCard = "americanExpressCC"; |
| 699 const char* const kDinersCard = "dinersCC"; | 687 const char* const kDinersCard = "dinersCC"; |
| 700 const char* const kDiscoverCard = "discoverCC"; | 688 const char* const kDiscoverCard = "discoverCC"; |
| 701 const char* const kGenericCard = "genericCC"; | 689 const char* const kGenericCard = "genericCC"; |
| 702 const char* const kJCBCard = "jcbCC"; | 690 const char* const kJCBCard = "jcbCC"; |
| 703 const char* const kMasterCard = "masterCardCC"; | 691 const char* const kMasterCard = "masterCardCC"; |
| 704 const char* const kUnionPay = "unionPayCC"; | 692 const char* const kUnionPay = "unionPayCC"; |
| 705 const char* const kVisaCard = "visaCC"; | 693 const char* const kVisaCard = "visaCC"; |
| 706 | 694 |
| 707 } // namespace autofill | 695 } // namespace autofill |
| OLD | NEW |