| 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 2c643c1e5f7a18b9e6c3d3377a7ba9845aa5f963..727e6a06f9da12c4aa367b26198fcbdc2fb738fa 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
|
| @@ -171,7 +171,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
|
|
| /**
|
| * In-memory mapping of the origins of websites that have recently called canMakePayment()
|
| - * to the list of the payment methods that were been queried. Used for throttling the usage of
|
| + * to the list of the payment methods that were being queried. Used for throttling the usage of
|
| * this call. The mapping is shared among all instances of PaymentRequestImpl in the browser
|
| * process on UI thread. The user can reset the throttling mechanism by restarting the browser.
|
| */
|
| @@ -247,6 +247,12 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| /** True if any of the requested payment methods are supported. */
|
| private boolean mArePaymentMethodsSupported;
|
|
|
| + /**
|
| + * True after at least one usable payment instrument has been found. Should be read only after
|
| + * all payment apps have been queried.
|
| + */
|
| + private boolean mCanMakePayment;
|
| +
|
| /** The helper to create and fill the response to send to the merchant. */
|
| private PaymentResponseHelper mPaymentResponseHelper;
|
|
|
| @@ -1006,10 +1012,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| }
|
|
|
| query.addObserver(this);
|
| - if (mPendingApps.isEmpty() && mPendingInstruments.isEmpty()) {
|
| - query.setResponse(mPaymentMethodsSection != null
|
| - && mPaymentMethodsSection.getSelectedItem() != null);
|
| - }
|
| + if (isFinishedQueryingPaymentApps()) query.setResponse(mCanMakePayment);
|
| }
|
|
|
| private void respondCanMakePaymentQuery(boolean response) {
|
| @@ -1070,18 +1073,22 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| if (disconnectIfNoPaymentMethodsSupported()) return;
|
|
|
| // Load the validation rules for each unique region code in the credit card billing
|
| - // addresses.
|
| + // addresses and check for validity.
|
| Set<String> uniqueCountryCodes = new HashSet<>();
|
| for (int i = 0; i < mPendingAutofillInstruments.size(); ++i) {
|
| assert mPendingAutofillInstruments.get(i) instanceof AutofillPaymentInstrument;
|
| + AutofillPaymentInstrument creditCard =
|
| + (AutofillPaymentInstrument) mPendingAutofillInstruments.get(i);
|
|
|
| - String countryCode = AutofillAddress.getCountryCode((
|
| - (AutofillPaymentInstrument) mPendingAutofillInstruments.get(
|
| - i)).getBillingAddress());
|
| + String countryCode = AutofillAddress.getCountryCode(creditCard.getBillingAddress());
|
| if (!uniqueCountryCodes.contains(countryCode)) {
|
| uniqueCountryCodes.add(countryCode);
|
| PersonalDataManager.getInstance().loadRulesForRegion(countryCode);
|
| }
|
| +
|
| + // If there's a card on file with a valid number and a name, then
|
| + // PaymentRequest.canMakePayment() returns true.
|
| + mCanMakePayment |= creditCard.isValid();
|
| }
|
|
|
| // List order:
|
| @@ -1097,18 +1104,22 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
|
|
| mPendingAutofillInstruments.clear();
|
|
|
| - // Pre-select the first instrument on the list, if it is complete.
|
| + // Possibly pre-select the first instrument on the list.
|
| int selection = SectionInformation.NO_SELECTION;
|
| if (!mPendingInstruments.isEmpty()) {
|
| PaymentInstrument first = mPendingInstruments.get(0);
|
| - if (!(first instanceof AutofillPaymentInstrument)
|
| - || ((AutofillPaymentInstrument) first).isComplete()) {
|
| + if (first instanceof AutofillPaymentInstrument) {
|
| + AutofillPaymentInstrument creditCard = (AutofillPaymentInstrument) first;
|
| + if (creditCard.isComplete()) selection = 0;
|
| + } else {
|
| + // If a payment app is available, then PaymentRequest.canMakePayment() returns true.
|
| + mCanMakePayment = true;
|
| selection = 0;
|
| }
|
| }
|
|
|
| CanMakePaymentQuery query = sCanMakePaymentQueries.get(mOrigin);
|
| - if (query != null) query.setResponse(selection == 0);
|
| + if (query != null) query.setResponse(mCanMakePayment);
|
|
|
| // The list of payment instruments is ready to display.
|
| mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.TYPE_PAYMENT_METHODS,
|
| @@ -1126,7 +1137,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| * @return True if no payment methods are supported
|
| */
|
| private boolean disconnectIfNoPaymentMethodsSupported() {
|
| - boolean waitingForPaymentApps = !mPendingApps.isEmpty() || !mPendingInstruments.isEmpty();
|
| + boolean waitingForPaymentApps = !isFinishedQueryingPaymentApps();
|
| boolean foundPaymentMethods =
|
| mPaymentMethodsSection != null && !mPaymentMethodsSection.isEmpty();
|
| boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstruments
|
| @@ -1150,6 +1161,11 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| return false;
|
| }
|
|
|
| + /** @return True after payment apps have been queried. */
|
| + private boolean isFinishedQueryingPaymentApps() {
|
| + return mPendingApps != null && mPendingApps.isEmpty() && mPendingInstruments.isEmpty();
|
| + }
|
| +
|
| /**
|
| * Saves the given instrument in either "autofill" or "non-autofill" list. The separation
|
| * enables placing autofill instruments on the bottom of the list.
|
|
|