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

Unified Diff: Source/modules/notifications/Notification.cpp

Issue 1078783002: Update the Notification Blink API to use integral persistent ids. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/web/ServiceWorkerGlobalScopeProxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/notifications/Notification.cpp
diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp
index 4822a20c94ea8521ccb12068a90dbcb1ff8198d6..867e438265d8171fc5c7cefd73b3a477a9b5f150 100644
--- a/Source/modules/notifications/Notification.cpp
+++ b/Source/modules/notifications/Notification.cpp
@@ -55,6 +55,8 @@
namespace blink {
namespace {
+const int64_t kInvalidPersistentId = -1;
+
WebNotificationManager* notificationManager()
{
return Platform::current()->notificationManager();
@@ -108,7 +110,7 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
return notification;
}
-Notification* Notification::create(ExecutionContext* context, const String& persistentId, const WebNotificationData& data)
+Notification* Notification::create(ExecutionContext* context, int64_t persistentId, const WebNotificationData& data)
{
Notification* notification = new Notification(data.title, context);
@@ -133,11 +135,37 @@ Notification* Notification::create(ExecutionContext* context, const String& pers
return notification;
}
+Notification* Notification::create(ExecutionContext* context, const String& persistentId, const WebNotificationData& data)
+{
+ Notification* notification = new Notification(data.title, context);
+
+ notification->setPersistentIdString(persistentId);
+ notification->setDir(data.direction == WebNotificationData::DirectionLeftToRight ? "ltr" : "rtl");
+ notification->setLang(data.lang);
+ notification->setBody(data.body);
+ notification->setTag(data.tag);
+ notification->setSilent(data.silent);
+
+ if (!data.icon.isEmpty())
+ notification->setIconUrl(data.icon);
+
+ const WebVector<char>& dataBytes = data.data;
+ if (!dataBytes.isEmpty()) {
+ notification->setSerializedData(SerializedScriptValueFactory::instance().createFromWireBytes(dataBytes.data(), dataBytes.size()));
+ notification->serializedData()->registerMemoryAllocatedWithCurrentScriptContext();
+ }
+
+ notification->setState(NotificationStateShowing);
+ notification->suspendIfNeeded();
+ return notification;
+}
+
Notification::Notification(const String& title, ExecutionContext* context)
: ActiveDOMObject(context)
, m_title(title)
, m_dir("auto")
, m_silent(false)
+ , m_persistentId(kInvalidPersistentId)
, m_state(NotificationStateIdle)
, m_asyncRunner(this, &Notification::show)
{
@@ -185,7 +213,7 @@ void Notification::close()
if (m_state != NotificationStateShowing)
return;
- if (m_persistentId.isEmpty()) {
+ if (m_persistentIdString.isEmpty() && m_persistentId == kInvalidPersistentId) {
// Fire the close event asynchronously.
executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notification::dispatchCloseEvent, this));
@@ -197,7 +225,10 @@ void Notification::close()
SecurityOrigin* origin = executionContext()->securityOrigin();
ASSERT(origin);
- notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_persistentId);
+ if (!m_persistentIdString.isEmpty())
+ notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_persistentIdString);
+ else
+ notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_persistentId);
}
}
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/web/ServiceWorkerGlobalScopeProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698