Modified: trunk/Source/WebKit2/ChangeLog (126151 => 126152)
--- trunk/Source/WebKit2/ChangeLog 2012-08-21 11:03:50 UTC (rev 126151)
+++ trunk/Source/WebKit2/ChangeLog 2012-08-21 12:50:18 UTC (rev 126152)
@@ -1,3 +1,20 @@
+2012-08-21 Jesse van den Kieboom <jesse...@gnome.org> and Carlos Garcia Campos <cgar...@igalia.com>
+
+ [GTK] Add destroy notify for register_uri_scheme
+ https://bugs.webkit.org/show_bug.cgi?id=94315
+
+ Reviewed by Philippe Normand.
+
+ For introspection to work correctly, a destroy notify needs to be
+ added to register_uri_scheme so that bindings know when to
+ finalize the user_data.
+
+ * UIProcess/API/gtk/WebKitWebContext.cpp:
+ (webkit_web_context_register_uri_scheme):
+ (webkitWebContextReceivedURIRequest):
+ * UIProcess/API/gtk/WebKitWebContext.h:
+ * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp:
+
2012-08-21 Simon Hausmann <simon.hausm...@nokia.com>
Unreviewed build fix for newer Qt 5: QT += qmltest does not imply QT += testlib anymore, but
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (126151 => 126152)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2012-08-21 11:03:50 UTC (rev 126151)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2012-08-21 12:50:18 UTC (rev 126152)
@@ -35,6 +35,8 @@
#include <WebCore/Language.h>
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
#include <wtf/gobject/GOwnPtr.h>
#include <wtf/gobject/GRefPtr.h>
#include <wtf/text/CString.h>
@@ -47,23 +49,46 @@
LAST_SIGNAL
};
-struct WebKitURISchemeHandler {
+class WebKitURISchemeHandler: public RefCounted<WebKitURISchemeHandler> {
+public:
WebKitURISchemeHandler()
- : callback(0)
- , userData(0)
+ : m_callback(0)
+ , m_userData(0)
+ , m_destroyNotify(0)
{
}
- WebKitURISchemeHandler(WebKitURISchemeRequestCallback callback, void* userData)
- : callback(callback)
- , userData(userData)
+ WebKitURISchemeHandler(WebKitURISchemeRequestCallback callback, void* userData, GDestroyNotify destroyNotify)
+ : m_callback(callback)
+ , m_userData(userData)
+ , m_destroyNotify(destroyNotify)
{
}
- WebKitURISchemeRequestCallback callback;
- void* userData;
+ ~WebKitURISchemeHandler()
+ {
+ if (m_destroyNotify)
+ m_destroyNotify(m_userData);
+ }
+
+ bool hasCallback()
+ {
+ return m_callback;
+ }
+
+ void performCallback(WebKitURISchemeRequest* request)
+ {
+ ASSERT(m_callback);
+
+ m_callback(request, m_userData);
+ }
+
+private:
+ WebKitURISchemeRequestCallback m_callback;
+ void* m_userData;
+ GDestroyNotify m_destroyNotify;
};
-typedef HashMap<String, WebKitURISchemeHandler> URISchemeHandlerMap;
+typedef HashMap<String, RefPtr<WebKitURISchemeHandler> > URISchemeHandlerMap;
typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap;
struct _WebKitWebContextPrivate {
@@ -379,8 +404,9 @@
* webkit_web_context_register_uri_scheme:
* @context: a #WebKitWebContext
* @scheme: the network scheme to register
- * @callback: a #WebKitURISchemeRequestCallback
+ * @callback: (scope async): a #WebKitURISchemeRequestCallback
* @user_data: data to pass to callback function
+ * @user_data_destroy_func: destroy notify for @user_data
*
* Register @scheme in @context, so that when an URI request with @scheme is made in the
* #WebKitWebContext, the #WebKitURISchemeRequestCallback registered will be called with a
@@ -417,13 +443,14 @@
* }
* </programlisting></informalexample>
*/
-void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData)
+void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData, GDestroyNotify destroyNotify)
{
g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
g_return_if_fail(scheme);
g_return_if_fail(callback);
- context->priv->uriSchemeHandlers.set(String::fromUTF8(scheme), WebKitURISchemeHandler(callback, userData));
+ RefPtr<WebKitURISchemeHandler> handler = adoptRef(new WebKitURISchemeHandler(callback, userData, destroyNotify));
+ context->priv->uriSchemeHandlers.set(String::fromUTF8(scheme), handler.get());
WKRetainPtr<WKStringRef> wkScheme(AdoptWK, WKStringCreateWithUTF8CString(scheme));
WKSoupRequestManagerRegisterURIScheme(context->priv->requestManager.get(), wkScheme.get());
}
@@ -579,12 +606,14 @@
void webkitWebContextReceivedURIRequest(WebKitWebContext* context, WebKitURISchemeRequest* request)
{
- WebKitURISchemeHandler handler = context->priv->uriSchemeHandlers.get(webkit_uri_scheme_request_get_scheme(request));
- if (!handler.callback)
+ String scheme(String::fromUTF8(webkit_uri_scheme_request_get_scheme(request)));
+ RefPtr<WebKitURISchemeHandler> handler = context->priv->uriSchemeHandlers.get(scheme);
+ ASSERT(handler.get());
+ if (!handler->hasCallback())
return;
context->priv->uriSchemeRequests.set(webkitURISchemeRequestGetID(request), request);
- handler.callback(request, handler.userData);
+ handler->performCallback(request);
}
void webkitWebContextDidFailToLoadURIRequest(WebKitWebContext* context, uint64_t requestID)
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h (126151 => 126152)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h 2012-08-21 11:03:50 UTC (rev 126151)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h 2012-08-21 12:50:18 UTC (rev 126152)
@@ -131,7 +131,8 @@
webkit_web_context_register_uri_scheme (WebKitWebContext *context,
const gchar *scheme,
WebKitURISchemeRequestCallback callback,
- gpointer user_data);
+ gpointer user_data,
+ GDestroyNotify user_data_destroy_func);
WEBKIT_API gboolean
webkit_web_context_get_spell_checking_enabled (WebKitWebContext *context);
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp (126151 => 126152)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp 2012-08-21 11:03:50 UTC (rev 126151)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp 2012-08-21 12:50:18 UTC (rev 126152)
@@ -165,7 +165,7 @@
void registerURISchemeHandler(const char* scheme, const char* reply, int replyLength, const char* mimeType, bool replyWithPath = false)
{
m_handlersMap.set(String::fromUTF8(scheme), URISchemeHandler(reply, replyLength, mimeType, replyWithPath));
- webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this);
+ webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this, 0);
}
GRefPtr<WebKitURISchemeRequest> m_uriSchemeRequest;