How to handle a custom URL scheme in Webkit GTK?

拟墨画扇 提交于 2019-11-30 12:56:25

I'm more familiar with the Chromium port of WebKit, but I believe that you might need to use webkit_web_resource_get_uri (see webkitwebresource.h) to handle resources such as images.

In WebKit GTK 2, there is a more official route for this:

WebKitWebContext *context = webkit_web_context_get_default();
webkit_web_context_register_uri_scheme(context, "custom",
    (WebKitURISchemeRequestCallback)handle_custom,
    NULL, NULL);

/* ... */

static void
handle_custom(WebKitURISchemeRequest *request)
{
    /* DO FILE LOCATING MAGIC HERE */
    GFile *file = g_file_new_for_path(real_location_of_file);
    GFileInputStream *stream = g_file_read(file, NULL, NULL);
    g_object_unref(file);

    webkit_uri_scheme_request_finish(request, stream, -1, NULL);
    g_object_unref(stream);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!