Go to file
Adrian Perez de Castro ec83c18d19
Workaround to ensure GVariant values are properly wrapped
Long story short: a GVariant must be wrapped into a gi.Struct subclass,
and PyGObject uses _pygi_struct_new_from_g_type() for that, but unfortunately
it is a private function (also, it uses other private functions, so copying
it code into pythonloader.c is not an option). Wading through the PyGObject
code it turns out that we can wrap the GVariant into a GValue, and instead use
pyg_value_as_pyobject(): it ends up calling _pygi_struct_new_from_g_type()
(via pygi_value_to_py_structured_type(), which is also private) for GValues
which wrap a GVariant.

This fixes issue #3
2016-08-11 15:55:48 +03:00
.gitignore Initial import 2015-08-25 19:05:14 +03:00
browse-with-extension Connect to load-failed and load-changed to provide some feedback 2016-08-04 19:58:45 +03:00
extension.py Initial import 2015-08-25 19:05:14 +03:00
Makefile Initial import 2015-08-25 19:05:14 +03:00
pythonloader.c Workaround to ensure GVariant values are properly wrapped 2016-08-11 15:55:48 +03:00
README.md Add README file 2015-08-25 19:24:08 +03:00
run.sh Initial import 2015-08-25 19:05:14 +03:00

WebKit2GTK+ Python WebExtension loader

This is some exploratory code towards finding a good solution which can be shipped built-in to allow loading of Python extensions in WebKit2GTK+

How does it work?

The pythonloader.c file contains a small WebExtension written in C, which is a thin shim that will:

  1. Initialize an embedded Python interpreter.
  2. Import the gi.repository.WebKit2WebExtension module, to ensure that the types used to implement WebExtensions are registered into PyGObject.
  3. Import the extension Python module (extension.py).
  4. Invoke the extension.initialize() function, passing as arguments a WebKitWebExtension instance, and a GVariant which contains the additional the value previously set with webkit_web_context_set_web_extensions_initialization_user_data().

The Python extension can use all the functionality exposed via GObject-Introspection, except for the WebKit, and WebKit2 modules (web extensions run in a process separate from the normal WebKit library, and using them is unsupported — and will most likely crash your program). In particular, the following modules included with WebKit2GTK+ can be used:

Any other module exposed by GObject-Introspection can be used, as long as they do not use the WebKit, or WebKit2 modules.

Trying it out

You will need the following components installed, including their development headers and libraries:

  • WebKit2GTK+, version 2.4, or newer.
  • Python 3.2, or newer.
  • A working PyGObject installation.
  • GNU Make.
  • pkg-config