From 06bd549cb17930e12212dc39fcc6111855be2850 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Tue, 15 Sep 2009 21:15:57 +0200 Subject: [PATCH] Lookup page icons via javascript --- katze/katze-net.c | 29 +++++++++++++++++------------ midori/midori-view.c | 38 +++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/katze/katze-net.c b/katze/katze-net.c index 8a82747b..e445aa8d 100644 --- a/katze/katze-net.c +++ b/katze/katze-net.c @@ -525,7 +525,6 @@ katze_net_load_icon (KatzeNet* net, GtkWidget* widget, gpointer user_data) { - guint i; KatzeNetIconPriv* priv; gchar* icon_uri; gchar* icon_file; @@ -535,22 +534,28 @@ katze_net_load_icon (KatzeNet* net, g_return_val_if_fail (KATZE_IS_NET (net), NULL); g_return_val_if_fail (!widget || GTK_IS_WIDGET (widget), NULL); + g_return_val_if_fail (uri != NULL, NULL); pixbuf = NULL; - if (uri && (g_str_has_prefix (uri, "http://") || - g_str_has_prefix (uri, "https://"))) + icon_uri = g_strdup (g_object_get_data (G_OBJECT (net), uri)); + g_object_set_data (G_OBJECT (net), uri, NULL); + if ((icon_uri && g_str_has_prefix (icon_uri, "http")) + || g_str_has_prefix (uri, "http")) { - i = 8; - while (uri[i] != '\0' && uri[i] != '/') - i++; - if (uri[i] == '/') + if (!icon_uri) { - icon_uri = g_strdup (uri); - icon_uri[i] = '\0'; - icon_uri = g_strdup_printf ("%s/favicon.ico", icon_uri); + guint i = 8; + while (uri[i] != '\0' && uri[i] != '/') + i++; + if (uri[i] == '/') + { + icon_uri = g_strdup (uri); + icon_uri[i] = '\0'; + icon_uri = g_strdup_printf ("%s/favicon.ico", icon_uri); + } + else + icon_uri = g_strdup_printf ("%s/favicon.ico", uri); } - else - icon_uri = g_strdup_printf ("%s/favicon.ico", uri); icon_file = katze_net_get_cached_path (net, icon_uri, "icons"); diff --git a/midori/midori-view.c b/midori/midori-view.c index efb037cb..44b1e880 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -696,9 +696,6 @@ midori_view_update_load_status (MidoriView* view, if (view->tab_icon) katze_throbber_set_animated (KATZE_THROBBER (view->tab_icon), view->load_status != MIDORI_LOAD_FINISHED); - - if (view->web_view && view->load_status == MIDORI_LOAD_COMMITTED) - _midori_web_view_load_icon (view); } static void @@ -857,11 +854,13 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view, URI1|title1,URI2|title2 FIXME: Ensure separators contained in the string can't break it */ gchar* value = sokoke_js_script_eval (js_context, - "function feeds (l) { var f = new Array (); for (i in l) " - "{ var t = l[i].type; " + "function links (l) { var f = new Array (); for (i in l) " + "{ var t = l[i].type; var r = l[i].rel; " "if (t && (t.indexOf ('rss') != -1 || t.indexOf ('atom') != -1)) " - "f.push (l[i].href + '|' + l[i].title); } return f; }" - "feeds (document.getElementsByTagName ('link'))", NULL); + "f.push (l[i].href + '|' + l[i].title);" + "else if (r && r.indexOf ('icon') != -1) f.push (l[i].href); } " + "return f; }" + "links (document.getElementsByTagName ('link'))", NULL); gchar** items = g_strsplit (value, ",", 0); guint i = 0; gchar* default_uri = NULL; @@ -871,14 +870,21 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view, while (items[i] != NULL) { gchar** parts = g_strsplit (items[i], "|", 2); - KatzeItem* item = g_object_new (KATZE_TYPE_ITEM, - "uri", parts ? *parts : "", - "name", parts && *parts ? parts[1] : NULL, - NULL); - katze_array_add_item (view->news_feeds, item); - g_object_unref (item); - if (!default_uri) - default_uri = g_strdup (parts ? *parts : NULL); + if (parts == NULL) + ; + else if (*parts && parts[1]) + { + KatzeItem* item = g_object_new (KATZE_TYPE_ITEM, + "uri", parts[0], "name", parts[1], NULL); + katze_array_add_item (view->news_feeds, item); + g_object_unref (item); + if (!default_uri) + default_uri = g_strdup (parts[0]); + } + else + g_object_set_data_full (G_OBJECT (view->net), view->uri, + g_strdup (*parts), (GDestroyNotify)g_free); + g_strfreev (parts); i++; } @@ -889,6 +895,8 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view, g_object_notify (G_OBJECT (view), "load-status"); } + _midori_web_view_load_icon (view); + g_object_thaw_notify (G_OBJECT (view)); } -- 2.39.5