chromium/components/autofill/core/browser/payments/credit_card_access_manager.cc

// Copyright 2019 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/payments/credit_card_access_manager.h"

#include <functional>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/check_deref.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_driver.h"
#include "components/autofill/core/browser/autofill_progress_dialog_type.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/metrics/form_events/credit_card_form_event_logger.h"
#include "components/autofill/core/browser/metrics/payments/better_auth_metrics.h"
#include "components/autofill/core/browser/metrics/payments/card_unmask_authentication_metrics.h"
#include "components/autofill/core/browser/metrics/payments/card_unmask_flow_metrics.h"
#include "components/autofill/core/browser/metrics/payments/mandatory_reauth_metrics.h"
#include "components/autofill/core/browser/payments/autofill_error_dialog_context.h"
#include "components/autofill/core/browser/payments/autofill_payments_feature_availability.h"
#include "components/autofill/core/browser/payments/credit_card_cvc_authenticator.h"
#include "components/autofill/core/browser/payments/credit_card_risk_based_authenticator.h"
#include "components/autofill/core/browser/payments/mandatory_reauth_manager.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/payments/payments_network_interface.h"
#include "components/autofill/core/browser/payments/payments_util.h"
#include "components/autofill/core/browser/payments/payments_window_manager.h"
#include "components/autofill/core/browser/payments/webauthn_callback_types.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"

#if !BUILDFLAG(IS_IOS)
#include "components/autofill/core/browser/strike_databases/payments/fido_authentication_strike_database.h"
#endif

