| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestFactory.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestFactory.java
|
| index 01a9e58cd5f9e35efbdbe0477929de26fd17706d..1bedddb631875bf5bb9d4a92d35302b6e98b62d9 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestFactory.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestFactory.java
|
| @@ -4,15 +4,62 @@
|
|
|
| package org.chromium.chrome.browser.payments;
|
|
|
| +import android.app.Activity;
|
| +
|
| +import org.chromium.chrome.browser.ChromeFeatureList;
|
| +import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestDismissObserver;
|
| +import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content.browser.InterfaceRegistry.ImplementationFactory;
|
| import org.chromium.content_public.browser.WebContents;
|
| +import org.chromium.mojo.system.MojoException;
|
| +import org.chromium.mojom.payments.PaymentDetails;
|
| +import org.chromium.mojom.payments.PaymentErrorReason;
|
| +import org.chromium.mojom.payments.PaymentMethodData;
|
| +import org.chromium.mojom.payments.PaymentOptions;
|
| import org.chromium.mojom.payments.PaymentRequest;
|
| +import org.chromium.mojom.payments.PaymentRequestClient;
|
| +import org.chromium.ui.base.WindowAndroid;
|
|
|
| /**
|
| * Creates instances of PaymentRequest.
|
| */
|
| -public class PaymentRequestFactory implements ImplementationFactory<PaymentRequest> {
|
| +public class PaymentRequestFactory implements ImplementationFactory<PaymentRequest>,
|
| + PaymentRequestDismissObserver {
|
| private final WebContents mWebContents;
|
| + private boolean mIsPaymentRequestRunning;
|
| +
|
| + /**
|
| + * An implementation of PaymentRequest that immediately rejects all connections.
|
| + * Necessary because Mojo does not handle null returned from createImpl().
|
| + */
|
| + private static final class InvalidPaymentRequest implements PaymentRequest {
|
| + @Override
|
| + public void setClient(PaymentRequestClient client) {
|
| + if (client != null) {
|
| + client.onError(PaymentErrorReason.USER_CANCEL);
|
| + client.close();
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public void show(PaymentMethodData[] methodData, PaymentDetails details,
|
| + PaymentOptions options) {}
|
| +
|
| + @Override
|
| + public void updateWith(PaymentDetails details) {}
|
| +
|
| + @Override
|
| + public void abort() {}
|
| +
|
| + @Override
|
| + public void complete(int result) {}
|
| +
|
| + @Override
|
| + public void close() {}
|
| +
|
| + @Override
|
| + public void onConnectionError(MojoException e) {}
|
| + }
|
|
|
| /**
|
| * Builds a factory for PaymentRequest.
|
| @@ -25,6 +72,29 @@ public class PaymentRequestFactory implements ImplementationFactory<PaymentReque
|
|
|
| @Override
|
| public PaymentRequest createImpl() {
|
| - return new PaymentRequestImpl(mWebContents);
|
| + if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS)) {
|
| + return new InvalidPaymentRequest();
|
| + }
|
| +
|
| + if (mWebContents == null) return new InvalidPaymentRequest();
|
| +
|
| + ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebContents);
|
| + if (contentViewCore == null) return new InvalidPaymentRequest();
|
| +
|
| + WindowAndroid window = contentViewCore.getWindowAndroid();
|
| + if (window == null) return new InvalidPaymentRequest();
|
| +
|
| + Activity context = window.getActivity().get();
|
| + if (context == null) return new InvalidPaymentRequest();
|
| +
|
| + if (mIsPaymentRequestRunning) return new InvalidPaymentRequest();
|
| + mIsPaymentRequestRunning = true;
|
| +
|
| + return new PaymentRequestImpl(context, mWebContents, this);
|
| + }
|
| +
|
| + @Override
|
| + public void onPaymentRequestDismissed() {
|
| + mIsPaymentRequestRunning = false;
|
| }
|
| }
|
|
|