Commit 60a02d2c authored by peter@chromium.org's avatar peter@chromium.org

ExtendableEvent and InstallEvent should have an EventConstructor

This brings the events in line with the Service Worker specification.

This allows us to implement events deriving from ExtendableEvent
(most notably Push, NotificationClick and NotificationError) according
to their specifications as well.

BUG=420896

Review URL: https://codereview.chromium.org/715013003

git-svn-id: svn://svn.chromium.org/blink/trunk@185365 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 10fed759
......@@ -7,5 +7,6 @@ PASS ServiceWorkerClients
PASS ServiceWorkerClient
FAIL CacheStorage assert_true: match should be an attribute of CacheStorage expected true got false
FAIL Cache assert_true: matchAll should be an attribute of Cache expected true got false
PASS Event constructors
Harness: the test ran to completion.
......@@ -62,3 +62,9 @@ promise_test(function(t) {
});
});
}, 'Cache');
test(function() {
assert_equals(new ExtendableEvent('ExtendableEvent').type, 'ExtendableEvent');
assert_equals(new InstallEvent('InstallEvent').type, 'InstallEvent');
}, 'Event constructors');
......@@ -41,7 +41,12 @@ PassRefPtrWillBeRawPtr<ExtendableEvent> ExtendableEvent::create()
return adoptRefWillBeNoop(new ExtendableEvent());
}
PassRefPtrWillBeRawPtr<ExtendableEvent> ExtendableEvent::create(const AtomicString& type, const EventInit& eventInit, WaitUntilObserver* observer)
PassRefPtrWillBeRawPtr<ExtendableEvent> ExtendableEvent::create(const AtomicString& type, const ExtendableEventInit& eventInit)
{
return adoptRefWillBeNoop(new ExtendableEvent(type, eventInit));
}
PassRefPtrWillBeRawPtr<ExtendableEvent> ExtendableEvent::create(const AtomicString& type, const ExtendableEventInit& eventInit, WaitUntilObserver* observer)
{
return adoptRefWillBeNoop(new ExtendableEvent(type, eventInit, observer));
}
......@@ -52,14 +57,20 @@ ExtendableEvent::~ExtendableEvent()
void ExtendableEvent::waitUntil(ScriptState* scriptState, const ScriptValue& value)
{
m_observer->waitUntil(scriptState, value);
if (m_observer)
m_observer->waitUntil(scriptState, value);
}
ExtendableEvent::ExtendableEvent()
{
}
ExtendableEvent::ExtendableEvent(const AtomicString& type, const EventInit& initializer, WaitUntilObserver* observer)
ExtendableEvent::ExtendableEvent(const AtomicString& type, const ExtendableEventInit& initializer)
: Event(type, initializer)
{
}
ExtendableEvent::ExtendableEvent(const AtomicString& type, const ExtendableEventInit& initializer, WaitUntilObserver* observer)
: Event(type, initializer)
, m_observer(observer)
{
......
......@@ -38,11 +38,14 @@ namespace blink {
class WaitUntilObserver;
using ExtendableEventInit = EventInit;
class ExtendableEvent : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtrWillBeRawPtr<ExtendableEvent> create();
static PassRefPtrWillBeRawPtr<ExtendableEvent> create(const AtomicString& type, const EventInit&, WaitUntilObserver*);
static PassRefPtrWillBeRawPtr<ExtendableEvent> create(const AtomicString& type, const ExtendableEventInit&);
static PassRefPtrWillBeRawPtr<ExtendableEvent> create(const AtomicString& type, const ExtendableEventInit&, WaitUntilObserver*);
virtual ~ExtendableEvent();
......@@ -53,7 +56,8 @@ public:
protected:
ExtendableEvent();
ExtendableEvent(const AtomicString& type, const EventInit&, WaitUntilObserver*);
ExtendableEvent(const AtomicString& type, const ExtendableEventInit&);
ExtendableEvent(const AtomicString& type, const ExtendableEventInit&, WaitUntilObserver*);
PersistentWillBeMember<WaitUntilObserver> m_observer;
};
......
......@@ -30,6 +30,7 @@
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#extendable-event-interface
[
EventConstructor,
RuntimeEnabled=ServiceWorker,
Exposed=ServiceWorker,
TypeChecking=Interface,
......
......@@ -42,7 +42,12 @@ PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create()
return adoptRefWillBeNoop(new InstallEvent());
}
PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& type, const EventInit& initializer, WaitUntilObserver* observer)
PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& type, const InstallEventInit& initializer)
{
return adoptRefWillBeNoop(new InstallEvent(type, initializer));
}
PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& type, const InstallEventInit& initializer, WaitUntilObserver* observer)
{
return adoptRefWillBeNoop(new InstallEvent(type, initializer, observer));
}
......@@ -56,7 +61,12 @@ InstallEvent::InstallEvent()
{
}
InstallEvent::InstallEvent(const AtomicString& type, const EventInit& initializer, WaitUntilObserver* observer)
InstallEvent::InstallEvent(const AtomicString& type, const InstallEventInit& initializer)
: ExtendableEvent(type, initializer)
{
}
InstallEvent::InstallEvent(const AtomicString& type, const InstallEventInit& initializer, WaitUntilObserver* observer)
: ExtendableEvent(type, initializer, observer)
{
}
......
......@@ -37,11 +37,14 @@
namespace blink {
using InstallEventInit = ExtendableEventInit;
class InstallEvent final : public ExtendableEvent {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtrWillBeRawPtr<InstallEvent> create();
static PassRefPtrWillBeRawPtr<InstallEvent> create(const AtomicString& type, const EventInit&, WaitUntilObserver*);
static PassRefPtrWillBeRawPtr<InstallEvent> create(const AtomicString& type, const InstallEventInit&);
static PassRefPtrWillBeRawPtr<InstallEvent> create(const AtomicString& type, const InstallEventInit&, WaitUntilObserver*);
virtual const AtomicString& interfaceName() const override;
......@@ -49,7 +52,8 @@ public:
private:
InstallEvent();
InstallEvent(const AtomicString& type, const EventInit&, WaitUntilObserver*);
InstallEvent(const AtomicString& type, const InstallEventInit&);
InstallEvent(const AtomicString& type, const InstallEventInit&, WaitUntilObserver*);
};
} // namespace blink
......
......@@ -30,6 +30,7 @@
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#install-event-interface
[
EventConstructor,
RuntimeEnabled=ServiceWorker,
Exposed=ServiceWorker,
TypeChecking=Interface,
......
......@@ -73,7 +73,7 @@ void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID)
{
ASSERT(m_workerGlobalScope);
WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::Activate, eventID);
RefPtrWillBeRawPtr<Event> event(ExtendableEvent::create(EventTypeNames::activate, EventInit(), observer));
RefPtrWillBeRawPtr<Event> event(ExtendableEvent::create(EventTypeNames::activate, ExtendableEventInit(), observer));
m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer);
}
......
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