Changeset 126152 in webkit


Ignore:
Timestamp:
Aug 21, 2012 5:50:18 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[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:
Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r126147 r126152  
     12012-08-21  Jesse van den Kieboom  <jessevdk@gnome.org> and Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add destroy notify for register_uri_scheme
     4        https://bugs.webkit.org/show_bug.cgi?id=94315
     5
     6        Reviewed by Philippe Normand.
     7
     8        For introspection to work correctly, a destroy notify needs to be
     9        added to register_uri_scheme so that bindings know when to
     10        finalize the user_data.
     11
     12        * UIProcess/API/gtk/WebKitWebContext.cpp:
     13        (webkit_web_context_register_uri_scheme):
     14        (webkitWebContextReceivedURIRequest):
     15        * UIProcess/API/gtk/WebKitWebContext.h:
     16        * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp:
     17
    1182012-08-21  Simon Hausmann  <simon.hausmann@nokia.com>
    219
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

    r126017 r126152  
    3636#include <wtf/HashMap.h>
    3737#include <wtf/OwnPtr.h>
     38#include <wtf/PassRefPtr.h>
     39#include <wtf/RefCounted.h>
    3840#include <wtf/gobject/GOwnPtr.h>
    3941#include <wtf/gobject/GRefPtr.h>
     
    4850};
    4951
    50 struct WebKitURISchemeHandler {
     52class WebKitURISchemeHandler: public RefCounted<WebKitURISchemeHandler> {
     53public:
    5154    WebKitURISchemeHandler()
    52         : callback(0)
    53         , userData(0)
     55        : m_callback(0)
     56        , m_userData(0)
     57        , m_destroyNotify(0)
    5458    {
    5559    }
    56     WebKitURISchemeHandler(WebKitURISchemeRequestCallback callback, void* userData)
    57         : callback(callback)
    58         , userData(userData)
     60    WebKitURISchemeHandler(WebKitURISchemeRequestCallback callback, void* userData, GDestroyNotify destroyNotify)
     61        : m_callback(callback)
     62        , m_userData(userData)
     63        , m_destroyNotify(destroyNotify)
    5964    {
    6065    }
    6166
    62     WebKitURISchemeRequestCallback callback;
    63     void* userData;
     67    ~WebKitURISchemeHandler()
     68    {
     69        if (m_destroyNotify)
     70            m_destroyNotify(m_userData);
     71    }
     72
     73    bool hasCallback()
     74    {
     75        return m_callback;
     76    }
     77
     78    void performCallback(WebKitURISchemeRequest* request)
     79    {
     80        ASSERT(m_callback);
     81
     82        m_callback(request, m_userData);
     83    }
     84
     85private:
     86    WebKitURISchemeRequestCallback m_callback;
     87    void* m_userData;
     88    GDestroyNotify m_destroyNotify;
    6489};
    6590
    66 typedef HashMap<String, WebKitURISchemeHandler> URISchemeHandlerMap;
     91typedef HashMap<String, RefPtr<WebKitURISchemeHandler> > URISchemeHandlerMap;
    6792typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap;
    6893
     
    380405 * @context: a #WebKitWebContext
    381406 * @scheme: the network scheme to register
    382  * @callback: a #WebKitURISchemeRequestCallback
     407 * @callback: (scope async): a #WebKitURISchemeRequestCallback
    383408 * @user_data: data to pass to callback function
     409 * @user_data_destroy_func: destroy notify for @user_data
    384410 *
    385411 * Register @scheme in @context, so that when an URI request with @scheme is made in the
     
    418444 * </programlisting></informalexample>
    419445 */
    420 void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData)
     446void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData, GDestroyNotify destroyNotify)
    421447{
    422448    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
     
    424450    g_return_if_fail(callback);
    425451
    426     context->priv->uriSchemeHandlers.set(String::fromUTF8(scheme), WebKitURISchemeHandler(callback, userData));
     452    RefPtr<WebKitURISchemeHandler> handler = adoptRef(new WebKitURISchemeHandler(callback, userData, destroyNotify));
     453    context->priv->uriSchemeHandlers.set(String::fromUTF8(scheme), handler.get());
    427454    WKRetainPtr<WKStringRef> wkScheme(AdoptWK, WKStringCreateWithUTF8CString(scheme));
    428455    WKSoupRequestManagerRegisterURIScheme(context->priv->requestManager.get(), wkScheme.get());
     
    580607void webkitWebContextReceivedURIRequest(WebKitWebContext* context, WebKitURISchemeRequest* request)
    581608{
    582     WebKitURISchemeHandler handler = context->priv->uriSchemeHandlers.get(webkit_uri_scheme_request_get_scheme(request));
    583     if (!handler.callback)
     609    String scheme(String::fromUTF8(webkit_uri_scheme_request_get_scheme(request)));
     610    RefPtr<WebKitURISchemeHandler> handler = context->priv->uriSchemeHandlers.get(scheme);
     611    ASSERT(handler.get());
     612    if (!handler->hasCallback())
    584613        return;
    585614
    586615    context->priv->uriSchemeRequests.set(webkitURISchemeRequestGetID(request), request);
    587     handler.callback(request, handler.userData);
     616    handler->performCallback(request);
    588617}
    589618
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h

    r126017 r126152  
    132132                                                     const gchar                   *scheme,
    133133                                                     WebKitURISchemeRequestCallback callback,
    134                                                      gpointer                       user_data);
     134                                                     gpointer                       user_data,
     135                                                     GDestroyNotify                 user_data_destroy_func);
    135136
    136137WEBKIT_API gboolean
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp

    r126017 r126152  
    166166    {
    167167        m_handlersMap.set(String::fromUTF8(scheme), URISchemeHandler(reply, replyLength, mimeType, replyWithPath));
    168         webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this);
     168        webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this, 0);
    169169    }
    170170
Note: See TracChangeset for help on using the changeset viewer.