| 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 a2d212bceba2642dc35a93eaf39ff84713984c6d..d88735aa420a9864bbc49967e427576a33ad6d1e 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
|
| @@ -29,6 +29,7 @@ import org.chromium.content_public.browser.WebContents;
|
| import org.chromium.mojo.system.MojoException;
|
| import org.chromium.mojom.payments.PaymentDetails;
|
| import org.chromium.mojom.payments.PaymentItem;
|
| +import org.chromium.mojom.payments.PaymentMethodData;
|
| import org.chromium.mojom.payments.PaymentOptions;
|
| import org.chromium.mojom.payments.PaymentRequest;
|
| import org.chromium.mojom.payments.PaymentRequestClient;
|
| @@ -40,8 +41,7 @@ import org.json.JSONObject;
|
|
|
| import java.util.ArrayList;
|
| import java.util.Arrays;
|
| -import java.util.HashSet;
|
| -import java.util.Iterator;
|
| +import java.util.HashMap;
|
| import java.util.List;
|
| import java.util.Locale;
|
| import java.util.Set;
|
| @@ -68,12 +68,11 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| private Bitmap mFavicon;
|
| private List<PaymentApp> mApps;
|
| private PaymentRequestClient mClient;
|
| - private Set<String> mSupportedMethods;
|
| + private HashMap<String, JSONObject> mMethodData;
|
| private List<LineItem> mLineItems;
|
| private List<PaymentItem> mPaymentItems;
|
| private List<ShippingOption> mShippingOptions;
|
| private SectionInformation mShippingOptionsSection;
|
| - private JSONObject mData;
|
| private SectionInformation mShippingAddressesSection;
|
| private List<PaymentApp> mPendingApps;
|
| private List<PaymentInstrument> mPendingInstruments;
|
| @@ -145,18 +144,18 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| * Called by the merchant website to show the payment request to the user.
|
| */
|
| @Override
|
| - public void show(String[] supportedMethods, PaymentDetails details, PaymentOptions options,
|
| - String stringifiedData) {
|
| + public void show(PaymentMethodData[] methodData, PaymentDetails details,
|
| + PaymentOptions options) {
|
| if (mClient == null) return;
|
|
|
| - if (mSupportedMethods != null) {
|
| + if (mMethodData != null) {
|
| disconnectFromClientWithDebugMessage("PaymentRequest.show() called more than once.");
|
| return;
|
| }
|
|
|
| - mSupportedMethods = getValidatedSupportedMethods(supportedMethods);
|
| - if (mSupportedMethods == null) {
|
| - disconnectFromClientWithDebugMessage("Invalid payment methods");
|
| + mMethodData = getValidatedMethodData(methodData);
|
| + if (mMethodData == null) {
|
| + disconnectFromClientWithDebugMessage("Invalid payment methods or data");
|
| return;
|
| }
|
|
|
| @@ -167,12 +166,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| boolean requestShipping = options != null && options.requestShipping;
|
| mMerchantNeedsShippingAddress = requestShipping && mShippingOptionsSection.isEmpty();
|
|
|
| - mData = getValidatedData(mSupportedMethods, stringifiedData);
|
| - if (mData == null) {
|
| - disconnectFromClientWithDebugMessage("Invalid payment method specific data");
|
| - return;
|
| - }
|
| -
|
| List<AutofillAddress> addresses = new ArrayList<>();
|
| List<AutofillProfile> profiles = PersonalDataManager.getInstance().getAddressOnlyProfiles();
|
| for (int i = 0; i < profiles.size(); i++) {
|
| @@ -201,7 +194,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| for (int i = 0; i < mApps.size(); i++) {
|
| PaymentApp app = mApps.get(i);
|
| Set<String> appMethods = app.getSupportedMethodNames();
|
| - appMethods.retainAll(mSupportedMethods);
|
| + appMethods.retainAll(mMethodData.keySet());
|
| if (appMethods.isEmpty()) {
|
| mPendingApps.remove(app);
|
| } else {
|
| @@ -265,15 +258,33 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| return true;
|
| }
|
|
|
| - private HashSet<String> getValidatedSupportedMethods(String[] methods) {
|
| - // Payment methods are required.
|
| - if (methods == null || methods.length == 0) return null;
|
| + private HashMap<String, JSONObject> getValidatedMethodData(PaymentMethodData[] methodData) {
|
| + // Payment methodData are required.
|
| + if (methodData == null || methodData.length == 0) return null;
|
| + HashMap<String, JSONObject> result = new HashMap<>();
|
| + for (int i = 0; i < methodData.length; i++) {
|
| + JSONObject data;
|
| + if (TextUtils.isEmpty(methodData[i].data)) {
|
| + data = null;
|
| + } else {
|
| + try {
|
| + data = new JSONObject(methodData[i].data);
|
| + } catch (JSONException e) {
|
| + // Payment method specific data should be a JSON object.
|
| + return null;
|
| + }
|
| + }
|
| +
|
| + String[] methods = methodData[i].supportedMethods;
|
|
|
| - HashSet<String> result = new HashSet<>();
|
| - for (int i = 0; i < methods.length; i++) {
|
| - // Payment methods should be non-empty.
|
| - if (TextUtils.isEmpty(methods[i])) return null;
|
| - result.add(methods[i]);
|
| + // Payment methods are required.
|
| + if (methods == null || methods.length == 0) return null;
|
| +
|
| + for (int j = 0; j < methods.length; j++) {
|
| + // Payment methods should be non-empty.
|
| + if (TextUtils.isEmpty(methods[j])) return null;
|
| + result.put(methods[j], data);
|
| + }
|
| }
|
|
|
| return result;
|
| @@ -371,29 +382,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| result.size() == 1 ? 0 : SectionInformation.NO_SELECTION, result);
|
| }
|
|
|
| - private JSONObject getValidatedData(Set<String> supportedMethods, String stringifiedData) {
|
| - if (TextUtils.isEmpty(stringifiedData)) return new JSONObject();
|
| -
|
| - JSONObject result;
|
| - try {
|
| - result = new JSONObject(stringifiedData);
|
| - } catch (JSONException e) {
|
| - // Payment method specific data should be a JSON object.
|
| - return null;
|
| - }
|
| -
|
| - Iterator<String> it = result.keys();
|
| - while (it.hasNext()) {
|
| - String name = it.next();
|
| - // Each key should be one of the supported payment methods.
|
| - if (!supportedMethods.contains(name)) return null;
|
| - // Each value should be a JSON object.
|
| - if (result.optJSONObject(name) == null) return null;
|
| - }
|
| -
|
| - return result;
|
| - }
|
| -
|
| /**
|
| * Called to retrieve the data to show in the initial PaymentRequest UI.
|
| */
|
| @@ -485,7 +473,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| assert selectedPaymentMethod instanceof PaymentInstrument;
|
| PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
|
| instrument.getDetails(mMerchantName, mOrigin, mPaymentItems,
|
| - mData.optJSONObject(instrument.getMethodName()), this);
|
| + mMethodData.get(instrument.getMethodName()), this);
|
| }
|
|
|
| @Override
|
| @@ -539,7 +527,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| if (instruments != null) {
|
| for (int i = 0; i < instruments.size(); i++) {
|
| PaymentInstrument instrument = instruments.get(i);
|
| - if (mSupportedMethods.contains(instrument.getMethodName())) {
|
| + if (mMethodData.containsKey(instrument.getMethodName())) {
|
| mPendingInstruments.add(instrument);
|
| } else {
|
| instrument.dismiss();
|
|
|