Improve error handling

svn path=/trunk/netsurf/; revision=12997
This commit is contained in:
John Mark Bell 2011-10-08 00:06:43 +00:00
parent 3bb98823f7
commit 4cd69b8aa9

View File

@ -979,40 +979,43 @@ static void browser_window_update_favicon(hlcache_handle *c,
if (link == NULL) { if (link == NULL) {
/* look for favicon metadata link */ /* look for favicon metadata link */
lwc_intern_string("icon", SLEN("icon"), &icon_str); if (lwc_intern_string("icon", SLEN("icon"),
link = content_find_rfc5988_link(c, icon_str); &icon_str) == lwc_error_ok) {
lwc_string_unref(icon_str); link = content_find_rfc5988_link(c, icon_str);
lwc_string_unref(icon_str);
}
} }
if (link == NULL) { if (link == NULL) {
lwc_intern_string("shortcut icon", SLEN("shortcut_icon"), if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
&icon_str); &icon_str) == lwc_error_ok) {
link = content_find_rfc5988_link(c, icon_str); link = content_find_rfc5988_link(c, icon_str);
lwc_string_unref(icon_str); lwc_string_unref(icon_str);
}
} }
if (link == NULL) { if (link == NULL) {
lwc_string *scheme; lwc_string *scheme;
bool speculative_default = false;
lwc_string *http_str;
lwc_string *https_str;
bool http_match = false;
bool https_match = false;
nsurl = content_get_url(c); nsurl = content_get_url(c);
scheme = nsurl_get_component(nsurl, NSURL_SCHEME); scheme = nsurl_get_component(nsurl, NSURL_SCHEME);
lwc_intern_string("http", SLEN("http"), &http_str); /* If the document was fetched over http(s), then speculate
lwc_intern_string("https", SLEN("https"), &https_str); * that there's a favicon living at /favicon.ico */
lwc_string_caseless_isequal(scheme, http_str, &http_match); if ((lwc_string_length(scheme) == SLEN("HTTP") &&
lwc_string_caseless_isequal(scheme, https_str, &https_match); strcasecmp(lwc_string_data(scheme),
lwc_string_unref(http_str); "http") == 0) ||
lwc_string_unref(https_str); (lwc_string_length(scheme) == SLEN("HTTPS") &&
strcasecmp(lwc_string_data(scheme),
"https") == 0)) {
speculative_default = true;
}
lwc_string_unref(scheme); lwc_string_unref(scheme);
if (http_match || https_match) { if (speculative_default) {
/* no favicon via link, try for the default location */ /* no favicon via link, try for the default location */
error = nsurl_join(nsurl, "/favicon.ico", &nsurl); error = nsurl_join(nsurl, "/favicon.ico", &nsurl);
} else { } else {
@ -1252,20 +1255,29 @@ nserror browser_window_callback(hlcache_handle *c,
{ {
lwc_string *icon_str; lwc_string *icon_str;
lwc_string *shortcut_icon_str; lwc_string *shortcut_icon_str;
bool icon_match; bool icon_match = false;
bool shortcut_icon_match; bool shortcut_icon_match = false;
lwc_intern_string("icon", SLEN("icon"), &icon_str); if (lwc_intern_string("icon", SLEN("icon"),
lwc_intern_string("shortcut icon", SLEN("shortcut_icon"), &shortcut_icon_str); &icon_str) == lwc_error_ok) {
lwc_string_caseless_isequal(event->data.rfc5988_link->rel, icon_str, &icon_match); lwc_string_caseless_isequal(
lwc_string_caseless_isequal(event->data.rfc5988_link->rel, shortcut_icon_str, &shortcut_icon_match); event->data.rfc5988_link->rel,
lwc_string_unref(icon_str); icon_str, &icon_match);
lwc_string_unref(shortcut_icon_str); lwc_string_unref(icon_str);
}
if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
&shortcut_icon_str) == lwc_error_ok) {
lwc_string_caseless_isequal(
event->data.rfc5988_link->rel,
shortcut_icon_str,
&shortcut_icon_match);
lwc_string_unref(shortcut_icon_str);
}
if (icon_match || shortcut_icon_match) { if (icon_match || shortcut_icon_match) {
/* its a favicon perhaps start a fetch for it */ /* it's a favicon perhaps start a fetch for it */
browser_window_update_favicon(c, bw, event->data.rfc5988_link); browser_window_update_favicon(c, bw, event->data.rfc5988_link);
} }
} }
break; break;