#include "components/autofill/core/browser/data_model/credit_card.h"
#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <ostream>
#include <string_view>
#include "base/check_op.h"
#include "base/i18n/rtl.h"
#include "base/i18n/time_formatting.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/data_model/data_model_utils.h"
#include "components/autofill/core/browser/data_model/payments_metadata.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/payments/constants.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_regexes.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/credit_card_number_validation.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
namespace autofill {
namespace {
constexpr char16_t kCreditCardObfuscationSymbol = …;
constexpr char16_t kWhiteSpaceSeparator = …;
constexpr int kMaxNicknameLength = …;
constexpr std::array<int, 3> k15DigitAmexNumberSegmentations = …;
constexpr std::array<int, 4> k16DigitNumberSegmentations = …;
constexpr char kVirtualCardIdentifierSuffix[] = …;
std::u16string NetworkForFill(const std::string& network) { … }
std::u16string GetLastFourDigits(const std::u16string& number) { … }
std::u16string AddWhiteSpaceSeparatorForNumber(const std::u16string& number,
base::span<const int> segments) { … }
Suggestion::Icon ConvertCardNetworkIntoIcon(std::string_view network) { … }
}
CreditCard CreditCard::CreateVirtualCard(const CreditCard& card) { … }
std::unique_ptr<CreditCard> CreditCard::CreateVirtualCardWithGuidSuffix(
const CreditCard& card) { … }
std::u16string CreditCard::GetObfuscatedStringForCardDigits(
int obfuscation_length,
const std::u16string& digits) { … }
CreditCard::CreditCard(const std::string& guid, const std::string& origin)
: … { … }
CreditCard::CreditCard(RecordType type, const std::string& server_id)
: … { … }
CreditCard::CreditCard(RecordType type, int64_t instrument_id) : … { … }
CreditCard::CreditCard()
: … { … }
CreditCard::CreditCard(const CreditCard& credit_card) = default;
CreditCard::CreditCard(CreditCard&& credit_card) = default;
CreditCard& CreditCard::operator=(const CreditCard& credit_card) = default;
CreditCard& CreditCard::operator=(CreditCard&& credit_card) = default;
CreditCard::~CreditCard() = default;
std::u16string CreditCard::NetworkForDisplay(const std::string& network) { … }
int CreditCard::IconResourceId(Suggestion::Icon icon) { … }
int CreditCard::IconResourceId(std::string_view icon_str) { … }
bool CreditCard::IsNicknameValid(const std::u16string& nickname) { … }
std::u16string CreditCard::GetMidlineEllipsisDots(size_t num_dots) { … }
std::u16string CreditCard::GetMidlineEllipsisPlainDots(size_t num_dots) { … }
bool CreditCard::IsLocalCard(const CreditCard* card) { … }
void CreditCard::SetNetworkForMaskedCard(std::string_view network) { … }
PaymentsMetadata CreditCard::GetMetadata() const { … }
double CreditCard::GetRankingScore(base::Time current_time,
bool use_frecency) const { … }
bool CreditCard::HasGreaterRankingThan(const CreditCard& other,
base::Time comparison_time,
bool use_frecency) const { … }
bool CreditCard::SetMetadata(const PaymentsMetadata& metadata) { … }
bool CreditCard::IsDeletable() const { … }
std::u16string CreditCard::GetRawInfo(FieldType type) const { … }
void CreditCard::SetRawInfoWithVerificationStatus(FieldType type,
const std::u16string& value,
VerificationStatus status) { … }
void CreditCard::GetMatchingTypes(const std::u16string& text,
const std::string& app_locale,
FieldTypeSet* matching_types) const { … }
void CreditCard::SetInfoForMonthInputType(const std::u16string& value) { … }
void CreditCard::SetExpirationMonth(int expiration_month) { … }
void CreditCard::SetExpirationYear(int expiration_year) { … }
void CreditCard::SetNickname(const std::u16string& nickname) { … }
bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card,
const std::string& app_locale) { … }
int CreditCard::Compare(const CreditCard& credit_card) const { … }
bool CreditCard::IsLocalOrServerDuplicateOf(const CreditCard& other) const { … }
bool CreditCard::MatchingCardDetails(const CreditCard& other) const { … }
bool CreditCard::HasSameNumberAs(const CreditCard& other) const { … }
bool CreditCard::HasSameExpirationDateAs(const CreditCard& other) const { … }
bool CreditCard::operator==(const CreditCard& credit_card) const { … }
bool CreditCard::IsVerified() const { … }
bool CreditCard::IsEmpty(const std::string& app_locale) const { … }
bool CreditCard::IsValid() const { … }
bool CreditCard::HasValidCardNumber() const { … }
bool CreditCard::HasValidExpirationYear() const { … }
bool CreditCard::HasValidExpirationDate() const { … }
bool CreditCard::SetExpirationMonthFromString(const std::u16string& text,
const std::string& app_locale) { … }
bool CreditCard::SetExpirationYearFromString(const std::u16string& text) { … }
void CreditCard::SetExpirationDateFromString(const std::u16string& text) { … }
std::pair<std::u16string, std::u16string> CreditCard::LabelPieces() const { … }
std::u16string CreditCard::Label() const { … }
std::u16string CreditCard::LastFourDigits() const { … }
std::u16string CreditCard::FullDigitsForDisplay() const { … }
std::u16string CreditCard::NetworkForDisplay() const { … }
std::u16string CreditCard::ObfuscatedNumberWithVisibleLastFourDigits(
int obfuscation_length) const { … }
std::u16string
CreditCard::ObfuscatedNumberWithVisibleLastFourDigitsForSplitFields() const { … }
Suggestion::Icon CreditCard::CardIconForAutofillSuggestion() const { … }
std::u16string CreditCard::NetworkAndLastFourDigits(
int obfuscation_length) const { … }
std::u16string CreditCard::CardNameAndLastFourDigits(
std::u16string customized_nickname,
int obfuscation_length) const { … }
std::u16string CreditCard::CardNameForAutofillDisplay(
const std::u16string& customized_nickname) const { … }
#if BUILDFLAG(IS_ANDROID)
std::u16string CreditCard::CardIdentifierStringForManualFilling() const {
std::u16string obfuscated_number =
ObfuscatedNumberWithVisibleLastFourDigits();
if (record_type_ == RecordType::kVirtualCard) {
return l10n_util::GetStringUTF16(
IDS_AUTOFILL_VIRTUAL_CARD_SUGGESTION_OPTION_VALUE) +
u" " + obfuscated_number;
}
return obfuscated_number;
}
#endif
std::u16string CreditCard::CardIdentifierStringAndDescriptiveExpiration(
const std::string& app_locale,
std::u16string customized_nickname) const { … }
std::u16string CreditCard::DescriptiveExpiration(
const std::string& app_locale) const { … }
std::u16string CreditCard::AbbreviatedExpirationDateForDisplay(
bool with_prefix) const { … }
std::u16string CreditCard::ExpirationDateForDisplay() const { … }
std::u16string CreditCard::Expiration2DigitMonthAsString() const { … }
std::u16string CreditCard::Expiration2DigitYearAsString() const { … }
std::u16string CreditCard::Expiration4DigitYearAsString() const { … }
bool CreditCard::HasNameOnCard() const { … }
bool CreditCard::HasNonEmptyValidNickname() const { … }
std::u16string CreditCard::NicknameAndLastFourDigitsForTesting() const { … }
bool CreditCard::HasRichCardArtImageFromMetadata() const { … }
void CreditCard::GetSupportedTypes(FieldTypeSet* supported_types) const { … }
std::u16string CreditCard::GetInfoImpl(const AutofillType& type,
const std::string& app_locale) const { … }
bool CreditCard::SetInfoWithVerificationStatusImpl(
const AutofillType& type,
const std::u16string& value,
const std::string& app_locale,
VerificationStatus status) { … }
std::u16string CreditCard::NetworkForFill() const { … }
std::u16string CreditCard::NicknameAndLastFourDigits(
std::u16string customized_nickname,
int obfuscation_length) const { … }
void CreditCard::SetNumber(const std::u16string& number) { … }
void CreditCard::RecordAndLogUse() { … }
bool CreditCard::IsExpired(base::Time current_time) const { … }
bool CreditCard::masked() const { … }
bool CreditCard::ShouldUpdateExpiration() const { … }
bool CreditCard::IsCompleteValidCard() const { … }
std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { … }
void CreditCard::SetNameOnCardFromSeparateParts() { … }
}