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

Side by Side 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: Remove now unnecessary dependency to payment_app.mojom Created 4 years 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 unified diff | Download patch
OLDNEW
(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.PaymentMethodData;
12
13 import java.util.ArrayList;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Set;
18
19 /**
20 * This app class represents a web based payment app.
21 *
22 * Such apps are implemented as service workers according to the Payment
23 * App API specification.
24 *
25 * @see https://w3c.github.io/webpayments-payment-apps-api/
26 */
27 public class WebBasedPaymentApp implements PaymentApp {
28 private final Context mContext;
29 private final WebContents mWebContents;
30 private final WebBasedPaymentAppBridge.Manifest mManifest;
31 private final Set<String> mMethodNames;
32
33 /**
34 * Build a web based payment app instance based on an installed manifest.
35 *
36 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest
37 *
38 * @param context The context.
39 * @param webContents The web contents where PaymentRequest was invoked.
40 * @param manifest A manifest that describes this payment app.
41 */
42 public WebBasedPaymentApp(Context context, WebContents webContents,
43 WebBasedPaymentAppBridge.Manifest manifest) {
44 mContext = context;
45 mWebContents = webContents;
46 mManifest = manifest;
47
48 mMethodNames = new HashSet<>();
49 for (WebBasedPaymentAppBridge.Option option : manifest.options) {
50 mMethodNames.addAll(option.enabledMethods);
51 }
52 }
53
54 @Override
55 public void getInstruments(
56 Map<String, PaymentMethodData> unusedMethodData,
57 final InstrumentsCallback callback) {
58 final List<PaymentInstrument> instruments =
59 new ArrayList<PaymentInstrument>();
60
61 for (WebBasedPaymentAppBridge.Option option : mManifest.options) {
62 instruments.add(new WebBasedPaymentInstrument(
63 mContext, mWebContents, mManifest.id, option));
64 }
65
66 new Handler().post(new Runnable() {
67 @Override
68 public void run() {
69 callback.onInstrumentsReady(WebBasedPaymentApp.this, instruments );
70 }
71 });
72 }
73
74 @Override
75 public Set<String> getAppMethodNames() {
76 return mMethodNames;
please use gerrit instead 2016/11/29 14:28:44 Collections.unmodifiableSet().
tommyt 2016/11/30 13:44:38 Done.
77 }
78
79 @Override
80 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) {
81 // TODO(tommyt): Implement this for Web Based Payment Apps.
please use gerrit instead 2016/11/29 14:28:44 TODO should have a bug number. Please file a new b
tommyt 2016/11/30 13:44:38 Done.
82 return true;
83 }
84
85 @Override
86 public String getAppIdentifier() {
87 return "Chrome_Web_Based_Payment_App";
88 }
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698