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 360ab4ad67ee38eef702f31cb2ffa1f82a82e97e..873d552c67cbf5faaac6e67e83ad3672e23b9252 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 |
@@ -21,8 +21,6 @@ import org.chromium.chrome.browser.payments.ui.PaymentOption; |
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI; |
import org.chromium.chrome.browser.payments.ui.SectionInformation; |
import org.chromium.chrome.browser.payments.ui.ShoppingCart; |
-import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
-import org.chromium.chrome.browser.preferences.autofill.AutofillLocalCardEditor; |
import org.chromium.chrome.browser.profiles.Profile; |
import org.chromium.chrome.browser.util.UrlUtilities; |
import org.chromium.components.safejson.JsonSanitizer; |
@@ -66,6 +64,12 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
* Called when an abort request was denied. |
*/ |
void onPaymentRequestServiceUnableToAbort(); |
+ |
+ /** |
+ * Called when the controller is notified of billing address change, but does not alter the |
+ * editor UI. |
+ */ |
+ void onPaymentRequestServiceProcessBillingAddressChange(); |
gone
2016/07/13 21:13:00
Changed?
please use gerrit instead
2016/07/14 17:21:44
onPaymentRequestServiceBillingAddressChangeProcess
|
} |
/** |
@@ -121,6 +125,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
private SectionInformation mShippingAddressesSection; |
private SectionInformation mContactSection; |
private List<PaymentApp> mPendingApps; |
+ private int mFirstCompletePendingInstrument; |
private List<PaymentInstrument> mPendingInstruments; |
private SectionInformation mPaymentMethodsSection; |
private PaymentRequestUI mUI; |
@@ -128,6 +133,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
private boolean mMerchantNeedsShippingAddress; |
private boolean mPaymentAppRunning; |
private AddressEditor mAddressEditor; |
+ private CardEditor mCardEditor; |
private ContactEditor mContactEditor; |
/** |
@@ -169,6 +175,9 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
}); |
mApps = PaymentAppFactory.create(webContents); |
+ |
+ mAddressEditor = new AddressEditor(); |
+ mCardEditor = new CardEditor(webContents, mAddressEditor, sObserverForTest); |
} |
/** |
@@ -200,7 +209,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
return; |
} |
- mMethodData = getValidatedMethodData(methodData); |
+ mMethodData = getValidatedMethodData(methodData, mCardEditor); |
if (mMethodData == null) { |
disconnectFromClientWithDebugMessage("Invalid payment methods or data"); |
return; |
@@ -223,7 +232,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
} |
if (requestShipping) { |
- mAddressEditor = new AddressEditor(); |
List<AutofillAddress> addresses = new ArrayList<>(); |
int firstCompleteAddressIndex = SectionInformation.NO_SELECTION; |
@@ -284,6 +292,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
} |
mPendingApps = new ArrayList<>(mApps); |
+ mFirstCompletePendingInstrument = SectionInformation.NO_SELECTION; |
mPendingInstruments = new ArrayList<>(); |
boolean isGettingInstruments = false; |
@@ -309,12 +318,13 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
if (mFavicon != null) mUI.setTitleBitmap(mFavicon); |
mFavicon = null; |
- if (mAddressEditor != null) mAddressEditor.setEditorView(mUI.getEditorView()); |
+ mAddressEditor.setEditorView(mUI.getEditorView()); |
+ mCardEditor.setEditorView(mUI.getCardEditorView()); |
if (mContactEditor != null) mContactEditor.setEditorView(mUI.getEditorView()); |
} |
private static HashMap<String, JSONObject> getValidatedMethodData( |
- PaymentMethodData[] methodData) { |
+ PaymentMethodData[] methodData, CardEditor paymentMethodsCollector) { |
// Payment methodData are required. |
if (methodData == null || methodData.length == 0) return null; |
HashMap<String, JSONObject> result = new HashMap<>(); |
@@ -344,6 +354,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
if (TextUtils.isEmpty(methods[j])) return null; |
result.put(methods[j], data); |
} |
+ |
+ paymentMethodsCollector.addAcceptedPaymentMethodsIfRecognized(methods); |
} |
return result; |
} |
@@ -625,6 +637,15 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
} |
} else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { |
assert option instanceof PaymentInstrument; |
+ if (option instanceof AutofillPaymentInstrument) { |
+ AutofillPaymentInstrument card = (AutofillPaymentInstrument) option; |
+ |
+ if (!card.isComplete()) { |
+ editCard(card); |
+ return false; |
+ } |
+ } |
+ |
mPaymentMethodsSection.setSelectedItem(option); |
} |
@@ -644,8 +665,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
} else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) { |
editContact(null); |
} else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { |
- PreferencesLauncher.launchSettingsPage( |
- mContext, AutofillLocalCardEditor.class.getName()); |
+ editCard(null); |
} |
return false; |
@@ -691,6 +711,21 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
}); |
} |
+ private void editCard(final AutofillPaymentInstrument toEdit) { |
+ mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() { |
+ @Override |
+ public void onResult(AutofillPaymentInstrument completeCard) { |
+ if (completeCard == null) { |
+ mPaymentMethodsSection.setSelectedItemIndex(SectionInformation.NO_SELECTION); |
+ } else if (toEdit == null) { |
+ mPaymentMethodsSection.addAndSelectItem(completeCard); |
+ } |
+ |
+ mUI.updateSection(PaymentRequestUI.TYPE_PAYMENT_METHODS, mPaymentMethodsSection); |
+ } |
+ }); |
+ } |
+ |
@Override |
public void onPayClicked(PaymentOption selectedShippingAddress, |
PaymentOption selectedShippingOption, PaymentOption selectedPaymentMethod) { |
@@ -763,6 +798,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
for (int i = 0; i < instruments.size(); i++) { |
PaymentInstrument instrument = instruments.get(i); |
if (mMethodData.containsKey(instrument.getMethodName())) { |
+ checkForCompletePaymentInstrument(instrument, mPendingInstruments.size()); |
mPendingInstruments.add(instrument); |
} else { |
instrument.dismiss(); |
@@ -771,14 +807,27 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie |
} |
if (mPendingApps.isEmpty()) { |
- mPaymentMethodsSection = new SectionInformation( |
- PaymentRequestUI.TYPE_PAYMENT_METHODS, 0, mPendingInstruments); |
+ mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.TYPE_PAYMENT_METHODS, |
+ mFirstCompletePendingInstrument, mPendingInstruments); |
mPendingInstruments.clear(); |
if (mPaymentInformationCallback != null) providePaymentInformation(); |
} |
} |
+ private void checkForCompletePaymentInstrument(PaymentInstrument instrument, int index) { |
+ boolean isComplete = true; |
+ if (instrument instanceof AutofillPaymentInstrument) { |
+ AutofillPaymentInstrument autofillInstrument = (AutofillPaymentInstrument) instrument; |
+ isComplete = mCardEditor.isCardComplete(autofillInstrument.getCard()); |
+ if (isComplete) autofillInstrument.setIsComplete(); |
+ } |
+ |
+ if (isComplete && mFirstCompletePendingInstrument == SectionInformation.NO_SELECTION) { |
+ mFirstCompletePendingInstrument = index; |
+ } |
+ } |
+ |
/** |
* Called after retrieving instrument details. |
*/ |