Diff
Modified: trunk/Source/WebKit2/ChangeLog (218321 => 218322)
--- trunk/Source/WebKit2/ChangeLog 2017-06-15 08:20:34 UTC (rev 218321)
+++ trunk/Source/WebKit2/ChangeLog 2017-06-15 08:31:58 UTC (rev 218322)
@@ -1,3 +1,25 @@
+2017-06-15 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Use API::NotificationProvider
+ https://bugs.webkit.org/show_bug.cgi?id=173312
+
+ Reviewed by Žan Doberšek.
+
+ Also cleanup a bit the WebKitNotificationProvider implementation, it doesn't need to be refcounted.
+
+ * UIProcess/API/gtk/WebKitNotificationProvider.cpp:
+ (WebKitNotificationProvider::WebKitNotificationProvider):
+ (WebKitNotificationProvider::~WebKitNotificationProvider):
+ (WebKitNotificationProvider::show):
+ (WebKitNotificationProvider::clearNotifications):
+ (WebKitNotificationProvider::notificationPermissions):
+ (WebKitNotificationProvider::setNotificationPermissions):
+ * UIProcess/API/gtk/WebKitNotificationProvider.h:
+ * UIProcess/API/gtk/WebKitWebContext.cpp:
+ (webkitWebContextConstructed):
+ (addOriginToMap):
+ (webkit_web_context_initialize_notification_permissions):
+
2017-06-14 Carlos Garcia Campos <[email protected]>
Add API::InjectedBundle::ResourceLoadClient
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp (218321 => 218322)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp 2017-06-15 08:20:34 UTC (rev 218321)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp 2017-06-15 08:31:58 UTC (rev 218322)
@@ -28,8 +28,7 @@
#include "WebKitNotificationProvider.h"
#include "APIArray.h"
-#include "APIDictionary.h"
-#include "WKNotificationManager.h"
+#include "APINotificationProvider.h"
#include "WebKitNotificationPrivate.h"
#include "WebKitWebContextPrivate.h"
#include "WebKitWebViewPrivate.h"
@@ -39,61 +38,49 @@
using namespace WebKit;
-static inline WebKitNotificationProvider* toNotificationProvider(const void* clientInfo)
-{
- return static_cast<WebKitNotificationProvider*>(const_cast<void*>(clientInfo));
-}
-static void showCallback(WKPageRef page, WKNotificationRef notification, const void* clientInfo)
-{
- toNotificationProvider(clientInfo)->show(toImpl(page), *toImpl(notification));
-}
+class NotificationProvider final : public API::NotificationProvider {
+public:
+ explicit NotificationProvider(WebKitNotificationProvider& provider)
+ : m_provider(provider)
+ {
+ }
-static void cancelCallback(WKNotificationRef notification, const void* clientInfo)
-{
- toNotificationProvider(clientInfo)->cancel(*toImpl(notification));
-}
+private:
+ void show(WebPageProxy& page, WebNotification& notification) override
+ {
+ m_provider.show(page, notification);
+ }
-static WKDictionaryRef notificationPermissionsCallback(const void* clientInfo)
-{
- return toAPI(toNotificationProvider(clientInfo)->notificationPermissions().leakRef());
-}
+ void cancel(WebNotification& notification) override
+ {
+ m_provider.cancel(notification);
+ }
-static void clearNotificationsCallback(WKArrayRef notificationIDs, const void* clientInfo)
-{
- toNotificationProvider(clientInfo)->clearNotifications(toImpl(notificationIDs));
-}
+ void clearNotifications(const Vector<uint64_t>& notificationIDs) override
+ {
+ m_provider.clearNotifications(notificationIDs);
+ }
-WebKitNotificationProvider::~WebKitNotificationProvider()
-{
-}
+ HashMap<String, bool> notificationPermissions() override
+ {
+ return m_provider.notificationPermissions();
+ }
-Ref<WebKitNotificationProvider> WebKitNotificationProvider::create(WebNotificationManagerProxy* notificationManager, WebKitWebContext* webContext)
-{
- return adoptRef(*new WebKitNotificationProvider(notificationManager, webContext));
-}
+ WebKitNotificationProvider& m_provider;
+};
WebKitNotificationProvider::WebKitNotificationProvider(WebNotificationManagerProxy* notificationManager, WebKitWebContext* webContext)
: m_webContext(webContext)
, m_notificationManager(notificationManager)
{
- ASSERT(notificationManager);
+ ASSERT(m_notificationManager);
+ m_notificationManager->setProvider(std::make_unique<NotificationProvider>(*this));
+}
- WKNotificationProviderV0 wkNotificationProvider = {
- {
- 0, // version
- this, // clientInfo
- },
- showCallback,
- cancelCallback,
- 0, // didDestroyNotificationCallback,
- 0, // addNotificationManagerCallback,
- 0, // removeNotificationManagerCallback,
- notificationPermissionsCallback,
- clearNotificationsCallback,
- };
-
- WKNotificationManagerSetProvider(toAPI(notificationManager), reinterpret_cast<WKNotificationProviderBase*>(&wkNotificationProvider));
+WebKitNotificationProvider::~WebKitNotificationProvider()
+{
+ m_notificationManager->setProvider(nullptr);
}
void WebKitNotificationProvider::notificationCloseCallback(WebKitNotification* notification, WebKitNotificationProvider* provider)
@@ -128,19 +115,19 @@
#endif
}
-void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
+void WebKitNotificationProvider::show(WebPageProxy& page, const WebNotification& webNotification)
{
GRefPtr<WebKitNotification> notification = m_notifications.get(webNotification.notificationID());
if (!notification) {
withdrawAnyPreviousNotificationMatchingTag(webNotification.tag().utf8());
- notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
+ notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page.viewWidget()), webNotification));
g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
g_signal_connect(notification.get(), "clicked", G_CALLBACK(notificationClickedCallback), this);
m_notifications.set(webNotification.notificationID(), notification);
}
- if (webkitWebViewEmitShowNotification(WEBKIT_WEB_VIEW(page->viewWidget()), notification.get()))
+ if (webkitWebViewEmitShowNotification(WEBKIT_WEB_VIEW(page.viewWidget()), notification.get()))
m_notificationManager->providerDidShowNotification(webNotification.notificationID());
}
@@ -155,19 +142,19 @@
cancelNotificationByID(webNotification.notificationID());
}
-void WebKitNotificationProvider::clearNotifications(const API::Array* notificationIDs)
+void WebKitNotificationProvider::clearNotifications(const Vector<uint64_t>& notificationIDs)
{
- for (const auto& item : notificationIDs->elementsOfType<API::UInt64>())
- cancelNotificationByID(item->value());
+ for (const auto& item : notificationIDs)
+ cancelNotificationByID(item);
}
-RefPtr<API::Dictionary> WebKitNotificationProvider::notificationPermissions()
+HashMap<WTF::String, bool> WebKitNotificationProvider::notificationPermissions()
{
webkitWebContextInitializeNotificationPermissions(m_webContext);
return m_notificationPermissions;
}
-void WebKitNotificationProvider::setNotificationPermissions(HashMap<String, RefPtr<API::Object>>&& permissionsMap)
+void WebKitNotificationProvider::setNotificationPermissions(HashMap<String, bool>&& permissionsMap)
{
- m_notificationPermissions = API::Dictionary::create(WTFMove(permissionsMap));
+ m_notificationPermissions = WTFMove(permissionsMap);
}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h (218321 => 218322)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h 2017-06-15 08:20:34 UTC (rev 218321)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h 2017-06-15 08:31:58 UTC (rev 218322)
@@ -17,37 +17,33 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef WebKitNotificationProvider_h
-#define WebKitNotificationProvider_h
+#pragma once
-#include "WebKitPrivate.h"
#include "WebKitNotification.h"
#include "WebKitWebContext.h"
#include <wtf/HashMap.h>
-#include <wtf/Ref.h>
-#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/text/StringHash.h>
-namespace API {
-class Array;
-}
-
namespace WebKit {
+class WebNotificationManagerProxy;
+class WebNotification;
+class WebPageProxy;
-class WebKitNotificationProvider : public RefCounted<WebKitNotificationProvider> {
+class WebKitNotificationProvider {
public:
- virtual ~WebKitNotificationProvider();
- static Ref<WebKitNotificationProvider> create(WebNotificationManagerProxy*, WebKitWebContext*);
+ WebKitNotificationProvider(WebNotificationManagerProxy*, WebKitWebContext*);
+ ~WebKitNotificationProvider();
- void show(WebPageProxy*, const WebNotification&);
+ void show(WebPageProxy&, const WebNotification&);
void cancel(const WebNotification&);
- void clearNotifications(const API::Array*);
+ void clearNotifications(const Vector<uint64_t>&);
- RefPtr<API::Dictionary> notificationPermissions();
- void setNotificationPermissions(HashMap<String, RefPtr<API::Object>>&&);
+ HashMap<WTF::String, bool> notificationPermissions();
+ void setNotificationPermissions(HashMap<String, bool>&&);
private:
- WebKitNotificationProvider(WebNotificationManagerProxy*, WebKitWebContext*);
-
void cancelNotificationByID(uint64_t);
static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*);
static void notificationClickedCallback(WebKitNotification*, WebKitNotificationProvider*);
@@ -55,11 +51,9 @@
void withdrawAnyPreviousNotificationMatchingTag(const CString&);
WebKitWebContext* m_webContext;
- RefPtr<API::Dictionary> m_notificationPermissions;
+ HashMap<WTF::String, bool> m_notificationPermissions;
RefPtr<WebNotificationManagerProxy> m_notificationManager;
HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications;
};
} // namespace WebKit
-
-#endif
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (218321 => 218322)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2017-06-15 08:20:34 UTC (rev 218321)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2017-06-15 08:31:58 UTC (rev 218322)
@@ -168,7 +168,7 @@
#if ENABLE(GEOLOCATION)
std::unique_ptr<WebKitGeolocationProvider> geolocationProvider;
#endif
- RefPtr<WebKitNotificationProvider> notificationProvider;
+ std::unique_ptr<WebKitNotificationProvider> notificationProvider;
GRefPtr<WebKitWebsiteDataManager> websiteDataManager;
CString faviconDatabaseDirectory;
@@ -325,7 +325,7 @@
#if ENABLE(GEOLOCATION)
priv->geolocationProvider = std::make_unique<WebKitGeolocationProvider>(priv->processPool->supplement<WebGeolocationManagerProxy>());
#endif
- priv->notificationProvider = WebKitNotificationProvider::create(priv->processPool->supplement<WebNotificationManagerProxy>(), webContext);
+ priv->notificationProvider = std::make_unique<WebKitNotificationProvider>(priv->processPool->supplement<WebNotificationManagerProxy>(), webContext);
#if ENABLE(REMOTE_INSPECTOR)
priv->remoteInspectorProtocolHandler = std::make_unique<RemoteInspectorProtocolHandler>(webContext);
#endif
@@ -1468,11 +1468,11 @@
return context->priv->processCountLimit;
}
-static void addOriginToMap(WebKitSecurityOrigin* origin, HashMap<String, RefPtr<API::Object>>* map, bool allowed)
+static void addOriginToMap(WebKitSecurityOrigin* origin, HashMap<String, bool>* map, bool allowed)
{
String string = webkitSecurityOriginGetSecurityOrigin(origin).toString();
if (string != "null")
- map->set(string, API::Boolean::create(allowed));
+ map->set(string, allowed);
}
/**
@@ -1501,12 +1501,12 @@
*/
void webkit_web_context_initialize_notification_permissions(WebKitWebContext* context, GList* allowedOrigins, GList* disallowedOrigins)
{
- HashMap<String, RefPtr<API::Object>> map;
+ HashMap<String, bool> map;
g_list_foreach(allowedOrigins, [](gpointer data, gpointer userData) {
- addOriginToMap(static_cast<WebKitSecurityOrigin*>(data), static_cast<HashMap<String, RefPtr<API::Object>>*>(userData), true);
+ addOriginToMap(static_cast<WebKitSecurityOrigin*>(data), static_cast<HashMap<String, bool>*>(userData), true);
}, &map);
g_list_foreach(disallowedOrigins, [](gpointer data, gpointer userData) {
- addOriginToMap(static_cast<WebKitSecurityOrigin*>(data), static_cast<HashMap<String, RefPtr<API::Object>>*>(userData), false);
+ addOriginToMap(static_cast<WebKitSecurityOrigin*>(data), static_cast<HashMap<String, bool>*>(userData), false);
}, &map);
context->priv->notificationProvider->setNotificationPermissions(WTFMove(map));
}