From 2f60ecea61b683a035dff5650620a8a69b7bc9e7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 7 Oct 2011 22:22:15 +0000 Subject: use the default resource:favicon.ico when a site has no icon of its own svn path=/trunk/netsurf/; revision=12992 --- desktop/browser.c | 38 ++++++++++++++++++++++++++++++-------- desktop/browser.h | 2 ++ 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index b442a224b..50dcc484a 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -912,11 +912,7 @@ static nserror browser_window_favicon_callback(hlcache_handle *c, /* content_get_bitmap on the hlcache_handle should give * us the favicon bitmap at this point */ - if (bw->window != NULL) { - gui_window_set_icon(bw->window, c); - } else { - LOG(("null browser window on favicon!")); - } + gui_window_set_icon(bw->window, c); break; case CONTENT_MSG_ERROR: @@ -930,9 +926,32 @@ static nserror browser_window_favicon_callback(hlcache_handle *c, hlcache_handle_release(c); - /** @todo if this was not the default - * resource:favicon.png start a fetch for it. - */ + if (bw->failed_favicon == false) { + nsurl *nsref = NULL; + nsurl *nsurl; + nserror error; + + bw->failed_favicon = true; + + error = nsurl_create("resource:favicon.ico", &nsurl); + if (error != NSERROR_OK) { + LOG(("Unable to create default location url")); + } else { + + hlcache_handle_retrieve(nsurl, + HLCACHE_RETRIEVE_SNIFF_TYPE, + nsref, + NULL, + browser_window_favicon_callback, + bw, + NULL, + CONTENT_IMAGE, + &bw->loading_favicon); + + nsurl_unref(nsurl); + } + + } break; default: @@ -962,6 +981,8 @@ static void browser_window_update_favicon(hlcache_handle *c, if (bw->loading_favicon != NULL) return; + bw->failed_favicon = false; + if (link == NULL) { /* look for favicon metadata link */ lwc_intern_string("icon", SLEN("icon"), &icon_str); @@ -1001,6 +1022,7 @@ static void browser_window_update_favicon(hlcache_handle *c, /* no favicon via link, try for the default location */ error = nsurl_join(nsurl, "/favicon.ico", &nsurl); } else { + bw->failed_favicon = true; error = nsurl_create("resource:favicon.ico", &nsurl); } if (error != NSERROR_OK) { diff --git a/desktop/browser.h b/desktop/browser.h index e990f1173..8ad261296 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -79,6 +79,8 @@ struct browser_window { struct hlcache_handle *current_favicon; /** handle for favicon which we started loading early */ struct hlcache_handle *loading_favicon; + /** favicon fetch already failed - prevents infinite error looping */ + bool failed_favicon; /** Window history structure. */ struct history *history; -- cgit v1.2.3