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

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

Issue 2526293003: PaymentApp: Add classes for supporting Web Based Payment Apps (Closed)
Patch Set: Created 4 years, 1 month 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
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/WebBasedPaymentApp.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/WebBasedPaymentApp.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/WebBasedPaymentApp.java
new file mode 100644
index 0000000000000000000000000000000000000000..ceb2578b503731818274a2c86d5306c4d421cdea
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/WebBasedPaymentApp.java
@@ -0,0 +1,96 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.payments;
+
+import android.content.Context;
+import android.os.Handler;
+
+import org.chromium.content_public.browser.WebContents;
+import org.chromium.payments.mojom.PaymentAppManifest;
zino 2016/11/27 18:41:23 Maybe we can not use mojom type here because the s
tommyt 2016/11/28 14:13:23 Done.
+import org.chromium.payments.mojom.PaymentAppOption;
+import org.chromium.payments.mojom.PaymentMethodData;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This app class represents a web based payment app.
+ *
+ * Such apps are implemented as service workers according to the Payment
+ * App API specification.
+ *
+ * @see https://w3c.github.io/webpayments-payment-apps-api/
+ */
+public class WebBasedPaymentApp implements PaymentApp {
+ private final Context mContext;
+ private final WebContents mWebContents;
+ private final String mAppId;
+ private final PaymentAppManifest mManifest;
+
+ /**
+ * Build a web based payment app instance based on an installed manifest.
+ *
+ * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-manifest
+ *
+ * @param context The context.
+ * @param webContents The web contents where PaymentRequest was invoked.
+ * @param appId A string that uniquely represents this payment app.
+ * @param manifest A manifest that describes this payment app.
+ */
+ public WebBasedPaymentApp(Context context, WebContents webContents,
+ String appId, PaymentAppManifest manifest) {
+ mContext = context;
+ mWebContents = webContents;
+ mAppId = appId;
+ mManifest = manifest;
+ }
+
+ @Override
+ public void getInstruments(
+ Map<String, PaymentMethodData> unusedMethodData,
+ final InstrumentsCallback callback) {
+ final List<PaymentInstrument> instruments =
+ new ArrayList<PaymentInstrument>();
+
+ for (PaymentAppOption option : mManifest.options) {
+ instruments.add(new WebBasedPaymentInstrument(
+ mContext, mWebContents, mAppId, mManifest, option));
+ }
+
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ callback.onInstrumentsReady(WebBasedPaymentApp.this, instruments);
+ }
+ });
+ }
+
+ @Override
+ public Set<String> getAppMethodNames() {
+ Set<String> methods = new HashSet<>();
+
+ for (PaymentAppOption option : mManifest.options) {
+ for (String methodName : option.enabledMethods) {
+ methods.add(methodName);
zino 2016/11/27 18:41:23 This method seems just getter that always returns
tommyt 2016/11/28 14:13:22 Done.
+ }
+ }
+
+ return methods;
+ }
+
+ @Override
+ public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methodsAndData) {
+ // TODO(tommyt): Implement this for Web Based Payment Apps.
+ return true;
+ }
+
+ @Override
+ public String getAppIdentifier() {
+ return "Chrome_Web_Based_Payment_App";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698