| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
|
| index c2ad56591af45fdefd3a5bb6d9d60d22527e818c..9d2977d8e30c611b71a56e20c6eaa4a1395e4c5f 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
|
| @@ -70,9 +70,11 @@ import javax.annotation.Nullable;
|
| * Android implementation of the PaymentRequest service defined in
|
| * components/payments/payment_request.mojom.
|
| */
|
| -public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Client,
|
| - PaymentApp.InstrumentsCallback, PaymentInstrument.InstrumentDetailsCallback,
|
| - PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver {
|
| +public class PaymentRequestImpl
|
| + implements PaymentRequest, PaymentRequestUI.Client, PaymentApp.InstrumentsCallback,
|
| + PaymentInstrument.InstrumentDetailsCallback,
|
| + PaymentAppFactory.PaymentAppCreatedCallback,
|
| + PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver {
|
| /**
|
| * A test-only observer for the PaymentRequest service implementation.
|
| */
|
| @@ -202,7 +204,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| private final ChromeActivity mContext;
|
| private final String mMerchantName;
|
| private final String mOrigin;
|
| - private final List<PaymentApp> mApps;
|
| private final AddressEditor mAddressEditor;
|
| private final CardEditor mCardEditor;
|
| private final PaymentRequestJourneyLogger mJourneyLogger = new PaymentRequestJourneyLogger();
|
| @@ -244,6 +245,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| private Map<String, PaymentMethodData> mMethodData;
|
| private SectionInformation mShippingAddressesSection;
|
| private SectionInformation mContactSection;
|
| + private List<PaymentApp> mApps;
|
| + private boolean mAllAppsCreated;
|
| private List<PaymentApp> mPendingApps;
|
| private List<PaymentInstrument> mPendingInstruments;
|
| private List<PaymentInstrument> mPendingAutofillInstruments;
|
| @@ -298,7 +301,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| }
|
| });
|
|
|
| - mApps = PaymentAppFactory.create(mContext, webContents);
|
| + mApps = new ArrayList<>();
|
| + PaymentAppFactory.getInstance().create(mContext, webContents, this);
|
|
|
| mAddressEditor = new AddressEditor();
|
| mCardEditor = new CardEditor(webContents, mAddressEditor, sObserverForTest);
|
| @@ -517,8 +521,20 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| return Collections.unmodifiableMap(result);
|
| }
|
|
|
| + @Override
|
| + public void onPaymentAppCreated(PaymentApp paymentApp) {
|
| + mApps.add(paymentApp);
|
| + }
|
| +
|
| + @Override
|
| + public void onAllPaymentAppsCreated() {
|
| + mAllAppsCreated = true;
|
| + getMatchingPaymentInstruments();
|
| + }
|
| +
|
| /** Queries the installed payment apps for their instruments that merchant supports. */
|
| private void getMatchingPaymentInstruments() {
|
| + if (!mAllAppsCreated || mClient == null || mPendingApps != null) return;
|
| mPendingApps = new ArrayList<>(mApps);
|
| mPendingInstruments = new ArrayList<>();
|
| mPendingAutofillInstruments = new ArrayList<>();
|
| @@ -1208,15 +1224,18 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| * @return True if no payment methods are supported
|
| */
|
| private boolean disconnectIfNoPaymentMethodsSupported() {
|
| - boolean waitingForPaymentApps = !mPendingApps.isEmpty() || !mPendingInstruments.isEmpty();
|
| + if (mPendingApps == null || !mPendingApps.isEmpty() || !mPendingInstruments.isEmpty()) {
|
| + // Waiting for pending apps and instruments.
|
| + return false;
|
| + }
|
| +
|
| boolean foundPaymentMethods = mPaymentMethodsSection != null
|
| && !mPaymentMethodsSection.isEmpty();
|
| boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstruments
|
| && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD_ABORT);
|
|
|
| if (!mArePaymentMethodsSupported
|
| - || (getIsShowing() && !waitingForPaymentApps && !foundPaymentMethods
|
| - && !userCanAddCreditCard)) {
|
| + || (getIsShowing() && !foundPaymentMethods && !userCanAddCreditCard)) {
|
| // All payment apps have responded, but none of them have instruments. It's possible to
|
| // add credit cards, but the merchant does not support them either. The payment request
|
| // must be rejected.
|
|
|