summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2014-01-24 23:13:18 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2014-01-24 23:13:18 +0000
commit5787f8335ea552e9011d989fc5d6473833bc1126 (patch)
tree6364d0486d60d28b7be1a6cc87efaf318243bbc3
parentdab6d7961ea6fb70aa6021e5dc7a189915b0c10c (diff)
downloadnetsurf-5787f8335ea552e9011d989fc5d6473833bc1126.tar.gz
netsurf-5787f8335ea552e9011d989fc5d6473833bc1126.tar.bz2
Simplify and optimise icon handling.
-rw-r--r--desktop/browser.c54
-rw-r--r--utils/corestrings.c12
-rw-r--r--utils/corestrings.h10
3 files changed, 33 insertions, 43 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index d94a2872a..a33c1b6eb 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -967,7 +967,6 @@ static nserror browser_window_favicon_callback(hlcache_handle *c,
static void browser_window_update_favicon(hlcache_handle *c,
struct browser_window *bw, struct content_rfc5988_link *link)
{
- lwc_string *icon_str;
nsurl *nsref = NULL;
nsurl *nsurl;
nserror error;
@@ -986,20 +985,14 @@ static void browser_window_update_favicon(hlcache_handle *c,
bw->failed_favicon = false;
if (link == NULL) {
- /* look for favicon metadata link */
- if (lwc_intern_string("icon", SLEN("icon"),
- &icon_str) == lwc_error_ok) {
- link = content_find_rfc5988_link(c, icon_str);
- lwc_string_unref(icon_str);
- }
+ /* Look for "icon" */
+ link = content_find_rfc5988_link(c, corestring_lwc_icon);
}
if (link == NULL) {
- if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
- &icon_str) == lwc_error_ok) {
- link = content_find_rfc5988_link(c, icon_str);
- lwc_string_unref(icon_str);
- }
+ /* Look for "shortcut icon" */
+ link = content_find_rfc5988_link(c,
+ corestring_lwc_shortcut_icon);
}
if (link == NULL) {
@@ -1404,34 +1397,17 @@ static nserror browser_window_callback(hlcache_handle *c,
case CONTENT_MSG_LINK: /* content has an rfc5988 link element */
{
- lwc_string *icon_str;
- lwc_string *shortcut_icon_str;
- bool icon_match = false;
- bool shortcut_icon_match = false;
-
- if (lwc_intern_string("icon", SLEN("icon"),
- &icon_str) == lwc_error_ok) {
- if (lwc_string_caseless_isequal(
- event->data.rfc5988_link->rel,
- icon_str,
- &icon_match) != lwc_error_ok) {
- icon_match = false;
- }
- lwc_string_unref(icon_str);
- }
-
- if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
- &shortcut_icon_str) == lwc_error_ok) {
- if (lwc_string_caseless_isequal(
- event->data.rfc5988_link->rel,
- shortcut_icon_str,
- &shortcut_icon_match) != lwc_error_ok) {
- shortcut_icon_match = false;
- }
- lwc_string_unref(shortcut_icon_str);
- }
+ bool match;
- if (icon_match || shortcut_icon_match) {
+ /* Handle "icon" and "shortcut icon" */
+ if ((lwc_string_caseless_isequal(
+ event->data.rfc5988_link->rel,
+ corestring_lwc_icon,
+ &match) == lwc_error_ok && match) ||
+ (lwc_string_caseless_isequal(
+ event->data.rfc5988_link->rel,
+ corestring_lwc_shortcut_icon,
+ &match) == lwc_error_ok && match)) {
/* it's a favicon perhaps start a fetch for it */
browser_window_update_favicon(c, bw,
event->data.rfc5988_link);
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 1a0c962da..47279c335 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -63,6 +63,7 @@ lwc_string *corestring_lwc_hr;
lwc_string *corestring_lwc_html;
lwc_string *corestring_lwc_http;
lwc_string *corestring_lwc_https;
+lwc_string *corestring_lwc_icon;
lwc_string *corestring_lwc_iframe;
lwc_string *corestring_lwc_image;
lwc_string *corestring_lwc_img;
@@ -94,6 +95,7 @@ lwc_string *corestring_lwc_resource;
lwc_string *corestring_lwc_right;
lwc_string *corestring_lwc_search;
lwc_string *corestring_lwc_select;
+lwc_string *corestring_lwc_shortcut_icon;
lwc_string *corestring_lwc_src;
lwc_string *corestring_lwc_style;
lwc_string *corestring_lwc_submit;
@@ -315,6 +317,7 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(html);
CSS_LWC_STRING_UNREF(http);
CSS_LWC_STRING_UNREF(https);
+ CSS_LWC_STRING_UNREF(icon);
CSS_LWC_STRING_UNREF(iframe);
CSS_LWC_STRING_UNREF(image);
CSS_LWC_STRING_UNREF(img);
@@ -346,6 +349,7 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(right);
CSS_LWC_STRING_UNREF(search);
CSS_LWC_STRING_UNREF(select);
+ CSS_LWC_STRING_UNREF(shortcut_icon);
CSS_LWC_STRING_UNREF(src);
CSS_LWC_STRING_UNREF(style);
CSS_LWC_STRING_UNREF(submit);
@@ -591,6 +595,7 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(html);
CSS_LWC_STRING_INTERN(http);
CSS_LWC_STRING_INTERN(https);
+ CSS_LWC_STRING_INTERN(icon);
CSS_LWC_STRING_INTERN(iframe);
CSS_LWC_STRING_INTERN(image);
CSS_LWC_STRING_INTERN(img);
@@ -655,6 +660,13 @@ nserror corestrings_init(void)
goto error;
}
+ lerror = lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
+ &corestring_lwc_shortcut_icon);
+ if ((lerror != lwc_error_ok) || (corestring_lwc_shortcut_icon == NULL)) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
lerror = lwc_intern_string("text/css", SLEN("text/css"),
&corestring_lwc_text_css);
if ((lerror != lwc_error_ok) || (corestring_lwc_text_css == NULL)) {
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 555b916b5..78fcd1560 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -67,6 +67,7 @@ extern lwc_string *corestring_lwc_hr;
extern lwc_string *corestring_lwc_html;
extern lwc_string *corestring_lwc_http;
extern lwc_string *corestring_lwc_https;
+extern lwc_string *corestring_lwc_icon;
extern lwc_string *corestring_lwc_iframe;
extern lwc_string *corestring_lwc_image;
extern lwc_string *corestring_lwc_img;
@@ -77,7 +78,7 @@ extern lwc_string *corestring_lwc_li;
extern lwc_string *corestring_lwc_link;
extern lwc_string *corestring_lwc_meta;
extern lwc_string *corestring_lwc_middle;
-extern lwc_string *corestring_lwc_multipart_form_data;
+extern lwc_string *corestring_lwc_multipart_form_data; /* multipart/form-data */
extern lwc_string *corestring_lwc_no;
extern lwc_string *corestring_lwc_noscript;
extern lwc_string *corestring_lwc_object;
@@ -98,6 +99,7 @@ extern lwc_string *corestring_lwc_resource;
extern lwc_string *corestring_lwc_right;
extern lwc_string *corestring_lwc_search;
extern lwc_string *corestring_lwc_select;
+extern lwc_string *corestring_lwc_shortcut_icon; /* shortcut icon */
extern lwc_string *corestring_lwc_src;
extern lwc_string *corestring_lwc_style;
extern lwc_string *corestring_lwc_submit;
@@ -107,7 +109,7 @@ extern lwc_string *corestring_lwc_td;
extern lwc_string *corestring_lwc_text;
extern lwc_string *corestring_lwc_textarea;
extern lwc_string *corestring_lwc_texttop;
-extern lwc_string *corestring_lwc_text_css;
+extern lwc_string *corestring_lwc_text_css; /* text/css */
extern lwc_string *corestring_lwc_tfoot;
extern lwc_string *corestring_lwc_th;
extern lwc_string *corestring_lwc_thead;
@@ -183,7 +185,7 @@ extern struct dom_string *corestring_dom_height;
extern struct dom_string *corestring_dom_href;
extern struct dom_string *corestring_dom_hreflang;
extern struct dom_string *corestring_dom_hspace;
-extern struct dom_string *corestring_dom_http_equiv;
+extern struct dom_string *corestring_dom_http_equiv; /* http-equiv */
extern struct dom_string *corestring_dom_id;
extern struct dom_string *corestring_dom_input;
extern struct dom_string *corestring_dom_invalid;
@@ -244,7 +246,7 @@ extern struct dom_string *corestring_dom_submit;
extern struct dom_string *corestring_dom_suspend;
extern struct dom_string *corestring_dom_target;
extern struct dom_string *corestring_dom_text;
-extern struct dom_string *corestring_dom_text_javascript;
+extern struct dom_string *corestring_dom_text_javascript; /* text/javascript */
extern struct dom_string *corestring_dom_timeupdate;
extern struct dom_string *corestring_dom_title;
extern struct dom_string *corestring_dom_type;