[epiphany] Add ephy-resource:// custom URI scheme implementation



commit bfdafa8240deb9307078bf09ebbcc9290b1e6528
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri Feb 21 10:03:35 2014 +0100

    Add ephy-resource:// custom URI scheme implementation
    
    Ideally we could use resource:// URIs since they are supported by both
    WebKit and libsoup, but the web process doesn't have access to the
    resources compiled in the UI process. And in multiprocess mode, the
    network process doesn't have access to the resources either.
    ephy-resource:// URIs are like a proxy to load gresources compiled in
    the UI process, the data is sent directly to the web process in
    single process mode or to the network process in multiprocess mode.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724862

 embed/ephy-embed-shell.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 0efa012..48fd2bb 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -450,6 +450,31 @@ about_request_cb (WebKitURISchemeRequest *request,
 }
 
 static void
+ephy_resource_request_cb (WebKitURISchemeRequest *request)
+{
+  const char *path;
+  GInputStream *stream;
+  gsize size;
+  GError *error = NULL;
+
+  path = webkit_uri_scheme_request_get_path (request);
+  if (!g_resources_get_info (path, 0, &size, NULL, &error)) {
+    webkit_uri_scheme_request_finish_error (request, error);
+    g_error_free (error);
+    return;
+  }
+
+  stream = g_resources_open_stream (path, 0, &error);
+  if (stream) {
+    webkit_uri_scheme_request_finish (request, stream, size, NULL);
+    g_object_unref (stream);
+  } else {
+    webkit_uri_scheme_request_finish_error (request, error);
+    g_error_free (error);
+  }
+}
+
+static void
 initialize_web_extensions (WebKitWebContext* web_context,
                            EphyEmbedShell *shell)
 {
@@ -574,6 +599,11 @@ ephy_embed_shell_startup (GApplication* application)
   webkit_security_manager_register_uri_scheme_as_local (webkit_web_context_get_security_manager 
(web_context),
                                                         EPHY_ABOUT_SCHEME);
 
+  /* ephy-resource handler */
+  webkit_web_context_register_uri_scheme (web_context, "ephy-resource",
+                                          (WebKitURISchemeRequestCallback)ephy_resource_request_cb,
+                                          NULL, NULL);
+
   /* Store cookies in moz-compatible SQLite format */
   cookie_manager = webkit_web_context_get_cookie_manager (web_context);
   filename = g_build_filename (ephy_dot_dir (), "cookies.sqlite", NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]