[webkit-gtk] rendering page from gresource

Michael Nazzareno Trimarchi michael at amarulasolutions.com
Mon Mar 22 03:44:39 PDT 2021


Hi Adrian

On Mon, Mar 22, 2021 at 11:42 AM Adrian Perez de Castro
<aperez at igalia.com> wrote:
>
> Hi again,
>
> On Mon, 22 Mar 2021 11:28:54 +0100 Michael Nazzareno Trimarchi <michael at amarulasolutions.com> wrote:
> > Hi
> >
> > On Mon, Mar 22, 2021 at 11:19 AM Adrian Perez de Castro
> > <aperez at igalia.com> wrote:
> > >
> > > Hello Michael,
> > >
> > > On Sun, 21 Mar 2021 20:28:44 +0100 Michael Nazzareno Trimarchi <michael at amarulasolutions.com> wrote:
> > >
> > > > I'm playing a bit with Alexa and gtkmm and I'm trying to do really
> > > > simple things. Read from the resource index.html and main...js
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <gresources>
> > > >   <gresource prefix="@APPLICATION_PREFIX@">
> > > >     <file preprocess="xml-stripblanks">ui/window.glade</file>
> > > >     <file preprocess="xml-stripblanks">ui/headerbar.glade</file>
> > > >     <file preprocess="xml-stripblanks">ui/preferences.glade</file>
> > > >     <file preprocess="xml-stripblanks">ui/menu.glade</file>
> > > >     <file>alexa/index.html</file>
> > > >     <file>alexa/main.bundle.js</file>
> > > >     <file>icons/48x48/icon.png</file>
> > > >   </gresource>
> > > > </gresources>
> > > >
> > > > Things are inside the resource and
> > > >
> > > > webview->load_uri(projectdefinitions::getApplicationPrefix() +
> > > > "alexa/index.html");
> > > > webview->set_visible();
> > > >
> > > > This does not fail but:
> > > > gtk_on_load_changed(WebKitWebView* webView, WebKitLoadEvent loadEvent,
> > > > gpointer userData)
> > > >
> > > > this is not triggered. If I load from a local file things are ok. Can
> > > > anyone knows what is going on?
> > >
> > > What does “getApplicationPrefix()” return? I suspect that the load-changed
> > > signal is not being emitted because there is a load error caused by an invalid
> > > URI, or an URI that has a scheme that is unknown to WebKit.
> > >
> > > The best option to make WebKit load content from a GResource bundle is to
> > > use “webkit_web_context_register_uri_scheme()” to install a custom URI scheme
> > > handler for resources. You can find the documentation here:
> > >
> > >   https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-register-uri-scheme
> > >
> >
> > Yes, I know but ->
> >
> > resources that are local inside the page need to be loaded so we need
> > to intercept load resource signals to get them
> > somehow.
>
> Let's say you have this HTML:
>
>   <html>
>     <head>
>           <script src="main.js" type="text/javascript"></script>
>         <!-- ... -->
>
> If you load that page using an URI like “resource:/index.html”, then the
> script resource will have “resource:/main.js” as its URI, and the custom URI
> scheme handler also takes care of it. The same will happen with all the other
> resources used by the page =)

Now it's perfectly clear ;). I was not aware about the second part
that it can happen
transparently

>
> (This is precisely the reason to use a custom URI scheme handler: everything
> will “just work” as expected.)
>
> > > If you want a more complete code example, GNOME Web (a.k.a. Epiphany) uses
> > > this. You can see the code here:
> > >
> > >   https://gitlab.gnome.org/GNOME/epiphany/-/blob/701aa05d70bb206cee67bfc9e834784f88000a30/embed/ephy-embed-shell.c#L934
> > >   https://gitlab.gnome.org/GNOME/epiphany/-/blob/701aa05d70bb206cee67bfc9e834784f88000a30/embed/ephy-embed-shell.c#L711
> > >
> > > I hope this helps =)
> >
> > I will give it a try. I think that the change should be landed inside
> > the webkit gtk component.
>
> This features does not belong inside WebKitGTK, sorry: Not all the
> applications that use WebKitGTK are interested in allowing web views to load
> contents of their GResource bundles.
>
> WebKitGTK provides support for custom URI scheme handlers so the applications
> which need this feature can provide it themselves with a few lines of code :)

Totally agree

Michael
>
> Best regards,
> -Adrian



-- 
Michael Nazzareno Trimarchi
Amarula Solutions Corporate
CEO Co-Founder
Cruquiuskade 47 Amsterdam 1018 AM NL
T. +31(0)851119172
M. +39(0)3479132170
[`as] https://www.amarulasolutions.com


More information about the webkit-gtk mailing list