| OLD | NEW |
| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.drawable.Drawable; | 8 import android.graphics.drawable.Drawable; |
| 9 | 9 |
| 10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
| 11 import org.chromium.base.annotations.CalledByNative; |
| 11 import org.chromium.base.annotations.SuppressFBWarnings; | 12 import org.chromium.base.annotations.SuppressFBWarnings; |
| 12 import org.chromium.content_public.browser.WebContents; | 13 import org.chromium.content_public.browser.WebContents; |
| 14 import org.chromium.payments.mojom.PaymentMethodData; |
| 13 | 15 |
| 14 import java.util.ArrayList; | 16 import java.util.ArrayList; |
| 15 import java.util.List; | 17 import java.util.List; |
| 18 import java.util.Map; |
| 16 | 19 |
| 17 /** | 20 /** |
| 18 * Native bridge for interacting with service worker based payment apps. | 21 * Native bridge for interacting with service worker based payment apps. |
| 19 */ | 22 */ |
| 20 // TODO(tommyt): crbug.com/669876. Remove these suppressions when we actually | 23 // TODO(tommyt): crbug.com/669876. Remove these suppressions when we actually |
| 21 // start using all of the functionality in this class. | 24 // start using all of the functionality in this class. |
| 22 @SuppressFBWarnings( | 25 @SuppressFBWarnings({"UWF_NULL_FIELD", "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", |
| 23 {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UUF_UNUSED_PUBLIC_OR_PROTEC
TED_FIELD"}) | 26 "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UUF_UNUSED_PUBLIC_OR_PROTECT
ED_FIELD"}) |
| 24 public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
ppFactoryAddition { | 27 public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
ppFactoryAddition { |
| 25 /** | 28 /** |
| 26 * This class represents a payment app manifest as defined in the Payment | 29 * This class represents a payment app manifest as defined in the Payment |
| 27 * App API specification. | 30 * App API specification. |
| 28 * | 31 * |
| 29 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani
fest | 32 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani
fest |
| 30 */ | 33 */ |
| 31 public static class Manifest { | 34 public static class Manifest { |
| 32 /** | 35 /** |
| 33 * The scope url of the service worker. | 36 * The scope url of the service worker. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 55 | 58 |
| 56 /** | 59 /** |
| 57 * Fetch all the installed service worker app manifests. | 60 * Fetch all the installed service worker app manifests. |
| 58 * | 61 * |
| 59 * This method is protected so that it can be overridden by tests. | 62 * This method is protected so that it can be overridden by tests. |
| 60 * | 63 * |
| 61 * @return The installed service worker app manifests. | 64 * @return The installed service worker app manifests. |
| 62 */ | 65 */ |
| 63 @VisibleForTesting | 66 @VisibleForTesting |
| 64 protected List<Manifest> getAllAppManifests() { | 67 protected List<Manifest> getAllAppManifests() { |
| 65 // TODO(tommyt): crbug.com/669876. Implement this function. | 68 return nativeGetAllAppManifests(); |
| 66 return new ArrayList<Manifest>(); | |
| 67 } | 69 } |
| 68 | 70 |
| 69 @Override | 71 @Override |
| 70 public void create(Context context, WebContents webContents, | 72 public void create(Context context, WebContents webContents, |
| 71 PaymentAppFactory.PaymentAppCreatedCallback callback) { | 73 PaymentAppFactory.PaymentAppCreatedCallback callback) { |
| 72 List<Manifest> manifests = getAllAppManifests(); | 74 List<Manifest> manifests = getAllAppManifests(); |
| 73 for (int i = 0; i < manifests.size(); i++) { | 75 for (int i = 0; i < manifests.size(); i++) { |
| 74 callback.onPaymentAppCreated(new ServiceWorkerPaymentApp(manifests.g
et(i))); | 76 callback.onPaymentAppCreated(new ServiceWorkerPaymentApp(manifests.g
et(i))); |
| 75 } | 77 } |
| 76 callback.onAllPaymentAppsCreated(); | 78 callback.onAllPaymentAppsCreated(); |
| 77 } | 79 } |
| 80 |
| 81 /** |
| 82 * Invoke a payment app with a given option and matching method data. |
| 83 */ |
| 84 public void invokePaymentapp( |
| 85 String scopeUrl, String optionId, Map<String, PaymentMethodData> met
hodData) { |
| 86 nativeInvokePaymentApp(scopeUrl, optionId, methodData); |
| 87 } |
| 88 |
| 89 @CalledByNative |
| 90 private static List<Manifest> createManifestList() { |
| 91 return new ArrayList<Manifest>(); |
| 92 } |
| 93 |
| 94 @CalledByNative |
| 95 private static Manifest createAndAddManifest( |
| 96 List<Manifest> manifestList, String scopeUrl, String label, String i
con) { |
| 97 Manifest manifest = new Manifest(); |
| 98 manifest.scopeUrl = scopeUrl; |
| 99 manifest.label = label; |
| 100 // TODO(tommyt): crbug.com/669876. Handle icons. |
| 101 manifest.icon = null; |
| 102 manifestList.add(manifest); |
| 103 return manifest; |
| 104 } |
| 105 |
| 106 @CalledByNative |
| 107 private static Option createAndAddOption( |
| 108 Manifest manifest, String id, String label, String icon) { |
| 109 Option option = new Option(); |
| 110 option.id = id; |
| 111 option.label = label; |
| 112 // TODO(tommyt): crbug.com/669876. Handle icons. |
| 113 option.icon = null; |
| 114 manifest.options.add(option); |
| 115 return option; |
| 116 } |
| 117 |
| 118 @CalledByNative |
| 119 private static void addEnabledMethod(Option option, String enabledMethod) { |
| 120 option.enabledMethods.add(enabledMethod); |
| 121 } |
| 122 |
| 123 private static native List<Manifest> nativeGetAllAppManifests(); |
| 124 private static native void nativeInvokePaymentApp( |
| 125 String scopeUrl, String optionId, Object methodDataMap); |
| 78 } | 126 } |
| OLD | NEW |