Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java

Issue 2341203002: Android payment apps. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
index ae353c0e2cf68353cfe9a94a62c9b88d6fb5662c..8cb143db298e388a7a8d70c77820005e390cebdf 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
@@ -67,7 +67,8 @@ import java.util.Set;
* third_party/WebKit/public/platform/modules/payments/payment_request.mojom.
*/
public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Client,
- PaymentApp.InstrumentsCallback, PaymentInstrument.DetailsCallback {
+ PaymentAppFactory.PaymentAppsCallback, PaymentApp.InstrumentsCallback,
+ PaymentInstrument.InstrumentDetailsCallback {
/**
* Observer to be notified when PaymentRequest UI has been dismissed.
*/
@@ -135,10 +136,10 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
private final Handler mHandler = new Handler();
private final ChromeActivity mContext;
+ private final WebContents mWebContents;
private final PaymentRequestDismissObserver mDismissObserver;
private final String mMerchantName;
private final String mOrigin;
- private final List<PaymentApp> mApps;
private final AddressEditor mAddressEditor;
private final CardEditor mCardEditor;
@@ -198,21 +199,23 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
public PaymentRequestImpl(Activity context, WebContents webContents,
PaymentRequestDismissObserver dismissObserver) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: new PaymentRequestImpl.");
assert context != null;
assert webContents != null;
assert dismissObserver != null;
assert context instanceof ChromeActivity;
mContext = (ChromeActivity) context;
+ mWebContents = webContents;
mDismissObserver = dismissObserver;
- mMerchantName = webContents.getTitle();
+ mMerchantName = mWebContents.getTitle();
// The feature is available only in secure context, so it's OK to not show HTTPS.
- mOrigin = UrlFormatter.formatUrlForSecurityDisplay(webContents.getVisibleUrl(), false);
+ mOrigin = UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getVisibleUrl(), false);
final FaviconHelper faviconHelper = new FaviconHelper();
faviconHelper.getLocalFaviconImageForURL(Profile.getLastUsedProfile(),
- webContents.getVisibleUrl(),
+ mWebContents.getVisibleUrl(),
mContext.getResources().getDimensionPixelSize(R.dimen.payments_favicon_size),
new FaviconHelper.FaviconImageCallback() {
@Override
@@ -227,10 +230,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
});
- mApps = PaymentAppFactory.create(webContents);
-
mAddressEditor = new AddressEditor();
- mCardEditor = new CardEditor(webContents, mAddressEditor, sObserverForTest);
+ mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForTest);
recordSuccessFunnelHistograms("Initiated");
}
@@ -241,6 +242,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
@Override
public void init(PaymentRequestClient client, PaymentMethodData[] methodData,
PaymentDetails details, PaymentOptions options) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: init.");
if (mClient != null || client == null) return;
mClient = client;
@@ -261,7 +263,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;
- getMatchingPaymentInstruments();
+ PaymentAppFactory.create(mContext, mWebContents, mMethodData.keySet(), this);
boolean requestShipping = options != null && options.requestShipping;
boolean requestPayerPhone = options != null && options.requestPayerPhone;
@@ -367,6 +369,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void show() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: show.");
if (mClient == null || mIsShowing) return;
mIsShowing = true;
@@ -383,6 +386,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
private static Map<String, JSONObject> getValidatedMethodData(
PaymentMethodData[] methodData, CardEditor paymentMethodsCollector) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: getValidatedMethodData.");
// Payment methodData are required.
if (methodData == null || methodData.length == 0) return null;
Map<String, JSONObject> result = new HashMap<>();
@@ -418,40 +422,64 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
return result;
}
- /** Queries the installed payment apps for their instruments that merchant supports. */
- private void getMatchingPaymentInstruments() {
- mPendingApps = new ArrayList<>(mApps);
+ /**
+ * Called when installed payment apps have been determined. Queries the installed payment apps
+ * for their instruments that merchant supports.
+ */
+ @Override
+ public void onPaymentAppsReady(List<PaymentApp> apps) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onPaymentAppsReady.");
+ mPendingApps = new ArrayList<>(apps);
mPendingInstruments = new ArrayList<>();
mPendingAutofillInstruments = new ArrayList<>();
- Map<PaymentApp, JSONObject> queryApps = new HashMap<>();
- for (int i = 0; i < mApps.size(); i++) {
- PaymentApp app = mApps.get(i);
- Set<String> appMethods = app.getSupportedMethodNames();
- appMethods.retainAll(mMethodData.keySet());
- if (appMethods.isEmpty()) {
+ Map<PaymentApp, Map<String, JSONObject>> queryApps = new HashMap<>();
+ for (int i = 0; i < apps.size(); i++) {
+ PaymentApp app = apps.get(i);
+ android.util.Log.e("chromium", "PaymentRequestImpl: payment app '" + app.getAppIdentifier() + "'");
+ Map<String, JSONObject> appMethods =
+ filterMerchantMethodData(mMethodData, app.getAppMethodNames());
+ if (appMethods == null) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: No app methods match!");
mPendingApps.remove(app);
} else {
+ android.util.Log.e("chromium", "PaymentRequestImpl: Have some app method matches.");
mArePaymentMethodsSupported = true;
mMerchantSupportsAutofillPaymentInstruments |= app instanceof AutofillPaymentApp;
- queryApps.put(app, mMethodData.get(appMethods.iterator().next()));
+ queryApps.put(app, appMethods);
}
}
// Query instruments after mMerchantSupportsAutofillPaymentInstruments has been initialized,
// so a fast response from a non-autofill payment app at the front of the app list does not
// cause NOT_SUPPORTED payment rejection.
- for (Map.Entry<PaymentApp, JSONObject> q : queryApps.entrySet()) {
+ for (Map.Entry<PaymentApp, Map<String, JSONObject>> q : queryApps.entrySet()) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: Looking for instruments.");
q.getKey().getInstruments(q.getValue(), this);
}
}
+ /** Filter out merchnat method data that's not relevant to a payment app. Can return null. */
+ private static Map<String, JSONObject> filterMerchantMethodData(
+ Map<String, JSONObject> merchantMethodData, Set<String> appMethods) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: filterMerchantMethodData.");
+ Map<String, JSONObject> result = null;
+ for (String method : appMethods) {
+ if (merchantMethodData.containsKey(method)) {
+ if (result == null) result = new HashMap<>();
+ result.put(method, merchantMethodData.get(method));
+ }
+ }
+ return result;
+ }
+
/**
* Called by merchant to update the shipping options and line items after the user has selected
* their shipping address or shipping option.
*/
@Override
public void updateWith(PaymentDetails details) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: updateWith.");
if (mClient == null) return;
if (mUI == null) {
@@ -487,6 +515,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
* @return True if the data is valid. False if the data is invalid.
*/
private boolean parseAndValidateDetailsOrDisconnectFromClient(PaymentDetails details) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: parseAndValidateDetailsOrDisconnectFromClient.");
if (details == null) {
disconnectFromClientWithDebugMessage("Payment details required");
recordAbortReasonHistogram(
@@ -556,6 +585,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
* @return True if all fields are present and non-empty.
*/
private static boolean hasAllPaymentItemFields(PaymentItem item) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: hasAllPaymentItemFields.");
// "label", "currency", and "value" should be non-empty.
return item != null && !TextUtils.isEmpty(item.label) && item.amount != null
&& !TextUtils.isEmpty(item.amount.currency)
@@ -572,6 +602,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
private static List<LineItem> getValidatedLineItems(
PaymentItem[] items, String totalCurrency, CurrencyStringFormatter formatter) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: getValidatedLineItems.");
// Line items are optional.
if (items == null) return new ArrayList<>();
@@ -604,6 +635,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
private static SectionInformation getValidatedShippingOptions(PaymentShippingOption[] options,
String totalCurrency, CurrencyStringFormatter formatter) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: getValidatedShippingOptions.");
// Shipping options are optional.
if (options == null || options.length == 0) {
return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS);
@@ -629,7 +661,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
for (int i = 0; i < options.length; i++) {
PaymentShippingOption option = options[i];
result.add(new PaymentOption(option.id, option.label,
- formatter.format(option.amount.value), PaymentOption.NO_ICON));
+ formatter.format(option.amount.value), null));
if (option.selected) selectedItemIndex = i;
}
@@ -642,6 +674,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void getDefaultPaymentInformation(Callback<PaymentInformation> callback) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: getDefaultPaymentInformation.");
mPaymentInformationCallback = callback;
if (mPaymentMethodsSection == null) return;
@@ -655,6 +688,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
private void providePaymentInformation() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: providePaymentInformation.");
mPaymentInformationCallback.onResult(
new PaymentInformation(mUiShoppingCart, mShippingAddressesSection,
mUiShippingOptions, mContactSection, mPaymentMethodsSection));
@@ -663,6 +697,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
@Override
public void getShoppingCart(final Callback<ShoppingCart> callback) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: getShoppingCart.");
mHandler.post(new Runnable() {
@Override
public void run() {
@@ -674,6 +709,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
@Override
public void getSectionInformation(@PaymentRequestUI.DataType final int optionType,
final Callback<SectionInformation> callback) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: getSectionInformation.");
mHandler.post(new Runnable() {
@Override
public void run() {
@@ -695,6 +731,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
@PaymentRequestUI.SelectionResult public int onSectionOptionSelected(
@PaymentRequestUI.DataType int optionType, PaymentOption option,
Callback<PaymentInformation> callback) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onSectionOptionSelected.");
if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
assert option instanceof AutofillAddress;
AutofillAddress address = (AutofillAddress) option;
@@ -743,6 +780,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
@Override
@PaymentRequestUI.SelectionResult public int onSectionAddOption(
@PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onSectionAddOption.");
if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
editAddress(null);
mPaymentInformationCallback = callback;
@@ -759,6 +797,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
private void editAddress(final AutofillAddress toEdit) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: editAddress.");
mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() {
@Override
public void onResult(AutofillAddress completeAddress) {
@@ -777,6 +816,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
private void editContact(final AutofillContact toEdit) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: editContact.");
mContactEditor.edit(toEdit, new Callback<AutofillContact>() {
@Override
public void onResult(AutofillContact completeContact) {
@@ -794,6 +834,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
private void editCard(final AutofillPaymentInstrument toEdit) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: editCard.");
mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() {
@Override
public void onResult(AutofillPaymentInstrument completeCard) {
@@ -813,27 +854,31 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
@Override
public boolean onPayClicked(PaymentOption selectedShippingAddress,
PaymentOption selectedShippingOption, PaymentOption selectedPaymentMethod) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onPayClicked.");
assert selectedPaymentMethod instanceof PaymentInstrument;
PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
mPaymentAppRunning = true;
- instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
- mMethodData.get(instrument.getMethodName()), this);
+ instrument.getInstrumentDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
+ mMethodData.get(instrument.getInstrumentMethodName()), this);
recordSuccessFunnelHistograms("PayClicked");
return !(instrument instanceof AutofillPaymentInstrument);
}
@Override
public void onDismiss() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onDismiss.");
disconnectFromClientWithDebugMessage("Dialog dismissed");
closeUI(true);
recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER);
}
private void disconnectFromClientWithDebugMessage(String debugMessage) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: disconnectFromClientWithDebugMessage.");
disconnectFromClientWithDebugMessage(debugMessage, PaymentErrorReason.USER_CANCEL);
}
private void disconnectFromClientWithDebugMessage(String debugMessage, int reason) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: disconnectFromClientWithDebugMessage.");
Log.d(TAG, debugMessage);
if (mClient != null) mClient.onError(reason);
closeClient();
@@ -845,6 +890,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void abort() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: abort.");
if (mClient == null) return;
mClient.onAbort(!mPaymentAppRunning);
if (mPaymentAppRunning) {
@@ -861,6 +907,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void complete(int result) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: complete.");
if (mClient == null) return;
recordSuccessFunnelHistograms("Completed");
closeUI(PaymentComplete.FAIL != result);
@@ -871,6 +918,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void close() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: close.");
if (mClient == null) return;
closeClient();
closeUI(true);
@@ -882,6 +930,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void onConnectionError(MojoException e) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onConnectionError.");
if (mClient == null) return;
closeClient();
closeUI(true);
@@ -893,6 +942,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instruments) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onInstrumentsReady.");
if (mClient == null) return;
mPendingApps.remove(app);
@@ -901,10 +951,10 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
if (instruments != null) {
for (int i = 0; i < instruments.size(); i++) {
PaymentInstrument instrument = instruments.get(i);
- if (mMethodData.containsKey(instrument.getMethodName())) {
+ if (mMethodData.containsKey(instrument.getInstrumentMethodName())) {
addPendingInstrument(instrument);
} else {
- instrument.dismiss();
+ instrument.dismissInstrument();
}
}
}
@@ -950,6 +1000,14 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
* @return True if no payment methods are supported
*/
private boolean disconnectIfNoPaymentMethodsSupported() {
+ android.util.Log.e("chromium",
+ String.format(
+ "PaymentRequestImpl: disconnectIfNoPaymentMethodsSupported: mPendingApps %s= null, mPendingInstruments %s= null, mPaymentMethodsSection %s= null",
+ mPendingApps == null ? "=" : "!", mPendingInstruments == null ? "=" : "!",
+ mPaymentMethodsSection == null ? "=" : "!"));
+ // Waiting for payment app factory to respond.
+ if (mPendingApps == null || mPendingInstruments == null) return false;
+
boolean waitingForPaymentApps = !mPendingApps.isEmpty() || !mPendingInstruments.isEmpty();
boolean foundPaymentMethods =
mPaymentMethodsSection != null && !mPaymentMethodsSection.isEmpty();
@@ -983,6 +1041,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
* @param instrument The instrument to add to either "autofill" or "non-autofill" list.
*/
private void addPendingInstrument(PaymentInstrument instrument) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: addPendingInstrument.");
if (instrument instanceof AutofillPaymentInstrument) {
AutofillPaymentInstrument autofillInstrument = (AutofillPaymentInstrument) instrument;
if (mCardEditor.isCardComplete(autofillInstrument.getCard())) {
@@ -999,6 +1058,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void onInstrumentDetailsReady(String methodName, String stringifiedDetails) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onInstrumentDetailsReady.");
PaymentResponse response = new PaymentResponse();
response.methodName = methodName;
response.stringifiedDetails = stringifiedDetails;
@@ -1065,6 +1125,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void onInstrumentDetailsError() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: onInstrumentDetailsError.");
mUI.onPayButtonProcessingCancelled();
mPaymentAppRunning = false;
}
@@ -1081,6 +1142,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
* always pass "true."
*/
private void closeUI(boolean immediateClose) {
+ android.util.Log.e("chromium", "PaymentRequestImpl: closeUI.");
if (mUI != null) {
mUI.close(immediateClose, new Runnable() {
@Override
@@ -1096,7 +1158,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
PaymentOption option = mPaymentMethodsSection.getItem(i);
assert option instanceof PaymentInstrument;
- ((PaymentInstrument) option).dismiss();
+ ((PaymentInstrument) option).dismissInstrument();
}
mPaymentMethodsSection = null;
}
@@ -1106,6 +1168,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
private void closeClient() {
+ android.util.Log.e("chromium", "PaymentRequestImpl: closeClient.");
if (mClient != null) mClient.close();
mClient = null;
mDismissObserver.onPaymentRequestDismissed();

Powered by Google App Engine
This is Rietveld 408576698