Commit 9a2fd169 authored by Manas Verma's avatar Manas Verma Committed by Commit Bot

[Autofill Auth] Remembering checkbox preference for WebAuthn offer.

On Android, ensuring that if user unchecks checkbox for WebAuthn offer, it
remains unchecked.

Bug: 949269
Change-Id: I7214abc01d40d916ba14b2b6d3bb55faa871608c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825796Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Commit-Queue: Manas Verma <manasverma@google.com>
Cr-Commit-Position: refs/heads/master@{#702968}
parent ddf069ec
......@@ -27,8 +27,8 @@ public class CardUnmaskBridge implements CardUnmaskPromptDelegate {
public CardUnmaskBridge(long nativeCardUnmaskPromptViewAndroid, String title,
String instructions, String confirmButtonLabel, int iconId,
boolean shouldRequestExpirationDate, boolean canStoreLocally,
boolean defaultToStoringLocally, long successMessageDurationMilliseconds,
WindowAndroid windowAndroid) {
boolean defaultToStoringLocally, boolean defaultUseScreenlockChecked,
long successMessageDurationMilliseconds, WindowAndroid windowAndroid) {
mNativeCardUnmaskPromptViewAndroid = nativeCardUnmaskPromptViewAndroid;
Activity activity = windowAndroid.getActivity().get();
if (activity == null) {
......@@ -40,7 +40,7 @@ public class CardUnmaskBridge implements CardUnmaskPromptDelegate {
mCardUnmaskPrompt = new CardUnmaskPrompt(activity, this, title, instructions,
confirmButtonLabel, ResourceId.mapToDrawableId(iconId),
shouldRequestExpirationDate, canStoreLocally, defaultToStoringLocally,
successMessageDurationMilliseconds);
defaultUseScreenlockChecked, successMessageDurationMilliseconds);
}
}
......@@ -48,11 +48,11 @@ public class CardUnmaskBridge implements CardUnmaskPromptDelegate {
private static CardUnmaskBridge create(long nativeUnmaskPrompt, String title,
String instructions, String confirmButtonLabel, int iconId,
boolean shouldRequestExpirationDate, boolean canStoreLocally,
boolean defaultToStoringLocally, long successMessageDurationMilliseconds,
WindowAndroid windowAndroid) {
boolean defaultToStoringLocally, boolean defaultUseScreenlockChecked,
long successMessageDurationMilliseconds, WindowAndroid windowAndroid) {
return new CardUnmaskBridge(nativeUnmaskPrompt, title, instructions, confirmButtonLabel,
iconId, shouldRequestExpirationDate, canStoreLocally, defaultToStoringLocally,
successMessageDurationMilliseconds, windowAndroid);
defaultUseScreenlockChecked, successMessageDurationMilliseconds, windowAndroid);
}
@Override
......@@ -91,9 +91,10 @@ public class CardUnmaskBridge implements CardUnmaskPromptDelegate {
*/
@CalledByNative
private void show(WindowAndroid windowAndroid) {
if (mCardUnmaskPrompt != null)
if (mCardUnmaskPrompt != null) {
mCardUnmaskPrompt.show((ChromeActivity) (windowAndroid.getActivity().get()));
}
}
/**
* After a prompt is already showing, update some UI elements.
......
......@@ -146,7 +146,8 @@ public class CardUnmaskPrompt
public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title,
String instructions, String confirmButtonLabel, int drawableId,
boolean shouldRequestExpirationDate, boolean canStoreLocally,
boolean defaultToStoringLocally, long successMessageDurationMilliseconds) {
boolean defaultToStoringLocally, boolean defaultUseScreenlockChecked,
long successMessageDurationMilliseconds) {
mDelegate = delegate;
LayoutInflater inflater = LayoutInflater.from(context);
......@@ -166,6 +167,7 @@ public class CardUnmaskPrompt
mStoreLocallyCheckbox = (CheckBox) v.findViewById(R.id.store_locally_checkbox);
mStoreLocallyCheckbox.setChecked(canStoreLocally && defaultToStoringLocally);
mUseScreenlockCheckbox = (CheckBox) v.findViewById(R.id.use_screenlock_checkbox);
mUseScreenlockCheckbox.setChecked(defaultUseScreenlockChecked);
if (canStoreLocally
|| !ChromeFeatureList.isEnabled(
ChromeFeatureList.AUTOFILL_CREDIT_CARD_AUTHENTICATION)) {
......@@ -195,8 +197,9 @@ public class CardUnmaskPrompt
mShouldRequestExpirationDate = shouldRequestExpirationDate;
mThisYear = -1;
mThisMonth = -1;
if (mShouldRequestExpirationDate)
if (mShouldRequestExpirationDate) {
new CalendarTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// Set the max length of the CVC field.
mCardUnmaskInput.setFilters(
......
......@@ -151,7 +151,7 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[autofill::prefs::kAutofillCreditCardEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[autofill::prefs::kAutofillCreditCardFIDOAuthEnabled] =
(*s_whitelist)[autofill::prefs::kAutofillCreditCardFidoAuthEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[payments::kCanMakePaymentEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
......
......@@ -53,6 +53,7 @@ void CardUnmaskPromptViewAndroid::Show() {
confirm, ResourceMapper::MapFromChromiumId(controller_->GetCvcImageRid()),
controller_->ShouldRequestExpirationDate(),
controller_->CanStoreLocally(), controller_->GetStoreLocallyStartState(),
controller_->GetWebauthnOfferStartState(),
controller_->GetSuccessMessageDuration().InMilliseconds(),
view_android->GetWindowAndroid()->GetJavaObject()));
......
......@@ -33,6 +33,7 @@ class CardUnmaskPromptController {
virtual bool ShouldRequestExpirationDate() const = 0;
virtual bool CanStoreLocally() const = 0;
virtual bool GetStoreLocallyStartState() const = 0;
virtual bool GetWebauthnOfferStartState() const = 0;
virtual base::TimeDelta GetSuccessMessageDuration() const = 0;
virtual AutofillClient::PaymentsRpcResult GetVerificationResult() const = 0;
......
......@@ -134,6 +134,16 @@ void CardUnmaskPromptControllerImpl::OnUnmaskPromptAccepted(
pending_details_.should_store_pan = false;
}
// The FIDO authentication checkbox is only shown when the local storage
// checkbox is not shown and the flag is turned on. If it is shown, then
// remember the last choice the user made on this device.
if (base::FeatureList::IsEnabled(
features::kAutofillCreditCardAuthentication) &&
!CanStoreLocally()) {
pref_service_->SetBoolean(
prefs::kAutofillCreditCardFidoAuthOfferCheckboxState, enable_fido_auth);
}
// There is a chance the delegate has disappeared (i.e. tab closed) before the
// unmask response came in. Avoid a crash.
if (delegate_)
......@@ -219,6 +229,11 @@ bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const {
prefs::kAutofillWalletImportStorageCheckboxState);
}
bool CardUnmaskPromptControllerImpl::GetWebauthnOfferStartState() const {
return pref_service_->GetBoolean(
prefs::kAutofillCreditCardFidoAuthOfferCheckboxState);
}
bool CardUnmaskPromptControllerImpl::InputCvcIsValid(
const base::string16& input_text) const {
base::string16 trimmed_text;
......
......@@ -48,6 +48,7 @@ class CardUnmaskPromptControllerImpl : public CardUnmaskPromptController {
bool ShouldRequestExpirationDate() const override;
bool CanStoreLocally() const override;
bool GetStoreLocallyStartState() const override;
bool GetWebauthnOfferStartState() const override;
bool InputCvcIsValid(const base::string16& input_text) const override;
bool InputExpirationIsValid(const base::string16& month,
const base::string16& year) const override;
......
......@@ -43,14 +43,18 @@ int GetSyncTransportOptInBitFieldForAccount(const PrefService* prefs,
const char kAutofillAcceptSaveCreditCardPromptState[] =
"autofill.accept_save_credit_card_prompt_state";
// Boolean that is true if FIDO Authentication is enabled for card unmasking.
const char kAutofillCreditCardFIDOAuthEnabled[] =
"autofill.credit_card_fido_auth_enabled";
// Boolean that is true if Autofill is enabled and allowed to save credit card
// data.
const char kAutofillCreditCardEnabled[] = "autofill.credit_card_enabled";
// Boolean that is true if FIDO Authentication is enabled for card unmasking.
const char kAutofillCreditCardFidoAuthEnabled[] =
"autofill.credit_card_fido_auth_enabled";
// Boolean that is true if FIDO Authentication is enabled for card unmasking.
const char kAutofillCreditCardFidoAuthOfferCheckboxState[] =
"autofill.credit_card_fido_auth_offer_checkbox_state";
// Number of times the credit card signin promo has been shown.
const char kAutofillCreditCardSigninPromoImpressionCount[] =
"autofill.credit_card_signin_promo_impression_count";
......@@ -157,8 +161,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
// Non-synced prefs. Used for per-device choices, e.g., signin promo.
registry->RegisterBooleanPref(prefs::kAutofillCreditCardFIDOAuthEnabled,
registry->RegisterBooleanPref(prefs::kAutofillCreditCardFidoAuthEnabled,
false);
registry->RegisterBooleanPref(
prefs::kAutofillCreditCardFidoAuthOfferCheckboxState, true);
registry->RegisterIntegerPref(
prefs::kAutofillCreditCardSigninPromoImpressionCount, 0);
registry->RegisterBooleanPref(prefs::kAutofillJapanCityFieldMigrated, false);
......@@ -226,11 +232,11 @@ void SetAutofillEnabled(PrefService* prefs, bool enabled) {
}
bool IsCreditCardFIDOAuthEnabled(PrefService* prefs) {
return prefs->GetBoolean(kAutofillCreditCardFIDOAuthEnabled);
return prefs->GetBoolean(kAutofillCreditCardFidoAuthEnabled);
}
void SetCreditCardFIDOAuthEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillCreditCardFIDOAuthEnabled, enabled);
prefs->SetBoolean(kAutofillCreditCardFidoAuthEnabled, enabled);
}
bool IsCreditCardAutofillEnabled(const PrefService* prefs) {
......
......@@ -20,8 +20,9 @@ namespace prefs {
// component. Keep alphabetized, and document each in the .cc file.
extern const char kAutofillAcceptSaveCreditCardPromptState[];
// Do not get/set the value of this pref directly. Use provided getter/setter.
extern const char kAutofillCreditCardFIDOAuthEnabled[];
extern const char kAutofillCreditCardEnabled[];
extern const char kAutofillCreditCardFidoAuthEnabled[];
extern const char kAutofillCreditCardFidoAuthOfferCheckboxState[];
extern const char kAutofillCreditCardSigninPromoImpressionCount[];
// Please use kAutofillCreditCardEnabled and kAutofillProfileEnabled instead.
extern const char kAutofillEnabledDeprecated[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment