Commit 0d50eba3 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PRImpl] Move OnSectionOptionSelected into PaymentUIsManager

Since OnSectionOptionSelected is PaymentRequest UI logic, move it into
PaymentUIsManager.

Bug: 1102522, 1114791

Change-Id: I8268493c6d65ec14aa89444b461910d58c5af4bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2402119
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805890}
parent ebc55b75
...@@ -24,10 +24,8 @@ import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; ...@@ -24,10 +24,8 @@ import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate; import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator; import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerWebContentsObserver; import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerWebContentsObserver;
import org.chromium.chrome.browser.payments.ui.ContactDetailsSection;
import org.chromium.chrome.browser.payments.ui.PaymentInformation; import org.chromium.chrome.browser.payments.ui.PaymentInformation;
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI; import org.chromium.chrome.browser.payments.ui.PaymentRequestUI;
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.SelectionResult;
import org.chromium.chrome.browser.payments.ui.PaymentUIsManager; import org.chromium.chrome.browser.payments.ui.PaymentUIsManager;
import org.chromium.chrome.browser.payments.ui.SectionInformation; import org.chromium.chrome.browser.payments.ui.SectionInformation;
import org.chromium.chrome.browser.payments.ui.ShoppingCart; import org.chromium.chrome.browser.payments.ui.ShoppingCart;
...@@ -1020,74 +1018,8 @@ public class PaymentRequestImpl ...@@ -1020,74 +1018,8 @@ public class PaymentRequestImpl
@PaymentRequestUI.SelectionResult @PaymentRequestUI.SelectionResult
public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType, public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType,
EditableOption option, Callback<PaymentInformation> callback) { EditableOption option, Callback<PaymentInformation> callback) {
if (mComponentPaymentRequestImpl == null) return SelectionResult.NONE; return mPaymentUIsManager.onSectionOptionSelected(
if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) { optionType, option, callback, mWasRetryCalled);
// Log the change of shipping address.
mJourneyLogger.incrementSelectionChanges(Section.SHIPPING_ADDRESS);
AutofillAddress address = (AutofillAddress) option;
if (address.isComplete()) {
mPaymentUIsManager.getShippingAddressesSection().setSelectedItem(option);
startShippingAddressChangeNormalization(address);
} else {
// Log the edit of a shipping address.
mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
mPaymentUIsManager.editAddress(address);
}
mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.SHIPPING_OPTIONS) {
// This may update the line items.
mPaymentUIsManager.getUiShippingOptions().setSelectedItem(option);
mComponentPaymentRequestImpl.onShippingOptionChange(option.getIdentifier());
mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.CONTACT_DETAILS) {
// Log the change of contact info.
mJourneyLogger.incrementSelectionChanges(Section.CONTACT_INFO);
AutofillContact contact = (AutofillContact) option;
if (contact.isComplete()) {
mPaymentUIsManager.getContactSection().setSelectedItem(option);
if (!mWasRetryCalled) return PaymentRequestUI.SelectionResult.NONE;
dispatchPayerDetailChangeEventIfNeeded(contact.toPayerDetail());
} else {
mJourneyLogger.incrementSelectionEdits(Section.CONTACT_INFO);
mPaymentUIsManager.editContactOnPaymentRequestUI(contact);
if (!mWasRetryCalled) return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
}
mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.PAYMENT_METHODS) {
if (shouldShowShippingSection()
&& mPaymentUIsManager.getShippingAddressesSection() == null) {
ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents);
assert activity != null;
mPaymentUIsManager.createShippingSectionForPaymentRequestUI(activity);
}
if (shouldShowContactSection() && mPaymentUIsManager.getContactSection() == null) {
ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents);
assert activity != null;
mPaymentUIsManager.setContactSection(new ContactDetailsSection(activity,
mPaymentUIsManager.getAutofillProfiles(),
mPaymentUIsManager.getContactEditor(), mJourneyLogger));
}
mPaymentUIsManager.onSelectedPaymentMethodUpdated();
PaymentApp paymentApp = (PaymentApp) option;
if (paymentApp instanceof AutofillPaymentInstrument) {
AutofillPaymentInstrument card = (AutofillPaymentInstrument) paymentApp;
if (!card.isComplete()) {
mPaymentUIsManager.editCard(card);
return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
}
}
// Log the change of payment method.
mJourneyLogger.incrementSelectionChanges(Section.PAYMENT_METHOD);
mPaymentUIsManager.updateOrderSummary(paymentApp);
mPaymentUIsManager.getPaymentMethodsSection().setSelectedItem(option);
}
return PaymentRequestUI.SelectionResult.NONE;
} }
@Override @Override
...@@ -2007,6 +1939,13 @@ public class PaymentRequestImpl ...@@ -2007,6 +1939,13 @@ public class PaymentRequestImpl
mComponentPaymentRequestImpl.warnNoFavicon(); mComponentPaymentRequestImpl.warnNoFavicon();
} }
// Implement PaymentUIsObserver:
@Override
public void onShippingOptionChange(String optionId) {
if (mComponentPaymentRequestImpl == null) return;
mComponentPaymentRequestImpl.onShippingOptionChange(optionId);
}
// Implement PaymentUIsObserver.onLeavingCurrentTab: // Implement PaymentUIsObserver.onLeavingCurrentTab:
@Override @Override
public void onLeavingCurrentTab(String reason) { public void onLeavingCurrentTab(String reason) {
......
...@@ -1495,4 +1495,82 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -1495,4 +1495,82 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
mOverviewModeBehavior = null; mOverviewModeBehavior = null;
} }
} }
/**
* The implementation of {@link PaymentRequestUI.Client#onSectionOptionSelected}.
* @param optionType Data being updated.
* @param option Value of the data being updated.
* @param callback The callback after an asynchronous check has completed.
* @param wasRetryCalled Whether {@link PaymentRequestImpl#retry} has been called.
* @return The result of the selection.
*/
@PaymentRequestUI.SelectionResult
public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType,
EditableOption option, Callback<PaymentInformation> callback, boolean wasRetryCalled) {
if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) {
// Log the change of shipping address.
mJourneyLogger.incrementSelectionChanges(Section.SHIPPING_ADDRESS);
AutofillAddress address = (AutofillAddress) option;
if (address.isComplete()) {
mShippingAddressesSection.setSelectedItem(option);
mDelegate.startShippingAddressChangeNormalization(address);
} else {
// Log the edit of a shipping address.
mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
editAddress(address);
}
mPaymentInformationCallback = callback;
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.SHIPPING_OPTIONS) {
// This may update the line items.
mUiShippingOptions.setSelectedItem(option);
mObserver.onShippingOptionChange(option.getIdentifier());
mPaymentInformationCallback = callback;
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.CONTACT_DETAILS) {
// Log the change of contact info.
mJourneyLogger.incrementSelectionChanges(Section.CONTACT_INFO);
AutofillContact contact = (AutofillContact) option;
if (contact.isComplete()) {
mContactSection.setSelectedItem(option);
if (!wasRetryCalled) return PaymentRequestUI.SelectionResult.NONE;
mDelegate.dispatchPayerDetailChangeEventIfNeeded(contact.toPayerDetail());
} else {
mJourneyLogger.incrementSelectionEdits(Section.CONTACT_INFO);
editContactOnPaymentRequestUI(contact);
if (!wasRetryCalled) return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
}
mPaymentInformationCallback = callback;
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.PAYMENT_METHODS) {
if (shouldShowShippingSection() && mShippingAddressesSection == null) {
ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents);
assert activity != null;
createShippingSectionForPaymentRequestUI(activity);
}
if (shouldShowContactSection() && mContactSection == null) {
ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents);
assert activity != null;
mContactSection = new ContactDetailsSection(
activity, mAutofillProfiles, mContactEditor, mJourneyLogger);
}
onSelectedPaymentMethodUpdated();
PaymentApp paymentApp = (PaymentApp) option;
if (paymentApp instanceof AutofillPaymentInstrument) {
AutofillPaymentInstrument card = (AutofillPaymentInstrument) paymentApp;
if (!card.isComplete()) {
editCard(card);
return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
}
}
// Log the change of payment method.
mJourneyLogger.incrementSelectionChanges(Section.PAYMENT_METHOD);
updateOrderSummary(paymentApp);
mPaymentMethodsSection.setSelectedItem(option);
}
return PaymentRequestUI.SelectionResult.NONE;
}
} }
...@@ -16,4 +16,10 @@ public interface PaymentUIsObserver { ...@@ -16,4 +16,10 @@ public interface PaymentUIsObserver {
* developers. * developers.
*/ */
void onLeavingCurrentTab(String reason); void onLeavingCurrentTab(String reason);
/**
* Called when the user's selected shipping option has changed.
* @param optionId The option id of the selected shipping option.
*/
void onShippingOptionChange(String optionId);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment