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 "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
41 #include "core/dom/ExecutionContextTask.h" | 41 #include "core/dom/ExecutionContextTask.h" |
42 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 42 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" |
43 #include "core/events/Event.h" | 43 #include "core/events/Event.h" |
44 #include "core/frame/UseCounter.h" | 44 #include "core/frame/UseCounter.h" |
45 #include "modules/notifications/NotificationOptions.h" | 45 #include "modules/notifications/NotificationOptions.h" |
46 #include "modules/notifications/NotificationPermissionClient.h" | 46 #include "modules/notifications/NotificationPermissionClient.h" |
47 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
48 #include "platform/UserGestureIndicator.h" | 48 #include "platform/UserGestureIndicator.h" |
49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
50 #include "public/platform/WebSerializedOrigin.h" | |
51 #include "public/platform/WebString.h" | 50 #include "public/platform/WebString.h" |
52 #include "public/platform/modules/notifications/WebNotificationData.h" | 51 #include "public/platform/modules/notifications/WebNotificationData.h" |
53 #include "public/platform/modules/notifications/WebNotificationManager.h" | 52 #include "public/platform/modules/notifications/WebNotificationManager.h" |
54 | 53 |
55 namespace blink { | 54 namespace blink { |
56 namespace { | 55 namespace { |
57 | 56 |
58 const int64_t kInvalidPersistentId = -1; | 57 const int64_t kInvalidPersistentId = -1; |
59 | 58 |
60 WebNotificationManager* notificationManager() | 59 WebNotificationManager* notificationManager() |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 ASSERT(origin); | 184 ASSERT(origin); |
186 | 185 |
187 // FIXME: Do CSP checks on the associated notification icon. | 186 // FIXME: Do CSP checks on the associated notification icon. |
188 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 187 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
189 | 188 |
190 // The lifetime and availability of non-persistent notifications is tied to
the page | 189 // The lifetime and availability of non-persistent notifications is tied to
the page |
191 // they were created by, and thus the data doesn't have to be known to the e
mbedder. | 190 // they were created by, and thus the data doesn't have to be known to the e
mbedder. |
192 Vector<char> emptyDataWireBytes; | 191 Vector<char> emptyDataWireBytes; |
193 | 192 |
194 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_vibrate, m_silent, emptyDataWireBytes); | 193 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_vibrate, m_silent, emptyDataWireBytes); |
195 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); | 194 notificationManager()->show(*origin, notificationData, this); |
196 | 195 |
197 m_state = NotificationStateShowing; | 196 m_state = NotificationStateShowing; |
198 } | 197 } |
199 | 198 |
200 void Notification::close() | 199 void Notification::close() |
201 { | 200 { |
202 if (m_state != NotificationStateShowing) | 201 if (m_state != NotificationStateShowing) |
203 return; | 202 return; |
204 | 203 |
205 if (m_persistentId == kInvalidPersistentId) { | 204 if (m_persistentId == kInvalidPersistentId) { |
206 // Fire the close event asynchronously. | 205 // Fire the close event asynchronously. |
207 executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notificati
on::dispatchCloseEvent, this)); | 206 executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notificati
on::dispatchCloseEvent, this)); |
208 | 207 |
209 m_state = NotificationStateClosing; | 208 m_state = NotificationStateClosing; |
210 notificationManager()->close(this); | 209 notificationManager()->close(this); |
211 } else { | 210 } else { |
212 m_state = NotificationStateClosed; | 211 m_state = NotificationStateClosed; |
213 | 212 |
214 SecurityOrigin* origin = executionContext()->securityOrigin(); | 213 SecurityOrigin* origin = executionContext()->securityOrigin(); |
215 ASSERT(origin); | 214 ASSERT(origin); |
216 | 215 |
217 notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_p
ersistentId); | 216 notificationManager()->closePersistent(*origin, m_persistentId); |
218 } | 217 } |
219 } | 218 } |
220 | 219 |
221 void Notification::dispatchShowEvent() | 220 void Notification::dispatchShowEvent() |
222 { | 221 { |
223 dispatchEvent(Event::create(EventTypeNames::show)); | 222 dispatchEvent(Event::create(EventTypeNames::show)); |
224 } | 223 } |
225 | 224 |
226 void Notification::dispatchClickEvent() | 225 void Notification::dispatchClickEvent() |
227 { | 226 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 String Notification::permission(ExecutionContext* context) | 275 String Notification::permission(ExecutionContext* context) |
277 { | 276 { |
278 return permissionString(checkPermission(context)); | 277 return permissionString(checkPermission(context)); |
279 } | 278 } |
280 | 279 |
281 WebNotificationPermission Notification::checkPermission(ExecutionContext* contex
t) | 280 WebNotificationPermission Notification::checkPermission(ExecutionContext* contex
t) |
282 { | 281 { |
283 SecurityOrigin* origin = context->securityOrigin(); | 282 SecurityOrigin* origin = context->securityOrigin(); |
284 ASSERT(origin); | 283 ASSERT(origin); |
285 | 284 |
286 return notificationManager()->checkPermission(WebSerializedOrigin(*origin)); | 285 return notificationManager()->checkPermission(*origin); |
287 } | 286 } |
288 | 287 |
289 void Notification::requestPermission(ExecutionContext* context, NotificationPerm
issionCallback* callback) | 288 void Notification::requestPermission(ExecutionContext* context, NotificationPerm
issionCallback* callback) |
290 { | 289 { |
291 // FIXME: Assert that this code-path will only be reached for Document envir
onments | 290 // FIXME: Assert that this code-path will only be reached for Document envir
onments |
292 // when Blink supports [Exposed] annotations on class members in IDL definit
ions. | 291 // when Blink supports [Exposed] annotations on class members in IDL definit
ions. |
293 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) | 292 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) |
294 permissionClient->requestPermission(context, callback); | 293 permissionClient->requestPermission(context, callback); |
295 } | 294 } |
296 | 295 |
(...skipping 30 matching lines...) Expand all Loading... |
327 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); | 326 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); |
328 } | 327 } |
329 | 328 |
330 DEFINE_TRACE(Notification) | 329 DEFINE_TRACE(Notification) |
331 { | 330 { |
332 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 331 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
333 ActiveDOMObject::trace(visitor); | 332 ActiveDOMObject::trace(visitor); |
334 } | 333 } |
335 | 334 |
336 } // namespace blink | 335 } // namespace blink |
OLD | NEW |