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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "platform/weborigin/KURL.h" | 45 #include "platform/weborigin/KURL.h" |
46 #include "public/platform/WebVector.h" | 46 #include "public/platform/WebVector.h" |
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/permissions/permission.mojom-blink.h" | 49 #include "public/platform/modules/permissions/permission.mojom-blink.h" |
50 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" | 50 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" |
51 | 51 |
52 namespace blink { | 52 namespace blink { |
53 | 53 |
54 class ExecutionContext; | 54 class ExecutionContext; |
55 class NotificationAction; | |
56 class NotificationManager; | |
57 class NotificationOptions; | 55 class NotificationOptions; |
58 class NotificationPermissionCallback; | 56 class NotificationPermissionCallback; |
59 class NotificationResourcesLoader; | 57 class NotificationResourcesLoader; |
60 class ScriptState; | 58 class ScriptState; |
61 | 59 |
62 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
{ |
63 USING_GARBAGE_COLLECTED_MIXIN(Notification); | 61 USING_GARBAGE_COLLECTED_MIXIN(Notification); |
64 DEFINE_WRAPPERTYPEINFO(); | 62 DEFINE_WRAPPERTYPEINFO(); |
65 public: | 63 public: |
66 // Used for JavaScript instantiations of the Notification object. Will autom
atically schedule for | 64 // Used for JavaScript instantiations of non-persistent notifications. Will |
67 // the notification to be displayed to the user when the developer-provided
data is valid. | 65 // automatically schedule for the notification to be displayed to the user |
| 66 // when the developer-provided data is valid. |
68 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&, ExceptionState&); | 67 static Notification* create(ExecutionContext*, const String& title, const No
tificationOptions&, ExceptionState&); |
69 | 68 |
70 // Used for embedder-created Notification objects. If |showing| is true, wil
l initialize the | 69 // Used for embedder-created persistent notifications. Initializes the state |
71 // Notification's state as showing, or as closed otherwise. | 70 // of the notification as either Showing or Closed based on |showing|. |
72 static Notification* create(ExecutionContext*, const String& notificationId,
const WebNotificationData&, bool showing); | 71 static Notification* create(ExecutionContext*, const String& notificationId,
const WebNotificationData&, bool showing); |
73 | 72 |
74 ~Notification() override; | 73 ~Notification() override; |
75 | 74 |
76 void close(); | 75 void close(); |
77 | 76 |
78 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); | 77 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); |
79 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); | 78 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); |
80 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 79 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
81 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // ScriptWrappable interface. | 117 // ScriptWrappable interface. |
119 bool hasPendingActivity() const final; | 118 bool hasPendingActivity() const final; |
120 | 119 |
121 DECLARE_VIRTUAL_TRACE(); | 120 DECLARE_VIRTUAL_TRACE(); |
122 | 121 |
123 protected: | 122 protected: |
124 // EventTarget interface. | 123 // EventTarget interface. |
125 DispatchEventResult dispatchEventInternal(Event*) final; | 124 DispatchEventResult dispatchEventInternal(Event*) final; |
126 | 125 |
127 private: | 126 private: |
128 Notification(ExecutionContext*, const WebNotificationData&); | 127 // The type of notification this instance represents. Non-persistent |
| 128 // notifications will have events delivered to their instance, whereas |
| 129 // persistent notification will be using a Service Worker. |
| 130 enum class Type { |
| 131 NonPersistent, |
| 132 Persistent |
| 133 }; |
| 134 |
| 135 // The current phase of the notification in its lifecycle. |
| 136 enum class State { |
| 137 Loading, |
| 138 Showing, |
| 139 Closing, |
| 140 Closed |
| 141 }; |
| 142 |
| 143 Notification(ExecutionContext*, Type, const WebNotificationData&); |
| 144 |
| 145 // Sets the state of the notification in its lifecycle. |
| 146 void setState(State state) { m_state = state; } |
| 147 |
| 148 // Sets the notification ID to |notificationId|. This should be done once |
| 149 // the notification has shown for non-persistent notifications, and at |
| 150 // object initialisation time for persistent notifications. |
| 151 void setNotificationId(const String& notificationId) { m_notificationId = no
tificationId; } |
129 | 152 |
130 // Schedules an asynchronous call to |prepareShow|, allowing the constructor | 153 // Schedules an asynchronous call to |prepareShow|, allowing the constructor |
131 // to return so that events can be fired on the notification object. | 154 // to return so that events can be fired on the notification object. |
132 void schedulePrepareShow(); | 155 void schedulePrepareShow(); |
133 | 156 |
134 // Checks permission and loads any necessary resources (this may be async) | 157 // Verifies that permission has been granted, then asynchronously starts |
135 // before showing the notification. | 158 // loading the resources associated with this notification. |
136 void prepareShow(); | 159 void prepareShow(); |
137 | 160 |
138 // Shows the notification, using the resources loaded by the | 161 // Shows the notification through the embedder using the loaded resources. |
139 // NotificationResourcesLoader. | |
140 void didLoadResources(NotificationResourcesLoader*); | 162 void didLoadResources(NotificationResourcesLoader*); |
141 | 163 |
142 void setNotificationId(const String& notificationId) { m_notificationId = no
tificationId; } | 164 Type m_type; |
| 165 State m_state; |
143 | 166 |
144 WebNotificationData m_data; | 167 WebNotificationData m_data; |
145 | 168 |
146 // Notifications can either be bound to the page, which means they're identi
fied by | |
147 // their delegate, or persistent, which means they're identified by a persis
tent Id | |
148 // given to us by the embedder. This influences how we close the notificatio
n. | |
149 String m_notificationId; | 169 String m_notificationId; |
150 | 170 |
151 enum NotificationState { | |
152 NotificationStateIdle, | |
153 NotificationStateShowing, | |
154 NotificationStateClosing, | |
155 NotificationStateClosed | |
156 }; | |
157 | |
158 // Only to be used by the Notification::create() method when notifications w
ere created | |
159 // by the embedder rather than by Blink. | |
160 void setState(NotificationState state) { m_state = state; } | |
161 | |
162 NotificationState m_state; | |
163 | |
164 Member<AsyncMethodRunner<Notification>> m_prepareShowMethodRunner; | 171 Member<AsyncMethodRunner<Notification>> m_prepareShowMethodRunner; |
165 | 172 |
166 Member<NotificationResourcesLoader> m_loader; | 173 Member<NotificationResourcesLoader> m_loader; |
167 }; | 174 }; |
168 | 175 |
169 } // namespace blink | 176 } // namespace blink |
170 | 177 |
171 #endif // Notification_h | 178 #endif // Notification_h |
OLD | NEW |