| 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> |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | 300 case CREDIT_CARD_EXP_2_DIGIT_YEAR: |
| 301 return Expiration2DigitYearAsString(); | 301 return Expiration2DigitYearAsString(); |
| 302 | 302 |
| 303 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 303 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 304 return Expiration4DigitYearAsString(); | 304 return Expiration4DigitYearAsString(); |
| 305 | 305 |
| 306 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: { | 306 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: { |
| 307 base::string16 month = ExpirationMonthAsString(); | 307 base::string16 month = ExpirationMonthAsString(); |
| 308 base::string16 year = Expiration2DigitYearAsString(); | 308 base::string16 year = Expiration2DigitYearAsString(); |
| 309 if (!month.empty() && !year.empty()) | 309 if (!month.empty() && !year.empty()) |
| 310 return month + ASCIIToUTF16("/") + year; | 310 return month + base::ASCIIToUTF16("/") + year; |
| 311 return base::string16(); | 311 return base::string16(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { | 314 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { |
| 315 base::string16 month = ExpirationMonthAsString(); | 315 base::string16 month = ExpirationMonthAsString(); |
| 316 base::string16 year = Expiration4DigitYearAsString(); | 316 base::string16 year = Expiration4DigitYearAsString(); |
| 317 if (!month.empty() && !year.empty()) | 317 if (!month.empty() && !year.empty()) |
| 318 return month + ASCIIToUTF16("/") + year; | 318 return month + base::ASCIIToUTF16("/") + year; |
| 319 return base::string16(); | 319 return base::string16(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 case CREDIT_CARD_TYPE: | 322 case CREDIT_CARD_TYPE: |
| 323 return TypeForDisplay(); | 323 return TypeForDisplay(); |
| 324 | 324 |
| 325 case CREDIT_CARD_NUMBER: | 325 case CREDIT_CARD_NUMBER: |
| 326 return number_; | 326 return number_; |
| 327 | 327 |
| 328 case CREDIT_CARD_VERIFICATION_CODE: | 328 case CREDIT_CARD_VERIFICATION_CODE: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 base::string16 label; | 428 base::string16 label; |
| 429 if (number().empty()) | 429 if (number().empty()) |
| 430 return name_on_card_; // No CC number, return name only. | 430 return name_on_card_; // No CC number, return name only. |
| 431 | 431 |
| 432 base::string16 obfuscated_cc_number = ObfuscatedNumber(); | 432 base::string16 obfuscated_cc_number = ObfuscatedNumber(); |
| 433 if (!expiration_month_ || !expiration_year_) | 433 if (!expiration_month_ || !expiration_year_) |
| 434 return obfuscated_cc_number; // No expiration date set. | 434 return obfuscated_cc_number; // No expiration date set. |
| 435 | 435 |
| 436 // TODO(georgey): Internationalize date. | 436 // TODO(georgey): Internationalize date. |
| 437 base::string16 formatted_date(ExpirationMonthAsString()); | 437 base::string16 formatted_date(ExpirationMonthAsString()); |
| 438 formatted_date.append(ASCIIToUTF16("/")); | 438 formatted_date.append(base::ASCIIToUTF16("/")); |
| 439 formatted_date.append(Expiration4DigitYearAsString()); | 439 formatted_date.append(Expiration4DigitYearAsString()); |
| 440 | 440 |
| 441 label = l10n_util::GetStringFUTF16(IDS_CREDIT_CARD_NUMBER_PREVIEW_FORMAT, | 441 label = l10n_util::GetStringFUTF16(IDS_CREDIT_CARD_NUMBER_PREVIEW_FORMAT, |
| 442 obfuscated_cc_number, | 442 obfuscated_cc_number, |
| 443 formatted_date); | 443 formatted_date); |
| 444 return label; | 444 return label; |
| 445 } | 445 } |
| 446 | 446 |
| 447 void CreditCard::SetInfoForMonthInputType(const base::string16& value) { | 447 void CreditCard::SetInfoForMonthInputType(const base::string16& value) { |
| 448 // Check if |text| is "yyyy-mm" format first, and check normal month format. | 448 // Check if |text| is "yyyy-mm" format first, and check normal month format. |
| 449 if (!autofill::MatchesPattern(value, UTF8ToUTF16("^[0-9]{4}-[0-9]{1,2}$"))) | 449 if (!autofill::MatchesPattern(value, |
| 450 base::UTF8ToUTF16("^[0-9]{4}-[0-9]{1,2}$"))) { |
| 450 return; | 451 return; |
| 452 } |
| 451 | 453 |
| 452 std::vector<base::string16> year_month; | 454 std::vector<base::string16> year_month; |
| 453 base::SplitString(value, L'-', &year_month); | 455 base::SplitString(value, L'-', &year_month); |
| 454 DCHECK_EQ((int)year_month.size(), 2); | 456 DCHECK_EQ((int)year_month.size(), 2); |
| 455 int num = 0; | 457 int num = 0; |
| 456 bool converted = false; | 458 bool converted = false; |
| 457 converted = base::StringToInt(year_month[0], &num); | 459 converted = base::StringToInt(year_month[0], &num); |
| 458 DCHECK(converted); | 460 DCHECK(converted); |
| 459 SetExpirationYear(num); | 461 SetExpirationYear(num); |
| 460 converted = base::StringToInt(year_month[1], &num); | 462 converted = base::StringToInt(year_month[1], &num); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 base::string16 CreditCard::TypeAndLastFourDigits() const { | 494 base::string16 CreditCard::TypeAndLastFourDigits() const { |
| 493 base::string16 type = TypeForDisplay(); | 495 base::string16 type = TypeForDisplay(); |
| 494 // TODO(estade): type may be empty, we probably want to return | 496 // TODO(estade): type may be empty, we probably want to return |
| 495 // "Card - 1234" or something in that case. | 497 // "Card - 1234" or something in that case. |
| 496 | 498 |
| 497 base::string16 digits = LastFourDigits(); | 499 base::string16 digits = LastFourDigits(); |
| 498 if (digits.empty()) | 500 if (digits.empty()) |
| 499 return type; | 501 return type; |
| 500 | 502 |
| 501 // TODO(estade): i18n. | 503 // TODO(estade): i18n. |
| 502 return type + ASCIIToUTF16(" - ") + digits; | 504 return type + base::ASCIIToUTF16(" - ") + digits; |
| 503 } | 505 } |
| 504 | 506 |
| 505 void CreditCard::operator=(const CreditCard& credit_card) { | 507 void CreditCard::operator=(const CreditCard& credit_card) { |
| 506 if (this == &credit_card) | 508 if (this == &credit_card) |
| 507 return; | 509 return; |
| 508 | 510 |
| 509 number_ = credit_card.number_; | 511 number_ = credit_card.number_; |
| 510 name_on_card_ = credit_card.name_on_card_; | 512 name_on_card_ = credit_card.name_on_card_; |
| 511 type_ = credit_card.type_; | 513 type_ = credit_card.type_; |
| 512 expiration_month_ = credit_card.expiration_month_; | 514 expiration_month_ = credit_card.expiration_month_; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 607 } |
| 606 | 608 |
| 607 base::string16 CreditCard::ExpirationMonthAsString() const { | 609 base::string16 CreditCard::ExpirationMonthAsString() const { |
| 608 if (expiration_month_ == 0) | 610 if (expiration_month_ == 0) |
| 609 return base::string16(); | 611 return base::string16(); |
| 610 | 612 |
| 611 base::string16 month = base::IntToString16(expiration_month_); | 613 base::string16 month = base::IntToString16(expiration_month_); |
| 612 if (expiration_month_ >= 10) | 614 if (expiration_month_ >= 10) |
| 613 return month; | 615 return month; |
| 614 | 616 |
| 615 base::string16 zero = ASCIIToUTF16("0"); | 617 base::string16 zero = base::ASCIIToUTF16("0"); |
| 616 zero.append(month); | 618 zero.append(month); |
| 617 return zero; | 619 return zero; |
| 618 } | 620 } |
| 619 | 621 |
| 620 base::string16 CreditCard::Expiration4DigitYearAsString() const { | 622 base::string16 CreditCard::Expiration4DigitYearAsString() const { |
| 621 if (expiration_year_ == 0) | 623 if (expiration_year_ == 0) |
| 622 return base::string16(); | 624 return base::string16(); |
| 623 | 625 |
| 624 return base::IntToString16(Expiration4DigitYear()); | 626 return base::IntToString16(Expiration4DigitYear()); |
| 625 } | 627 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 (expiration_year < 2006 || expiration_year > 10000)) { | 667 (expiration_year < 2006 || expiration_year > 10000)) { |
| 666 return; | 668 return; |
| 667 } | 669 } |
| 668 | 670 |
| 669 expiration_year_ = expiration_year; | 671 expiration_year_ = expiration_year; |
| 670 } | 672 } |
| 671 | 673 |
| 672 // So we can compare CreditCards with EXPECT_EQ(). | 674 // So we can compare CreditCards with EXPECT_EQ(). |
| 673 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { | 675 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { |
| 674 return os | 676 return os |
| 675 << UTF16ToUTF8(credit_card.Label()) | 677 << base::UTF16ToUTF8(credit_card.Label()) |
| 676 << " " | 678 << " " |
| 677 << credit_card.guid() | 679 << credit_card.guid() |
| 678 << " " | 680 << " " |
| 679 << credit_card.origin() | 681 << credit_card.origin() |
| 680 << " " | 682 << " " |
| 681 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NAME)) | 683 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NAME)) |
| 682 << " " | 684 << " " |
| 683 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_TYPE)) | 685 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_TYPE)) |
| 684 << " " | 686 << " " |
| 685 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER)) | 687 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER)) |
| 686 << " " | 688 << " " |
| 687 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) | 689 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) |
| 688 << " " | 690 << " " |
| 689 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 691 << base::UTF16ToUTF8( |
| 692 credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 690 } | 693 } |
| 691 | 694 |
| 692 // These values must match the values in WebKitPlatformSupportImpl in | 695 // These values must match the values in WebKitPlatformSupportImpl in |
| 693 // webkit/glue. We send these strings to WebKit, which then asks | 696 // webkit/glue. We send these strings to WebKit, which then asks |
| 694 // WebKitPlatformSupportImpl to load the image data. | 697 // WebKitPlatformSupportImpl to load the image data. |
| 695 const char* const kAmericanExpressCard = "americanExpressCC"; | 698 const char* const kAmericanExpressCard = "americanExpressCC"; |
| 696 const char* const kDinersCard = "dinersCC"; | 699 const char* const kDinersCard = "dinersCC"; |
| 697 const char* const kDiscoverCard = "discoverCC"; | 700 const char* const kDiscoverCard = "discoverCC"; |
| 698 const char* const kGenericCard = "genericCC"; | 701 const char* const kGenericCard = "genericCC"; |
| 699 const char* const kJCBCard = "jcbCC"; | 702 const char* const kJCBCard = "jcbCC"; |
| 700 const char* const kMasterCard = "masterCardCC"; | 703 const char* const kMasterCard = "masterCardCC"; |
| 701 const char* const kUnionPay = "unionPayCC"; | 704 const char* const kUnionPay = "unionPayCC"; |
| 702 const char* const kVisaCard = "visaCC"; | 705 const char* const kVisaCard = "visaCC"; |
| 703 | 706 |
| 704 } // namespace autofill | 707 } // namespace autofill |
| OLD | NEW |