Method
WebKit2WebContextregister_uri_scheme
Declaration [src]
void
webkit_web_context_register_uri_scheme (
WebKitWebContext* context,
const gchar* scheme,
WebKitURISchemeRequestCallback callback,
gpointer user_data,
GDestroyNotify user_data_destroy_func
)
Description [src]
Register scheme
in context
.
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
WebKitURISchemeRequest
.
It is possible to handle URI scheme requests asynchronously, by calling g_object_ref()
on the
WebKitURISchemeRequest
and calling webkit_uri_scheme_request_finish()
later
when the data of the request is available or
webkit_uri_scheme_request_finish_error()
in case of error.
static void
about_uri_scheme_request_cb (WebKitURISchemeRequest *request,
gpointer user_data)
{
GInputStream *stream;
gsize stream_length;
const gchar *path = webkit_uri_scheme_request_get_path (request);
if (!g_strcmp0 (path, "memory")) {
// Create a GInputStream with the contents of memory about page, and set its length to stream_length
} else if (!g_strcmp0 (path, "applications")) {
// Create a GInputStream with the contents of applications about page, and set its length to stream_length
} else if (!g_strcmp0 (path, "example")) {
gchar *contents = g_strdup_printf ("<html><body><p>Example about page</p></body></html>");
stream_length = strlen (contents);
stream = g_memory_input_stream_new_from_data (contents, stream_length, g_free);
} else {
GError *error = g_error_new (ABOUT_HANDLER_ERROR, ABOUT_HANDLER_ERROR_INVALID, "Invalid about:%s page.", path);
webkit_uri_scheme_request_finish_error (request, error);
g_error_free (error);
return;
}
webkit_uri_scheme_request_finish (request, stream, stream_length, "text/html");
g_object_unref (stream);
}
Parameters
scheme
-
Type:
const gchar*
The network scheme to register.
The data is owned by the caller of the method. The value is a NUL terminated UTF-8 string. callback
-
Type:
WebKitURISchemeRequestCallback
A
WebKitURISchemeRequestCallback
. user_data
-
Type:
gpointer
Data to pass to callback function.
The argument can be NULL
.The data is owned by the caller of the method. user_data_destroy_func
-
Type:
GDestroyNotify
Destroy notify for
user_data
.