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 30 matching lines...) Expand all Loading... |
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" | 50 #include "public/platform/WebSerializedOrigin.h" |
| 51 #include "public/platform/WebString.h" |
51 #include "public/platform/modules/notifications/WebNotificationData.h" | 52 #include "public/platform/modules/notifications/WebNotificationData.h" |
52 #include "public/platform/modules/notifications/WebNotificationManager.h" | 53 #include "public/platform/modules/notifications/WebNotificationManager.h" |
53 | 54 |
54 namespace blink { | 55 namespace blink { |
55 namespace { | 56 namespace { |
56 | 57 |
57 WebNotificationManager* notificationManager() | 58 WebNotificationManager* notificationManager() |
58 { | 59 { |
59 return Platform::current()->notificationManager(); | 60 return Platform::current()->notificationManager(); |
60 } | 61 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 notification->setPersistentId(persistentId); | 115 notification->setPersistentId(persistentId); |
115 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); | 116 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
116 notification->setLang(data.lang); | 117 notification->setLang(data.lang); |
117 notification->setBody(data.body); | 118 notification->setBody(data.body); |
118 notification->setTag(data.tag); | 119 notification->setTag(data.tag); |
119 notification->setSilent(data.silent); | 120 notification->setSilent(data.silent); |
120 | 121 |
121 if (!data.icon.isEmpty()) | 122 if (!data.icon.isEmpty()) |
122 notification->setIconUrl(data.icon); | 123 notification->setIconUrl(data.icon); |
123 | 124 |
| 125 if (!data.data.isEmpty()) { |
| 126 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWire(data.data)); |
| 127 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); |
| 128 } |
| 129 |
124 notification->setState(NotificationStateShowing); | 130 notification->setState(NotificationStateShowing); |
125 notification->suspendIfNeeded(); | 131 notification->suspendIfNeeded(); |
126 return notification; | 132 return notification; |
127 } | 133 } |
128 | 134 |
129 Notification::Notification(const String& title, ExecutionContext* context) | 135 Notification::Notification(const String& title, ExecutionContext* context) |
130 : ActiveDOMObject(context) | 136 : ActiveDOMObject(context) |
131 , m_title(title) | 137 , m_title(title) |
132 , m_dir("auto") | 138 , m_dir("auto") |
133 , m_silent(false) | 139 , m_silent(false) |
(...skipping 21 matching lines...) Expand all Loading... |
155 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { | 161 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { |
156 dispatchErrorEvent(); | 162 dispatchErrorEvent(); |
157 return; | 163 return; |
158 } | 164 } |
159 | 165 |
160 SecurityOrigin* origin = executionContext()->securityOrigin(); | 166 SecurityOrigin* origin = executionContext()->securityOrigin(); |
161 ASSERT(origin); | 167 ASSERT(origin); |
162 | 168 |
163 // FIXME: Do CSP checks on the associated notification icon. | 169 // FIXME: Do CSP checks on the associated notification icon. |
164 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 170 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
165 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_silent); | 171 |
| 172 // The lifetime and availability of non-persistent notifications is tied to
the page |
| 173 // they were created by, and thus the data doesn't have to be known to the e
mbedder. |
| 174 String emptyDataAsWireString; |
| 175 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_silent, emptyDataAsWireString); |
166 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); | 176 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); |
167 | 177 |
168 m_state = NotificationStateShowing; | 178 m_state = NotificationStateShowing; |
169 } | 179 } |
170 | 180 |
171 void Notification::close() | 181 void Notification::close() |
172 { | 182 { |
173 if (m_state != NotificationStateShowing) | 183 if (m_state != NotificationStateShowing) |
174 return; | 184 return; |
175 | 185 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); | 302 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); |
293 } | 303 } |
294 | 304 |
295 DEFINE_TRACE(Notification) | 305 DEFINE_TRACE(Notification) |
296 { | 306 { |
297 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 307 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
298 ActiveDOMObject::trace(visitor); | 308 ActiveDOMObject::trace(visitor); |
299 } | 309 } |
300 | 310 |
301 } // namespace blink | 311 } // namespace blink |
OLD | NEW |