Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f2a6cef9fead85ba3a77f6070e9165748a287c3 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| @@ -0,0 +1,80 @@ |
| +// 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.os.Handler; |
| + |
| +import org.chromium.payments.mojom.PaymentMethodData; |
| + |
| +import java.util.ArrayList; |
| +import java.util.Collections; |
| +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. |
|
zino
2016/11/30 13:50:09
nit: You probably should replace 'web based' with
tommyt
2016/11/30 13:54:30
Done. I had tried, but apparently I wasn't thoroug
|
| + * |
| + * 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 ServiceWorkerPaymentApp implements PaymentApp { |
| + private final ServiceWorkerPaymentAppBridge.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 manifest A manifest that describes this payment app. |
| + */ |
| + public ServiceWorkerPaymentApp(ServiceWorkerPaymentAppBridge.Manifest manifest) { |
| + mManifest = manifest; |
| + |
| + mMethodNames = new HashSet<>(); |
| + for (ServiceWorkerPaymentAppBridge.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 (ServiceWorkerPaymentAppBridge.Option option : mManifest.options) { |
| + instruments.add(new ServiceWorkerPaymentInstrument(mManifest.id, option)); |
| + } |
| + |
| + new Handler().post(new Runnable() { |
| + @Override |
| + public void run() { |
| + callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instruments); |
| + } |
| + }); |
| + } |
| + |
| + @Override |
| + public Set<String> getAppMethodNames() { |
| + return Collections.unmodifiableSet(mMethodNames); |
| + } |
| + |
| + @Override |
| + public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methodsAndData) { |
| + // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Payment Apps. |
| + return true; |
| + } |
| + |
| + @Override |
| + public String getAppIdentifier() { |
| + return "Chrome_Service_Worker_Payment_App"; |
| + } |
| +} |