Commit 2d1d3d0a authored by Jinho Bang's avatar Jinho Bang Committed by Commit Bot

PaymentHandler: Add Interfaces for AbortPaymentEvent.

This is an initial implementation of AbortPaymentEvent in WebIDL level.

Related spec change:
  https://github.com/w3c/payment-handler/pull/170

Bug: 736745
Change-Id: I5cdf6b8e6a8019121aed4e10d33e884076bb519b
Reviewed-on: https://chromium-review.googlesource.com/571345
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487463}
parent 99a3034d
<!doctype html>
<meta charset="utf-8">
<title>Payment App: Tests for AbortPaymentEvent</title>
<link rel="help" href="https://github.com/w3c/payment-handler/pull/170">
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script>
'use strict';
// Tests that the AbortPaymentEvent is in a ServiceWorkerGloablContext and
// exposes its members (e.g. respondWith, waitUntil and data).
service_worker_test(
'resources/abort-payment-event.js',
'Exposure of the AbortPaymentEvent object in a Service Worker.');
</script>
importScripts('../../serviceworker/resources/worker-testharness.js');
test(() => {
assert_true('AbortPaymentEvent' in self);
assert_inherits(AbortPaymentEvent.prototype, 'waitUntil');
assert_own_property(AbortPaymentEvent.prototype, 'respondWith');
});
promise_test(() => {
return new Promise(resolve => {
var abortEvent = new AbortPaymentEvent('abortpayment', {});
self.addEventListener('abortpayment', e => {
resolve();
});
self.dispatchEvent(abortEvent);
});
});
[INTERFACES] [INTERFACES]
interface AbortPaymentEvent : ExtendableEvent
attribute @@toStringTag
method constructor
method respondWith
interface BackgroundFetchClickEvent : BackgroundFetchEvent interface BackgroundFetchClickEvent : BackgroundFetchEvent
attribute @@toStringTag attribute @@toStringTag
getter state getter state
...@@ -2467,6 +2471,7 @@ interface WritableStream ...@@ -2467,6 +2471,7 @@ interface WritableStream
attribute console attribute console
attribute internals attribute internals
getter clients getter clients
getter onabortpayment
getter onactivate getter onactivate
getter onbackgroundfetchabort getter onbackgroundfetchabort
getter onbackgroundfetchclick getter onbackgroundfetchclick
...@@ -2486,6 +2491,7 @@ interface WritableStream ...@@ -2486,6 +2491,7 @@ interface WritableStream
method fetch method fetch
method gc method gc
method skipWaiting method skipWaiting
setter onabortpayment
setter onactivate setter onactivate
setter onbackgroundfetchabort setter onbackgroundfetchabort
setter onbackgroundfetchclick setter onbackgroundfetchclick
......
[INTERFACES] [INTERFACES]
interface AbortPaymentEvent : ExtendableEvent
attribute @@toStringTag
method constructor
method respondWith
interface BackgroundFetchClickEvent : BackgroundFetchEvent interface BackgroundFetchClickEvent : BackgroundFetchEvent
attribute @@toStringTag attribute @@toStringTag
getter state getter state
...@@ -2458,6 +2462,7 @@ interface WritableStream ...@@ -2458,6 +2462,7 @@ interface WritableStream
attribute console attribute console
attribute internals attribute internals
getter clients getter clients
getter onabortpayment
getter onactivate getter onactivate
getter onbackgroundfetchabort getter onbackgroundfetchabort
getter onbackgroundfetchclick getter onbackgroundfetchclick
...@@ -2477,6 +2482,7 @@ interface WritableStream ...@@ -2477,6 +2482,7 @@ interface WritableStream
method fetch method fetch
method gc method gc
method skipWaiting method skipWaiting
setter onabortpayment
setter onactivate setter onactivate
setter onbackgroundfetchabort setter onbackgroundfetchabort
setter onbackgroundfetchclick setter onbackgroundfetchclick
......
interface AbortPaymentEvent : ExtendableEvent
attribute @@toStringTag
method constructor
method respondWith
interface BackgroundFetchClickEvent : BackgroundFetchEvent interface BackgroundFetchClickEvent : BackgroundFetchEvent
getter state getter state
method constructor method constructor
...@@ -2293,6 +2297,7 @@ global object ...@@ -2293,6 +2297,7 @@ global object
attribute console attribute console
attribute internals attribute internals
getter clients getter clients
getter onabortpayment
getter onactivate getter onactivate
getter onbackgroundfetchabort getter onbackgroundfetchabort
getter onbackgroundfetchclick getter onbackgroundfetchclick
...@@ -2312,6 +2317,7 @@ global object ...@@ -2312,6 +2317,7 @@ global object
method fetch method fetch
method gc method gc
method skipWaiting method skipWaiting
setter onabortpayment
setter onactivate setter onactivate
setter onbackgroundfetchabort setter onbackgroundfetchabort
setter onbackgroundfetchclick setter onbackgroundfetchclick
......
...@@ -34,6 +34,7 @@ generate_event_interfaces("modules_bindings_generated_event_interfaces") { ...@@ -34,6 +34,7 @@ generate_event_interfaces("modules_bindings_generated_event_interfaces") {
"//third_party/WebKit/Source/modules/mediastream/MediaStreamEvent.idl", "//third_party/WebKit/Source/modules/mediastream/MediaStreamEvent.idl",
"//third_party/WebKit/Source/modules/mediastream/MediaStreamTrackEvent.idl", "//third_party/WebKit/Source/modules/mediastream/MediaStreamTrackEvent.idl",
"//third_party/WebKit/Source/modules/notifications/NotificationEvent.idl", "//third_party/WebKit/Source/modules/notifications/NotificationEvent.idl",
"//third_party/WebKit/Source/modules/payments/AbortPaymentEvent.idl",
"//third_party/WebKit/Source/modules/payments/CanMakePaymentEvent.idl", "//third_party/WebKit/Source/modules/payments/CanMakePaymentEvent.idl",
"//third_party/WebKit/Source/modules/payments/PaymentRequestEvent.idl", "//third_party/WebKit/Source/modules/payments/PaymentRequestEvent.idl",
"//third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.idl", "//third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.idl",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"DOMNodeRemovedFromDocument", "DOMNodeRemovedFromDocument",
"DOMSubtreeModified", "DOMSubtreeModified",
"abort", "abort",
"abortpayment",
"activate", "activate",
"active", "active",
"addsourcebuffer", "addsourcebuffer",
......
...@@ -178,6 +178,7 @@ modules_idl_files = ...@@ -178,6 +178,7 @@ modules_idl_files =
"notifications/NotificationEvent.idl", "notifications/NotificationEvent.idl",
"notifications/NotificationPermissionCallback.idl", "notifications/NotificationPermissionCallback.idl",
"offscreencanvas2d/OffscreenCanvasRenderingContext2D.idl", "offscreencanvas2d/OffscreenCanvasRenderingContext2D.idl",
"payments/AbortPaymentEvent.idl",
"payments/CanMakePaymentEvent.idl", "payments/CanMakePaymentEvent.idl",
"payments/PaymentAddress.idl", "payments/PaymentAddress.idl",
"payments/PaymentInstruments.idl", "payments/PaymentInstruments.idl",
......
// Copyright 2017 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/AbortPaymentEvent.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "modules/EventModules.h"
#include "modules/serviceworkers/ExtendableEventInit.h"
#include "modules/serviceworkers/RespondWithObserver.h"
#include "modules/serviceworkers/WaitUntilObserver.h"
#include "platform/bindings/ScriptState.h"
#include "platform/wtf/text/AtomicString.h"
namespace blink {
AbortPaymentEvent* AbortPaymentEvent::Create(
const AtomicString& type,
const ExtendableEventInit& initializer) {
return new AbortPaymentEvent(type, initializer, nullptr, nullptr);
}
AbortPaymentEvent* AbortPaymentEvent::Create(
const AtomicString& type,
const ExtendableEventInit& initializer,
RespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer) {
return new AbortPaymentEvent(type, initializer, respond_with_observer,
wait_until_observer);
}
AbortPaymentEvent::~AbortPaymentEvent() {}
const AtomicString& AbortPaymentEvent::InterfaceName() const {
return EventNames::AbortPaymentEvent;
}
void AbortPaymentEvent::respondWith(ScriptState* script_state,
ScriptPromise script_promise,
ExceptionState& exception_state) {
stopImmediatePropagation();
if (observer_) {
observer_->RespondWith(script_state, script_promise, exception_state);
}
}
DEFINE_TRACE(AbortPaymentEvent) {
visitor->Trace(observer_);
ExtendableEvent::Trace(visitor);
}
AbortPaymentEvent::AbortPaymentEvent(const AtomicString& type,
const ExtendableEventInit& initializer,
RespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer)
: ExtendableEvent(type, initializer, wait_until_observer),
observer_(respond_with_observer) {}
} // namespace blink
// Copyright 2017 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.
#ifndef AbortPaymentEvent_h
#define AbortPaymentEvent_h
#include "modules/EventModules.h"
#include "modules/serviceworkers/ExtendableEvent.h"
#include "platform/bindings/ScriptWrappable.h"
#include "platform/heap/Handle.h"
#include "platform/wtf/Noncopyable.h"
namespace WTF {
class AtomicString;
}
namespace blink {
class ExtendableEventInit;
class RespondWithObserver;
class ScriptState;
class MODULES_EXPORT AbortPaymentEvent final : public ExtendableEvent {
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(AbortPaymentEvent);
public:
static AbortPaymentEvent* Create(const AtomicString& type,
const ExtendableEventInit&);
static AbortPaymentEvent* Create(const AtomicString& type,
const ExtendableEventInit&,
RespondWithObserver*,
WaitUntilObserver*);
~AbortPaymentEvent() override;
const AtomicString& InterfaceName() const override;
void respondWith(ScriptState*, ScriptPromise, ExceptionState&);
DECLARE_VIRTUAL_TRACE();
private:
AbortPaymentEvent(const AtomicString& type,
const ExtendableEventInit&,
RespondWithObserver*,
WaitUntilObserver*);
Member<RespondWithObserver> observer_;
};
} // namespace blink
#endif // AbortPaymentEvent_h
// Copyright 2017 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.
// https://github.com/w3c/payment-handler/pull/170
[
RuntimeEnabled=PaymentApp,
Constructor(DOMString type, ExtendableEventInit eventInitDict),
Exposed=ServiceWorker
] interface AbortPaymentEvent : ExtendableEvent {
[CallWith=ScriptState, RaisesException] void respondWith(Promise<boolean> paymentAbortedResponse);
};
...@@ -6,6 +6,8 @@ import("//third_party/WebKit/Source/modules/modules.gni") ...@@ -6,6 +6,8 @@ import("//third_party/WebKit/Source/modules/modules.gni")
blink_modules_sources("payments") { blink_modules_sources("payments") {
sources = [ sources = [
"AbortPaymentEvent.cpp",
"AbortPaymentEvent.h",
"CanMakePaymentEvent.cpp", "CanMakePaymentEvent.cpp",
"CanMakePaymentEvent.h", "CanMakePaymentEvent.h",
"CanMakePaymentRespondWithObserver.cpp", "CanMakePaymentRespondWithObserver.cpp",
......
...@@ -14,6 +14,7 @@ class PaymentAppServiceWorkerGlobalScope { ...@@ -14,6 +14,7 @@ class PaymentAppServiceWorkerGlobalScope {
STATIC_ONLY(PaymentAppServiceWorkerGlobalScope); STATIC_ONLY(PaymentAppServiceWorkerGlobalScope);
public: public:
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(abortpayment);
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(canmakepayment); DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(canmakepayment);
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(paymentrequest); DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(paymentrequest);
}; };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
[ [
RuntimeEnabled=PaymentApp RuntimeEnabled=PaymentApp
] partial interface ServiceWorkerGlobalScope { ] partial interface ServiceWorkerGlobalScope {
attribute EventHandler onabortpayment;
attribute EventHandler oncanmakepayment; attribute EventHandler oncanmakepayment;
attribute EventHandler onpaymentrequest; attribute EventHandler onpaymentrequest;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment