summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-11-05 23:44:31 +0000
committerVincent Sanders <vince@kyllikki.org>2014-11-05 23:44:31 +0000
commit8ec7ad053a9a291ea2619055b1ca1989d4c975b9 (patch)
treeaa7272b673e2062985667d87fcfe7e19f30eb239
parent4ca959f46baf18213bf5ded769d87c7f030d392f (diff)
downloadnetsurf-8ec7ad053a9a291ea2619055b1ca1989d4c975b9.tar.gz
netsurf-8ec7ad053a9a291ea2619055b1ca1989d4c975b9.tar.bz2
Make the fetching of a contents encoding generic.
The frontends previously had to use an html renderer API to get the encoding of a content. This also required the explicit checking of the contents type rather than using the existing content API to abstract this knowledge.
-rw-r--r--content/content.c24
-rw-r--r--content/content.h3
-rw-r--r--content/content_protected.h3
-rw-r--r--content/hlcache.c5
-rw-r--r--desktop/browser.c2
-rw-r--r--gtk/viewsource.c3
-rw-r--r--render/html.c11
-rw-r--r--render/html.h1
-rw-r--r--riscos/window.c4
9 files changed, 40 insertions, 16 deletions
diff --git a/content/content.c b/content/content.c
index ee6ff818f..728147f31 100644
--- a/content/content.c
+++ b/content/content.c
@@ -1302,6 +1302,30 @@ bool content_get_quirks(hlcache_handle *h)
/**
+ * Retrieve the encoding of a content
+ *
+ * \param c Content to retrieve bitmap from
+ * \return Pointer to bitmap, or NULL if none.
+ */
+const char *content_get_encoding(hlcache_handle *h)
+{
+ return content__get_encoding(hlcache_handle_get_content(h));
+}
+
+const char *content__get_encoding(struct content *c)
+{
+ const char *encoding = NULL;
+
+ if ((c != NULL) &&
+ (c->handler != NULL) &&
+ (c->handler->get_encoding != NULL) ) {
+ encoding = c->handler->get_encoding(c);
+ }
+
+ return encoding;
+}
+
+/**
* Return whether a content is currently locked
*
* \param c Content to test
diff --git a/content/content.h b/content/content.h
index 11ddee1dd..67a519df6 100644
--- a/content/content.h
+++ b/content/content.h
@@ -318,7 +318,8 @@ void content_invalidate_reuse_data(struct hlcache_handle *c);
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 *c);
+bool content_get_quirks(struct hlcache_handle *h);
+const char *content_get_encoding(struct hlcache_handle *h);
bool content_is_locked(struct hlcache_handle *h);
diff --git a/content/content_protected.h b/content/content_protected.h
index 84b401f00..ce161befc 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -79,6 +79,7 @@ struct content_handler {
nserror (*debug_dump)(struct content *c, FILE *f, 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);
content_type (*type)(void);
/** handler dependant content sensitive internal data interface. */
@@ -196,7 +197,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);
bool content__is_locked(struct content *c);
#endif
diff --git a/content/hlcache.c b/content/hlcache.c
index 8a7ffe9da..6cfcba328 100644
--- a/content/hlcache.c
+++ b/content/hlcache.c
@@ -718,10 +718,9 @@ nserror hlcache_handle_release(hlcache_handle *handle)
/* See hlcache.h for documentation */
struct content *hlcache_handle_get_content(const hlcache_handle *handle)
{
- assert(handle != NULL);
-
- if (handle->entry != NULL)
+ if ((handle != NULL) && (handle->entry != NULL)) {
return handle->entry->content;
+ }
return NULL;
}
diff --git a/desktop/browser.c b/desktop/browser.c
index ada46cdd3..b075bcb15 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1907,8 +1907,8 @@ nserror browser_window_navigate(struct browser_window *bw,
post.data.urlenc = post_urlenc;
}
+ child.charset = content_get_encoding(parent);
if ((parent != NULL) && (content_get_type(parent) == CONTENT_HTML)) {
- child.charset = html_get_encoding(parent);
child.quirks = content_get_quirks(parent);
}
diff --git a/gtk/viewsource.c b/gtk/viewsource.c
index 7ff8ad64b..9a103eef0 100644
--- a/gtk/viewsource.c
+++ b/gtk/viewsource.c
@@ -23,7 +23,6 @@
#include "utils/messages.h"
#include "desktop/browser.h"
#include "content/content.h"
-#include "render/html.h"
#include "gtk/viewdata.h"
#include "gtk/viewsource.h"
@@ -62,7 +61,7 @@ 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,
- html_get_encoding(hlcontent),
+ content_get_encoding(hlcontent),
source_size,
&ndata,
&ndata_len);
diff --git a/render/html.c b/render/html.c
index 854d892cd..d4ce3366f 100644
--- a/render/html.c
+++ b/render/html.c
@@ -2109,16 +2109,16 @@ struct box *html_get_box_tree(hlcache_handle *h)
/**
* Retrieve the charset of an HTML document
*
- * \param h Content to retrieve charset from
+ * \param c Content to retrieve charset from
* \return Pointer to charset, or NULL
*/
-const char *html_get_encoding(hlcache_handle *h)
+static const char *html_encoding(const struct content *c)
{
- html_content *c = (html_content *) hlcache_handle_get_content(h);
+ html_content *html = (html_content *) c;
- assert(c != NULL);
+ assert(html != NULL);
- return c->encoding;
+ return html->encoding;
}
/**
@@ -2262,6 +2262,7 @@ static const content_handler html_content_handler = {
.search_clear = html_search_clear,
.debug_dump = html_debug_dump,
.clone = html_clone,
+ .get_encoding = html_encoding,
.type = html_content_type,
.no_share = true,
};
diff --git a/render/html.h b/render/html.h
index 6f222dbf6..145471827 100644
--- a/render/html.h
+++ b/render/html.h
@@ -174,7 +174,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);
-const char *html_get_encoding(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);
diff --git a/riscos/window.c b/riscos/window.c
index f3c92092c..76c4105bb 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -3824,11 +3824,11 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g)
sprintf(icon_buf, "file_xxx");
if (content_get_type(h) == CONTENT_HTML) {
- if (html_get_encoding(h)) {
+ if (content_get_encoding(h)) {
char enc_token[10] = "Encoding0";
enc_token[8] = '0' + html_get_encoding_source(h);
snprintf(enc_buf, sizeof enc_buf, "%s (%s)",
- html_get_encoding(h),
+ content_get_encoding(h),
messages_get(enc_token));
enc = enc_buf;
} else {