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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/notifications/Notification.h" | 32 #include "modules/notifications/Notification.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | |
35 #include "bindings/core/v8/ScriptState.h" | |
36 #include "bindings/core/v8/ScriptValue.h" | |
34 #include "bindings/core/v8/ScriptWrappable.h" | 37 #include "bindings/core/v8/ScriptWrappable.h" |
38 #include "bindings/core/v8/SerializedScriptValueFactory.h" | |
35 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
36 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
37 #include "core/dom/ExecutionContextTask.h" | 41 #include "core/dom/ExecutionContextTask.h" |
38 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 42 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" |
39 #include "core/events/Event.h" | 43 #include "core/events/Event.h" |
40 #include "core/frame/UseCounter.h" | 44 #include "core/frame/UseCounter.h" |
41 #include "modules/notifications/NotificationOptions.h" | 45 #include "modules/notifications/NotificationOptions.h" |
42 #include "modules/notifications/NotificationPermissionClient.h" | 46 #include "modules/notifications/NotificationPermissionClient.h" |
43 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
44 #include "platform/UserGestureIndicator.h" | 48 #include "platform/UserGestureIndicator.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
65 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); | 69 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); |
66 return nullptr; | 70 return nullptr; |
67 } | 71 } |
68 | 72 |
69 // The Web Notification constructor may not be used in Service Worker contex ts. | 73 // The Web Notification constructor may not be used in Service Worker contex ts. |
70 if (context->isServiceWorkerGlobalScope()) { | 74 if (context->isServiceWorkerGlobalScope()) { |
71 exceptionState.throwTypeError("Illegal constructor."); | 75 exceptionState.throwTypeError("Illegal constructor."); |
72 return nullptr; | 76 return nullptr; |
73 } | 77 } |
74 | 78 |
79 RefPtr<SerializedScriptValue> data; | |
80 if (options.hasData()) { | |
81 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate()); | |
82 if (exceptionState.hadException()) | |
83 return nullptr; | |
84 } | |
85 | |
75 Notification* notification = new Notification(title, context); | 86 Notification* notification = new Notification(title, context); |
76 | 87 |
77 notification->setBody(options.body()); | 88 notification->setBody(options.body()); |
78 notification->setTag(options.tag()); | 89 notification->setTag(options.tag()); |
79 notification->setLang(options.lang()); | 90 notification->setLang(options.lang()); |
80 notification->setDir(options.dir()); | 91 notification->setDir(options.dir()); |
81 notification->setSilent(options.silent()); | 92 notification->setSilent(options.silent()); |
93 notification->setSerializedData(data.release()); | |
82 if (options.hasIcon()) { | 94 if (options.hasIcon()) { |
83 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); | 95 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); |
84 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 96 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
85 notification->setIconUrl(iconUrl); | 97 notification->setIconUrl(iconUrl); |
86 } | 98 } |
87 | 99 |
88 String insecureOriginMessage; | 100 String insecureOriginMessage; |
89 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) | 101 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) |
90 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin; | 102 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin; |
91 UseCounter::count(context, feature); | 103 UseCounter::count(context, feature); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 m_state = NotificationStateClosed; | 273 m_state = NotificationStateClosed; |
262 | 274 |
263 m_asyncRunner.stop(); | 275 m_asyncRunner.stop(); |
264 } | 276 } |
265 | 277 |
266 bool Notification::hasPendingActivity() const | 278 bool Notification::hasPendingActivity() const |
267 { | 279 { |
268 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); | 280 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); |
269 } | 281 } |
270 | 282 |
283 ScriptValue Notification::data(ScriptState* scriptState) | |
Peter Beverloo
2015/03/13 12:12:07
nit: can this be const?
Sanghyun Park
2015/03/13 17:47:31
I'll add this keyword
| |
284 { | |
285 if (!m_serializedData) | |
286 return ScriptValue::createNull(scriptState); | |
287 | |
288 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); | |
289 } | |
290 | |
271 DEFINE_TRACE(Notification) | 291 DEFINE_TRACE(Notification) |
272 { | 292 { |
273 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); | 293 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); |
274 ActiveDOMObject::trace(visitor); | 294 ActiveDOMObject::trace(visitor); |
275 } | 295 } |
276 | 296 |
277 } // namespace blink | 297 } // namespace blink |
OLD | NEW |