Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| index 7a73a7eaecabb2c57a5438ba39b7c63c1b1670e7..e7cd305224fe3aa6bc10e27676fb439b10770a31 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentApp.java |
| @@ -4,18 +4,23 @@ |
| package org.chromium.chrome.browser.payments; |
| +import android.graphics.drawable.Drawable; |
| import android.os.Handler; |
| import org.chromium.content_public.browser.WebContents; |
| +import org.chromium.payments.mojom.PaymentDetailsModifier; |
| import org.chromium.payments.mojom.PaymentItem; |
| import org.chromium.payments.mojom.PaymentMethodData; |
| +import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.HashSet; |
| import java.util.List; |
| import java.util.Map; |
| import java.util.Set; |
| +import javax.annotation.Nullable; |
| + |
| /** |
| * This app class represents a service worker based payment app. |
| * |
| @@ -24,9 +29,10 @@ import java.util.Set; |
| * |
| * @see https://w3c.github.io/webpayments-payment-handler/ |
| */ |
| -public class ServiceWorkerPaymentApp implements PaymentApp { |
| +public class ServiceWorkerPaymentApp extends PaymentInstrument implements PaymentApp { |
| private final WebContents mWebContents; |
| - private final List<PaymentInstrument> mInstruments; |
| + private final long mSWRegistrationId; |
|
please use gerrit instead
2017/07/05 13:14:21
This is a service worker, so the "SW" part of the
gogerald1
2017/07/05 19:49:39
Done.
|
| + private final Drawable mIcon; |
| private final Set<String> mMethodNames; |
| /** |
| @@ -34,16 +40,22 @@ public class ServiceWorkerPaymentApp implements PaymentApp { |
| * |
| * @see https://w3c.github.io/webpayments-payment-handler/#structure-of-a-web-payment-app |
| * |
| - * @param webContents The web contents where PaymentRequest was invoked. |
| - * @param instruments A list of payment instruments supported by the payment app. |
| + * @param webContents The web contents where PaymentRequest was invoked. |
| + * @param swRegistrationId The registration id of the corresponding service worker payment app. |
| + * @param label The label of the payment app. |
| + * @param icon The drawable icon of the payment app. |
| + * @param methodNames A set of payment method names supported by the payment app. |
| */ |
| - public ServiceWorkerPaymentApp(WebContents webContents, List<PaymentInstrument> instruments) { |
| + public ServiceWorkerPaymentApp(WebContents webContents, long swRegistrationId, String label, |
| + @Nullable Drawable icon, String[] methodNames) { |
| + super(Long.toString(swRegistrationId), label, null /* sublabel */, icon); |
| mWebContents = webContents; |
| - mInstruments = instruments; |
| + mSWRegistrationId = swRegistrationId; |
| + mIcon = icon; |
| mMethodNames = new HashSet<>(); |
| - for (PaymentInstrument instrument : instruments) { |
| - mMethodNames.addAll(instrument.getInstrumentMethodNames()); |
| + for (String method : methodNames) { |
|
please use gerrit instead
2017/07/05 13:14:21
Use int loops. Foreach loops are not efficient.
gogerald1
2017/07/05 19:49:39
Done.
|
| + mMethodNames.add(method); |
| } |
| } |
| @@ -54,8 +66,9 @@ public class ServiceWorkerPaymentApp implements PaymentApp { |
| new Handler().post(new Runnable() { |
| @Override |
| public void run() { |
| - callback.onInstrumentsReady( |
| - ServiceWorkerPaymentApp.this, Collections.unmodifiableList(mInstruments)); |
| + List<PaymentInstrument> instruments = new ArrayList(); |
| + instruments.add(ServiceWorkerPaymentApp.this); |
| + callback.onInstrumentsReady(ServiceWorkerPaymentApp.this, instruments); |
| } |
| }); |
| } |
| @@ -80,4 +93,22 @@ public class ServiceWorkerPaymentApp implements PaymentApp { |
| public int getAdditionalAppTextResourceId() { |
| return 0; |
| } |
| + |
| + @Override |
| + public Set<String> getInstrumentMethodNames() { |
| + return getAppMethodNames(); |
| + } |
| + |
| + @Override |
| + public void invokePaymentApp(String id, String merchantName, String origin, String iframeOrigin, |
| + byte[][] unusedCertificateChain, Map<String, PaymentMethodData> methodData, |
| + PaymentItem total, List<PaymentItem> displayItems, |
| + Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCallback callback) { |
| + ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mSWRegistrationId, origin, |
| + iframeOrigin, id, new HashSet<>(methodData.values()), total, |
| + new HashSet<>(modifiers.values()), "", callback); |
|
please use gerrit instead
2017/07/05 13:14:21
Add a comment about what "" is.
gogerald1
2017/07/05 19:49:38
Done. Removed this unused variable
|
| + } |
| + |
| + @Override |
| + public void dismissInstrument() {} |
| } |