+2012-02-16 Jon Lee <jonlee@apple.com>
+
+ [WK2] Clearing notifications does not clean up internal state
+ https://bugs.webkit.org/show_bug.cgi?id=78861
+ <rdar://problem/10881167>
+
+ Reviewed by Anders Carlsson.
+
+ * WebProcess/Notifications/WebNotificationManager.cpp:
+ (WebKit::WebNotificationManager::clearNotifications): This function was missing removing the notification
+ entries from the other maps.
+ (WebKit::WebNotificationManager::didDestroyNotification): When the notification is destroyed, it should
+ also be removed from the context map.
+ (WebKit::WebNotificationManager::didCloseNotifications): Refactor to pull out the code that removes
+ a provided notification from the context map.
+ (WebKit::WebNotificationManager::removeNotificationFromContextMap): Find the notification in the map, and
+ remove it. If the map is empty, get rid of the entry.
+ * WebProcess/Notifications/WebNotificationManager.h:
+ (WebNotificationManager):
+
2012-02-22 Jon Lee <jonlee@apple.com>
Code cleanup in WebNotificationManager (79285)
/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
if (it == m_notificationContextMap.end())
return;
- m_process->connection()->send(Messages::WebNotificationManagerProxy::ClearNotifications(it->second), page->pageID());
+ Vector<uint64_t>& notificationIDs = it->second;
+ m_process->connection()->send(Messages::WebNotificationManagerProxy::ClearNotifications(notificationIDs), page->pageID());
+ size_t count = notificationIDs.size();
+ for (size_t i = 0; i < count; ++i) {
+ RefPtr<Notification> notification = m_notificationIDMap.take(notificationIDs[i]);
+ if (!notification)
+ continue;
+ m_notificationMap.remove(notification);
+ }
+
m_notificationContextMap.remove(it);
#endif
}
if (!notificationID)
return;
- m_notificationIDMap.take(notificationID);
+ m_notificationIDMap.remove(notificationID);
+ removeNotificationFromContextMap(notificationID, notification);
m_process->connection()->send(Messages::WebNotificationManagerProxy::DidDestroyNotification(notificationID), page->pageID());
#endif
}
if (!isNotificationIDValid(notificationID))
continue;
- RefPtr<Notification> notification = m_notificationIDMap.get(notificationID);
+ RefPtr<Notification> notification = m_notificationIDMap.take(notificationID);
if (!notification)
continue;
- NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
- ASSERT(it != m_notificationContextMap.end());
- size_t index = it->second.find(notificationID);
- ASSERT(index != notFound);
- it->second.remove(index);
+ m_notificationMap.remove(notification);
+ removeNotificationFromContextMap(notificationID, notification.get());
notification->dispatchCloseEvent();
}
#endif
}
+#if ENABLE(NOTIFICATIONS)
+void WebNotificationManager::removeNotificationFromContextMap(uint64_t notificationID, Notification* notification)
+{
+ // This is a helper function for managing the hash maps.
+ NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
+ ASSERT(it != m_notificationContextMap.end());
+ size_t index = it->second.find(notificationID);
+ ASSERT(index != notFound);
+ it->second.remove(index);
+ if (it->second.isEmpty())
+ m_notificationContextMap.remove(it);
+}
+#endif
+
} // namespace WebKit
/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
void didCloseNotifications(const Vector<uint64_t>& notificationIDs);
void didUpdateNotificationDecision(const String& originString, bool allowed);
void didRemoveNotificationDecisions(const Vector<String>& originStrings);
+
+#if ENABLE(NOTIFICATIONS)
+ void removeNotificationFromContextMap(uint64_t notificationID, WebCore::Notification*);
+#endif
WebProcess* m_process;