From 2920bca14adbf145d64754b1ef8e6b888c7995ee Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sat, 9 Apr 2005 09:47:37 +0000 Subject: [project @ 2005-04-09 09:47:36 by bursa] Move HTML contents almost fully over to talloc(), simplifying code. Improvements to title attributes, broken forms, cellpadding. Reorder functions in box_construct.c. svn path=/import/netsurf/; revision=1608 --- render/html.c | 86 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) (limited to 'render/html.c') diff --git a/render/html.c b/render/html.c index 60e29f694..506904f6f 100644 --- a/render/html.c +++ b/render/html.c @@ -28,6 +28,7 @@ #include "netsurf/render/layout.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" +#include "netsurf/utils/talloc.h" #include "netsurf/utils/url.h" #include "netsurf/utils/utils.h" @@ -65,7 +66,7 @@ bool html_create(struct content *c, const char *params[]) html->encoding_handler = 0; html->encoding = 0; html->getenc = true; - html->base_url = strdup(c->url); + html->base_url = c->url; html->layout = 0; html->background_colour = TRANSPARENT; html->stylesheet_count = 0; @@ -73,17 +74,13 @@ bool html_create(struct content *c, const char *params[]) html->style = 0; html->object_count = 0; html->object = 0; + html->forms = 0; html->imagemaps = 0; - html->box_pool = pool_create(sizeof (struct box) * 100); - html->string_pool = pool_create(8000); html->bw = 0; - if (!html->base_url || !html->string_pool || !html->box_pool) - goto no_memory; - for (i = 0; params[i]; i += 2) { if (strcasecmp(params[i], "charset") == 0) { - html->encoding = strdup(params[i + 1]); + html->encoding = talloc_strdup(c, params[i + 1]); if (!html->encoding) goto no_memory; html->encoding_source = ENCODING_SOURCE_HEADER; @@ -135,7 +132,7 @@ bool html_process_data(struct content *c, char *data, unsigned int size) if (encoding) { if (!html_set_parser_encoding(c, encoding)) return false; - c->data.html.encoding = strdup(encoding); + c->data.html.encoding = talloc_strdup(c, encoding); if (!c->data.html.encoding) return false; c->data.html.encoding_source = @@ -266,7 +263,7 @@ bool html_convert(struct content *c, int width, int height) /* The encoding was not in headers or detected, and the parser * found a . */ - c->data.html.encoding = strdup(document->encoding); + c->data.html.encoding = talloc_strdup(c, document->encoding); if (!c->data.html.encoding) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -338,12 +335,13 @@ bool html_convert(struct content *c, int width, int height) content_set_status(c, messages_get("Formatting")); content_broadcast(c, CONTENT_MSG_STATUS, msg_data); LOG(("Layout document")); - layout_document(c->data.html.layout, width, - c->data.html.box_pool); + layout_document(c, width); /*box_dump(c->data.html.layout->children, 0);*/ c->width = c->data.html.layout->descendant_x1; c->height = c->data.html.layout->descendant_y1; + c->size = talloc_total_size(c); + if (c->active == 0) { c->status = CONTENT_STATUS_DONE; content_set_status(c, messages_get("Done")); @@ -380,20 +378,26 @@ bool html_head(struct content *c, xmlNode *head) xmlChar *title = xmlNodeGetContent(node); if (!title) return false; - c->title = squash_whitespace(title); + char *title2 = squash_whitespace(title); + xmlFree(title); + if (!title2) + return false; + c->title = talloc_strdup(c, title2); + free(title2); if (!c->title) return false; - xmlFree(title); } else if (strcmp(node->name, "base") == 0) { - char *href = (char *) xmlGetProp(node, (const xmlChar *) "href"); + char *href = (char *) xmlGetProp(node, + (const xmlChar *) "href"); if (href) { char *url; url_func_result res; res = url_normalize(href, &url); if (res == URL_FUNC_OK) { - free(c->data.html.base_url); - c->data.html.base_url = url; + c->data.html.base_url = + talloc_strdup(c, url); + free(url); } xmlFree(href); } @@ -424,8 +428,8 @@ bool html_find_stylesheets(struct content *c, xmlNode *head) /* stylesheet 0 is the base style sheet, * stylesheet 1 is the adblocking stylesheet, * stylesheet 2 is any