Commit 0d23163d authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[WebLayer] Replace static abortForInvalidDataFromRenderer

This CL removes the static abortForInvalidDataFromRenderer and uses the
dynamic method of the same name. The two methods executes the same code
essentially, so this CL causes no behavioural change.

Bug: 1157847
Change-Id: I21ea9cd860c98b4ab0552f3261e63c6f187154d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592013
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837236}
parent 362378b9
...@@ -76,9 +76,11 @@ public class PaymentRequestService ...@@ -76,9 +76,11 @@ public class PaymentRequestService
private static NativeObserverForTest sNativeObserverForTest; private static NativeObserverForTest sNativeObserverForTest;
private static boolean sIsLocalHasEnrolledInstrumentQueryQuotaEnforcedForTest; private static boolean sIsLocalHasEnrolledInstrumentQueryQuotaEnforcedForTest;
private final Runnable mOnClosedListener; private final Runnable mOnClosedListener;
private final RenderFrameHost mRenderFrameHost;
private final Delegate mDelegate;
private final List<PaymentApp> mPendingApps = new ArrayList<>();
private WebContents mWebContents; private WebContents mWebContents;
private JourneyLogger mJourneyLogger; private JourneyLogger mJourneyLogger;
private final RenderFrameHost mRenderFrameHost;
private String mTopLevelOrigin; private String mTopLevelOrigin;
private String mPaymentRequestOrigin; private String mPaymentRequestOrigin;
private Origin mPaymentRequestSecurityOrigin; private Origin mPaymentRequestSecurityOrigin;
...@@ -91,9 +93,7 @@ public class PaymentRequestService ...@@ -91,9 +93,7 @@ public class PaymentRequestService
private boolean mRequestPayerName; private boolean mRequestPayerName;
private boolean mRequestPayerPhone; private boolean mRequestPayerPhone;
private boolean mRequestPayerEmail; private boolean mRequestPayerEmail;
private final Delegate mDelegate;
private int mShippingType; private int mShippingType;
private final List<PaymentApp> mPendingApps = new ArrayList<>();
private PaymentRequestSpec mSpec; private PaymentRequestSpec mSpec;
private boolean mHasClosed; private boolean mHasClosed;
private boolean mIsFinishedQueryingPaymentApps; private boolean mIsFinishedQueryingPaymentApps;
...@@ -414,8 +414,7 @@ public class PaymentRequestService ...@@ -414,8 +414,7 @@ public class PaymentRequestService
@Nullable PaymentOptions options, boolean googlePayBridgeEligible) { @Nullable PaymentOptions options, boolean googlePayBridgeEligible) {
if (mRenderFrameHost.getLastCommittedOrigin() == null if (mRenderFrameHost.getLastCommittedOrigin() == null
|| mRenderFrameHost.getLastCommittedURL() == null) { || mRenderFrameHost.getLastCommittedURL() == null) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.NO_FRAME);
/*client=*/null, /*journeyLogger=*/null, ErrorStrings.NO_FRAME);
return false; return false;
} }
mPaymentRequestSecurityOrigin = mRenderFrameHost.getLastCommittedOrigin(); mPaymentRequestSecurityOrigin = mRenderFrameHost.getLastCommittedOrigin();
...@@ -425,8 +424,7 @@ public class PaymentRequestService ...@@ -425,8 +424,7 @@ public class PaymentRequestService
mWebContents = mDelegate.getLiveWebContents(mRenderFrameHost); mWebContents = mDelegate.getLiveWebContents(mRenderFrameHost);
if (mWebContents == null || mWebContents.isDestroyed()) { if (mWebContents == null || mWebContents.isDestroyed()) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.NO_WEB_CONTENTS);
/*client=*/null, /*journeyLogger=*/null, ErrorStrings.NO_WEB_CONTENTS);
return false; return false;
} }
// TODO(crbug.com/992593): replace UrlFormatter with GURL operations. // TODO(crbug.com/992593): replace UrlFormatter with GURL operations.
...@@ -438,35 +436,30 @@ public class PaymentRequestService ...@@ -438,35 +436,30 @@ public class PaymentRequestService
mJourneyLogger = mDelegate.createJourneyLogger(mIsOffTheRecord, mWebContents); mJourneyLogger = mDelegate.createJourneyLogger(mIsOffTheRecord, mWebContents);
if (mClient == null) { if (mClient == null) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.INVALID_STATE);
/*client=*/null, mJourneyLogger, ErrorStrings.INVALID_STATE);
return false; return false;
} }
if (!mDelegate.isOriginSecure(mWebContents.getLastCommittedUrl())) { if (!mDelegate.isOriginSecure(mWebContents.getLastCommittedUrl())) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.NOT_IN_A_SECURE_ORIGIN);
mClient, mJourneyLogger, ErrorStrings.NOT_IN_A_SECURE_ORIGIN);
return false; return false;
} }
if (methodData == null) { if (methodData == null) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.INVALID_PAYMENT_METHODS_OR_DATA);
mClient, mJourneyLogger, ErrorStrings.INVALID_PAYMENT_METHODS_OR_DATA);
return false; return false;
} }
// details has default value, so could never be null, according to payment_request.idl. // details has default value, so could never be null, according to payment_request.idl.
if (details == null) { if (details == null) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.INVALID_PAYMENT_DETAILS);
mClient, mJourneyLogger, ErrorStrings.INVALID_PAYMENT_DETAILS);
return false; return false;
} }
// options has default value, so could never be null, according to // options has default value, so could never be null, according to
// payment_request.idl. // payment_request.idl.
if (options == null) { if (options == null) {
abortForInvalidDataFromRenderer( abortForInvalidDataFromRenderer(ErrorStrings.INVALID_PAYMENT_OPTIONS);
mClient, mJourneyLogger, ErrorStrings.INVALID_PAYMENT_OPTIONS);
return false; return false;
} }
mPaymentOptions = options; mPaymentOptions = options;
...@@ -533,16 +526,6 @@ public class PaymentRequestService ...@@ -533,16 +526,6 @@ public class PaymentRequestService
} }
} }
private static void abortForInvalidDataFromRenderer(@Nullable PaymentRequestClient client,
@Nullable JourneyLogger journeyLogger, String debugMessage) {
Log.d(TAG, debugMessage);
if (client != null) {
client.onError(PaymentErrorReason.INVALID_DATA_FROM_RENDERER, debugMessage);
}
if (journeyLogger != null) journeyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
if (sNativeObserverForTest != null) sNativeObserverForTest.onConnectionTerminated();
}
/** /**
* Set a native-side observer for PaymentRequest implementations. This observer should be set * Set a native-side observer for PaymentRequest implementations. This observer should be set
* before PaymentRequest implementations are instantiated. * before PaymentRequest implementations are instantiated.
...@@ -1383,7 +1366,9 @@ public class PaymentRequestService ...@@ -1383,7 +1366,9 @@ public class PaymentRequestService
* @param debugMessage The debug message to be sent to the renderer. * @param debugMessage The debug message to be sent to the renderer.
*/ */
/* package */ void abortForInvalidDataFromRenderer(String debugMessage) { /* package */ void abortForInvalidDataFromRenderer(String debugMessage) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); if (mJourneyLogger != null) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
}
disconnectFromClientWithDebugMessage( disconnectFromClientWithDebugMessage(
debugMessage, PaymentErrorReason.INVALID_DATA_FROM_RENDERER); debugMessage, PaymentErrorReason.INVALID_DATA_FROM_RENDERER);
} }
...@@ -1413,7 +1398,9 @@ public class PaymentRequestService ...@@ -1413,7 +1398,9 @@ public class PaymentRequestService
mOnClosedListener.run(); mOnClosedListener.run();
mJourneyLogger.destroy(); if (mJourneyLogger != null) {
mJourneyLogger.destroy();
}
if (mSpec != null) { if (mSpec != null) {
mSpec.destroy(); mSpec.destroy();
......
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