diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
commit | ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (patch) | |
tree | b34b0daceb7c8e7fdde4b4ec43650ab7caadb0a9 /Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp | |
parent | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (diff) | |
download | qtwebkit-ad0d549d4cc13433f77c1ac8f0ab379c83d93f28.tar.gz |
Imported WebKit commit bb52bf3c0119e8a128cd93afe5572413a8617de9 (http://svn.webkit.org/repository/webkit/trunk@108790)
Diffstat (limited to 'Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp index 84b52c2ac..90a7f4021 100644 --- a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp +++ b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp @@ -1,5 +1,5 @@ /* - * 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 @@ -114,11 +114,7 @@ bool WebNotificationManager::show(Notification* notification, WebPage* page) m_notificationMap.set(notification, notificationID); m_notificationIDMap.set(notificationID, notification); - NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext()); - if (it == m_notificationContextMap.end()) { - pair<NotificationContextMap::iterator, bool> addedPair = m_notificationContextMap.add(notification->scriptExecutionContext(), Vector<uint64_t>()); - it = addedPair.first; - } + NotificationContextMap::iterator it = m_notificationContextMap.add(notification->scriptExecutionContext(), Vector<uint64_t>()).first; it->second.append(notificationID); m_process->connection()->send(Messages::WebPageProxy::ShowNotification(notification->contents().title, notification->contents().body, notification->iconURL().string(), notification->scriptExecutionContext()->securityOrigin()->toString(), notificationID), page->pageID()); @@ -149,7 +145,16 @@ void WebNotificationManager::clearNotifications(WebCore::ScriptExecutionContext* 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 } @@ -161,7 +166,8 @@ void WebNotificationManager::didDestroyNotification(Notification* notification, 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 } @@ -203,19 +209,30 @@ void WebNotificationManager::didCloseNotifications(const Vector<uint64_t>& notif 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 |