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..2e645ac30f517485786927d34307de97d8409216 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp |
| @@ -0,0 +1,124 @@ |
| +// 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/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) |
| +{ |
| + return new PaymentRequestUpdateEvent(type); |
| +} |
| + |
| +PaymentRequestUpdateEvent* PaymentRequestUpdateEvent::create(const AtomicString& type, const PaymentRequestUpdateEventInit&) |
| +{ |
| + return new PaymentRequestUpdateEvent(type); |
|
Marijn Kruisselbrink
2016/05/03 17:57:28
You should probably pass the EventInit to the cons
please use gerrit instead
2016/05/03 21:38:33
Done.
|
| +} |
| + |
| +void PaymentRequestUpdateEvent::setPaymentDetailsUpdater(PaymentUpdater* updater) |
| +{ |
| + m_updater = updater; |
| +} |
| + |
| +void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromise promise) |
| +{ |
| + promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_updater), |
|
Marijn Kruisselbrink
2016/05/03 17:57:28
This seems to be missing the various checks from t
please use gerrit instead
2016/05/03 21:38:33
Now checking:
- The event is being fired.
- upda
|
| + UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater)); |
| +} |
| + |
| +DEFINE_TRACE(PaymentRequestUpdateEvent) |
| +{ |
| + visitor->trace(m_updater); |
| + Event::trace(visitor); |
| +} |
| + |
| +PaymentRequestUpdateEvent::PaymentRequestUpdateEvent() |
| +{ |
| +} |
| + |
| +PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type) |
| + : Event(type, false, false) |
| +{ |
| +} |
| + |
| +} // namespace blink |