summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-11-07 12:33:34 +0000
committerVincent Sanders <vince@kyllikki.org>2014-11-07 12:33:34 +0000
commit3405803280c9cafab0a4ef229faa4bc447e4c953 (patch)
treeac7d85272d21ec15cec1825a2ea6b43f7b4cf11b
parent6993e842d902e363d44014fa514c91ca30896555 (diff)
downloadnetsurf-3405803280c9cafab0a4ef229faa4bc447e4c953.tar.gz
netsurf-3405803280c9cafab0a4ef229faa4bc447e4c953.tar.bz2
Improve content encoding information API
Extend the content_get_encoding() API to retrieve the source of the encoding as well as the actual encoding.
-rw-r--r--content/content.c8
-rw-r--r--content/content.h8
-rw-r--r--content/content_protected.h4
-rw-r--r--desktop/browser.c2
-rw-r--r--gtk/viewsource.c8
-rw-r--r--render/html.c22
-rw-r--r--render/html.h1
-rw-r--r--riscos/window.c8
8 files changed, 28 insertions, 33 deletions
diff --git a/content/content.c b/content/content.c
index 83fdacf78..cd493ba44 100644
--- a/content/content.c
+++ b/content/content.c
@@ -1323,19 +1323,19 @@ bool content_get_quirks(hlcache_handle *h)
* \param c Content to retrieve bitmap from
* \return Pointer to bitmap, or NULL if none.
*/
-const char *content_get_encoding(hlcache_handle *h)
+const char *content_get_encoding(hlcache_handle *h, enum content_encoding_type op)
{
- return content__get_encoding(hlcache_handle_get_content(h));
+ return content__get_encoding(hlcache_handle_get_content(h), op);
}
-const char *content__get_encoding(struct content *c)
+const char *content__get_encoding(struct content *c, enum content_encoding_type op)
{
const char *encoding = NULL;
if ((c != NULL) &&
(c->handler != NULL) &&
(c->handler->get_encoding != NULL) ) {
- encoding = c->handler->get_encoding(c);
+ encoding = c->handler->get_encoding(c, op);
}
return encoding;
diff --git a/content/content.h b/content/content.h
index bc47ffef0..9c9d64975 100644
--- a/content/content.h
+++ b/content/content.h
@@ -94,6 +94,12 @@ enum content_debug {
CONTENT_DEBUG_REDRAW /** Debug redraw operations. */
};
+/** Content encoding informstion types */
+enum content_encoding_type {
+ CONTENT_ENCODING_NORMAL, /** The content encoding */
+ CONTENT_ENCODING_SOURCE /** The content encoding source */
+};
+
/** RFC5988 metadata link */
struct content_rfc5988_link {
struct content_rfc5988_link *next; /**< next rfc5988_link in list */
@@ -328,7 +334,7 @@ nsurl *content_get_refresh_url(struct hlcache_handle *c);
struct bitmap *content_get_bitmap(struct hlcache_handle *c);
bool content_get_opaque(struct hlcache_handle *h);
bool content_get_quirks(struct hlcache_handle *h);
-const char *content_get_encoding(struct hlcache_handle *h);
+const char *content_get_encoding(struct hlcache_handle *h, enum content_encoding_type op);
bool content_is_locked(struct hlcache_handle *h);
diff --git a/content/content_protected.h b/content/content_protected.h
index af274ef5a..2647b2e0f 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -80,7 +80,7 @@ struct content_handler {
nserror (*debug)(struct content *c, enum content_debug op);
nserror (*clone)(const struct content *old, struct content **newc);
bool (*matches_quirks)(const struct content *c, bool quirks);
- const char *(*get_encoding)(const struct content *c);
+ const char *(*get_encoding)(const struct content *c, enum content_encoding_type op);
content_type (*type)(void);
/** handler dependant content sensitive internal data interface. */
@@ -198,7 +198,7 @@ void content__invalidate_reuse_data(struct content *c);
nsurl *content__get_refresh_url(struct content *c);
struct bitmap *content__get_bitmap(struct content *c);
bool content__get_opaque(struct content *c);
-const char *content__get_encoding(struct content *c);
+const char *content__get_encoding(struct content *c, enum content_encoding_type op);
bool content__is_locked(struct content *c);
#endif
diff --git a/desktop/browser.c b/desktop/browser.c
index 528fb1fe5..c139cad28 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1916,7 +1916,7 @@ nserror browser_window_navigate(struct browser_window *bw,
post.data.urlenc = post_urlenc;
}
- child.charset = content_get_encoding(parent);
+ child.charset = content_get_encoding(parent, CONTENT_ENCODING_NORMAL);
if ((parent != NULL) && (content_get_type(parent) == CONTENT_HTML)) {
child.quirks = content_get_quirks(parent);
}
diff --git a/gtk/viewsource.c b/gtk/viewsource.c
index 9a103eef0..364ec8156 100644
--- a/gtk/viewsource.c
+++ b/gtk/viewsource.c
@@ -61,10 +61,10 @@ void nsgtk_viewsource(GtkWindow *parent, struct browser_window *bw)
sprintf(title, "Source of %s - NetSurf", nsurl_access(browser_window_get_url(bw)));
ret = utf8_from_enc(source_data,
- content_get_encoding(hlcontent),
- source_size,
- &ndata,
- &ndata_len);
+ content_get_encoding(hlcontent, CONTENT_ENCODING_NORMAL),
+ source_size,
+ &ndata,
+ &ndata_len);
if (ret == NSERROR_OK) {
ret = nsgtk_viewdata(title, filename, ndata, ndata_len);
}
diff --git a/render/html.c b/render/html.c
index 4e9347aa5..a3474c7ad 100644
--- a/render/html.c
+++ b/render/html.c
@@ -2128,29 +2128,21 @@ struct box *html_get_box_tree(hlcache_handle *h)
* \param c Content to retrieve charset from
* \return Pointer to charset, or NULL
*/
-static const char *html_encoding(const struct content *c)
+static const char *html_encoding(const struct content *c, enum content_encoding_type op)
{
html_content *html = (html_content *) c;
assert(html != NULL);
+ if (op == CONTENT_ENCODING_SOURCE) {
+ char enc_token[10] = "Encoding0";
+ enc_token[8] = '0' + html->encoding_source;
+ return messages_get(enc_token);
+ }
+
return html->encoding;
}
-/**
- * Retrieve the charset of an HTML document
- *
- * \param h Content to retrieve charset from
- * \return Pointer to charset, or NULL
- */
-dom_hubbub_encoding_source html_get_encoding_source(hlcache_handle *h)
-{
- html_content *c = (html_content *) hlcache_handle_get_content(h);
-
- assert(c != NULL);
-
- return c->encoding_source;
-}
/**
* Retrieve framesets used in an HTML document
diff --git a/render/html.h b/render/html.h
index 6503c91fe..ee204d3d6 100644
--- a/render/html.h
+++ b/render/html.h
@@ -171,7 +171,6 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
dom_document *html_get_document(struct hlcache_handle *h);
struct box *html_get_box_tree(struct hlcache_handle *h);
-dom_hubbub_encoding_source html_get_encoding_source(struct hlcache_handle *h);
struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
struct nsurl *html_get_base_url(struct hlcache_handle *h);
diff --git a/riscos/window.c b/riscos/window.c
index 1c8d8bd95..b2a46fc02 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -3825,12 +3825,10 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g)
sprintf(icon_buf, "file_xxx");
if (content_get_type(h) == CONTENT_HTML) {
- if (content_get_encoding(h)) {
- char enc_token[10] = "Encoding0";
- enc_token[8] = '0' + html_get_encoding_source(h);
+ if (content_get_encoding(h, CONTENT_ENCODING_NORMAL)) {
snprintf(enc_buf, sizeof enc_buf, "%s (%s)",
- content_get_encoding(h),
- messages_get(enc_token));
+ content_get_encoding(h, CONTENT_ENCODING_NORMAL),
+ content_get_encoding(h, CONTENT_ENCODING_SOURCE));
enc = enc_buf;
} else {
enc = messages_get("EncodingUnk");