Chromium Code Reviews| 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 26bbd0f448e358b1cf04bbefa9ffad28e0f367e9..afd6022aff8222a230d07d9bffcdc4a16acdee36 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 |
| @@ -69,6 +69,7 @@ import java.util.Set; |
| * components/payments/payment_request.mojom. |
| */ |
| public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Client, |
| + PaymentAppFactory.PaymentAppsCallback, |
| PaymentApp.InstrumentsCallback, PaymentInstrument.InstrumentDetailsCallback, |
| PaymentResponseHelper.PaymentResponseRequesterDelegate { |
| /** |
| @@ -138,10 +139,10 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| private final Handler mHandler = new Handler(); |
| private final ChromeActivity mContext; |
| + private final WebContents mWebContents; |
| private final PaymentRequestDismissObserver mDismissObserver; |
| 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(); |
| @@ -186,6 +187,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| private boolean mMerchantSupportsAutofillPaymentInstruments; |
| private ContactEditor mContactEditor; |
| private boolean mHasRecordedAbortReason; |
| + private boolean mWaitingForPaymentFactory; |
| /** True if any of the requested payment methods are supported. */ |
| private boolean mArePaymentMethodsSupported; |
| @@ -211,15 +213,16 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| assert context instanceof ChromeActivity; |
| mContext = (ChromeActivity) context; |
| + mWebContents = webContents; |
| mDismissObserver = dismissObserver; |
| - mMerchantName = webContents.getTitle(); |
| + mMerchantName = mWebContents.getTitle(); |
| // The feature is available only in secure context, so it's OK to not show HTTPS. |
| - mOrigin = UrlFormatter.formatUrlForSecurityDisplay(webContents.getVisibleUrl(), false); |
| + mOrigin = UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getVisibleUrl(), false); |
| final FaviconHelper faviconHelper = new FaviconHelper(); |
| faviconHelper.getLocalFaviconImageForURL(Profile.getLastUsedProfile(), |
| - webContents.getVisibleUrl(), |
| + mWebContents.getVisibleUrl(), |
| mContext.getResources().getDimensionPixelSize(R.dimen.payments_favicon_size), |
| new FaviconHelper.FaviconImageCallback() { |
| @Override |
| @@ -234,10 +237,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| } |
| }); |
| - mApps = PaymentAppFactory.create(mContext, webContents); |
| - |
| mAddressEditor = new AddressEditor(); |
| - mCardEditor = new CardEditor(webContents, mAddressEditor, sObserverForTest); |
| + mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForTest); |
| recordSuccessFunnelHistograms("Initiated"); |
| } |
| @@ -268,7 +269,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; |
| - getMatchingPaymentInstruments(); |
| + mWaitingForPaymentFactory = true; |
| + PaymentAppFactory.create(mContext, mWebContents, mMethodData.keySet(), this); |
| boolean requestShipping = options != null && options.requestShipping; |
| boolean requestPayerName = options != null && options.requestPayerName; |
| @@ -451,15 +453,19 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| return result; |
| } |
| - /** Queries the installed payment apps for their instruments that merchant supports. */ |
| - private void getMatchingPaymentInstruments() { |
| - mPendingApps = new ArrayList<>(mApps); |
| + /** |
| + * Called when installed payment apps have been determined. Queries the installed payment apps |
| + * for their instruments that merchant supports. |
| + */ |
| + @Override |
| + public void onPaymentAppsReady(List<PaymentApp> apps) { |
| + mPendingApps = new ArrayList<>(apps); |
| mPendingInstruments = new ArrayList<>(); |
| mPendingAutofillInstruments = new ArrayList<>(); |
| Map<PaymentApp, Map<String, JSONObject>> queryApps = new HashMap<>(); |
| - for (int i = 0; i < mApps.size(); i++) { |
| - PaymentApp app = mApps.get(i); |
| + for (int i = 0; i < apps.size(); i++) { |
| + PaymentApp app = apps.get(i); |
| Map<String, JSONObject> appMethods = |
| filterMerchantMethodData(mMethodData, app.getAppMethodNames()); |
| if (appMethods == null) { |
| @@ -475,8 +481,9 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| // so a fast response from a non-autofill payment app at the front of the app list does not |
| // cause NOT_SUPPORTED payment rejection. |
| for (Map.Entry<PaymentApp, Map<String, JSONObject>> q : queryApps.entrySet()) { |
| - q.getKey().getInstruments(q.getValue(), this); |
| + q.getKey().getInstruments(q.getValue(), mOrigin, this); |
| } |
| + mWaitingForPaymentFactory = false; |
| } |
| /** Filter out merchant method data that's not relevant to a payment app. Can return null. */ |
| @@ -1058,6 +1065,9 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| * @return True if no payment methods are supported |
| */ |
| private boolean disconnectIfNoPaymentMethodsSupported() { |
| + // Waiting for payment app factory to respond. |
| + if (mPendingApps == null || mPendingInstruments == null) return false; |
|
please use gerrit instead
2016/11/17 20:40:08
Maybe check mWaitingForPaymentFactory here instead
|
| + |
| boolean waitingForPaymentApps = !mPendingApps.isEmpty() || !mPendingInstruments.isEmpty(); |
| boolean foundPaymentMethods = |
| mPaymentMethodsSection != null && !mPaymentMethodsSection.isEmpty(); |
| @@ -1066,7 +1076,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| if (!mArePaymentMethodsSupported |
| || (mIsShowing && !waitingForPaymentApps && !foundPaymentMethods |
| - && !userCanAddCreditCard)) { |
| + && !mWaitingForPaymentFactory && !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. |