| 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_ID = "id"; |
| 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 id, final String merchantName, fin
al String origin, |
| 247 final String iframeOrigin, final byte[][] certificateChain, | 248 final String iframeOrigin, final byte[][] certificateChain, |
| 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(id, merchantName, origin, iframeOrigin, certificate
Chain, |
| 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(id, merchantName, origin, ifram
eOrigin, |
| 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 id, 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 if (mWebContents.isDestroyed()) { | 302 if (mWebContents.isDestroyed()) { |
| 302 notifyErrorInvokingPaymentApp(); | 303 notifyErrorInvokingPaymentApp(); |
| 303 return; | 304 return; |
| 304 } | 305 } |
| 305 | 306 |
| 306 WindowAndroid window = mWebContents.getTopLevelNativeWindow(); | 307 WindowAndroid window = mWebContents.getTopLevelNativeWindow(); |
| 307 if (window == null) { | 308 if (window == null) { |
| 308 notifyErrorInvokingPaymentApp(); | 309 notifyErrorInvokingPaymentApp(); |
| 309 return; | 310 return; |
| 310 } | 311 } |
| 311 | 312 |
| 312 mPayIntent.putExtras(buildExtras(merchantName, origin, iframeOrigin, cer
tificateChain, | 313 mPayIntent.putExtras(buildExtras(id, merchantName, origin, iframeOrigin,
certificateChain, |
| 313 methodDataMap, total, displayItems, modifiers)); | 314 methodDataMap, total, displayItems, modifiers)); |
| 314 if (!window.showIntent(mPayIntent, this, R.string.payments_android_app_e
rror)) { | 315 if (!window.showIntent(mPayIntent, this, R.string.payments_android_app_e
rror)) { |
| 315 notifyErrorInvokingPaymentApp(); | 316 notifyErrorInvokingPaymentApp(); |
| 316 } | 317 } |
| 317 } | 318 } |
| 318 | 319 |
| 319 private static Bundle buildExtras(@Nullable String merchantName, String orig
in, | 320 private static Bundle buildExtras(@Nullable String id, @Nullable String merc
hantName, |
| 320 String iframeOrigin, @Nullable byte[][] certificateChain, | 321 String origin, String iframeOrigin, @Nullable byte[][] certificateCh
ain, |
| 321 Map<String, PaymentMethodData> methodDataMap, @Nullable PaymentItem
total, | 322 Map<String, PaymentMethodData> methodDataMap, @Nullable PaymentItem
total, |
| 322 @Nullable List<PaymentItem> displayItems, | 323 @Nullable List<PaymentItem> displayItems, |
| 323 @Nullable Map<String, PaymentDetailsModifier> modifiers) { | 324 @Nullable Map<String, PaymentDetailsModifier> modifiers) { |
| 324 Bundle extras = new Bundle(); | 325 Bundle extras = new Bundle(); |
| 325 | 326 |
| 327 if (id != null) extras.putString(EXTRA_ID, id); |
| 326 if (merchantName != null) extras.putString(EXTRA_MERCHANT_NAME, merchant
Name); | 328 if (merchantName != null) extras.putString(EXTRA_MERCHANT_NAME, merchant
Name); |
| 327 extras.putString(EXTRA_ORIGIN, origin); | 329 extras.putString(EXTRA_ORIGIN, origin); |
| 328 extras.putString(EXTRA_IFRAME_ORIGIN, iframeOrigin); | 330 extras.putString(EXTRA_IFRAME_ORIGIN, iframeOrigin); |
| 329 | 331 |
| 330 if (certificateChain != null && certificateChain.length > 0) { | 332 if (certificateChain != null && certificateChain.length > 0) { |
| 331 extras.putParcelableArray( | 333 extras.putParcelableArray( |
| 332 EXTRA_CERTIFICATE_CHAIN, buildCertificateChain(certificateCh
ain)); | 334 EXTRA_CERTIFICATE_CHAIN, buildCertificateChain(certificateCh
ain)); |
| 333 } | 335 } |
| 334 | 336 |
| 335 // Deprecated: | 337 // Deprecated: |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 435 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
| 434 data.getExtras().getString(EXTRA_METHOD_NAME), | 436 data.getExtras().getString(EXTRA_METHOD_NAME), |
| 435 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); | 437 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); |
| 436 } | 438 } |
| 437 mInstrumentDetailsCallback = null; | 439 mInstrumentDetailsCallback = null; |
| 438 } | 440 } |
| 439 | 441 |
| 440 @Override | 442 @Override |
| 441 public void dismissInstrument() {} | 443 public void dismissInstrument() {} |
| 442 } | 444 } |
| OLD | NEW |