Chromium Code Reviews| 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 8c920f4ac903726efc7e359c2b440323be725240..7b51af8f95ef1dc4b099623d1674c50eee1506d1 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 |
| @@ -30,6 +30,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; |
| @@ -41,8 +42,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; |
| @@ -70,7 +70,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| private Bitmap mFavicon; |
| private List<PaymentApp> mApps; |
| private PaymentRequestClient mClient; |
| - private Set<String> mSupportedMethods; |
| /** |
| * The raw total amount being charged, as it was received from the website. This data is passed |
| @@ -103,7 +102,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| */ |
| private SectionInformation mUiShippingOptions; |
| - private JSONObject mData; |
| + private HashMap<String, JSONObject> mMethodData; |
| private SectionInformation mShippingAddressesSection; |
| private List<PaymentApp> mPendingApps; |
| private List<PaymentInstrument> mPendingInstruments; |
| @@ -175,18 +174,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; |
| } |
| @@ -197,12 +196,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| boolean requestShipping = options != null && options.requestShipping; |
| mMerchantNeedsShippingAddress = requestShipping && mUiShippingOptions.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().getProfilesToSuggest(); |
| for (int i = 0; i < profiles.size(); i++) { |
| @@ -231,7 +224,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 { |
| @@ -249,17 +242,32 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| mFavicon = null; |
| } |
| - 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 = null; |
| + if (!TextUtils.isEmpty(methodData[i].data)) { |
| + try { |
| + data = new JSONObject(methodData[i].data); |
| + } catch (JSONException e) { |
| + // Payment method specific data should be a JSON object. |
|
please use gerrit instead
2016/06/09 02:44:13
Looks like your rebase has removed that very usefu
|
| + return null; |
| + } |
| + } |
| - 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]); |
| - } |
| + String[] methods = methodData[i].supportedMethods; |
| + |
| + // 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; |
| } |
| @@ -461,29 +469,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. |
| */ |
| @@ -574,7 +559,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
| assert selectedPaymentMethod instanceof PaymentInstrument; |
| PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod; |
| instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems, |
| - mData.optJSONObject(instrument.getMethodName()), this); |
| + mMethodData.get(instrument.getMethodName()), this); |
| } |
| @Override |
| @@ -633,7 +618,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(); |