summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/notifications
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/notifications
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/Modules/notifications')
-rw-r--r--Source/WebCore/Modules/notifications/DOMWindowNotifications.cpp42
-rw-r--r--Source/WebCore/Modules/notifications/DOMWindowNotifications.h24
-rw-r--r--Source/WebCore/Modules/notifications/DOMWindowNotifications.idl4
-rw-r--r--Source/WebCore/Modules/notifications/Notification.cpp156
-rw-r--r--Source/WebCore/Modules/notifications/Notification.h153
-rw-r--r--Source/WebCore/Modules/notifications/Notification.idl62
-rw-r--r--Source/WebCore/Modules/notifications/NotificationCenter.cpp101
-rw-r--r--Source/WebCore/Modules/notifications/NotificationCenter.h63
-rw-r--r--Source/WebCore/Modules/notifications/NotificationCenter.idl11
-rw-r--r--Source/WebCore/Modules/notifications/NotificationClient.h24
-rw-r--r--Source/WebCore/Modules/notifications/NotificationController.cpp27
-rw-r--r--Source/WebCore/Modules/notifications/NotificationController.h24
-rw-r--r--Source/WebCore/Modules/notifications/NotificationPermissionCallback.h9
-rw-r--r--Source/WebCore/Modules/notifications/NotificationPermissionCallback.idl8
-rw-r--r--Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.cpp26
-rw-r--r--Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.h21
-rw-r--r--Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.idl4
17 files changed, 338 insertions, 421 deletions
diff --git a/Source/WebCore/Modules/notifications/DOMWindowNotifications.cpp b/Source/WebCore/Modules/notifications/DOMWindowNotifications.cpp
index 21a6b9352..be9d681b3 100644
--- a/Source/WebCore/Modules/notifications/DOMWindowNotifications.cpp
+++ b/Source/WebCore/Modules/notifications/DOMWindowNotifications.cpp
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -56,27 +56,28 @@ DOMWindowNotifications* DOMWindowNotifications::from(DOMWindow* window)
{
DOMWindowNotifications* supplement = static_cast<DOMWindowNotifications*>(Supplement<DOMWindow>::from(window, supplementName()));
if (!supplement) {
- supplement = new DOMWindowNotifications(window);
- Supplement<DOMWindow>::provideTo(window, supplementName(), adoptPtr(supplement));
+ auto newSupplement = std::make_unique<DOMWindowNotifications>(window);
+ supplement = newSupplement.get();
+ provideTo(window, supplementName(), WTFMove(newSupplement));
}
return supplement;
}
-NotificationCenter* DOMWindowNotifications::webkitNotifications(DOMWindow* window)
+NotificationCenter* DOMWindowNotifications::webkitNotifications(DOMWindow& window)
{
- return DOMWindowNotifications::from(window)->webkitNotifications();
+ return DOMWindowNotifications::from(&window)->webkitNotifications();
}
-void DOMWindowNotifications::disconnectFrameForPageCache()
+void DOMWindowNotifications::disconnectFrameForDocumentSuspension()
{
- m_suspendedNotificationCenter = m_notificationCenter.release();
- DOMWindowProperty::disconnectFrameForPageCache();
+ m_suspendedNotificationCenter = WTFMove(m_notificationCenter);
+ DOMWindowProperty::disconnectFrameForDocumentSuspension();
}
-void DOMWindowNotifications::reconnectFrameFromPageCache(Frame* frame)
+void DOMWindowNotifications::reconnectFrameFromDocumentSuspension(Frame* frame)
{
- DOMWindowProperty::reconnectFrameFromPageCache(frame);
- m_notificationCenter = m_suspendedNotificationCenter.release();
+ DOMWindowProperty::reconnectFrameFromDocumentSuspension(frame);
+ m_notificationCenter = WTFMove(m_suspendedNotificationCenter);
}
void DOMWindowNotifications::willDestroyGlobalObjectInCachedFrame()
@@ -100,23 +101,24 @@ void DOMWindowNotifications::willDetachGlobalObjectFromFrame()
NotificationCenter* DOMWindowNotifications::webkitNotifications()
{
if (!m_window->isCurrentlyDisplayedInFrame())
- return 0;
+ return nullptr;
if (m_notificationCenter)
return m_notificationCenter.get();
- Document* document = m_window->document();
+ auto* document = m_window->document();
if (!document)
- return 0;
+ return nullptr;
- Page* page = document->page();
+ auto* page = document->page();
if (!page)
- return 0;
+ return nullptr;
- NotificationClient* provider = NotificationController::clientFrom(page);
- if (provider)
- m_notificationCenter = NotificationCenter::create(document, provider);
+ auto* provider = NotificationController::clientFrom(*page);
+ if (!provider)
+ return nullptr;
+ m_notificationCenter = NotificationCenter::create(*document, provider);
return m_notificationCenter.get();
}
diff --git a/Source/WebCore/Modules/notifications/DOMWindowNotifications.h b/Source/WebCore/Modules/notifications/DOMWindowNotifications.h
index c8e2206b5..7fd5ba671 100644
--- a/Source/WebCore/Modules/notifications/DOMWindowNotifications.h
+++ b/Source/WebCore/Modules/notifications/DOMWindowNotifications.h
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -24,8 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef DOMWindowNotifications_h
-#define DOMWindowNotifications_h
+#pragma once
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
@@ -40,20 +39,19 @@ class NotificationCenter;
class DOMWindowNotifications : public Supplement<DOMWindow>, public DOMWindowProperty {
public:
+ explicit DOMWindowNotifications(DOMWindow*);
virtual ~DOMWindowNotifications();
- static NotificationCenter* webkitNotifications(DOMWindow*);
+ static NotificationCenter* webkitNotifications(DOMWindow&);
static DOMWindowNotifications* from(DOMWindow*);
- virtual void disconnectFrameForPageCache() override;
- virtual void reconnectFrameFromPageCache(Frame*) override;
- virtual void willDestroyGlobalObjectInCachedFrame() override;
- virtual void willDestroyGlobalObjectInFrame() override;
- virtual void willDetachGlobalObjectFromFrame() override;
+ void disconnectFrameForDocumentSuspension() override;
+ void reconnectFrameFromDocumentSuspension(Frame*) override;
+ void willDestroyGlobalObjectInCachedFrame() override;
+ void willDestroyGlobalObjectInFrame() override;
+ void willDetachGlobalObjectFromFrame() override;
private:
- explicit DOMWindowNotifications(DOMWindow*);
-
NotificationCenter* webkitNotifications();
static const char* supplementName();
@@ -65,5 +63,3 @@ private:
} // namespace WebCore
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
-
-#endif // DOMWindowNotifications_h
diff --git a/Source/WebCore/Modules/notifications/DOMWindowNotifications.idl b/Source/WebCore/Modules/notifications/DOMWindowNotifications.idl
index 0e5039bcc..50ddfb2db 100644
--- a/Source/WebCore/Modules/notifications/DOMWindowNotifications.idl
+++ b/Source/WebCore/Modules/notifications/DOMWindowNotifications.idl
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
diff --git a/Source/WebCore/Modules/notifications/Notification.cpp b/Source/WebCore/Modules/notifications/Notification.cpp
index 20cc0c309..1e02ce1cf 100644
--- a/Source/WebCore/Modules/notifications/Notification.cpp
+++ b/Source/WebCore/Modules/notifications/Notification.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011, 2012, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -37,60 +37,46 @@
#include "DOMWindow.h"
#include "DOMWindowNotifications.h"
-#include "Dictionary.h"
#include "Document.h"
-#include "ErrorEvent.h"
+#include "Event.h"
#include "EventNames.h"
+#include "ExceptionCode.h"
#include "NotificationCenter.h"
-#include "NotificationClient.h"
#include "NotificationController.h"
#include "NotificationPermissionCallback.h"
-#include "ResourceRequest.h"
-#include "ResourceResponse.h"
-#include "ThreadableLoader.h"
+#include "VoidCallback.h"
#include "WindowFocusAllowedIndicator.h"
-#include "WorkerGlobalScope.h"
namespace WebCore {
-Notification::Notification()
- : ActiveDOMObject(0)
-{
-}
-
#if ENABLE(LEGACY_NOTIFICATIONS)
-Notification::Notification(const String& title, const String& body, const String& iconURI, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider)
- : ActiveDOMObject(context)
+
+Notification::Notification(const String& title, const String& body, URL&& iconURL, ScriptExecutionContext& context, NotificationCenter& notificationCenter)
+ : ActiveDOMObject(&context)
+ , m_icon(WTFMove(iconURL))
, m_title(title)
, m_body(body)
- , m_state(Idle)
- , m_notificationCenter(provider)
+ , m_notificationCenter(&notificationCenter)
{
- if (m_notificationCenter->checkPermission() != NotificationClient::PermissionAllowed) {
- ec = SECURITY_ERR;
- return;
- }
-
- m_icon = iconURI.isEmpty() ? URL() : scriptExecutionContext()->completeURL(iconURI);
- if (!m_icon.isEmpty() && !m_icon.isValid()) {
- ec = SYNTAX_ERR;
- return;
- }
}
+
#endif
#if ENABLE(NOTIFICATIONS)
-Notification::Notification(ScriptExecutionContext& context, const String& title)
- : ActiveDOMObject(&context)
+
+Notification::Notification(Document& document, const String& title)
+ : ActiveDOMObject(&document)
, m_title(title)
, m_state(Idle)
- , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTimerFired)))
+ , m_notificationCenter(DOMWindowNotifications::webkitNotifications(*document.domWindow()))
+ , m_taskTimer(std::make_unique<Timer>([this] () { show(); }))
{
- m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocument(context).domWindow());
-
+ // FIXME: Seems that m_notificationCenter can be null so should not be changed from RefPtr to Ref.
+ // But the rest of the code in this class isn't trying to handle that case.
ASSERT(m_notificationCenter->client());
m_taskTimer->startOneShot(0);
}
+
#endif
Notification::~Notification()
@@ -98,36 +84,57 @@ Notification::~Notification()
}
#if ENABLE(LEGACY_NOTIFICATIONS)
-PassRefPtr<Notification> Notification::create(const String& title, const String& body, const String& iconURI, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider)
+
+ExceptionOr<Ref<Notification>> Notification::create(const String& title, const String& body, const String& iconURL, ScriptExecutionContext& context, NotificationCenter& provider)
{
- RefPtr<Notification> notification(adoptRef(new Notification(title, body, iconURI, context, ec, provider)));
- notification->suspendIfNeeded();
- return notification.release();
+ if (provider.checkPermission() != NotificationClient::PermissionAllowed)
+ return Exception { SECURITY_ERR };
+
+ URL completedIconURL = iconURL.isEmpty() ? URL() : context.completeURL(iconURL);
+ if (!completedIconURL.isEmpty() && !completedIconURL.isValid())
+ return Exception { SYNTAX_ERR };
+
+ auto notification = adoptRef(*new Notification(title, body, WTFMove(completedIconURL), context, provider));
+ notification.get().suspendIfNeeded();
+ return WTFMove(notification);
}
+
#endif
#if ENABLE(NOTIFICATIONS)
-PassRefPtr<Notification> Notification::create(ScriptExecutionContext& context, const String& title, const Dictionary& options)
-{
- RefPtr<Notification> notification(adoptRef(new Notification(context, title)));
- String argument;
- if (options.get("body", argument))
- notification->setBody(argument);
- if (options.get("tag", argument))
- notification->setTag(argument);
- if (options.get("lang", argument))
- notification->setLang(argument);
- if (options.get("dir", argument))
- notification->setDir(argument);
- if (options.get("icon", argument)) {
- URL iconURI = argument.isEmpty() ? URL() : context.completeURL(argument);
- if (!iconURI.isEmpty() && iconURI.isValid())
- notification->setIconURL(iconURI);
+
+static String directionString(Notification::Direction direction)
+{
+ // FIXME: Storing this as a string is not the right way to do it.
+ // FIXME: Seems highly unlikely that this does the right thing for Auto.
+ switch (direction) {
+ case Notification::Direction::Auto:
+ return ASCIILiteral("auto");
+ case Notification::Direction::Ltr:
+ return ASCIILiteral("ltr");
+ case Notification::Direction::Rtl:
+ return ASCIILiteral("rtl");
}
+ ASSERT_NOT_REACHED();
+ return { };
+}
- notification->suspendIfNeeded();
- return notification.release();
+Ref<Notification> Notification::create(Document& context, const String& title, const Options& options)
+{
+ auto notification = adoptRef(*new Notification(context, title));
+ notification.get().m_body = options.body;
+ notification.get().m_tag = options.tag;
+ notification.get().m_lang = options.lang;
+ notification.get().m_direction = directionString(options.dir);
+ if (!options.icon.isEmpty()) {
+ auto iconURL = context.completeURL(options.icon);
+ if (iconURL.isValid())
+ notification.get().m_icon = iconURL;
+ }
+ notification.get().suspendIfNeeded();
+ return notification;
}
+
#endif
void Notification::show()
@@ -135,9 +142,10 @@ void Notification::show()
// prevent double-showing
if (m_state == Idle && m_notificationCenter->client()) {
#if ENABLE(NOTIFICATIONS)
- if (!toDocument(scriptExecutionContext())->page())
+ auto* page = downcast<Document>(*scriptExecutionContext()).page();
+ if (!page)
return;
- if (NotificationController::from(toDocument(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
+ if (NotificationController::from(page)->client().checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
dispatchErrorEvent();
return;
}
@@ -170,6 +178,17 @@ void Notification::contextDestroyed()
m_notificationCenter->client()->notificationObjectDestroyed(this);
}
+const char* Notification::activeDOMObjectName() const
+{
+ return "Notification";
+}
+
+bool Notification::canSuspendForDocumentSuspension() const
+{
+ // We can suspend if the Notification is not shown yet or after it is closed.
+ return m_state == Idle || m_state == Closed;
+}
+
void Notification::finalize()
{
if (m_state == Closed)
@@ -201,23 +220,13 @@ void Notification::dispatchErrorEvent()
}
#if ENABLE(NOTIFICATIONS)
-void Notification::taskTimerFired(Timer<Notification>& timer)
-{
- ASSERT(scriptExecutionContext()->isDocument());
- ASSERT_UNUSED(timer, &timer == m_taskTimer.get());
- show();
-}
-#endif
-
-#if ENABLE(NOTIFICATIONS)
-const String Notification::permission(ScriptExecutionContext* context)
+String Notification::permission(Document& document)
{
- ASSERT(toDocument(context)->page());
- return permissionString(NotificationController::from(toDocument(context)->page())->client()->checkPermission(context));
+ return permissionString(NotificationController::from(document.page())->client().checkPermission(&document));
}
-const String Notification::permissionString(NotificationClient::Permission permission)
+String Notification::permissionString(NotificationClient::Permission permission)
{
switch (permission) {
case NotificationClient::PermissionAllowed:
@@ -227,16 +236,15 @@ const String Notification::permissionString(NotificationClient::Permission permi
case NotificationClient::PermissionNotAllowed:
return ASCIILiteral("default");
}
-
ASSERT_NOT_REACHED();
- return String();
+ return { };
}
-void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr<NotificationPermissionCallback> callback)
+void Notification::requestPermission(Document& document, RefPtr<NotificationPermissionCallback>&& callback)
{
- ASSERT(toDocument(context)->page());
- NotificationController::from(toDocument(context)->page())->client()->requestPermission(context, callback);
+ NotificationController::from(document.page())->client().requestPermission(&document, WTFMove(callback));
}
+
#endif
} // namespace WebCore
diff --git a/Source/WebCore/Modules/notifications/Notification.h b/Source/WebCore/Modules/notifications/Notification.h
index 004f412d5..3b21bbc88 100644
--- a/Source/WebCore/Modules/notifications/Notification.h
+++ b/Source/WebCore/Modules/notifications/Notification.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011, 2012, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,140 +29,100 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef Notification_h
-#define Notification_h
+#pragma once
+
+#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
#include "ActiveDOMObject.h"
-#include "EventNames.h"
#include "EventTarget.h"
-#include "URL.h"
+#include "ExceptionOr.h"
#include "NotificationClient.h"
-#include "SharedBuffer.h"
-#include "TextDirection.h"
-#include "ThreadableLoaderClient.h"
-#include <wtf/OwnPtr.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/AtomicStringHash.h>
-
-#if ENABLE(NOTIFICATIONS)
#include "Timer.h"
-#endif
+#include "URL.h"
+#include "WritingMode.h"
-#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
namespace WebCore {
-class Dictionary;
+class Document;
class NotificationCenter;
class NotificationPermissionCallback;
-class ResourceError;
-class ResourceResponse;
-class ScriptExecutionContext;
-class ThreadableLoader;
-
-typedef int ExceptionCode;
class Notification final : public RefCounted<Notification>, public ActiveDOMObject, public EventTargetWithInlineData {
WTF_MAKE_FAST_ALLOCATED;
public:
- Notification();
#if ENABLE(LEGACY_NOTIFICATIONS)
- static PassRefPtr<Notification> create(const String& title, const String& body, const String& iconURI, ScriptExecutionContext*, ExceptionCode&, PassRefPtr<NotificationCenter> provider);
+ static ExceptionOr<Ref<Notification>> create(const String& title, const String& body, const String& iconURL, ScriptExecutionContext&, NotificationCenter&);
#endif
+
#if ENABLE(NOTIFICATIONS)
- static PassRefPtr<Notification> create(ScriptExecutionContext&, const String& title, const Dictionary& options);
+ enum class Direction { Auto, Ltr, Rtl };
+ struct Options {
+ Direction dir;
+ String lang;
+ String body;
+ String tag;
+ String icon;
+ };
+ static Ref<Notification> create(Document&, const String& title, const Options&);
#endif
virtual ~Notification();
void show();
-#if ENABLE(LEGACY_NOTIFICATIONS)
- void cancel() { close(); }
-#endif
void close();
- URL iconURL() const { return m_icon; }
- void setIconURL(const URL& url) { m_icon = url; }
+ const URL& iconURL() const { return m_icon; }
+ const String& title() const { return m_title; }
+ const String& body() const { return m_body; }
+ const String& lang() const { return m_lang; }
- String title() const { return m_title; }
- String body() const { return m_body; }
-
- String lang() const { return m_lang; }
- void setLang(const String& lang) { m_lang = lang; }
-
- String dir() const { return m_direction; }
+ const String& dir() const { return m_direction; }
void setDir(const String& dir) { m_direction = dir; }
-#if ENABLE(LEGACY_NOTIFICATIONS)
- String replaceId() const { return tag(); }
- void setReplaceId(const String& replaceId) { setTag(replaceId); }
-#endif
+ const String& replaceId() const { return m_tag; }
+ void setReplaceId(const String& replaceId) { m_tag = replaceId; }
- String tag() const { return m_tag; }
+ const String& tag() const { return m_tag; }
void setTag(const String& tag) { m_tag = tag; }
- TextDirection direction() const { return dir() == "rtl" ? RTL : LTR; }
+ TextDirection direction() const { return m_direction == "rtl" ? RTL : LTR; }
-#if ENABLE(LEGACY_NOTIFICATIONS)
- EventListener* ondisplay() { return getAttributeEventListener(eventNames().showEvent); }
- void setOndisplay(PassRefPtr<EventListener> listener) { setAttributeEventListener(eventNames().showEvent, listener); }
-#endif
- DEFINE_ATTRIBUTE_EVENT_LISTENER(show);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(close);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
-
- void dispatchClickEvent();
- void dispatchCloseEvent();
- void dispatchErrorEvent();
- void dispatchShowEvent();
-
- using RefCounted<Notification>::ref;
- using RefCounted<Notification>::deref;
-
- // EventTarget interface
- virtual EventTargetInterface eventTargetInterface() const override { return NotificationEventTargetInterfaceType; }
- virtual ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
+ WEBCORE_EXPORT void dispatchClickEvent();
+ WEBCORE_EXPORT void dispatchCloseEvent();
+ WEBCORE_EXPORT void dispatchErrorEvent();
+ WEBCORE_EXPORT void dispatchShowEvent();
- void stopLoadingIcon();
-
- // Deprecated. Use functions from NotificationCenter.
- void detachPresenter() { }
-
- void finalize();
+ WEBCORE_EXPORT void finalize();
#if ENABLE(NOTIFICATIONS)
- static const String permission(ScriptExecutionContext*);
- static const String permissionString(NotificationClient::Permission);
- static void requestPermission(ScriptExecutionContext*, PassRefPtr<NotificationPermissionCallback> = 0);
+ static String permission(Document&);
+ WEBCORE_EXPORT static String permissionString(NotificationClient::Permission);
+ static void requestPermission(Document&, RefPtr<NotificationPermissionCallback>&&);
#endif
+ ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
+
+ using RefCounted::ref;
+ using RefCounted::deref;
+
private:
#if ENABLE(LEGACY_NOTIFICATIONS)
- Notification(const String& title, const String& body, const String& iconURI, ScriptExecutionContext*, ExceptionCode&, PassRefPtr<NotificationCenter>);
+ Notification(const String& title, const String& body, URL&& iconURL, ScriptExecutionContext&, NotificationCenter&);
#endif
+
#if ENABLE(NOTIFICATIONS)
- Notification(ScriptExecutionContext&, const String& title);
+ Notification(Document&, const String& title);
#endif
- void setBody(const String& body) { m_body = body; }
-
- // ActiveDOMObject interface
- virtual void contextDestroyed() override;
+ EventTargetInterface eventTargetInterface() const final { return NotificationEventTargetInterfaceType; }
- // EventTarget interface
- virtual void refEventTarget() override { ref(); }
- virtual void derefEventTarget() override { deref(); }
+ void contextDestroyed() final;
+ const char* activeDOMObjectName() const final;
+ bool canSuspendForDocumentSuspension() const final;
- void startLoadingIcon();
- void finishLoadingIcon();
-
-#if ENABLE(NOTIFICATIONS)
- void taskTimerFired(Timer<Notification>&);
-#endif
+ void refEventTarget() final { ref(); }
+ void derefEventTarget() final { deref(); }
- // Text notifications.
URL m_icon;
String m_title;
String m_body;
@@ -170,23 +130,16 @@ private:
String m_lang;
String m_tag;
- enum NotificationState {
- Idle = 0,
- Showing = 1,
- Closed = 2,
- };
-
- NotificationState m_state;
+ enum State { Idle, Showing, Closed };
+ State m_state { Idle };
RefPtr<NotificationCenter> m_notificationCenter;
#if ENABLE(NOTIFICATIONS)
- OwnPtr<Timer<Notification>> m_taskTimer;
+ std::unique_ptr<Timer> m_taskTimer;
#endif
};
} // namespace WebCore
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
-
-#endif // Notifications_h
diff --git a/Source/WebCore/Modules/notifications/Notification.idl b/Source/WebCore/Modules/notifications/Notification.idl
index 6b0e14021..cb3fbee74 100644
--- a/Source/WebCore/Modules/notifications/Notification.idl
+++ b/Source/WebCore/Modules/notifications/Notification.idl
@@ -32,49 +32,37 @@
[
Conditional=NOTIFICATIONS|LEGACY_NOTIFICATIONS,
ActiveDOMObject,
- EventTarget,
+ ExportMacro=WEBCORE_EXPORT,
#if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
- Constructor(DOMString title, [Default=Undefined] optional Dictionary options),
- ConstructorCallWith=ScriptExecutionContext,
+ Constructor(DOMString title, optional NotificationOptions options),
+ ConstructorCallWith=Document,
#endif
-] interface Notification {
+] interface Notification : EventTarget {
void show();
-#if defined(ENABLE_LEGACY_NOTIFICATIONS) && ENABLE_LEGACY_NOTIFICATIONS
- void cancel();
-#endif
-#if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
- void close();
-#endif
+ [Conditional=LEGACY_NOTIFICATIONS, ImplementedAs=close] void cancel();
+ [Conditional=NOTIFICATIONS] void close();
+ [Conditional=NOTIFICATIONS, CallWith=Document] static readonly attribute DOMString permission;
+ [Conditional=NOTIFICATIONS, CallWith=Document] static void requestPermission(optional NotificationPermissionCallback? callback);
-#if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
- [CallWith=ScriptExecutionContext] static readonly attribute DOMString permission;
- [CallWith=ScriptExecutionContext] static void requestPermission(optional NotificationPermissionCallback callback);
-#endif
-
- attribute EventListener onshow;
-#if defined(ENABLE_LEGACY_NOTIFICATIONS) && ENABLE_LEGACY_NOTIFICATIONS
- attribute EventListener ondisplay;
-#endif
- attribute EventListener onerror;
- attribute EventListener onclose;
- attribute EventListener onclick;
+ attribute EventHandler onclick;
+ attribute EventHandler onclose;
+ [ImplementedAs=onshow] attribute EventHandler ondisplay;
+ attribute EventHandler onerror;
+ attribute EventHandler onshow;
-#if defined(ENABLE_LEGACY_NOTIFICATIONS) && ENABLE_LEGACY_NOTIFICATIONS
- attribute DOMString dir;
- attribute DOMString replaceId;
-#endif
-#if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
- attribute DOMString tag;
-#endif
+ [Conditional=LEGACY_NOTIFICATIONS] attribute DOMString dir;
+ [Conditional=LEGACY_NOTIFICATIONS] attribute DOMString replaceId;
- // EventTarget interface
- void addEventListener(DOMString type,
- EventListener listener,
- optional boolean useCapture);
- void removeEventListener(DOMString type,
- EventListener listener,
- optional boolean useCapture);
- [RaisesException] boolean dispatchEvent(Event evt);
+ [Conditional=NOTIFICATIONS] attribute DOMString tag;
};
+[Conditional=NOTIFICATIONS] enum NotificationDirection { "auto", "ltr", "rtl" };
+
+[Conditional=NOTIFICATIONS] dictionary NotificationOptions {
+ NotificationDirection dir = "auto";
+ DOMString lang = "";
+ DOMString body = "";
+ DOMString tag = "";
+ DOMString icon;
+};
diff --git a/Source/WebCore/Modules/notifications/NotificationCenter.cpp b/Source/WebCore/Modules/notifications/NotificationCenter.cpp
index 13f77de4a..a9298f752 100644
--- a/Source/WebCore/Modules/notifications/NotificationCenter.cpp
+++ b/Source/WebCore/Modules/notifications/NotificationCenter.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -35,30 +35,40 @@
#include "NotificationCenter.h"
-#include "Document.h"
-#include "NotificationClient.h"
+#include "ExceptionCode.h"
+#include "Notification.h"
+#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
-#include "WorkerGlobalScope.h"
+#include "VoidCallback.h"
namespace WebCore {
-PassRefPtr<NotificationCenter> NotificationCenter::create(ScriptExecutionContext* context, NotificationClient* client)
+Ref<NotificationCenter> NotificationCenter::create(ScriptExecutionContext& context, NotificationClient* client)
{
- RefPtr<NotificationCenter> notificationCenter(adoptRef(new NotificationCenter(context, client)));
+ auto notificationCenter = adoptRef(*new NotificationCenter(context, client));
notificationCenter->suspendIfNeeded();
- return notificationCenter.release();
+ return notificationCenter;
}
-NotificationCenter::NotificationCenter(ScriptExecutionContext* context, NotificationClient* client)
- : ActiveDOMObject(context)
+NotificationCenter::NotificationCenter(ScriptExecutionContext& context, NotificationClient* client)
+ : ActiveDOMObject(&context)
, m_client(client)
+ , m_timer([this]() { timerFired(); })
{
}
#if ENABLE(LEGACY_NOTIFICATIONS)
+
+ExceptionOr<Ref<Notification>> NotificationCenter::createNotification(const String& iconURI, const String& title, const String& body)
+{
+ if (!m_client || !scriptExecutionContext())
+ return Exception { INVALID_STATE_ERR };
+ return Notification::create(title, body, iconURI, *scriptExecutionContext(), *this);
+}
+
int NotificationCenter::checkPermission()
{
- if (!client() || !scriptExecutionContext())
+ if (!m_client || !scriptExecutionContext())
return NotificationClient::PermissionDenied;
switch (scriptExecutionContext()->securityOrigin()->canShowNotifications()) {
@@ -73,67 +83,74 @@ int NotificationCenter::checkPermission()
ASSERT_NOT_REACHED();
return m_client->checkPermission(scriptExecutionContext());
}
-#endif
-#if ENABLE(LEGACY_NOTIFICATIONS)
-void NotificationCenter::requestPermission(PassRefPtr<VoidCallback> callback)
+void NotificationCenter::requestPermission(RefPtr<VoidCallback>&& callback)
{
- if (!client() || !scriptExecutionContext())
+ if (!m_client || !scriptExecutionContext())
return;
switch (scriptExecutionContext()->securityOrigin()->canShowNotifications()) {
case SecurityOrigin::AlwaysAllow:
- case SecurityOrigin::AlwaysDeny: {
- m_callbacks.add(NotificationRequestCallback::createAndStartTimer(this, callback));
+ case SecurityOrigin::AlwaysDeny:
+ if (m_callbacks.isEmpty()) {
+ ref(); // Balanced by the derefs in NotificationCenter::stop and NotificationCenter::timerFired.
+ m_timer.startOneShot(0);
+ }
+ m_callbacks.append([callback]() {
+ if (callback)
+ callback->handleEvent();
+ });
return;
- }
case SecurityOrigin::Ask:
- return m_client->requestPermission(scriptExecutionContext(), callback);
+ m_client->requestPermission(scriptExecutionContext(), WTFMove(callback));
+ return;
}
ASSERT_NOT_REACHED();
- m_client->requestPermission(scriptExecutionContext(), callback);
+ m_client->requestPermission(scriptExecutionContext(), WTFMove(callback));
}
+
#endif
void NotificationCenter::stop()
{
if (!m_client)
return;
- m_client->cancelRequestsForPermission(scriptExecutionContext());
- m_client->clearNotifications(scriptExecutionContext());
- m_client = 0;
-}
-void NotificationCenter::requestTimedOut(NotificationCenter::NotificationRequestCallback* request)
-{
- m_callbacks.remove(request);
-}
+ // Clear m_client immediately to guarantee reentrant calls to NotificationCenter do nothing.
+ // Also protect |this| so it's not indirectly destroyed under us by work done by the client.
+ auto& client = *std::exchange(m_client, nullptr);
+ Ref<NotificationCenter> protectedThis(*this);
-PassRefPtr<NotificationCenter::NotificationRequestCallback> NotificationCenter::NotificationRequestCallback::createAndStartTimer(NotificationCenter* center, PassRefPtr<VoidCallback> callback)
-{
- RefPtr<NotificationCenter::NotificationRequestCallback> requestCallback = adoptRef(new NotificationCenter::NotificationRequestCallback(center, callback));
- requestCallback->startTimer();
- return requestCallback.release();
+ if (!m_callbacks.isEmpty())
+ deref(); // Balanced by the ref in NotificationCenter::requestPermission.
+
+ m_timer.stop();
+ m_callbacks.clear();
+
+ client.cancelRequestsForPermission(scriptExecutionContext());
+ client.clearNotifications(scriptExecutionContext());
}
-NotificationCenter::NotificationRequestCallback::NotificationRequestCallback(NotificationCenter* center, PassRefPtr<VoidCallback> callback)
- : m_notificationCenter(center)
- , m_timer(this, &NotificationCenter::NotificationRequestCallback::timerFired)
- , m_callback(callback)
+const char* NotificationCenter::activeDOMObjectName() const
{
+ return "NotificationCenter";
}
-void NotificationCenter::NotificationRequestCallback::startTimer()
+bool NotificationCenter::canSuspendForDocumentSuspension() const
{
- m_timer.startOneShot(0);
+ // We don't need to worry about Notifications because those are ActiveDOMObject too.
+ // The NotificationCenter can safely be suspended if there are no pending permission requests.
+ return m_callbacks.isEmpty() && (!m_client || !m_client->hasPendingPermissionRequests(scriptExecutionContext()));
}
-void NotificationCenter::NotificationRequestCallback::timerFired(Timer<NotificationCenter::NotificationRequestCallback>&)
+void NotificationCenter::timerFired()
{
- if (m_callback)
- m_callback->handleEvent();
- m_notificationCenter->requestTimedOut(this);
+ ASSERT(m_client);
+ auto callbacks = WTFMove(m_callbacks);
+ for (auto& callback : callbacks)
+ callback();
+ deref(); // Balanced by the ref in NotificationCenter::requestPermission.
}
} // namespace WebCore
diff --git a/Source/WebCore/Modules/notifications/NotificationCenter.h b/Source/WebCore/Modules/notifications/NotificationCenter.h
index d27b45e4f..4646e182e 100644
--- a/Source/WebCore/Modules/notifications/NotificationCenter.h
+++ b/Source/WebCore/Modules/notifications/NotificationCenter.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,75 +29,50 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef NotificationCenter_h
-#define NotificationCenter_h
+#pragma once
-#include "ExceptionCode.h"
-#include "Notification.h"
-#include "ScriptExecutionContext.h"
+#include "ActiveDOMObject.h"
+#include "ExceptionOr.h"
#include "Timer.h"
-#include "VoidCallback.h"
-#include <wtf/OwnPtr.h>
-#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
namespace WebCore {
+class Notification;
class NotificationClient;
class VoidCallback;
-class NotificationCenter : public RefCounted<NotificationCenter>, public ActiveDOMObject {
+class NotificationCenter final : public RefCounted<NotificationCenter>, private ActiveDOMObject {
public:
- static PassRefPtr<NotificationCenter> create(ScriptExecutionContext*, NotificationClient*);
+ static Ref<NotificationCenter> create(ScriptExecutionContext&, NotificationClient*);
#if ENABLE(LEGACY_NOTIFICATIONS)
- PassRefPtr<Notification> createNotification(const String& iconURI, const String& title, const String& body, ExceptionCode& ec)
- {
- if (!client()) {
- ec = INVALID_STATE_ERR;
- return 0;
- }
- return Notification::create(title, body, iconURI, scriptExecutionContext(), ec, this);
- }
-#endif
-
- NotificationClient* client() const { return m_client; }
+ ExceptionOr<Ref<Notification>> createNotification(const String& iconURL, const String& title, const String& body);
-#if ENABLE(LEGACY_NOTIFICATIONS)
int checkPermission();
- void requestPermission(PassRefPtr<VoidCallback> = 0);
+ void requestPermission(RefPtr<VoidCallback>&&);
#endif
-private:
- NotificationCenter(ScriptExecutionContext*, NotificationClient*);
+ NotificationClient* client() const { return m_client; }
- // ActiveDOMObject
- virtual void stop() override;
+ using ActiveDOMObject::hasPendingActivity;
- class NotificationRequestCallback : public RefCounted<NotificationRequestCallback> {
- public:
- static PassRefPtr<NotificationRequestCallback> createAndStartTimer(NotificationCenter*, PassRefPtr<VoidCallback>);
- void startTimer();
- void timerFired(Timer<NotificationRequestCallback>&);
- private:
- NotificationRequestCallback(NotificationCenter*, PassRefPtr<VoidCallback>);
+private:
+ NotificationCenter(ScriptExecutionContext&, NotificationClient*);
- RefPtr<NotificationCenter> m_notificationCenter;
- Timer<NotificationRequestCallback> m_timer;
- RefPtr<VoidCallback> m_callback;
- };
+ void stop() final;
+ const char* activeDOMObjectName() const final;
+ bool canSuspendForDocumentSuspension() const final;
- void requestTimedOut(NotificationRequestCallback*);
+ void timerFired();
NotificationClient* m_client;
- HashSet<RefPtr<NotificationRequestCallback>> m_callbacks;
+ Vector<std::function<void ()>> m_callbacks;
+ Timer m_timer;
};
} // namespace WebCore
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
-
-#endif // NotificationCenter_h
diff --git a/Source/WebCore/Modules/notifications/NotificationCenter.idl b/Source/WebCore/Modules/notifications/NotificationCenter.idl
index 54343cfa9..07a380fc4 100644
--- a/Source/WebCore/Modules/notifications/NotificationCenter.idl
+++ b/Source/WebCore/Modules/notifications/NotificationCenter.idl
@@ -30,13 +30,12 @@
*/
[
- NoInterfaceObject,
- Conditional=LEGACY_NOTIFICATIONS,
ActiveDOMObject,
+ Conditional=LEGACY_NOTIFICATIONS,
+ NoInterfaceObject,
] interface NotificationCenter {
- [RaisesException] Notification createNotification(DOMString iconUrl, DOMString title, DOMString body);
+ [MayThrowException] Notification createNotification(DOMString iconUrl, DOMString title, DOMString body);
- int checkPermission();
- void requestPermission(optional VoidCallback callback);
+ long checkPermission();
+ void requestPermission(optional VoidCallback? callback);
};
-
diff --git a/Source/WebCore/Modules/notifications/NotificationClient.h b/Source/WebCore/Modules/notifications/NotificationClient.h
index 22815bf7a..b03dfd92a 100644
--- a/Source/WebCore/Modules/notifications/NotificationClient.h
+++ b/Source/WebCore/Modules/notifications/NotificationClient.h
@@ -29,23 +29,19 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef NotificationClient_h
-#define NotificationClient_h
+#pragma once
-#include "NotificationPermissionCallback.h"
-#include "VoidCallback.h"
-#include <wtf/PassRefPtr.h>
+#include <wtf/Forward.h>
namespace WebCore {
-class Document;
-class URL;
class Notification;
+class NotificationPermissionCallback;
class Page;
class ScriptExecutionContext;
+class VoidCallback;
class NotificationClient {
-
public:
enum Permission {
PermissionAllowed, // User has allowed notifications
@@ -71,16 +67,18 @@ public:
// Informs the presenter the controller attached to the page has been destroyed.
virtual void notificationControllerDestroyed() = 0;
-#if ENABLE(LEGACY_NOTIFICATIONS)
// Requests user permission to show desktop notifications from a particular
// script context. The callback parameter should be run when the user has
// made a decision.
- virtual void requestPermission(ScriptExecutionContext*, PassRefPtr<VoidCallback>) = 0;
+#if ENABLE(LEGACY_NOTIFICATIONS)
+ virtual void requestPermission(ScriptExecutionContext*, RefPtr<VoidCallback>&&) = 0;
#endif
#if ENABLE(NOTIFICATIONS)
- virtual void requestPermission(ScriptExecutionContext*, PassRefPtr<NotificationPermissionCallback>) = 0;
+ virtual void requestPermission(ScriptExecutionContext*, RefPtr<NotificationPermissionCallback>&&) = 0;
#endif
+ virtual bool hasPendingPermissionRequests(ScriptExecutionContext*) const = 0;
+
// Cancel all outstanding requests for the ScriptExecutionContext
virtual void cancelRequestsForPermission(ScriptExecutionContext*) = 0;
@@ -91,8 +89,6 @@ protected:
virtual ~NotificationClient() { }
};
-void provideNotification(Page*, NotificationClient*);
+WEBCORE_EXPORT void provideNotification(Page*, NotificationClient*);
} // namespace WebCore
-
-#endif // NotificationClient_h
diff --git a/Source/WebCore/Modules/notifications/NotificationController.cpp b/Source/WebCore/Modules/notifications/NotificationController.cpp
index 0a90889d4..fc08b276f 100644
--- a/Source/WebCore/Modules/notifications/NotificationController.cpp
+++ b/Source/WebCore/Modules/notifications/NotificationController.cpp
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -29,31 +29,26 @@
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
#include "NotificationClient.h"
-#include <wtf/PassOwnPtr.h>
namespace WebCore {
NotificationController::NotificationController(NotificationClient* client)
- : m_client(client)
+ : m_client(*client)
{
+ ASSERT(client);
}
NotificationController::~NotificationController()
{
- if (m_client)
- m_client->notificationControllerDestroyed();
+ m_client.notificationControllerDestroyed();
}
-PassOwnPtr<NotificationController> NotificationController::create(NotificationClient* client)
+NotificationClient* NotificationController::clientFrom(Page& page)
{
- return adoptPtr(new NotificationController(client));
-}
-
-NotificationClient* NotificationController::clientFrom(Page* page)
-{
- if (NotificationController* controller = NotificationController::from(page))
- return controller->client();
- return 0;
+ auto* controller = NotificationController::from(&page);
+ if (!controller)
+ return nullptr;
+ return &controller->client();
}
const char* NotificationController::supplementName()
@@ -63,7 +58,7 @@ const char* NotificationController::supplementName()
void provideNotification(Page* page, NotificationClient* client)
{
- NotificationController::provideTo(page, NotificationController::supplementName(), NotificationController::create(client));
+ NotificationController::provideTo(page, NotificationController::supplementName(), std::make_unique<NotificationController>(client));
}
} // namespace WebCore
diff --git a/Source/WebCore/Modules/notifications/NotificationController.h b/Source/WebCore/Modules/notifications/NotificationController.h
index 751d4779e..25fca7422 100644
--- a/Source/WebCore/Modules/notifications/NotificationController.h
+++ b/Source/WebCore/Modules/notifications/NotificationController.h
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
-* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -23,39 +23,33 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef NotificationController_h
-#define NotificationController_h
+#pragma once
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
#include "Page.h"
#include <wtf/Forward.h>
-#include <wtf/Noncopyable.h>
namespace WebCore {
class NotificationClient;
class NotificationController : public Supplement<Page> {
- WTF_MAKE_NONCOPYABLE(NotificationController);
+ WTF_MAKE_FAST_ALLOCATED;
public:
+ explicit NotificationController(NotificationClient*);
~NotificationController();
- static PassOwnPtr<NotificationController> create(NotificationClient*);
static const char* supplementName();
static NotificationController* from(Page* page) { return static_cast<NotificationController*>(Supplement<Page>::from(page, supplementName())); }
- static NotificationClient* clientFrom(Page*);
+ WEBCORE_EXPORT static NotificationClient* clientFrom(Page&);
- NotificationClient* client() { return m_client; }
-
-private:
- explicit NotificationController(NotificationClient*);
+ NotificationClient& client() { return m_client; }
- NotificationClient* m_client;
+private:
+ NotificationClient& m_client;
};
} // namespace WebCore
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
-
-#endif // NotificationController_h
diff --git a/Source/WebCore/Modules/notifications/NotificationPermissionCallback.h b/Source/WebCore/Modules/notifications/NotificationPermissionCallback.h
index 84e732a7f..6fd86df64 100644
--- a/Source/WebCore/Modules/notifications/NotificationPermissionCallback.h
+++ b/Source/WebCore/Modules/notifications/NotificationPermissionCallback.h
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -23,8 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef NotificationPermissionCallback_h
-#define NotificationPermissionCallback_h
+#pragma once
#if ENABLE(NOTIFICATIONS)
@@ -42,5 +41,3 @@ public:
} // namespace WebCore
#endif // ENABLE(NOTIFICATIONS)
-
-#endif // NotificationPermissionCallback_h
diff --git a/Source/WebCore/Modules/notifications/NotificationPermissionCallback.idl b/Source/WebCore/Modules/notifications/NotificationPermissionCallback.idl
index ca4879435..6d3d984f5 100644
--- a/Source/WebCore/Modules/notifications/NotificationPermissionCallback.idl
+++ b/Source/WebCore/Modules/notifications/NotificationPermissionCallback.idl
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -25,7 +25,5 @@
[
Conditional=NOTIFICATIONS,
-] callback interface NotificationPermissionCallback {
- boolean handleEvent(DOMString permission);
-};
+] callback NotificationPermissionCallback = void (DOMString permission);
diff --git a/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.cpp b/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.cpp
index acf48f0f7..022163d4b 100644
--- a/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.cpp
+++ b/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.cpp
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -36,8 +36,8 @@
namespace WebCore {
-WorkerGlobalScopeNotifications::WorkerGlobalScopeNotifications(WorkerGlobalScope* context)
- : m_context(context)
+WorkerGlobalScopeNotifications::WorkerGlobalScopeNotifications(WorkerGlobalScope& scope)
+ : m_context(&scope)
{
}
@@ -50,25 +50,29 @@ const char* WorkerGlobalScopeNotifications::supplementName()
return "WorkerGlobalScopeNotifications";
}
-WorkerGlobalScopeNotifications* WorkerGlobalScopeNotifications::from(WorkerGlobalScope* context)
+WorkerGlobalScopeNotifications* WorkerGlobalScopeNotifications::from(WorkerGlobalScope& scope)
{
- WorkerGlobalScopeNotifications* supplement = static_cast<WorkerGlobalScopeNotifications*>(Supplement<ScriptExecutionContext>::from(context, supplementName()));
+ WorkerGlobalScopeNotifications* supplement = static_cast<WorkerGlobalScopeNotifications*>(Supplement<WorkerGlobalScope>::from(&scope, supplementName()));
if (!supplement) {
- supplement = new WorkerGlobalScopeNotifications(context);
- Supplement<ScriptExecutionContext>::provideTo(context, supplementName(), adoptPtr(supplement));
+ auto newSupplement = std::make_unique<WorkerGlobalScopeNotifications>(scope);
+ supplement = newSupplement.get();
+ provideTo(&scope, supplementName(), WTFMove(newSupplement));
}
return supplement;
}
-NotificationCenter* WorkerGlobalScopeNotifications::webkitNotifications(WorkerGlobalScope* context)
+NotificationCenter* WorkerGlobalScopeNotifications::webkitNotifications(WorkerGlobalScope& scope)
{
- return WorkerGlobalScopeNotifications::from(context)->webkitNotifications();
+ return WorkerGlobalScopeNotifications::from(scope)->webkitNotifications();
}
NotificationCenter* WorkerGlobalScopeNotifications::webkitNotifications()
{
+ // FIXME: As of this writing, this always passes nullptr for the client.
+ // If it wasn't for that, the notification center create function could be taking a reference.
+ // How is it useful to create a notification center with no client?
if (!m_notificationCenter)
- m_notificationCenter = NotificationCenter::create(m_context, m_context->thread()->getNotificationClient());
+ m_notificationCenter = NotificationCenter::create(*m_context, m_context->thread().getNotificationClient());
return m_notificationCenter.get();
}
diff --git a/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.h b/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.h
index 455c15133..6760e6e11 100644
--- a/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.h
+++ b/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009, 2013, 2014, 2015, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -24,8 +24,7 @@
*
*/
-#ifndef WorkerGlobalScopeNotifications_h
-#define WorkerGlobalScopeNotifications_h
+#pragma once
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
@@ -34,19 +33,17 @@
namespace WebCore {
class NotificationCenter;
-class ScriptExecutionContext;
class WorkerGlobalScope;
-class WorkerGlobalScopeNotifications : public Supplement<ScriptExecutionContext> {
+class WorkerGlobalScopeNotifications : public Supplement<WorkerGlobalScope> {
public:
+ explicit WorkerGlobalScopeNotifications(WorkerGlobalScope&);
virtual ~WorkerGlobalScopeNotifications();
- static NotificationCenter* webkitNotifications(WorkerGlobalScope*);
- static WorkerGlobalScopeNotifications* from(WorkerGlobalScope*);
+ static NotificationCenter* webkitNotifications(WorkerGlobalScope&);
+ static WorkerGlobalScopeNotifications* from(WorkerGlobalScope&);
private:
- explicit WorkerGlobalScopeNotifications(WorkerGlobalScope*);
-
NotificationCenter* webkitNotifications();
static const char* supplementName();
@@ -57,5 +54,3 @@ private:
} // namespace WebCore
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
-
-#endif // WorkerGlobalScopeNotifications_h
diff --git a/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.idl b/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.idl
index 0f721afef..4eb249d56 100644
--- a/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.idl
+++ b/Source/WebCore/Modules/notifications/WorkerGlobalScopeNotifications.idl
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR