From 79ce683b4e6d34fe327b00f1e427e476016cfab0 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 4 Apr 2010 12:41:19 +0000 Subject: Most of a stop implementation. Remaining work: 1) Clone content_html_data 2) Cloning content_css_data requires the charset of the old content 3) Calling hlcache_handle_abort() before a content has been created must clean up the retrieval context. svn path=/trunk/netsurf/; revision=10236 --- render/directory.c | 11 +++++++++++ render/directory.h | 1 + render/favicon.c | 7 +++++-- render/html.c | 7 ++++++- render/html.h | 1 + render/textplain.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++-------- render/textplain.h | 3 ++- 7 files changed, 73 insertions(+), 12 deletions(-) (limited to 'render') diff --git a/render/directory.c b/render/directory.c index 969b0c5b9..193941ecf 100644 --- a/render/directory.c +++ b/render/directory.c @@ -150,3 +150,14 @@ void directory_destroy(struct content *c) return; } + +bool directory_clone(const struct content *old, struct content *new_content) +{ + /* This will only get called if the content is cloned before + * content_convert() is called. Simply replay creation. */ + if (directory_create(new_content, NULL) == false) + return false; + + return true; +} + diff --git a/render/directory.h b/render/directory.h index 25e5f3281..f16ad541b 100644 --- a/render/directory.h +++ b/render/directory.h @@ -33,5 +33,6 @@ struct http_parameter; bool directory_create(struct content *c, const struct http_parameter *params); bool directory_convert(struct content *c); void directory_destroy(struct content *c); +bool directory_clone(const struct content *old, struct content *new_content); #endif diff --git a/render/favicon.c b/render/favicon.c index 9f7ad7647..89b292528 100644 --- a/render/favicon.c +++ b/render/favicon.c @@ -195,9 +195,12 @@ nserror favicon_callback(hlcache_handle *icon, if (*type == CONTENT_UNKNOWN) { union content_msg_data msg_data; - hlcache_handle_release(c->data.html.favicon); - c->data.html.favicon = NULL; LOG(("%s is not a favicon", content_get_url(icon))); + + hlcache_handle_abort(icon); + hlcache_handle_release(icon); + c->data.html.favicon = NULL; + content_add_error(c, "NotFavIco", 0); msg_data.error = messages_get("NotFavIco"); diff --git a/render/html.c b/render/html.c index e38a4ba99..2ead62fc3 100644 --- a/render/html.c +++ b/render/html.c @@ -1681,7 +1681,7 @@ void html_stop(struct content *c) if (content_get_status(object) == CONTENT_STATUS_DONE) ; /* already loaded: do nothing */ else if (content_get_status(object) == CONTENT_STATUS_READY) - content_stop(object, html_object_callback, NULL); + hlcache_handle_abort(object); else { hlcache_handle_release(object); c->data.html.object[i].content = NULL; @@ -1847,6 +1847,11 @@ void html_destroy_iframe(struct content_html_iframe *iframe) { } } +bool html_clone(const struct content *old, struct content *new_content) +{ + /** \todo Clone HTML specifics */ + return true; +} /** * Set the content status. diff --git a/render/html.h b/render/html.h index 42d4ec163..79a3b209a 100644 --- a/render/html.h +++ b/render/html.h @@ -190,6 +190,7 @@ bool html_process_data(struct content *c, const char *data, unsigned int size); bool html_convert(struct content *c); void html_reformat(struct content *c, int width, int height); void html_destroy(struct content *c); +bool html_clone(const struct content *old, struct content *new_content); bool html_fetch_object(struct content *c, const char *url, struct box *box, const content_type *permitted_types, int available_width, int available_height, diff --git a/render/textplain.c b/render/textplain.c index 8983fc2a9..f39a89a08 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -65,6 +65,7 @@ static plot_font_style_t textplain_style = { static int textplain_tab_width = 256; /* try for a sensible default */ +static bool textplain_create_internal(struct content *c, const char *encoding); static int textplain_coord_from_offset(const char *text, size_t offset, size_t length); static float textplain_line_height(void); @@ -76,23 +77,29 @@ static float textplain_line_height(void); bool textplain_create(struct content *c, const http_parameter *params) { - char *utf8_data; const char *encoding; - iconv_t iconv_cd; - union content_msg_data msg_data; nserror error; textplain_style.size = (option_font_size * FONT_SIZE_SCALE) / 10; - utf8_data = talloc_array(c, char, CHUNK); - if (!utf8_data) - goto no_memory; - error = http_parameter_list_find_item(params, "charset", &encoding); if (error != NSERROR_OK) { encoding = "Windows-1252"; } + return textplain_create_internal(c, encoding); +} + +bool textplain_create_internal(struct content *c, const char *encoding) +{ + char *utf8_data; + iconv_t iconv_cd; + union content_msg_data msg_data; + + utf8_data = talloc_array(c, char, CHUNK); + if (!utf8_data) + goto no_memory; + iconv_cd = iconv_open("utf-8", encoding); if (iconv_cd == (iconv_t)(-1) && errno == EINVAL) { LOG(("unsupported encoding \"%s\"", encoding)); @@ -110,7 +117,10 @@ bool textplain_create(struct content *c, const http_parameter *params) return false; } - c->data.textplain.encoding = encoding; + c->data.textplain.encoding = strdup(encoding); + if (c->data.textplain.encoding == NULL) + goto no_memory; + c->data.textplain.iconv_cd = iconv_cd; c->data.textplain.converted = 0; c->data.textplain.utf8_data = utf8_data; @@ -310,11 +320,40 @@ no_memory: void textplain_destroy(struct content *c) { + if (c->data.textplain.encoding != NULL) + free(c->data.textplain.encoding); + if (c->data.textplain.iconv_cd) iconv_close(c->data.textplain.iconv_cd); } +bool textplain_clone(const struct content *old, struct content *new_content) +{ + const char *data; + unsigned long size; + + /* Simply replay create/process/convert */ + if (textplain_create_internal(new_content, + old->data.textplain.encoding) == false) + return false; + + data = content__get_source_data(new_content, &size); + if (size > 0) { + if (textplain_process_data(new_content, data, size) == false) + return false; + } + + if (old->status == CONTENT_STATUS_READY || + old->status == CONTENT_STATUS_DONE) { + if (textplain_convert(new_content) == false) + return false; + } + + return true; +} + + /** * Draw a CONTENT_TEXTPLAIN using the current set of plotters (plot). * diff --git a/render/textplain.h b/render/textplain.h index ec4882800..61a1c0c9a 100644 --- a/render/textplain.h +++ b/render/textplain.h @@ -37,7 +37,7 @@ struct textplain_line { }; struct content_textplain_data { - const char *encoding; + char *encoding; iconv_t iconv_cd; size_t converted; char *utf8_data; @@ -58,6 +58,7 @@ bool textplain_redraw(struct content *c, int x, int y, int width, int height, int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale, colour background_colour); +bool textplain_clone(const struct content *old, struct content *new_content); /* access to lines for text selection and searching */ unsigned long textplain_line_count(struct hlcache_handle *h); -- cgit v1.2.3