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 29 matching lines...) Expand all Loading... |
40 #include "public/platform/WebNotificationDelegate.h" | 40 #include "public/platform/WebNotificationDelegate.h" |
41 #include "public/platform/WebNotificationPermission.h" | 41 #include "public/platform/WebNotificationPermission.h" |
42 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
43 #include "wtf/RefCounted.h" | 43 #include "wtf/RefCounted.h" |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 class ExecutionContext; | 47 class ExecutionContext; |
48 class NotificationOptions; | 48 class NotificationOptions; |
49 class NotificationPermissionCallback; | 49 class NotificationPermissionCallback; |
| 50 struct WebNotificationData; |
50 | 51 |
51 class Notification : public RefCountedGarbageCollectedWillBeGarbageCollectedFina
lized<Notification>, public ActiveDOMObject, public EventTargetWithInlineData, p
ublic WebNotificationDelegate { | 52 class Notification : public RefCountedGarbageCollectedWillBeGarbageCollectedFina
lized<Notification>, public ActiveDOMObject, public EventTargetWithInlineData, p
ublic WebNotificationDelegate { |
52 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<N
otification>); | 53 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<N
otification>); |
53 DEFINE_WRAPPERTYPEINFO(); | 54 DEFINE_WRAPPERTYPEINFO(); |
54 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Notification); | 55 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Notification); |
55 public: | 56 public: |
| 57 // Used for JavaScript instantiations of the Notification object. Will autom
atically schedule for |
| 58 // the notification to be displayed to the user. |
56 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&); | 59 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&); |
57 | 60 |
| 61 // Used for embedder-created Notification objects. Will initialize the Notif
ication's state as showing. |
| 62 static Notification* create(ExecutionContext*, const String& persistentId, c
onst WebNotificationData&); |
| 63 |
58 virtual ~Notification(); | 64 virtual ~Notification(); |
59 | 65 |
60 void close(); | 66 void close(); |
61 | 67 |
62 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); | 68 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); |
63 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); | 69 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); |
64 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 70 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
65 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 71 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
66 | 72 |
67 // WebNotificationDelegate implementation. | 73 // WebNotificationDelegate implementation. |
(...skipping 22 matching lines...) Expand all Loading... |
90 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) override final; | 96 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) override final; |
91 virtual const AtomicString& interfaceName() const override; | 97 virtual const AtomicString& interfaceName() const override; |
92 | 98 |
93 // ActiveDOMObject interface. | 99 // ActiveDOMObject interface. |
94 virtual void stop() override; | 100 virtual void stop() override; |
95 virtual bool hasPendingActivity() const override; | 101 virtual bool hasPendingActivity() const override; |
96 | 102 |
97 private: | 103 private: |
98 Notification(const String& title, ExecutionContext*); | 104 Notification(const String& title, ExecutionContext*); |
99 | 105 |
| 106 void scheduleShow(); |
| 107 |
100 // Calling show() may start asynchronous operation. If this object has | 108 // Calling show() may start asynchronous operation. If this object has |
101 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being | 109 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being |
102 // collected while m_state is Showing, and so this instance stays alive | 110 // collected while m_state is Showing, and so this instance stays alive |
103 // until the operation completes. Otherwise, you need to hold a ref on this | 111 // until the operation completes. Otherwise, you need to hold a ref on this |
104 // instance until the operation completes. | 112 // instance until the operation completes. |
105 void show(); | 113 void show(); |
106 | 114 |
107 void setDir(const String& dir) { m_dir = dir; } | 115 void setDir(const String& dir) { m_dir = dir; } |
108 void setLang(const String& lang) { m_lang = lang; } | 116 void setLang(const String& lang) { m_lang = lang; } |
109 void setBody(const String& body) { m_body = body; } | 117 void setBody(const String& body) { m_body = body; } |
110 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } | 118 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } |
111 void setTag(const String& tag) { m_tag = tag; } | 119 void setTag(const String& tag) { m_tag = tag; } |
112 | 120 |
| 121 void setPersistentId(const String& persistentId) { m_persistentId = persiste
ntId; } |
| 122 |
113 private: | 123 private: |
114 String m_title; | 124 String m_title; |
115 String m_dir; | 125 String m_dir; |
116 String m_lang; | 126 String m_lang; |
117 String m_body; | 127 String m_body; |
118 String m_tag; | 128 String m_tag; |
119 | 129 |
120 KURL m_iconUrl; | 130 KURL m_iconUrl; |
121 | 131 |
| 132 // Notifications can either be bound to the page, which means they're identi
fied by |
| 133 // their delegate, or persistent, which means they're identified by a persis
tent Id |
| 134 // given to us by the embedder. This influences how we close the notificatio
n. |
| 135 String m_persistentId; |
| 136 |
122 enum NotificationState { | 137 enum NotificationState { |
123 NotificationStateIdle, | 138 NotificationStateIdle, |
124 NotificationStateShowing, | 139 NotificationStateShowing, |
125 NotificationStateClosed | 140 NotificationStateClosed |
126 }; | 141 }; |
127 | 142 |
| 143 // Only to be used by the Notification::create() method when notifications w
ere created |
| 144 // by the embedder rather than by Blink. |
| 145 void setState(NotificationState state) { m_state = state; } |
| 146 |
128 NotificationState m_state; | 147 NotificationState m_state; |
129 | 148 |
130 AsyncMethodRunner<Notification> m_asyncRunner; | 149 AsyncMethodRunner<Notification> m_asyncRunner; |
131 }; | 150 }; |
132 | 151 |
133 } // namespace blink | 152 } // namespace blink |
134 | 153 |
135 #endif // Notification_h | 154 #endif // Notification_h |
OLD | NEW |