From 08b42089ca43d7d51166032179b015706ea5c337 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 4 Oct 2011 10:23:47 +0000 Subject: Pass nsurls through html_fetch_object. svn path=/trunk/netsurf/; revision=12945 --- render/box_construct.c | 77 ++++++++++++++++++++++++++++++++------------------ render/html.c | 15 ++-------- render/html_internal.h | 2 +- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/render/box_construct.c b/render/box_construct.c index 6101d8f1b..2e6d52567 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -399,12 +399,24 @@ static bool box_construct_marker(struct box *box, const char *title, if (css_computed_list_style_image(box->style, &image_uri) == CSS_LIST_STYLE_IMAGE_URI && image_uri != NULL) { - if (html_fetch_object(content, - lwc_string_data(image_uri), - marker, image_types, - content->base.available_width, - 1000, false) == false) + nsurl *url; + nserror error; + + /* TODO: we get a url out of libcss as a lwc string, but + * earlier we already had it as a nsurl after we + * nsurl_joined it. Can this be improved? + * For now, just making another nsurl. */ + error = nsurl_create(lwc_string_data(image_uri), &url); + if (error != NSERROR_OK) return false; + + if (html_fetch_object(content, url, marker, image_types, + content->base.available_width, 1000, false) == + false) { + nsurl_unref(url); + return false; + } + nsurl_unref(url); } box->list_marker = marker; @@ -685,12 +697,24 @@ bool box_construct_element(struct box_construct_ctx *ctx, /* Kick off fetch for any background image */ if (css_computed_background_image(box->style, &bgimage_uri) == CSS_BACKGROUND_IMAGE_IMAGE && bgimage_uri != NULL) { - if (html_fetch_object(ctx->content, - lwc_string_data(bgimage_uri), - box, image_types, + nsurl *url; + nserror error; + + /* TODO: we get a url out of libcss as a lwc string, but + * earlier we already had it as a nsurl after we + * nsurl_joined it. Can this be improved? + * For now, just making another nsurl. */ + error = nsurl_create(lwc_string_data(bgimage_uri), &url); + if (error != NSERROR_OK) + return false; + + if (html_fetch_object(ctx->content, url, box, image_types, ctx->content->base.available_width, 1000, - true) == false) + true) == false) { + nsurl_unref(url); return false; + } + nsurl_unref(url); } if (*convert_children) @@ -1339,7 +1363,7 @@ bool box_image(BOX_SPECIAL_PARAMS) return true; /* start fetch */ - ok = html_fetch_object(content, nsurl_access(url), box, image_types, + ok = html_fetch_object(content, url, box, image_types, content->base.available_width, 1000, false); nsurl_unref(url); @@ -1536,9 +1560,8 @@ bool box_object(BOX_SPECIAL_PARAMS) /* start fetch (MIME type is ok or not specified) */ if (!html_fetch_object(content, - params->data ? nsurl_access(params->data) : - nsurl_access(params->classid), - box, CONTENT_ANY, content->base.available_width, 1000, + params->data ? params->data : params->classid, + box, CONTENT_ANY, content->base.available_width, 1000, false)) return false; @@ -1913,8 +1936,9 @@ bool box_iframe(BOX_SPECIAL_PARAMS) bool box_input(BOX_SPECIAL_PARAMS) { struct form_control *gadget = NULL; - char *s, *type, *url; - url_func_result res; + char *s, *type; + nsurl *url; + nserror error; type = (char *) xmlGetProp(n, (const xmlChar *) "type"); @@ -1983,28 +2007,26 @@ bool box_input(BOX_SPECIAL_PARAMS) n->parent == NULL) != CSS_DISPLAY_NONE) { if ((s = (char *) xmlGetProp(n, (const xmlChar*) "src"))) { - res = url_join(s, - nsurl_access(content->base_url), - &url); + error = nsurl_join(content->base_url, s, &url); xmlFree(s); + if (error != NSERROR_OK) + goto no_memory; + /* if url is equivalent to the parent's url, * we've got infinite inclusion. stop it here - * also bail if url_join failed. */ - if (res == URL_FUNC_OK && - strcasecmp(url, - nsurl_access( - content->base_url)) != 0) { + if (nsurl_compare(url, content->base_url, + NSURL_COMPLETE) == false) { if (!html_fetch_object(content, url, box, image_types, content->base. available_width, 1000, false)) { - free(url); + nsurl_unref(url); goto no_memory; } } - free(url); + nsurl_unref(url); } } } else { @@ -2421,9 +2443,8 @@ bool box_embed(BOX_SPECIAL_PARAMS) box->object_params = params; /* start fetch */ - return html_fetch_object(content, nsurl_access(params->data), box, - CONTENT_ANY, content->base.available_width, 1000, - false); + return html_fetch_object(content, params->data, box, CONTENT_ANY, + content->base.available_width, 1000, false); } /** diff --git a/render/html.c b/render/html.c index 9aaa914c4..27fe59424 100644 --- a/render/html.c +++ b/render/html.c @@ -1388,7 +1388,7 @@ nserror html_convert_css_callback(hlcache_handle *css, * \return true on success, false on memory exhaustion */ -bool html_fetch_object(html_content *c, const char *url, struct box *box, +bool html_fetch_object(html_content *c, nsurl *url, struct box *box, content_type permitted_types, int available_width, int available_height, bool background) @@ -1396,7 +1396,6 @@ bool html_fetch_object(html_content *c, const char *url, struct box *box, struct content_html_object *object; hlcache_child_context child; nserror error; - nsurl *object_url; /* If we've already been aborted, don't bother attempting the fetch */ if (c->aborted) @@ -1405,15 +1404,8 @@ bool html_fetch_object(html_content *c, const char *url, struct box *box, child.charset = c->encoding; child.quirks = c->base.quirks; - error = nsurl_create(url, &object_url); - if (error != NSERROR_OK) { - LOG(("failed to normalize url '%s'", url)); - return false; - } - object = talloc(c, struct content_html_object); if (object == NULL) { - nsurl_unref(object_url); return false; } @@ -1424,19 +1416,16 @@ bool html_fetch_object(html_content *c, const char *url, struct box *box, object->permitted_types = permitted_types; object->background = background; - error = hlcache_handle_retrieve(object_url, + error = hlcache_handle_retrieve(url, HLCACHE_RETRIEVE_SNIFF_TYPE, content__get_url(&c->base), NULL, html_object_callback, object, &child, object->permitted_types, &object->content); if (error != NSERROR_OK) { talloc_free(object); - nsurl_unref(object_url); return error != NSERROR_NOMEM; } - nsurl_unref(object_url); - /* add to content object list */ object->next = c->object_list; c->object_list = object; diff --git a/render/html_internal.h b/render/html_internal.h index 0c0b5fee5..83547401c 100644 --- a/render/html_internal.h +++ b/render/html_internal.h @@ -105,7 +105,7 @@ typedef struct html_content { } html_content; -bool html_fetch_object(html_content *c, const char *url, struct box *box, +bool html_fetch_object(html_content *c, nsurl *url, struct box *box, content_type permitted_types, int available_width, int available_height, bool background); -- cgit v1.2.3