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

[WebLayer] Refactor disconnectIfNoPaymentMethodsSupported

Refactors disconnectIfNoPaymentMethodsSupported() so that:
* it becomes ready to be moved into PRService,
* hasAvailableApps() becomes ready to be delegated through BrowserPR
* disconnectForStrictShow() becomes ready to be delegated through
  BrowserPR

Bug: 1144527

Change-Id: I4dab80acf293fc332729970e546a5c059b8c9e49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515522Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824059}
parent 91ac5f26
...@@ -408,7 +408,7 @@ public class ChromePaymentRequestService ...@@ -408,7 +408,7 @@ public class ChromePaymentRequestService
mWaitForUpdatedDetails = waitForUpdatedDetails; mWaitForUpdatedDetails = waitForUpdatedDetails;
mJourneyLogger.setTriggerTime(); mJourneyLogger.setTriggerTime();
if (disconnectIfNoPaymentMethodsSupported()) return; if (disconnectIfNoPaymentMethodsSupported(hasAvailableApps())) return;
if (mIsFinishedQueryingPaymentApps && !showAppSelector()) return; if (mIsFinishedQueryingPaymentApps && !showAppSelector()) return;
triggerPaymentAppUiSkipIfApplicable(); triggerPaymentAppUiSkipIfApplicable();
...@@ -1373,7 +1373,8 @@ public class ChromePaymentRequestService ...@@ -1373,7 +1373,8 @@ public class ChromePaymentRequestService
public void onDoneCreatingPaymentApps(PaymentAppFactoryInterface factory /* Unused */) { public void onDoneCreatingPaymentApps(PaymentAppFactoryInterface factory /* Unused */) {
mIsFinishedQueryingPaymentApps = true; mIsFinishedQueryingPaymentApps = true;
if (mPaymentRequestService == null || disconnectIfNoPaymentMethodsSupported()) { if (mPaymentRequestService == null
|| disconnectIfNoPaymentMethodsSupported(hasAvailableApps())) {
return; return;
} }
...@@ -1463,24 +1464,19 @@ public class ChromePaymentRequestService ...@@ -1463,24 +1464,19 @@ public class ChromePaymentRequestService
/** /**
* If no payment methods are supported, disconnect from the client and return true. * If no payment methods are supported, disconnect from the client and return true.
* @param hasAvailableApps Whether any payment app is available.
* @return Whether client has been disconnected. * @return Whether client has been disconnected.
*/ */
private boolean disconnectIfNoPaymentMethodsSupported() { private boolean disconnectIfNoPaymentMethodsSupported(boolean hasAvailableApps) {
if (!mIsFinishedQueryingPaymentApps || !mIsCurrentPaymentRequestShowing) return false; if (!mIsFinishedQueryingPaymentApps || !mIsCurrentPaymentRequestShowing) return false;
if (!mCanMakePayment || (mPendingApps.isEmpty() && !hasAvailableApps)) {
boolean havePaymentApps = !mPendingApps.isEmpty()
|| (mPaymentUiService.getPaymentMethodsSection() != null
&& !mPaymentUiService.getPaymentMethodsSection().isEmpty());
if (!mCanMakePayment
|| (!havePaymentApps && !mPaymentUiService.merchantSupportsAutofillCards())) {
// All factories have responded, but none of them have apps. It's possible to add credit // All factories have responded, but none of them have apps. It's possible to add credit
// cards, but the merchant does not support them either. The payment request must be // cards, but the merchant does not support them either. The payment request must be
// rejected. // rejected.
mJourneyLogger.setNotShown(mCanMakePayment mJourneyLogger.setNotShown(mCanMakePayment
? NotShownReason.NO_MATCHING_PAYMENT_METHOD ? NotShownReason.NO_MATCHING_PAYMENT_METHOD
: NotShownReason.NO_SUPPORTED_PAYMENT_METHOD); : NotShownReason.NO_SUPPORTED_PAYMENT_METHOD);
if (mPaymentRequestService.isOffTheRecord()) { if (mDelegate.isOffTheRecord()) {
// If the user is in the OffTheRecord mode, hide the absence of their payment // If the user is in the OffTheRecord mode, hide the absence of their payment
// methods from the merchant site. // methods from the merchant site.
disconnectFromClientWithDebugMessage( disconnectFromClientWithDebugMessage(
...@@ -1505,8 +1501,16 @@ public class ChromePaymentRequestService ...@@ -1505,8 +1501,16 @@ public class ChromePaymentRequestService
} }
return true; return true;
} }
boolean isDisconnected = disconnectForStrictShow(mIsUserGestureShow);
if (isDisconnected && PaymentRequestService.getObserverForTest() != null) {
PaymentRequestService.getObserverForTest().onPaymentRequestServiceShowFailed();
}
return isDisconnected;
}
return disconnectForStrictShow(); /** @return Whether at least one payment app (including basic-card payment app) is available. */
private boolean hasAvailableApps() {
return mPaymentUiService.hasAvailableApps();
} }
private boolean isInTwa() { private boolean isInTwa() {
...@@ -1516,9 +1520,10 @@ public class ChromePaymentRequestService ...@@ -1516,9 +1520,10 @@ public class ChromePaymentRequestService
/** /**
* If strict show() conditions are not satisfied, disconnect from client and return true. * If strict show() conditions are not satisfied, disconnect from client and return true.
* @return Whether client has been disconnected. * @return Whether client has been disconnected.
* @param isUserGestureShow Whether the PaymentRequest.show() is triggered by user gesture.
*/ */
private boolean disconnectForStrictShow() { private boolean disconnectForStrictShow(boolean isUserGestureShow) {
if (!mIsUserGestureShow || !mSpec.getMethodData().containsKey(MethodStrings.BASIC_CARD) if (!isUserGestureShow || !mSpec.getMethodData().containsKey(MethodStrings.BASIC_CARD)
|| mPaymentRequestService.getHasEnrolledInstrument() || mPaymentRequestService.getHasEnrolledInstrument()
|| mPaymentRequestService.getHasNonAutofillApp() || mPaymentRequestService.getHasNonAutofillApp()
|| !PaymentFeatureList.isEnabledOrExperimentalFeaturesEnabled( || !PaymentFeatureList.isEnabledOrExperimentalFeaturesEnabled(
......
...@@ -1684,6 +1684,13 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1684,6 +1684,13 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
PersonalDataManager.getInstance().normalizeAddress(address.getProfile(), /*delegate=*/this); PersonalDataManager.getInstance().normalizeAddress(address.getProfile(), /*delegate=*/this);
} }
/** @return Whether at least one payment app (including basic-card payment app) is available. */
public boolean hasAvailableApps() {
assert mHasInitialized;
return (mPaymentMethodsSection != null && !mPaymentMethodsSection.isEmpty())
|| mMerchantSupportsAutofillCards;
}
/** Close the instance. Do not use this instance any more after calling this method. */ /** Close the instance. Do not use this instance any more after calling this method. */
public void close() { public void close() {
assert !mHasClosed; assert !mHasClosed;
......
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