Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 102 notification->setPersistentId(persistentId); | 114 notification->setPersistentId(persistentId); |
| 103 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); | 115 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); |
| 104 notification->setLang(data.lang); | 116 notification->setLang(data.lang); |
| 105 notification->setBody(data.body); | 117 notification->setBody(data.body); |
| 106 notification->setTag(data.tag); | 118 notification->setTag(data.tag); |
| 107 notification->setSilent(data.silent); | 119 notification->setSilent(data.silent); |
| 108 | 120 |
| 109 if (!data.icon.isEmpty()) | 121 if (!data.icon.isEmpty()) |
| 110 notification->setIconUrl(data.icon); | 122 notification->setIconUrl(data.icon); |
| 111 | 123 |
| 124 if (!data.data.isNull()) { | |
| 125 notification->setSerializedData(data.data); | |
| 126 notification->serializedData()->registerMemoryAllocatedWithCurrentScript Context(); | |
| 127 } | |
| 128 | |
| 112 notification->setState(NotificationStateShowing); | 129 notification->setState(NotificationStateShowing); |
| 113 notification->suspendIfNeeded(); | 130 notification->suspendIfNeeded(); |
| 114 return notification; | 131 return notification; |
| 115 } | 132 } |
| 116 | 133 |
| 117 Notification::Notification(const String& title, ExecutionContext* context) | 134 Notification::Notification(const String& title, ExecutionContext* context) |
| 118 : ActiveDOMObject(context) | 135 : ActiveDOMObject(context) |
| 119 , m_title(title) | 136 , m_title(title) |
| 120 , m_dir("auto") | 137 , m_dir("auto") |
| 121 , m_silent(false) | 138 , m_silent(false) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 143 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { | 160 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { |
| 144 dispatchErrorEvent(); | 161 dispatchErrorEvent(); |
| 145 return; | 162 return; |
| 146 } | 163 } |
| 147 | 164 |
| 148 SecurityOrigin* origin = executionContext()->securityOrigin(); | 165 SecurityOrigin* origin = executionContext()->securityOrigin(); |
| 149 ASSERT(origin); | 166 ASSERT(origin); |
| 150 | 167 |
| 151 // FIXME: Do CSP checks on the associated notification icon. | 168 // FIXME: Do CSP checks on the associated notification icon. |
| 152 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 169 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
| 153 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent); | 170 |
| 171 // No send data property in non-persistent notification. | |
|
Peter Beverloo
2015/03/12 20:30:46
No -> Don't.
Sanghyun Park
2015/03/13 02:57:07
Okay, I'll fix
| |
| 172 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, PassRefPtr<SerializedScriptValue>(nullptr)); | |
|
Peter Beverloo
2015/03/12 20:30:45
The reason that this doesn't work is that the WebN
Sanghyun Park
2015/03/13 02:57:07
Okay, I'll fix this also.:)
| |
| 154 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); | 173 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); |
| 155 | 174 |
| 156 m_state = NotificationStateShowing; | 175 m_state = NotificationStateShowing; |
| 157 } | 176 } |
| 158 | 177 |
| 159 void Notification::close() | 178 void Notification::close() |
| 160 { | 179 { |
| 161 if (m_state != NotificationStateShowing) | 180 if (m_state != NotificationStateShowing) |
| 162 return; | 181 return; |
| 163 | 182 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 m_state = NotificationStateClosed; | 280 m_state = NotificationStateClosed; |
| 262 | 281 |
| 263 m_asyncRunner.stop(); | 282 m_asyncRunner.stop(); |
| 264 } | 283 } |
| 265 | 284 |
| 266 bool Notification::hasPendingActivity() const | 285 bool Notification::hasPendingActivity() const |
| 267 { | 286 { |
| 268 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); | 287 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); |
| 269 } | 288 } |
| 270 | 289 |
| 290 ScriptValue Notification::data(ScriptState* scriptState) | |
| 291 { | |
| 292 if (!m_dataAsSerializedScriptValue) | |
| 293 return ScriptValue::createNull(scriptState); | |
| 294 | |
| 295 return ScriptValue(scriptState, m_dataAsSerializedScriptValue->deserialize(s criptState->isolate())); | |
| 296 } | |
| 297 | |
| 271 DEFINE_TRACE(Notification) | 298 DEFINE_TRACE(Notification) |
| 272 { | 299 { |
| 273 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); | 300 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); |
| 274 ActiveDOMObject::trace(visitor); | 301 ActiveDOMObject::trace(visitor); |
| 275 } | 302 } |
| 276 | 303 |
| 277 } // namespace blink | 304 } // namespace blink |
| OLD | NEW |