diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-30 12:48:17 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-30 12:48:17 +0200 |
commit | 881da28418d380042aa95a97f0cbd42560a64f7c (patch) | |
tree | a794dff3274695e99c651902dde93d934ea7a5af /Tools/WebKitTestRunner/WebNotificationProvider.cpp | |
parent | 7e104c57a70fdf551bb3d22a5d637cdcbc69dbea (diff) | |
parent | 0fcedcd17cc00d3dd44c718b3cb36c1033319671 (diff) | |
download | qtwebkit-881da28418d380042aa95a97f0cbd42560a64f7c.tar.gz |
Merge 'wip/next' into dev
Change-Id: Iff9ee5e23bb326c4371ec8ed81d56f2f05d680e9
Diffstat (limited to 'Tools/WebKitTestRunner/WebNotificationProvider.cpp')
-rw-r--r-- | Tools/WebKitTestRunner/WebNotificationProvider.cpp | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/Tools/WebKitTestRunner/WebNotificationProvider.cpp b/Tools/WebKitTestRunner/WebNotificationProvider.cpp index 14c95308f..de6adece0 100644 --- a/Tools/WebKitTestRunner/WebNotificationProvider.cpp +++ b/Tools/WebKitTestRunner/WebNotificationProvider.cpp @@ -26,10 +26,10 @@ #include "config.h" #include "WebNotificationProvider.h" -#include <WebKit2/WKMutableArray.h> -#include <WebKit2/WKNotification.h> -#include <WebKit2/WKNumber.h> -#include <WebKit2/WKSecurityOrigin.h> +#include <WebKit/WKMutableArray.h> +#include <WebKit/WKNotification.h> +#include <WebKit/WKNumber.h> +#include <WebKit/WKSecurityOriginRef.h> #include <wtf/Assertions.h> namespace WTR { @@ -65,14 +65,14 @@ WebNotificationProvider::WebNotificationProvider() WebNotificationProvider::~WebNotificationProvider() { - WKNotificationManagerSetProvider(m_notificationManager.get(), 0); + for (auto& manager : m_ownedNotifications) + WKNotificationManagerSetProvider(manager.key.get(), nullptr); } -WKNotificationProvider WebNotificationProvider::provider() +WKNotificationProviderV0 WebNotificationProvider::provider() { - WKNotificationProvider notificationProvider = { - kWKNotificationProviderCurrentVersion, - this, + WKNotificationProviderV0 notificationProvider = { + { 0, this }, WTR::showWebNotification, WTR::closeWebNotification, 0, // didDestroyNotification @@ -84,44 +84,57 @@ WKNotificationProvider WebNotificationProvider::provider() return notificationProvider; } -void WebNotificationProvider::showWebNotification(WKPageRef, WKNotificationRef notification) +void WebNotificationProvider::showWebNotification(WKPageRef page, WKNotificationRef notification) { - if (!m_notificationManager) - return; - + auto context = WKPageGetContext(page); + auto notificationManager = WKContextGetNotificationManager(context); uint64_t id = WKNotificationGetID(notification); - ASSERT(!m_shownNotifications.contains(id)); - m_shownNotifications.add(id); - WKNotificationManagerProviderDidShowNotification(m_notificationManager.get(), WKNotificationGetID(notification)); + ASSERT(m_ownedNotifications.contains(notificationManager)); + auto addResult = m_ownedNotifications.find(notificationManager)->value.add(id); + ASSERT_UNUSED(addResult, addResult.isNewEntry); + auto addResult2 = m_owningManager.set(id, notificationManager); + ASSERT_UNUSED(addResult2, addResult2.isNewEntry); + + WKNotificationManagerProviderDidShowNotification(notificationManager, id); } void WebNotificationProvider::closeWebNotification(WKNotificationRef notification) { - if (!m_notificationManager) - return; - uint64_t id = WKNotificationGetID(notification); + ASSERT(m_owningManager.contains(id)); + auto notificationManager = m_owningManager.get(id); + + ASSERT(m_ownedNotifications.contains(notificationManager)); + bool success = m_ownedNotifications.find(notificationManager)->value.remove(id); + ASSERT_UNUSED(success, success); + m_owningManager.remove(id); + WKRetainPtr<WKUInt64Ref> wkID = WKUInt64Create(id); WKRetainPtr<WKMutableArrayRef> array(AdoptWK, WKMutableArrayCreate()); WKArrayAppendItem(array.get(), wkID.get()); - m_shownNotifications.remove(id); - WKNotificationManagerProviderDidCloseNotifications(m_notificationManager.get(), array.get()); + WKNotificationManagerProviderDidCloseNotifications(notificationManager, array.get()); } void WebNotificationProvider::addNotificationManager(WKNotificationManagerRef manager) { - // We assume there is only one for testing. - ASSERT(!m_notificationManager); - m_notificationManager = manager; + m_ownedNotifications.add(manager, HashSet<uint64_t>()); } void WebNotificationProvider::removeNotificationManager(WKNotificationManagerRef manager) { - // We assume there is only one for testing. - ASSERT(m_notificationManager); - ASSERT(m_notificationManager.get() == manager); - m_notificationManager = 0; + auto iterator = m_ownedNotifications.find(manager); + ASSERT(iterator != m_ownedNotifications.end()); + auto toRemove = iterator->value; + WKRetainPtr<WKNotificationManagerRef> guard(manager); + m_ownedNotifications.remove(iterator); + WKRetainPtr<WKMutableArrayRef> array = adoptWK(WKMutableArrayCreate()); + for (uint64_t notificationID : toRemove) { + bool success = m_owningManager.remove(notificationID); + ASSERT_UNUSED(success, success); + WKArrayAppendItem(array.get(), adoptWK(WKUInt64Create(notificationID)).get()); + } + WKNotificationManagerProviderDidCloseNotifications(manager, array.get()); } WKDictionaryRef WebNotificationProvider::notificationPermissions() @@ -132,29 +145,23 @@ WKDictionaryRef WebNotificationProvider::notificationPermissions() void WebNotificationProvider::simulateWebNotificationClick(uint64_t notificationID) { - if (!m_notificationManager) - return; - - ASSERT(m_shownNotifications.contains(notificationID)); - WKNotificationManagerProviderDidClickNotification(m_notificationManager.get(), notificationID); + ASSERT(m_owningManager.contains(notificationID)); + WKNotificationManagerProviderDidClickNotification(m_owningManager.get(notificationID), notificationID); } void WebNotificationProvider::reset() { - if (!m_notificationManager) { - m_shownNotifications.clear(); - return; + for (auto& notificationPair : m_ownedNotifications) { + if (notificationPair.value.isEmpty()) + continue; + WKRetainPtr<WKMutableArrayRef> array = adoptWK(WKMutableArrayCreate()); + for (uint64_t notificationID : notificationPair.value) + WKArrayAppendItem(array.get(), adoptWK(WKUInt64Create(notificationID)).get()); + + notificationPair.value.clear(); + WKNotificationManagerProviderDidCloseNotifications(notificationPair.key.get(), array.get()); } - - WKRetainPtr<WKMutableArrayRef> array(AdoptWK, WKMutableArrayCreate()); - HashSet<uint64_t>::const_iterator itEnd = m_shownNotifications.end(); - for (HashSet<uint64_t>::const_iterator it = m_shownNotifications.begin(); it != itEnd; ++it) { - WKRetainPtr<WKUInt64Ref> wkID = WKUInt64Create(*it); - WKArrayAppendItem(array.get(), wkID.get()); - } - - m_shownNotifications.clear(); - WKNotificationManagerProviderDidCloseNotifications(m_notificationManager.get(), array.get()); + m_owningManager.clear(); } } // namespace WTR |