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

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: Fix layout test failures. 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 /* 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
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
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 m_state = NotificationStateClosed; 277 m_state = NotificationStateClosed;
266 278
267 m_asyncRunner.stop(); 279 m_asyncRunner.stop();
268 } 280 }
269 281
270 bool Notification::hasPendingActivity() const 282 bool Notification::hasPendingActivity() const
271 { 283 {
272 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); 284 return m_state == NotificationStateShowing || m_asyncRunner.isActive();
273 } 285 }
274 286
287 ScriptValue Notification::data(ScriptState* scriptState) const
288 {
289 if (!m_serializedData)
290 return ScriptValue::createNull(scriptState);
291
292 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate()));
293 }
294
275 DEFINE_TRACE(Notification) 295 DEFINE_TRACE(Notification)
276 { 296 {
277 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 297 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
278 ActiveDOMObject::trace(visitor); 298 ActiveDOMObject::trace(visitor);
279 } 299 }
280 300
281 } // namespace blink 301 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698