chromium/components/autofill/core/browser/field_filling_payments_util.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/field_filling_payments_util.h"

#include <optional>

#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/data_model_utils.h"
#include "components/autofill/core/browser/field_type_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_filler.h"
#include "components/autofill/core/browser/form_parsing/credit_card_field_parser.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/select_control_util.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"

namespace autofill {

namespace {

// Gets the expiration month `value` inside the <select> or <selectlist>
// `field`. Since `value` is well defined but the website's `field` option
// values may not be, some heuristics are run to cover all observed cases.
std::u16string GetExpirationMonthSelectControlValue(
    const std::u16string& value,
    const std::string& app_locale,
    base::span<const SelectOption> field_options,
    std::string* failure_to_fill) {}

// Returns true if the last two digits in `year` match those in `str`.
bool LastTwoDigitsMatch(const std::u16string& year,
                        const std::u16string& option) {}

// Gets the year `value` in a select control to fill into the given `field` by
// comparing the last two digits of the year to the field's options.
// Returns an empty string if no value for filling was found.
std::u16string GetYearSelectControlValue(
    const std::u16string& value,
    base::span<const SelectOption> field_options,
    std::string* failure_to_fill) {}

// Gets the credit card type `value` (Visa, Mastercard, etc.) to fill into the
// given `field`. We ignore whitespace when filling credit card types to
// allow for cases such as "Master card".
// Returns an empty string if no value for filling was found.
std::u16string GetCreditCardTypeSelectControlValue(
    const std::u16string& value,
    base::span<const SelectOption> field_options,
    std::string* failure_to_fill) {}

std::u16string TruncateCardNumberIfNecessary(size_t card_number_offset,
                                             uint64_t field_max_length,
                                             const std::u16string& value) {}

// Returns the appropriate credit card number from `credit_card`. Truncates the
// credit card number to be split across HTML form input fields depending on if
// 'field.credit_card_number_offset()' is less than the length of the credit
// card number.
std::u16string GetCreditCardNumberForInput(
    const CreditCard& credit_card,
    size_t card_number_offset,
    uint64_t field_max_length,
    const std::string& app_locale,
    mojom::ActionPersistence action_persistence) {}

// Returns the appropriate credit card number from `virtual_card`. Truncates the
// credit card number to be split across HTML form input fields depending on if
// 'field.credit_card_number_offset()' is less than the length of the credit
// card number.
std::u16string GetVirtualCardNumberForPreviewInput(
    const CreditCard& virtual_card,
    size_t card_number_offset,
    uint64_t field_max_length) {}

// Returns the credit card CVC for Preview or Fill.
std::u16string GetCreditCardVerificationCodeForInput(
    const CreditCard& credit_card,
    mojom::ActionPersistence action_persistence,
    const std::u16string& cvc) {}

// Gets the appropriate expiration date from the |card| for a month control
// field. (i.e. a <input type="month">)
std::u16string GetExpirationForMonthControl(const CreditCard& card) {}

// Returns the appropriate expiration year from `credit_card` for the field.
// Uses the `field`'s type and the `field`'s max_length attribute to
// determine if the year needs to be truncated.
std::u16string GetExpirationYearForInput(const CreditCard& credit_card,
                                         FieldType field_type,
                                         uint64_t field_max_length) {}

// Returns the appropriate expiration date from `credit_card` for the field
// based on the `field_type`. If the field contains a recognized date format
// string, the function follows that format. Otherwise, it uses the `field`'s
// max_length attribute to determine if the `value` needs to be truncated or
// padded. Returns an empty string in case of a failure.
std::u16string GetExpirationDateForInput(const CreditCard& credit_card,
                                         const AutofillField& field,
                                         std::string* failure_to_fill) {}

// Returns the appropriate `credit_card` value based on `field`'s type to fill
// into the input `field`.
std::u16string GetFillingValueForCreditCardForInput(
    const CreditCard& credit_card,
    const std::u16string& cvc,
    const std::string& app_locale,
    mojom::ActionPersistence action_persistence,
    const AutofillField& field,
    std::string* failure_to_fill) {}

// Replaces the digits in `value` with dots. Used for credit card preview when
// obfuscating card information to the user.
std::u16string ReplaceDigitsWithCenterDots(std::u16string value) {}

// Returns the appropriate `virtual_card` value based on the type of `field` to
// preview into `field`.
std::u16string GetValueForVirtualCardInputPreview(
    const CreditCard& virtual_card,
    const std::string& app_locale,
    const AutofillField& field,
    std::string* failure_to_fill) {}

std::u16string GetFillingValueForCreditCardSelectControl(
    const std::u16string& value,
    const std::string& app_locale,
    const AutofillField& field,
    std::string* failure_to_fill) {}

}  // namespace

std::u16string GetFillingValueForCreditCard(
    const CreditCard& credit_card,
    const std::u16string& cvc,
    const std::string& app_locale,
    mojom::ActionPersistence action_persistence,
    const AutofillField& field,
    std::string* failure_to_fill) {}

bool WillFillCreditCardNumberOrCvc(
    base::span<const FormFieldData> fields,
    base::span<const std::unique_ptr<AutofillField>> autofill_fields,
    const AutofillField& trigger_autofill_field,
    bool card_has_cvc) {}

}  // namespace autofill