Commit 8fe2301a authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PRImpl] Move EnableUserInterfaceAfterPaymentRequestUpdateEvent...

Change:
* Move EnableUserInterfaceAfterPaymentRequestUpdateEvent,
shouldShowShippingSection into PaymentUIsManager.

Bug: 1102522

Change-Id: Ie56768af521987c0a181db550720296f02bfe583
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317565
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792460}
parent c997b5e8
...@@ -134,7 +134,7 @@ public class PaymentRequestImpl ...@@ -134,7 +134,7 @@ public class PaymentRequestImpl
PaymentApp.InstrumentDetailsCallback, PaymentApp.InstrumentDetailsCallback,
PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver, PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver,
NormalizedAddressRequestDelegate, PaymentDetailsConverter.MethodChecker, NormalizedAddressRequestDelegate, PaymentDetailsConverter.MethodChecker,
PaymentHandlerUiObserver { PaymentHandlerUiObserver, PaymentUIsManager.Delegate {
/** /**
* A delegate to ask questions about the system, that allows tests to inject behaviour without * A delegate to ask questions about the system, that allows tests to inject behaviour without
* having to modify the entire system. This partially mirrors a similar C++ * having to modify the entire system. This partially mirrors a similar C++
...@@ -349,7 +349,6 @@ public class PaymentRequestImpl ...@@ -349,7 +349,6 @@ public class PaymentRequestImpl
private List<PaymentApp> mPendingApps = new ArrayList<>(); private List<PaymentApp> mPendingApps = new ArrayList<>();
private final PaymentUIsManager mPaymentUIsManager; private final PaymentUIsManager mPaymentUIsManager;
private MinimalUICoordinator mMinimalUi; private MinimalUICoordinator mMinimalUi;
private Callback<PaymentInformation> mPaymentInformationCallback;
private PaymentApp mInvokedPaymentApp; private PaymentApp mInvokedPaymentApp;
private PaymentHandlerCoordinator mPaymentHandlerUi; private PaymentHandlerCoordinator mPaymentHandlerUi;
private boolean mHideServerAutofillCards; private boolean mHideServerAutofillCards;
...@@ -468,7 +467,7 @@ public class PaymentRequestImpl ...@@ -468,7 +467,7 @@ public class PaymentRequestImpl
mSkipUiForNonUrlPaymentMethodIdentifiers = mDelegate.skipUiForBasicCard(); mSkipUiForNonUrlPaymentMethodIdentifiers = mDelegate.skipUiForBasicCard();
if (sObserverForTest != null) sObserverForTest.onPaymentRequestCreated(this); if (sObserverForTest != null) sObserverForTest.onPaymentRequestCreated(this);
mPaymentUIsManager = new PaymentUIsManager( mPaymentUIsManager = new PaymentUIsManager(/*delegate=*/this,
/*params=*/this, addressEditor, cardEditor); /*params=*/this, addressEditor, cardEditor);
mPaymentAppComparator = new PaymentAppComparator(/*params=*/this); mPaymentAppComparator = new PaymentAppComparator(/*params=*/this);
} }
...@@ -1324,7 +1323,7 @@ public class PaymentRequestImpl ...@@ -1324,7 +1323,7 @@ public class PaymentRequestImpl
mPaymentUIsManager.getShippingAddressesSection().setErrorMessage(details.error); mPaymentUIsManager.getShippingAddressesSection().setErrorMessage(details.error);
} }
enableUserInterfaceAfterPaymentRequestUpdateEvent(); mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent();
} }
private void initializeWithUpdatedDetails(PaymentDetails details) { private void initializeWithUpdatedDetails(PaymentDetails details) {
...@@ -1368,7 +1367,7 @@ public class PaymentRequestImpl ...@@ -1368,7 +1367,7 @@ public class PaymentRequestImpl
triggerPaymentAppUiSkipIfApplicable(chromeActivity); triggerPaymentAppUiSkipIfApplicable(chromeActivity);
if (mIsFinishedQueryingPaymentApps && !mShouldSkipShowingPaymentRequestUi) { if (mIsFinishedQueryingPaymentApps && !mShouldSkipShowingPaymentRequestUi) {
enableUserInterfaceAfterPaymentRequestUpdateEvent(); mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent();
} }
} }
...@@ -1392,22 +1391,7 @@ public class PaymentRequestImpl ...@@ -1392,22 +1391,7 @@ public class PaymentRequestImpl
return; return;
} }
enableUserInterfaceAfterPaymentRequestUpdateEvent(); mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent();
}
private void enableUserInterfaceAfterPaymentRequestUpdateEvent() {
if (mPaymentInformationCallback != null
&& mPaymentUIsManager.getPaymentMethodsSection() != null) {
providePaymentInformation();
} else {
mPaymentUIsManager.getPaymentRequestUI().updateOrderSummarySection(
mPaymentUIsManager.getUiShoppingCart());
if (shouldShowShippingSection()) {
mPaymentUIsManager.getPaymentRequestUI().updateSection(
PaymentRequestUI.DataType.SHIPPING_OPTIONS,
mPaymentUIsManager.getUiShippingOptions());
}
}
} }
/** /**
...@@ -1487,7 +1471,7 @@ public class PaymentRequestImpl ...@@ -1487,7 +1471,7 @@ public class PaymentRequestImpl
*/ */
@Override @Override
public void getDefaultPaymentInformation(Callback<PaymentInformation> callback) { public void getDefaultPaymentInformation(Callback<PaymentInformation> callback) {
mPaymentInformationCallback = callback; mPaymentUIsManager.setPaymentInformationCallback(callback);
// mPaymentUIsManager.getPaymentRequestUI().show() is called only after request.show() is // mPaymentUIsManager.getPaymentRequestUI().show() is called only after request.show() is
// called and all payment apps are ready. // called and all payment apps are ready.
...@@ -1501,19 +1485,21 @@ public class PaymentRequestImpl ...@@ -1501,19 +1485,21 @@ public class PaymentRequestImpl
}); });
} }
private void providePaymentInformation() { // Implement PaymentUIsManager.Delegate:
@Override
public void providePaymentInformation() {
// Do not display service worker payment apps summary in single line so as to display its // Do not display service worker payment apps summary in single line so as to display its
// origin completely. // origin completely.
mPaymentUIsManager.getPaymentMethodsSection() mPaymentUIsManager.getPaymentMethodsSection()
.setDisplaySelectedItemSummaryInSingleLineInNormalMode( .setDisplaySelectedItemSummaryInSingleLineInNormalMode(
mPaymentUIsManager.getSelectedPaymentAppType() mPaymentUIsManager.getSelectedPaymentAppType()
!= PaymentAppType.SERVICE_WORKER_APP); != PaymentAppType.SERVICE_WORKER_APP);
mPaymentInformationCallback.onResult(new PaymentInformation( mPaymentUIsManager.getPaymentInformationCallback().onResult(new PaymentInformation(
mPaymentUIsManager.getUiShoppingCart(), mPaymentUIsManager.getUiShoppingCart(),
mPaymentUIsManager.getShippingAddressesSection(), mPaymentUIsManager.getShippingAddressesSection(),
mPaymentUIsManager.getUiShippingOptions(), mPaymentUIsManager.getContactSection(), mPaymentUIsManager.getUiShippingOptions(), mPaymentUIsManager.getContactSection(),
mPaymentUIsManager.getPaymentMethodsSection())); mPaymentUIsManager.getPaymentMethodsSection()));
mPaymentInformationCallback = null; mPaymentUIsManager.setPaymentInformationCallback(null);
if (!mDidRecordShowEvent) { if (!mDidRecordShowEvent) {
mDidRecordShowEvent = true; mDidRecordShowEvent = true;
...@@ -1573,13 +1559,13 @@ public class PaymentRequestImpl ...@@ -1573,13 +1559,13 @@ public class PaymentRequestImpl
} else { } else {
editAddress(address); editAddress(address);
} }
mPaymentInformationCallback = callback; mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.SHIPPING_OPTIONS) { } else if (optionType == PaymentRequestUI.DataType.SHIPPING_OPTIONS) {
// This may update the line items. // This may update the line items.
mPaymentUIsManager.getUiShippingOptions().setSelectedItem(option); mPaymentUIsManager.getUiShippingOptions().setSelectedItem(option);
client.onShippingOptionChange(option.getIdentifier()); client.onShippingOptionChange(option.getIdentifier());
mPaymentInformationCallback = callback; mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.CONTACT_DETAILS) { } else if (optionType == PaymentRequestUI.DataType.CONTACT_DETAILS) {
// Log the change of contact info. // Log the change of contact info.
...@@ -1593,7 +1579,7 @@ public class PaymentRequestImpl ...@@ -1593,7 +1579,7 @@ public class PaymentRequestImpl
editContact(contact); editContact(contact);
if (!mWasRetryCalled) return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH; if (!mWasRetryCalled) return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
} }
mPaymentInformationCallback = callback; mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.PAYMENT_METHODS) { } else if (optionType == PaymentRequestUI.DataType.PAYMENT_METHODS) {
if (shouldShowShippingSection() if (shouldShowShippingSection()
...@@ -1634,7 +1620,7 @@ public class PaymentRequestImpl ...@@ -1634,7 +1620,7 @@ public class PaymentRequestImpl
Callback<PaymentInformation> callback) { Callback<PaymentInformation> callback) {
if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) { if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) {
editAddress((AutofillAddress) option); editAddress((AutofillAddress) option);
mPaymentInformationCallback = callback; mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} }
...@@ -1659,7 +1645,7 @@ public class PaymentRequestImpl ...@@ -1659,7 +1645,7 @@ public class PaymentRequestImpl
@PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) { @PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) {
if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) { if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) {
editAddress(null); editAddress(null);
mPaymentInformationCallback = callback; mPaymentUIsManager.setPaymentInformationCallback(callback);
// Log the add of shipping address. // Log the add of shipping address.
mJourneyLogger.incrementSelectionAdds(Section.SHIPPING_ADDRESS); mJourneyLogger.incrementSelectionAdds(Section.SHIPPING_ADDRESS);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
...@@ -1680,13 +1666,7 @@ public class PaymentRequestImpl ...@@ -1680,13 +1666,7 @@ public class PaymentRequestImpl
@Override @Override
public boolean shouldShowShippingSection() { public boolean shouldShowShippingSection() {
if (!mRequestShipping) return false; return mPaymentUIsManager.shouldShowShippingSection();
if (mPaymentUIsManager.getPaymentMethodsSection() == null) return true;
PaymentApp selectedApp =
(PaymentApp) mPaymentUIsManager.getPaymentMethodsSection().getSelectedItem();
return selectedApp == null || !selectedApp.handlesShippingAddress();
} }
@Override @Override
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.payments.ui; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.payments.ui;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.payments.AddressEditor; import org.chromium.chrome.browser.payments.AddressEditor;
import org.chromium.chrome.browser.payments.AutofillAddress; import org.chromium.chrome.browser.payments.AutofillAddress;
...@@ -19,6 +20,7 @@ import org.chromium.components.payments.CurrencyFormatter; ...@@ -19,6 +20,7 @@ import org.chromium.components.payments.CurrencyFormatter;
import org.chromium.components.payments.PaymentApp; import org.chromium.components.payments.PaymentApp;
import org.chromium.components.payments.PaymentAppType; import org.chromium.components.payments.PaymentAppType;
import org.chromium.components.payments.PaymentFeatureList; import org.chromium.components.payments.PaymentFeatureList;
import org.chromium.components.payments.PaymentOptionsUtils;
import org.chromium.components.payments.PaymentRequestLifecycleObserver; import org.chromium.components.payments.PaymentRequestLifecycleObserver;
import org.chromium.components.payments.PaymentRequestParams; import org.chromium.components.payments.PaymentRequestParams;
import org.chromium.payments.mojom.PaymentCurrencyAmount; import org.chromium.payments.mojom.PaymentCurrencyAmount;
...@@ -43,7 +45,9 @@ import java.util.Set; ...@@ -43,7 +45,9 @@ import java.util.Set;
*/ */
public class PaymentUIsManager public class PaymentUIsManager
implements SettingsAutofillAndPaymentsObserver.Observer, PaymentRequestLifecycleObserver { implements SettingsAutofillAndPaymentsObserver.Observer, PaymentRequestLifecycleObserver {
private Callback<PaymentInformation> mPaymentInformationCallback;
private SectionInformation mUiShippingOptions; private SectionInformation mUiShippingOptions;
private final Delegate mDelegate;
private final Map<String, CurrencyFormatter> mCurrencyFormatterMap; private final Map<String, CurrencyFormatter> mCurrencyFormatterMap;
private final AddressEditor mAddressEditor; private final AddressEditor mAddressEditor;
private final CardEditor mCardEditor; private final CardEditor mCardEditor;
...@@ -61,6 +65,12 @@ public class PaymentUIsManager ...@@ -61,6 +65,12 @@ public class PaymentUIsManager
private Boolean mCanUserAddCreditCard; private Boolean mCanUserAddCreditCard;
/** The delegate of this class. */
public interface Delegate {
/** Provide payment information to the Payment Request UI. */
void providePaymentInformation();
}
/** /**
* This class is to coordinate the show state of a bottom sheet UI (either expandable payment * This class is to coordinate the show state of a bottom sheet UI (either expandable payment
* handler or minimal UI) and the Payment Request UI so that these visibility rules are * handler or minimal UI) and the Payment Request UI so that these visibility rules are
...@@ -117,6 +127,7 @@ public class PaymentUIsManager ...@@ -117,6 +127,7 @@ public class PaymentUIsManager
/** /**
* Create PaymentUIsManager. * Create PaymentUIsManager.
* @param delegate The delegate of this instance.
* @param params The parameters of the payment request specified by the merchant. * @param params The parameters of the payment request specified by the merchant.
* @param addressEditor The AddressEditor of the PaymentRequest UI. * @param addressEditor The AddressEditor of the PaymentRequest UI.
* @param cardEditor The CardEditor of the PaymentRequest UI. * @param cardEditor The CardEditor of the PaymentRequest UI.
...@@ -124,8 +135,9 @@ public class PaymentUIsManager ...@@ -124,8 +135,9 @@ public class PaymentUIsManager
// TODO(crbug.com/1107102): AddressEditor and CardEditor should be initialized in this // TODO(crbug.com/1107102): AddressEditor and CardEditor should be initialized in this
// constructor instead of the caller of the constructor, once CardEditor's "ForTest" symbols // constructor instead of the caller of the constructor, once CardEditor's "ForTest" symbols
// have been removed from the production code. // have been removed from the production code.
public PaymentUIsManager( public PaymentUIsManager(Delegate delegate, PaymentRequestParams params,
PaymentRequestParams params, AddressEditor addressEditor, CardEditor cardEditor) { AddressEditor addressEditor, CardEditor cardEditor) {
mDelegate = delegate;
mParams = params; mParams = params;
mAddressEditor = addressEditor; mAddressEditor = addressEditor;
mCardEditor = cardEditor; mCardEditor = cardEditor;
...@@ -244,6 +256,20 @@ public class PaymentUIsManager ...@@ -244,6 +256,20 @@ public class PaymentUIsManager
mUiShippingOptions = uiShippingOptions; mUiShippingOptions = uiShippingOptions;
} }
/** Get the PaymentInformation callback. */
public Callback<PaymentInformation> getPaymentInformationCallback() {
return mPaymentInformationCallback;
}
/**
* Set the call back of PaymentInformation. This callback would be invoked when the payment
* information is retrieved.
*/
public void setPaymentInformationCallback(
Callback<PaymentInformation> paymentInformationCallback) {
mPaymentInformationCallback = paymentInformationCallback;
}
// Implement SettingsAutofillAndPaymentsObserver.Observer: // Implement SettingsAutofillAndPaymentsObserver.Observer:
@Override @Override
public void onAddressUpdated(AutofillAddress address) { public void onAddressUpdated(AutofillAddress address) {
...@@ -515,4 +541,31 @@ public class PaymentUIsManager ...@@ -515,4 +541,31 @@ public class PaymentUIsManager
new PaymentInformation(mUiShoppingCart, mShippingAddressesSection, new PaymentInformation(mUiShoppingCart, mShippingAddressesSection,
mUiShippingOptions, mContactSection, mPaymentMethodsSection)); mUiShippingOptions, mContactSection, mPaymentMethodsSection));
} }
/**
* Update Payment Request UI with the update event's information and enable the UI (The user
* interface is disabled with a "↻" spinner being displayed and the user is unable to interact
* with the user interface until this "enableUserInterface" method is called).
*/
public void enableUserInterfaceAfterPaymentRequestUpdateEvent() {
if (mPaymentInformationCallback != null && mPaymentMethodsSection != null) {
mDelegate.providePaymentInformation();
} else {
mPaymentRequestUI.updateOrderSummarySection(mUiShoppingCart);
if (shouldShowShippingSection()) {
mPaymentRequestUI.updateSection(
PaymentRequestUI.DataType.SHIPPING_OPTIONS, mUiShippingOptions);
}
}
}
/** @return Whether PaymentRequest UI should show the shipping section. */
public boolean shouldShowShippingSection() {
if (!PaymentOptionsUtils.requestShipping(mParams.getPaymentOptions())) return false;
if (mPaymentMethodsSection == null) return true;
PaymentApp selectedApp = (PaymentApp) mPaymentMethodsSection.getSelectedItem();
return selectedApp == null || !selectedApp.handlesShippingAddress();
}
} }
...@@ -42,4 +42,13 @@ public class PaymentOptionsUtils { ...@@ -42,4 +42,13 @@ public class PaymentOptionsUtils {
return String.format("{payerEmail:%s,payerName:%s,payerPhone:%s,shipping:%s}", return String.format("{payerEmail:%s,payerName:%s,payerPhone:%s,shipping:%s}",
requestPayerEmail, requestPayerName, requestPayerPhone, requestShipping); requestPayerEmail, requestPayerName, requestPayerPhone, requestShipping);
} }
/**
* @param paymentOptions The PaymentOptions of the payment request.
* @return Whether requestShipping is specified in the payment request.
*/
public static boolean requestShipping(
org.chromium.payments.mojom.PaymentOptions paymentOptions) {
return paymentOptions != null && paymentOptions.requestShipping;
}
} }
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