Improve content encoding information API

Extend the content_get_encoding() API to retrieve the source of
the encoding as well as the actual encoding.
This commit is contained in:
Vincent Sanders 2014-11-07 12:33:34 +00:00
parent 6993e842d9
commit 3405803280
8 changed files with 28 additions and 33 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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");