 Chromium Code Reviews
 Chromium Code Reviews Issue 993893002:
  Add the data attribute to the Notification object  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 993893002:
  Add the data attribute to the Notification object  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| 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/ScriptValue.h" | |
| 34 #include "bindings/core/v8/ScriptWrappable.h" | 36 #include "bindings/core/v8/ScriptWrappable.h" | 
| 37 #include "bindings/core/v8/SerializedScriptValueFactory.h" | |
| 35 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" | 
| 36 #include "core/dom/ExecutionContext.h" | 39 #include "core/dom/ExecutionContext.h" | 
| 37 #include "core/dom/ExecutionContextTask.h" | 40 #include "core/dom/ExecutionContextTask.h" | 
| 38 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 41 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 
| 39 #include "core/events/Event.h" | 42 #include "core/events/Event.h" | 
| 40 #include "core/frame/UseCounter.h" | 43 #include "core/frame/UseCounter.h" | 
| 41 #include "modules/notifications/NotificationOptions.h" | 44 #include "modules/notifications/NotificationOptions.h" | 
| 42 #include "modules/notifications/NotificationPermissionClient.h" | 45 #include "modules/notifications/NotificationPermissionClient.h" | 
| 43 #include "platform/RuntimeEnabledFeatures.h" | 46 #include "platform/RuntimeEnabledFeatures.h" | 
| 44 #include "platform/UserGestureIndicator.h" | 47 #include "platform/UserGestureIndicator.h" | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 65 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); | 68 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); | 
| 66 return nullptr; | 69 return nullptr; | 
| 67 } | 70 } | 
| 68 | 71 | 
| 69 // The Web Notification constructor may not be used in Service Worker contex ts. | 72 // The Web Notification constructor may not be used in Service Worker contex ts. | 
| 70 if (context->isServiceWorkerGlobalScope()) { | 73 if (context->isServiceWorkerGlobalScope()) { | 
| 71 exceptionState.throwTypeError("Illegal constructor."); | 74 exceptionState.throwTypeError("Illegal constructor."); | 
| 72 return nullptr; | 75 return nullptr; | 
| 73 } | 76 } | 
| 74 | 77 | 
| 78 RefPtr<SerializedScriptValue> data; | |
| 79 if (options.hasData()) { | |
| 80 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate()); | |
| 81 if (exceptionState.hadException()) | |
| 82 return nullptr; | |
| 83 } | |
| 84 | |
| 75 Notification* notification = new Notification(title, context); | 85 Notification* notification = new Notification(title, context); | 
| 76 | 86 | 
| 77 notification->setBody(options.body()); | 87 notification->setBody(options.body()); | 
| 78 notification->setTag(options.tag()); | 88 notification->setTag(options.tag()); | 
| 79 notification->setLang(options.lang()); | 89 notification->setLang(options.lang()); | 
| 80 notification->setDir(options.dir()); | 90 notification->setDir(options.dir()); | 
| 81 notification->setSilent(options.silent()); | 91 notification->setSilent(options.silent()); | 
| 92 notification->setData(data.release()); | |
| 82 if (options.hasIcon()) { | 93 if (options.hasIcon()) { | 
| 83 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); | 94 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); | 
| 84 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 95 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 
| 85 notification->setIconUrl(iconUrl); | 96 notification->setIconUrl(iconUrl); | 
| 86 } | 97 } | 
| 87 | 98 | 
| 88 String insecureOriginMessage; | 99 String insecureOriginMessage; | 
| 89 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) | 100 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) | 
| 90 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin; | 101 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin; | 
| 91 UseCounter::count(context, feature); | 102 UseCounter::count(context, feature); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 102 notification->setPersistentId(persistentId); | 113 notification->setPersistentId(persistentId); | 
| 103 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); | 114 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); | 
| 104 notification->setLang(data.lang); | 115 notification->setLang(data.lang); | 
| 105 notification->setBody(data.body); | 116 notification->setBody(data.body); | 
| 106 notification->setTag(data.tag); | 117 notification->setTag(data.tag); | 
| 107 notification->setSilent(data.silent); | 118 notification->setSilent(data.silent); | 
| 108 | 119 | 
| 109 if (!data.icon.isEmpty()) | 120 if (!data.icon.isEmpty()) | 
| 110 notification->setIconUrl(data.icon); | 121 notification->setIconUrl(data.icon); | 
| 111 | 122 | 
| 123 if (!data.data.isNull()) { | |
| 124 notification->setData(data.data); | |
| 125 notification->data()->registerMemoryAllocatedWithCurrentScriptContext(); | |
| 126 } | |
| 127 | |
| 112 notification->setState(NotificationStateShowing); | 128 notification->setState(NotificationStateShowing); | 
| 113 notification->suspendIfNeeded(); | 129 notification->suspendIfNeeded(); | 
| 114 return notification; | 130 return notification; | 
| 115 } | 131 } | 
| 116 | 132 | 
| 117 Notification::Notification(const String& title, ExecutionContext* context) | 133 Notification::Notification(const String& title, ExecutionContext* context) | 
| 118 : ActiveDOMObject(context) | 134 : ActiveDOMObject(context) | 
| 119 , m_title(title) | 135 , m_title(title) | 
| 120 , m_dir("auto") | 136 , m_dir("auto") | 
| 121 , m_silent(false) | 137 , m_silent(false) | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 143 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { | 159 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { | 
| 144 dispatchErrorEvent(); | 160 dispatchErrorEvent(); | 
| 145 return; | 161 return; | 
| 146 } | 162 } | 
| 147 | 163 | 
| 148 SecurityOrigin* origin = executionContext()->securityOrigin(); | 164 SecurityOrigin* origin = executionContext()->securityOrigin(); | 
| 149 ASSERT(origin); | 165 ASSERT(origin); | 
| 150 | 166 | 
| 151 // FIXME: Do CSP checks on the associated notification icon. | 167 // FIXME: Do CSP checks on the associated notification icon. | 
| 152 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 168 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); | 169 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, m_data.get()); | 
| 
Peter Beverloo
2015/03/12 01:16:26
Why does the embedder have to know about the data
 
Sanghyun Park
2015/03/12 02:58:47
I understand about your meant.
non-persistent do n
 
Sanghyun Park
2015/03/12 11:52:58
When I think of that, above suggested way is not g
 
Sanghyun Park
2015/03/12 12:39:36
Oops. I was wrong. we can use PassRefPtr<Serialize
 | |
| 154 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); | 170 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); | 
| 155 | 171 | 
| 156 m_state = NotificationStateShowing; | 172 m_state = NotificationStateShowing; | 
| 157 } | 173 } | 
| 158 | 174 | 
| 159 void Notification::close() | 175 void Notification::close() | 
| 160 { | 176 { | 
| 161 if (m_state != NotificationStateShowing) | 177 if (m_state != NotificationStateShowing) | 
| 162 return; | 178 return; | 
| 163 | 179 | 
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); | 284 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); | 
| 269 } | 285 } | 
| 270 | 286 | 
| 271 DEFINE_TRACE(Notification) | 287 DEFINE_TRACE(Notification) | 
| 272 { | 288 { | 
| 273 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); | 289 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); | 
| 274 ActiveDOMObject::trace(visitor); | 290 ActiveDOMObject::trace(visitor); | 
| 275 } | 291 } | 
| 276 | 292 | 
| 277 } // namespace blink | 293 } // namespace blink | 
| OLD | NEW |