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

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

Issue 2526293003: PaymentApp: Add classes for supporting Web Based Payment Apps (Closed)
Patch Set: Make the service worker unittests work even with the feature flag off Created 4 years 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
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.content.Context; 7 import android.content.Context;
8 8
9 import org.chromium.base.VisibleForTesting; 9 import org.chromium.base.VisibleForTesting;
10 import org.chromium.chrome.browser.ChromeFeatureList;
10 import org.chromium.content_public.browser.WebContents; 11 import org.chromium.content_public.browser.WebContents;
11 12
12 import java.util.ArrayList; 13 import java.util.ArrayList;
13 import java.util.List; 14 import java.util.List;
14 15
15 /** 16 /**
16 * Builds instances of payment apps. 17 * Builds instances of payment apps.
17 */ 18 */
18 public class PaymentAppFactory { 19 public class PaymentAppFactory {
19 /** 20 /**
20 * Can be used to build additional types of payment apps without Chrome know ing about their 21 * Can be used to build additional types of payment apps without Chrome know ing about their
21 * types. 22 * types.
22 */ 23 */
23 private static PaymentAppFactoryAddition sAdditionalFactory; 24 private static PaymentAppFactoryAddition sAdditionalFactory;
24 25
25 /** 26 /**
27 * Native bridge that can be used to retrieve information about installed se rvice worker
28 * payment apps.
29 */
30 private static ServiceWorkerPaymentAppBridge sServiceWorkerPaymentAppBridge;
31
32 /**
26 * The interface for additional payment app factories. 33 * The interface for additional payment app factories.
27 */ 34 */
28 public interface PaymentAppFactoryAddition { 35 public interface PaymentAppFactoryAddition {
29 /** 36 /**
30 * Builds instances of payment apps. 37 * Builds instances of payment apps.
31 * 38 *
32 * @param context The application context. 39 * @param context The application context.
33 * @param webContents The web contents that invoked PaymentRequest. 40 * @param webContents The web contents that invoked PaymentRequest.
34 */ 41 */
35 List<PaymentApp> create(Context context, WebContents webContents); 42 List<PaymentApp> create(Context context, WebContents webContents);
36 } 43 }
37 44
38 /** 45 /**
39 * Sets the additional factory that can build instances of payment apps. 46 * Sets the additional factory that can build instances of payment apps.
40 * 47 *
41 * @param additionalFactory Can build instances of payment apps. 48 * @param additionalFactory Can build instances of payment apps.
42 */ 49 */
43 @VisibleForTesting 50 @VisibleForTesting
44 public static void setAdditionalFactory(PaymentAppFactoryAddition additional Factory) { 51 public static void setAdditionalFactory(PaymentAppFactoryAddition additional Factory) {
45 sAdditionalFactory = additionalFactory; 52 sAdditionalFactory = additionalFactory;
46 } 53 }
47 54
48 /** 55 /**
56 * Set a custom native bridge for service worker payment apps for testing.
57 */
58 @VisibleForTesting
59 public static void setServiceWorkerPaymentAppBridgeForTest(
60 ServiceWorkerPaymentAppBridge bridge) {
61 sServiceWorkerPaymentAppBridge = bridge;
62 }
63
64 /**
49 * Builds instances of payment apps. 65 * Builds instances of payment apps.
50 * 66 *
51 * @param context The context. 67 * @param context The context.
52 * @param webContents The web contents where PaymentRequest was invoked. 68 * @param webContents The web contents where PaymentRequest was invoked.
53 */ 69 */
54 public static List<PaymentApp> create(Context context, WebContents webConten ts) { 70 public static List<PaymentApp> create(Context context, WebContents webConten ts) {
55 List<PaymentApp> result = new ArrayList<>(2); 71 List<PaymentApp> result = new ArrayList<>(2);
56 result.add(new AutofillPaymentApp(context, webContents)); 72 result.add(new AutofillPaymentApp(context, webContents));
73
74 result.addAll(createServiceWorkerPaymentApps());
75
57 if (sAdditionalFactory != null) { 76 if (sAdditionalFactory != null) {
58 result.addAll( 77 result.addAll(
59 sAdditionalFactory.create(context, webContents)); 78 sAdditionalFactory.create(context, webContents));
60 } 79 }
61 return result; 80 return result;
62 } 81 }
82
83 /**
84 * Build a ServiceWorkerPaymentApp instance for each installed service
85 * worker based payment app.
86 */
87 private static List<ServiceWorkerPaymentApp> createServiceWorkerPaymentApps( ) {
88 if (sServiceWorkerPaymentAppBridge == null) {
89 if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAY MENT_APPS)) {
90 sServiceWorkerPaymentAppBridge = new ServiceWorkerPaymentAppBrid ge();
91 } else {
92 return new ArrayList<>();
93 }
94 }
95
96 List<ServiceWorkerPaymentApp> result = new ArrayList<>();
97
98 for (ServiceWorkerPaymentAppBridge.Manifest manifest :
99 sServiceWorkerPaymentAppBridge.getAllAppManifests()) {
100 result.add(new ServiceWorkerPaymentApp(manifest));
101 }
102
103 return result;
104 }
63 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698