| 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 #include "chrome/browser/autofill/credit_card.h" | 5 #include "chrome/browser/autofill/credit_card.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" | 
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" | 
|  | 11 #include "base/string_split.h" | 
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" | 
| 12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" | 
| 13 #include "base/string16.h" | 14 #include "base/string16.h" | 
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" | 
| 15 #include "chrome/browser/autofill/autofill_type.h" | 16 #include "chrome/browser/autofill/autofill_type.h" | 
| 16 #include "chrome/browser/autofill/field_types.h" | 17 #include "chrome/browser/autofill/field_types.h" | 
| 17 #include "chrome/common/guid.h" | 18 #include "chrome/common/guid.h" | 
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" | 
|  | 20 #include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h" | 
|  | 21 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 
| 19 | 22 | 
| 20 namespace { | 23 namespace { | 
| 21 | 24 | 
| 22 const char* kCreditCardObfuscationString = "************"; | 25 const char* kCreditCardObfuscationString = "************"; | 
| 23 | 26 | 
| 24 const AutoFillFieldType kAutoFillCreditCardTypes[] = { | 27 const AutoFillFieldType kAutoFillCreditCardTypes[] = { | 
| 25   CREDIT_CARD_NAME, | 28   CREDIT_CARD_NAME, | 
| 26   CREDIT_CARD_NUMBER, | 29   CREDIT_CARD_NUMBER, | 
| 27   CREDIT_CARD_TYPE, | 30   CREDIT_CARD_TYPE, | 
| 28   CREDIT_CARD_EXP_MONTH, | 31   CREDIT_CARD_EXP_MONTH, | 
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 436 | 439 | 
| 437   return (sum % 10) == 0; | 440   return (sum % 10) == 0; | 
| 438 } | 441 } | 
| 439 | 442 | 
| 440 bool CreditCard::IsEmpty() const { | 443 bool CreditCard::IsEmpty() const { | 
| 441   FieldTypeSet types; | 444   FieldTypeSet types; | 
| 442   GetAvailableFieldTypes(&types); | 445   GetAvailableFieldTypes(&types); | 
| 443   return types.empty(); | 446   return types.empty(); | 
| 444 } | 447 } | 
| 445 | 448 | 
|  | 449 void CreditCard::SetMonthInputInfo(const string16& value) { | 
|  | 450   // Check if |text| is "yyyy-mm" format first, and check normal month format. | 
|  | 451   WebKit::WebRegularExpression re(WebKit::WebString("^[0-9]{4}\\-[0-9]{1,2}$"), | 
|  | 452                                   WebKit::WebTextCaseInsensitive); | 
|  | 453   bool match = re.match(WebKit::WebString(StringToLowerASCII(value))) != -1; | 
|  | 454   if (match) { | 
|  | 455     std::vector<string16> year_month; | 
|  | 456     base::SplitString(value, L'-', &year_month); | 
|  | 457     DCHECK_EQ((int)year_month.size(), 2); | 
|  | 458     int num = 0; | 
|  | 459     bool converted = false; | 
|  | 460     converted = base::StringToInt(year_month[0], &num); | 
|  | 461     DCHECK(converted); | 
|  | 462     set_expiration_year(num); | 
|  | 463     converted = base::StringToInt(year_month[1], &num); | 
|  | 464     DCHECK(converted); | 
|  | 465     set_expiration_month(num); | 
|  | 466   } | 
|  | 467 } | 
|  | 468 | 
| 446 string16 CreditCard::ExpirationMonthAsString() const { | 469 string16 CreditCard::ExpirationMonthAsString() const { | 
| 447   if (expiration_month_ == 0) | 470   if (expiration_month_ == 0) | 
| 448     return string16(); | 471     return string16(); | 
| 449 | 472 | 
| 450   string16 month = base::IntToString16(expiration_month_); | 473   string16 month = base::IntToString16(expiration_month_); | 
| 451   if (expiration_month_ >= 10) | 474   if (expiration_month_ >= 10) | 
| 452     return month; | 475     return month; | 
| 453 | 476 | 
| 454   string16 zero = ASCIIToUTF16("0"); | 477   string16 zero = ASCIIToUTF16("0"); | 
| 455   zero.append(month); | 478   zero.append(month); | 
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 636 // send these strings to WK, which then asks WebKitClientImpl to load the image | 659 // send these strings to WK, which then asks WebKitClientImpl to load the image | 
| 637 // data. | 660 // data. | 
| 638 const char* const kAmericanExpressCard = "americanExpressCC"; | 661 const char* const kAmericanExpressCard = "americanExpressCC"; | 
| 639 const char* const kDinersCard = "dinersCC"; | 662 const char* const kDinersCard = "dinersCC"; | 
| 640 const char* const kDiscoverCard = "discoverCC"; | 663 const char* const kDiscoverCard = "discoverCC"; | 
| 641 const char* const kGenericCard = "genericCC"; | 664 const char* const kGenericCard = "genericCC"; | 
| 642 const char* const kJCBCard = "jcbCC"; | 665 const char* const kJCBCard = "jcbCC"; | 
| 643 const char* const kMasterCard = "masterCardCC"; | 666 const char* const kMasterCard = "masterCardCC"; | 
| 644 const char* const kSoloCard = "soloCC"; | 667 const char* const kSoloCard = "soloCC"; | 
| 645 const char* const kVisaCard = "visaCC"; | 668 const char* const kVisaCard = "visaCC"; | 
| OLD | NEW | 
|---|