From 9ba55139349e1e8cfa70fc37ae851ccd43ce0040 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 17 Jul 2008 19:15:36 +0200 Subject: [PATCH] Avoid loading favicons unless we need to --- midori/midori-browser.c | 32 +++++++++----------------------- midori/midori-webview.c | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index ffdc8693..d8542690 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -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", diff --git a/midori/midori-webview.c b/midori/midori-webview.c index 3201607e..19e0f813 100644 --- a/midori/midori-webview.c +++ b/midori/midori-webview.c @@ -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); }