Commit 44b344d9 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[WebLayer] Combine two init methods

This CL inlines initAndValidate() in init(). This CL causes no
behavioural change.

Other changes:
* The result of getValidatedMethodData() is null-check before used.

Bug: 1157847
Change-Id: Ie2fcc98f4089cb3cdf196794c5440cf232af115c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592192
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837255}
parent 79f842ac
...@@ -410,8 +410,9 @@ public class PaymentRequestService ...@@ -410,8 +410,9 @@ public class PaymentRequestService
* browser process to determine whether to trigger it. * browser process to determine whether to trigger it.
* @return Whether the initialization is successful. * @return Whether the initialization is successful.
*/ */
public boolean init(@Nullable PaymentMethodData[] methodData, @Nullable PaymentDetails details, public boolean init(@Nullable PaymentMethodData[] rawMethodData,
@Nullable PaymentOptions options, boolean googlePayBridgeEligible) { @Nullable PaymentDetails details, @Nullable PaymentOptions options,
boolean googlePayBridgeEligible) {
if (mRenderFrameHost.getLastCommittedOrigin() == null if (mRenderFrameHost.getLastCommittedOrigin() == null
|| mRenderFrameHost.getLastCommittedURL() == null) { || mRenderFrameHost.getLastCommittedURL() == null) {
abortForInvalidDataFromRenderer(ErrorStrings.NO_FRAME); abortForInvalidDataFromRenderer(ErrorStrings.NO_FRAME);
...@@ -445,7 +446,7 @@ public class PaymentRequestService ...@@ -445,7 +446,7 @@ public class PaymentRequestService
return false; return false;
} }
if (methodData == null) { if (rawMethodData == null) {
abortForInvalidDataFromRenderer(ErrorStrings.INVALID_PAYMENT_METHODS_OR_DATA); abortForInvalidDataFromRenderer(ErrorStrings.INVALID_PAYMENT_METHODS_OR_DATA);
return false; return false;
} }
...@@ -469,13 +470,71 @@ public class PaymentRequestService ...@@ -469,13 +470,71 @@ public class PaymentRequestService
mRequestPayerEmail = mPaymentOptions.requestPayerEmail; mRequestPayerEmail = mPaymentOptions.requestPayerEmail;
mShippingType = mPaymentOptions.shippingType; mShippingType = mPaymentOptions.shippingType;
mJourneyLogger.recordCheckoutStep(CheckoutFunnelStep.INITIATED);
if (!mDelegate.isOriginAllowedToUseWebPaymentApis(mWebContents.getLastCommittedUrl())) {
Log.d(TAG, ErrorStrings.PROHIBITED_ORIGIN);
Log.d(TAG, ErrorStrings.PROHIBITED_ORIGIN_OR_INVALID_SSL_EXPLANATION);
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.PROHIBITED_ORIGIN,
PaymentErrorReason.NOT_SUPPORTED_FOR_INVALID_ORIGIN_OR_SSL);
return false;
}
mJourneyLogger.setRequestedInformation(
mRequestShipping, mRequestPayerEmail, mRequestPayerPhone, mRequestPayerName);
String rejectShowErrorMessage = mDelegate.getInvalidSslCertificateErrorMessage();
if (!TextUtils.isEmpty(rejectShowErrorMessage)) {
Log.d(TAG, rejectShowErrorMessage);
Log.d(TAG, ErrorStrings.PROHIBITED_ORIGIN_OR_INVALID_SSL_EXPLANATION);
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(rejectShowErrorMessage,
PaymentErrorReason.NOT_SUPPORTED_FOR_INVALID_ORIGIN_OR_SSL);
return false;
}
mBrowserPaymentRequest = mDelegate.createBrowserPaymentRequest(this); mBrowserPaymentRequest = mDelegate.createBrowserPaymentRequest(this);
boolean valid = initAndValidate( mBrowserPaymentRequest.onWhetherGooglePayBridgeEligible(
mBrowserPaymentRequest, methodData, details, googlePayBridgeEligible); googlePayBridgeEligible, mWebContents, rawMethodData);
if (!valid) { @Nullable
close(); Map<String, PaymentMethodData> methodData = getValidatedMethodData(rawMethodData);
if (methodData == null) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_PAYMENT_METHODS_OR_DATA,
PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
return false; return false;
} }
mBrowserPaymentRequest.modifyMethodDataIfNeeded(methodData);
methodData = Collections.unmodifiableMap(methodData);
mQueryForQuota = new HashMap<>(methodData);
mBrowserPaymentRequest.modifyQueryForQuotaCreatedIfNeeded(mQueryForQuota, mPaymentOptions);
if (details.id == null || details.total == null
|| !mDelegate.validatePaymentDetails(details)) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_PAYMENT_DETAILS,
PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
return false;
}
if (mBrowserPaymentRequest.disconnectIfExtraValidationFails(
mWebContents, methodData, details, mPaymentOptions)) {
return false;
}
PaymentRequestSpec spec = mDelegate.createPaymentRequestSpec(mPaymentOptions, details,
methodData.values(), LocaleUtils.getDefaultLocaleString());
if (spec.getRawTotal() == null) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(
ErrorStrings.TOTAL_REQUIRED, PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
return false;
}
mSpec = spec;
mBrowserPaymentRequest.onSpecValidated(mSpec);
logMethodTypes(mSpec.getMethodData());
startPaymentAppService(); startPaymentAppService();
return true; return true;
} }
...@@ -542,78 +601,6 @@ public class PaymentRequestService ...@@ -542,78 +601,6 @@ public class PaymentRequestService
return sNativeObserverForTest; return sNativeObserverForTest;
} }
private boolean initAndValidate(BrowserPaymentRequest browserPaymentRequest,
PaymentMethodData[] rawMethodData, PaymentDetails details,
boolean googlePayBridgeEligible) {
assert rawMethodData != null;
assert details != null;
mJourneyLogger.recordCheckoutStep(CheckoutFunnelStep.INITIATED);
if (!mDelegate.isOriginAllowedToUseWebPaymentApis(mWebContents.getLastCommittedUrl())) {
Log.d(TAG, ErrorStrings.PROHIBITED_ORIGIN);
Log.d(TAG, ErrorStrings.PROHIBITED_ORIGIN_OR_INVALID_SSL_EXPLANATION);
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.PROHIBITED_ORIGIN,
PaymentErrorReason.NOT_SUPPORTED_FOR_INVALID_ORIGIN_OR_SSL);
return false;
}
mJourneyLogger.setRequestedInformation(
mRequestShipping, mRequestPayerEmail, mRequestPayerPhone, mRequestPayerName);
String rejectShowErrorMessage = mDelegate.getInvalidSslCertificateErrorMessage();
if (!TextUtils.isEmpty(rejectShowErrorMessage)) {
Log.d(TAG, rejectShowErrorMessage);
Log.d(TAG, ErrorStrings.PROHIBITED_ORIGIN_OR_INVALID_SSL_EXPLANATION);
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(rejectShowErrorMessage,
PaymentErrorReason.NOT_SUPPORTED_FOR_INVALID_ORIGIN_OR_SSL);
return false;
}
mBrowserPaymentRequest.onWhetherGooglePayBridgeEligible(
googlePayBridgeEligible, mWebContents, rawMethodData);
@Nullable
Map<String, PaymentMethodData> methodData = getValidatedMethodData(rawMethodData);
mBrowserPaymentRequest.modifyMethodDataIfNeeded(methodData);
if (methodData == null) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_PAYMENT_METHODS_OR_DATA,
PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
return false;
}
methodData = Collections.unmodifiableMap(methodData);
mQueryForQuota = new HashMap<>(methodData);
mBrowserPaymentRequest.modifyQueryForQuotaCreatedIfNeeded(mQueryForQuota, mPaymentOptions);
if (details.id == null || details.total == null
|| !mDelegate.validatePaymentDetails(details)) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_PAYMENT_DETAILS,
PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
return false;
}
if (mBrowserPaymentRequest.disconnectIfExtraValidationFails(
mWebContents, methodData, details, mPaymentOptions)) {
return false;
}
PaymentRequestSpec spec = mDelegate.createPaymentRequestSpec(mPaymentOptions, details,
methodData.values(), LocaleUtils.getDefaultLocaleString());
if (spec.getRawTotal() == null) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(
ErrorStrings.TOTAL_REQUIRED, PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
return false;
}
mSpec = spec;
mBrowserPaymentRequest.onSpecValidated(mSpec);
logMethodTypes(mSpec.getMethodData());
return true;
}
private void logMethodTypes(Map<String, PaymentMethodData> methodDataMap) { private void logMethodTypes(Map<String, PaymentMethodData> methodDataMap) {
// Log the various types of payment methods that were requested by the merchant. // Log the various types of payment methods that were requested by the merchant.
boolean requestedMethodGoogle = false; boolean requestedMethodGoogle = false;
......
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