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

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

Issue 2586213002: PaymentApp: Implement nativeGetAllAppManifests (Closed)
Patch Set: Rebase Created 3 years, 11 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.payments.mojom.PaymentMethodData; 10 import org.chromium.payments.mojom.PaymentMethodData;
10 11
11 import java.util.ArrayList; 12 import java.util.ArrayList;
12 import java.util.Collections; 13 import java.util.Collections;
13 import java.util.HashSet; 14 import java.util.HashSet;
14 import java.util.List; 15 import java.util.List;
15 import java.util.Map; 16 import java.util.Map;
16 import java.util.Set; 17 import java.util.Set;
17 18
18 /** 19 /**
19 * This app class represents a service worker based payment app. 20 * This app class represents a service worker based payment app.
20 * 21 *
21 * Such apps are implemented as service workers according to the Payment 22 * Such apps are implemented as service workers according to the Payment
22 * App API specification. 23 * App API specification.
23 * 24 *
24 * @see https://w3c.github.io/webpayments-payment-apps-api/ 25 * @see https://w3c.github.io/webpayments-payment-apps-api/
25 */ 26 */
26 public class ServiceWorkerPaymentApp implements PaymentApp { 27 public class ServiceWorkerPaymentApp implements PaymentApp {
28 private final WebContents mWebContents;
27 private final ServiceWorkerPaymentAppBridge.Manifest mManifest; 29 private final ServiceWorkerPaymentAppBridge.Manifest mManifest;
28 private final Set<String> mMethodNames; 30 private final Set<String> mMethodNames;
29 31
30 /** 32 /**
31 * Build a service worker payment app instance based on an installed manifes t. 33 * Build a service worker payment app instance based on an installed manifes t.
32 * 34 *
33 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest 35 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest
34 * 36 *
37 * @param webContents The web contents where PaymentRequest was invoked.
35 * @param manifest A manifest that describes this payment app. 38 * @param manifest A manifest that describes this payment app.
36 */ 39 */
37 public ServiceWorkerPaymentApp(ServiceWorkerPaymentAppBridge.Manifest manife st) { 40 public ServiceWorkerPaymentApp(
41 WebContents webContents, ServiceWorkerPaymentAppBridge.Manifest mani fest) {
42 mWebContents = webContents;
38 mManifest = manifest; 43 mManifest = manifest;
39 44
40 mMethodNames = new HashSet<>(); 45 mMethodNames = new HashSet<>();
41 for (ServiceWorkerPaymentAppBridge.Option option : manifest.options) { 46 for (ServiceWorkerPaymentAppBridge.Option option : manifest.options) {
42 mMethodNames.addAll(option.enabledMethods); 47 mMethodNames.addAll(option.enabledMethods);
43 } 48 }
44 } 49 }
45 50
46 @Override 51 @Override
47 public void getInstruments( 52 public void getInstruments(
48 Map<String, PaymentMethodData> unusedMethodData, 53 Map<String, PaymentMethodData> unusedMethodData,
49 final InstrumentsCallback callback) { 54 final InstrumentsCallback callback) {
50 final List<PaymentInstrument> instruments = 55 final List<PaymentInstrument> instruments =
51 new ArrayList<PaymentInstrument>(); 56 new ArrayList<PaymentInstrument>();
52 57
53 for (ServiceWorkerPaymentAppBridge.Option option : mManifest.options) { 58 for (ServiceWorkerPaymentAppBridge.Option option : mManifest.options) {
54 instruments.add(new ServiceWorkerPaymentInstrument(mManifest.scopeUr l, option)); 59 instruments.add(new ServiceWorkerPaymentInstrument(
60 mWebContents, mManifest.registrationId, option));
55 } 61 }
56 62
57 new Handler().post(new Runnable() { 63 new Handler().post(new Runnable() {
58 @Override 64 @Override
59 public void run() { 65 public void run() {
60 callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instru ments); 66 callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instru ments);
61 } 67 }
62 }); 68 });
63 } 69 }
64 70
65 @Override 71 @Override
66 public Set<String> getAppMethodNames() { 72 public Set<String> getAppMethodNames() {
67 return Collections.unmodifiableSet(mMethodNames); 73 return Collections.unmodifiableSet(mMethodNames);
68 } 74 }
69 75
70 @Override 76 @Override
71 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) { 77 public boolean supportsMethodsAndData(Map<String, PaymentMethodData> methods AndData) {
72 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay ment Apps. 78 // TODO(tommyt): crbug.com/669876. Implement this for Service Worker Pay ment Apps.
73 return true; 79 return true;
74 } 80 }
75 81
76 @Override 82 @Override
77 public String getAppIdentifier() { 83 public String getAppIdentifier() {
78 return "Chrome_Service_Worker_Payment_App"; 84 return "Chrome_Service_Worker_Payment_App";
79 } 85 }
80 } 86 }
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