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