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.DialogInterface; | 10 import android.content.DialogInterface; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 /** The maximum number of milliseconds to wait for a response from a READY_T
O_PAY service. */ | 51 /** The maximum number of milliseconds to wait for a response from a READY_T
O_PAY service. */ |
52 private static final long READY_TO_PAY_TIMEOUT_MS = 400; | 52 private static final long READY_TO_PAY_TIMEOUT_MS = 400; |
53 | 53 |
54 /** The maximum number of milliseconds to wait for a connection to READY_TO_
PAY service. */ | 54 /** The maximum number of milliseconds to wait for a connection to READY_TO_
PAY service. */ |
55 private static final long SERVICE_CONNECTION_TIMEOUT_MS = 1000; | 55 private static final long SERVICE_CONNECTION_TIMEOUT_MS = 1000; |
56 | 56 |
57 private static final String EXTRA_METHOD_NAME = "methodName"; | 57 private static final String EXTRA_METHOD_NAME = "methodName"; |
58 private static final String EXTRA_DATA = "data"; | 58 private static final String EXTRA_DATA = "data"; |
59 private static final String EXTRA_ORIGIN = "origin"; | 59 private static final String EXTRA_ORIGIN = "origin"; |
| 60 private static final String EXTRA_IFRAME_ORIGIN = "iframeOrigin"; |
60 private static final String EXTRA_DETAILS = "details"; | 61 private static final String EXTRA_DETAILS = "details"; |
61 private static final String EXTRA_INSTRUMENT_DETAILS = "instrumentDetails"; | 62 private static final String EXTRA_INSTRUMENT_DETAILS = "instrumentDetails"; |
62 private static final String EXTRA_CERTIFICATE_CHAIN = "certificateChain"; | 63 private static final String EXTRA_CERTIFICATE_CHAIN = "certificateChain"; |
63 private static final String EXTRA_CERTIFICATE = "certificate"; | 64 private static final String EXTRA_CERTIFICATE = "certificate"; |
64 private static final String EMPTY_JSON_DATA = "{}"; | 65 private static final String EMPTY_JSON_DATA = "{}"; |
65 private final Handler mHandler; | 66 private final Handler mHandler; |
66 private final WebContents mWebContents; | 67 private final WebContents mWebContents; |
67 private final Intent mIsReadyToPayIntent; | 68 private final Intent mIsReadyToPayIntent; |
68 private final Intent mPayIntent; | 69 private final Intent mPayIntent; |
69 private final Set<String> mMethodNames; | 70 private final Set<String> mMethodNames; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 Bundle bundle = new Bundle(); | 117 Bundle bundle = new Bundle(); |
117 bundle.putByteArray(EXTRA_CERTIFICATE, certificateChain[i]); | 118 bundle.putByteArray(EXTRA_CERTIFICATE, certificateChain[i]); |
118 certificateArray[i] = bundle; | 119 certificateArray[i] = bundle; |
119 } | 120 } |
120 extras.putParcelableArray(EXTRA_CERTIFICATE_CHAIN, certificateArray)
; | 121 extras.putParcelableArray(EXTRA_CERTIFICATE_CHAIN, certificateArray)
; |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 @Override | 125 @Override |
125 public void getInstruments(Map<String, PaymentMethodData> methodData, String
origin, | 126 public void getInstruments(Map<String, PaymentMethodData> methodData, String
origin, |
126 byte[][] certificateChain, InstrumentsCallback callback) { | 127 String iframeOrigin, byte[][] certificateChain, InstrumentsCallback
callback) { |
127 assert mInstrumentsCallback | 128 assert mInstrumentsCallback |
128 == null : "Have not responded to previous request for instrument
s yet"; | 129 == null : "Have not responded to previous request for instrument
s yet"; |
129 mInstrumentsCallback = callback; | 130 mInstrumentsCallback = callback; |
130 if (mIsReadyToPayIntent.getComponent() == null) { | 131 if (mIsReadyToPayIntent.getComponent() == null) { |
131 respondToGetInstrumentsQuery(AndroidPaymentApp.this); | 132 respondToGetInstrumentsQuery(AndroidPaymentApp.this); |
132 return; | 133 return; |
133 } | 134 } |
134 | 135 |
135 assert !mIsIncognito; | 136 assert !mIsIncognito; |
136 Bundle extras = new Bundle(); | 137 Bundle extras = new Bundle(); |
137 extras.putString(EXTRA_METHOD_NAME, mMethodNames.iterator().next()); | 138 extras.putString(EXTRA_METHOD_NAME, mMethodNames.iterator().next()); |
138 extras.putString(EXTRA_ORIGIN, origin); | 139 extras.putString(EXTRA_ORIGIN, origin); |
| 140 extras.putString(EXTRA_IFRAME_ORIGIN, iframeOrigin); |
139 PaymentMethodData data = methodData.get(mMethodNames.iterator().next()); | 141 PaymentMethodData data = methodData.get(mMethodNames.iterator().next()); |
140 extras.putString(EXTRA_DATA, data == null ? EMPTY_JSON_DATA : data.strin
gifiedData); | 142 extras.putString(EXTRA_DATA, data == null ? EMPTY_JSON_DATA : data.strin
gifiedData); |
141 addCertificateChain(extras, certificateChain); | 143 addCertificateChain(extras, certificateChain); |
142 mIsReadyToPayIntent.putExtras(extras); | 144 mIsReadyToPayIntent.putExtras(extras); |
143 | 145 |
144 mServiceConnection = new ServiceConnection() { | 146 mServiceConnection = new ServiceConnection() { |
145 @Override | 147 @Override |
146 public void onServiceConnected(ComponentName name, IBinder service)
{ | 148 public void onServiceConnected(ComponentName name, IBinder service)
{ |
147 IsReadyToPayService isReadyToPayService = | 149 IsReadyToPayService isReadyToPayService = |
148 IsReadyToPayService.Stub.asInterface(service); | 150 IsReadyToPayService.Stub.asInterface(service); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return Collections.unmodifiableSet(mMethodNames); | 248 return Collections.unmodifiableSet(mMethodNames); |
247 } | 249 } |
248 | 250 |
249 @Override | 251 @Override |
250 public Set<String> getInstrumentMethodNames() { | 252 public Set<String> getInstrumentMethodNames() { |
251 return getAppMethodNames(); | 253 return getAppMethodNames(); |
252 } | 254 } |
253 | 255 |
254 @Override | 256 @Override |
255 public void invokePaymentApp(final String merchantName, final String origin, | 257 public void invokePaymentApp(final String merchantName, final String origin, |
256 final byte[][] certificateChain, final Map<String, PaymentMethodData
> methodDataMap, | 258 final String iframeOrigin, final byte[][] certificateChain, |
257 final PaymentItem total, final List<PaymentItem> displayItems, | 259 final Map<String, PaymentMethodData> methodDataMap, final PaymentIte
m total, |
| 260 final List<PaymentItem> displayItems, |
258 final Map<String, PaymentDetailsModifier> modifiers, | 261 final Map<String, PaymentDetailsModifier> modifiers, |
259 InstrumentDetailsCallback callback) { | 262 InstrumentDetailsCallback callback) { |
260 mInstrumentDetailsCallback = callback; | 263 mInstrumentDetailsCallback = callback; |
261 | 264 |
262 if (!mIsIncognito) { | 265 if (!mIsIncognito) { |
263 launchPaymentApp(merchantName, origin, certificateChain, methodDataM
ap, total, | 266 launchPaymentApp(merchantName, origin, iframeOrigin, certificateChai
n, methodDataMap, |
264 displayItems, modifiers); | 267 total, displayItems, modifiers); |
265 return; | 268 return; |
266 } | 269 } |
267 | 270 |
268 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); | 271 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); |
269 if (activity == null) { | 272 if (activity == null) { |
270 notifyErrorInvokingPaymentApp(); | 273 notifyErrorInvokingPaymentApp(); |
271 return; | 274 return; |
272 } | 275 } |
273 | 276 |
274 new AlertDialog.Builder(activity, R.style.AlertDialogTheme) | 277 new AlertDialog.Builder(activity, R.style.AlertDialogTheme) |
275 .setTitle(R.string.external_app_leave_incognito_warning_title) | 278 .setTitle(R.string.external_app_leave_incognito_warning_title) |
276 .setMessage(R.string.external_payment_app_leave_incognito_warnin
g) | 279 .setMessage(R.string.external_payment_app_leave_incognito_warnin
g) |
277 .setPositiveButton(R.string.ok, | 280 .setPositiveButton(R.string.ok, |
278 new OnClickListener() { | 281 new OnClickListener() { |
279 @Override | 282 @Override |
280 public void onClick(DialogInterface dialog, int whic
h) { | 283 public void onClick(DialogInterface dialog, int whic
h) { |
281 launchPaymentApp(merchantName, origin, certifica
teChain, | 284 launchPaymentApp(merchantName, origin, iframeOri
gin, |
282 methodDataMap, total, displayItems, modi
fiers); | 285 certificateChain, methodDataMap, total,
displayItems, |
| 286 modifiers); |
283 } | 287 } |
284 }) | 288 }) |
285 .setNegativeButton(R.string.cancel, | 289 .setNegativeButton(R.string.cancel, |
286 new OnClickListener() { | 290 new OnClickListener() { |
287 @Override | 291 @Override |
288 public void onClick(DialogInterface dialog, int whic
h) { | 292 public void onClick(DialogInterface dialog, int whic
h) { |
289 notifyErrorInvokingPaymentApp(); | 293 notifyErrorInvokingPaymentApp(); |
290 } | 294 } |
291 }) | 295 }) |
292 .setOnCancelListener(new OnCancelListener() { | 296 .setOnCancelListener(new OnCancelListener() { |
293 @Override | 297 @Override |
294 public void onCancel(DialogInterface dialog) { | 298 public void onCancel(DialogInterface dialog) { |
295 notifyErrorInvokingPaymentApp(); | 299 notifyErrorInvokingPaymentApp(); |
296 } | 300 } |
297 }) | 301 }) |
298 .show(); | 302 .show(); |
299 } | 303 } |
300 | 304 |
301 private void launchPaymentApp(String merchantName, String origin, byte[][] c
ertificateChain, | 305 private void launchPaymentApp(String merchantName, String origin, String ifr
ameOrigin, |
302 Map<String, PaymentMethodData> methodDataMap, PaymentItem total, | 306 byte[][] certificateChain, Map<String, PaymentMethodData> methodData
Map, |
303 List<PaymentItem> displayItems, Map<String, PaymentDetailsModifier>
modifiers) { | 307 PaymentItem total, List<PaymentItem> displayItems, |
| 308 Map<String, PaymentDetailsModifier> modifiers) { |
304 assert mInstrumentDetailsCallback != null; | 309 assert mInstrumentDetailsCallback != null; |
305 assert !mMethodNames.isEmpty(); | 310 assert !mMethodNames.isEmpty(); |
306 Bundle extras = new Bundle(); | 311 Bundle extras = new Bundle(); |
307 extras.putString(EXTRA_ORIGIN, origin); | 312 extras.putString(EXTRA_ORIGIN, origin); |
| 313 extras.putString(EXTRA_IFRAME_ORIGIN, iframeOrigin); |
308 addCertificateChain(extras, certificateChain); | 314 addCertificateChain(extras, certificateChain); |
309 | 315 |
310 String methodName = mMethodNames.iterator().next(); | 316 String methodName = mMethodNames.iterator().next(); |
311 extras.putString(EXTRA_METHOD_NAME, methodName); | 317 extras.putString(EXTRA_METHOD_NAME, methodName); |
312 | 318 |
313 PaymentMethodData methodData = methodDataMap.get(methodName); | 319 PaymentMethodData methodData = methodDataMap.get(methodName); |
314 extras.putString( | 320 extras.putString( |
315 EXTRA_DATA, methodData == null ? EMPTY_JSON_DATA : methodData.st
ringifiedData); | 321 EXTRA_DATA, methodData == null ? EMPTY_JSON_DATA : methodData.st
ringifiedData); |
316 | 322 |
317 String details = serializeDetails(total, displayItems); | 323 String details = serializeDetails(total, displayItems); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 401 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
396 data.getExtras().getString(EXTRA_METHOD_NAME), | 402 data.getExtras().getString(EXTRA_METHOD_NAME), |
397 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); | 403 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); |
398 } | 404 } |
399 mInstrumentDetailsCallback = null; | 405 mInstrumentDetailsCallback = null; |
400 } | 406 } |
401 | 407 |
402 @Override | 408 @Override |
403 public void dismissInstrument() {} | 409 public void dismissInstrument() {} |
404 } | 410 } |
OLD | NEW |