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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 base::string16 CreditCard::GetInfo(const AutofillType& type, | 375 base::string16 CreditCard::GetInfo(const AutofillType& type, |
376 const std::string& app_locale) const { | 376 const std::string& app_locale) const { |
377 ServerFieldType storable_type = type.GetStorableType(); | 377 ServerFieldType storable_type = type.GetStorableType(); |
378 if (storable_type == CREDIT_CARD_NUMBER) { | 378 if (storable_type == CREDIT_CARD_NUMBER) { |
379 // Web pages should never actually be filled by a masked server card, | 379 // Web pages should never actually be filled by a masked server card, |
380 // but this function is used at the preview stage. | 380 // but this function is used at the preview stage. |
381 if (record_type() == MASKED_SERVER_CARD) | 381 if (record_type() == MASKED_SERVER_CARD) |
382 return TypeAndLastFourDigits(); | 382 return TypeAndLastFourDigitsForDisplay(); |
383 | 383 |
384 return StripSeparators(number_); | 384 return StripSeparators(number_); |
385 } | 385 } |
386 | 386 |
387 return GetRawInfo(storable_type); | 387 return GetRawInfo(storable_type); |
388 } | 388 } |
389 | 389 |
390 bool CreditCard::SetInfo(const AutofillType& type, | 390 bool CreditCard::SetInfo(const AutofillType& type, |
391 const base::string16& value, | 391 const base::string16& value, |
392 const std::string& app_locale) { | 392 const std::string& app_locale) { |
(...skipping 30 matching lines...) Expand all Loading... |
423 return pieces.first + pieces.second; | 423 return pieces.first + pieces.second; |
424 } | 424 } |
425 | 425 |
426 const std::pair<base::string16, base::string16> CreditCard::LabelPieces() | 426 const std::pair<base::string16, base::string16> CreditCard::LabelPieces() |
427 const { | 427 const { |
428 base::string16 label; | 428 base::string16 label; |
429 // No CC number, return name only. | 429 // No CC number, return name only. |
430 if (number().empty()) | 430 if (number().empty()) |
431 return std::make_pair(name_on_card_, base::string16()); | 431 return std::make_pair(name_on_card_, base::string16()); |
432 | 432 |
433 base::string16 obfuscated_cc_number = TypeAndLastFourDigits(); | 433 base::string16 obfuscated_cc_number = TypeAndLastFourDigitsForDisplay(); |
434 // No expiration date set. | 434 // No expiration date set. |
435 if (!expiration_month_ || !expiration_year_) | 435 if (!expiration_month_ || !expiration_year_) |
436 return std::make_pair(obfuscated_cc_number, base::string16()); | 436 return std::make_pair(obfuscated_cc_number, base::string16()); |
437 | 437 |
438 base::string16 formatted_date(ExpirationMonthAsString()); | 438 base::string16 formatted_date(ExpirationMonthAsString()); |
439 formatted_date.append(base::ASCIIToUTF16("/")); | 439 formatted_date.append(base::ASCIIToUTF16("/")); |
440 formatted_date.append(Expiration4DigitYearAsString()); | 440 formatted_date.append(Expiration4DigitYearAsString()); |
441 | 441 |
442 base::string16 separator = | 442 base::string16 separator = |
443 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); | 443 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 base::string16 CreditCard::LastFourDigits() const { | 479 base::string16 CreditCard::LastFourDigits() const { |
480 static const size_t kNumLastDigits = 4; | 480 static const size_t kNumLastDigits = 4; |
481 | 481 |
482 base::string16 number = StripSeparators(number_); | 482 base::string16 number = StripSeparators(number_); |
483 if (number.size() <= kNumLastDigits) | 483 if (number.size() <= kNumLastDigits) |
484 return number; | 484 return number; |
485 | 485 |
486 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); | 486 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); |
487 } | 487 } |
488 | 488 |
| 489 base::string16 CreditCard::LastFourDigitsForDisplay() const { |
| 490 base::string16 digits = LastFourDigits(); |
| 491 // Prepend the midline horizontal ellipsis (U+22EF). |
| 492 // TODO(estade): i18n? |
| 493 return digits.empty() ? base::string16() |
| 494 : base::UTF8ToUTF16("\xE2\x8B\xAF") + digits; |
| 495 } |
| 496 |
489 base::string16 CreditCard::TypeForDisplay() const { | 497 base::string16 CreditCard::TypeForDisplay() const { |
490 return CreditCard::TypeForDisplay(type_); | 498 return CreditCard::TypeForDisplay(type_); |
491 } | 499 } |
492 | 500 |
493 base::string16 CreditCard::TypeAndLastFourDigits() const { | 501 base::string16 CreditCard::TypeAndLastFourDigitsForDisplay() const { |
494 base::string16 type = TypeForDisplay(); | 502 base::string16 type = TypeForDisplay(); |
495 | 503 |
496 base::string16 digits = LastFourDigits(); | 504 base::string16 digits = LastFourDigitsForDisplay(); |
497 if (digits.empty()) | 505 if (digits.empty()) |
498 return type; | 506 return type; |
499 | 507 |
500 // The separator character is a non breaking space and a horizontal midline | 508 // The separator character is a non breaking space. |
501 // ellipsis. | 509 return type + base::UTF8ToUTF16("\xC2\xA0") + digits; |
502 // TODO(estade): i18n? | 510 } |
503 return type + base::UTF8ToUTF16("\xC2\xA0\xE2\x8B\xAF") + digits; | 511 |
| 512 base::string16 CreditCard::AbbreviatedExpirationDateForDisplay() const { |
| 513 base::string16 month = ExpirationMonthAsString(); |
| 514 base::string16 year = Expiration2DigitYearAsString(); |
| 515 return month.empty() || year.empty() |
| 516 ? base::string16() |
| 517 : l10n_util::GetStringFUTF16( |
| 518 IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_ABBR, month, year); |
504 } | 519 } |
505 | 520 |
506 void CreditCard::operator=(const CreditCard& credit_card) { | 521 void CreditCard::operator=(const CreditCard& credit_card) { |
507 set_use_count(credit_card.use_count()); | 522 set_use_count(credit_card.use_count()); |
508 set_use_date(credit_card.use_date()); | 523 set_use_date(credit_card.use_date()); |
509 set_modification_date(credit_card.modification_date()); | 524 set_modification_date(credit_card.modification_date()); |
510 | 525 |
511 if (this == &credit_card) | 526 if (this == &credit_card) |
512 return; | 527 return; |
513 | 528 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 return false; | 616 return false; |
602 } | 617 } |
603 | 618 |
604 if (number_.empty()) | 619 if (number_.empty()) |
605 return true; | 620 return true; |
606 | 621 |
607 if (other.record_type() == FULL_SERVER_CARD) | 622 if (other.record_type() == FULL_SERVER_CARD) |
608 return StripSeparators(number_) == StripSeparators(other.number_); | 623 return StripSeparators(number_) == StripSeparators(other.number_); |
609 | 624 |
610 // For masked cards, this is the best we can do to compare card numbers. | 625 // For masked cards, this is the best we can do to compare card numbers. |
611 return TypeAndLastFourDigits() == other.TypeAndLastFourDigits(); | 626 return TypeAndLastFourDigitsForDisplay() == |
| 627 other.TypeAndLastFourDigitsForDisplay(); |
612 } | 628 } |
613 | 629 |
614 bool CreditCard::operator==(const CreditCard& credit_card) const { | 630 bool CreditCard::operator==(const CreditCard& credit_card) const { |
615 return guid() == credit_card.guid() && | 631 return guid() == credit_card.guid() && |
616 origin() == credit_card.origin() && | 632 origin() == credit_card.origin() && |
617 Compare(credit_card) == 0; | 633 Compare(credit_card) == 0; |
618 } | 634 } |
619 | 635 |
620 bool CreditCard::operator!=(const CreditCard& credit_card) const { | 636 bool CreditCard::operator!=(const CreditCard& credit_card) const { |
621 return !operator==(credit_card); | 637 return !operator==(credit_card); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 const char kAmericanExpressCard[] = "americanExpressCC"; | 806 const char kAmericanExpressCard[] = "americanExpressCC"; |
791 const char kDinersCard[] = "dinersCC"; | 807 const char kDinersCard[] = "dinersCC"; |
792 const char kDiscoverCard[] = "discoverCC"; | 808 const char kDiscoverCard[] = "discoverCC"; |
793 const char kGenericCard[] = "genericCC"; | 809 const char kGenericCard[] = "genericCC"; |
794 const char kJCBCard[] = "jcbCC"; | 810 const char kJCBCard[] = "jcbCC"; |
795 const char kMasterCard[] = "masterCardCC"; | 811 const char kMasterCard[] = "masterCardCC"; |
796 const char kUnionPay[] = "unionPayCC"; | 812 const char kUnionPay[] = "unionPayCC"; |
797 const char kVisaCard[] = "visaCC"; | 813 const char kVisaCard[] = "visaCC"; |
798 | 814 |
799 } // namespace autofill | 815 } // namespace autofill |
OLD | NEW |