#include "components/autofill/core/browser/browser_autofill_manager.h"
#include <stddef.h>
#include <stdint.h>
#include <array>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <ranges>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#include "base/barrier_callback.h"
#include "base/check_deref.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/containers/adapters.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/hash/hash.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/address_suggestion_generator.h"
#include "components/autofill/core/browser/autocomplete_history_manager.h"
#include "components/autofill/core/browser/autofill_browser_util.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_compose_delegate.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_external_delegate.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_granular_filling_utils.h"
#include "components/autofill/core/browser/autofill_optimization_guide.h"
#include "components/autofill/core/browser/autofill_prediction_improvements_delegate.h"
#include "components/autofill/core/browser/autofill_trigger_details.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_encoding.h"
#include "components/autofill/core/browser/crowdsourcing/determine_possible_field_types.h"
#include "components/autofill/core/browser/data_model/autofill_data_model.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/autofill_profile_comparator.h"
#include "components/autofill/core/browser/data_model/borrowed_transliterator.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/phone_number.h"
#include "components/autofill/core/browser/field_filling_address_util.h"
#include "components/autofill/core/browser/field_filling_payments_util.h"
#include "components/autofill/core/browser/field_type_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/filling_product.h"
#include "components/autofill/core/browser/form_autofill_history.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/geo/phone_number_i18n.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/autofill_metrics_utils.h"
#include "components/autofill/core/browser/metrics/autofill_settings_metrics.h"
#include "components/autofill/core/browser/metrics/fallback_autocomplete_unrecognized_metrics.h"
#include "components/autofill/core/browser/metrics/field_filling_stats_and_score_metrics.h"
#include "components/autofill/core/browser/metrics/form_events/form_event_logger_base.h"
#include "components/autofill/core/browser/metrics/form_events/form_events.h"
#include "components/autofill/core/browser/metrics/log_event.h"
#include "components/autofill/core/browser/metrics/manual_fallback_metrics.h"
#include "components/autofill/core/browser/metrics/payments/card_metadata_metrics.h"
#include "components/autofill/core/browser/metrics/quality_metrics.h"
#include "components/autofill/core/browser/metrics/suggestions_list_metrics.h"
#include "components/autofill/core/browser/payments/autofill_offer_manager.h"
#include "components/autofill/core/browser/payments/credit_card_access_manager.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/payments_suggestion_generator.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/profile_token_quality.h"
#include "components/autofill/core/browser/randomized_encoder.h"
#include "components/autofill/core/browser/suggestions_context.h"
#include "components/autofill/core/browser/ui/payments/bubble_show_options.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_hiding_reason.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/autocomplete_parsing_util.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_data_validation.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_internals/log_message.h"
#include "components/autofill/core/common/autofill_internals/logging_scope.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_regex_constants.h"
#include "components/autofill/core/common/autofill_regexes.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/credit_card_number_validation.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_data_predictions.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "components/autofill/core/common/password_form_fill_data.h"
#include "components/autofill/core/common/signatures.h"
#include "components/autofill/core/common/unique_ids.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/core/pref_names.h"
#include "components/security_state/core/security_state.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/strings/grit/components_strings.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace autofill {
FillingProductSet;
SubmissionSource;
namespace {
constexpr size_t kMinNumberAddressFieldsToTriggerAddressUserPerceptionSurvey = …;
bool IsAddressAutofillManuallyTriggeredOnNonAddressField(
SuggestionType type,
const AutofillField* autofill_field) { … }
bool IsCreditCardAutofillManuallyTriggeredOnNonCreditCardField(
SuggestionType type,
const AutofillField* autofill_field) { … }
std::map<std::string, std::string> FormFillingStatsToSurveyStringData(
autofill_metrics::FormGroupFillingStats& filling_stats) { … }
void LogDeveloperEngagementUkm(ukm::UkmRecorder* ukm_recorder,
ukm::SourceId source_id,
const FormStructure& form_structure) { … }
ValuePatternsMetric GetValuePattern(const std::u16string& value) { … }
void LogValuePatternsMetric(const FormData& form) { … }
bool IsSingleFieldFormFillerFillingProduct(FillingProduct filling_product) { … }
FillDataType GetEventTypeFromSingleFieldSuggestionType(SuggestionType type) { … }
void LogAutocompletePredictionCollisionTypeMetrics(
const FormStructure& form_structure) { … }
const char* SubmissionSourceToString(SubmissionSource source) { … }
bool ShouldShowSuggestionsForAutocompleteUnrecognizedFields(
AutofillSuggestionTriggerSource trigger_source) { … }
bool ShouldFetchCreditCard(const FormData& form,
const FormFieldData& field,
const FormStructure& form_structure,
const AutofillField& autofill_field,
const CreditCard& credit_card) { … }
bool ShouldRecordUkm() { … }
bool IsTriggerSourceOnlyRelevantForCompose(
AutofillSuggestionTriggerSource source) { … }
void LogSuggestionsCount(const SuggestionsContext& context,
const std::vector<Suggestion>& suggestions) { … }
FieldTypeSet GetTargetFieldsForAddressFillingSuggestionType(
SuggestionType suggestion_type,
FieldType trigger_field_type) { … }
bool ShouldOfferSingleFieldFormFill(
const FormFieldData& field,
const AutofillField* autofill_field,
AutofillSuggestionTriggerSource trigger_source,
SuppressReason suppress_reason) { … }
bool ShouldSuppressSuggestions(SuppressReason suppress_reason,
LogManager* log_manager) { … }
void MaybeAddAddressSuggestionStrikes(AutofillClient& client,
const FormStructure& form) { … }
}
BrowserAutofillManager::MetricsState::MetricsState(
BrowserAutofillManager* owner)
: … { … }
BrowserAutofillManager::MetricsState::~MetricsState() { … }
BrowserAutofillManager::BrowserAutofillManager(AutofillDriver* driver,
const std::string& app_locale)
: … { … }
BrowserAutofillManager::~BrowserAutofillManager() { … }
base::WeakPtr<AutofillManager> BrowserAutofillManager::GetWeakPtr() { … }
CreditCardAccessManager& BrowserAutofillManager::GetCreditCardAccessManager() { … }
const CreditCardAccessManager&
BrowserAutofillManager::GetCreditCardAccessManager() const { … }
bool BrowserAutofillManager::ShouldShowScanCreditCard(
const FormData& form,
const FormFieldData& field) { … }
bool BrowserAutofillManager::ShouldShowCardsFromAccountOption(
const FormData& form,
const FormFieldData& field,
AutofillSuggestionTriggerSource trigger_source) const { … }
void BrowserAutofillManager::OnUserAcceptedCardsFromAccountOption() { … }
void BrowserAutofillManager::RefetchCardsAndUpdatePopup(
const FormData& form,
const FormFieldData& field_data) { … }
bool BrowserAutofillManager::ShouldParseForms() { … }
void BrowserAutofillManager::OnFormSubmittedImpl(const FormData& form,
bool known_success,
SubmissionSource source) { … }
bool BrowserAutofillManager::MaybeStartVoteUploadProcess(
std::unique_ptr<FormStructure> form_structure,
bool observed_submission) { … }
void BrowserAutofillManager::UpdatePendingForm(const FormData& form) { … }
void BrowserAutofillManager::ProcessPendingFormForUpload() { … }
void BrowserAutofillManager::MaybeImportFromSubmittedForm(
const FormData& form,
const FormStructure* const form_structure) { … }
void BrowserAutofillManager::LogSubmissionMetrics(
const FormStructure* submitted_form,
const base::TimeTicks& form_submitted_timestamp) { … }
void BrowserAutofillManager::OnTextFieldDidChangeImpl(
const FormData& form,
const FieldGlobalId& field_id,
const base::TimeTicks timestamp) { … }
bool BrowserAutofillManager::IsFormNonSecure(const FormData& form) const { … }
SuggestionsContext BrowserAutofillManager::BuildSuggestionsContext(
const FormData& form,
const FormStructure* form_structure,
const FormFieldData& field,
const AutofillField* autofill_field,
AutofillSuggestionTriggerSource trigger_source) { … }
void BrowserAutofillManager::OnAskForValuesToFillImpl(
const FormData& form,
const FieldGlobalId& field_id,
const gfx::Rect& caret_bounds,
AutofillSuggestionTriggerSource trigger_source) { … }
void BrowserAutofillManager::GenerateSuggestionsAndMaybeShowUI(
const FormData& form,
const FormStructure* form_structure,
const FormFieldData& field,
const AutofillField* autofill_field,
AutofillSuggestionTriggerSource trigger_source,
SuggestionsContext& context,
OnGenerateSuggestionsCallback callback) { … }
void BrowserAutofillManager::
OnGeneratedPlusAddressAndSingleFieldFormFillSuggestions(
AutofillPlusAddressDelegate::SuggestionContext suggestions_context,
AutofillClient::PasswordFormClassification::Type password_form_type,
const FormData& form,
const FormFieldData& field,
OnGenerateSuggestionsCallback callback,
std::vector<std::vector<Suggestion>> suggestion_lists) { … }
void BrowserAutofillManager::MaybeShowIphForManualFallback(
const FormFieldData& field,
const AutofillField* autofill_field,
AutofillSuggestionTriggerSource trigger_source,
SuppressReason suppress_reason) { … }
void BrowserAutofillManager::OnGenerateSuggestionsComplete(
const FormData& form,
const FormFieldData& field,
AutofillSuggestionTriggerSource trigger_source,
const SuggestionsContext& context,
bool show_suggestions,
std::vector<Suggestion> suggestions,
std::optional<autofill_metrics::SuggestionRankingContext> ranking_context) { … }
void BrowserAutofillManager::OnGetPlusAddressSuggestions(
AutofillPlusAddressDelegate::SuggestionContext suggestions_context,
AutofillClient::PasswordFormClassification::Type password_form_type,
const FormData& form,
const FormFieldData& field,
std::vector<Suggestion> address_suggestions,
OnGenerateSuggestionsCallback callback,
std::vector<Suggestion> suggestions) { … }
void BrowserAutofillManager::AuthenticateThenFillCreditCardForm(
const FormData& form,
const FormFieldData& field,
const CreditCard& credit_card,
const AutofillTriggerDetails& trigger_details) { … }
void BrowserAutofillManager::FillOrPreviewProfileForm(
mojom::ActionPersistence action_persistence,
const FormData& form,
const FormFieldData& field,
const AutofillProfile& profile,
const AutofillTriggerDetails& trigger_details) { … }
void BrowserAutofillManager::FillOrPreviewFormExperimental(
mojom::ActionPersistence action_persistence,
FillingProduct filling_product,
const FieldTypeSet& field_types_to_fill,
const DenseSet<FieldFillingSkipReason>& ignorable_skip_reasons,
const FormData& form,
const FormFieldData& trigger_field,
const base::flat_map<FieldGlobalId, std::u16string>& values_to_fill) { … }
void BrowserAutofillManager::FillOrPreviewField(
mojom::ActionPersistence action_persistence,
mojom::FieldActionType action_type,
const FormData& form,
const FormFieldData& field,
const std::u16string& value,
SuggestionType type,
std::optional<FieldType> field_type_used) { … }
void BrowserAutofillManager::OnDidFillAddressFormFillingSuggestion(
const AutofillProfile& profile,
const FormData& form,
const FormFieldData& field,
AutofillTriggerSource trigger_source) { … }
void BrowserAutofillManager::UndoAutofill(
mojom::ActionPersistence action_persistence,
const FormData& form,
const FormFieldData& trigger_field) { … }
void BrowserAutofillManager::FillOrPreviewCreditCardForm(
mojom::ActionPersistence action_persistence,
const FormData& form,
const FormFieldData& field,
const CreditCard& credit_card,
const std::u16string& cvc,
const AutofillTriggerDetails& trigger_details) { … }
void BrowserAutofillManager::OnFocusOnNonFormFieldImpl() { … }
void BrowserAutofillManager::OnFocusOnFormFieldImpl(
const FormData& form,
const FieldGlobalId& field_id) { … }
void BrowserAutofillManager::OnSelectControlDidChangeImpl(
const FormData& form,
const FieldGlobalId& field_id) { … }
void BrowserAutofillManager::OnDidFillAutofillFormDataImpl(
const FormData& form,
const base::TimeTicks timestamp) { … }
void BrowserAutofillManager::DidShowSuggestions(
base::span<const SuggestionType> shown_suggestions_types,
const FormData& form,
const FormFieldData& field) { … }
void BrowserAutofillManager::OnHidePopupImpl() { … }
bool BrowserAutofillManager::RemoveAutofillProfileOrCreditCard(
Suggestion::BackendId backend_id) { … }
void BrowserAutofillManager::RemoveCurrentSingleFieldSuggestion(
const std::u16string& name,
const std::u16string& value,
SuggestionType type) { … }
void BrowserAutofillManager::OnSingleFieldSuggestionSelected(
const Suggestion& suggestion,
const FormData& form,
const FormFieldData& field) { … }
void BrowserAutofillManager::OnUserHideSuggestions(const FormData& form,
const FormFieldData& field) { … }
bool BrowserAutofillManager::ShouldClearPreviewedForm() { … }
void BrowserAutofillManager::OnSelectOrSelectListFieldOptionsDidChangeImpl(
const FormData& form) { … }
void BrowserAutofillManager::OnJavaScriptChangedAutofilledValueImpl(
const FormData& form,
const FieldGlobalId& field_id,
const std::u16string& old_value,
bool formatting_only) { … }
void BrowserAutofillManager::AnalyzeJavaScriptChangedAutofilledValue(
const FormStructure& form,
AutofillField& field,
bool cleared_value,
bool formatting_only) { … }
void BrowserAutofillManager::OnCreditCardFetched(
const FormData& form,
const FormFieldData& field,
AutofillTriggerSource fetched_credit_card_trigger_source,
CreditCardFetchResult result,
const CreditCard* credit_card) { … }
void BrowserAutofillManager::OnDidEndTextFieldEditingImpl() { … }
bool BrowserAutofillManager::IsAutofillEnabled() const { … }
bool BrowserAutofillManager::IsAutofillProfileEnabled() const { … }
bool BrowserAutofillManager::IsAutofillPaymentMethodsEnabled() const { … }
const FormData& BrowserAutofillManager::last_query_form() const { … }
bool BrowserAutofillManager::ShouldUploadForm(const FormStructure& form) { … }
void BrowserAutofillManager::
FetchPotentialCardLastFourDigitsCombinationFromDOM() { … }
void BrowserAutofillManager::StoreUploadVotesAndLogQualityCallback(
FormSignature form_signature,
base::OnceClosure callback) { … }
void BrowserAutofillManager::WipeLogQualityAndVotesUploadCallback(
FormSignature form_signature) { … }
void BrowserAutofillManager::FlushPendingLogQualityAndVotesUploadCallbacks() { … }
void BrowserAutofillManager::UploadVotesAndLogQuality(
std::unique_ptr<FormStructure> submitted_form,
base::TimeTicks interaction_time,
base::TimeTicks submission_time,
bool observed_submission,
ukm::SourceId source_id) { … }
const gfx::Image& BrowserAutofillManager::GetCardImage(
const CreditCard& credit_card) { … }
void BrowserAutofillManager::OnSubmissionFieldTypesDetermined(
std::unique_ptr<FormStructure> submitted_form,
base::TimeTicks interaction_time,
base::TimeTicks submission_time,
bool observed_submission,
ukm::SourceId source_id) { … }
void BrowserAutofillManager::Reset() { … }
void BrowserAutofillManager::UpdateLoggersReadinessData() { … }
void BrowserAutofillManager::OnDidFillOrPreviewForm(
mojom::ActionPersistence action_persistence,
const FormStructure& form_structure,
const AutofillField& trigger_autofill_field,
base::span<const FormFieldData*> safe_filled_fields,
base::span<const AutofillField*> safe_filled_autofill_fields,
const base::flat_set<FieldGlobalId>& filled_fields,
const base::flat_set<FieldGlobalId>& safe_fields,
absl::variant<const AutofillProfile*, const CreditCard*>
profile_or_credit_card,
const AutofillTriggerDetails& trigger_details,
bool is_refill) { … }
std::unique_ptr<FormStructure> BrowserAutofillManager::ValidateSubmittedForm(
const FormData& form) { … }
AutofillField* BrowserAutofillManager::GetAutofillField(
const FormData& form,
const FormFieldData& field) const { … }
void BrowserAutofillManager::OnCreditCardFetchedSuccessfully(
const CreditCard& credit_card) { … }
std::vector<Suggestion> BrowserAutofillManager::GetProfileSuggestions(
const FormData& form,
const FormStructure* form_structure,
const FormFieldData& trigger_field,
const AutofillField* trigger_autofill_field,
AutofillSuggestionTriggerSource trigger_source) { … }
std::vector<Suggestion> BrowserAutofillManager::GetCreditCardSuggestions(
const FormData& form,
const FormFieldData& trigger_field,
FieldType trigger_field_type,
AutofillSuggestionTriggerSource trigger_source,
autofill_metrics::SuggestionRankingContext& ranking_context) { … }
base::flat_map<std::string, VirtualCardUsageData::VirtualCardLastFour>
BrowserAutofillManager::GetVirtualCreditCardsForStandaloneCvcField(
const url::Origin& origin) const { … }
void BrowserAutofillManager::OnBeforeProcessParsedForms() { … }
void BrowserAutofillManager::OnFormProcessed(
const FormData& form,
const FormStructure& form_structure) { … }
void BrowserAutofillManager::UpdateInitialInteractionTimestamp(
base::TimeTicks interaction_timestamp) { … }
std::vector<Suggestion>
BrowserAutofillManager::GetAvailableAddressAndCreditCardSuggestions(
const FormData& form,
const FormStructure* form_structure,
const FormFieldData& field,
const AutofillField* autofill_field,
AutofillSuggestionTriggerSource trigger_source,
SuggestionsContext& context,
autofill_metrics::SuggestionRankingContext& ranking_context) { … }
autofill_metrics::FormEventLoggerBase*
BrowserAutofillManager::GetEventFormLogger(const AutofillField& field) { … }
void BrowserAutofillManager::PreProcessStateMatchingTypes(
const std::vector<AutofillProfile>& profiles,
FormStructure* form_structure) { … }
void BrowserAutofillManager::ReportAutofillWebOTPMetrics(bool used_web_otp) { … }
void BrowserAutofillManager::ProcessFieldLogEventsInForm(
const FormStructure& form_structure) { … }
bool BrowserAutofillManager::ShouldUploadUkm(
const FormStructure& form_structure,
bool require_classified_field) { … }
void BrowserAutofillManager::LogEventCountsUMAMetric(
const FormStructure& form_structure) { … }
void BrowserAutofillManager::SetFastCheckoutRunId(
FieldTypeGroup field_type_group,
int64_t run_id) { … }
}