PaymentRequestUpdateEvent.cpp [plain text]
#include "config.h"
#include "PaymentRequestUpdateEvent.h"
#if ENABLE(PAYMENT_REQUEST)
#include "PaymentRequest.h"
namespace WebCore {
PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, PaymentRequestUpdateEventInit&& eventInit)
: Event { type, WTFMove(eventInit), IsTrusted::No }
{
}
PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, PaymentRequest& paymentRequest)
: Event { type, false, false }
, m_paymentRequest { &paymentRequest }
{
}
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 {
ASSERT_NOT_REACHED();
return Exception { TypeError };
}
auto exception = m_paymentRequest->updateWith(reason, WTFMove(detailsPromise));
if (exception.hasException())
return exception.releaseException();
m_waitForUpdate = true;
return { };
}
EventInterface PaymentRequestUpdateEvent::eventInterface() const
{
return PaymentRequestUpdateEventInterfaceType;
}
}
#endif // ENABLE(PAYMENT_REQUEST)