Commit 6f069ab9 authored by peter@chromium.org's avatar peter@chromium.org

Introduce the NotificationEvent object.

Notification events delivered to Service Workers (notificationclick
and notificationerror) will receive an instance of the Notification
object which they were triggered for, represented through a
NotificationEvent. It's of the SW ExtendableEvent type.

BUG=432527

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

git-svn-id: svn://svn.chromium.org/blink/trunk@185296 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fc16ecb3
importScripts('../../serviceworker/resources/worker-testharness.js');
importScripts('/resources/testharness-helpers.js');
test(function() {
assert_true('NotificationEvent' in self);
}, 'NotificationEvent is exposed.');
<!doctype html>
<html>
<head>
<title>Notifications: NotificationEvent exposure in a Service Worker.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
</head>
<body>
<script>
// Tests that the NotificationEvent object is exposed in a ServiceWorker.
service_worker_test(
'resources/serviceworker-notification-event.js',
'Exposure of the NotificationEvent object in a ServiceWorker.');
</script>
</body>
</html>
\ No newline at end of file
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
'mediastream/SourceInfo.idl', 'mediastream/SourceInfo.idl',
'netinfo/NetworkInformation.idl', 'netinfo/NetworkInformation.idl',
'notifications/Notification.idl', 'notifications/Notification.idl',
'notifications/NotificationEvent.idl',
'notifications/NotificationPermissionCallback.idl', 'notifications/NotificationPermissionCallback.idl',
'performance/WorkerPerformance.idl', 'performance/WorkerPerformance.idl',
'presentation/Presentation.idl', 'presentation/Presentation.idl',
...@@ -273,6 +274,7 @@ ...@@ -273,6 +274,7 @@
'mediastream/RTCDTMFToneChangeEvent.idl', 'mediastream/RTCDTMFToneChangeEvent.idl',
'mediastream/RTCDataChannelEvent.idl', 'mediastream/RTCDataChannelEvent.idl',
'mediastream/RTCIceCandidateEvent.idl', 'mediastream/RTCIceCandidateEvent.idl',
'notifications/NotificationEvent.idl',
'push_messaging/PushEvent.idl', 'push_messaging/PushEvent.idl',
'serviceworkers/ExtendableEvent.idl', 'serviceworkers/ExtendableEvent.idl',
'serviceworkers/FetchEvent.idl', 'serviceworkers/FetchEvent.idl',
...@@ -736,6 +738,8 @@ ...@@ -736,6 +738,8 @@
'notifications/NotificationClient.h', 'notifications/NotificationClient.h',
'notifications/NotificationController.cpp', 'notifications/NotificationController.cpp',
'notifications/NotificationController.h', 'notifications/NotificationController.h',
'notifications/NotificationEvent.cpp',
'notifications/NotificationEvent.h',
'notifications/NotificationPermissionCallback.h', 'notifications/NotificationPermissionCallback.h',
'notifications/NotificationPermissionClient.cpp', 'notifications/NotificationPermissionClient.cpp',
'notifications/NotificationPermissionClient.h', 'notifications/NotificationPermissionClient.h',
......
...@@ -3,8 +3,10 @@ include_rules = [ ...@@ -3,8 +3,10 @@ include_rules = [
"+core", "+core",
"+heap", "+heap",
"-modules", "-modules",
"+modules/EventModules.h",
"+modules/EventTargetModules.h", "+modules/EventTargetModules.h",
"+modules/notifications", "+modules/notifications",
"+modules/serviceworkers",
"+platform", "+platform",
"+public/platform", "+public/platform",
"-web", "-web",
......
// 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.
#include "config.h"
#include "modules/notifications/NotificationEvent.h"
namespace blink {
NotificationEventInit::NotificationEventInit()
{
}
NotificationEvent::NotificationEvent()
{
}
NotificationEvent::NotificationEvent(const AtomicString& type, const NotificationEventInit& initializer, WaitUntilObserver* observer)
: ExtendableEvent(type, initializer, observer)
, m_notification(initializer.notification)
{
}
NotificationEvent::~NotificationEvent()
{
}
const AtomicString& NotificationEvent::interfaceName() const
{
return EventNames::NotificationEvent;
}
void NotificationEvent::trace(Visitor* visitor)
{
visitor->trace(m_notification);
ExtendableEvent::trace(visitor);
}
} // namespace blink
// 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 NotificationEvent_h
#define NotificationEvent_h
#include "modules/EventModules.h"
#include "modules/notifications/Notification.h"
#include "modules/serviceworkers/ExtendableEvent.h"
#include "platform/heap/Handle.h"
namespace blink {
struct NotificationEventInit : public EventInit {
NotificationEventInit();
Member<Notification> notification;
};
class NotificationEvent final : public ExtendableEvent {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtrWillBeRawPtr<NotificationEvent> create()
{
return adoptRefWillBeNoop(new NotificationEvent);
}
static PassRefPtrWillBeRawPtr<NotificationEvent> create(const AtomicString& type, const NotificationEventInit& initializer, WaitUntilObserver* observer)
{
return adoptRefWillBeNoop(new NotificationEvent(type, initializer, observer));
}
~NotificationEvent() override;
Notification* notification() const { return m_notification.get(); }
const AtomicString& interfaceName() const override;
void trace(Visitor*) override;
private:
NotificationEvent();
NotificationEvent(const AtomicString& type, const NotificationEventInit&, WaitUntilObserver*);
PersistentWillBeMember<Notification> m_notification;
};
} // namespace blink
#endif // NotificationEvent_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
// FIXME: NotificationEvent should support being constructed from JavaScript.
[
Exposed=ServiceWorker,
RuntimeEnabled=ServiceWorkerNotifications,
TypeChecking=Interface,
] interface NotificationEvent : ExtendableEvent {
readonly attribute Notification notification;
};
...@@ -117,6 +117,7 @@ ScrollTopLeftInterop status=experimental ...@@ -117,6 +117,7 @@ ScrollTopLeftInterop status=experimental
ShowModalDialog status=deprecated ShowModalDialog status=deprecated
ServiceWorker status=stable ServiceWorker status=stable
ServiceWorkerCache status=stable ServiceWorkerCache status=stable
ServiceWorkerNotifications status=experimental
ServiceWorkerOnFetch status=stable ServiceWorkerOnFetch status=stable
SessionStorage status=stable SessionStorage status=stable
SharedWorker status=stable SharedWorker status=stable
......
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