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

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

Issue 2516923002: [Merge M-56] Add canMakeActivePayment() method to web payments. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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;
11 import org.chromium.content.browser.ContentViewCore; 10 import org.chromium.content.browser.ContentViewCore;
12 import org.chromium.content_public.browser.WebContents; 11 import org.chromium.content_public.browser.WebContents;
13 import org.chromium.mojo.system.MojoException; 12 import org.chromium.mojo.system.MojoException;
13 import org.chromium.payments.mojom.ActivePaymentQueryResult;
14 import org.chromium.payments.mojom.PaymentDetails; 14 import org.chromium.payments.mojom.PaymentDetails;
15 import org.chromium.payments.mojom.PaymentErrorReason; 15 import org.chromium.payments.mojom.PaymentErrorReason;
16 import org.chromium.payments.mojom.PaymentMethodData; 16 import org.chromium.payments.mojom.PaymentMethodData;
17 import org.chromium.payments.mojom.PaymentOptions; 17 import org.chromium.payments.mojom.PaymentOptions;
18 import org.chromium.payments.mojom.PaymentRequest; 18 import org.chromium.payments.mojom.PaymentRequest;
19 import org.chromium.payments.mojom.PaymentRequestClient; 19 import org.chromium.payments.mojom.PaymentRequestClient;
20 import org.chromium.services.service_manager.InterfaceFactory; 20 import org.chromium.services.service_manager.InterfaceFactory;
21 import org.chromium.ui.base.WindowAndroid; 21 import org.chromium.ui.base.WindowAndroid;
22 22
23 /** 23 /**
24 * Creates instances of PaymentRequest. 24 * Creates instances of PaymentRequest.
25 */ 25 */
26 public class PaymentRequestFactory 26 public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> {
27 implements InterfaceFactory<PaymentRequest>, PaymentRequestDismissObserv er {
28 private final WebContents mWebContents; 27 private final WebContents mWebContents;
29 private boolean mIsPaymentRequestRunning;
30 28
31 /** 29 /**
32 * An implementation of PaymentRequest that immediately rejects all connecti ons. 30 * An implementation of PaymentRequest that immediately rejects all connecti ons.
33 * Necessary because Mojo does not handle null returned from createImpl(). 31 * Necessary because Mojo does not handle null returned from createImpl().
34 */ 32 */
35 private static final class InvalidPaymentRequest implements PaymentRequest { 33 private static final class InvalidPaymentRequest implements PaymentRequest {
36 private PaymentRequestClient mClient; 34 private PaymentRequestClient mClient;
37 35
38 @Override 36 @Override
39 public void init(PaymentRequestClient client, PaymentMethodData[] method Data, 37 public void init(PaymentRequestClient client, PaymentMethodData[] method Data,
(...skipping 12 matching lines...) Expand all
52 @Override 50 @Override
53 public void updateWith(PaymentDetails details) {} 51 public void updateWith(PaymentDetails details) {}
54 52
55 @Override 53 @Override
56 public void abort() {} 54 public void abort() {}
57 55
58 @Override 56 @Override
59 public void complete(int result) {} 57 public void complete(int result) {}
60 58
61 @Override 59 @Override
60 public void canMakeActivePayment() {
61 if (mClient != null) {
62 mClient.onCanMakeActivePayment(ActivePaymentQueryResult.CANNOT_M AKE_ACTIVE_PAYMENT);
63 }
64 }
65
66 @Override
62 public void close() {} 67 public void close() {}
63 68
64 @Override 69 @Override
65 public void onConnectionError(MojoException e) {} 70 public void onConnectionError(MojoException e) {}
66 } 71 }
67 72
68 /** 73 /**
69 * Builds a factory for PaymentRequest. 74 * Builds a factory for PaymentRequest.
70 * 75 *
71 * @param webContents The web contents that may invoke the PaymentRequest AP I. 76 * @param webContents The web contents that may invoke the PaymentRequest AP I.
(...skipping 12 matching lines...) Expand all
84 89
85 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebCo ntents); 90 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebCo ntents);
86 if (contentViewCore == null) return new InvalidPaymentRequest(); 91 if (contentViewCore == null) return new InvalidPaymentRequest();
87 92
88 WindowAndroid window = contentViewCore.getWindowAndroid(); 93 WindowAndroid window = contentViewCore.getWindowAndroid();
89 if (window == null) return new InvalidPaymentRequest(); 94 if (window == null) return new InvalidPaymentRequest();
90 95
91 Activity context = window.getActivity().get(); 96 Activity context = window.getActivity().get();
92 if (context == null) return new InvalidPaymentRequest(); 97 if (context == null) return new InvalidPaymentRequest();
93 98
94 if (mIsPaymentRequestRunning) return new InvalidPaymentRequest(); 99 return new PaymentRequestImpl(context, mWebContents);
95 mIsPaymentRequestRunning = true;
96
97 return new PaymentRequestImpl(context, mWebContents, this);
98 }
99
100 @Override
101 public void onPaymentRequestDismissed() {
102 mIsPaymentRequestRunning = false;
103 } 100 }
104 } 101 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698