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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "public/platform/modules/notifications/WebNotificationData.h" | 47 #include "public/platform/modules/notifications/WebNotificationData.h" |
48 #include "public/platform/modules/notifications/WebNotificationDelegate.h" | 48 #include "public/platform/modules/notifications/WebNotificationDelegate.h" |
49 #include "public/platform/modules/notifications/WebNotificationPermission.h" | 49 #include "public/platform/modules/notifications/WebNotificationPermission.h" |
50 | 50 |
51 namespace blink { | 51 namespace blink { |
52 | 52 |
53 class ExecutionContext; | 53 class ExecutionContext; |
54 class NotificationAction; | 54 class NotificationAction; |
55 class NotificationOptions; | 55 class NotificationOptions; |
56 class NotificationPermissionCallback; | 56 class NotificationPermissionCallback; |
| 57 class NotificationResourcesLoader; |
57 class ScriptState; | 58 class ScriptState; |
58 | 59 |
59 class MODULES_EXPORT Notification final : public EventTargetWithInlineData, publ
ic ActiveScriptWrappable, public ActiveDOMObject, public WebNotificationDelegate
{ | 60 class MODULES_EXPORT Notification final : public EventTargetWithInlineData, publ
ic ActiveScriptWrappable, public ActiveDOMObject, public WebNotificationDelegate
{ |
60 USING_GARBAGE_COLLECTED_MIXIN(Notification); | 61 USING_GARBAGE_COLLECTED_MIXIN(Notification); |
61 DEFINE_WRAPPERTYPEINFO(); | 62 DEFINE_WRAPPERTYPEINFO(); |
62 public: | 63 public: |
63 // Used for JavaScript instantiations of the Notification object. Will autom
atically schedule for | 64 // Used for JavaScript instantiations of the Notification object. Will autom
atically schedule for |
64 // the notification to be displayed to the user when the developer-provided
data is valid. | 65 // the notification to be displayed to the user when the developer-provided
data is valid. |
65 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&, ExceptionState&); | 66 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&, ExceptionState&); |
66 | 67 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 118 |
118 DECLARE_VIRTUAL_TRACE(); | 119 DECLARE_VIRTUAL_TRACE(); |
119 | 120 |
120 protected: | 121 protected: |
121 // EventTarget interface. | 122 // EventTarget interface. |
122 DispatchEventResult dispatchEventInternal(Event*) final; | 123 DispatchEventResult dispatchEventInternal(Event*) final; |
123 | 124 |
124 private: | 125 private: |
125 Notification(ExecutionContext*, const WebNotificationData&); | 126 Notification(ExecutionContext*, const WebNotificationData&); |
126 | 127 |
127 void scheduleShow(); | 128 // Schedules an asynchronous call to |prepareShow|, allowing the constructor |
| 129 // to return so that events can be fired on the notification object. |
| 130 void schedulePrepareShow(); |
128 | 131 |
129 // Calling show() may start asynchronous operation. If this object has | 132 // Checks permission and loads any necessary resources (this may be async) |
130 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being | 133 // before showing the notification. |
131 // collected while m_state is Showing, and so this instance stays alive | 134 void prepareShow(); |
132 // until the operation completes. Otherwise, you need to hold a ref on this | 135 |
133 // instance until the operation completes. | 136 // Shows the notification, using the resources loaded by the |
134 void show(); | 137 // NotificationResourcesLoader. |
| 138 void didLoadResources(NotificationResourcesLoader*); |
135 | 139 |
136 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId;
} | 140 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId;
} |
137 | 141 |
138 WebNotificationData m_data; | 142 WebNotificationData m_data; |
139 | 143 |
140 // ScriptValue representations of the developer-associated data. Initialized
lazily on first access. | 144 // ScriptValue representations of the developer-associated data. Initialized
lazily on first access. |
141 ScriptValue m_developerData; | 145 ScriptValue m_developerData; |
142 | 146 |
143 // Notifications can either be bound to the page, which means they're identi
fied by | 147 // Notifications can either be bound to the page, which means they're identi
fied by |
144 // their delegate, or persistent, which means they're identified by a persis
tent Id | 148 // their delegate, or persistent, which means they're identified by a persis
tent Id |
145 // given to us by the embedder. This influences how we close the notificatio
n. | 149 // given to us by the embedder. This influences how we close the notificatio
n. |
146 int64_t m_persistentId; | 150 int64_t m_persistentId; |
147 | 151 |
148 enum NotificationState { | 152 enum NotificationState { |
149 NotificationStateIdle, | 153 NotificationStateIdle, |
150 NotificationStateShowing, | 154 NotificationStateShowing, |
151 NotificationStateClosing, | 155 NotificationStateClosing, |
152 NotificationStateClosed | 156 NotificationStateClosed |
153 }; | 157 }; |
154 | 158 |
155 // Only to be used by the Notification::create() method when notifications w
ere created | 159 // Only to be used by the Notification::create() method when notifications w
ere created |
156 // by the embedder rather than by Blink. | 160 // by the embedder rather than by Blink. |
157 void setState(NotificationState state) { m_state = state; } | 161 void setState(NotificationState state) { m_state = state; } |
158 | 162 |
159 NotificationState m_state; | 163 NotificationState m_state; |
160 | 164 |
161 Member<AsyncMethodRunner<Notification>> m_asyncRunner; | 165 Member<AsyncMethodRunner<Notification>> m_prepareShowMethodRunner; |
| 166 |
| 167 Member<NotificationResourcesLoader> m_loader; |
162 }; | 168 }; |
163 | 169 |
164 } // namespace blink | 170 } // namespace blink |
165 | 171 |
166 #endif // Notification_h | 172 #endif // Notification_h |
OLD | NEW |