summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-10-07 18:12:47 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-10-07 18:12:47 +0000
commit230779848e22f5d185cbeb0ccaae0c16cbc5836c (patch)
tree414dc368828574374d85553490daa23dd53e1bd6 /content
parent52ad2c1e2523b28aa5363656fbbef20e97665cce (diff)
downloadnetsurf-230779848e22f5d185cbeb0ccaae0c16cbc5836c.tar.gz
netsurf-230779848e22f5d185cbeb0ccaae0c16cbc5836c.tar.bz2
metadata links stored in contents
browser uses metadata links for favicons svn path=/trunk/netsurf/; revision=12977
Diffstat (limited to 'content')
-rw-r--r--content/content.c99
-rw-r--r--content/content.h20
-rw-r--r--content/content_protected.h7
3 files changed, 121 insertions, 5 deletions
diff --git a/content/content.c b/content/content.c
index 7b722a274..28d18bcab 100644
--- a/content/content.c
+++ b/content/content.c
@@ -376,6 +376,8 @@ void content__reformat(struct content *c, bool background,
void content_destroy(struct content *c)
{
+ struct content_rfc5988_link *link;
+
assert(c);
LOG(("content %p %s", c,
nsurl_access(llcache_handle_get_url(c->llcache))));
@@ -389,6 +391,12 @@ void content_destroy(struct content *c)
lwc_string_unref(c->mime_type);
+ /* release metadata links */
+ link = c->links;
+ while (link != NULL) {
+ link = content__free_rfc5988_link(link);
+ }
+
talloc_free(c);
}
@@ -744,6 +752,97 @@ bool content__set_title(struct content *c, const char *title)
return true;
}
+struct content_rfc5988_link *
+content_find_rfc5988_link(hlcache_handle *h, lwc_string *rel)
+{
+ struct content *c = hlcache_handle_get_content(h);
+ struct content_rfc5988_link *link = c->links;
+ bool rel_match = false;
+
+ while (link != NULL) {
+ lwc_string_caseless_isequal(link->rel, rel, &rel_match);
+ if (rel_match) {
+ break;
+ }
+ link = link->next;
+ }
+ return link;
+}
+
+struct content_rfc5988_link *
+content__free_rfc5988_link(struct content_rfc5988_link *link)
+{
+ struct content_rfc5988_link *next;
+
+ next = link->next;
+
+ lwc_string_unref(link->rel);
+ nsurl_unref(link->href);
+ if (link->hreflang != NULL) {
+ lwc_string_unref(link->hreflang);
+ }
+ if (link->type != NULL) {
+ lwc_string_unref(link->type);
+ }
+ if (link->media != NULL) {
+ lwc_string_unref(link->media);
+ }
+ if (link->sizes != NULL) {
+ lwc_string_unref(link->sizes);
+ }
+ free(link);
+
+ return next;
+}
+
+bool content__add_rfc5988_link(struct content *c,
+ const struct content_rfc5988_link *link)
+{
+ struct content_rfc5988_link *newlink;
+ union content_msg_data msg_data;
+
+ /* a link relation must be present for it to be a link */
+ if (link->rel == NULL) {
+ return false;
+ }
+
+ /* a link href must be present for it to be a link */
+ if (link->href == NULL) {
+ return false;
+ }
+
+ newlink = calloc(1, sizeof(struct content_rfc5988_link));
+ if (newlink == NULL) {
+ return false;
+ }
+
+ /* copy values */
+ newlink->rel = lwc_string_ref(link->rel);
+ newlink->href = nsurl_ref(link->href);
+ if (link->hreflang != NULL) {
+ newlink->hreflang = lwc_string_ref(link->hreflang);
+ }
+ if (link->type != NULL) {
+ newlink->type = lwc_string_ref(link->type);
+ }
+ if (link->media != NULL) {
+ newlink->media = lwc_string_ref(link->media);
+ }
+ if (link->sizes != NULL) {
+ newlink->sizes = lwc_string_ref(link->sizes);
+ }
+
+ /* add to metadata link to list */
+ newlink->next = c->links;
+ c->links = newlink;
+
+ /* broadcast the data */
+ msg_data.rfc5988_link = newlink;
+ content_broadcast(c, CONTENT_MSG_LINK, msg_data);
+
+ return true;
+}
+
/**
* Retrieve computed type of content
*
diff --git a/content/content.h b/content/content.h
index eb8fbe689..3fd0bd63a 100644
--- a/content/content.h
+++ b/content/content.h
@@ -75,6 +75,18 @@ typedef enum {
CONTENT_MSG_LINK, /**< RFC5988 link */
} content_msg;
+/** RFC5988 metadata link */
+struct content_rfc5988_link {
+ struct content_rfc5988_link *next; /**< next rfc5988_link in list */
+
+ lwc_string *rel; /**< the link relationship - must be present */
+ nsurl *href; /* the link href - must be present */
+ lwc_string *hreflang;
+ lwc_string *type;
+ lwc_string *media;
+ lwc_string *sizes;
+};
+
/** Extra data for some content_msg messages. */
union content_msg_data {
const char *error; /**< Error message, for CONTENT_MSG_ERROR. */
@@ -97,11 +109,7 @@ union content_msg_data {
/** Low-level cache handle, for CONTENT_MSG_DOWNLOAD */
struct llcache_handle *download;
/** rfc5988 link data CONTENT_MSG_RFC5988_LINK */
- struct {
- nsurl *url;
- char *rel;
- char *type;
- } rfc5988_link;
+ struct content_rfc5988_link *rfc5988_link;
};
@@ -167,6 +175,8 @@ void content_close(struct hlcache_handle *h);
struct selection *content_get_selection(struct hlcache_handle *h);
void content_get_contextual_content(struct hlcache_handle *h,
int x, int y, struct contextual_content *data);
+struct content_rfc5988_link *content_find_rfc5988_link(struct hlcache_handle *c,
+ lwc_string *rel);
/* Member accessors */
content_type content_get_type(struct hlcache_handle *c);
diff --git a/content/content_protected.h b/content/content_protected.h
index eeaa67cbf..05b1940f2 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -108,6 +108,8 @@ struct content {
nsurl *refresh; /**< URL for refresh request */
+ struct content_rfc5988_link *links; /**< list of metadata links */
+
unsigned int time; /**< Creation time,
if LOADING or READY,
otherwise total time. */
@@ -160,6 +162,11 @@ void content_broadcast(struct content *c, content_msg msg,
void content_add_error(struct content *c, const char *token,
unsigned int line);
+bool content__add_rfc5988_link(struct content *c,
+ const struct content_rfc5988_link *link);
+struct content_rfc5988_link *content__free_rfc5988_link(
+ struct content_rfc5988_link *link);
+
void content__reformat(struct content *c, bool background,
int width, int height);
void content__request_redraw(struct content *c,