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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 extends PaymentInstrument implements PaymentApp, WindowAndroid.IntentCal lback { | 49 extends PaymentInstrument implements PaymentApp, WindowAndroid.IntentCal lback { |
50 /** The action name for the Pay Intent. */ | 50 /** The action name for the Pay Intent. */ |
51 public static final String ACTION_PAY = "org.chromium.intent.action.PAY"; | 51 public static final String ACTION_PAY = "org.chromium.intent.action.PAY"; |
52 | 52 |
53 /** The maximum number of milliseconds to wait for a response from a READY_T O_PAY service. */ | 53 /** The maximum number of milliseconds to wait for a response from a READY_T O_PAY service. */ |
54 private static final long READY_TO_PAY_TIMEOUT_MS = 400; | 54 private static final long READY_TO_PAY_TIMEOUT_MS = 400; |
55 | 55 |
56 /** The maximum number of milliseconds to wait for a connection to READY_TO_ PAY service. */ | 56 /** The maximum number of milliseconds to wait for a connection to READY_TO_ PAY service. */ |
57 private static final long SERVICE_CONNECTION_TIMEOUT_MS = 1000; | 57 private static final long SERVICE_CONNECTION_TIMEOUT_MS = 1000; |
58 | 58 |
59 private static final String EXTRA_REQUEST_ID = "requestId"; | |
please use gerrit instead
2017/03/24 20:14:18
Why "requestId" instead of id"? What does the paym
| |
59 private static final String EXTRA_MERCHANT_NAME = "merchantName"; | 60 private static final String EXTRA_MERCHANT_NAME = "merchantName"; |
60 private static final String EXTRA_METHOD_NAME = "methodName"; | 61 private static final String EXTRA_METHOD_NAME = "methodName"; |
61 private static final String EXTRA_METHOD_NAMES = "methodNames"; | 62 private static final String EXTRA_METHOD_NAMES = "methodNames"; |
62 private static final String EXTRA_DATA = "data"; | 63 private static final String EXTRA_DATA = "data"; |
63 private static final String EXTRA_ORIGIN = "origin"; | 64 private static final String EXTRA_ORIGIN = "origin"; |
64 private static final String EXTRA_IFRAME_ORIGIN = "iframeOrigin"; | 65 private static final String EXTRA_IFRAME_ORIGIN = "iframeOrigin"; |
65 private static final String EXTRA_DATA_MAP = "dataMap"; | 66 private static final String EXTRA_DATA_MAP = "dataMap"; |
66 private static final String EXTRA_DETAILS = "details"; | 67 private static final String EXTRA_DETAILS = "details"; |
67 private static final String EXTRA_INSTRUMENT_DETAILS = "instrumentDetails"; | 68 private static final String EXTRA_INSTRUMENT_DETAILS = "instrumentDetails"; |
68 private static final String EXTRA_CERTIFICATE_CHAIN = "certificateChain"; | 69 private static final String EXTRA_CERTIFICATE_CHAIN = "certificateChain"; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 respondToGetInstrumentsQuery(null); | 140 respondToGetInstrumentsQuery(null); |
140 } else { | 141 } else { |
141 sendIsReadyToPayIntentToPaymentApp(isReadyToPayService); | 142 sendIsReadyToPayIntentToPaymentApp(isReadyToPayService); |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 @Override | 146 @Override |
146 public void onServiceDisconnected(ComponentName name) {} | 147 public void onServiceDisconnected(ComponentName name) {} |
147 }; | 148 }; |
148 | 149 |
149 mIsReadyToPayIntent.putExtras(buildExtras( | 150 mIsReadyToPayIntent.putExtras(buildExtras(null, null, origin, iframeOrig in, |
150 null, origin, iframeOrigin, certificateChain, methodDataMap, nul l, null, null)); | 151 certificateChain, methodDataMap, null, null, null)); |
151 try { | 152 try { |
152 if (!ContextUtils.getApplicationContext().bindService( | 153 if (!ContextUtils.getApplicationContext().bindService( |
153 mIsReadyToPayIntent, mServiceConnection, Context.BIND_AU TO_CREATE)) { | 154 mIsReadyToPayIntent, mServiceConnection, Context.BIND_AU TO_CREATE)) { |
154 respondToGetInstrumentsQuery(null); | 155 respondToGetInstrumentsQuery(null); |
155 return; | 156 return; |
156 } | 157 } |
157 } catch (SecurityException e) { | 158 } catch (SecurityException e) { |
158 respondToGetInstrumentsQuery(null); | 159 respondToGetInstrumentsQuery(null); |
159 return; | 160 return; |
160 } | 161 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 public Set<String> getAppMethodNames() { | 237 public Set<String> getAppMethodNames() { |
237 return Collections.unmodifiableSet(mMethodNames); | 238 return Collections.unmodifiableSet(mMethodNames); |
238 } | 239 } |
239 | 240 |
240 @Override | 241 @Override |
241 public Set<String> getInstrumentMethodNames() { | 242 public Set<String> getInstrumentMethodNames() { |
242 return getAppMethodNames(); | 243 return getAppMethodNames(); |
243 } | 244 } |
244 | 245 |
245 @Override | 246 @Override |
246 public void invokePaymentApp(final String merchantName, final String origin, | 247 public void invokePaymentApp(final String requestId, final String merchantNa me, |
247 final String iframeOrigin, final byte[][] certificateChain, | 248 final String origin, final String iframeOrigin, final byte[][] certi ficateChain, |
248 final Map<String, PaymentMethodData> methodDataMap, final PaymentIte m total, | 249 final Map<String, PaymentMethodData> methodDataMap, final PaymentIte m total, |
249 final List<PaymentItem> displayItems, | 250 final List<PaymentItem> displayItems, |
250 final Map<String, PaymentDetailsModifier> modifiers, | 251 final Map<String, PaymentDetailsModifier> modifiers, |
251 InstrumentDetailsCallback callback) { | 252 InstrumentDetailsCallback callback) { |
252 mInstrumentDetailsCallback = callback; | 253 mInstrumentDetailsCallback = callback; |
253 | 254 |
254 if (!mIsIncognito) { | 255 if (!mIsIncognito) { |
255 launchPaymentApp(merchantName, origin, iframeOrigin, certificateChai n, methodDataMap, | 256 launchPaymentApp(requestId, merchantName, origin, iframeOrigin, cert ificateChain, |
256 total, displayItems, modifiers); | 257 methodDataMap, total, displayItems, modifiers); |
257 return; | 258 return; |
258 } | 259 } |
259 | 260 |
260 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); | 261 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); |
261 if (activity == null) { | 262 if (activity == null) { |
262 notifyErrorInvokingPaymentApp(); | 263 notifyErrorInvokingPaymentApp(); |
263 return; | 264 return; |
264 } | 265 } |
265 | 266 |
266 new AlertDialog.Builder(activity, R.style.AlertDialogTheme) | 267 new AlertDialog.Builder(activity, R.style.AlertDialogTheme) |
267 .setTitle(R.string.external_app_leave_incognito_warning_title) | 268 .setTitle(R.string.external_app_leave_incognito_warning_title) |
268 .setMessage(R.string.external_payment_app_leave_incognito_warnin g) | 269 .setMessage(R.string.external_payment_app_leave_incognito_warnin g) |
269 .setPositiveButton(R.string.ok, | 270 .setPositiveButton(R.string.ok, |
270 new OnClickListener() { | 271 new OnClickListener() { |
271 @Override | 272 @Override |
272 public void onClick(DialogInterface dialog, int whic h) { | 273 public void onClick(DialogInterface dialog, int whic h) { |
273 launchPaymentApp(merchantName, origin, iframeOri gin, | 274 launchPaymentApp(requestId, merchantName, origin , iframeOrigin, |
274 certificateChain, methodDataMap, total, displayItems, | 275 certificateChain, methodDataMap, total, displayItems, |
275 modifiers); | 276 modifiers); |
276 } | 277 } |
277 }) | 278 }) |
278 .setNegativeButton(R.string.cancel, | 279 .setNegativeButton(R.string.cancel, |
279 new OnClickListener() { | 280 new OnClickListener() { |
280 @Override | 281 @Override |
281 public void onClick(DialogInterface dialog, int whic h) { | 282 public void onClick(DialogInterface dialog, int whic h) { |
282 notifyErrorInvokingPaymentApp(); | 283 notifyErrorInvokingPaymentApp(); |
283 } | 284 } |
284 }) | 285 }) |
285 .setOnCancelListener(new OnCancelListener() { | 286 .setOnCancelListener(new OnCancelListener() { |
286 @Override | 287 @Override |
287 public void onCancel(DialogInterface dialog) { | 288 public void onCancel(DialogInterface dialog) { |
288 notifyErrorInvokingPaymentApp(); | 289 notifyErrorInvokingPaymentApp(); |
289 } | 290 } |
290 }) | 291 }) |
291 .show(); | 292 .show(); |
292 } | 293 } |
293 | 294 |
294 private void launchPaymentApp(String merchantName, String origin, String ifr ameOrigin, | 295 private void launchPaymentApp(String requestId, String merchantName, String origin, |
295 byte[][] certificateChain, Map<String, PaymentMethodData> methodData Map, | 296 String iframeOrigin, byte[][] certificateChain, |
296 PaymentItem total, List<PaymentItem> displayItems, | 297 Map<String, PaymentMethodData> methodDataMap, PaymentItem total, |
297 Map<String, PaymentDetailsModifier> modifiers) { | 298 List<PaymentItem> displayItems, Map<String, PaymentDetailsModifier> modifiers) { |
298 assert mMethodNames.containsAll(methodDataMap.keySet()); | 299 assert mMethodNames.containsAll(methodDataMap.keySet()); |
299 assert mInstrumentDetailsCallback != null; | 300 assert mInstrumentDetailsCallback != null; |
300 | 301 |
301 WindowAndroid window = mWebContents.getTopLevelNativeWindow(); | 302 WindowAndroid window = mWebContents.getTopLevelNativeWindow(); |
302 if (window == null) { | 303 if (window == null) { |
303 notifyErrorInvokingPaymentApp(); | 304 notifyErrorInvokingPaymentApp(); |
304 return; | 305 return; |
305 } | 306 } |
306 | 307 |
307 mPayIntent.putExtras(buildExtras(merchantName, origin, iframeOrigin, cer tificateChain, | 308 mPayIntent.putExtras(buildExtras(requestId, merchantName, origin, iframe Origin, |
308 methodDataMap, total, displayItems, modifiers)); | 309 certificateChain, methodDataMap, total, displayItems, modifiers) ); |
309 if (!window.showIntent(mPayIntent, this, R.string.payments_android_app_e rror)) { | 310 if (!window.showIntent(mPayIntent, this, R.string.payments_android_app_e rror)) { |
310 notifyErrorInvokingPaymentApp(); | 311 notifyErrorInvokingPaymentApp(); |
311 } | 312 } |
312 } | 313 } |
313 | 314 |
314 private static Bundle buildExtras(@Nullable String merchantName, String orig in, | 315 private static Bundle buildExtras(@Nullable String requestId, @Nullable Stri ng merchantName, |
315 String iframeOrigin, @Nullable byte[][] certificateChain, | 316 String origin, String iframeOrigin, @Nullable byte[][] certificateCh ain, |
316 Map<String, PaymentMethodData> methodDataMap, @Nullable PaymentItem total, | 317 Map<String, PaymentMethodData> methodDataMap, @Nullable PaymentItem total, |
317 @Nullable List<PaymentItem> displayItems, | 318 @Nullable List<PaymentItem> displayItems, |
318 @Nullable Map<String, PaymentDetailsModifier> modifiers) { | 319 @Nullable Map<String, PaymentDetailsModifier> modifiers) { |
319 Bundle extras = new Bundle(); | 320 Bundle extras = new Bundle(); |
320 | 321 |
322 if (requestId != null) extras.putString(EXTRA_REQUEST_ID, requestId); | |
321 if (merchantName != null) extras.putString(EXTRA_MERCHANT_NAME, merchant Name); | 323 if (merchantName != null) extras.putString(EXTRA_MERCHANT_NAME, merchant Name); |
322 extras.putString(EXTRA_ORIGIN, origin); | 324 extras.putString(EXTRA_ORIGIN, origin); |
323 extras.putString(EXTRA_IFRAME_ORIGIN, iframeOrigin); | 325 extras.putString(EXTRA_IFRAME_ORIGIN, iframeOrigin); |
324 | 326 |
325 if (certificateChain != null && certificateChain.length > 0) { | 327 if (certificateChain != null && certificateChain.length > 0) { |
326 extras.putParcelableArray( | 328 extras.putParcelableArray( |
327 EXTRA_CERTIFICATE_CHAIN, buildCertificateChain(certificateCh ain)); | 329 EXTRA_CERTIFICATE_CHAIN, buildCertificateChain(certificateCh ain)); |
328 } | 330 } |
329 | 331 |
330 // Deprecated: | 332 // Deprecated: |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 430 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
429 data.getExtras().getString(EXTRA_METHOD_NAME), | 431 data.getExtras().getString(EXTRA_METHOD_NAME), |
430 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); | 432 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); |
431 } | 433 } |
432 mInstrumentDetailsCallback = null; | 434 mInstrumentDetailsCallback = null; |
433 } | 435 } |
434 | 436 |
435 @Override | 437 @Override |
436 public void dismissInstrument() {} | 438 public void dismissInstrument() {} |
437 } | 439 } |
OLD | NEW |