Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: Source/modules/notifications/Notification.cpp

Issue 993893002: Add the data attribute to the Notification object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: [WIP] modified wrong comment. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1
Peter Beverloo 2015/03/10 23:34:26 nit: no blank line
Sanghyun Park 2015/03/11 10:59:52 Oops, this is my fault;; I'll remove this.
1 /* 2 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
6 * met: 7 * met:
7 * 8 *
8 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (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. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 30 */
30 31
31 #include "config.h" 32 #include "config.h"
32 #include "modules/notifications/Notification.h" 33 #include "modules/notifications/Notification.h"
33 34
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 notification->setTag(options.tag()); 81 notification->setTag(options.tag());
79 notification->setLang(options.lang()); 82 notification->setLang(options.lang());
80 notification->setDir(options.dir()); 83 notification->setDir(options.dir());
81 notification->setSilent(options.silent()); 84 notification->setSilent(options.silent());
82 if (options.hasIcon()) { 85 if (options.hasIcon()) {
83 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); 86 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon());
84 if (!iconUrl.isEmpty() && iconUrl.isValid()) 87 if (!iconUrl.isEmpty() && iconUrl.isValid())
85 notification->setIconUrl(iconUrl); 88 notification->setIconUrl(iconUrl);
86 } 89 }
87 90
91 if (options.hasData()) {
92 notification->setData(SerializedScriptValueFactory::instance().create(op tions.data(), 0, exceptionState, options.data().isolate()));
Peter Beverloo 2015/03/10 23:34:26 We would need to abort after this call if an excep
Peter Beverloo 2015/03/10 23:34:26 nit: s/0/nullptr/
Sanghyun Park 2015/03/11 10:59:52 I'll fix this.
Sanghyun Park 2015/03/11 10:59:52 I fully agree about your opinion. I think that to
93 notification->data()->registerMemoryAllocatedWithCurrentScriptContext();
Peter Beverloo 2015/03/10 23:34:26 I don't think we need this here. If I read the co
Sanghyun Park 2015/03/11 10:59:52 I had checked about this again. You are right! I
94 }
95
88 String insecureOriginMessage; 96 String insecureOriginMessage;
89 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) 97 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage)
90 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin; 98 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin;
91 UseCounter::count(context, feature); 99 UseCounter::count(context, feature);
92 100
93 notification->scheduleShow(); 101 notification->scheduleShow();
94 notification->suspendIfNeeded(); 102 notification->suspendIfNeeded();
95 return notification; 103 return notification;
96 } 104 }
97 105
98 Notification* Notification::create(ExecutionContext* context, const String& pers istentId, const WebNotificationData& data) 106 Notification* Notification::create(ExecutionContext* context, const String& pers istentId, const WebNotificationData& data)
99 { 107 {
100 Notification* notification = new Notification(data.title, context); 108 Notification* notification = new Notification(data.title, context);
101 109
102 notification->setPersistentId(persistentId); 110 notification->setPersistentId(persistentId);
103 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); 111 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl");
104 notification->setLang(data.lang); 112 notification->setLang(data.lang);
105 notification->setBody(data.body); 113 notification->setBody(data.body);
106 notification->setTag(data.tag); 114 notification->setTag(data.tag);
107 notification->setSilent(data.silent); 115 notification->setSilent(data.silent);
108 116
109 if (!data.icon.isEmpty()) 117 if (!data.icon.isEmpty())
110 notification->setIconUrl(data.icon); 118 notification->setIconUrl(data.icon);
111 119
120 if (!data.data.isNull()) {
121 notification->setData(data.data);
122 notification->data()->registerMemoryAllocatedWithCurrentScriptContext();
123 }
124
112 notification->setState(NotificationStateShowing); 125 notification->setState(NotificationStateShowing);
113 notification->suspendIfNeeded(); 126 notification->suspendIfNeeded();
114 return notification; 127 return notification;
115 } 128 }
116 129
117 Notification::Notification(const String& title, ExecutionContext* context) 130 Notification::Notification(const String& title, ExecutionContext* context)
118 : ActiveDOMObject(context) 131 : ActiveDOMObject(context)
119 , m_title(title) 132 , m_title(title)
120 , m_dir("auto") 133 , m_dir("auto")
121 , m_silent(false) 134 , m_silent(false)
(...skipping 21 matching lines...) Expand all
143 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { 156 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) {
144 dispatchErrorEvent(); 157 dispatchErrorEvent();
145 return; 158 return;
146 } 159 }
147 160
148 SecurityOrigin* origin = executionContext()->securityOrigin(); 161 SecurityOrigin* origin = executionContext()->securityOrigin();
149 ASSERT(origin); 162 ASSERT(origin);
150 163
151 // FIXME: Do CSP checks on the associated notification icon. 164 // FIXME: Do CSP checks on the associated notification icon.
152 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; 165 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); 166 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, m_data.release());
Peter Beverloo 2015/03/10 23:34:26 Why does the embedder need to know about the data
Sanghyun Park 2015/03/11 10:59:52 Oops, This is my mistake. I'll change to data.get(
154 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); 167 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this);
155 168
156 m_state = NotificationStateShowing; 169 m_state = NotificationStateShowing;
157 } 170 }
158 171
159 void Notification::close() 172 void Notification::close()
160 { 173 {
161 if (m_state != NotificationStateShowing) 174 if (m_state != NotificationStateShowing)
162 return; 175 return;
163 176
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); 281 return m_state == NotificationStateShowing || m_asyncRunner.isActive();
269 } 282 }
270 283
271 DEFINE_TRACE(Notification) 284 DEFINE_TRACE(Notification)
272 { 285 {
273 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 286 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
274 ActiveDOMObject::trace(visitor); 287 ActiveDOMObject::trace(visitor);
275 } 288 }
276 289
277 } // namespace blink 290 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698