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

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

Issue 1072873002: Clean up Blink left-overs of textual persistent notification 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 unified diff | Download patch | Annotate | Revision Log
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (!dataBytes.isEmpty()) { 128 if (!dataBytes.isEmpty()) {
129 notification->setSerializedData(SerializedScriptValueFactory::instance() .createFromWireBytes(dataBytes.data(), dataBytes.size())); 129 notification->setSerializedData(SerializedScriptValueFactory::instance() .createFromWireBytes(dataBytes.data(), dataBytes.size()));
130 notification->serializedData()->registerMemoryAllocatedWithCurrentScript Context(); 130 notification->serializedData()->registerMemoryAllocatedWithCurrentScript Context();
131 } 131 }
132 132
133 notification->setState(NotificationStateShowing); 133 notification->setState(NotificationStateShowing);
134 notification->suspendIfNeeded(); 134 notification->suspendIfNeeded();
135 return notification; 135 return notification;
136 } 136 }
137 137
138 Notification* Notification::create(ExecutionContext* context, const String& pers istentId, const WebNotificationData& data)
139 {
140 Notification* notification = new Notification(data.title, context);
141
142 notification->setPersistentIdString(persistentId);
143 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl");
144 notification->setLang(data.lang);
145 notification->setBody(data.body);
146 notification->setTag(data.tag);
147 notification->setSilent(data.silent);
148
149 if (!data.icon.isEmpty())
150 notification->setIconUrl(data.icon);
151
152 const WebVector<char>& dataBytes = data.data;
153 if (!dataBytes.isEmpty()) {
154 notification->setSerializedData(SerializedScriptValueFactory::instance() .createFromWireBytes(dataBytes.data(), dataBytes.size()));
155 notification->serializedData()->registerMemoryAllocatedWithCurrentScript Context();
156 }
157
158 notification->setState(NotificationStateShowing);
159 notification->suspendIfNeeded();
160 return notification;
161 }
162
163 Notification::Notification(const String& title, ExecutionContext* context) 138 Notification::Notification(const String& title, ExecutionContext* context)
164 : ActiveDOMObject(context) 139 : ActiveDOMObject(context)
165 , m_title(title) 140 , m_title(title)
166 , m_dir("auto") 141 , m_dir("auto")
167 , m_silent(false) 142 , m_silent(false)
168 , m_persistentId(kInvalidPersistentId) 143 , m_persistentId(kInvalidPersistentId)
169 , m_state(NotificationStateIdle) 144 , m_state(NotificationStateIdle)
170 , m_asyncRunner(this, &Notification::show) 145 , m_asyncRunner(this, &Notification::show)
171 { 146 {
172 ASSERT(notificationManager()); 147 ASSERT(notificationManager());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); 181 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this);
207 182
208 m_state = NotificationStateShowing; 183 m_state = NotificationStateShowing;
209 } 184 }
210 185
211 void Notification::close() 186 void Notification::close()
212 { 187 {
213 if (m_state != NotificationStateShowing) 188 if (m_state != NotificationStateShowing)
214 return; 189 return;
215 190
216 if (m_persistentIdString.isEmpty() && m_persistentId == kInvalidPersistentId ) { 191 if (m_persistentId == kInvalidPersistentId) {
217 // Fire the close event asynchronously. 192 // Fire the close event asynchronously.
218 executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notificati on::dispatchCloseEvent, this)); 193 executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notificati on::dispatchCloseEvent, this));
219 194
220 m_state = NotificationStateClosing; 195 m_state = NotificationStateClosing;
221 notificationManager()->close(this); 196 notificationManager()->close(this);
222 } else { 197 } else {
223 m_state = NotificationStateClosed; 198 m_state = NotificationStateClosed;
224 199
225 SecurityOrigin* origin = executionContext()->securityOrigin(); 200 SecurityOrigin* origin = executionContext()->securityOrigin();
226 ASSERT(origin); 201 ASSERT(origin);
227 202
228 if (!m_persistentIdString.isEmpty()) 203 notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_p ersistentId);
229 notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_persistentIdString);
230 else
231 notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_persistentId);
232 } 204 }
233 } 205 }
234 206
235 void Notification::dispatchShowEvent() 207 void Notification::dispatchShowEvent()
236 { 208 {
237 dispatchEvent(Event::create(EventTypeNames::show)); 209 dispatchEvent(Event::create(EventTypeNames::show));
238 } 210 }
239 211
240 void Notification::dispatchClickEvent() 212 void Notification::dispatchClickEvent()
241 { 213 {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); 307 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate()));
336 } 308 }
337 309
338 DEFINE_TRACE(Notification) 310 DEFINE_TRACE(Notification)
339 { 311 {
340 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 312 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
341 ActiveDOMObject::trace(visitor); 313 ActiveDOMObject::trace(visitor);
342 } 314 }
343 315
344 } // namespace blink 316 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698