OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. |
3 * | 4 * |
4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
6 * met: | 7 * met: |
7 * | 8 * |
8 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 11 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 12 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 13 * in the documentation and/or other materials provided with the |
(...skipping 11 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 30 */ |
30 | 31 |
31 #ifndef Notification_h | 32 #ifndef Notification_h |
32 #define Notification_h | 33 #define Notification_h |
33 | 34 |
34 #include "bindings/v8/ScriptWrappable.h" | |
35 #include "core/dom/ActiveDOMObject.h" | |
36 #include "core/events/EventTarget.h" | |
37 #include "heap/Handle.h" | 35 #include "heap/Handle.h" |
38 #include "modules/notifications/NotificationClient.h" | 36 #include "modules/notifications/NotificationBase.h" |
39 #include "platform/AsyncMethodRunner.h" | 37 #include "platform/AsyncMethodRunner.h" |
40 #include "platform/text/TextDirection.h" | |
41 #include "platform/weborigin/KURL.h" | |
42 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
43 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
44 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
45 | 41 |
46 namespace WebCore { | 42 namespace WebCore { |
47 | 43 |
48 class Dictionary; | 44 class Dictionary; |
49 class ExecutionContext; | 45 class ExecutionContext; |
| 46 class NotificationClient; |
50 class NotificationPermissionCallback; | 47 class NotificationPermissionCallback; |
51 | 48 |
52 class Notification : public RefCountedWillBeRefCountedGarbageCollected<Notificat
ion>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInli
neData { | 49 class Notification FINAL : public RefCountedWillBeRefCountedGarbageCollected<Not
ification>, public NotificationBase { |
53 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<N
otification>); | 50 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<N
otification>); |
54 | 51 |
55 public: | 52 public: |
56 static PassRefPtrWillBeRawPtr<Notification> create(ExecutionContext*, const
String& title, const Dictionary& options); | 53 static PassRefPtrWillBeRawPtr<Notification> create(ExecutionContext*, const
String& title, const Dictionary& options); |
57 | 54 |
58 virtual ~Notification(); | 55 virtual ~Notification(); |
59 | 56 |
60 // Calling show() may start asynchronous operation. If this object has | |
61 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being | |
62 // collected while m_state is Showing, and so this instance stays alive | |
63 // until the operation completes. Otherwise, you need to hold a ref on this | |
64 // instance until the operation completes. | |
65 void show(); | |
66 | |
67 void close(); | |
68 | |
69 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); | |
70 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); | |
71 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | |
72 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | |
73 | |
74 void dispatchShowEvent(); | |
75 void dispatchClickEvent(); | |
76 void dispatchErrorEvent(); | |
77 void dispatchCloseEvent(); | |
78 | |
79 String title() const { return m_title; } | |
80 String dir() const { return m_dir; } | |
81 String lang() const { return m_lang; } | |
82 String body() const { return m_body; } | |
83 String tag() const { return m_tag; } | |
84 String icon() const { return m_iconUrl; } | |
85 | |
86 TextDirection direction() const; | |
87 KURL iconURL() const { return m_iconUrl; } | |
88 | |
89 static const String& permissionString(NotificationClient::Permission); | |
90 static const String& permission(ExecutionContext*); | 57 static const String& permission(ExecutionContext*); |
91 static void requestPermission(ExecutionContext*, PassOwnPtr<NotificationPerm
issionCallback> = nullptr); | 58 static void requestPermission(ExecutionContext*, PassOwnPtr<NotificationPerm
issionCallback> = nullptr); |
92 | 59 |
93 // EventTarget interface. | 60 // EventTarget interface |
94 virtual ExecutionContext* executionContext() const OVERRIDE FINAL { return A
ctiveDOMObject::executionContext(); } | |
95 virtual bool dispatchEvent(PassRefPtr<Event>) OVERRIDE FINAL; | |
96 virtual const AtomicString& interfaceName() const OVERRIDE; | 61 virtual const AtomicString& interfaceName() const OVERRIDE; |
97 | 62 |
98 // ActiveDOMObject interface. | 63 // ActiveDOMObject interface |
99 virtual void stop() OVERRIDE; | 64 virtual void stop() OVERRIDE; |
100 virtual bool hasPendingActivity() const OVERRIDE; | 65 virtual bool hasPendingActivity() const OVERRIDE; |
101 | 66 |
102 // RefCountedWillBeRefCountedGarbageCollected<Notification> interface. | |
103 void trace(Visitor*) { } | 67 void trace(Visitor*) { } |
104 | 68 |
105 private: | 69 private: |
106 Notification(const String& title, ExecutionContext*, NotificationClient*); | 70 Notification(ExecutionContext*, const String& title, NotificationClient*); |
107 | |
108 void setDir(const String& dir) { m_dir = dir; } | |
109 void setLang(const String& lang) { m_lang = lang; } | |
110 void setBody(const String& body) { m_body = body; } | |
111 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } | |
112 void setTag(const String& tag) { m_tag = tag; } | |
113 | 71 |
114 void showSoon(); | 72 void showSoon(); |
115 | 73 |
116 private: | |
117 String m_title; | |
118 String m_dir; | |
119 String m_lang; | |
120 String m_body; | |
121 String m_tag; | |
122 | |
123 KURL m_iconUrl; | |
124 | |
125 enum NotificationState { | |
126 Idle = 0, | |
127 Showing = 1, | |
128 Closed = 2, | |
129 }; | |
130 | |
131 NotificationState m_state; | |
132 | |
133 NotificationClient* m_client; | |
134 | |
135 OwnPtr<AsyncMethodRunner<Notification> > m_asyncRunner; | 74 OwnPtr<AsyncMethodRunner<Notification> > m_asyncRunner; |
136 }; | 75 }; |
137 | 76 |
138 } // namespace WebCore | 77 } // namespace WebCore |
139 | 78 |
140 #endif // Notification_h | 79 #endif // Notifications_h |
OLD | NEW |