| 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 874c38d4f8946903a03f4231eb9b0f36a7168db6..b5347db3b17ad419b9db2af9da2fc3d04442955d 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
|
| @@ -174,7 +174,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
|
|
| private Map<String, JSONObject> mMethodData;
|
| private SectionInformation mShippingAddressesSection;
|
| - private SectionInformation mContactSection;
|
| + private SectionInformation mPayerInfoSection;
|
| private List<PaymentApp> mPendingApps;
|
| private List<PaymentInstrument> mPendingInstruments;
|
| private List<PaymentInstrument> mPendingAutofillInstruments;
|
| @@ -183,7 +183,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| private Callback<PaymentInformation> mPaymentInformationCallback;
|
| private boolean mPaymentAppRunning;
|
| private boolean mMerchantSupportsAutofillPaymentInstruments;
|
| - private ContactEditor mContactEditor;
|
| + private PayerInfoEditor mPayerInfoEditor;
|
| private boolean mHasRecordedAbortReason;
|
|
|
| /** True if any of the requested payment methods are supported. */
|
| @@ -270,11 +270,12 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| getMatchingPaymentInstruments();
|
|
|
| boolean requestShipping = options != null && options.requestShipping;
|
| + boolean requestPayerName = options != null && options.requestPayerName;
|
| boolean requestPayerPhone = options != null && options.requestPayerPhone;
|
| boolean requestPayerEmail = options != null && options.requestPayerEmail;
|
|
|
| List<AutofillProfile> profiles = null;
|
| - if (requestShipping || requestPayerPhone || requestPayerEmail) {
|
| + if (requestShipping || requestPayerName || requestPayerPhone || requestPayerEmail) {
|
| profiles = PersonalDataManager.getInstance().getProfilesToSuggest(
|
| false /* includeName */);
|
| }
|
| @@ -319,60 +320,65 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| firstCompleteAddressIndex, addresses);
|
| }
|
|
|
| - if (requestPayerPhone || requestPayerEmail) {
|
| - Set<String> uniqueContactInfos = new HashSet<>();
|
| - mContactEditor = new ContactEditor(requestPayerPhone, requestPayerEmail);
|
| - List<AutofillContact> contacts = new ArrayList<>();
|
| + if (requestPayerName || requestPayerPhone || requestPayerEmail) {
|
| + Set<String> uniquePayerInfos = new HashSet<>();
|
| + mPayerInfoEditor =
|
| + new PayerInfoEditor(requestPayerName, requestPayerPhone, requestPayerEmail);
|
| + List<AutofillPayerInfo> payerInfos = new ArrayList<>();
|
|
|
| for (int i = 0; i < profiles.size(); i++) {
|
| AutofillProfile profile = profiles.get(i);
|
| + String name = requestPayerName && !TextUtils.isEmpty(profile.getFullName())
|
| + ? profile.getFullName() : null;
|
| String phone = requestPayerPhone && !TextUtils.isEmpty(profile.getPhoneNumber())
|
| ? profile.getPhoneNumber() : null;
|
| String email = requestPayerEmail && !TextUtils.isEmpty(profile.getEmailAddress())
|
| ? profile.getEmailAddress() : null;
|
| - mContactEditor.addPhoneNumberIfValid(phone);
|
| - mContactEditor.addEmailAddressIfValid(email);
|
| + mPayerInfoEditor.addPayerNameIfValid(name);
|
| + mPayerInfoEditor.addPhoneNumberIfValid(phone);
|
| + mPayerInfoEditor.addEmailAddressIfValid(email);
|
|
|
| - if (phone != null || email != null) {
|
| - // Different profiles can have identical contact info. Do not add the same
|
| - // contact info to the list twice.
|
| - String uniqueContactInfo = phone + email;
|
| - if (!uniqueContactInfos.contains(uniqueContactInfo)) {
|
| - uniqueContactInfos.add(uniqueContactInfo);
|
| + if (name != null || phone != null || email != null) {
|
| + // Different profiles can have identical payer info. Do not add the same
|
| + // payer info to the list twice.
|
| + String uniquePayerInfo = name + phone + email;
|
| + if (!uniquePayerInfos.contains(uniquePayerInfo)) {
|
| + uniquePayerInfos.add(uniquePayerInfo);
|
|
|
| boolean isComplete =
|
| - mContactEditor.isContactInformationComplete(phone, email);
|
| - contacts.add(new AutofillContact(profile, phone, email, isComplete));
|
| + mPayerInfoEditor.isPayerInformationComplete(name, phone, email);
|
| + payerInfos.add(
|
| + new AutofillPayerInfo(profile, name, phone, email, isComplete));
|
| }
|
| }
|
| }
|
|
|
| - // Suggest complete contact infos first.
|
| - Collections.sort(contacts, COMPLETENESS_COMPARATOR);
|
| + // Suggest complete payer infos first.
|
| + Collections.sort(payerInfos, COMPLETENESS_COMPARATOR);
|
|
|
| // Limit the number of suggestions.
|
| - contacts = contacts.subList(0, Math.min(contacts.size(), SUGGESTIONS_LIMIT));
|
| + payerInfos = payerInfos.subList(0, Math.min(payerInfos.size(), SUGGESTIONS_LIMIT));
|
|
|
| // Automatically select the first address if it is complete.
|
| - int firstCompleteContactIndex = SectionInformation.NO_SELECTION;
|
| - if (!contacts.isEmpty() && contacts.get(0).isComplete()) {
|
| - firstCompleteContactIndex = 0;
|
| + int firstCompletePayerInfoIndex = SectionInformation.NO_SELECTION;
|
| + if (!payerInfos.isEmpty() && payerInfos.get(0).isComplete()) {
|
| + firstCompletePayerInfoIndex = 0;
|
| }
|
|
|
| - mContactSection = new SectionInformation(
|
| - PaymentRequestUI.TYPE_CONTACT_DETAILS, firstCompleteContactIndex, contacts);
|
| + mPayerInfoSection = new SectionInformation(
|
| + PaymentRequestUI.TYPE_CONTACT_DETAILS, firstCompletePayerInfoIndex, payerInfos);
|
| }
|
|
|
| mUI = new PaymentRequestUI(mContext, this, requestShipping,
|
| - requestPayerPhone || requestPayerEmail, mMerchantSupportsAutofillPaymentInstruments,
|
| - mMerchantName, mOrigin);
|
| + requestPayerName || requestPayerPhone || requestPayerEmail,
|
| + mMerchantSupportsAutofillPaymentInstruments, mMerchantName, mOrigin);
|
|
|
| if (mFavicon != null) mUI.setTitleBitmap(mFavicon);
|
| mFavicon = null;
|
|
|
| mAddressEditor.setEditorView(mUI.getEditorView());
|
| mCardEditor.setEditorView(mUI.getCardEditorView());
|
| - if (mContactEditor != null) mContactEditor.setEditorView(mUI.getEditorView());
|
| + if (mPayerInfoEditor != null) mPayerInfoEditor.setEditorView(mUI.getEditorView());
|
|
|
| PaymentRequestMetrics.recordRequestedInformationHistogram(requestPayerEmail,
|
| requestPayerPhone, requestShipping);
|
| @@ -673,7 +679,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| private void providePaymentInformation() {
|
| mPaymentInformationCallback.onResult(
|
| new PaymentInformation(mUiShoppingCart, mShippingAddressesSection,
|
| - mUiShippingOptions, mContactSection, mPaymentMethodsSection));
|
| + mUiShippingOptions, mPayerInfoSection, mPaymentMethodsSection));
|
| mPaymentInformationCallback = null;
|
| }
|
|
|
| @@ -698,7 +704,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
|
| callback.onResult(mUiShippingOptions);
|
| } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
|
| - callback.onResult(mContactSection);
|
| + callback.onResult(mPayerInfoSection);
|
| } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
|
| assert mPaymentMethodsSection != null;
|
| callback.onResult(mPaymentMethodsSection);
|
| @@ -730,13 +736,13 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| mPaymentInformationCallback = callback;
|
| return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
|
| } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
|
| - assert option instanceof AutofillContact;
|
| - AutofillContact contact = (AutofillContact) option;
|
| + assert option instanceof AutofillPayerInfo;
|
| + AutofillPayerInfo payerInfo = (AutofillPayerInfo) option;
|
|
|
| - if (contact.isComplete()) {
|
| - mContactSection.setSelectedItem(option);
|
| + if (payerInfo.isComplete()) {
|
| + mPayerInfoSection.setSelectedItem(option);
|
| } else {
|
| - editContact(contact);
|
| + editPayerInfo(payerInfo);
|
| return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
|
| }
|
| } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
|
| @@ -764,7 +770,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| mPaymentInformationCallback = callback;
|
| return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
|
| } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
|
| - editContact(null);
|
| + editPayerInfo(null);
|
| return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
|
| } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
|
| editCard(null);
|
| @@ -792,19 +798,19 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| });
|
| }
|
|
|
| - private void editContact(final AutofillContact toEdit) {
|
| - mContactEditor.edit(toEdit, new Callback<AutofillContact>() {
|
| + private void editPayerInfo(final AutofillPayerInfo toEdit) {
|
| + mPayerInfoEditor.edit(toEdit, new Callback<AutofillPayerInfo>() {
|
| @Override
|
| - public void onResult(AutofillContact completeContact) {
|
| + public void onResult(AutofillPayerInfo completePayerInfo) {
|
| if (mUI == null) return;
|
|
|
| - if (completeContact == null) {
|
| - mContactSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
|
| + if (completePayerInfo == null) {
|
| + mPayerInfoSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
|
| } else if (toEdit == null) {
|
| - mContactSection.addAndSelectItem(completeContact);
|
| + mPayerInfoSection.addAndSelectItem(completePayerInfo);
|
| }
|
|
|
| - mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mContactSection);
|
| + mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mPayerInfoSection);
|
| }
|
| });
|
| }
|
| @@ -1021,13 +1027,15 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
|
| response.methodName = methodName;
|
| response.stringifiedDetails = stringifiedDetails;
|
|
|
| - if (mContactSection != null) {
|
| - PaymentOption selectedContact = mContactSection.getSelectedItem();
|
| - if (selectedContact != null) {
|
| - // Contacts are created in show(). These should all be instances of AutofillContact.
|
| - assert selectedContact instanceof AutofillContact;
|
| - response.payerPhone = ((AutofillContact) selectedContact).getPayerPhone();
|
| - response.payerEmail = ((AutofillContact) selectedContact).getPayerEmail();
|
| + if (mPayerInfoSection != null) {
|
| + PaymentOption selectedPayerInfo = mPayerInfoSection.getSelectedItem();
|
| + if (selectedPayerInfo != null) {
|
| + // Payer informations are created in show(). These should all be instances of
|
| + // AutofillPayerInfo.
|
| + assert selectedPayerInfo instanceof AutofillPayerInfo;
|
| + response.payerName = ((AutofillPayerInfo) selectedPayerInfo).getPayerName();
|
| + response.payerPhone = ((AutofillPayerInfo) selectedPayerInfo).getPayerPhone();
|
| + response.payerEmail = ((AutofillPayerInfo) selectedPayerInfo).getPayerEmail();
|
| }
|
| }
|
|
|
|
|