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

[WebLayer] Move mShouldSkipShowingPaymentRequestUi

Changes:
* CPRService takes over mShouldSkipShowingPaymentRequestUi from
  PaymentUiService.
* Simplifies calculateWhetherShouldSkipShowingPaymentRequestUi as
  shouldSkipShowingPaymentRequestUi.

Bug: 1025619
Change-Id: Id57c9225f85e99b8a174072e0e54c708eabbf876
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556473
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830705}
parent bf618c59
......@@ -93,6 +93,14 @@ public class ChromePaymentRequestService
/** A helper to manage the Skip-to-GPay experimental flow. */
private SkipToGPayHelper mSkipToGPayHelper;
private boolean mIsGooglePayBridgeActivated;
/**
* True if the browser should skip showing PaymentRequest UI.
*
* <p>In cases where there is a single payment app and the merchant does not request shipping
* or billing, the browser can skip showing UI as Payment Request UI is not benefiting the user
* at all.
*/
private boolean mShouldSkipShowingPaymentRequestUi;
/** The delegate of this class */
public interface Delegate extends PaymentRequestService.Delegate {
......@@ -220,11 +228,6 @@ public class ChromePaymentRequestService
PaymentRequestService.getNativeObserverForTest().onAppListReady(
mPaymentUiService.getPaymentApps(), total);
}
// Calculate skip ui and build ui only after all payment apps are ready and
// request.show() is called.
mPaymentUiService.calculateWhetherShouldSkipShowingPaymentRequestUi(isUserGestureShow,
mDelegate.skipUiForBasicCard(), mSpec.getPaymentOptions(),
mSpec.getMethodData().keySet());
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (chromeActivity == null) return ErrorStrings.ACTIVITY_NOT_FOUND;
String error = mPaymentUiService.buildPaymentRequestUI(chromeActivity,
......@@ -232,7 +235,12 @@ public class ChromePaymentRequestService
PaymentRequestServiceUtil.isWebContentsActive(mRenderFrameHost),
/*isShowWaitingForUpdatedDetails=*/isShowWaitingForUpdatedDetails);
if (error != null) return error;
if (!mPaymentUiService.shouldSkipShowingPaymentRequestUi() && mSkipToGPayHelper == null) {
// Calculate skip ui and build ui only after all payment apps are ready and
// request.show() is called.
mShouldSkipShowingPaymentRequestUi = mPaymentUiService.shouldSkipShowingPaymentRequestUi(
isUserGestureShow, mDelegate.skipUiForBasicCard(), mSpec.getPaymentOptions(),
mSpec.getMethodData().keySet());
if (!mShouldSkipShowingPaymentRequestUi && mSkipToGPayHelper == null) {
mPaymentUiService.getPaymentRequestUI().show(isShowWaitingForUpdatedDetails);
}
return null;
......@@ -259,7 +267,7 @@ public class ChromePaymentRequestService
public String triggerPaymentAppUiSkipIfApplicable(boolean isUserGestureShow) {
// If we are skipping showing the Payment Request UI, we should call into the payment app
// immediately after we determine the apps are ready and UI is shown.
if ((mPaymentUiService.shouldSkipShowingPaymentRequestUi() || mSkipToGPayHelper != null)) {
if (mShouldSkipShowingPaymentRequestUi || mSkipToGPayHelper != null) {
assert !mPaymentUiService.getPaymentApps().isEmpty();
assert mPaymentUiService.getPaymentRequestUI() != null;
......@@ -420,8 +428,7 @@ public class ChromePaymentRequestService
mSpec.getRawTotal().amount.value, false /*completed*/);
}
if (isFinishedQueryingPaymentApps
&& !mPaymentUiService.shouldSkipShowingPaymentRequestUi()) {
if (isFinishedQueryingPaymentApps && !mShouldSkipShowingPaymentRequestUi) {
boolean providedInformationToPaymentRequestUI =
mPaymentUiService.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
......@@ -657,8 +664,7 @@ public class ChromePaymentRequestService
// Showing the payment request UI if we were previously skipping it so the loading
// spinner shows up until the merchant notifies that payment was completed.
if (mPaymentUiService.shouldSkipShowingPaymentRequestUi()
&& mPaymentUiService.getPaymentRequestUI() != null) {
if (mShouldSkipShowingPaymentRequestUi && mPaymentUiService.getPaymentRequestUI() != null) {
mPaymentUiService.getPaymentRequestUI().showProcessingMessageAfterUiSkip();
}
}
......@@ -680,7 +686,7 @@ public class ChromePaymentRequestService
}
// When skipping UI, any errors/cancel from fetching payment details should abort payment.
if (mPaymentUiService.shouldSkipShowingPaymentRequestUi()) {
if (mShouldSkipShowingPaymentRequestUi) {
assert !TextUtils.isEmpty(errorMessage);
mJourneyLogger.setAborted(AbortReason.ABORTED_BY_USER);
disconnectFromClientWithDebugMessage(errorMessage);
......
......@@ -149,14 +149,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
private OverviewModeBehavior mOverviewModeBehavior;
private MinimalUICoordinator mMinimalUi;
/**
* True if we should skip showing PaymentRequest UI.
*
* <p>In cases where there is a single payment app and the merchant does not request shipping
* or billing, we can skip showing UI as Payment Request UI is not benefiting the user at all.
*/
private boolean mShouldSkipShowingPaymentRequestUi;
/** The delegate of this class. */
public interface Delegate {
/** Dispatch the payer detail change event if needed. */
......@@ -517,11 +509,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
onUiCompleted.run();
}
/** @return Whether PaymentRequestUI should be skipped. */
public boolean shouldSkipShowingPaymentRequestUi() {
return mShouldSkipShowingPaymentRequestUi;
}
// Implement SettingsAutofillAndPaymentsObserver.Observer:
@Override
public void onAddressUpdated(AutofillAddress address) {
......@@ -1498,14 +1485,14 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
}
/**
* Calculate whether the browser payment sheet should be skipped directly into the payment app.
* @param isUserGestureShow Whether the PaymentRequest.show() is triggered by user gesture.
* @param skipUiForNonUrlPaymentMethodIdentifiers True when skip UI is available for non-url
* based payment method identifiers (e.g., basic-card).
* @param options The payment options specified in the payment request.
* @param paymentMethods The payment methods supported by this request.
* @return Whether the browser payment sheet should be skipped directly into the payment app.
*/
public void calculateWhetherShouldSkipShowingPaymentRequestUi(boolean isUserGestureShow,
public boolean shouldSkipShowingPaymentRequestUi(boolean isUserGestureShow,
boolean skipUiForNonUrlPaymentMethodIdentifiers, PaymentOptions options,
Set<String> paymentMethods) {
assert mPaymentMethodsSection != null;
......@@ -1517,8 +1504,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
// If there is only a single payment app which can provide all merchant requested
// information, we can safely go directly to the payment app instead of showing Payment
// Request UI.
mShouldSkipShowingPaymentRequestUi =
PaymentFeatureList.isEnabled(PaymentFeatureList.WEB_PAYMENTS_SINGLE_APP_UI_SKIP)
return PaymentFeatureList.isEnabled(PaymentFeatureList.WEB_PAYMENTS_SINGLE_APP_UI_SKIP)
// Only allowing payment apps that own their own UIs.
// This excludes AutofillPaymentInstrument as its UI is rendered inline in
// the payment request UI, thus can't be skipped.
......
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