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 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 GetNonEmptyTypes(app_locale, &types); | 657 GetNonEmptyTypes(app_locale, &types); |
658 return types.empty(); | 658 return types.empty(); |
659 } | 659 } |
660 | 660 |
661 bool CreditCard::IsValid() const { | 661 bool CreditCard::IsValid() const { |
662 return IsValidCreditCardNumber(number_) && | 662 return IsValidCreditCardNumber(number_) && |
663 IsValidCreditCardExpirationDate(expiration_year_, expiration_month_, | 663 IsValidCreditCardExpirationDate(expiration_year_, expiration_month_, |
664 AutofillClock::Now()); | 664 AutofillClock::Now()); |
665 } | 665 } |
666 | 666 |
667 void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { | |
668 supported_types->insert(CREDIT_CARD_NAME_FULL); | |
669 supported_types->insert(CREDIT_CARD_NAME_FIRST); | |
670 supported_types->insert(CREDIT_CARD_NAME_LAST); | |
671 supported_types->insert(CREDIT_CARD_NUMBER); | |
672 supported_types->insert(CREDIT_CARD_TYPE); | |
673 supported_types->insert(CREDIT_CARD_EXP_MONTH); | |
674 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); | |
675 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); | |
676 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); | |
677 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); | |
678 } | |
679 | |
680 base::string16 CreditCard::ExpirationMonthAsString() const { | |
681 if (expiration_month_ == 0) | |
682 return base::string16(); | |
683 | |
684 base::string16 month = base::IntToString16(expiration_month_); | |
685 if (expiration_month_ >= 10) | |
686 return month; | |
687 | |
688 base::string16 zero = ASCIIToUTF16("0"); | |
689 zero.append(month); | |
690 return zero; | |
691 } | |
692 | |
693 base::string16 CreditCard::TypeForFill() const { | |
694 return ::autofill::TypeForFill(type_); | |
695 } | |
696 | |
697 base::string16 CreditCard::Expiration4DigitYearAsString() const { | |
698 if (expiration_year_ == 0) | |
699 return base::string16(); | |
700 | |
701 return base::IntToString16(Expiration4DigitYear()); | |
702 } | |
703 | |
704 base::string16 CreditCard::Expiration2DigitYearAsString() const { | |
705 if (expiration_year_ == 0) | |
706 return base::string16(); | |
707 | |
708 return base::IntToString16(Expiration2DigitYear()); | |
709 } | |
710 | |
711 bool CreditCard::SetExpirationMonthFromString(const base::string16& text, | 667 bool CreditCard::SetExpirationMonthFromString(const base::string16& text, |
712 const std::string& app_locale) { | 668 const std::string& app_locale) { |
713 base::string16 trimmed; | 669 base::string16 trimmed; |
714 base::TrimWhitespace(text, base::TRIM_ALL, &trimmed); | 670 base::TrimWhitespace(text, base::TRIM_ALL, &trimmed); |
715 | 671 |
716 int month = 0; | 672 int month = 0; |
717 if (!ConvertMonth(trimmed, app_locale, &month)) | 673 if (!ConvertMonth(trimmed, app_locale, &month)) |
718 return false; | 674 return false; |
719 | 675 |
720 SetExpirationMonth(month); | 676 SetExpirationMonth(month); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 int num = 0; | 724 int num = 0; |
769 bool converted = false; | 725 bool converted = false; |
770 converted = base::StringToInt(month, &num); | 726 converted = base::StringToInt(month, &num); |
771 DCHECK(converted); | 727 DCHECK(converted); |
772 SetExpirationMonth(num); | 728 SetExpirationMonth(num); |
773 converted = base::StringToInt(year, &num); | 729 converted = base::StringToInt(year, &num); |
774 DCHECK(converted); | 730 DCHECK(converted); |
775 SetExpirationYear(num); | 731 SetExpirationYear(num); |
776 } | 732 } |
777 | 733 |
| 734 void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { |
| 735 supported_types->insert(CREDIT_CARD_NAME_FULL); |
| 736 supported_types->insert(CREDIT_CARD_NAME_FIRST); |
| 737 supported_types->insert(CREDIT_CARD_NAME_LAST); |
| 738 supported_types->insert(CREDIT_CARD_NUMBER); |
| 739 supported_types->insert(CREDIT_CARD_TYPE); |
| 740 supported_types->insert(CREDIT_CARD_EXP_MONTH); |
| 741 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
| 742 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
| 743 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); |
| 744 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); |
| 745 } |
| 746 |
| 747 base::string16 CreditCard::ExpirationMonthAsString() const { |
| 748 if (expiration_month_ == 0) |
| 749 return base::string16(); |
| 750 |
| 751 base::string16 month = base::IntToString16(expiration_month_); |
| 752 if (expiration_month_ >= 10) |
| 753 return month; |
| 754 |
| 755 base::string16 zero = ASCIIToUTF16("0"); |
| 756 zero.append(month); |
| 757 return zero; |
| 758 } |
| 759 |
| 760 base::string16 CreditCard::TypeForFill() const { |
| 761 return ::autofill::TypeForFill(type_); |
| 762 } |
| 763 |
| 764 base::string16 CreditCard::Expiration4DigitYearAsString() const { |
| 765 if (expiration_year_ == 0) |
| 766 return base::string16(); |
| 767 |
| 768 return base::IntToString16(Expiration4DigitYear()); |
| 769 } |
| 770 |
| 771 base::string16 CreditCard::Expiration2DigitYearAsString() const { |
| 772 if (expiration_year_ == 0) |
| 773 return base::string16(); |
| 774 |
| 775 return base::IntToString16(Expiration2DigitYear()); |
| 776 } |
| 777 |
778 void CreditCard::SetNumber(const base::string16& number) { | 778 void CreditCard::SetNumber(const base::string16& number) { |
779 number_ = number; | 779 number_ = number; |
780 | 780 |
781 // Set the type based on the card number, but only for full numbers, not | 781 // Set the type based on the card number, but only for full numbers, not |
782 // when we have masked cards from the server (last 4 digits). | 782 // when we have masked cards from the server (last 4 digits). |
783 if (record_type_ != MASKED_SERVER_CARD) | 783 if (record_type_ != MASKED_SERVER_CARD) |
784 type_ = GetCreditCardType(StripSeparators(number_)); | 784 type_ = GetCreditCardType(StripSeparators(number_)); |
785 } | 785 } |
786 | 786 |
787 void CreditCard::RecordAndLogUse() { | 787 void CreditCard::RecordAndLogUse() { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 const char kDinersCard[] = "dinersCC"; | 873 const char kDinersCard[] = "dinersCC"; |
874 const char kDiscoverCard[] = "discoverCC"; | 874 const char kDiscoverCard[] = "discoverCC"; |
875 const char kGenericCard[] = "genericCC"; | 875 const char kGenericCard[] = "genericCC"; |
876 const char kJCBCard[] = "jcbCC"; | 876 const char kJCBCard[] = "jcbCC"; |
877 const char kMasterCard[] = "masterCardCC"; | 877 const char kMasterCard[] = "masterCardCC"; |
878 const char kMirCard[] = "mirCC"; | 878 const char kMirCard[] = "mirCC"; |
879 const char kUnionPay[] = "unionPayCC"; | 879 const char kUnionPay[] = "unionPayCC"; |
880 const char kVisaCard[] = "visaCC"; | 880 const char kVisaCard[] = "visaCC"; |
881 | 881 |
882 } // namespace autofill | 882 } // namespace autofill |
OLD | NEW |