Commit e2f88954 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payments] Rename isChanging() and noUpdatedPaymentDetails() methods.

This cl renames isChanging() to isWaitingForPaymentDetailsUpdate().
This function returns true after changePaymentMethod(),
changeShippingAddress(), and changeShippingOption() calls an before
updateWith() or NoUpdatedPaymentDetails() are called, showing that
change events are fired and we are waiting for merchants response.

This cl also renames noUpdatedPaymentDetials() method to
onPaymentDetailsNotUpdated() since the latter is more appropriate for
showing that the merchant has not updated any payment details in
response to change payment method, shipping address, or shipping
option events.

TBR=kenrb@chromium.org

Bug: 984694
Change-Id: I9b9b5080c31b58432a42f611b880afa21fa79ec0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946597
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720675}
parent afa58d45
......@@ -46,7 +46,7 @@ public interface PaymentApp {
public interface PaymentRequestUpdateEventCallback {
/**
* Called to notify merchant of payment method change. The payment app should block user
* interaction until updateWith() or noUpdatedPaymentDetails().
* interaction until updateWith() or onPaymentDetailsNotUpdated().
* https://w3c.github.io/payment-request/#paymentmethodchangeevent-interface
*
* @param methodName Method name. For example, "https://google.com/pay". Should not
......@@ -59,7 +59,7 @@ public interface PaymentApp {
/**
* Called to notify merchant of shipping option change. The payment app should block user
* interaction until updateWith() or noUpdatedPaymentDetails().
* interaction until updateWith() or onPaymentDetailsNotUpdated().
* https://w3c.github.io/payment-request/#dom-paymentrequestupdateevent
*
* @param shippingOptionId Selected shipping option Identifier, Should not be null or
......@@ -70,7 +70,7 @@ public interface PaymentApp {
/**
* Called to notify merchant of shipping address change. The payment app should block user
* interaction until updateWith() or noUpdatedPaymentDetails().
* interaction until updateWith() or onPaymentDetailsNotUpdated().
* https://w3c.github.io/payment-request/#dom-paymentrequestupdateevent
*
* @param shippingAddress Selected shipping address. Should not be null.
......
......@@ -289,11 +289,17 @@ public abstract class PaymentInstrument extends EditableOption {
public void updateWith(PaymentMethodChangeResponse response) {}
/** Called when the merchant ignored the payment method change event. */
public void onPaymentDetailsNotUpdated() {}
/**
* Called when the merchant ignored the payment method change event.
* TODO(sahel): Remove this stub after updating clank code. crbug.com/984694
*/
public void noUpdatedPaymentDetails() {}
/**
* @return True after changePaymentMethodFromInvokedApp(), before update updateWith() or
* noUpdatedPaymentDetails().
* onPaymentDetailsNotUpdated().
* TODO(sahel): Remove this stub after updating clank code. crbug.com/984694
*/
public boolean isChangingPaymentMethod() {
......@@ -303,9 +309,9 @@ public abstract class PaymentInstrument extends EditableOption {
/**
* @return True after changePaymentMethodFromInvokedApp(), changeShippingOptionFromInvokedApp(),
* or changeShippingAddressFromInvokedApp() and before update updateWith() or
* noUpdatedPaymentDetails().
* onPaymentDetailsNotUpdated().
*/
public boolean isChanging() {
public boolean isWaitingForPaymentDetailsUpdate() {
return false;
}
......
......@@ -66,7 +66,7 @@ public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> {
public void updateWith(PaymentDetails details) {}
@Override
public void noUpdatedPaymentDetails() {}
public void onPaymentDetailsNotUpdated() {}
@Override
public void abort() {}
......
......@@ -1318,7 +1318,7 @@ public class PaymentRequestImpl
@Override
public boolean changePaymentMethodFromPaymentHandler(
String methodName, String stringifiedData) {
if (mPaymentHandlerHost == null || mPaymentHandlerHost.isChanging()) {
if (mPaymentHandlerHost == null || mPaymentHandlerHost.isWaitingForPaymentDetailsUpdate()) {
return false;
}
......@@ -1331,7 +1331,7 @@ public class PaymentRequestImpl
*/
@Override
public boolean changeShippingOptionFromPaymentHandler(String shippingOptionId) {
if (mPaymentHandlerHost == null || mPaymentHandlerHost.isChanging()) {
if (mPaymentHandlerHost == null || mPaymentHandlerHost.isWaitingForPaymentDetailsUpdate()) {
return false;
}
......@@ -1344,7 +1344,7 @@ public class PaymentRequestImpl
*/
@Override
public boolean changeShippingAddressFromPaymentHandler(PaymentAddress shippingAddress) {
if (mPaymentHandlerHost == null || mPaymentHandlerHost.isChanging()) {
if (mPaymentHandlerHost == null || mPaymentHandlerHost.isWaitingForPaymentDetailsUpdate()) {
return false;
}
......@@ -1418,7 +1418,8 @@ public class PaymentRequestImpl
}
if (!mRequestShipping && !mRequestPayerName && !mRequestPayerEmail && !mRequestPayerPhone
&& (mInvokedPaymentInstrument == null || !mInvokedPaymentInstrument.isChanging())) {
&& (mInvokedPaymentInstrument == null
|| !mInvokedPaymentInstrument.isWaitingForPaymentDetailsUpdate())) {
mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_STATE);
return;
......@@ -1426,7 +1427,8 @@ public class PaymentRequestImpl
if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;
if (mInvokedPaymentInstrument != null && mInvokedPaymentInstrument.isChanging()) {
if (mInvokedPaymentInstrument != null
&& mInvokedPaymentInstrument.isWaitingForPaymentDetailsUpdate()) {
// After a payment app has been invoked, all of the merchant's calls to update the price
// via updateWith() should be forwarded to the invoked app, so it can reflect the
// updated price in its UI.
......@@ -1504,7 +1506,7 @@ public class PaymentRequestImpl
* info, but did not update the payment details in response.
*/
@Override
public void noUpdatedPaymentDetails() {
public void onPaymentDetailsNotUpdated() {
if (mClient == null) return;
if (mUI == null) {
......@@ -1513,8 +1515,9 @@ public class PaymentRequestImpl
return;
}
if (mInvokedPaymentInstrument != null && mInvokedPaymentInstrument.isChanging()) {
mInvokedPaymentInstrument.noUpdatedPaymentDetails();
if (mInvokedPaymentInstrument != null
&& mInvokedPaymentInstrument.isWaitingForPaymentDetailsUpdate()) {
mInvokedPaymentInstrument.onPaymentDetailsNotUpdated();
return;
}
......
......@@ -388,19 +388,20 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen
@Override
public void updateWith(PaymentRequestDetailsUpdate response) {
assert isChanging();
assert isWaitingForPaymentDetailsUpdate();
mPaymentHandlerHost.updateWith(response);
}
@Override
public void noUpdatedPaymentDetails() {
assert isChanging();
mPaymentHandlerHost.noUpdatedPaymentDetails();
public void onPaymentDetailsNotUpdated() {
assert isWaitingForPaymentDetailsUpdate();
mPaymentHandlerHost.onPaymentDetailsNotUpdated();
}
@Override
public boolean isChanging() {
return mPaymentHandlerHost != null && mPaymentHandlerHost.isChanging();
public boolean isWaitingForPaymentDetailsUpdate() {
return mPaymentHandlerHost != null
&& mPaymentHandlerHost.isWaitingForPaymentDetailsUpdate();
}
@Override
......
......@@ -74,10 +74,10 @@ public class PaymentHandlerHost {
* ongoing.
* @return True after payment handler called changePaymentMethod(), changeShippingAddress(), or
* changeShippingOption() and before the merchant replies with either updateWith() or
* noUpdatedPaymentDetails().
* onPaymentDetailsNotUpdated().
*/
public boolean isChanging() {
return PaymentHandlerHostJni.get().isChanging(mNativePointer);
public boolean isWaitingForPaymentDetailsUpdate() {
return PaymentHandlerHostJni.get().isWaitingForPaymentDetailsUpdate(mNativePointer);
}
/**
......@@ -104,8 +104,8 @@ public class PaymentHandlerHost {
* Notifies the payment handler that the merchant ignored the the payment-method,
* shipping-address, or shipping-option change event.
*/
public void noUpdatedPaymentDetails() {
PaymentHandlerHostJni.get().noUpdatedPaymentDetails(mNativePointer);
public void onPaymentDetailsNotUpdated() {
PaymentHandlerHostJni.get().onPaymentDetailsNotUpdated(mNativePointer);
}
/** Destroys the native bridge. This object shouldn't be used afterwards. */
......@@ -153,7 +153,7 @@ public class PaymentHandlerHost {
* currently in progress.
* @param nativePaymentHandlerHost The pointer to the native payment handler host bridge.
*/
boolean isChanging(long nativePaymentHandlerHost);
boolean isWaitingForPaymentDetailsUpdate(long nativePaymentHandlerHost);
/**
* Returns the native pointer to the payment handler host (not the bridge). The native
......@@ -175,7 +175,7 @@ public class PaymentHandlerHost {
* address, or shipping option change event.
* @param nativePaymentHandlerHost The pointer to the native payment handler host bridge.
*/
void noUpdatedPaymentDetails(long nativePaymentHandlerHost);
void onPaymentDetailsNotUpdated(long nativePaymentHandlerHost);
/**
* Destroys the native payment handler host bridge.
......
......@@ -34,8 +34,9 @@ PaymentHandlerHost::PaymentHandlerHost(
PaymentHandlerHost::~PaymentHandlerHost() {}
jboolean PaymentHandlerHost::IsChanging(JNIEnv* env) const {
return payment_handler_host_.is_changing();
jboolean PaymentHandlerHost::IsWaitingForPaymentDetailsUpdate(
JNIEnv* env) const {
return payment_handler_host_.is_waiting_for_payment_details_update();
}
jlong PaymentHandlerHost::GetNativePaymentHandlerHost(JNIEnv* env) {
......@@ -57,8 +58,8 @@ void PaymentHandlerHost::UpdateWith(
payment_handler_host_.UpdateWith(std::move(response));
}
void PaymentHandlerHost::NoUpdatedPaymentDetails(JNIEnv* env) {
payment_handler_host_.NoUpdatedPaymentDetails();
void PaymentHandlerHost::OnPaymentDetailsNotUpdated(JNIEnv* env) {
payment_handler_host_.OnPaymentDetailsNotUpdated();
}
bool PaymentHandlerHost::ChangePaymentMethod(
......
......@@ -44,7 +44,7 @@ class PaymentHandlerHost : public payments::PaymentHandlerHost::Delegate {
// Checks whether any payment method, shipping address or shipping option
// change is currently in progress.
jboolean IsChanging(JNIEnv* env) const;
jboolean IsWaitingForPaymentDetailsUpdate(JNIEnv* env) const;
// Returns the pointer to the payments::PaymentHandlerHost for binding to its
// IPC endpoint in service_worker_payment_app_bridge.cc.
......@@ -61,7 +61,7 @@ class PaymentHandlerHost : public payments::PaymentHandlerHost::Delegate {
// Notifies the payment handler that the merchant ignored the payment
// method change event.
void NoUpdatedPaymentDetails(JNIEnv* env);
void OnPaymentDetailsNotUpdated(JNIEnv* env);
private:
// PaymentHandlerHost::Delegate implementation:
......
......@@ -156,7 +156,7 @@ void PaymentHandlerHost::UpdateWith(
std::move(change_payment_request_details_callback_).Run(std::move(response));
}
void PaymentHandlerHost::NoUpdatedPaymentDetails() {
void PaymentHandlerHost::OnPaymentDetailsNotUpdated() {
if (!change_payment_request_details_callback_)
return;
......
......@@ -80,7 +80,7 @@ class PaymentHandlerHost : public mojom::PaymentHandlerHost {
// Returns "true" when the payment handler has changed any of the payment
// method, shipping address or shipping option, but has not received the
// response from the merchant yet.
bool is_changing() const {
bool is_waiting_for_payment_details_update() const {
return !!change_payment_request_details_callback_;
}
......@@ -95,7 +95,7 @@ class PaymentHandlerHost : public mojom::PaymentHandlerHost {
// Notifies the payment handler that the merchant did not handle the payment
// method, shipping option, or shipping address change events, so the payment
// details are unchanged.
void NoUpdatedPaymentDetails();
void OnPaymentDetailsNotUpdated();
// Disconnects from the payment handler.
void Disconnect();
......
......@@ -343,7 +343,7 @@ void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) {
}
if (state()->selected_app() && state()->IsPaymentAppInvoked() &&
payment_handler_host_.is_changing()) {
payment_handler_host_.is_waiting_for_payment_details_update()) {
payment_handler_host_.UpdateWith(
PaymentDetailsConverter::ConvertToPaymentRequestDetailsUpdate(
details, state()->selected_app()->HandlesShippingAddress(),
......@@ -368,7 +368,7 @@ void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) {
}
}
void PaymentRequest::NoUpdatedPaymentDetails() {
void PaymentRequest::OnPaymentDetailsNotUpdated() {
// This Mojo call is triggered by the user of the API doing nothing in
// response to a shipping address update event, so the error messages cannot
// be more verbose.
......@@ -386,8 +386,9 @@ void PaymentRequest::NoUpdatedPaymentDetails() {
spec_->RecomputeSpecForDetails();
if (state()->IsPaymentAppInvoked() && payment_handler_host_.is_changing()) {
payment_handler_host_.NoUpdatedPaymentDetails();
if (state()->IsPaymentAppInvoked() &&
payment_handler_host_.is_waiting_for_payment_details_update()) {
payment_handler_host_.OnPaymentDetailsNotUpdated();
}
}
......
......@@ -76,7 +76,7 @@ class PaymentRequest : public mojom::PaymentRequest,
void Show(bool is_user_gesture, bool wait_for_updated_details) override;
void Retry(mojom::PaymentValidationErrorsPtr errors) override;
void UpdateWith(mojom::PaymentDetailsPtr details) override;
void NoUpdatedPaymentDetails() override;
void OnPaymentDetailsNotUpdated() override;
void Abort() override;
void Complete(mojom::PaymentComplete result) override;
void CanMakePayment() override;
......
......@@ -65,7 +65,7 @@ interface PaymentHandlerHost {
// The Merchant renderer then responds to the browser via
// PaymentRequest.UpdateWith(details) to update the total or other details of
// the payment request based on the selected instrument/shipping address/
// shipping option or PaymentRequest.NoUpdatedPaymentDetails() if the
// shipping option or PaymentRequest.OnPaymentDetailsNotUpdated() if the
// total and other details are unchanged. The total can change, for example,
// based on the billing address of the selected instrument or the selected
// shipping address/option. The list of available shipping options can change
......
......@@ -233,7 +233,7 @@ interface PaymentRequest {
// Called when the merchant received a new shipping address or shipping
// option, but did not update the payment details in response.
NoUpdatedPaymentDetails();
OnPaymentDetailsNotUpdated();
// Requests to abort the checkout in process, for example because the item
// went out of stock.
......
......@@ -1196,7 +1196,7 @@ void PaymentRequest::OnPaymentMethodChange(const String& method_name,
DCHECK(!complete_resolver_);
if (!RuntimeEnabledFeatures::PaymentMethodChangeEventEnabled()) {
payment_provider_->NoUpdatedPaymentDetails();
payment_provider_->OnPaymentDetailsNotUpdated();
return;
}
......@@ -1552,7 +1552,7 @@ void PaymentRequest::DispatchPaymentRequestUpdateEvent(
GetExecutionContext()->AddConsoleMessage(
ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript,
mojom::ConsoleMessageLevel::kWarning, message));
payment_provider_->NoUpdatedPaymentDetails();
payment_provider_->OnPaymentDetailsNotUpdated();
// Make sure that updateWith() is only allowed to be called within the same
// event loop as the event dispatch. See
// https://w3c.github.io/payment-request/#paymentrequest-updated-algorithm
......
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