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

[WebLayer] Remove CPRService.mPaymentRequestOptions

Changes:
* Removed CPRService.mPaymentRequestOptions
* onQueryForQuotaCreated has taken passed-in payment options from
  PRService.
* Saved PaymentOptions in PaymentRequestSpec.

Bug: 1025619

Change-Id: Ifafd0e4d0e1b5ac8815c63fe75eb3e779196c6a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2538110
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827796}
parent c0a6fbe7
......@@ -48,6 +48,7 @@ import org.chromium.payments.mojom.PaymentAddress;
import org.chromium.payments.mojom.PaymentComplete;
import org.chromium.payments.mojom.PaymentDetails;
import org.chromium.payments.mojom.PaymentErrorReason;
import org.chromium.payments.mojom.PaymentItem;
import org.chromium.payments.mojom.PaymentMethodData;
import org.chromium.payments.mojom.PaymentOptions;
import org.chromium.payments.mojom.PaymentRequest;
......@@ -80,7 +81,6 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
private final JourneyLogger mJourneyLogger;
private final PaymentUiService mPaymentUiService;
private final PaymentOptions mPaymentOptions;
private boolean mWasRetryCalled;
private boolean mHasClosed;
......@@ -133,9 +133,6 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
mWebContents = paymentRequestService.getWebContents();
mJourneyLogger = paymentRequestService.getJourneyLogger();
mPaymentOptions = paymentRequestService.getPaymentOptions();
assert mPaymentOptions != null;
mPaymentRequestService = paymentRequestService;
mPaymentUiService = new PaymentUiService(/*delegate=*/this,
/*params=*/mPaymentRequestService, mWebContents,
......@@ -218,13 +215,14 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// Implements BrowserPaymentRequest:
@Override
public void onQueryForQuotaCreated(Map<String, PaymentMethodData> queryForQuota) {
public void onQueryForQuotaCreated(
Map<String, PaymentMethodData> queryForQuota, PaymentOptions paymentOptions) {
if (queryForQuota.containsKey(MethodStrings.BASIC_CARD)
&& PaymentFeatureList.isEnabledOrExperimentalFeaturesEnabled(
PaymentFeatureList.STRICT_HAS_ENROLLED_AUTOFILL_INSTRUMENT)) {
PaymentMethodData paymentMethodData = new PaymentMethodData();
paymentMethodData.stringifiedData =
PaymentOptionsUtils.stringifyRequestedInformation(mPaymentOptions);
PaymentOptionsUtils.stringifyRequestedInformation(paymentOptions);
queryForQuota.put("basic-card-payment-options", paymentMethodData);
}
}
......@@ -276,17 +274,20 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// Implements BrowserPaymentRequest:
@Override
public boolean showAppSelector(boolean isShowWaitingForUpdatedDetails) {
public boolean showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) {
assert mPaymentRequestService
!= null : "This method is only supposed to be called by mPaymentRequestService.";
// Send AppListReady signal when all apps are created and request.show() is called.
if (PaymentRequestService.getNativeObserverForTest() != null) {
PaymentRequestService.getNativeObserverForTest().onAppListReady(
mPaymentUiService.getPaymentMethodsSection().getItems(), mSpec.getRawTotal());
mPaymentUiService.getPaymentMethodsSection().getItems(), total);
}
// Calculate skip ui and build ui only after all payment apps are ready and
// request.show() is called.
mPaymentUiService.calculateWhetherShouldSkipShowingPaymentRequestUi(
mPaymentRequestService.isUserGestureShow(), mURLPaymentMethodIdentifiersSupported,
mDelegate.skipUiForBasicCard(), mPaymentOptions);
mDelegate.skipUiForBasicCard(), paymentOptions);
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (quitShowIfActivityNotFound(chromeActivity)
|| !buildUI(chromeActivity, isShowWaitingForUpdatedDetails)) {
......@@ -577,6 +578,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
@Override
public boolean invokePaymentApp(EditableOption selectedShippingAddress,
EditableOption selectedShippingOption, PaymentApp selectedPaymentApp) {
if (mSpec == null || mSpec.isDestroyed()) return false;
EditableOption selectedContact = mPaymentUiService.getContactSection() != null
? mPaymentUiService.getContactSection().getSelectedItem()
: null;
......@@ -589,7 +591,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
}
PaymentResponseHelperInterface paymentResponseHelper = new ChromePaymentResponseHelper(
selectedShippingAddress, selectedShippingOption, selectedContact,
selectedPaymentApp, mPaymentOptions, mSkipToGPayHelper != null);
selectedPaymentApp, mSpec.getPaymentOptions(), mSkipToGPayHelper != null);
mPaymentRequestService.invokePaymentApp(selectedPaymentApp, paymentResponseHelper);
return !selectedPaymentApp.isAutofillInstrument();
}
......
......@@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentComplete;
import org.chromium.payments.mojom.PaymentDetails;
import org.chromium.payments.mojom.PaymentItem;
import org.chromium.payments.mojom.PaymentMethodData;
import org.chromium.payments.mojom.PaymentOptions;
import org.chromium.payments.mojom.PaymentRequest;
......@@ -81,8 +82,10 @@ public interface BrowserPaymentRequest {
/**
* Called when queryForQuota is created.
* @param queryForQuota The created queryForQuota, which could be modified in place.
* @param paymentOptions The payment options specified by the merchant.
*/
default void onQueryForQuotaCreated(Map<String, PaymentMethodData> queryForQuota) {}
default void onQueryForQuotaCreated(
Map<String, PaymentMethodData> queryForQuota, PaymentOptions paymentOptions) {}
/**
* Performs extra validation for the given input and disconnects the mojo pipe if failed.
......@@ -123,11 +126,13 @@ public interface BrowserPaymentRequest {
/**
* Shows the payment apps selector.
* @return Whether the showing is successful.
* @param isShowWaitingForUpdatedDetails Whether {@link PaymentRequest#show} is waiting for the
* updated details.
* @param total The total amount specified in the payment request.
* @param paymentOptions The payment options specified in the payment request.
* @return Whether the showing is successful.
*/
default boolean showAppSelector(boolean isShowWaitingForUpdatedDetails) {
default boolean showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) {
return false;
}
......
......@@ -500,7 +500,7 @@ public class PaymentRequestService
methodData = Collections.unmodifiableMap(methodData);
mQueryForQuota = new HashMap<>(methodData);
mBrowserPaymentRequest.onQueryForQuotaCreated(mQueryForQuota);
mBrowserPaymentRequest.onQueryForQuotaCreated(mQueryForQuota, mPaymentOptions);
if (!PaymentValidator.validatePaymentDetails(details)) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
......@@ -614,6 +614,9 @@ public class PaymentRequestService
@Override
public void onDoneCreatingPaymentApps(PaymentAppFactoryInterface factory /* Unused */) {
if (mBrowserPaymentRequest == null) return;
assert mSpec != null;
assert !mSpec.isDestroyed() : "mSpec is destroyed only after close()";
mIsFinishedQueryingPaymentApps = true;
if (disconnectIfNoPaymentMethodsSupported(mBrowserPaymentRequest.hasAvailableApps())) {
......@@ -634,7 +637,8 @@ public class PaymentRequestService
mBrowserPaymentRequest.notifyPaymentUiOfPendingApps(mPendingApps);
mPendingApps.clear();
if (isCurrentPaymentRequestShowing()
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails)) {
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions())) {
return;
}
......@@ -868,6 +872,9 @@ public class PaymentRequestService
*/
/* package */ void show(boolean isUserGesture, boolean waitForUpdatedDetails) {
if (mBrowserPaymentRequest == null) return;
assert mSpec != null;
assert !mSpec.isDestroyed() : "mSpec is destroyed only after close().";
if (mBrowserPaymentRequest.isShowingUi()) {
// Can be triggered only by a compromised renderer. In normal operation, calling show()
// twice on the same instance of PaymentRequest in JavaScript is rejected at the
......@@ -900,7 +907,8 @@ public class PaymentRequestService
return;
}
if (isFinishedQueryingPaymentApps()
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails)) {
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions())) {
return;
}
......
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