mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-25 07:49:38 +03:00
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.
This commit is contained in:
parent
4ca959f46b
commit
8ec7ad053a
@ -1301,6 +1301,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
|
||||
*
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user