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 | 8 |
9 import org.chromium.base.CommandLine; | |
9 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
11 import org.chromium.chrome.browser.ChromeSwitches; | |
10 import org.chromium.content_public.browser.WebContents; | 12 import org.chromium.content_public.browser.WebContents; |
11 | 13 |
12 import java.util.ArrayList; | 14 import java.util.ArrayList; |
13 import java.util.List; | 15 import java.util.List; |
14 | 16 |
15 /** | 17 /** |
16 * Builds instances of payment apps. | 18 * Builds instances of payment apps. |
17 */ | 19 */ |
18 public class PaymentAppFactory { | 20 public class PaymentAppFactory { |
19 /** | 21 /** |
20 * Can be used to build additional types of payment apps without Chrome know ing about their | 22 * Can be used to build additional types of payment apps without Chrome know ing about their |
21 * types. | 23 * types. |
22 */ | 24 */ |
23 private static PaymentAppFactoryAddition sAdditionalFactory; | 25 private static PaymentAppFactoryAddition sAdditionalFactory; |
24 | 26 |
27 private static ServiceWorkerPaymentAppBridge sServiceWorkerPaymentAppBridge = | |
28 new ServiceWorkerPaymentAppBridge(); | |
29 | |
25 /** | 30 /** |
26 * The interface for additional payment app factories. | 31 * The interface for additional payment app factories. |
27 */ | 32 */ |
28 public interface PaymentAppFactoryAddition { | 33 public interface PaymentAppFactoryAddition { |
29 /** | 34 /** |
30 * Builds instances of payment apps. | 35 * Builds instances of payment apps. |
31 * | 36 * |
32 * @param context The application context. | 37 * @param context The application context. |
33 * @param webContents The web contents that invoked PaymentRequest. | 38 * @param webContents The web contents that invoked PaymentRequest. |
34 */ | 39 */ |
(...skipping 12 matching lines...) Expand all Loading... | |
47 | 52 |
48 /** | 53 /** |
49 * Builds instances of payment apps. | 54 * Builds instances of payment apps. |
50 * | 55 * |
51 * @param context The context. | 56 * @param context The context. |
52 * @param webContents The web contents where PaymentRequest was invoked. | 57 * @param webContents The web contents where PaymentRequest was invoked. |
53 */ | 58 */ |
54 public static List<PaymentApp> create(Context context, WebContents webConten ts) { | 59 public static List<PaymentApp> create(Context context, WebContents webConten ts) { |
55 List<PaymentApp> result = new ArrayList<>(2); | 60 List<PaymentApp> result = new ArrayList<>(2); |
56 result.add(new AutofillPaymentApp(context, webContents)); | 61 result.add(new AutofillPaymentApp(context, webContents)); |
62 | |
63 if (CommandLine.getInstance().hasSwitch( | |
please use gerrit instead
2016/11/30 15:08:28
The new way to add command line flags is base::Fea
tommyt
2016/12/01 13:55:49
Done.
| |
64 ChromeSwitches.ENABLE_SERVICE_WORKER_PAYMENT_APPS)) { | |
65 result.addAll(createServiceWorkerPaymentApps()); | |
66 } | |
67 | |
57 if (sAdditionalFactory != null) { | 68 if (sAdditionalFactory != null) { |
58 result.addAll( | 69 result.addAll( |
59 sAdditionalFactory.create(context, webContents)); | 70 sAdditionalFactory.create(context, webContents)); |
60 } | 71 } |
61 return result; | 72 return result; |
62 } | 73 } |
74 | |
75 /** | |
76 * Build a ServiceWorkerPaymentApp instance for each installed service | |
77 * worker based payment app. | |
78 */ | |
79 private static List<ServiceWorkerPaymentApp> createServiceWorkerPaymentApps( ) { | |
80 List<ServiceWorkerPaymentApp> result = new ArrayList<>(); | |
81 for (ServiceWorkerPaymentAppBridge.Manifest manifest : | |
82 sServiceWorkerPaymentAppBridge.getAllAppManifests()) { | |
83 result.add(new ServiceWorkerPaymentApp(manifest)); | |
84 } | |
85 return result; | |
86 } | |
63 } | 87 } |
OLD | NEW |