1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
// Copyright 2018 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/common/autofill_prefs.h"
#include "build/build_config.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
namespace autofill::prefs {
namespace {
// To simplify the rollout of AutofillSilentlyRemoveQuasiDuplicates,
// deduplication can be run a second time per milestone for users enrolled in
// the experiment. This pref tracks whether deduplication was run a second time.
// TODO(crbug.com/325450676): Remove after the rollout finished.
constexpr char kAutofillRanQuasiDuplicateExtraDeduplication[] =
"autofill.ran_quasi_duplicate_extra_deduplication";
} // namespace
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// Synced prefs. Used for cross-device choices, e.g., credit card Autofill.
registry->RegisterBooleanPref(
kAutofillProfileEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterIntegerPref(
kAutofillLastVersionDeduped, 0,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kAutofillHasSeenIban, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kAutofillCreditCardEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kAutofillPaymentCvcStorage, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kAutofillPaymentCardBenefits, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
// Non-synced prefs. Used for per-device choices, e.g., signin promo.
registry->RegisterDictionaryPref(kAutofillAiOptInStatus);
registry->RegisterBooleanPref(kAutofillCreditCardFidoAuthEnabled, false);
#if BUILDFLAG(IS_ANDROID)
registry->RegisterBooleanPref(kAutofillCreditCardFidoAuthOfferCheckboxState,
true);
#endif
registry->RegisterIntegerPref(kAutocompleteLastVersionRetentionPolicy, 0);
registry->RegisterStringPref(kAutofillUploadEncodingSeed, "");
registry->RegisterDictionaryPref(kAutofillVoteUploadEvents);
registry->RegisterDictionaryPref(
kAutofillVoteSecondaryFormSignatureUploadEvents);
registry->RegisterDictionaryPref(kAutofillMetadataUploadEvents);
registry->RegisterTimePref(kAutofillUploadEventsLastResetTimestamp, {});
registry->RegisterDictionaryPref(kAutofillSyncTransportOptIn);
registry->RegisterBooleanPref(kAutofillRanExtraDeduplication, false);
#if BUILDFLAG(IS_ANDROID)
// Automotive devices require stricter data protection for user privacy, so
// mandatory reauth for autofill payment methods should always be enabled.
if (base::android::BuildInfo::GetInstance()->is_automotive()) {
registry->RegisterBooleanPref(kAutofillPaymentMethodsMandatoryReauth, true);
} else {
registry->RegisterBooleanPref(kAutofillPaymentMethodsMandatoryReauth,
false);
}
registry->RegisterIntegerPref(
kAutofillPaymentMethodsMandatoryReauthPromoShownCounter, 0);
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
registry->RegisterBooleanPref(kAutofillPaymentMethodsMandatoryReauth, false);
registry->RegisterIntegerPref(
kAutofillPaymentMethodsMandatoryReauthPromoShownCounter, 0);
#elif BUILDFLAG(IS_IOS)
registry->RegisterBooleanPref(kAutofillPaymentMethodsMandatoryReauth, true);
#endif
// Deprecated prefs registered for migration.
registry->RegisterBooleanPref(kAutofillEnabledDeprecated, true);
registry->RegisterStringPref(kAutofillAblationSeedPref, "");
registry->RegisterBooleanPref(kAutofillRanQuasiDuplicateExtraDeduplication,
false);
#if BUILDFLAG(IS_ANDROID)
registry->RegisterBooleanPref(kAutofillUsingVirtualViewStructure, false);
registry->RegisterBooleanPref(kAutofillThirdPartyPasswordManagersAllowed,
true);
registry->RegisterBooleanPref(
kFacilitatedPaymentsEwallet, /*default_value=*/true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kFacilitatedPaymentsPix, /*default_value=*/true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kFacilitatedPaymentsPixAccountLinking, /*default_value=*/true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
registry->RegisterBooleanPref(
kAutofillBnplEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
kAutofillHasSeenBnpl, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS)
}
void MigrateDeprecatedAutofillPrefs(PrefService* pref_service) {
// Added 07/2024 (moved from profile pref to local state)
pref_service->ClearPref(kAutofillAblationSeedPref);
// Added 10/2024
pref_service->ClearPref(kAutofillRanQuasiDuplicateExtraDeduplication);
// Added 03/2025
pref_service->ClearPref(kAutofillEnabledDeprecated);
}
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(kAutofillAblationSeedPref, "");
}
bool IsAutocompleteEnabled(const PrefService* prefs) {
return IsAutofillProfileEnabled(prefs);
}
bool IsCreditCardFIDOAuthEnabled(PrefService* prefs) {
return prefs->GetBoolean(kAutofillCreditCardFidoAuthEnabled);
}
void SetCreditCardFIDOAuthEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillCreditCardFidoAuthEnabled, enabled);
}
bool IsAutofillPaymentMethodsEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillCreditCardEnabled);
}
void SetAutofillPaymentMethodsEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillCreditCardEnabled, enabled);
}
bool HasSeenIban(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillHasSeenIban);
}
// If called, always sets the pref to true, and once true, it will follow the
// user around forever.
void SetAutofillHasSeenIban(PrefService* prefs) {
prefs->SetBoolean(kAutofillHasSeenIban, true);
}
bool IsAutofillProfileManaged(const PrefService* prefs) {
return prefs->IsManagedPreference(kAutofillProfileEnabled);
}
bool IsAutofillCreditCardManaged(const PrefService* prefs) {
return prefs->IsManagedPreference(kAutofillCreditCardEnabled);
}
bool IsAutofillProfileEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillProfileEnabled);
}
void SetAutofillProfileEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillProfileEnabled, enabled);
}
bool IsPaymentMethodsMandatoryReauthEnabled(const PrefService* prefs) {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) || \
BUILDFLAG(IS_IOS)
return prefs->GetBoolean(kAutofillPaymentMethodsMandatoryReauth);
#else
return false;
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) ||
// BUILDFLAG(IS_IOS)
}
void SetPaymentMethodsMandatoryReauthEnabled(PrefService* prefs, bool enabled) {
#if BUILDFLAG(IS_ANDROID)
// The user should not be able to update the pref value on automotive devices.
CHECK(!base::android::BuildInfo::GetInstance()->is_automotive());
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) || \
BUILDFLAG(IS_IOS)
prefs->SetBoolean(kAutofillPaymentMethodsMandatoryReauth, enabled);
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) ||
// BUILDFLAG(IS_IOS)
}
bool IsPaymentMethodsMandatoryReauthSetExplicitly(const PrefService* prefs) {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
return prefs->GetUserPrefValue(kAutofillPaymentMethodsMandatoryReauth) !=
nullptr;
#else
return false;
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
}
bool IsPaymentMethodsMandatoryReauthPromoShownCounterBelowMaxCap(
const PrefService* prefs) {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
return prefs->GetInteger(
kAutofillPaymentMethodsMandatoryReauthPromoShownCounter) <
kMaxValueForMandatoryReauthPromoShownCounter;
#else
return false;
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
}
void IncrementPaymentMethodsMandatoryReauthPromoShownCounter(
PrefService* prefs) {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
if (prefs->GetInteger(
kAutofillPaymentMethodsMandatoryReauthPromoShownCounter) >=
kMaxValueForMandatoryReauthPromoShownCounter) {
return;
}
prefs->SetInteger(
kAutofillPaymentMethodsMandatoryReauthPromoShownCounter,
prefs->GetInteger(
kAutofillPaymentMethodsMandatoryReauthPromoShownCounter) +
1);
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
}
bool IsPaymentCvcStorageEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillPaymentCvcStorage);
}
void SetPaymentCvcStorage(PrefService* prefs, bool value) {
prefs->SetBoolean(kAutofillPaymentCvcStorage, value);
}
bool IsPaymentCardBenefitsEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillPaymentCardBenefits);
}
void SetPaymentCardBenefits(PrefService* prefs, bool value) {
prefs->SetBoolean(kAutofillPaymentCardBenefits, value);
}
void ClearSyncTransportOptIns(PrefService* prefs) {
prefs->SetDict(kAutofillSyncTransportOptIn, base::Value::Dict());
}
void SetFacilitatedPaymentsEwallet(PrefService* prefs, bool value) {
#if BUILDFLAG(IS_ANDROID)
prefs->SetBoolean(kFacilitatedPaymentsEwallet, value);
#endif // BUILDFLAG(IS_ANDROID)
}
bool IsFacilitatedPaymentsEwalletEnabled(const PrefService* prefs) {
#if BUILDFLAG(IS_ANDROID)
return prefs->GetBoolean(kFacilitatedPaymentsEwallet);
#else
return false;
#endif // BUILDFLAG(IS_ANDROID)
}
void SetFacilitatedPaymentsPix(PrefService* prefs, bool value) {
#if BUILDFLAG(IS_ANDROID)
prefs->SetBoolean(kFacilitatedPaymentsPix, value);
#endif // BUILDFLAG(IS_ANDROID)
}
bool IsFacilitatedPaymentsPixEnabled(const PrefService* prefs) {
#if BUILDFLAG(IS_ANDROID)
return prefs->GetBoolean(kFacilitatedPaymentsPix);
#else
return false;
#endif // BUILDFLAG(IS_ANDROID)
}
void SetFacilitatedPaymentsPixAccountLinking(PrefService* prefs, bool value) {
#if BUILDFLAG(IS_ANDROID)
prefs->SetBoolean(kFacilitatedPaymentsPixAccountLinking, value);
#endif // BUILDFLAG(IS_ANDROID)
}
bool IsFacilitatedPaymentsPixAccountLinkingEnabled(const PrefService* prefs) {
#if BUILDFLAG(IS_ANDROID)
return prefs->GetBoolean(kFacilitatedPaymentsPixAccountLinking);
#else
// Default to false on other platforms as the feature is Android-only.
return false;
#endif // BUILDFLAG(IS_ANDROID)
}
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
void SetAutofillBnplEnabled(PrefService* prefs, bool value) {
prefs->SetBoolean(kAutofillBnplEnabled, value);
}
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS)
bool IsAutofillBnplEnabled(const PrefService* prefs) {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
return prefs->GetBoolean(kAutofillBnplEnabled);
#else
return false;
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS)
}
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
// If called, always sets the pref to true, and once true, it will follow the
// user around forever.
void SetAutofillHasSeenBnpl(PrefService* prefs) {
prefs->SetBoolean(kAutofillHasSeenBnpl, true);
}
bool HasSeenBnpl(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillHasSeenBnpl);
}
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS)
} // namespace autofill::prefs
|