Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1725)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestFactory.java

Issue 2192423002: Show at most one PaymentRequest UI at a time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698