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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java

Issue 2867273003: PaymentHandler: Replace GetAllManifests() with GetAllPaymentApps(). (Closed)
Patch Set: Created 3 years, 7 months 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.os.Handler; 7 import android.os.Handler;
8 8
9 import org.chromium.content_public.browser.WebContents; 9 import org.chromium.content_public.browser.WebContents;
10 import org.chromium.payments.mojom.PaymentMethodData; 10 import org.chromium.payments.mojom.PaymentMethodData;
11 11
12 import java.util.ArrayList;
13 import java.util.Collections; 12 import java.util.Collections;
14 import java.util.HashSet; 13 import java.util.HashSet;
15 import java.util.List; 14 import java.util.List;
16 import java.util.Map; 15 import java.util.Map;
17 import java.util.Set; 16 import java.util.Set;
18 17
19 /** 18 /**
20 * This app class represents a service worker based payment app. 19 * This app class represents a service worker based payment app.
21 * 20 *
22 * Such apps are implemented as service workers according to the Payment 21 * Such apps are implemented as service workers according to the Payment
23 * App API specification. 22 * Handler API specification.
24 * 23 *
25 * @see https://w3c.github.io/webpayments-payment-apps-api/ 24 * @see https://w3c.github.io/webpayments-payment-handler/
26 */ 25 */
27 public class ServiceWorkerPaymentApp implements PaymentApp { 26 public class ServiceWorkerPaymentApp implements PaymentApp {
28 private final WebContents mWebContents; 27 private final WebContents mWebContents;
29 private final ServiceWorkerPaymentAppBridge.Manifest mManifest; 28 private final List<PaymentInstrument> mInstruments;
30 private final Set<String> mMethodNames; 29 private final Set<String> mMethodNames;
31 30
32 /** 31 /**
33 * Build a service worker payment app instance based on an installed manifes t. 32 * Build a service worker payment app instance per origin.
34 * 33 *
35 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest 34 * @see https://w3c.github.io/webpayments-payment-handler/#structure-of-a-we b-payment-app
36 * 35 *
37 * @param webContents The web contents where PaymentRequest was invoked. 36 * @param webContents The web contents where PaymentRequest was invoked.
38 * @param manifest A manifest that describes this payment app. 37 * @param instruments A list of payment instruments supported by the payment app.
39 */ 38 */
40 public ServiceWorkerPaymentApp( 39 public ServiceWorkerPaymentApp(WebContents webContents, List<PaymentInstrume nt> instruments) {
41 WebContents webContents, ServiceWorkerPaymentAppBridge.Manifest mani fest) {
42 mWebContents = webContents; 40 mWebContents = webContents;
43 mManifest = manifest; 41 mInstruments = instruments;
44 42
45 mMethodNames = new HashSet<>(); 43 mMethodNames = new HashSet<>();
46 for (ServiceWorkerPaymentAppBridge.Option option : manifest.options) { 44 for (PaymentInstrument instrument : instruments) {
47 mMethodNames.addAll(option.enabledMethods); 45 mMethodNames.addAll(instrument.getInstrumentMethodNames());
48 } 46 }
49 } 47 }
50 48
51 @Override 49 @Override
52 public void getInstruments(Map<String, PaymentMethodData> unusedMethodDataMa p, 50 public void getInstruments(Map<String, PaymentMethodData> unusedMethodDataMa p,
53 String unusedOrigin, String unusedIFrameOrigin, byte[][] unusedCerti ficateChain, 51 String unusedOrigin, String unusedIFrameOrigin, byte[][] unusedCerti ficateChain,
54 final InstrumentsCallback callback) { 52 final InstrumentsCallback callback) {
55 final List<PaymentInstrument> instruments =
56 new ArrayList<PaymentInstrument>();
57
58 for (ServiceWorkerPaymentAppBridge.Option option : mManifest.options) {
59 instruments.add(new ServiceWorkerPaymentInstrument(
60 mWebContents, mManifest.registrationId, option));
61 }
62
63 new Handler().post(new Runnable() { 53 new Handler().post(new Runnable() {
64 @Override 54 @Override
65 public void run() { 55 public void run() {
66 callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instru ments); 56 callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, mInstr uments);
please use gerrit instead 2017/05/09 18:54:36 Collections.unmodifiableList(mInstruments)
zino 2017/05/10 18:28:39 Done.
67 } 57 }
68 }); 58 });
69 } 59 }
70 60
71 @Override 61 @Override
72 public Set<String> getAppMethodNames() { 62 public Set<String> getAppMethodNames() {
73 return Collections.unmodifiableSet(mMethodNames); 63 return Collections.unmodifiableSet(mMethodNames);
74 } 64 }
75 65
76 @Override 66 @Override
77 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) { 67 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) {
78 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay ment Apps. 68 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay ment Apps.
79 return true; 69 return true;
80 } 70 }
81 71
82 @Override 72 @Override
83 public String getAppIdentifier() { 73 public String getAppIdentifier() {
84 return "Chrome_Service_Worker_Payment_App"; 74 return "Chrome_Service_Worker_Payment_App";
85 } 75 }
86 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698