| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 import android.content.ComponentName; | 8 import android.content.ComponentName; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| 11 import android.content.ServiceConnection; | 11 import android.content.ServiceConnection; |
| 12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
| 13 import android.os.Bundle; | 13 import android.os.Bundle; |
| 14 import android.os.Handler; | 14 import android.os.Handler; |
| 15 import android.os.IBinder; | 15 import android.os.IBinder; |
| 16 import android.os.Parcelable; |
| 16 import android.os.RemoteException; | 17 import android.os.RemoteException; |
| 17 import android.util.JsonWriter; | 18 import android.util.JsonWriter; |
| 18 | 19 |
| 19 import org.chromium.IsReadyToPayService; | 20 import org.chromium.IsReadyToPayService; |
| 20 import org.chromium.IsReadyToPayServiceCallback; | 21 import org.chromium.IsReadyToPayServiceCallback; |
| 21 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
| 22 import org.chromium.content.browser.ContentViewCore; | 23 import org.chromium.content.browser.ContentViewCore; |
| 23 import org.chromium.content_public.browser.WebContents; | 24 import org.chromium.content_public.browser.WebContents; |
| 24 import org.chromium.payments.mojom.PaymentDetailsModifier; | 25 import org.chromium.payments.mojom.PaymentDetailsModifier; |
| 25 import org.chromium.payments.mojom.PaymentItem; | 26 import org.chromium.payments.mojom.PaymentItem; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 public class AndroidPaymentApp extends PaymentInstrument implements PaymentApp, | 40 public class AndroidPaymentApp extends PaymentInstrument implements PaymentApp, |
| 40 WindowAndroid.IntentCallback { | 41 WindowAndroid.IntentCallback { |
| 41 /** The action name for the Pay Intent. */ | 42 /** The action name for the Pay Intent. */ |
| 42 public static final String ACTION_PAY = "org.chromium.intent.action.PAY"; | 43 public static final String ACTION_PAY = "org.chromium.intent.action.PAY"; |
| 43 | 44 |
| 44 private static final String EXTRA_METHOD_NAME = "methodName"; | 45 private static final String EXTRA_METHOD_NAME = "methodName"; |
| 45 private static final String EXTRA_DATA = "data"; | 46 private static final String EXTRA_DATA = "data"; |
| 46 private static final String EXTRA_ORIGIN = "origin"; | 47 private static final String EXTRA_ORIGIN = "origin"; |
| 47 private static final String EXTRA_DETAILS = "details"; | 48 private static final String EXTRA_DETAILS = "details"; |
| 48 private static final String EXTRA_INSTRUMENT_DETAILS = "instrumentDetails"; | 49 private static final String EXTRA_INSTRUMENT_DETAILS = "instrumentDetails"; |
| 50 private static final String EXTRA_CERTIFICATE_CHAIN = "certificateChain"; |
| 51 private static final String EXTRA_CERTIFICATE = "certificate"; |
| 49 private static final String EMPTY_JSON_DATA = "{}"; | 52 private static final String EMPTY_JSON_DATA = "{}"; |
| 50 private final Handler mHandler; | 53 private final Handler mHandler; |
| 51 private final WebContents mWebContents; | 54 private final WebContents mWebContents; |
| 52 private final Intent mIsReadyToPayIntent; | 55 private final Intent mIsReadyToPayIntent; |
| 53 private final Intent mPayIntent; | 56 private final Intent mPayIntent; |
| 54 private final Set<String> mMethodNames; | 57 private final Set<String> mMethodNames; |
| 55 private IsReadyToPayService mIsReadyToPayService; | 58 private IsReadyToPayService mIsReadyToPayService; |
| 56 private InstrumentsCallback mInstrumentsCallback; | 59 private InstrumentsCallback mInstrumentsCallback; |
| 57 private InstrumentDetailsCallback mInstrumentDetailsCallback; | 60 private InstrumentDetailsCallback mInstrumentDetailsCallback; |
| 58 private final ServiceConnection mServiceConnection = new ServiceConnection()
{ | 61 private final ServiceConnection mServiceConnection = new ServiceConnection()
{ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 /** @param methodName A payment method that this app supports, e.g., "https:
//bobpay.com". */ | 100 /** @param methodName A payment method that this app supports, e.g., "https:
//bobpay.com". */ |
| 98 public void addMethodName(String methodName) { | 101 public void addMethodName(String methodName) { |
| 99 mMethodNames.add(methodName); | 102 mMethodNames.add(methodName); |
| 100 } | 103 } |
| 101 | 104 |
| 102 /** @param className The class name of the "is ready to pay" service in the
payment app. */ | 105 /** @param className The class name of the "is ready to pay" service in the
payment app. */ |
| 103 public void setIsReadyToPayAction(String className) { | 106 public void setIsReadyToPayAction(String className) { |
| 104 mIsReadyToPayIntent.setClassName(mIsReadyToPayIntent.getPackage(), class
Name); | 107 mIsReadyToPayIntent.setClassName(mIsReadyToPayIntent.getPackage(), class
Name); |
| 105 } | 108 } |
| 106 | 109 |
| 110 private void addCertificateChain(Bundle extras, byte[][] certificateChain) { |
| 111 if (certificateChain != null && certificateChain.length > 0) { |
| 112 Parcelable[] certificateArray = new Parcelable[certificateChain.leng
th]; |
| 113 for (int i = 0; i < certificateChain.length; i++) { |
| 114 Bundle bundle = new Bundle(); |
| 115 bundle.putByteArray(EXTRA_CERTIFICATE, certificateChain[i]); |
| 116 certificateArray[i] = bundle; |
| 117 } |
| 118 extras.putParcelableArray(EXTRA_CERTIFICATE_CHAIN, certificateArray)
; |
| 119 } |
| 120 } |
| 121 |
| 107 @Override | 122 @Override |
| 108 public void getInstruments(Map<String, PaymentMethodData> methodData, String
origin, | 123 public void getInstruments(Map<String, PaymentMethodData> methodData, String
origin, |
| 109 InstrumentsCallback callback) { | 124 byte[][] certificateChain, InstrumentsCallback callback) { |
| 110 mInstrumentsCallback = callback; | 125 mInstrumentsCallback = callback; |
| 111 if (mIsReadyToPayIntent.getPackage() == null) { | 126 if (mIsReadyToPayIntent.getPackage() == null) { |
| 112 mHandler.post(new Runnable() { | 127 mHandler.post(new Runnable() { |
| 113 @Override | 128 @Override |
| 114 public void run() { | 129 public void run() { |
| 115 respondToGetInstrumentsQuery(AndroidPaymentApp.this); | 130 respondToGetInstrumentsQuery(AndroidPaymentApp.this); |
| 116 } | 131 } |
| 117 }); | 132 }); |
| 118 return; | 133 return; |
| 119 } | 134 } |
| 120 Bundle extras = new Bundle(); | 135 Bundle extras = new Bundle(); |
| 121 extras.putString(EXTRA_METHOD_NAME, mMethodNames.iterator().next()); | 136 extras.putString(EXTRA_METHOD_NAME, mMethodNames.iterator().next()); |
| 122 extras.putString(EXTRA_ORIGIN, origin); | 137 extras.putString(EXTRA_ORIGIN, origin); |
| 123 PaymentMethodData data = methodData.get(mMethodNames.iterator().next()); | 138 PaymentMethodData data = methodData.get(mMethodNames.iterator().next()); |
| 124 extras.putString(EXTRA_DATA, data == null ? EMPTY_JSON_DATA : data.strin
gifiedData); | 139 extras.putString(EXTRA_DATA, data == null ? EMPTY_JSON_DATA : data.strin
gifiedData); |
| 140 addCertificateChain(extras, certificateChain); |
| 125 mIsReadyToPayIntent.putExtras(extras); | 141 mIsReadyToPayIntent.putExtras(extras); |
| 126 | 142 |
| 127 if (mIsReadyToPayService != null) { | 143 if (mIsReadyToPayService != null) { |
| 128 sendIsReadyToPayIntentToPaymentApp(); | 144 sendIsReadyToPayIntentToPaymentApp(); |
| 129 } else { | 145 } else { |
| 130 ContentViewCore contentView = ContentViewCore.fromWebContents(mWebCo
ntents); | 146 ContentViewCore contentView = ContentViewCore.fromWebContents(mWebCo
ntents); |
| 131 if (contentView == null) { | 147 if (contentView == null) { |
| 132 notifyError(); | 148 notifyError(); |
| 133 return; | 149 return; |
| 134 } | 150 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 public Set<String> getAppMethodNames() { | 211 public Set<String> getAppMethodNames() { |
| 196 return Collections.unmodifiableSet(mMethodNames); | 212 return Collections.unmodifiableSet(mMethodNames); |
| 197 } | 213 } |
| 198 | 214 |
| 199 @Override | 215 @Override |
| 200 public Set<String> getInstrumentMethodNames() { | 216 public Set<String> getInstrumentMethodNames() { |
| 201 return getAppMethodNames(); | 217 return getAppMethodNames(); |
| 202 } | 218 } |
| 203 | 219 |
| 204 @Override | 220 @Override |
| 205 public void invokePaymentApp(String merchantName, String origin, | 221 public void invokePaymentApp(String merchantName, String origin, byte[][] ce
rtificateChain, |
| 206 Map<String, PaymentMethodData> methodDataMap, PaymentItem total, | 222 Map<String, PaymentMethodData> methodDataMap, PaymentItem total, |
| 207 List<PaymentItem> displayItems, Map<String, PaymentDetailsModifier>
modifiers, | 223 List<PaymentItem> displayItems, Map<String, PaymentDetailsModifier>
modifiers, |
| 208 InstrumentDetailsCallback callback) { | 224 InstrumentDetailsCallback callback) { |
| 209 assert !mMethodNames.isEmpty(); | 225 assert !mMethodNames.isEmpty(); |
| 210 Bundle extras = new Bundle(); | 226 Bundle extras = new Bundle(); |
| 211 extras.putString(EXTRA_ORIGIN, origin); | 227 extras.putString(EXTRA_ORIGIN, origin); |
| 228 addCertificateChain(extras, certificateChain); |
| 212 | 229 |
| 213 String methodName = mMethodNames.iterator().next(); | 230 String methodName = mMethodNames.iterator().next(); |
| 214 extras.putString(EXTRA_METHOD_NAME, methodName); | 231 extras.putString(EXTRA_METHOD_NAME, methodName); |
| 215 | 232 |
| 216 PaymentMethodData methodData = methodDataMap.get(methodName); | 233 PaymentMethodData methodData = methodDataMap.get(methodName); |
| 217 extras.putString( | 234 extras.putString( |
| 218 EXTRA_DATA, methodData == null ? EMPTY_JSON_DATA : methodData.st
ringifiedData); | 235 EXTRA_DATA, methodData == null ? EMPTY_JSON_DATA : methodData.st
ringifiedData); |
| 219 | 236 |
| 220 String details = serializeDetails(total, displayItems); | 237 String details = serializeDetails(total, displayItems); |
| 221 extras.putString(EXTRA_DETAILS, details == null ? EMPTY_JSON_DATA : deta
ils); | 238 extras.putString(EXTRA_DETAILS, details == null ? EMPTY_JSON_DATA : deta
ils); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 322 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
| 306 data.getExtras().getString(EXTRA_METHOD_NAME), | 323 data.getExtras().getString(EXTRA_METHOD_NAME), |
| 307 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); | 324 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); |
| 308 } | 325 } |
| 309 mInstrumentDetailsCallback = null; | 326 mInstrumentDetailsCallback = null; |
| 310 } | 327 } |
| 311 | 328 |
| 312 @Override | 329 @Override |
| 313 public void dismissInstrument() {} | 330 public void dismissInstrument() {} |
| 314 } | 331 } |
| OLD | NEW |