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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/notifications/Notification.cpp
diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp
index 0a8cf69dae08118ca53c7ea87a16e0f59bf85c07..22f8dc2fa870ab582a72efd4069420816c08704a 100644
--- a/Source/modules/notifications/Notification.cpp
+++ b/Source/modules/notifications/Notification.cpp
@@ -31,7 +31,11 @@
#include "config.h"
#include "modules/notifications/Notification.h"
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/ScriptWrappable.h"
+#include "bindings/core/v8/SerializedScriptValueFactory.h"
#include "core/dom/Document.h"
#include "core/dom/ExecutionContext.h"
#include "core/dom/ExecutionContextTask.h"
@@ -72,6 +76,13 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
return nullptr;
}
+ RefPtr<SerializedScriptValue> data;
+ if (options.hasData()) {
+ data = SerializedScriptValueFactory::instance().create(options.data(), nullptr, exceptionState, options.data().isolate());
+ if (exceptionState.hadException())
+ return nullptr;
+ }
+
Notification* notification = new Notification(title, context);
notification->setBody(options.body());
@@ -79,6 +90,7 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
notification->setLang(options.lang());
notification->setDir(options.dir());
notification->setSilent(options.silent());
+ notification->setSerializedData(data.release());
if (options.hasIcon()) {
KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(options.icon());
if (!iconUrl.isEmpty() && iconUrl.isValid())
@@ -109,6 +121,11 @@ Notification* Notification::create(ExecutionContext* context, const String& pers
if (!data.icon.isEmpty())
notification->setIconUrl(data.icon);
+ if (!data.data.isNull()) {
+ notification->setSerializedData(data.data);
+ notification->serializedData()->registerMemoryAllocatedWithCurrentScriptContext();
+ }
+
notification->setState(NotificationStateShowing);
notification->suspendIfNeeded();
return notification;
@@ -150,7 +167,9 @@ void Notification::show()
// FIXME: Do CSP checks on the associated notification icon.
WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight;
- WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_iconUrl, m_silent);
+
+ // 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
+ 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.:)
notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this);
m_state = NotificationStateShowing;
@@ -268,6 +287,14 @@ bool Notification::hasPendingActivity() const
return m_state == NotificationStateShowing || m_asyncRunner.isActive();
}
+ScriptValue Notification::data(ScriptState* scriptState)
+{
+ if (!m_dataAsSerializedScriptValue)
+ return ScriptValue::createNull(scriptState);
+
+ return ScriptValue(scriptState, m_dataAsSerializedScriptValue->deserialize(scriptState->isolate()));
+}
+
DEFINE_TRACE(Notification)
{
RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(visitor);

Powered by Google App Engine
This is Rietveld 408576698