PaymentRequestUpdateEvent.cpp [plain text]
#include "config.h"
#include "PaymentRequestUpdateEvent.h"
#if ENABLE(PAYMENT_REQUEST)
#include "EventNames.h"
#include "PaymentRequest.h"
namespace WebCore {
PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, const PaymentRequestUpdateEventInit& eventInit)
: Event { type, eventInit, IsTrusted::No }
{
ASSERT(!isTrusted());
}
PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type)
: Event { type, CanBubble::No, IsCancelable::No }
{
ASSERT(isTrusted());
}
PaymentRequestUpdateEvent::~PaymentRequestUpdateEvent() = default;
ExceptionOr<void> PaymentRequestUpdateEvent::updateWith(Ref<DOMPromise>&& detailsPromise)
{
if (!isTrusted())
return Exception { InvalidStateError };
if (m_waitForUpdate)
return Exception { InvalidStateError };
stopPropagation();
stopImmediatePropagation();
PaymentRequest::UpdateReason reason;
if (type() == eventNames().shippingaddresschangeEvent)
reason = PaymentRequest::UpdateReason::ShippingAddressChanged;
else if (type() == eventNames().shippingoptionchangeEvent)
reason = PaymentRequest::UpdateReason::ShippingOptionChanged;
else if (type() == eventNames().paymentmethodchangeEvent)
reason = PaymentRequest::UpdateReason::PaymentMethodChanged;
else {
ASSERT_NOT_REACHED();
return Exception { TypeError };
}
auto exception = downcast<PaymentRequest>(target())->updateWith(reason, WTFMove(detailsPromise));
if (exception.hasException())
return exception.releaseException();
m_waitForUpdate = true;
return { };
}
EventInterface PaymentRequestUpdateEvent::eventInterface() const
{
return PaymentRequestUpdateEventInterfaceType;
}
}
#endif // ENABLE(PAYMENT_REQUEST)