Commit 41cf6502 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[WebLayer] Encapsulate createShippingSectionForPaymentRequestUI

This CL combines two invocation of
createShippingSectionForPaymentRequestUI() into one and simplify the
invocation conditions.

Before the CL, the method was called in the following control routes:
1. PRService#updateWith()
   -> CPRService#continueShow()
   -> if isPaymentRequestUiAlive()
   -> invoke
2. PRService#onShowCalledAndAppsQueried()
   -> CPRService#showOrSkipAppSelector()
   -> PaymentUiService#buildPaymentRequestUI
   -> if !isShowWaitingForUpdatedDetails
   -> invoke

Observing the invocation conditions of the two routes, we know that
they are invoked under the same conditions because:
1. isShowWaitingForUpdatedDetails == false: satisfied by updateWith()
   show() called and apps queried: satisfied by
   isPaymentRequestUiAlive().
2. isShowWaitingForUpdatedDetails == false: satisfied by the if.
   show() called and apps queried: satisfied by showOrSkipAppSelector().

Based on the conditions, these invocations is equivalent to one in
CPRService#onShowCalledAndAppsQueriedAndDetailsFinalized().

Bug: 1155582
Change-Id: Id2978142bd62f4396bdae3937973631bc9408d73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575203
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835245}
parent b5b39f65
...@@ -278,6 +278,11 @@ public class ChromePaymentRequestService ...@@ -278,6 +278,11 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public String onShowCalledAndAppsQueriedAndDetailsFinalized(boolean isUserGestureShow) { public String onShowCalledAndAppsQueriedAndDetailsFinalized(boolean isUserGestureShow) {
WindowAndroid windowAndroid = mDelegate.getWindowAndroid(mRenderFrameHost);
if (windowAndroid == null) return ErrorStrings.WINDOW_NOT_FOUND;
Context context = windowAndroid.getContext().get();
if (context == null) return ErrorStrings.CONTEXT_NOT_FOUND;
// If we are skipping showing the app selector UI, we should call into the payment app // If we are skipping showing the app selector UI, we should call into the payment app
// immediately after we determine the apps are ready and UI is shown. // immediately after we determine the apps are ready and UI is shown.
if (mHasSkippedAppSelector) { if (mHasSkippedAppSelector) {
...@@ -285,8 +290,6 @@ public class ChromePaymentRequestService ...@@ -285,8 +290,6 @@ public class ChromePaymentRequestService
assert mPaymentUiService.isPaymentRequestUiAlive(); assert mPaymentUiService.isPaymentRequestUiAlive();
if (isMinimalUiApplicable(isUserGestureShow)) { if (isMinimalUiApplicable(isUserGestureShow)) {
WindowAndroid windowAndroid = mDelegate.getWindowAndroid(mRenderFrameHost);
if (windowAndroid == null) return ErrorStrings.WINDOW_NOT_FOUND;
if (mPaymentUiService.triggerMinimalUI(windowAndroid, mSpec.getRawTotal(), if (mPaymentUiService.triggerMinimalUI(windowAndroid, mSpec.getRawTotal(),
this::onMinimalUIReady, this::onMinimalUiConfirmed, this::onMinimalUIReady, this::onMinimalUiConfirmed,
/*dismissObserver=*/ /*dismissObserver=*/
...@@ -313,6 +316,8 @@ public class ChromePaymentRequestService ...@@ -313,6 +316,8 @@ public class ChromePaymentRequestService
mSpec.getRawTotal().amount.value, false /*completed*/); mSpec.getRawTotal().amount.value, false /*completed*/);
invokePaymentApp(null /* selectedShippingAddress */, null /* selectedShippingOption */, invokePaymentApp(null /* selectedShippingAddress */, null /* selectedShippingOption */,
selectedApp); selectedApp);
} else {
mPaymentUiService.createShippingSectionIfNeeded(context);
} }
return null; return null;
} }
...@@ -414,13 +419,6 @@ public class ChromePaymentRequestService ...@@ -414,13 +419,6 @@ public class ChromePaymentRequestService
mPaymentUiService.updateDetailsOnPaymentRequestUI(mSpec.getPaymentDetails()); mPaymentUiService.updateDetailsOnPaymentRequestUI(mSpec.getPaymentDetails());
// Do not create shipping section When UI is not built yet. This happens when the show
// promise gets resolved before all apps are ready.
if (mPaymentUiService.isPaymentRequestUiAlive()
&& mPaymentUiService.shouldShowShippingSection()) {
mPaymentUiService.createShippingSectionForPaymentRequestUI(context);
}
// Triggered transaction amount gets recorded when both of the following conditions are met: // Triggered transaction amount gets recorded when both of the following conditions are met:
// 1- Either Event.Shown or Event.SKIPPED_SHOW bits are set showing that transaction is // 1- Either Event.Shown or Event.SKIPPED_SHOW bits are set showing that transaction is
// triggered (mDidRecordShowEvent == true). 2- The total amount in details won't change // triggered (mDidRecordShowEvent == true). 2- The total amount in details won't change
......
...@@ -332,6 +332,16 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -332,6 +332,16 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
}; };
} }
/**
* Creates the shipping section for the app selector UI if needed. This method should be called
* when UI has been built and payment details has been finalized.
* @param context The activity context.
*/
public void createShippingSectionIfNeeded(Context context) {
if (!shouldShowShippingSection()) return;
createShippingSectionForPaymentRequestUI(context);
}
/** /**
* @return Whether the PaymentRequest UI is alive. The UI comes to live when * @return Whether the PaymentRequest UI is alive. The UI comes to live when
* buildPaymentRequestUi() has been called to create it; it stops being alive when * buildPaymentRequestUi() has been called to create it; it stops being alive when
...@@ -1236,10 +1246,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1236,10 +1246,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
mOverviewModeBehavior.addOverviewModeObserver(mOverviewModeObserver); mOverviewModeBehavior.addOverviewModeObserver(mOverviewModeObserver);
} }
if (shouldShowShippingSection() && !isShowWaitingForUpdatedDetails) {
createShippingSectionForPaymentRequestUI(activity);
}
if (shouldShowContactSection()) { if (shouldShowContactSection()) {
mContactSection = new ContactDetailsSection( mContactSection = new ContactDetailsSection(
activity, mAutofillProfiles, mContactEditor, mJourneyLogger); activity, mAutofillProfiles, mContactEditor, mJourneyLogger);
...@@ -1282,7 +1288,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1282,7 +1288,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
} }
/** Create a shipping section for PaymentRequest UI. */ /** Create a shipping section for PaymentRequest UI. */
public void createShippingSectionForPaymentRequestUI(Context context) { private void createShippingSectionForPaymentRequestUI(Context context) {
List<AutofillAddress> addresses = new ArrayList<>(); List<AutofillAddress> addresses = new ArrayList<>();
for (int i = 0; i < mAutofillProfiles.size(); i++) { for (int i = 0; i < mAutofillProfiles.size(); i++) {
......
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