namespace autofill {
namespace {

PaymentsRpcCardType;
PaymentsRpcResult;

// Timeout to wait for unmask details from Google Payments.
constexpr auto kUnmaskDetailsResponseTimeout =;
// Time to wait between multiple calls to GetUnmaskDetails().
constexpr auto kDelayForGetUnmaskDetails =;

// Suffix for server IDs in the cache indicating that a card is a virtual card.
constexpr char kVirtualCardIdentifier[] =;

}  // namespace

CreditCardAccessManager::CreditCardAccessManager(
    AutofillManager* manager,
    autofill_metrics::CreditCardFormEventLogger* form_event_logger)
    :{}

CreditCardAccessManager::~CreditCardAccessManager() {}

void CreditCardAccessManager::UpdateCreditCardFormEventLogger() {}

bool CreditCardAccessManager::UnmaskedCardCacheIsEmpty() {}

std::vector<const CachedServerCardInfo*>
CreditCardAccessManager::GetCachedUnmaskedCards() const {}

bool CreditCardAccessManager::IsCardPresentInUnmaskedCache(
    const CreditCard& card) const {}

bool CreditCardAccessManager::ShouldClearPreviewedForm() {}

void CreditCardAccessManager::PrepareToFetchCreditCard() {}

void CreditCardAccessManager::GetUnmaskDetailsIfUserIsVerifiable(
    bool is_user_verifiable) {}

void CreditCardAccessManager::LogMetricsAndFillFormForServerUnmaskFlows(
    UnmaskAuthFlowType unmask_auth_flow_type) {}

void CreditCardAccessManager::OnDidGetUnmaskDetails(
    PaymentsRpcResult result,
    payments::PaymentsNetworkInterface::UnmaskDetails& unmask_details) {}

void CreditCardAccessManager::FetchCreditCard(
    const CreditCard* card,
    OnCreditCardFetchedCallback on_credit_card_fetched) {}

bool CreditCardAccessManager::IsMaskedServerCardRiskBasedAuthAvailable() const {}

void CreditCardAccessManager::FIDOAuthOptChange(bool opt_in) {}

void CreditCardAccessManager::OnSettingsPageFIDOAuthToggled(bool opt_in) {}

void CreditCardAccessManager::SignalCanFetchUnmaskDetails() {}

void CreditCardAccessManager::CacheUnmaskedCardInfo(const CreditCard& card,
                                                    const std::u16string& cvc) {}

bool AreVirtualCardsSupported() {}

void CreditCardAccessManager::StartAuthenticationFlow(bool fido_auth_enabled) {}

void CreditCardAccessManager::StartAuthenticationFlowForVirtualCard(
    bool fido_auth_enabled) {}

void CreditCardAccessManager::StartAuthenticationFlowForMaskedServerCard(
    bool fido_auth_enabled) {}

void CreditCardAccessManager::Authenticate(
    UnmaskAuthFlowType unmask_auth_flow_type) {}

#if !BUILDFLAG(IS_IOS)
CreditCardFidoAuthenticator*
CreditCardAccessManager::GetOrCreateFidoAuthenticator() {}
#endif

void CreditCardAccessManager::OnCvcAuthenticationComplete(
    const CreditCardCvcAuthenticator::CvcAuthenticationResponse& response) {}

#if BUILDFLAG(IS_ANDROID)
bool CreditCardAccessManager::ShouldOfferFidoAuth() const {
  if (!unmask_details_.offer_fido_opt_in &&
      !unmask_details_.fido_request_options.empty()) {
    // Server instructed the client to not offer fido because the client is
    // already opted in. This can be verified with the presence of request
    // options in the server response.
    autofill_metrics::LogWebauthnOptInPromoNotOfferedReason(
        autofill_metrics::WebauthnOptInPromoNotOfferedReason::kAlreadyOptedIn);
    return false;
  }

  if (!unmask_details_.offer_fido_opt_in) {
    // If the server thinks FIDO opt-in is not required for this user, then we
    // won't offer the FIDO opt-in checkbox on the card unmask dialog. Since the
    // client is not opted-in and device is eligible, this could mean that the
    // server does not have a valid key for this device or the server is in a
    // bad state.
    autofill_metrics::LogWebauthnOptInPromoNotOfferedReason(
        autofill_metrics::WebauthnOptInPromoNotOfferedReason::
            kUnmaskDetailsOfferFidoOptInFalse);
    return false;
  }

  if (opt_in_intention_ == UserOptInIntention::kIntentToOptIn) {
    // If the user opted-in through the settings page, do not show checkbox.
    autofill_metrics::LogWebauthnOptInPromoNotOfferedReason(
        autofill_metrics::WebauthnOptInPromoNotOfferedReason::
            kOptedInFromSettings);
    return false;
  }

  if (card_->record_type() == CreditCard::RecordType::kVirtualCard) {
    // We should not offer FIDO opt-in for virtual cards.
    autofill_metrics::LogWebauthnOptInPromoNotOfferedReason(
        autofill_metrics::WebauthnOptInPromoNotOfferedReason::kVirtualCard);
    return false;
  }

  // No situations were found where we should not show the checkbox, so we
  // should return true to indicate that we should display the checkbox to the
  // user.
  return true;
}

bool CreditCardAccessManager::UserOptedInToFidoFromSettingsPageOnMobile()
    const {
  return opt_in_intention_ == UserOptInIntention::kIntentToOptIn;
}
#endif

#if !BUILDFLAG(IS_IOS)
void CreditCardAccessManager::OnFIDOAuthenticationComplete(
    const CreditCardFidoAuthenticator::FidoAuthenticationResponse& response) {}

void CreditCardAccessManager::OnFidoAuthorizationComplete(bool did_succeed) {}
#endif

void CreditCardAccessManager::OnOtpAuthenticationComplete(
    const OtpAuthenticationResponse& response) {}

bool CreditCardAccessManager::IsUserOptedInToFidoAuth() {}

bool CreditCardAccessManager::IsFidoAuthEnabled(bool fido_auth_offered) {}

bool CreditCardAccessManager::IsSelectedCardFidoAuthorized() {}

bool CreditCardAccessManager::ShouldRespondImmediately(
    const CreditCardCvcAuthenticator::CvcAuthenticationResponse& response) {}

bool CreditCardAccessManager::ShouldRegisterCardWithFido(
    const CreditCardCvcAuthenticator::CvcAuthenticationResponse& response) {}

bool CreditCardAccessManager::ShouldOfferFidoOptInDialog(
    const CreditCardCvcAuthenticator::CvcAuthenticationResponse& response) {}

void CreditCardAccessManager::ShowWebauthnOfferDialog(
    std::string card_authorization_token) {}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
void CreditCardAccessManager::ShowVerifyPendingDialog() {}

void CreditCardAccessManager::HandleDialogUserResponse(
    WebauthnDialogCallbackType type) {}
#endif

std::string CreditCardAccessManager::GetKeyForUnmaskedCardsCache(
    const CreditCard& card) const {}

void CreditCardAccessManager::FetchMaskedServerCard() {}

void CreditCardAccessManager::FetchVirtualCard() {}

void CreditCardAccessManager::FetchLocalCard() {}

void CreditCardAccessManager::OnRiskBasedAuthenticationResponseReceived(
    const CreditCardRiskBasedAuthenticator::RiskBasedAuthenticationResponse&
        response) {}

void CreditCardAccessManager::
    OnVirtualCardRiskBasedAuthenticationResponseReceived(
        PaymentsRpcResult result,
        const payments::PaymentsNetworkInterface::UnmaskResponseDetails&
            response_details) {}

void CreditCardAccessManager::OnNonInteractiveAuthenticationSuccess(
    CreditCard::RecordType record_type) {}

void CreditCardAccessManager::OnStopWaitingForUnmaskDetails(
    bool get_unmask_details_returned) {}

void CreditCardAccessManager::OnUserAcceptedAuthenticationSelectionDialog(
    const std::string& selected_challenge_option_id) {}

void CreditCardAccessManager::OnVirtualCardUnmaskCancelled() {}

void CreditCardAccessManager::Reset() {}

void CreditCardAccessManager::HandleFidoOptInStatusChange() {}

void CreditCardAccessManager::ShowUnmaskAuthenticatorSelectionDialog() {}

CardUnmaskChallengeOption*
CreditCardAccessManager::GetCardUnmaskChallengeOptionForChallengeId(
    const std::string& challenge_id) {}

bool CreditCardAccessManager::ShouldLogServerCardUnmaskAttemptMetrics(
    CreditCard::RecordType record_type) {}

void CreditCardAccessManager::StartDeviceAuthenticationForFilling(
    const CreditCard* card) {}

void CreditCardAccessManager::OnDeviceAuthenticationResponseForFilling(
    payments::MandatoryReauthAuthenticationMethod authentication_method,
    const CreditCard* card,
    bool successful_auth) {}

void CreditCardAccessManager::OnVcn3dsAuthenticationComplete(
    payments::PaymentsWindowManager::Vcn3dsAuthenticationResponse response) {}

}  // namespace autofill