diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/notifications/Notification.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/Modules/notifications/Notification.h')
-rw-r--r-- | Source/WebCore/Modules/notifications/Notification.h | 153 |
1 files changed, 53 insertions, 100 deletions
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 |