Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6fa7a85e658a4c264f64826310ff7c7d33a7d685 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp |
| @@ -0,0 +1,138 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/payments/PaymentRequestUpdateEvent.h" |
| + |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "bindings/core/v8/ScriptFunction.h" |
| +#include "core/dom/DOMException.h" |
| +#include "core/dom/ExceptionCode.h" |
| +#include "modules/payments/PaymentUpdater.h" |
| + |
| +namespace blink { |
| +namespace { |
| + |
| + class UpdatePaymentDetailsFunction : public ScriptFunction { |
| + public: |
| + static v8::Local<v8::Function> createFunction(ScriptState* scriptState, PaymentUpdater* updater) |
| + { |
| + UpdatePaymentDetailsFunction* self = new UpdatePaymentDetailsFunction(scriptState, updater); |
| + return self->bindToV8Function(); |
| + } |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() |
| + { |
| + visitor->trace(m_updater); |
| + ScriptFunction::trace(visitor); |
| + } |
| + |
| + private: |
| + UpdatePaymentDetailsFunction(ScriptState* scriptState, PaymentUpdater* updater) |
| + : ScriptFunction(scriptState) |
| + , m_updater(updater) |
| + { |
| + DCHECK(m_updater); |
| + } |
| + |
| + ScriptValue call(ScriptValue value) override |
| + { |
| + m_updater->onUpdatePaymentDetails(value); |
| + return ScriptValue(); |
| + } |
| + |
| + Member<PaymentUpdater> m_updater; |
| + }; |
| + |
| + class UpdatePaymentDetailsErrorFunction : public ScriptFunction { |
| + public: |
| + static v8::Local<v8::Function> createFunction(ScriptState* scriptState, PaymentUpdater* updater) |
| + { |
| + UpdatePaymentDetailsErrorFunction* self = new UpdatePaymentDetailsErrorFunction(scriptState, updater); |
| + return self->bindToV8Function(); |
| + } |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() |
| + { |
| + visitor->trace(m_updater); |
| + ScriptFunction::trace(visitor); |
| + } |
| + |
| + private: |
| + UpdatePaymentDetailsErrorFunction(ScriptState* scriptState, PaymentUpdater* updater) |
| + : ScriptFunction(scriptState) |
| + , m_updater(updater) |
| + { |
| + DCHECK(m_updater); |
| + } |
| + |
| + ScriptValue call(ScriptValue value) override |
| + { |
| + m_updater->onUpdatePaymentDetailsFailure(value); |
| + return ScriptValue(); |
| + } |
| + |
| + Member<PaymentUpdater> m_updater; |
| + }; |
| + |
| +} // namespace |
| + |
| +PaymentRequestUpdateEvent::~PaymentRequestUpdateEvent() |
| +{ |
| +} |
| + |
| +PaymentRequestUpdateEvent* PaymentRequestUpdateEvent::create() |
| +{ |
| + return new PaymentRequestUpdateEvent(); |
| +} |
| + |
| +PaymentRequestUpdateEvent* PaymentRequestUpdateEvent::create(const AtomicString& type, const PaymentRequestUpdateEventInit& init) |
| +{ |
| + return new PaymentRequestUpdateEvent(type, init); |
| +} |
| + |
| +void PaymentRequestUpdateEvent::setPaymentDetailsUpdater(PaymentUpdater* updater) |
| +{ |
| + m_updater = updater; |
| +} |
| + |
| +void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromise promise, ExceptionState& exceptionState) |
| +{ |
| + DCHECK(m_updater); |
|
Marijn Kruisselbrink
2016/05/03 22:28:51
This can't just be a DCHECK, you need to actually
please use gerrit instead
2016/05/05 04:57:48
Done.
|
| + |
| + if (!isBeingDispatched()) { |
| + exceptionState.throwDOMException(InvalidStateError, "Cannot update details when the event is not being dispatched"); |
| + return; |
| + } |
| + |
| + if (m_waitForUpdate) { |
| + exceptionState.throwDOMException(InvalidStateError, "Cannot update details twice"); |
| + return; |
| + } |
| + |
| + stopPropagation(); |
|
Marijn Kruisselbrink
2016/05/03 22:28:51
I think calling just stopImmediatePropagation() is
please use gerrit instead
2016/05/05 04:57:48
Done.
|
| + stopImmediatePropagation(); |
| + m_waitForUpdate = true; |
| + |
| + promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_updater), |
| + UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater)); |
| +} |
| + |
| +DEFINE_TRACE(PaymentRequestUpdateEvent) |
| +{ |
| + visitor->trace(m_updater); |
| + Event::trace(visitor); |
| +} |
| + |
| +PaymentRequestUpdateEvent::PaymentRequestUpdateEvent() |
| + : m_waitForUpdate(false) |
| +{ |
| +} |
| + |
| +PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, const PaymentRequestUpdateEventInit& init) |
| + : Event(type, init) |
| + , m_waitForUpdate(false) |
| +{ |
| +} |
| + |
| +} // namespace blink |