1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/payments/abort_payment_event.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_extendable_event_init.h"
#include "third_party/blink/renderer/modules/event_modules.h"
#include "third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.h"
#include "third_party/blink/renderer/modules/service_worker/wait_until_observer.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink {
class AbortPaymentRespondWithFulfill final
: public ThenCallable<IDLBoolean, AbortPaymentRespondWithFulfill> {
public:
explicit AbortPaymentRespondWithFulfill(
AbortPaymentRespondWithObserver* observer)
: observer_(observer) {}
void Trace(Visitor* visitor) const override {
visitor->Trace(observer_);
ThenCallable<IDLBoolean, AbortPaymentRespondWithFulfill>::Trace(visitor);
}
void React(ScriptState* script_state, bool response) {
DCHECK(observer_);
observer_->OnResponseFulfilled(script_state, response);
}
private:
Member<AbortPaymentRespondWithObserver> observer_;
};
AbortPaymentEvent* AbortPaymentEvent::Create(
const AtomicString& type,
const ExtendableEventInit* initializer) {
return MakeGarbageCollected<AbortPaymentEvent>(type, initializer, nullptr,
nullptr);
}
AbortPaymentEvent* AbortPaymentEvent::Create(
const AtomicString& type,
const ExtendableEventInit* initializer,
AbortPaymentRespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer) {
return MakeGarbageCollected<AbortPaymentEvent>(
type, initializer, respond_with_observer, wait_until_observer);
}
AbortPaymentEvent::~AbortPaymentEvent() = default;
const AtomicString& AbortPaymentEvent::InterfaceName() const {
return event_interface_names::kAbortPaymentEvent;
}
void AbortPaymentEvent::respondWith(ScriptState* script_state,
ScriptPromise<IDLBoolean> script_promise,
ExceptionState& exception_state) {
stopImmediatePropagation();
if (observer_) {
observer_->RespondWith(
script_state, script_promise,
MakeGarbageCollected<AbortPaymentRespondWithFulfill>(observer_),
exception_state);
}
}
void AbortPaymentEvent::Trace(Visitor* visitor) const {
visitor->Trace(observer_);
ExtendableEvent::Trace(visitor);
}
AbortPaymentEvent::AbortPaymentEvent(
const AtomicString& type,
const ExtendableEventInit* initializer,
AbortPaymentRespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer)
: ExtendableEvent(type, initializer, wait_until_observer),
observer_(respond_with_observer) {}
} // namespace blink
|