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

[PRImpl] Move PaymentHandlerUI

Change:
* Move mPaymentHandlerUI from PRImpl to PaymentUIsManager.

Bug: 1102522

Change-Id: I7f74893ad5e92f2ea6d97636fab9e1cfe38c2e23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317605
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792767}
parent 34a3fd44
...@@ -27,7 +27,6 @@ import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver; ...@@ -27,7 +27,6 @@ import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator; import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerUiObserver;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerWebContentsObserver; import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerWebContentsObserver;
import org.chromium.chrome.browser.payments.minimal.MinimalUICoordinator; import org.chromium.chrome.browser.payments.minimal.MinimalUICoordinator;
import org.chromium.chrome.browser.payments.ui.ContactDetailsSection; import org.chromium.chrome.browser.payments.ui.ContactDetailsSection;
...@@ -134,7 +133,7 @@ public class PaymentRequestImpl ...@@ -134,7 +133,7 @@ public class PaymentRequestImpl
PaymentApp.InstrumentDetailsCallback, PaymentApp.InstrumentDetailsCallback,
PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver, PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver,
NormalizedAddressRequestDelegate, PaymentDetailsConverter.MethodChecker, NormalizedAddressRequestDelegate, PaymentDetailsConverter.MethodChecker,
PaymentHandlerUiObserver, PaymentUIsManager.Delegate { 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++
...@@ -350,7 +349,6 @@ public class PaymentRequestImpl ...@@ -350,7 +349,6 @@ public class PaymentRequestImpl
private final PaymentUIsManager mPaymentUIsManager; private final PaymentUIsManager mPaymentUIsManager;
private MinimalUICoordinator mMinimalUi; private MinimalUICoordinator mMinimalUi;
private PaymentApp mInvokedPaymentApp; private PaymentApp mInvokedPaymentApp;
private PaymentHandlerCoordinator mPaymentHandlerUi;
private boolean mHideServerAutofillCards; private boolean mHideServerAutofillCards;
private ContactEditor mContactEditor; private ContactEditor mContactEditor;
private boolean mHasRecordedAbortReason; private boolean mHasRecordedAbortReason;
...@@ -1153,8 +1151,7 @@ public class PaymentRequestImpl ...@@ -1153,8 +1151,7 @@ public class PaymentRequestImpl
@VisibleForTesting(otherwise = VisibleForTesting.NONE) @VisibleForTesting(otherwise = VisibleForTesting.NONE)
private WebContents getPaymentHandlerWebContentsForTestInternal() { private WebContents getPaymentHandlerWebContentsForTestInternal() {
if (mPaymentHandlerUi == null) return null; return mPaymentUIsManager.getPaymentHandlerWebContentsForTest();
return mPaymentHandlerUi.getWebContentsForTest();
} }
/** /**
...@@ -1171,9 +1168,7 @@ public class PaymentRequestImpl ...@@ -1171,9 +1168,7 @@ public class PaymentRequestImpl
@VisibleForTesting(otherwise = VisibleForTesting.NONE) @VisibleForTesting(otherwise = VisibleForTesting.NONE)
private boolean clickPaymentHandlerSecurityIconForTestInternal() { private boolean clickPaymentHandlerSecurityIconForTestInternal() {
if (mPaymentHandlerUi == null) return false; return mPaymentUIsManager.clickPaymentHandlerSecurityIconForTest();
mPaymentHandlerUi.clickSecurityIconForTest();
return true;
} }
/** /**
...@@ -1238,13 +1233,8 @@ public class PaymentRequestImpl ...@@ -1238,13 +1233,8 @@ public class PaymentRequestImpl
assert mInvokedPaymentApp != null; assert mInvokedPaymentApp != null;
assert mInvokedPaymentApp.getPaymentAppType() == PaymentAppType.SERVICE_WORKER_APP; assert mInvokedPaymentApp.getPaymentAppType() == PaymentAppType.SERVICE_WORKER_APP;
if (mPaymentHandlerUi != null) return false; boolean success = mPaymentUIsManager.showPaymentHandlerUI(
mPaymentHandlerUi = new PaymentHandlerCoordinator(); mWebContents, url, paymentHandlerWebContentsObserver, mIsOffTheRecord);
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (chromeActivity == null) return false;
boolean success = mPaymentHandlerUi.show(chromeActivity, url, mIsOffTheRecord,
paymentHandlerWebContentsObserver, /*uiObserver=*/this);
if (success) { if (success) {
// UKM for payment app origin should get recorded only when the origin of the invoked // UKM for payment app origin should get recorded only when the origin of the invoked
// payment app is shown to the user. // payment app is shown to the user.
...@@ -1253,18 +1243,6 @@ public class PaymentRequestImpl ...@@ -1253,18 +1243,6 @@ public class PaymentRequestImpl
return success; return success;
} }
@Override
public void onPaymentHandlerUiClosed() {
mPaymentUIsManager.getPaymentUisShowStateReconciler().onBottomSheetClosed();
mPaymentHandlerUi = null;
}
@Override
public void onPaymentHandlerUiShown() {
assert mPaymentHandlerUi != null;
mPaymentUIsManager.getPaymentUisShowStateReconciler().onBottomSheetShown();
}
@Override @Override
public boolean isInvokedInstrumentValidForPaymentMethodIdentifier(String methodName) { public boolean isInvokedInstrumentValidForPaymentMethodIdentifier(String methodName) {
return mInvokedPaymentApp != null return mInvokedPaymentApp != null
...@@ -2674,19 +2652,13 @@ public class PaymentRequestImpl ...@@ -2674,19 +2652,13 @@ public class PaymentRequestImpl
PersonalDataManager.getInstance().normalizeAddress(address.getProfile(), this); PersonalDataManager.getInstance().normalizeAddress(address.getProfile(), this);
} }
private void ensureHideAndResetPaymentHandlerUi() {
if (mPaymentHandlerUi == null) return;
mPaymentHandlerUi.hide();
mPaymentHandlerUi = null;
}
/** /**
* Closes the UI and destroys native objects. If the client is still connected, then it's * Closes the UI and destroys native objects. If the client is still connected, then it's
* notified of UI hiding. This PaymentRequestImpl object can't be reused after this function is * notified of UI hiding. This PaymentRequestImpl object can't be reused after this function is
* called. * called.
*/ */
private void closeUIAndDestroyNativeObjects() { private void closeUIAndDestroyNativeObjects() {
ensureHideAndResetPaymentHandlerUi(); mPaymentUIsManager.ensureHideAndResetPaymentHandlerUi();
if (mMinimalUi != null) { if (mMinimalUi != null) {
mMinimalUi.hide(); mMinimalUi.hide();
mMinimalUi = null; mMinimalUi = null;
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
package org.chromium.chrome.browser.payments.ui; package org.chromium.chrome.browser.payments.ui;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.browser.ChromeActivity;
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;
...@@ -15,6 +17,9 @@ import org.chromium.chrome.browser.payments.AutofillPaymentAppFactory; ...@@ -15,6 +17,9 @@ import org.chromium.chrome.browser.payments.AutofillPaymentAppFactory;
import org.chromium.chrome.browser.payments.CardEditor; import org.chromium.chrome.browser.payments.CardEditor;
import org.chromium.chrome.browser.payments.PaymentRequestImpl; import org.chromium.chrome.browser.payments.PaymentRequestImpl;
import org.chromium.chrome.browser.payments.SettingsAutofillAndPaymentsObserver; import org.chromium.chrome.browser.payments.SettingsAutofillAndPaymentsObserver;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerUiObserver;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerWebContentsObserver;
import org.chromium.components.autofill.EditableOption; import org.chromium.components.autofill.EditableOption;
import org.chromium.components.payments.CurrencyFormatter; import org.chromium.components.payments.CurrencyFormatter;
import org.chromium.components.payments.PaymentApp; import org.chromium.components.payments.PaymentApp;
...@@ -23,11 +28,13 @@ import org.chromium.components.payments.PaymentFeatureList; ...@@ -23,11 +28,13 @@ import org.chromium.components.payments.PaymentFeatureList;
import org.chromium.components.payments.PaymentOptionsUtils; 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.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentCurrencyAmount; import org.chromium.payments.mojom.PaymentCurrencyAmount;
import org.chromium.payments.mojom.PaymentDetails; import org.chromium.payments.mojom.PaymentDetails;
import org.chromium.payments.mojom.PaymentDetailsModifier; import org.chromium.payments.mojom.PaymentDetailsModifier;
import org.chromium.payments.mojom.PaymentItem; import org.chromium.payments.mojom.PaymentItem;
import org.chromium.payments.mojom.PaymentShippingOption; import org.chromium.payments.mojom.PaymentShippingOption;
import org.chromium.url.GURL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -43,8 +50,10 @@ import java.util.Set; ...@@ -43,8 +50,10 @@ import java.util.Set;
* This class manages all of the UIs related to payment. The UI logic of {@link PaymentRequestImpl} * This class manages all of the UIs related to payment. The UI logic of {@link PaymentRequestImpl}
* should be moved into this class. * should be moved into this class.
*/ */
public class PaymentUIsManager public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Observer,
implements SettingsAutofillAndPaymentsObserver.Observer, PaymentRequestLifecycleObserver { PaymentRequestLifecycleObserver,
PaymentHandlerUiObserver {
private PaymentHandlerCoordinator mPaymentHandlerUi;
private Callback<PaymentInformation> mPaymentInformationCallback; private Callback<PaymentInformation> mPaymentInformationCallback;
private SectionInformation mUiShippingOptions; private SectionInformation mUiShippingOptions;
private final Delegate mDelegate; private final Delegate mDelegate;
...@@ -590,4 +599,59 @@ public class PaymentUIsManager ...@@ -590,4 +599,59 @@ public class PaymentUIsManager
return false; return false;
} }
// Implement PaymentHandlerUiObserver:
@Override
public void onPaymentHandlerUiClosed() {
mPaymentUisShowStateReconciler.onBottomSheetClosed();
mPaymentHandlerUi = null;
}
// Implement PaymentHandlerUiObserver:
@Override
public void onPaymentHandlerUiShown() {
assert mPaymentHandlerUi != null;
mPaymentUisShowStateReconciler.onBottomSheetShown();
}
/** Close the PaymentHandler UI if not already. */
public void ensureHideAndResetPaymentHandlerUi() {
if (mPaymentHandlerUi == null) return;
mPaymentHandlerUi.hide();
mPaymentHandlerUi = null;
}
/**
* Create and show the (BottomSheet) PaymentHandler UI.
* @param webContents The WebContents of the merchant page.
* @param url The URL of the payment app.
* @param paymentHandlerWebContentsObserver An observer of the WebContents of the Payment
* Handler UI.
* @param isOffTheRecord Whether the merchant page is currently in an OffTheRecord tab.
* @return Whether the PaymentHandler UI is shown successfully.
*/
public boolean showPaymentHandlerUI(WebContents webContents, GURL url,
PaymentHandlerWebContentsObserver paymentHandlerWebContentsObserver,
boolean isOffTheRecord) {
if (mPaymentHandlerUi != null) return false;
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(webContents);
if (chromeActivity == null) return false;
mPaymentHandlerUi = new PaymentHandlerCoordinator();
return mPaymentHandlerUi.show(chromeActivity, url, isOffTheRecord,
paymentHandlerWebContentsObserver, /*uiObserver=*/this);
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public WebContents getPaymentHandlerWebContentsForTest() {
if (mPaymentHandlerUi == null) return null;
return mPaymentHandlerUi.getWebContentsForTest();
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public boolean clickPaymentHandlerSecurityIconForTest() {
if (mPaymentHandlerUi == null) return false;
mPaymentHandlerUi.clickSecurityIconForTest();
return true;
}
} }
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