| 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.app.Activity; | 7 import android.app.Activity; |
| 8 | 8 |
| 9 import org.chromium.chrome.browser.ChromeFeatureList; | 9 import org.chromium.chrome.browser.ChromeFeatureList; |
| 10 import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestDis
missObserver; | 10 import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestDis
playObserver; |
| 11 import org.chromium.content.browser.ContentViewCore; | 11 import org.chromium.content.browser.ContentViewCore; |
| 12 import org.chromium.content_public.browser.WebContents; | 12 import org.chromium.content_public.browser.WebContents; |
| 13 import org.chromium.mojo.system.MojoException; | 13 import org.chromium.mojo.system.MojoException; |
| 14 import org.chromium.payments.mojom.ActivePaymentQueryResult; |
| 14 import org.chromium.payments.mojom.PaymentDetails; | 15 import org.chromium.payments.mojom.PaymentDetails; |
| 15 import org.chromium.payments.mojom.PaymentErrorReason; | 16 import org.chromium.payments.mojom.PaymentErrorReason; |
| 16 import org.chromium.payments.mojom.PaymentMethodData; | 17 import org.chromium.payments.mojom.PaymentMethodData; |
| 17 import org.chromium.payments.mojom.PaymentOptions; | 18 import org.chromium.payments.mojom.PaymentOptions; |
| 18 import org.chromium.payments.mojom.PaymentRequest; | 19 import org.chromium.payments.mojom.PaymentRequest; |
| 19 import org.chromium.payments.mojom.PaymentRequestClient; | 20 import org.chromium.payments.mojom.PaymentRequestClient; |
| 20 import org.chromium.services.service_manager.InterfaceFactory; | 21 import org.chromium.services.service_manager.InterfaceFactory; |
| 21 import org.chromium.ui.base.WindowAndroid; | 22 import org.chromium.ui.base.WindowAndroid; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Creates instances of PaymentRequest. | 25 * Creates instances of PaymentRequest. |
| 25 */ | 26 */ |
| 26 public class PaymentRequestFactory | 27 public class PaymentRequestFactory |
| 27 implements InterfaceFactory<PaymentRequest>, PaymentRequestDismissObserv
er { | 28 implements InterfaceFactory<PaymentRequest>, PaymentRequestDisplayObserv
er { |
| 28 private final WebContents mWebContents; | 29 private final WebContents mWebContents; |
| 29 private boolean mIsPaymentRequestRunning; | 30 private boolean mIsPaymentRequestRunning; |
| 30 | 31 |
| 31 /** | 32 /** |
| 32 * An implementation of PaymentRequest that immediately rejects all connecti
ons. | 33 * An implementation of PaymentRequest that immediately rejects all connecti
ons. |
| 33 * Necessary because Mojo does not handle null returned from createImpl(). | 34 * Necessary because Mojo does not handle null returned from createImpl(). |
| 34 */ | 35 */ |
| 35 private static final class InvalidPaymentRequest implements PaymentRequest { | 36 private static final class InvalidPaymentRequest implements PaymentRequest { |
| 36 private PaymentRequestClient mClient; | 37 private PaymentRequestClient mClient; |
| 37 | 38 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 @Override | 53 @Override |
| 53 public void updateWith(PaymentDetails details) {} | 54 public void updateWith(PaymentDetails details) {} |
| 54 | 55 |
| 55 @Override | 56 @Override |
| 56 public void abort() {} | 57 public void abort() {} |
| 57 | 58 |
| 58 @Override | 59 @Override |
| 59 public void complete(int result) {} | 60 public void complete(int result) {} |
| 60 | 61 |
| 61 @Override | 62 @Override |
| 63 public void canMakeActivePayment() { |
| 64 if (mClient != null) { |
| 65 mClient.onCanMakeActivePayment(ActivePaymentQueryResult.CANNOT_M
AKE_ACTIVE_PAYMENT); |
| 66 } |
| 67 } |
| 68 |
| 69 @Override |
| 62 public void close() {} | 70 public void close() {} |
| 63 | 71 |
| 64 @Override | 72 @Override |
| 65 public void onConnectionError(MojoException e) {} | 73 public void onConnectionError(MojoException e) {} |
| 66 } | 74 } |
| 67 | 75 |
| 68 /** | 76 /** |
| 69 * Builds a factory for PaymentRequest. | 77 * Builds a factory for PaymentRequest. |
| 70 * | 78 * |
| 71 * @param webContents The web contents that may invoke the PaymentRequest AP
I. | 79 * @param webContents The web contents that may invoke the PaymentRequest AP
I. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 85 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebCo
ntents); | 93 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebCo
ntents); |
| 86 if (contentViewCore == null) return new InvalidPaymentRequest(); | 94 if (contentViewCore == null) return new InvalidPaymentRequest(); |
| 87 | 95 |
| 88 WindowAndroid window = contentViewCore.getWindowAndroid(); | 96 WindowAndroid window = contentViewCore.getWindowAndroid(); |
| 89 if (window == null) return new InvalidPaymentRequest(); | 97 if (window == null) return new InvalidPaymentRequest(); |
| 90 | 98 |
| 91 Activity context = window.getActivity().get(); | 99 Activity context = window.getActivity().get(); |
| 92 if (context == null) return new InvalidPaymentRequest(); | 100 if (context == null) return new InvalidPaymentRequest(); |
| 93 | 101 |
| 94 if (mIsPaymentRequestRunning) return new InvalidPaymentRequest(); | 102 if (mIsPaymentRequestRunning) return new InvalidPaymentRequest(); |
| 95 mIsPaymentRequestRunning = true; | |
| 96 | 103 |
| 97 return new PaymentRequestImpl(context, mWebContents, this); | 104 return new PaymentRequestImpl(context, mWebContents, this); |
| 98 } | 105 } |
| 99 | 106 |
| 100 @Override | 107 @Override |
| 108 public void onPaymentRequestDisplayed() { |
| 109 mIsPaymentRequestRunning = true; |
| 110 } |
| 111 |
| 112 @Override |
| 101 public void onPaymentRequestDismissed() { | 113 public void onPaymentRequestDismissed() { |
| 102 mIsPaymentRequestRunning = false; | 114 mIsPaymentRequestRunning = false; |
| 103 } | 115 } |
| 104 } | 116 } |
| OLD | NEW |