[Xfce4-commits] <midori:master> Implement view-based favicon handling for WebKit2

Christian Dywan noreply at xfce.org
Sat Apr 6 00:08:01 CEST 2013


Updating branch refs/heads/master
         to 183747f06cd9e327b61360b20056a3f5f228cddb (commit)
       from 8d041d8a30fd40a70627fe806a42930c1a93f5f9 (commit)

commit 183747f06cd9e327b61360b20056a3f5f228cddb
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Apr 5 23:28:30 2013 +0200

    Implement view-based favicon handling for WebKit2

 katze/midori-paths.vala    |   18 ++++++++++++------
 midori/midori-view.c       |   23 ++++++++++++++++++-----
 midori/webkit2gtk-3.0.vapi |   11 +++++++++++
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/katze/midori-paths.vala b/katze/midori-paths.vala
index 6f5cd45..b894b19 100644
--- a/katze/midori-paths.vala
+++ b/katze/midori-paths.vala
@@ -131,20 +131,24 @@ namespace Midori {
                 cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
                     Environment.get_user_cache_dir (), PACKAGE_NAME);
                 user_data_dir = Environment.get_user_data_dir ();
+#if 0 // HAVE_WEBKIT2
+                WebKit.WebContext.get_default ().set_disk_cache_directory (
+                    Path.build_path (Path.DIR_SEPARATOR_S, cache_dir, "web"));
+#endif
                 tmp_dir = get_runtime_dir ();
             }
-#if !HAVE_WEBKIT2
 #if HAVE_WEBKIT_1_3_13
             if (user_data_dir != null) {
                 string folder = Path.build_filename (user_data_dir, "webkit", "icondatabase");
-#if HAVE_WEBKIT_1_8_0
+#if HAVE_WEBKIT2
+                WebKit.WebContext.get_default ().set_favicon_database_directory (folder);
+#elif HAVE_WEBKIT_1_8_0
                 WebKit.get_favicon_database ().set_path (folder);
 #elif HAVE_WEBKIT_1_3_13
                 WebKit.get_icon_database ().set_path (folder);
 #endif
             }
 #endif
-#endif
             if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "paths") == 0) {
                 stdout.printf ("config: %s\ncache: %s\nuser_data: %s\ntmp: %s\n",
                                config_dir, cache_dir, user_data_dir, tmp_dir);
@@ -419,8 +423,11 @@ namespace Midori {
             if (widget != null)
                 Gtk.icon_size_lookup_for_settings (widget.get_settings (),
                     Gtk.IconSize.MENU, out icon_width, out icon_height);
-#if !HAVE_WEBKIT2
-#if HAVE_WEBKIT_1_8_0
+#if HAVE_WEBKIT2
+            /* TODO async
+            var database = WebKit.WebContext.get_default ().get_favicon_database ();
+            database.get_favicon.begin (uri, null); */
+#elif HAVE_WEBKIT_1_8_0
             Gdk.Pixbuf? pixbuf = WebKit.get_favicon_database ()
                 .try_get_favicon_pixbuf (uri, icon_width, icon_height);
             if (pixbuf != null)
@@ -448,7 +455,6 @@ namespace Midori {
                 catch (GLib.Error error) { }
             }
 #endif
-#endif
             if (widget != null)
                 return widget.render_icon (Gtk.STOCK_FILE, Gtk.IconSize.MENU, null);
             return null;
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 7fa0165..d81bb88 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -619,7 +619,17 @@ _midori_web_view_load_icon (MidoriView* view)
     gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
     GdkPixbuf* pixbuf = NULL;
     #ifdef HAVE_WEBKIT2
-    /* FIXME */
+    cairo_surface_t* surface = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (view->web_view));
+    if (surface != NULL
+     && (pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
+        cairo_image_surface_get_width (surface),
+        cairo_image_surface_get_height (surface))))
+    {
+        GdkPixbuf* pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf,
+            icon_width, icon_height, GDK_INTERP_BILINEAR);
+        g_object_unref (pixbuf);
+        midori_view_apply_icon (view, pixbuf_scaled, view->icon_uri);
+    }
     #elif WEBKIT_CHECK_VERSION (1, 8, 0)
     if ((pixbuf = webkit_web_view_try_get_favicon_pixbuf (
         WEBKIT_WEB_VIEW (view->web_view), icon_width, icon_height)))
@@ -1643,12 +1653,15 @@ midori_web_view_notify_icon_uri_cb (WebKitWebView* web_view,
                                     MidoriView*    view)
 {
 #ifdef HAVE_WEBKIT2
-    /* TODO */
+    const gchar* uri = webkit_web_view_get_uri (web_view);
+    WebKitWebContext* context = webkit_web_context_get_default ();
+    WebKitFaviconDatabase* favicon_database = webkit_web_context_get_favicon_database (context);
+    gchar* icon_uri = webkit_favicon_database_get_favicon_uri (favicon_database, uri);
 #else
-    const gchar* icon_uri = webkit_web_view_get_icon_uri (web_view);
-    katze_assign (view->icon_uri, g_strdup (icon_uri));
-    _midori_web_view_load_icon (view);
+    gchar* icon_uri = g_strdup (webkit_web_view_get_icon_uri (web_view));
 #endif
+    katze_assign (view->icon_uri, icon_uri);
+    _midori_web_view_load_icon (view);
 }
 #endif
 
diff --git a/midori/webkit2gtk-3.0.vapi b/midori/webkit2gtk-3.0.vapi
index 0279812..0cb4757 100644
--- a/midori/webkit2gtk-3.0.vapi
+++ b/midori/webkit2gtk-3.0.vapi
@@ -74,6 +74,14 @@ namespace WebKit {
 		public void set_persistent_storage (string filename, WebKit.CookiePersistentStorage storage);
 		public signal void changed ();
 	}
+	[CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_favicon_database_get_type ()")]
+	public class FaviconDatabase : GLib.Object {
+		[CCode (has_construct_function = false)]
+		protected FaviconDatabase ();
+		public async Cairo.Surface? get_favicon (string page_uri, GLib.Cancellable? cancellable) throws GLib.Error;
+		public string? get_favicon_uri (string page_uri);
+		public void clear ();
+	}
 	[CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_download_get_type ()")]
 	public class Download : GLib.Object {
 		[CCode (has_construct_function = false)]
@@ -419,7 +427,10 @@ namespace WebKit {
 		public WebKit.Download download_uri (string uri);
 		public WebKit.CacheModel get_cache_model ();
 		public unowned WebKit.CookieManager get_cookie_manager ();
+		public unowned WebKit.FaviconDatabase get_favicon_database ();
+		public void set_favicon_database_directory (string path);
 		public static unowned WebKit.WebContext get_default ();
+		public void set_disk_cache_directory (string path);
 		public async GLib.List<WebKit.Plugin> get_plugins (GLib.Cancellable? cancellable) throws GLib.Error;
 		public bool get_spell_checking_enabled ();
 		public unowned string get_spell_checking_languages ();


More information about the Xfce4-commits mailing list