Commit 4f331c65 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PlayBilling] Move intent creation into helper

Before Change:
* AndroidPaymentApp owns mPayIntent, mIsReadyToPayIntent.
* AndroidPaymentApp is responsible for creating the Intent.

After Change:
* The two intents become temporary variables.
* WebPaymentIntentHelper is responsible for creating the Intent.

Bug: 1057488

Change-Id: I9510c9bf50b697c3809c31445cea5ff99805e45d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096109
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748879}
parent bbfe0e12
...@@ -59,10 +59,11 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten ...@@ -59,10 +59,11 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten
private final Handler mHandler; private final Handler mHandler;
private final WebContents mWebContents; private final WebContents mWebContents;
private final Intent mPayIntent;
private final Set<String> mMethodNames; private final Set<String> mMethodNames;
private final boolean mIsIncognito; private final boolean mIsIncognito;
private Intent mIsReadyToPayIntent; private final String mPackageName;
private final String mPayActivityName;
private final String mIsReadyToPayServiceName;
private IsReadyToPayCallback mIsReadyToPayCallback; private IsReadyToPayCallback mIsReadyToPayCallback;
private InstrumentDetailsCallback mInstrumentDetailsCallback; private InstrumentDetailsCallback mInstrumentDetailsCallback;
private ServiceConnection mServiceConnection; private ServiceConnection mServiceConnection;
...@@ -94,14 +95,12 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten ...@@ -94,14 +95,12 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten
mHandler = new Handler(); mHandler = new Handler();
mWebContents = webContents; mWebContents = webContents;
mPayIntent = new Intent(); mPackageName = packageName;
mPayIntent.setClassName(packageName, activity); mPayActivityName = activity;
mPayIntent.setAction(WebPaymentIntentHelper.ACTION_PAY); mIsReadyToPayServiceName = isReadyToPayService;
if (isReadyToPayService != null) { if (mIsReadyToPayServiceName != null) {
assert !isIncognito; assert !isIncognito;
mIsReadyToPayIntent = new Intent();
mIsReadyToPayIntent.setClassName(packageName, isReadyToPayService);
} }
mMethodNames = new HashSet<>(); mMethodNames = new HashSet<>();
...@@ -133,7 +132,7 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten ...@@ -133,7 +132,7 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten
== null : "Have not responded to previous IS_READY_TO_PAY request"; == null : "Have not responded to previous IS_READY_TO_PAY request";
mIsReadyToPayCallback = callback; mIsReadyToPayCallback = callback;
if (mIsReadyToPayIntent == null) { if (mIsReadyToPayServiceName == null) {
respondToIsReadyToPayQuery(true); respondToIsReadyToPayQuery(true);
return; return;
} }
...@@ -164,11 +163,10 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten ...@@ -164,11 +163,10 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten
} }
}; };
mIsReadyToPayIntent.putExtras(WebPaymentIntentHelper.buildExtras(null /* id */, Intent isReadyToPayIntent = WebPaymentIntentHelper.createIsReadyToPayIntent(
null /* merchantName */, removeUrlScheme(origin), removeUrlScheme(iframeOrigin), /*packageName=*/mPackageName, /*serviceName=*/mIsReadyToPayServiceName,
certificateChain, removeUrlScheme(origin), removeUrlScheme(iframeOrigin), certificateChain,
WebPaymentIntentHelperTypeConverter.fromMojoPaymentMethodDataMap(methodDataMap), WebPaymentIntentHelperTypeConverter.fromMojoPaymentMethodDataMap(methodDataMap));
null /* total */, null /* displayItems */, null /* modifiers */));
if (mBypassIsReadyToPayServiceInTest) { if (mBypassIsReadyToPayServiceInTest) {
respondToIsReadyToPayQuery(true); respondToIsReadyToPayQuery(true);
...@@ -183,7 +181,7 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten ...@@ -183,7 +181,7 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten
// connection." // connection."
// https://developer.android.com/reference/android/content/Context.html#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int) // https://developer.android.com/reference/android/content/Context.html#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)
mIsServiceBindingInitiated = ContextUtils.getApplicationContext().bindService( mIsServiceBindingInitiated = ContextUtils.getApplicationContext().bindService(
mIsReadyToPayIntent, mServiceConnection, Context.BIND_AUTO_CREATE); isReadyToPayIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
} catch (SecurityException e) { } catch (SecurityException e) {
// Intentionally blank, so mIsServiceBindingInitiated is false. // Intentionally blank, so mIsServiceBindingInitiated is false.
} }
...@@ -315,14 +313,14 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten ...@@ -315,14 +313,14 @@ public class AndroidPaymentApp extends PaymentApp implements WindowAndroid.Inten
return; return;
} }
mPayIntent.putExtras(WebPaymentIntentHelper.buildExtras(id, merchantName, origin, Intent payIntent = WebPaymentIntentHelper.createPayIntent(mPackageName, mPayActivityName,
iframeOrigin, certificateChain, id, merchantName, origin, iframeOrigin, certificateChain,
WebPaymentIntentHelperTypeConverter.fromMojoPaymentMethodDataMap(methodDataMap), WebPaymentIntentHelperTypeConverter.fromMojoPaymentMethodDataMap(methodDataMap),
WebPaymentIntentHelperTypeConverter.fromMojoPaymentItem(total), WebPaymentIntentHelperTypeConverter.fromMojoPaymentItem(total),
WebPaymentIntentHelperTypeConverter.fromMojoPaymentItems(displayItems), WebPaymentIntentHelperTypeConverter.fromMojoPaymentItems(displayItems),
WebPaymentIntentHelperTypeConverter.fromMojoPaymentDetailsModifierMap(modifiers))); WebPaymentIntentHelperTypeConverter.fromMojoPaymentDetailsModifierMap(modifiers));
try { try {
if (!window.showIntent(mPayIntent, this, R.string.payments_android_app_error)) { if (!window.showIntent(payIntent, this, R.string.payments_android_app_error)) {
notifyErrorInvokingPaymentApp(ErrorStrings.PAYMENT_APP_LAUNCH_FAIL); notifyErrorInvokingPaymentApp(ErrorStrings.PAYMENT_APP_LAUNCH_FAIL);
} }
} catch (SecurityException e) { } catch (SecurityException e) {
......
...@@ -110,8 +110,10 @@ public class WebPaymentIntentHelper { ...@@ -110,8 +110,10 @@ public class WebPaymentIntentHelper {
} }
/** /**
* Build the 'extra' property for an intent. * Create an intent to invoke a native payment app.
* *
* @param packageName The name of the package of the payment app.
* @param activityName The name of the payment activity in the payment app.
* @param id The unique identifier of the PaymentRequest. * @param id The unique identifier of the PaymentRequest.
* @param merchantName The name of the merchant. * @param merchantName The name of the merchant.
* @param schemelessOrigin The schemeless origin of this merchant * @param schemelessOrigin The schemeless origin of this merchant
...@@ -124,9 +126,48 @@ public class WebPaymentIntentHelper { ...@@ -124,9 +126,48 @@ public class WebPaymentIntentHelper {
* @param total The total amount. * @param total The total amount.
* @param displayItems The shopping cart items. * @param displayItems The shopping cart items.
* @param modifiers The relevant payment details modifiers. * @param modifiers The relevant payment details modifiers.
* @return the 'extra' property built for the intent. * @return The intent to invoke the payment app.
*/ */
public static Bundle buildExtras(@Nullable String id, @Nullable String merchantName, public static Intent createPayIntent(String packageName, String activityName, String id,
String merchantName, String schemelessOrigin, String schemelessIframeOrigin,
byte[][] certificateChain, Map<String, PaymentMethodData> methodDataMap,
PaymentItem total, List<PaymentItem> displayItems,
Map<String, PaymentDetailsModifier> modifiers) {
Intent payIntent = new Intent();
payIntent.setClassName(packageName, activityName);
payIntent.setAction(ACTION_PAY);
payIntent.putExtras(buildExtras(id, merchantName, schemelessOrigin, schemelessIframeOrigin,
certificateChain, methodDataMap, total, displayItems, modifiers));
return payIntent;
}
/**
* Create an intent to invoke a service that can answer "is ready to pay" query, or null of
* none.
*
* @param packageName The name of the package of the payment app.
* @param serviceName The name of the service.
* @param schemelessOrigin The schemeless origin of this merchant
* @param schemelessIframeOrigin The schemeless origin of the iframe that invoked PaymentRequest
* @param certificateChain The site certificate chain of the merchant. Can be null for localhost
* or local file, which are secure contexts without SSL.
* @param methodDataMap The payment-method specific data for all applicable payment methods,
* e.g., whether the app should be invoked in test or production, a
* merchant identifier, or a public key.
* @return The intent to invoke the service.
*/
public static Intent createIsReadyToPayIntent(String packageName, String serviceName,
String schemelessOrigin, String schemelessIframeOrigin, byte[][] certificateChain,
Map<String, PaymentMethodData> methodDataMap) {
Intent isReadyToPayIntent = new Intent();
isReadyToPayIntent.setClassName(packageName, serviceName);
isReadyToPayIntent.putExtras(buildExtras(/*id=*/null,
/*merchantName=*/null, schemelessOrigin, schemelessIframeOrigin, certificateChain,
methodDataMap, /*total=*/null, /*displayItems=*/null, /*modifiers=*/null));
return isReadyToPayIntent;
}
private static Bundle buildExtras(@Nullable String id, @Nullable String merchantName,
String schemelessOrigin, String schemelessIframeOrigin, String schemelessOrigin, String schemelessIframeOrigin,
@Nullable byte[][] certificateChain, Map<String, PaymentMethodData> methodDataMap, @Nullable byte[][] certificateChain, Map<String, PaymentMethodData> methodDataMap,
@Nullable PaymentItem total, @Nullable List<PaymentItem> displayItems, @Nullable PaymentItem total, @Nullable List<PaymentItem> displayItems,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment