Skip to content

Commit

Permalink
[Dialog][Clank] Update card unmask dialog (CVC dialog) - Part 4
Browse files Browse the repository at this point in the history
This change populates the card details layout with the actual card
details.

Implementation doc: https://docs.google.com/document/d/1Ck0WIei2vQJr9zvRzN6a5mS65X_wRqKaXg5v1604iYo

Change 1: crrev.com/c/4155032
Change 2: crrev.com/c/4020964
Change 3: crrev.com/c/4023850
Change 4: This CL
Change 5: crrev.com/c/4102981
Change 6: crrev.com/c/4153092


Bug: 1356735
Change-Id: I77470e4b8dcc7c951e9bfc4d62ef441174571e58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4030878
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: Siddharth Shah <siashah@chromium.org>
Reviewed-by: Siyu An <siyua@chromium.org>
Commit-Queue: Vishwas Uppoor <vishwasuppoor@google.com>
Reviewed-by: Tanmoy Mollik <triploblastic@google.com>
Cr-Commit-Position: refs/heads/main@{#1095960}
  • Loading branch information
Vishwas Uppoor authored and Chromium LUCI CQ committed Jan 24, 2023
1 parent 3c1509e commit fce1757
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp">

<org.chromium.ui.widget.ChromeImageView
android:id="@+id/card_icon"
app:srcCompat="@drawable/visa_card"
android:layout_width="32dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ found in the LICENSE file.
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginHorizontal="20dp"
android:visibility="gone" />
android:layout_marginHorizontal="20dp" />

<LinearLayout
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class CardUnmaskBridge implements CardUnmaskPromptDelegate {
private final CardUnmaskPrompt mCardUnmaskPrompt;

private CardUnmaskBridge(long nativeCardUnmaskPromptViewAndroid, String title,
String instructions, String confirmButtonLabel, int cvcIconId, int googlePayIconId,
String instructions, int cardIconId, String cardName, String cardLastFourDigits,
String cardExpiration, String confirmButtonLabel, int cvcIconId, int googlePayIconId,
boolean isVirtualCard, boolean shouldRequestExpirationDate, boolean shouldOfferWebauthn,
boolean defaultUseScreenlockChecked, long successMessageDurationMilliseconds,
WindowAndroid windowAndroid) {
Expand All @@ -36,22 +37,26 @@ private CardUnmaskBridge(long nativeCardUnmaskPromptViewAndroid, String title,
new Handler().post(() -> dismissed());
} else {
mCardUnmaskPrompt = new CardUnmaskPrompt(activity, this, title, instructions,
confirmButtonLabel, cvcIconId, googlePayIconId, isVirtualCard,
shouldRequestExpirationDate, shouldOfferWebauthn, defaultUseScreenlockChecked,
cardIconId, cardName, cardLastFourDigits, cardExpiration, confirmButtonLabel,
cvcIconId, googlePayIconId, isVirtualCard, shouldRequestExpirationDate,
shouldOfferWebauthn, defaultUseScreenlockChecked,
successMessageDurationMilliseconds);
}
}

// TODO (crbug.com/1356735): Sync down the credit card directly from native instead of adding
// more and more arguments.
@CalledByNative
private static CardUnmaskBridge create(long nativeUnmaskPrompt, String title,
String instructions, String confirmButtonLabel, int cvcIconId, int googlePayIconId,
String instructions, int cardIconId, String cardName, String cardLastFourDigits,
String cardExpiration, String confirmButtonLabel, int cvcIconId, int googlePayIconId,
boolean isVirtualCard, boolean shouldRequestExpirationDate, boolean shouldOfferWebauthn,
boolean defaultUseScreenlockChecked, long successMessageDurationMilliseconds,
WindowAndroid windowAndroid) {
return new CardUnmaskBridge(nativeUnmaskPrompt, title, instructions, confirmButtonLabel,
cvcIconId, googlePayIconId, isVirtualCard, shouldRequestExpirationDate,
shouldOfferWebauthn, defaultUseScreenlockChecked,
successMessageDurationMilliseconds, windowAndroid);
return new CardUnmaskBridge(nativeUnmaskPrompt, title, instructions, cardIconId, cardName,
cardLastFourDigits, cardExpiration, confirmButtonLabel, cvcIconId, googlePayIconId,
isVirtualCard, shouldRequestExpirationDate, shouldOfferWebauthn,
defaultUseScreenlockChecked, successMessageDurationMilliseconds, windowAndroid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@
import androidx.core.view.ViewCompat;

import org.chromium.base.task.AsyncTask;
import org.chromium.build.BuildConfig;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.AutofillUiUtils.ErrorType;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.widget.ChromeImageView;

import java.util.Calendar;
import java.util.Locale;

/**
* A prompt that bugs users to enter their CVC when unmasking a Wallet instrument (credit card).
Expand Down Expand Up @@ -148,7 +147,8 @@ public interface CardUnmaskObserverForTest {
}

public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title,
String instructions, String confirmButtonLabel, int cvcDrawableId,
String instructions, int cardIconId, String cardName, String cardLastFourDigits,
String cardExpiration, String confirmButtonLabel, int cvcDrawableId,
int googlePayDrawableId, boolean isVirtualCard, boolean shouldRequestExpirationDate,
boolean shouldOfferWebauthn, boolean defaultUseScreenlockChecked,
long successMessageDurationMilliseconds) {
Expand All @@ -161,23 +161,15 @@ public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, Stri
ChromeFeatureList.AUTOFILL_TOUCH_TO_FILL_FOR_CREDIT_CARDS_ANDROID)) {
mMainView = inflater.inflate(R.layout.autofill_card_unmask_prompt_new, null);

// TODO (crbug.com/1356735): These mock card details are added to demo the UI. Remove
// when actual card details are synced from native. Only shown in debug builds.
if (BuildConfig.ENABLE_ASSERTS) {
ViewGroup cardDetails =
(ViewGroup) mMainView.findViewById(R.id.card_details_container);
cardDetails.setVisibility(View.VISIBLE);

String cardName = "Chase Sapphire Preferred Ultimate Rewards Card";
String lastFour = "....1234";
String expiration = "12/2029";
((TextView) mMainView.findViewById(R.id.card_name))
.setText(String.format(Locale.ROOT, "%s", cardName));
((TextView) mMainView.findViewById(R.id.card_last_four))
.setText(String.format(Locale.ROOT, "%s", lastFour));
((TextView) mMainView.findViewById(R.id.card_expiration))
.setText(String.format(Locale.ROOT, "%s", expiration));
// Populate card details.
if (cardIconId != 0) {
ChromeImageView cardIconView =
(ChromeImageView) mMainView.findViewById(R.id.card_icon);
cardIconView.setImageDrawable(context.getDrawable(cardIconId));
}
((TextView) mMainView.findViewById(R.id.card_name)).setText(cardName);
((TextView) mMainView.findViewById(R.id.card_last_four)).setText(cardLastFourDigits);
((TextView) mMainView.findViewById(R.id.card_expiration)).setText(cardExpiration);
} else {
mMainView = inflater.inflate(R.layout.autofill_card_unmask_prompt, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "chrome/android/chrome_jni_headers/CardUnmaskBridge_jni.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/autofill/autofill_popup_controller_utils.h"
#include "chrome/browser/ui/autofill/payments/create_card_unmask_prompt_view.h"
#include "components/autofill/core/browser/ui/payments/card_unmask_prompt_controller.h"
#include "components/autofill/core/common/autofill_payments_features.h"
Expand Down Expand Up @@ -149,12 +150,22 @@ CardUnmaskPromptViewAndroid::GetOrCreateJavaObject() {
ScopedJavaLocalRef<jstring> instructions =
base::android::ConvertUTF16ToJavaString(
env, controller_->GetInstructionsMessage());
ScopedJavaLocalRef<jstring> card_name =
base::android::ConvertUTF16ToJavaString(env, controller_->GetCardName());
ScopedJavaLocalRef<jstring> card_last_four_digits =
base::android::ConvertUTF16ToJavaString(
env, controller_->GetCardLastFourDigits());
ScopedJavaLocalRef<jstring> card_expiration =
base::android::ConvertUTF16ToJavaString(env,
controller_->GetCardExpiration());
ScopedJavaLocalRef<jstring> confirm = base::android::ConvertUTF16ToJavaString(
env, controller_->GetOkButtonLabel());

return java_object_internal_ = Java_CardUnmaskBridge_create(
env, reinterpret_cast<intptr_t>(this), dialog_title, instructions,
confirm,
ResourceMapper::MapToJavaDrawableId(
GetIconResourceID(controller_->GetCardIconString())),
card_name, card_last_four_digits, card_expiration, confirm,
ResourceMapper::MapToJavaDrawableId(controller_->GetCvcImageRid()),
ResourceMapper::MapToJavaDrawableId(
controller_->GetGooglePayImageRid()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class CardUnmaskPromptController {
virtual int GetCvcImageRid() const = 0;
virtual bool ShouldRequestExpirationDate() const = 0;
#if BUILDFLAG(IS_ANDROID)
virtual std::string GetCardIconString() const = 0;
virtual std::u16string GetCardName() const = 0;
virtual std::u16string GetCardLastFourDigits() const = 0;
virtual std::u16string GetCardExpiration() const = 0;
virtual int GetGooglePayImageRid() const = 0;
virtual bool ShouldOfferWebauthn() const = 0;
virtual bool GetWebauthnOfferStartState() const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,22 @@ bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const {
}

#if BUILDFLAG(IS_ANDROID)
std::string CardUnmaskPromptControllerImpl::GetCardIconString() const {
return card_.CardIconStringForAutofillSuggestion();
}

std::u16string CardUnmaskPromptControllerImpl::GetCardName() const {
return card_.CardNameForAutofillDisplay();
}

std::u16string CardUnmaskPromptControllerImpl::GetCardLastFourDigits() const {
return card_.ObfuscatedNumberWithVisibleLastFourDigits();
}

std::u16string CardUnmaskPromptControllerImpl::GetCardExpiration() const {
return card_.ExpirationDateForDisplay();
}

int CardUnmaskPromptControllerImpl::GetGooglePayImageRid() const {
return IDR_AUTOFILL_GOOGLE_PAY_WITH_DIVIDER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class CardUnmaskPromptControllerImpl : public CardUnmaskPromptController {
int GetCvcImageRid() const override;
bool ShouldRequestExpirationDate() const override;
#if BUILDFLAG(IS_ANDROID)
std::string GetCardIconString() const override;
std::u16string GetCardName() const override;
std::u16string GetCardLastFourDigits() const override;
std::u16string GetCardExpiration() const override;
int GetGooglePayImageRid() const override;
bool ShouldOfferWebauthn() const override;
bool GetWebauthnOfferStartState() const override;
Expand Down

0 comments on commit fce1757

Please sign in to comment.