[webkit-gtk] Selective blocking of image requests

Carlos Garcia Campos cgarcia at igalia.com
Mon Mar 25 00:18:00 PDT 2013

El dom, 24-03-2013 a las 20:47 -0400, Peter Bloomfield escribió:
> Dear List,
> I'm exploring porting an email agent from Webkit-1-Gtk to
> Webkit-2-Gtk.

Great news! Please let us know if you have any issues porting your
application or if you miss API.

> An important privacy issue for users is to control the download of
> images or other resources from untrusted hosts.  In Webkit-1-Gtk we
> could use the "resource-request-starting" signal to intercept the
> request, and replace the URI with "about:blank" to postpone the
> download.  In Webkit-2-Gtk, "resource-load-started" appears to be the
> corresponding signal, but changing the URI in the WebKitURIRequest
> with webkit_uri_request_set_uri does not prevent the download.

Yes, this feature is not exposed in the UI process API, because it
requires a synchronous message to the Web process for every resource
before it's loaded. 

> Does the Webkit-2-Gtk API offer a way to intercept the request in time
> to replace the URI?

Yes, there's a low-level API called Web Extensions API[1], that allow
you to run code in the Web process. In such API there's
WebKitWebPage::send-request signal[2] that you can connect to intercept
any resource request for a page. You don't need to change the URI to
about:blank, simply return TRUE from the callback and the request won't
be sent. 

To use the Web Extensions API you need to provide a plugin with an
initialization function[3] that receives a WebKitWebExtension object[4]
and tell the UI process where your plugin is[5]. You can connect to the
WebKitWebExtension::page-created signal[6] to be notified when a web
page is created and get the pointer to the WebKitWebPage to connect a
callback to send-request signal.

You have examples of how to do this in Epiphany[7], although the ephy
web extension is a lot more complex. To implement only the send-request
feature you don't need any communication with between the UI process and
your extension. 

> Thanks for any help!

Hope it helps, if you have any other question, do not hesitate to ask
here or in the IRC channel. 

[1] http://www.webkitgtk.org/reference/webkit2gtk/unstable/ch02.html
[2] http://www.webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebPage.html#WebKitWebPage-send-request
[3] http://www.webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebExtension.html#WebKitWebExtensionInitializeFunction
[4] http://www.webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebExtension.html
[5] http://www.webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebContext.html#webkit-web-context-set-web-extensions-directory
[6] http://www.webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebExtension.html#WebKitWebExtension-page-created
[7] https://git.gnome.org/browse/epiphany/tree/embed/web-extension

Carlos Garcia Campos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.webkit.org/pipermail/webkit-gtk/attachments/20130325/43c5a634/attachment.sig>

More information about the webkit-gtk mailing list