Avoid loading favicons unless we need to

This commit is contained in:
Christian Dywan 2008-07-17 19:15:36 +02:00
parent 272046d94a
commit 9ba5513934
2 changed files with 22 additions and 25 deletions

View file

@ -188,26 +188,6 @@ _midori_browser_get_tab_title (MidoriBrowser* browser,
return "untitled";
}
static GdkPixbuf*
_midori_browser_get_tab_icon (MidoriBrowser* browser,
GtkWidget* widget)
{
const gchar* uri;
GdkPixbuf* icon;
if (MIDORI_IS_WEB_VIEW (widget))
return midori_web_view_get_icon (MIDORI_WEB_VIEW (widget));
uri = g_object_get_data (G_OBJECT (widget), "browser-tab-uri");
if (g_str_has_prefix (uri, "view-source:"))
icon = gtk_widget_render_icon (widget, GTK_STOCK_EDIT,
GTK_ICON_SIZE_MENU, NULL);
else
icon = gtk_widget_render_icon (widget, GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU, NULL);
return icon;
}
static void
_midori_browser_open_uri (MidoriBrowser* browser,
const gchar* uri)
@ -296,9 +276,9 @@ _midori_browser_update_interface (MidoriBrowser* browser)
gtk_widget_show (browser->progressbar);
}
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
icon = _midori_browser_get_tab_icon (browser, widget);
icon = katze_throbber_get_static_pixbuf (KATZE_THROBBER (
g_object_get_data (G_OBJECT (widget), "browser-tab-icon")));
gtk_image_set_from_pixbuf (GTK_IMAGE (browser->location_icon), icon);
g_object_unref (icon);
}
static GtkWidget*
@ -938,7 +918,12 @@ _midori_browser_add_tab (MidoriBrowser* browser,
}
else
{
icon = _midori_browser_get_tab_icon (browser, widget);
if (GTK_IS_TEXT_VIEW (widget))
icon = gtk_widget_render_icon (widget, GTK_STOCK_EDIT,
GTK_ICON_SIZE_MENU, NULL);
else
icon = gtk_widget_render_icon (widget, GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU, NULL);
tab_icon = gtk_image_new_from_pixbuf (icon);
title = _midori_browser_get_tab_title (browser, widget);
tab_title = gtk_label_new (title);
@ -957,6 +942,7 @@ _midori_browser_add_tab (MidoriBrowser* browser,
xbel_item);
}
}
g_object_set_data (G_OBJECT (widget), "browser-tab-icon", tab_icon);
browser->tab_titles = g_list_prepend (browser->tab_titles, tab_title);
g_signal_connect (widget, "leave-notify-event",

View file

@ -29,6 +29,7 @@ struct _MidoriWebView
{
WebKitWebView parent_instance;
GdkPixbuf* icon;
gchar* uri;
gchar* title;
gboolean is_loading;
@ -239,7 +240,8 @@ webkit_web_view_load_committed (MidoriWebView* web_view,
_midori_web_view_set_uri (web_view, uri);
if (web_view->tab_icon)
{
icon = midori_web_view_get_icon (web_view);
icon = gtk_widget_render_icon (GTK_WIDGET (web_view),
GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
katze_throbber_set_static_pixbuf (KATZE_THROBBER (web_view->tab_icon),
icon);
g_object_unref (icon);
@ -281,6 +283,8 @@ webkit_web_frame_load_done (WebKitWebFrame* web_frame, gboolean success,
web_view->is_loading = FALSE;
web_view->progress = -1;
katze_object_assign (web_view->icon, NULL);
if (web_view->tab_icon || web_view->menu_item)
{
icon = midori_web_view_get_icon (web_view);
@ -553,6 +557,8 @@ midori_web_view_finalize (GObject* object)
{
MidoriWebView* web_view = MIDORI_WEB_VIEW (object);
if (web_view->icon)
g_object_unref (web_view->icon);
g_free (web_view->uri);
g_free (web_view->title);
g_free (web_view->statusbar_text);
@ -926,6 +932,9 @@ midori_web_view_get_icon (MidoriWebView* web_view)
g_return_val_if_fail (MIDORI_IS_WEB_VIEW (web_view), NULL);
if (web_view->icon)
return g_object_ref (web_view->icon);
#if GLIB_CHECK_VERSION (2, 16, 0)
parent = g_file_new_for_uri (web_view->uri ? web_view->uri : "");
icon = NULL;
@ -966,5 +975,7 @@ midori_web_view_get_icon (MidoriWebView* web_view)
g_object_unref (icon_file);
g_object_unref (file);
#endif
return pixbuf;
web_view->icon = pixbuf;
return g_object_ref (web_view->icon);
}