| 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..e8a8ede51d49283e687d89dc21657fde00972846
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/WebBasedPaymentApp.java
|
| @@ -0,0 +1,89 @@
|
| +// 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.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 WebBasedPaymentAppBridge.Manifest mManifest;
|
| + private final Set<String> mMethodNames;
|
| +
|
| + /**
|
| + * 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 manifest A manifest that describes this payment app.
|
| + */
|
| + public WebBasedPaymentApp(Context context, WebContents webContents,
|
| + WebBasedPaymentAppBridge.Manifest manifest) {
|
| + mContext = context;
|
| + mWebContents = webContents;
|
| + mManifest = manifest;
|
| +
|
| + mMethodNames = new HashSet<>();
|
| + for (WebBasedPaymentAppBridge.Option option : manifest.options) {
|
| + mMethodNames.addAll(option.enabledMethods);
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public void getInstruments(
|
| + Map<String, PaymentMethodData> unusedMethodData,
|
| + final InstrumentsCallback callback) {
|
| + final List<PaymentInstrument> instruments =
|
| + new ArrayList<PaymentInstrument>();
|
| +
|
| + for (WebBasedPaymentAppBridge.Option option : mManifest.options) {
|
| + instruments.add(new WebBasedPaymentInstrument(
|
| + mContext, mWebContents, mManifest.id, option));
|
| + }
|
| +
|
| + new Handler().post(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + callback.onInstrumentsReady(WebBasedPaymentApp.this, instruments);
|
| + }
|
| + });
|
| + }
|
| +
|
| + @Override
|
| + public Set<String> getAppMethodNames() {
|
| + return mMethodNames;
|
| + }
|
| +
|
| + @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";
|
| + }
|
| +}
|
|
|