Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppFactory.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppFactory.java |
index 06bf964172c65de8d180ec1d4b8670dbb0d33201..69116d1574beebe756fb0636c041aafcec41211b 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppFactory.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppFactory.java |
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.payments; |
import android.content.Context; |
import org.chromium.base.VisibleForTesting; |
+import org.chromium.chrome.browser.ChromeFeatureList; |
import org.chromium.content_public.browser.WebContents; |
import java.util.ArrayList; |
@@ -23,6 +24,12 @@ public class PaymentAppFactory { |
private static PaymentAppFactoryAddition sAdditionalFactory; |
/** |
+ * Native bridge that can be used to retrieve information about installed service worker |
+ * payment apps. |
+ */ |
+ private static ServiceWorkerPaymentAppBridge sServiceWorkerPaymentAppBridge; |
+ |
+ /** |
* The interface for additional payment app factories. |
*/ |
public interface PaymentAppFactoryAddition { |
@@ -46,6 +53,15 @@ public class PaymentAppFactory { |
} |
/** |
+ * Set a custom native bridge for service worker payment apps for testing. |
+ */ |
+ @VisibleForTesting |
+ public static void setServiceWorkerPaymentAppBridgeForTest( |
+ ServiceWorkerPaymentAppBridge bridge) { |
+ sServiceWorkerPaymentAppBridge = bridge; |
+ } |
+ |
+ /** |
* Builds instances of payment apps. |
* |
* @param context The context. |
@@ -54,10 +70,36 @@ public class PaymentAppFactory { |
public static List<PaymentApp> create(Context context, WebContents webContents) { |
List<PaymentApp> result = new ArrayList<>(2); |
result.add(new AutofillPaymentApp(context, webContents)); |
+ |
+ result.addAll(createServiceWorkerPaymentApps()); |
+ |
if (sAdditionalFactory != null) { |
result.addAll( |
sAdditionalFactory.create(context, webContents)); |
} |
return result; |
} |
+ |
+ /** |
+ * Build a ServiceWorkerPaymentApp instance for each installed service |
+ * worker based payment app. |
+ */ |
+ private static List<ServiceWorkerPaymentApp> createServiceWorkerPaymentApps() { |
+ if (sServiceWorkerPaymentAppBridge == null) { |
+ if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS)) { |
+ sServiceWorkerPaymentAppBridge = new ServiceWorkerPaymentAppBridge(); |
+ } else { |
+ return new ArrayList<>(); |
+ } |
+ } |
+ |
+ List<ServiceWorkerPaymentApp> result = new ArrayList<>(); |
+ |
+ for (ServiceWorkerPaymentAppBridge.Manifest manifest : |
+ sServiceWorkerPaymentAppBridge.getAllAppManifests()) { |
+ result.add(new ServiceWorkerPaymentApp(manifest)); |
+ } |
+ |
+ return result; |
+ } |
} |