Changeset 126152 in webkit
- Timestamp:
- Aug 21, 2012 5:50:18 AM (12 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r126147 r126152 1 2012-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 1 18 2012-08-21 Simon Hausmann <simon.hausmann@nokia.com> 2 19 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp
r126017 r126152 36 36 #include <wtf/HashMap.h> 37 37 #include <wtf/OwnPtr.h> 38 #include <wtf/PassRefPtr.h> 39 #include <wtf/RefCounted.h> 38 40 #include <wtf/gobject/GOwnPtr.h> 39 41 #include <wtf/gobject/GRefPtr.h> … … 48 50 }; 49 51 50 struct WebKitURISchemeHandler { 52 class WebKitURISchemeHandler: public RefCounted<WebKitURISchemeHandler> { 53 public: 51 54 WebKitURISchemeHandler() 52 : callback(0) 53 , userData(0) 55 : m_callback(0) 56 , m_userData(0) 57 , m_destroyNotify(0) 54 58 { 55 59 } 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) 59 64 { 60 65 } 61 66 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 85 private: 86 WebKitURISchemeRequestCallback m_callback; 87 void* m_userData; 88 GDestroyNotify m_destroyNotify; 64 89 }; 65 90 66 typedef HashMap<String, WebKitURISchemeHandler> URISchemeHandlerMap;91 typedef HashMap<String, RefPtr<WebKitURISchemeHandler> > URISchemeHandlerMap; 67 92 typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap; 68 93 … … 380 405 * @context: a #WebKitWebContext 381 406 * @scheme: the network scheme to register 382 * @callback: a #WebKitURISchemeRequestCallback407 * @callback: (scope async): a #WebKitURISchemeRequestCallback 383 408 * @user_data: data to pass to callback function 409 * @user_data_destroy_func: destroy notify for @user_data 384 410 * 385 411 * Register @scheme in @context, so that when an URI request with @scheme is made in the … … 418 444 * </programlisting></informalexample> 419 445 */ 420 void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData )446 void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData, GDestroyNotify destroyNotify) 421 447 { 422 448 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); … … 424 450 g_return_if_fail(callback); 425 451 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()); 427 454 WKRetainPtr<WKStringRef> wkScheme(AdoptWK, WKStringCreateWithUTF8CString(scheme)); 428 455 WKSoupRequestManagerRegisterURIScheme(context->priv->requestManager.get(), wkScheme.get()); … … 580 607 void webkitWebContextReceivedURIRequest(WebKitWebContext* context, WebKitURISchemeRequest* request) 581 608 { 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()) 584 613 return; 585 614 586 615 context->priv->uriSchemeRequests.set(webkitURISchemeRequestGetID(request), request); 587 handler .callback(request, handler.userData);616 handler->performCallback(request); 588 617 } 589 618 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h
r126017 r126152 132 132 const gchar *scheme, 133 133 WebKitURISchemeRequestCallback callback, 134 gpointer user_data); 134 gpointer user_data, 135 GDestroyNotify user_data_destroy_func); 135 136 136 137 WEBKIT_API gboolean -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
r126017 r126152 166 166 { 167 167 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); 169 169 } 170 170
Note: See TracChangeset
for help on using the changeset viewer.