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

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: rebased 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentAppBridge.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.PaymentItem; 10 import org.chromium.payments.mojom.PaymentItem;
11 import org.chromium.payments.mojom.PaymentMethodData; 11 import org.chromium.payments.mojom.PaymentMethodData;
12 12
13 import java.util.ArrayList;
14 import java.util.Collections; 13 import java.util.Collections;
15 import java.util.HashSet; 14 import java.util.HashSet;
16 import java.util.List; 15 import java.util.List;
17 import java.util.Map; 16 import java.util.Map;
18 import java.util.Set; 17 import java.util.Set;
19 18
20 /** 19 /**
21 * This app class represents a service worker based payment app. 20 * This app class represents a service worker based payment app.
22 * 21 *
23 * Such apps are implemented as service workers according to the Payment 22 * Such apps are implemented as service workers according to the Payment
24 * App API specification. 23 * Handler API specification.
25 * 24 *
26 * @see https://w3c.github.io/webpayments-payment-apps-api/ 25 * @see https://w3c.github.io/webpayments-payment-handler/
27 */ 26 */
28 public class ServiceWorkerPaymentApp implements PaymentApp { 27 public class ServiceWorkerPaymentApp implements PaymentApp {
29 private final WebContents mWebContents; 28 private final WebContents mWebContents;
30 private final ServiceWorkerPaymentAppBridge.Manifest mManifest; 29 private final List<PaymentInstrument> mInstruments;
31 private final Set<String> mMethodNames; 30 private final Set<String> mMethodNames;
32 31
33 /** 32 /**
34 * Build a service worker payment app instance based on an installed manifes t. 33 * Build a service worker payment app instance per origin.
35 * 34 *
36 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest 35 * @see https://w3c.github.io/webpayments-payment-handler/#structure-of-a-we b-payment-app
37 * 36 *
38 * @param webContents The web contents where PaymentRequest was invoked. 37 * @param webContents The web contents where PaymentRequest was invoked.
39 * @param manifest A manifest that describes this payment app. 38 * @param instruments A list of payment instruments supported by the payment app.
40 */ 39 */
41 public ServiceWorkerPaymentApp( 40 public ServiceWorkerPaymentApp(WebContents webContents, List<PaymentInstrume nt> instruments) {
42 WebContents webContents, ServiceWorkerPaymentAppBridge.Manifest mani fest) {
43 mWebContents = webContents; 41 mWebContents = webContents;
44 mManifest = manifest; 42 mInstruments = instruments;
45 43
46 mMethodNames = new HashSet<>(); 44 mMethodNames = new HashSet<>();
47 for (ServiceWorkerPaymentAppBridge.Option option : manifest.options) { 45 for (PaymentInstrument instrument : instruments) {
48 mMethodNames.addAll(option.enabledMethods); 46 mMethodNames.addAll(instrument.getInstrumentMethodNames());
49 } 47 }
50 } 48 }
51 49
52 @Override 50 @Override
53 public void getInstruments(Map<String, PaymentMethodData> unusedMethodDataMa p, 51 public void getInstruments(Map<String, PaymentMethodData> unusedMethodDataMa p,
54 String unusedOrigin, String unusedIFrameOrigin, byte[][] unusedCerti ficateChain, 52 String unusedOrigin, String unusedIFrameOrigin, byte[][] unusedCerti ficateChain,
55 PaymentItem unusedTotal, final InstrumentsCallback callback) { 53 PaymentItem unusedItem, final InstrumentsCallback callback) {
56 final List<PaymentInstrument> instruments =
57 new ArrayList<PaymentInstrument>();
58
59 for (ServiceWorkerPaymentAppBridge.Option option : mManifest.options) {
60 instruments.add(new ServiceWorkerPaymentInstrument(
61 mWebContents, mManifest.registrationId, option));
62 }
63
64 new Handler().post(new Runnable() { 54 new Handler().post(new Runnable() {
65 @Override 55 @Override
66 public void run() { 56 public void run() {
67 callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instru ments); 57 callback.onInstrumentsReady(
58 ServiceWorkerPaymentApp.this, Collections.unmodifiableLi st(mInstruments));
68 } 59 }
69 }); 60 });
70 } 61 }
71 62
72 @Override 63 @Override
73 public Set<String> getAppMethodNames() { 64 public Set<String> getAppMethodNames() {
74 return Collections.unmodifiableSet(mMethodNames); 65 return Collections.unmodifiableSet(mMethodNames);
75 } 66 }
76 67
77 @Override 68 @Override
78 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) { 69 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) {
79 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay ment Apps. 70 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay ment Apps.
80 return true; 71 return true;
81 } 72 }
82 73
83 @Override 74 @Override
84 public String getAppIdentifier() { 75 public String getAppIdentifier() {
85 return "Chrome_Service_Worker_Payment_App"; 76 return "Chrome_Service_Worker_Payment_App";
86 } 77 }
87 } 78 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentAppBridge.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698