Commit 982ff9b3 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PaymentHandler] Adds user-facing error types

Changes:
* PaymentHandlerMediator, PaymentHandlerActivity returns different
messages for different errors.
* ServiceWorkerPaymentAppBridge combines similar methods into
onClosingPaymentAppWindow().
* Added two enums to PaymentEventResponseType in payment_app.mojom and
sorted all enums of the type:
 - PAYMENT_HANDLER_ACTIVITY_DIED
 - PAYMENT_HANDLER_FAIL_TO_LOAD_MAIN_FRAME

Bug: 1091957

Change-Id: Iab712ea3b72965ffd4e2bae6a1bd1c5e4776e441
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469116Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822793}
parent 3661f48b
......@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvid
import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentEventResponseType;
import org.chromium.ui.display.DisplayUtil;
/**
......@@ -56,7 +57,8 @@ public class PaymentHandlerActivity extends CustomTabActivity {
// Notify the window is closing so as to abort invoking payment app early.
if (!mHaveNotifiedServiceWorker && mWebContents != null) {
mHaveNotifiedServiceWorker = true;
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContents);
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(
mWebContents, PaymentEventResponseType.PAYMENT_HANDLER_WINDOW_CLOSING);
}
super.handleFinishAndClose();
......
......@@ -112,7 +112,8 @@ public class ServiceWorkerPaymentAppBridge {
WebContents paymentRequestWebContents = tab.getWebContents();
if (!SslValidityChecker.isValidPageInPaymentHandlerWindow(
paymentRequestWebContents)) {
onClosingPaymentAppWindowForInsecureNavigation(paymentRequestWebContents);
onClosingPaymentAppWindow(paymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_INSECURE_NAVIGATION);
}
}
......@@ -122,33 +123,25 @@ public class ServiceWorkerPaymentAppBridge {
WebContents paymentRequestWebContents = tab.getWebContents();
if (!SslValidityChecker.isValidPageInPaymentHandlerWindow(
paymentRequestWebContents)) {
onClosingPaymentAppWindowForInsecureNavigation(paymentRequestWebContents);
onClosingPaymentAppWindow(paymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_INSECURE_NAVIGATION);
}
}
});
}
/**
* Notify closing the opened payment app window for insecure navigation.
*
* @param paymentRequestWebContents The web contents in the opened window.
*/
public static void onClosingPaymentAppWindowForInsecureNavigation(
WebContents paymentRequestWebContents) {
if (paymentRequestWebContents.isDestroyed()) return;
ServiceWorkerPaymentAppBridgeJni.get().onClosingPaymentAppWindow(paymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_INSECURE_NAVIGATION);
}
/**
* Notify closing the opened payment app window.
*
* @param paymentRequestWebContents The web contents in the opened window. Can be null.
* @param responseType The type of response for payment event, used to decide the user-visible
* error message, defined in {@link PaymentEventResponseType}.
*/
public static void onClosingPaymentAppWindow(@Nullable WebContents paymentRequestWebContents) {
public static void onClosingPaymentAppWindow(
@Nullable WebContents paymentRequestWebContents, int responseType) {
if (paymentRequestWebContents == null || paymentRequestWebContents.isDestroyed()) return;
ServiceWorkerPaymentAppBridgeJni.get().onClosingPaymentAppWindow(
paymentRequestWebContents, PaymentEventResponseType.PAYMENT_HANDLER_WINDOW_CLOSING);
paymentRequestWebContents, responseType);
}
/**
......@@ -159,7 +152,6 @@ public class ServiceWorkerPaymentAppBridge {
*/
public static void onOpeningPaymentAppWindow(
WebContents paymentRequestWebContents, WebContents paymentHandlerWebContents) {
if (paymentHandlerWebContents == null || paymentHandlerWebContents.isDestroyed()) return;
if (paymentRequestWebContents == null || paymentRequestWebContents.isDestroyed()) return;
ServiceWorkerPaymentAppBridgeJni.get().onOpeningPaymentAppWindow(
/*paymentRequestWebContents=*/paymentRequestWebContents,
......
......@@ -27,6 +27,7 @@ import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.payments.mojom.PaymentEventResponseType;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.util.TokenHolder;
......@@ -205,16 +206,20 @@ import java.lang.annotation.RetentionPolicy;
switch (mCloseReason) {
case CloseReason.INSECURE_NAVIGATION:
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindowForInsecureNavigation(
mPaymentRequestWebContents);
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mPaymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_INSECURE_NAVIGATION);
break;
case CloseReason.USER:
// Intentional fallthrough.
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mPaymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_WINDOW_CLOSING);
break;
case CloseReason.FAIL_LOAD:
// Intentional fallthrough.
// TODO(crbug.com/1017926): Respond to service worker with the net error.
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mPaymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_FAIL_TO_LOAD_MAIN_FRAME);
break;
case CloseReason.ACTIVITY_DIED:
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mPaymentRequestWebContents);
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mPaymentRequestWebContents,
PaymentEventResponseType.PAYMENT_HANDLER_ACTIVITY_DIED);
break;
case CloseReason.OTHERS:
// No need to notify ServiceWorkerPaymentAppBridge when merchant aborts the
......
......@@ -78,6 +78,11 @@ base::StringPiece ConvertPaymentEventResponseTypeToErrorString(
return errors::kPaymentEventTimeout;
case mojom::PaymentEventResponseType::PAYMENT_HANDLER_INSECURE_NAVIGATION:
return errors::kPaymentHandlerInsecureNavigation;
case mojom::PaymentEventResponseType::PAYMENT_HANDLER_ACTIVITY_DIED:
return errors::kPaymentHandlerActivityDied;
case mojom::PaymentEventResponseType::
PAYMENT_HANDLER_FAIL_TO_LOAD_MAIN_FRAME:
return errors::kPaymentHandlerFailToLoadMainFrame;
case mojom::PaymentEventResponseType::PAYER_NAME_EMPTY:
return errors::kPayerNameEmpty;
case mojom::PaymentEventResponseType::PAYER_EMAIL_EMPTY:
......
......@@ -134,6 +134,12 @@ const char kPaymentHandlerInsecureNavigation[] =
"The payment handler navigated to a page with insecure context, invalid "
"certificate state, or malicious content.";
const char kPaymentHandlerActivityDied[] =
"The payment handler is closed because the Android activity is destroyed.";
const char kPaymentHandlerFailToLoadMainFrame[] =
"The payment handler fails to load the page.";
const char kSinglePaymentMethodNotSupportedFormat[] =
"The payment method $ is not supported.";
......
......@@ -148,6 +148,12 @@ extern const char kPaymentEventTimeout[];
// malicious content.
extern const char kPaymentHandlerInsecureNavigation[];
// The payment handler is closed because the Android activity is destroyed.
extern const char kPaymentHandlerActivityDied[];
// The payment handler fails to load the page.
extern const char kPaymentHandlerFailToLoadMainFrame[];
// Payment handler encountered an internal error when handling the
// "paymentrequest" event.
extern const char kPaymentEventInternalError[];
......
......@@ -46,22 +46,24 @@ enum CanMakePaymentEventResponseType {
};
enum PaymentEventResponseType {
PAYMENT_EVENT_SUCCESS,
PAYMENT_EVENT_REJECT,
PAYMENT_EVENT_SERVICE_WORKER_ERROR,
PAYMENT_HANDLER_WINDOW_CLOSING,
PAYMENT_EVENT_INTERNAL_ERROR,
PAYMENT_EVENT_NO_RESPONSE,
PAYMENT_DETAILS_STRINGIFY_ERROR,
PAYMENT_METHOD_NAME_EMPTY,
PAYER_NAME_EMPTY,
PAYER_EMAIL_EMPTY,
PAYER_PHONE_EMPTY,
PAYMENT_DETAILS_ABSENT,
PAYMENT_DETAILS_NOT_OBJECT,
PAYMENT_DETAILS_STRINGIFY_ERROR,
PAYMENT_EVENT_BROWSER_ERROR,
PAYMENT_EVENT_INTERNAL_ERROR,
PAYMENT_EVENT_NO_RESPONSE,
PAYMENT_EVENT_REJECT,
PAYMENT_EVENT_SERVICE_WORKER_ERROR,
PAYMENT_EVENT_SUCCESS,
PAYMENT_EVENT_TIMEOUT,
PAYMENT_HANDLER_ACTIVITY_DIED,
PAYMENT_HANDLER_FAIL_TO_LOAD_MAIN_FRAME,
PAYMENT_HANDLER_INSECURE_NAVIGATION,
PAYER_NAME_EMPTY,
PAYER_EMAIL_EMPTY,
PAYER_PHONE_EMPTY,
PAYMENT_HANDLER_WINDOW_CLOSING,
PAYMENT_METHOD_NAME_EMPTY,
SHIPPING_ADDRESS_INVALID,
SHIPPING_OPTION_EMPTY,
};
......
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