OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef Notification_h | 31 #ifndef Notification_h |
32 #define Notification_h | 32 #define Notification_h |
33 | 33 |
34 #include "core/dom/ActiveDOMObject.h" | 34 #include "core/dom/ActiveDOMObject.h" |
35 #include "modules/EventTargetModules.h" | 35 #include "modules/EventTargetModules.h" |
36 #include "modules/notifications/NotificationClient.h" | |
37 #include "platform/AsyncMethodRunner.h" | 36 #include "platform/AsyncMethodRunner.h" |
38 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
39 #include "platform/text/TextDirection.h" | 38 #include "platform/text/TextDirection.h" |
40 #include "platform/weborigin/KURL.h" | 39 #include "platform/weborigin/KURL.h" |
| 40 #include "public/platform/WebNotificationDelegate.h" |
| 41 #include "public/platform/WebNotificationPermission.h" |
41 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
42 #include "wtf/RefCounted.h" | 43 #include "wtf/RefCounted.h" |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 class ExecutionContext; | 47 class ExecutionContext; |
47 class NotificationOptions; | 48 class NotificationOptions; |
48 class NotificationPermissionCallback; | 49 class NotificationPermissionCallback; |
| 50 class WebNotificationPresenter; |
49 | 51 |
50 class Notification : public RefCountedGarbageCollectedWillBeGarbageCollectedFina
lized<Notification>, public ActiveDOMObject, public EventTargetWithInlineData { | 52 class Notification : public RefCountedGarbageCollectedWillBeGarbageCollectedFina
lized<Notification>, public ActiveDOMObject, public EventTargetWithInlineData, p
ublic WebNotificationDelegate { |
51 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<N
otification>); | 53 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<N
otification>); |
52 DEFINE_WRAPPERTYPEINFO(); | 54 DEFINE_WRAPPERTYPEINFO(); |
53 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Notification); | 55 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Notification); |
54 public: | 56 public: |
55 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&); | 57 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&); |
56 | 58 |
57 virtual ~Notification(); | 59 virtual ~Notification(); |
58 | 60 |
59 void close(); | 61 void close(); |
60 | 62 |
61 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); | 63 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); |
62 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); |
63 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
64 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
65 | 67 |
66 void dispatchShowEvent(); | 68 // WebNotificationDelegate implementation. |
67 void dispatchClickEvent(); | 69 virtual void dispatchShowEvent() override; |
68 void dispatchErrorEvent(); | 70 virtual void dispatchClickEvent() override; |
69 void dispatchCloseEvent(); | 71 virtual void dispatchErrorEvent() override; |
| 72 virtual void dispatchCloseEvent() override; |
70 | 73 |
71 String title() const { return m_title; } | 74 String title() const { return m_title; } |
72 String dir() const { return m_dir; } | 75 String dir() const { return m_dir; } |
73 String lang() const { return m_lang; } | 76 String lang() const { return m_lang; } |
74 String body() const { return m_body; } | 77 String body() const { return m_body; } |
75 String tag() const { return m_tag; } | 78 String tag() const { return m_tag; } |
76 String icon() const { return m_iconUrl; } | 79 String icon() const { return m_iconUrl; } |
77 | 80 |
78 TextDirection direction() const; | 81 TextDirection direction() const; |
79 KURL iconURL() const { return m_iconUrl; } | 82 KURL iconURL() const { return m_iconUrl; } |
80 | 83 |
81 static const String& permissionString(NotificationClient::Permission); | 84 static const String& permissionString(WebNotificationPermission); |
82 static const String& permission(ExecutionContext*); | 85 static const String& permission(ExecutionContext*); |
| 86 static WebNotificationPermission checkPermission(ExecutionContext*); |
83 static void requestPermission(ExecutionContext*, NotificationPermissionCallb
ack* = nullptr); | 87 static void requestPermission(ExecutionContext*, NotificationPermissionCallb
ack* = nullptr); |
84 | 88 |
85 // EventTarget interface. | 89 // EventTarget interface. |
86 virtual ExecutionContext* executionContext() const override final { return A
ctiveDOMObject::executionContext(); } | 90 virtual ExecutionContext* executionContext() const override final { return A
ctiveDOMObject::executionContext(); } |
87 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) override final; | 91 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) override final; |
88 virtual const AtomicString& interfaceName() const override; | 92 virtual const AtomicString& interfaceName() const override; |
89 | 93 |
90 // ActiveDOMObject interface. | 94 // ActiveDOMObject interface. |
91 virtual void stop() override; | 95 virtual void stop() override; |
92 virtual bool hasPendingActivity() const override; | 96 virtual bool hasPendingActivity() const override; |
93 | 97 |
94 private: | 98 private: |
95 Notification(const String& title, ExecutionContext*, NotificationClient*); | 99 Notification(const String& title, ExecutionContext*); |
96 | 100 |
97 // Calling show() may start asynchronous operation. If this object has | 101 // Calling show() may start asynchronous operation. If this object has |
98 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being | 102 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being |
99 // collected while m_state is Showing, and so this instance stays alive | 103 // collected while m_state is Showing, and so this instance stays alive |
100 // until the operation completes. Otherwise, you need to hold a ref on this | 104 // until the operation completes. Otherwise, you need to hold a ref on this |
101 // instance until the operation completes. | 105 // instance until the operation completes. |
102 void show(); | 106 void show(); |
103 | 107 |
104 void setDir(const String& dir) { m_dir = dir; } | 108 void setDir(const String& dir) { m_dir = dir; } |
105 void setLang(const String& lang) { m_lang = lang; } | 109 void setLang(const String& lang) { m_lang = lang; } |
(...skipping 11 matching lines...) Expand all Loading... |
117 KURL m_iconUrl; | 121 KURL m_iconUrl; |
118 | 122 |
119 enum NotificationState { | 123 enum NotificationState { |
120 NotificationStateIdle, | 124 NotificationStateIdle, |
121 NotificationStateShowing, | 125 NotificationStateShowing, |
122 NotificationStateClosed | 126 NotificationStateClosed |
123 }; | 127 }; |
124 | 128 |
125 NotificationState m_state; | 129 NotificationState m_state; |
126 | 130 |
127 NotificationClient* m_client; | |
128 | |
129 AsyncMethodRunner<Notification> m_asyncRunner; | 131 AsyncMethodRunner<Notification> m_asyncRunner; |
130 }; | 132 }; |
131 | 133 |
132 } // namespace blink | 134 } // namespace blink |
133 | 135 |
134 #endif // Notification_h | 136 #endif // Notification_h |
OLD | NEW |