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.content.Context; | |
8 import android.os.Handler; | |
9 | |
10 import org.chromium.content_public.browser.WebContents; | |
11 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.
| |
12 import org.chromium.payments.mojom.PaymentAppOption; | |
13 import org.chromium.payments.mojom.PaymentMethodData; | |
14 | |
15 import java.util.ArrayList; | |
16 import java.util.HashSet; | |
17 import java.util.List; | |
18 import java.util.Map; | |
19 import java.util.Set; | |
20 | |
21 /** | |
22 * This app class represents a web based payment app. | |
23 * | |
24 * Such apps are implemented as service workers according to the Payment | |
25 * App API specification. | |
26 * | |
27 * @see https://w3c.github.io/webpayments-payment-apps-api/ | |
28 */ | |
29 public class WebBasedPaymentApp implements PaymentApp { | |
30 private final Context mContext; | |
31 private final WebContents mWebContents; | |
32 private final String mAppId; | |
33 private final PaymentAppManifest mManifest; | |
34 | |
35 /** | |
36 * Build a web based payment app instance based on an installed manifest. | |
37 * | |
38 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest | |
39 * | |
40 * @param context The context. | |
41 * @param webContents The web contents where PaymentRequest was invoked. | |
42 * @param appId A string that uniquely represents this payment app. | |
43 * @param manifest A manifest that describes this payment app. | |
44 */ | |
45 public WebBasedPaymentApp(Context context, WebContents webContents, | |
46 String appId, PaymentAppManifest manifest) { | |
47 mContext = context; | |
48 mWebContents = webContents; | |
49 mAppId = appId; | |
50 mManifest = manifest; | |
51 } | |
52 | |
53 @Override | |
54 public void getInstruments( | |
55 Map<String, PaymentMethodData> unusedMethodData, | |
56 final InstrumentsCallback callback) { | |
57 final List<PaymentInstrument> instruments = | |
58 new ArrayList<PaymentInstrument>(); | |
59 | |
60 for (PaymentAppOption option : mManifest.options) { | |
61 instruments.add(new WebBasedPaymentInstrument( | |
62 mContext, mWebContents, mAppId, mManifest, option)); | |
63 } | |
64 | |
65 new Handler().post(new Runnable() { | |
66 @Override | |
67 public void run() { | |
68 callback.onInstrumentsReady(WebBasedPaymentApp.this, instruments ); | |
69 } | |
70 }); | |
71 } | |
72 | |
73 @Override | |
74 public Set<String> getAppMethodNames() { | |
75 Set<String> methods = new HashSet<>(); | |
76 | |
77 for (PaymentAppOption option : mManifest.options) { | |
78 for (String methodName : option.enabledMethods) { | |
79 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.
| |
80 } | |
81 } | |
82 | |
83 return methods; | |
84 } | |
85 | |
86 @Override | |
87 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) { | |
88 // TODO(tommyt): Implement this for Web Based Payment Apps. | |
89 return true; | |
90 } | |
91 | |
92 @Override | |
93 public String getAppIdentifier() { | |
94 return "Chrome_Web_Based_Payment_App"; | |
95 } | |
96 } | |
OLD | NEW |