Commit af8a094c authored by peter@chromium.org's avatar peter@chromium.org

Expose the notificationclick and notificationerror events on ServiceWorkerGlobalScope

This patch introduces the notificationclick and notificationerror
events on the ServiceWorkerGlobalScope, and provides the necessary
plumbing to be able to invoke them from the embedder.

BUG=432527

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

git-svn-id: svn://svn.chromium.org/blink/trunk@185313 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 090677ed
...@@ -5,3 +5,9 @@ test(function() { ...@@ -5,3 +5,9 @@ test(function() {
assert_true('NotificationEvent' in self); assert_true('NotificationEvent' in self);
}, 'NotificationEvent is exposed.'); }, 'NotificationEvent is exposed.');
test(function() {
assert_own_property(self, 'onnotificationclick', 'The notificationclick event exists.');
assert_own_property(self, 'onnotificationerror', 'The notificationerror event exists.');
}, 'The notificationclick and notificationerror events exist on the global scope.');
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
</head> </head>
<body> <body>
<script> <script>
// Tests that the NotificationEvent object is exposed in a ServiceWorker. // Tests that the NotificationEvent object is exposed in a ServiceWorker,
// as well as the "notificationclick" and "notificationerror" events.
service_worker_test( service_worker_test(
'resources/serviceworker-notification-event.js', 'resources/serviceworker-notification-event.js',
'Exposure of the NotificationEvent object in a ServiceWorker.'); 'Exposure of the NotificationEvent object in a ServiceWorker.');
......
...@@ -133,6 +133,8 @@ mousewheel ...@@ -133,6 +133,8 @@ mousewheel
mute mute
negotiationneeded negotiationneeded
nomatch nomatch
notificationclick
notificationerror
noupdate noupdate
obsolete obsolete
offline offline
......
...@@ -242,6 +242,7 @@ ...@@ -242,6 +242,7 @@
'navigatorcontentutils/NavigatorContentUtils.idl', 'navigatorcontentutils/NavigatorContentUtils.idl',
'netinfo/NavigatorNetworkInformation.idl', 'netinfo/NavigatorNetworkInformation.idl',
'netinfo/WorkerNavigatorNetworkInformation.idl', 'netinfo/WorkerNavigatorNetworkInformation.idl',
'notifications/ServiceWorkerGlobalScopeNotifications.idl',
'performance/SharedWorkerPerformance.idl', 'performance/SharedWorkerPerformance.idl',
'performance/WorkerGlobalScopePerformance.idl', 'performance/WorkerGlobalScopePerformance.idl',
'presentation/NavigatorPresentation.idl', 'presentation/NavigatorPresentation.idl',
...@@ -743,6 +744,7 @@ ...@@ -743,6 +744,7 @@
'notifications/NotificationPermissionCallback.h', 'notifications/NotificationPermissionCallback.h',
'notifications/NotificationPermissionClient.cpp', 'notifications/NotificationPermissionClient.cpp',
'notifications/NotificationPermissionClient.h', 'notifications/NotificationPermissionClient.h',
'notifications/ServiceWorkerGlobalScopeNotifications.h',
'performance/SharedWorkerPerformance.cpp', 'performance/SharedWorkerPerformance.cpp',
'performance/WorkerGlobalScopePerformance.cpp', 'performance/WorkerGlobalScopePerformance.cpp',
'performance/WorkerGlobalScopePerformance.h', 'performance/WorkerGlobalScopePerformance.h',
......
// Copyright 2014 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 ServiceWorkerGlobalScopeNotifications_h
#define ServiceWorkerGlobalScopeNotifications_h
#include "core/events/EventTarget.h"
namespace blink {
class ServiceWorkerGlobalScopeNotifications {
public:
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(notificationclick);
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(notificationerror);
};
} // namespace blink
#endif // ServiceWorkerGlobalScopeNotifications_h
// Copyright 2014 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://notifications.spec.whatwg.org/#service-worker-api
[
RuntimeEnabled=ServiceWorkerNotifications,
] partial interface ServiceWorkerGlobalScope {
attribute EventHandler onnotificationclick;
attribute EventHandler onnotificationerror;
};
...@@ -58,11 +58,13 @@ public: ...@@ -58,11 +58,13 @@ public:
virtual WebServiceWorkerCacheStorage* cacheStorage() const = 0; virtual WebServiceWorkerCacheStorage* cacheStorage() const = 0;
virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult) = 0; virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult) = 0;
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult) = 0;
// Calling didHandleFetchEvent without response means no response was // Calling didHandleFetchEvent without response means no response was
// provided by the service worker in the fetch events, so fallback to native. // provided by the service worker in the fetch events, so fallback to native.
virtual void didHandleFetchEvent(int fetchEventID) = 0; virtual void didHandleFetchEvent(int fetchEventID) = 0;
virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse&) = 0; virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse&) = 0;
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult) = 0;
virtual void didHandleNotificationClickEvent(int eventID, WebServiceWorkerEventResult) = 0;
virtual void didHandleNotificationErrorEvent(int eventID, WebServiceWorkerEventResult) = 0;
virtual void didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult) = 0; virtual void didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult) = 0;
virtual void didHandleSyncEvent(int syncEventID) = 0; virtual void didHandleSyncEvent(int syncEventID) = 0;
virtual void postMessageToClient(int clientID, const WebString& message, PassOwnPtr<WebMessagePortChannelArray>) = 0; virtual void postMessageToClient(int clientID, const WebString& message, PassOwnPtr<WebMessagePortChannelArray>) = 0;
......
...@@ -124,6 +124,12 @@ void WaitUntilObserver::decrementPendingActivity() ...@@ -124,6 +124,12 @@ void WaitUntilObserver::decrementPendingActivity()
case Install: case Install:
client->didHandleInstallEvent(m_eventID, result); client->didHandleInstallEvent(m_eventID, result);
break; break;
case NotificationClick:
client->didHandleNotificationClickEvent(m_eventID, result);
break;
case NotificationError:
client->didHandleNotificationErrorEvent(m_eventID, result);
break;
} }
observeContext(0); observeContext(0);
} }
......
...@@ -21,7 +21,9 @@ class WaitUntilObserver final : public GarbageCollectedFinalized<WaitUntilObserv ...@@ -21,7 +21,9 @@ class WaitUntilObserver final : public GarbageCollectedFinalized<WaitUntilObserv
public: public:
enum EventType { enum EventType {
Activate, Activate,
Install Install,
NotificationClick,
NotificationError
}; };
static WaitUntilObserver* create(ExecutionContext*, EventType, int eventID); static WaitUntilObserver* create(ExecutionContext*, EventType, int eventID);
......
...@@ -68,19 +68,29 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleActivateEvent(int eventID, Web ...@@ -68,19 +68,29 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleActivateEvent(int eventID, Web
m_client.didHandleActivateEvent(eventID, result); m_client.didHandleActivateEvent(eventID, result);
} }
void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID)
{
m_client.didHandleFetchEvent(fetchEventID);
}
void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse& webResponse)
{
m_client.didHandleFetchEvent(fetchEventID, webResponse);
}
void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result)
{ {
m_client.didHandleInstallEvent(installEventID, result); m_client.didHandleInstallEvent(installEventID, result);
} }
void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID) void ServiceWorkerGlobalScopeClientImpl::didHandleNotificationClickEvent(int eventID, WebServiceWorkerEventResult result)
{ {
m_client.didHandleFetchEvent(fetchEventID); m_client.didHandleNotificationClickEvent(eventID, result);
} }
void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse& webResponse) void ServiceWorkerGlobalScopeClientImpl::didHandleNotificationErrorEvent(int eventID, WebServiceWorkerEventResult result)
{ {
m_client.didHandleFetchEvent(fetchEventID, webResponse); m_client.didHandleNotificationErrorEvent(eventID, result);
} }
void ServiceWorkerGlobalScopeClientImpl::didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult result) void ServiceWorkerGlobalScopeClientImpl::didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult result)
......
...@@ -52,9 +52,11 @@ public: ...@@ -52,9 +52,11 @@ public:
virtual WebServiceWorkerCacheStorage* cacheStorage() const override; virtual WebServiceWorkerCacheStorage* cacheStorage() const override;
virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult) override; virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult) override;
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult) override;
virtual void didHandleFetchEvent(int fetchEventID) override; virtual void didHandleFetchEvent(int fetchEventID) override;
virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse&) override; virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse&) override;
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult) override;
virtual void didHandleNotificationClickEvent(int eventID, WebServiceWorkerEventResult) override;
virtual void didHandleNotificationErrorEvent(int eventID, WebServiceWorkerEventResult) override;
virtual void didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult) override; virtual void didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult) override;
virtual void didHandleSyncEvent(int syncEventID) override; virtual void didHandleSyncEvent(int syncEventID) override;
virtual void postMessageToClient(int clientID, const WebString& message, PassOwnPtr<WebMessagePortChannelArray>) override; virtual void postMessageToClient(int clientID, const WebString& message, PassOwnPtr<WebMessagePortChannelArray>) override;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "core/workers/WorkerGlobalScope.h" #include "core/workers/WorkerGlobalScope.h"
#include "modules/geofencing/CircularGeofencingRegion.h" #include "modules/geofencing/CircularGeofencingRegion.h"
#include "modules/geofencing/GeofencingEvent.h" #include "modules/geofencing/GeofencingEvent.h"
#include "modules/notifications/NotificationEvent.h"
#include "modules/push_messaging/PushEvent.h" #include "modules/push_messaging/PushEvent.h"
#include "modules/serviceworkers/ExtendableEvent.h" #include "modules/serviceworkers/ExtendableEvent.h"
#include "modules/serviceworkers/FetchEvent.h" #include "modules/serviceworkers/FetchEvent.h"
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
#include "modules/serviceworkers/ServiceWorkerGlobalScope.h" #include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
#include "modules/serviceworkers/WaitUntilObserver.h" #include "modules/serviceworkers/WaitUntilObserver.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "public/platform/WebNotificationData.h"
#include "public/platform/WebServiceWorkerEventResult.h" #include "public/platform/WebServiceWorkerEventResult.h"
#include "public/platform/WebServiceWorkerRequest.h" #include "public/platform/WebServiceWorkerRequest.h"
#include "public/web/WebSerializedScriptValue.h" #include "public/web/WebSerializedScriptValue.h"
...@@ -67,14 +69,6 @@ ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() ...@@ -67,14 +69,6 @@ ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy()
{ {
} }
void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID)
{
ASSERT(m_workerGlobalScope);
WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::Install, eventID);
RefPtrWillBeRawPtr<Event> event(InstallEvent::create(EventTypeNames::install, EventInit(), observer));
m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer);
}
void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID)
{ {
ASSERT(m_workerGlobalScope); ASSERT(m_workerGlobalScope);
...@@ -106,6 +100,14 @@ void ServiceWorkerGlobalScopeProxy::dispatchGeofencingEvent(int eventID, WebGeof ...@@ -106,6 +100,14 @@ void ServiceWorkerGlobalScopeProxy::dispatchGeofencingEvent(int eventID, WebGeof
m_workerGlobalScope->dispatchEvent(GeofencingEvent::create(type, regionID, CircularGeofencingRegion::create(regionID, region))); m_workerGlobalScope->dispatchEvent(GeofencingEvent::create(type, regionID, CircularGeofencingRegion::create(regionID, region)));
} }
void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID)
{
ASSERT(m_workerGlobalScope);
WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::Install, eventID);
RefPtrWillBeRawPtr<Event> event(InstallEvent::create(EventTypeNames::install, EventInit(), observer));
m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer);
}
void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& webChannels) void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& webChannels)
{ {
ASSERT(m_workerGlobalScope); ASSERT(m_workerGlobalScope);
...@@ -115,6 +117,26 @@ void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag ...@@ -115,6 +117,26 @@ void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), value)); m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), value));
} }
void ServiceWorkerGlobalScopeProxy::dispatchNotificationClickEvent(int eventID, const WebNotificationData& data)
{
ASSERT(m_workerGlobalScope);
WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::NotificationClick, eventID);
// FIXME: Initialize a Notification object based on |data|.
NotificationEventInit eventInit;
RefPtrWillBeRawPtr<Event> event(NotificationEvent::create(EventTypeNames::notificationclick, eventInit, observer));
m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer);
}
void ServiceWorkerGlobalScopeProxy::dispatchNotificationErrorEvent(int eventID, const WebNotificationData& data)
{
ASSERT(m_workerGlobalScope);
WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::NotificationError, eventID);
// FIXME: Initialize a Notification object based on |data|.
NotificationEventInit eventInit;
RefPtrWillBeRawPtr<Event> event(NotificationEvent::create(EventTypeNames::notificationerror, eventInit, observer));
m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer);
}
void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebString& data) void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebString& data)
{ {
ASSERT(m_workerGlobalScope); ASSERT(m_workerGlobalScope);
......
...@@ -69,10 +69,12 @@ public: ...@@ -69,10 +69,12 @@ public:
// WebServiceWorkerContextProxy overrides: // WebServiceWorkerContextProxy overrides:
virtual void dispatchActivateEvent(int) override; virtual void dispatchActivateEvent(int) override;
virtual void dispatchInstallEvent(int) override;
virtual void dispatchFetchEvent(int, const WebServiceWorkerRequest&) override; virtual void dispatchFetchEvent(int, const WebServiceWorkerRequest&) override;
virtual void dispatchGeofencingEvent(int, WebGeofencingEventType, const WebString& regionID, const WebCircularGeofencingRegion&) override; virtual void dispatchGeofencingEvent(int, WebGeofencingEventType, const WebString& regionID, const WebCircularGeofencingRegion&) override;
virtual void dispatchInstallEvent(int) override;
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray&) override; virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray&) override;
virtual void dispatchNotificationClickEvent(int eventID, const WebNotificationData&) override;
virtual void dispatchNotificationErrorEvent(int eventID, const WebNotificationData&) override;
virtual void dispatchPushEvent(int, const WebString& data) override; virtual void dispatchPushEvent(int, const WebString& data) override;
virtual void dispatchSyncEvent(int) override; virtual void dispatchSyncEvent(int) override;
......
...@@ -111,17 +111,23 @@ public: ...@@ -111,17 +111,23 @@ public:
// ServiceWorker specific method. // ServiceWorker specific method.
virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult result) { } virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult result) { }
// ServiceWorker specific method. Called after InstallEvent (dispatched
// via WebServiceWorkerContextProxy) is handled by the ServiceWorker's
// script context.
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) { }
// ServiceWorker specific methods. Called after FetchEvent is handled by the // ServiceWorker specific methods. Called after FetchEvent is handled by the
// ServiceWorker's script context. When no response is provided, the browser // ServiceWorker's script context. When no response is provided, the browser
// should fallback to native fetch. // should fallback to native fetch.
virtual void didHandleFetchEvent(int fetchEventID) { } virtual void didHandleFetchEvent(int fetchEventID) { }
virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse& response) { } virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse& response) { }
// ServiceWorker specific method. Called after InstallEvent (dispatched
// via WebServiceWorkerContextProxy) is handled by the ServiceWorker's
// script context.
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) { }
// ServiceWorker specific method. Called after NotificationClickEvent and
// NotificationErrorEvent (dispatched via WebServiceWorkerContextProxy) are
// handled by the ServiceWorker's script context.
virtual void didHandleNotificationClickEvent(int eventID, WebServiceWorkerEventResult result) { }
virtual void didHandleNotificationErrorEvent(int eventID, WebServiceWorkerEventResult result) { }
// ServiceWorker specific method. Called after PushEvent (dispatched via // ServiceWorker specific method. Called after PushEvent (dispatched via
// WebServiceWorkerContextProxy) is handled by the ServiceWorker's script // WebServiceWorkerContextProxy) is handled by the ServiceWorker's script
// context. // context.
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
namespace blink { namespace blink {
struct WebCircularGeofencingRegion; struct WebCircularGeofencingRegion;
struct WebNotificationData;
class WebServiceWorkerRequest; class WebServiceWorkerRequest;
class WebString; class WebString;
...@@ -55,6 +56,9 @@ public: ...@@ -55,6 +56,9 @@ public:
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& channels) = 0; virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& channels) = 0;
virtual void dispatchNotificationClickEvent(int eventID, const WebNotificationData&) = 0;
virtual void dispatchNotificationErrorEvent(int eventID, const WebNotificationData&) = 0;
virtual void dispatchPushEvent(int eventID, const WebString& data) = 0; virtual void dispatchPushEvent(int eventID, const WebString& data) = 0;
// Once the ServiceWorker has finished handling the sync event // Once the ServiceWorker has finished handling the sync event
......
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