OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.payments; |
| 6 |
| 7 import android.os.Handler; |
| 8 |
| 9 import org.chromium.payments.mojom.PaymentMethodData; |
| 10 |
| 11 import java.util.ArrayList; |
| 12 import java.util.Collections; |
| 13 import java.util.HashSet; |
| 14 import java.util.List; |
| 15 import java.util.Map; |
| 16 import java.util.Set; |
| 17 |
| 18 /** |
| 19 * This app class represents a service worker based payment app. |
| 20 * |
| 21 * Such apps are implemented as service workers according to the Payment |
| 22 * App API specification. |
| 23 * |
| 24 * @see https://w3c.github.io/webpayments-payment-apps-api/ |
| 25 */ |
| 26 public class ServiceWorkerPaymentApp implements PaymentApp { |
| 27 private final ServiceWorkerPaymentAppBridge.Manifest mManifest; |
| 28 private final Set<String> mMethodNames; |
| 29 |
| 30 /** |
| 31 * Build a service worker payment app instance based on an installed manifes
t. |
| 32 * |
| 33 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani
fest |
| 34 * |
| 35 * @param manifest A manifest that describes this payment app. |
| 36 */ |
| 37 public ServiceWorkerPaymentApp(ServiceWorkerPaymentAppBridge.Manifest manife
st) { |
| 38 mManifest = manifest; |
| 39 |
| 40 mMethodNames = new HashSet<>(); |
| 41 for (ServiceWorkerPaymentAppBridge.Option option : manifest.options) { |
| 42 mMethodNames.addAll(option.enabledMethods); |
| 43 } |
| 44 } |
| 45 |
| 46 @Override |
| 47 public void getInstruments( |
| 48 Map<String, PaymentMethodData> unusedMethodData, |
| 49 final InstrumentsCallback callback) { |
| 50 final List<PaymentInstrument> instruments = |
| 51 new ArrayList<PaymentInstrument>(); |
| 52 |
| 53 for (ServiceWorkerPaymentAppBridge.Option option : mManifest.options) { |
| 54 instruments.add(new ServiceWorkerPaymentInstrument(mManifest.scopeUr
l, option)); |
| 55 } |
| 56 |
| 57 new Handler().post(new Runnable() { |
| 58 @Override |
| 59 public void run() { |
| 60 callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instru
ments); |
| 61 } |
| 62 }); |
| 63 } |
| 64 |
| 65 @Override |
| 66 public Set<String> getAppMethodNames() { |
| 67 return Collections.unmodifiableSet(mMethodNames); |
| 68 } |
| 69 |
| 70 @Override |
| 71 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods
AndData) { |
| 72 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay
ment Apps. |
| 73 return true; |
| 74 } |
| 75 |
| 76 @Override |
| 77 public String getAppIdentifier() { |
| 78 return "Chrome_Service_Worker_Payment_App"; |
| 79 } |
| 80 } |
OLD | NEW |