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 org.chromium.chrome.browser.ChromeFeatureList; | 7 import org.chromium.chrome.browser.ChromeFeatureList; |
8 import org.chromium.content_public.browser.WebContents; | 8 import org.chromium.content_public.browser.RenderFrameHost; |
9 import org.chromium.mojo.system.MojoException; | 9 import org.chromium.mojo.system.MojoException; |
10 import org.chromium.payments.mojom.CanMakePaymentQueryResult; | 10 import org.chromium.payments.mojom.CanMakePaymentQueryResult; |
11 import org.chromium.payments.mojom.PaymentDetails; | 11 import org.chromium.payments.mojom.PaymentDetails; |
12 import org.chromium.payments.mojom.PaymentErrorReason; | 12 import org.chromium.payments.mojom.PaymentErrorReason; |
13 import org.chromium.payments.mojom.PaymentMethodData; | 13 import org.chromium.payments.mojom.PaymentMethodData; |
14 import org.chromium.payments.mojom.PaymentOptions; | 14 import org.chromium.payments.mojom.PaymentOptions; |
15 import org.chromium.payments.mojom.PaymentRequest; | 15 import org.chromium.payments.mojom.PaymentRequest; |
16 import org.chromium.payments.mojom.PaymentRequestClient; | 16 import org.chromium.payments.mojom.PaymentRequestClient; |
17 import org.chromium.services.service_manager.InterfaceFactory; | 17 import org.chromium.services.service_manager.InterfaceFactory; |
18 | 18 |
19 /** | 19 /** |
20 * Creates instances of PaymentRequest. | 20 * Creates instances of PaymentRequest. |
21 */ | 21 */ |
22 public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> { | 22 public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> { |
23 private final WebContents mWebContents; | 23 private final RenderFrameHost mRenderFrameHost; |
24 | 24 |
25 /** | 25 /** |
26 * An implementation of PaymentRequest that immediately rejects all connecti
ons. | 26 * An implementation of PaymentRequest that immediately rejects all connecti
ons. |
27 * Necessary because Mojo does not handle null returned from createImpl(). | 27 * Necessary because Mojo does not handle null returned from createImpl(). |
28 */ | 28 */ |
29 private static final class InvalidPaymentRequest implements PaymentRequest { | 29 private static final class InvalidPaymentRequest implements PaymentRequest { |
30 private PaymentRequestClient mClient; | 30 private PaymentRequestClient mClient; |
31 | 31 |
32 @Override | 32 @Override |
33 public void init(PaymentRequestClient client, PaymentMethodData[] method
Data, | 33 public void init(PaymentRequestClient client, PaymentMethodData[] method
Data, |
(...skipping 30 matching lines...) Expand all Loading... |
64 | 64 |
65 @Override | 65 @Override |
66 public void onConnectionError(MojoException e) {} | 66 public void onConnectionError(MojoException e) {} |
67 } | 67 } |
68 | 68 |
69 /** | 69 /** |
70 * Builds a factory for PaymentRequest. | 70 * Builds a factory for PaymentRequest. |
71 * | 71 * |
72 * @param webContents The web contents that may invoke the PaymentRequest AP
I. | 72 * @param webContents The web contents that may invoke the PaymentRequest AP
I. |
73 */ | 73 */ |
74 public PaymentRequestFactory(WebContents webContents) { | 74 public PaymentRequestFactory(RenderFrameHost renderFrameHost) { |
75 mWebContents = webContents; | 75 mRenderFrameHost = renderFrameHost; |
76 } | 76 } |
77 | 77 |
78 @Override | 78 @Override |
79 public PaymentRequest createImpl() { | 79 public PaymentRequest createImpl() { |
80 if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS)) { | 80 if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS)) { |
81 return new InvalidPaymentRequest(); | 81 return new InvalidPaymentRequest(); |
82 } | 82 } |
83 | 83 |
84 if (mWebContents == null) return new InvalidPaymentRequest(); | 84 if (mRenderFrameHost == null) return new InvalidPaymentRequest(); |
85 | 85 |
86 return new PaymentRequestImpl(mWebContents); | 86 return new PaymentRequestImpl(mRenderFrameHost); |
87 } | 87 } |
88 } | 88 } |
OLD | NEW |