1
votes

When I call webkit_web_view_load_string() to load a html content into a webkitview, webkit always refuses to load local files or resources (css, javascript, images) referred in the html content.

Note : i'm using GResource for loading resources into the binary?. this is un example :

GBytes *data;
GResource *resource;
GByteArray* gbarray;  resource = one_file_get_resource();

.

. . .

g_resources_register (resource);
data = g_resource_lookup_data (resource,"/com/test/resources/index.html", G_RESOURCE_LOOKUP_FLAGS_NONE,NULL);
gbarray  = g_bytes_unref_to_array(data);
const gchar* data_char = gbarray->data;

. . .

webkit_web_view_load_string(webView, data_char, NULL, NULL,"");

This is my xml file for GResources :

    <?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/com/test">
    <file>resources/index.html</file>
    <file>resources/style.css</file>
  </gresource>
</gresources>

Now my problem is that index.html is loaded but without the css file. I got my html file without styling!! How can i solve this and thanks?!

1

1 Answers

1
votes

You should somehow tell WebKit that it is okey to load local resources. You can do this by using webkit_web_view_load_uri and making sure that you use a file:// URI. Otherwise, WebKit will assume that the string (in load_string) comes from an untrusted sources, hence is not allowed to access local resources.