[epiphany] overview: Do not send decoded snapshots to the web process



commit ad5b34dcfb479922908b3a995a54ee7901ed708f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Mon Feb 17 14:27:49 2014 +0100

    overview: Do not send decoded snapshots to the web process
    
    Use the thumbnail path instead so that thumbnails are loaded in the web
    process.

 embed/ephy-about-handler.c               |   22 ++++++++++------------
 embed/ephy-embed-shell.c                 |    4 ++++
 embed/web-extension/Makefile.am          |    4 ++++
 embed/web-extension/ephy-web-extension.c |   20 ++++++++++++++++++++
 src/resources/overview.html              |    1 +
 5 files changed, 39 insertions(+), 12 deletions(-)
---
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index 9a2c4d6..d6b7c33 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -434,10 +434,9 @@ ephy_about_handler_generate_overview_html (EphyOverviewStore *store)
 {
   GtkTreeIter iter;
   GString *data_str;
-  char *row_url, *row_title, *row_snapshot_base64;
-  GdkPixbuf *row_snapshot;
-  guchar *buffer;
-  gsize buffersize;
+  char *row_url, *row_title;
+  char *row_snapshot;
+  char *thumbnail_style;
   gboolean valid;
 
   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
@@ -447,27 +446,26 @@ ephy_about_handler_generate_overview_html (EphyOverviewStore *store)
     gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
       EPHY_OVERVIEW_STORE_URI, &row_url,
       EPHY_OVERVIEW_STORE_TITLE, &row_title,
-      EPHY_OVERVIEW_STORE_SNAPSHOT, &row_snapshot,
+      EPHY_OVERVIEW_STORE_SNAPSHOT_PATH, &row_snapshot,
       -1);
 
-    /* FIXME: use a more efficient way to get the base64 snapshot */
-    gdk_pixbuf_save_to_buffer (row_snapshot, (gchar **) &buffer, &buffersize, "png", NULL, NULL);
-    row_snapshot_base64 = g_base64_encode (buffer, buffersize);
-    g_free (buffer);
+    thumbnail_style = row_snapshot ? g_strdup_printf (" style=\"background: 
url(ephy-about:/thumbnail-frame.png), url(file://%s) no-repeat 10px 9px;\"", row_snapshot) : NULL;
+    g_free (row_snapshot);
 
     g_string_append_printf (data_str,
       "<li>" \
       "  <a class=\"overview-item\" title=\"%s\" href=\"%s\">" \
       "    <div class=\"close-button\" onclick=\"removeFromOverview(this.parentNode,event)\" 
title=\"%s\">&#10006;</div>" \
-      "    <span class=\"thumbnail\" style=\"background-image: url(data:image/png;base64,%s);\"></span>" \
+      "    <span class=\"thumbnail\"%s></span>" \
       "    <span class=\"title\">%s</span>" \
       "  </a>" \
       "</li>",
-      g_markup_escape_text (row_title,-1), row_url, _("Remove from overview"),row_snapshot_base64, 
row_title);
+      g_markup_escape_text (row_title,-1), row_url, _("Remove from overview"),
+                            thumbnail_style ? thumbnail_style : "", row_title);
 
     g_free (row_title);
     g_free (row_url);
-    g_free (row_snapshot_base64);
+    g_free (thumbnail_style);
 
     valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
   }
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 0d744c3..0ebfab1 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -445,6 +445,10 @@ ephy_embed_shell_startup (GApplication* application)
                                           (WebKitURISchemeRequestCallback)about_request_cb,
                                           shell, NULL);
 
+  /* Register about scheme as local so that it can contain file resources */
+  webkit_security_manager_register_uri_scheme_as_local (webkit_web_context_get_security_manager 
(web_context),
+                                                        EPHY_ABOUT_SCHEME);
+
   /* 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);
diff --git a/embed/web-extension/Makefile.am b/embed/web-extension/Makefile.am
index 68bf1d6..5513d30 100644
--- a/embed/web-extension/Makefile.am
+++ b/embed/web-extension/Makefile.am
@@ -12,6 +12,8 @@ libephywebextension_la_SOURCES = \
        $(top_srcdir)/embed/uri-tester.h \
        $(top_srcdir)/lib/ephy-debug.c \
        $(top_srcdir)/lib/ephy-debug.h \
+       $(top_srcdir)/lib/ephy-file-helpers.c \
+       $(top_srcdir)/lib/ephy-file-helpers.h \
        $(top_srcdir)/lib/ephy-form-auth-data.c \
        $(top_srcdir)/lib/ephy-form-auth-data.h \
        $(top_srcdir)/lib/ephy-settings.c \
@@ -29,6 +31,8 @@ libephywebextension_la_CPPFLAGS = \
        $(AM_CPPFLAGS)
 
 libephywebextension_la_CFLAGS = \
+       -DSHARE_DIR=\"$(pkgdatadir)\" \
+       -DTOP_SRC_DATADIR=\"$(top_srcdir)/data\" \
        $(WEB_EXTENSION_CFLAGS)
 
 libephywebextension_la_LIBADD = \
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index d5197bd..9d3d7c7 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -23,6 +23,7 @@
 
 #include "ephy-debug.h"
 #include "ephy-embed-form-auth.h"
+#include "ephy-file-helpers.h"
 #include "ephy-form-auth-data.h"
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
@@ -33,6 +34,7 @@
 #include <gio/gio.h>
 #include <gtk/gtk.h>
 #include <libsoup/soup.h>
+#include <string.h>
 #include <webkit2/webkit-web-extension.h>
 #include <JavaScriptCore/JavaScript.h>
 
@@ -91,6 +93,18 @@ web_page_send_request (WebKitWebPage *web_page,
 
   request_uri = webkit_uri_request_get_uri (request);
 
+  if (g_str_has_prefix (request_uri, "ephy-about:/")) {
+    char *about_resource;
+
+    /* Ideally we should use resource:// uris directly in about pages, but in multiprocess mode the
+     * Network Process doesn't have access to the resources compiled in the Web Process */
+    about_resource = g_filename_to_uri (ephy_file (request_uri + strlen ("ephy-about:/")), NULL, NULL);
+    webkit_uri_request_set_uri (request, about_resource);
+    g_free (about_resource);
+
+    return FALSE;
+  }
+
   if (g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DO_NOT_TRACK)) {
     SoupMessageHeaders *headers;
     char *new_uri;
@@ -1254,9 +1268,15 @@ webkit_web_extension_initialize_with_user_data (WebKitWebExtension *extension,
   const char *extension_id;
   const char *dot_dir;
   gboolean private_profile;
+  GError *error = NULL;
 
   g_variant_get (user_data, "(&s&sb)", &extension_id, &dot_dir, &private_profile);
 
+  if (!ephy_file_helpers_init (dot_dir, 0, &error)) {
+    g_printerr ("Failed to initialize file helpers: %s\n", error->message);
+    g_error_free (error);
+  }
+
   ephy_debug_init ();
   uri_tester = uri_tester_new (dot_dir);
   if (!private_profile)
diff --git a/src/resources/overview.html b/src/resources/overview.html
index 1a88869..56d2f45 100755
--- a/src/resources/overview.html
+++ b/src/resources/overview.html
@@ -75,6 +75,7 @@
       display: block;
       opacity: 0.6;
       transition: opacity 0.2s ease-in-out;
+      background: url(ephy-about:/thumbnail-frame.png), url(ephy-about:/missing-thumbnail.png) 10px 9px;
       background-repeat: no-repeat;
       animation: fadeOut 0.5s;
   }


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