Port more internals to nsurl. Front ends may need updating.

svn path=/trunk/netsurf/; revision=12926
This commit is contained in:
Michael Drake 2011-10-03 15:56:47 +00:00
parent a595d7c4bb
commit 36eff6da2b
33 changed files with 352 additions and 296 deletions

View File

@ -785,17 +785,17 @@ lwc_string *content__get_mime_type(struct content *c)
* \param c Content to retrieve URL from
* \return Pointer to URL, or NULL if not found.
*/
const char *content_get_url(hlcache_handle *h)
nsurl *content_get_url(hlcache_handle *h)
{
return content__get_url(hlcache_handle_get_content(h));
}
const char *content__get_url(struct content *c)
nsurl *content__get_url(struct content *c)
{
if (c == NULL)
return NULL;
return nsurl_access(llcache_handle_get_url(c->llcache));
return llcache_handle_get_url(c->llcache);
}
/**
@ -970,12 +970,12 @@ void content__invalidate_reuse_data(struct content *c)
* \param c Content to retrieve refresh URL from
* \return Pointer to URL, or NULL if none
*/
const char *content_get_refresh_url(hlcache_handle *h)
nsurl *content_get_refresh_url(hlcache_handle *h)
{
return content__get_refresh_url(hlcache_handle_get_content(h));
}
const char *content__get_refresh_url(struct content *c)
nsurl *content__get_refresh_url(struct content *c)
{
if (c == NULL)
return NULL;
@ -1159,7 +1159,7 @@ nserror content__clone(const struct content *c, struct content *nc)
}
if (c->refresh != NULL) {
nc->refresh = talloc_strdup(nc, c->refresh);
nc->refresh = nsurl_ref(c->refresh);
if (nc->refresh == NULL) {
return NSERROR_NOMEM;
}

View File

@ -33,6 +33,7 @@
#include "utils/config.h"
#include "utils/errors.h"
#include "utils/http.h"
#include "utils/nsurl.h"
#include "utils/types.h"
#include "content/content_factory.h"
#include "content/content_type.h"
@ -164,7 +165,7 @@ void content_get_contextual_content(struct hlcache_handle *h,
/* Member accessors */
content_type content_get_type(struct hlcache_handle *c);
lwc_string *content_get_mime_type(struct hlcache_handle *c);
const char *content_get_url(struct hlcache_handle *c);
nsurl *content_get_url(struct hlcache_handle *c);
const char *content_get_title(struct hlcache_handle *c);
content_status content_get_status(struct hlcache_handle *c);
const char *content_get_status_message(struct hlcache_handle *c);
@ -174,7 +175,7 @@ int content_get_available_width(struct hlcache_handle *c);
const char *content_get_source_data(struct hlcache_handle *c,
unsigned long *size);
void content_invalidate_reuse_data(struct hlcache_handle *c);
const char *content_get_refresh_url(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);

View File

@ -106,8 +106,7 @@ struct content {
bool quirks; /**< Content is in quirks mode */
char *fallback_charset; /**< Fallback charset, or NULL */
/** URL for refresh request, in standard form as from url_join. */
char *refresh;
nsurl *refresh; /**< URL for refresh request */
unsigned int time; /**< Creation time,
if LOADING or READY,
@ -169,7 +168,7 @@ void content__request_redraw(struct content *c,
bool content__set_title(struct content *c, const char *title);
lwc_string *content__get_mime_type(struct content *c);
const char *content__get_url(struct content *c);
nsurl *content__get_url(struct content *c);
const char *content__get_title(struct content *c);
const char *content__get_status_message(struct content *c);
int content__get_width(struct content *c);
@ -177,7 +176,7 @@ int content__get_height(struct content *c);
int content__get_available_width(struct content *c);
const char *content__get_source_data(struct content *c, unsigned long *size);
void content__invalidate_reuse_data(struct content *c);
const char *content__get_refresh_url(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);

View File

@ -41,6 +41,7 @@
#include "content/fetch.h"
#include "content/fetchers/resource.h"
#include "content/urldb.h"
#include "desktop/gui.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
#include "utils/log.h"

View File

@ -37,17 +37,4 @@
*/
void fetch_resource_register(void);
/**
* Callback to translate resource to full url.
*
* Transforms a resource: filename into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
* the returned string including freeing it when finished with it.
*
* \param filename The filename of the resource to locate.
* \return A string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
char* gui_get_resource_url(const char *filename);
#endif

View File

@ -225,16 +225,14 @@ nserror hlcache_poll(void)
}
/* See hlcache.h for documentation */
nserror hlcache_handle_retrieve(const char *url, uint32_t flags,
const char *referer, llcache_post_data *post,
nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags,
nsurl *referer, llcache_post_data *post,
hlcache_handle_callback cb, void *pw,
hlcache_child_context *child,
content_type accepted_types, hlcache_handle **result)
{
hlcache_retrieval_ctx *ctx;
nserror error;
nsurl *nsref = NULL;
nsurl *nsurl;
assert(cb != NULL);
@ -266,42 +264,16 @@ nserror hlcache_handle_retrieve(const char *url, uint32_t flags,
ctx->handle->cb = cb;
ctx->handle->pw = pw;
error = nsurl_create(url, &nsurl);
if (error != NSERROR_OK) {
free((char *) ctx->child.charset);
free(ctx->handle);
free(ctx);
return error;
}
if (referer != NULL) {
error = nsurl_create(referer, &nsref);
if (error != NSERROR_OK) {
free((char *) ctx->child.charset);
free(ctx->handle);
free(ctx);
nsurl_unref(nsurl);
return error;
}
}
error = llcache_handle_retrieve(nsurl, flags, nsref, post,
error = llcache_handle_retrieve(url, flags, referer, post,
hlcache_llcache_callback, ctx,
&ctx->llcache);
if (error != NSERROR_OK) {
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
free((char *) ctx->child.charset);
free(ctx->handle);
free(ctx);
return error;
}
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
RING_INSERT(hlcache->retrieval_ctx_ring, ctx);
*result = ctx->handle;

View File

@ -129,8 +129,8 @@ nserror hlcache_poll(void);
*
* \todo Is there any way to sensibly reduce the number of parameters here?
*/
nserror hlcache_handle_retrieve(const char *url, uint32_t flags,
const char *referer, llcache_post_data *post,
nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags,
nsurl *referer, llcache_post_data *post,
hlcache_handle_callback cb, void *pw,
hlcache_child_context *child,
content_type accepted_types, hlcache_handle **result);

View File

@ -173,7 +173,7 @@ nserror nscss_create(const content_handler *handler,
}
error = nscss_create_css_data(&result->data,
content__get_url(&result->base),
nsurl_access(content__get_url(&result->base)),
charset, result->base.quirks,
nscss_content_done, result);
if (error != NSERROR_OK) {
@ -401,7 +401,7 @@ nserror nscss_clone(const struct content *old, struct content **newc)
/* Simply replay create/process/convert */
error = nscss_create_css_data(&new_css->data,
content__get_url(&new_css->base),
nsurl_access(content__get_url(&new_css->base)),
old_css->data.charset,
new_css->base.quirks,
nscss_content_done, new_css);
@ -550,6 +550,9 @@ css_error nscss_handle_import(void *pw, css_stylesheet *parent,
css_error error;
nserror nerror;
nsurl *ns_url;
nsurl *ns_ref;
assert(parent == c->sheet);
error = css_stylesheet_get_url(c->sheet, &referer);
@ -584,15 +587,30 @@ css_error nscss_handle_import(void *pw, css_stylesheet *parent,
/* Create content */
c->imports[c->import_count].media = media;
/* TODO: Why aren't we getting a relative url part, to join? */
nerror = nsurl_create(lwc_string_data(url), &ns_url);
if (nerror != NSERROR_OK) {
free(ctx);
return CSS_NOMEM;
}
/* TODO: Constructing nsurl for referer here is silly, avoid */
nerror = nsurl_create(referer, &ns_ref);
if (nerror != NSERROR_OK) {
nsurl_unref(ns_url);
free(ctx);
return CSS_NOMEM;
}
/* Avoid importing ourself */
if (strcmp(lwc_string_data(url), referer) == 0) {
if (nsurl_compare(ns_url, ns_ref, NSURL_COMPLETE)) {
c->imports[c->import_count].c = NULL;
/* No longer require context as we're not fetching anything */
free(ctx);
ctx = NULL;
} else {
nerror = hlcache_handle_retrieve(lwc_string_data(url),
0, referer, NULL, nscss_import, ctx,
nerror = hlcache_handle_retrieve(ns_url,
0, ns_ref, NULL, nscss_import, ctx,
&child, accept,
&c->imports[c->import_count].c);
if (nerror != NSERROR_OK) {
@ -601,6 +619,9 @@ css_error nscss_handle_import(void *pw, css_stylesheet *parent,
}
}
nsurl_unref(ns_url);
nsurl_unref(ns_ref);
#ifdef NSCSS_IMPORT_TRACE
LOG(("Import %d '%s' -> (handle: %p ctx: %p)",
c->import_count, lwc_string_data(url),

View File

@ -20,7 +20,7 @@
#include "css/internal.h"
#include "utils/url.h"
#include "utils/nsurl.h"
/**
* URL resolution callback for libcss
@ -37,33 +37,36 @@ css_error nscss_resolve_url(void *pw, const char *base,
lwc_string *rel, lwc_string **abs)
{
lwc_error lerror;
char *abs_url, *norm_url;
url_func_result res;
nserror error;
nsurl *nsbase;
nsurl *nsabs;
/* Create nsurl from base */
/* TODO: avoid this */
error = nsurl_create(base, &nsbase);
if (error != NSERROR_OK) {
return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID;
}
/* Resolve URI */
res = url_join(lwc_string_data(rel), base, &abs_url);
if (res != URL_FUNC_OK) {
return res == URL_FUNC_NOMEM ? CSS_NOMEM : CSS_INVALID;
error = nsurl_join(nsbase, lwc_string_data(rel), &nsabs);
if (error != NSERROR_OK) {
nsurl_unref(nsbase);
return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID;
}
/* Normalise it */
res = url_normalize(abs_url, &norm_url);
if (res != URL_FUNC_OK) {
free(abs_url);
return res == URL_FUNC_NOMEM ? CSS_NOMEM : CSS_INVALID;
}
free(abs_url);
nsurl_unref(nsbase);
/* Intern it */
lerror = lwc_intern_string(norm_url, strlen(norm_url), abs);
lerror = lwc_intern_string(nsurl_access(nsabs),
strlen(nsurl_access(nsabs)), abs);
if (lerror != lwc_error_ok) {
*abs = NULL;
free(norm_url);
nsurl_unref(nsabs);
return lerror == lwc_error_oom ? CSS_NOMEM : CSS_INVALID;
}
free(norm_url);
nsurl_unref(nsabs);
return CSS_OK;
}

View File

@ -1639,7 +1639,8 @@ css_error node_presentational_hint(void *pw, void *node,
return CSS_PROPERTY_NOT_SET;
res = url_join((const char *) bg, ctx->base_url, &url);
res = url_join((const char *) bg, nsurl_access(ctx->base_url),
&url);
xmlFree(bg);

View File

@ -24,6 +24,7 @@
#include <libxml/tree.h>
#include "css/css.h"
#include "utils/nsurl.h"
struct content;
@ -34,7 +35,7 @@ typedef struct nscss_select_ctx
{
css_select_ctx *ctx;
bool quirks;
const char *base_url;
nsurl *base_url;
} nscss_select_ctx;
css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,

View File

@ -703,9 +703,6 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
bool verifiable, hlcache_handle *parent)
{
hlcache_handle *c;
char *url2;
char *fragment;
url_func_result res;
int depth = 0;
struct browser_window *cur;
uint32_t fetch_flags = 0;
@ -714,6 +711,9 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
hlcache_child_context child;
nserror error;
nsurl *nsref = NULL;
nsurl *nsurl;
LOG(("bw %p, url %s", bw, url));
assert(bw);
assert(url);
@ -743,33 +743,22 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
child.quirks = content_get_quirks(parent);
}
/* Normalize the request URL */
res = url_normalize(url, &url2);
if (res != URL_FUNC_OK) {
LOG(("failed to normalize url %s", url));
error = nsurl_create(url, &nsurl);
if (error != NSERROR_OK) {
return;
}
if (referer != NULL) {
error = nsurl_create(referer, &nsref);
if (error != NSERROR_OK) {
nsurl_unref(nsurl);
return;
}
}
/* Get download out of the way */
if (download) {
llcache_handle *l;
nsurl *nsref = NULL;
nsurl *nsurl;
error = nsurl_create(url2, &nsurl);
if (error != NSERROR_OK) {
free(url2);
return;
}
if (referer != NULL) {
error = nsurl_create(referer, &nsref);
if (error != NSERROR_OK) {
free(url2);
nsurl_unref(nsurl);
return;
}
}
fetch_flags |= LLCACHE_RETRIEVE_FORCE_FETCH;
fetch_flags |= LLCACHE_RETRIEVE_STREAM_DATA;
@ -778,7 +767,7 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
fetch_is_post ? &post : NULL,
NULL, NULL, &l);
if (error == NSERROR_NO_FETCH_HANDLER) {
gui_launch_url(url2);
gui_launch_url(nsurl_access(nsurl));
} else if (error != NSERROR_OK) {
LOG(("Failed to fetch download: %d", error));
} else {
@ -791,7 +780,6 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
}
}
free(url2);
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
@ -802,37 +790,40 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
free(bw->frag_id);
bw->frag_id = NULL;
/* find any fragment identifier on end of URL */
res = url_fragment(url2, &fragment);
if (res == URL_FUNC_NOMEM) {
free(url2);
warn_user("NoMemory", 0);
return;
} else if (res == URL_FUNC_OK) {
if (nsurl_enquire(nsurl, NSURL_FRAGMENT)) {
lwc_string *lwc_frag;
bool same_url = false;
bw->frag_id = fragment;
lwc_frag = nsurl_get_component(nsurl, NSURL_FRAGMENT);
bw->frag_id = strdup(lwc_string_data(lwc_frag));
if (bw->frag_id == NULL) {
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
lwc_string_unref(lwc_frag);
warn_user("NoMemory", 0);
return;
}
lwc_string_unref(lwc_frag);
/* Compare new URL with existing one (ignoring fragments) */
if (bw->current_content != NULL &&
content_get_url(bw->current_content) != NULL) {
res = url_compare(content_get_url(bw->current_content),
url2, true, &same_url);
if (res == URL_FUNC_NOMEM) {
free(url2);
warn_user("NoMemory", 0);
return;
} else if (res == URL_FUNC_FAILED) {
same_url = false;
}
same_url = nsurl_compare(nsurl,
content_get_url(bw->current_content),
NSURL_COMPLETE);
}
/* if we're simply moving to another ID on the same page,
* don't bother to fetch, just update the window.
*/
if (same_url && fetch_is_post == false &&
strchr(url2, '?') == 0) {
free(url2);
nsurl_enquire(nsurl, NSURL_QUERY) == false) {
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
if (add_to_history)
history_add(bw->history, bw->current_content,
bw->frag_id);
@ -850,35 +841,41 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
browser_window_remove_caret(bw);
browser_window_destroy_children(bw);
LOG(("Loading '%s'", url2));
LOG(("Loading '%s'", nsurl_access(nsurl)));
browser_window_set_status(bw, messages_get("Loading"));
bw->history_add = add_to_history;
error = hlcache_handle_retrieve(url2,
error = hlcache_handle_retrieve(nsurl,
fetch_flags | HLCACHE_RETRIEVE_MAY_DOWNLOAD |
HLCACHE_RETRIEVE_SNIFF_TYPE,
referer,
nsref,
fetch_is_post ? &post : NULL,
browser_window_callback, bw,
parent != NULL ? &child : NULL,
CONTENT_ANY, &c);
if (error == NSERROR_NO_FETCH_HANDLER) {
gui_launch_url(url2);
free(url2);
gui_launch_url(nsurl_access(nsurl));
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
return;
} else if (error != NSERROR_OK) {
free(url2);
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
browser_window_set_status(bw, messages_get("NoMemory"));
warn_user("NoMemory", 0);
return;
}
free(url2);
bw->loading_content = c;
browser_window_start_throbber(bw);
browser_window_refresh_url_bar(bw, url, NULL);
browser_window_refresh_url_bar(bw, nsurl, NULL);
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
}
@ -898,8 +895,8 @@ nserror browser_window_callback(hlcache_handle *c,
browser_window_convert_to_download(bw, event->data.download);
if (bw->current_content != NULL) {
browser_window_refresh_url_bar(bw,
content_get_url(bw->current_content),
browser_window_refresh_url_bar(bw, content_get_url(
bw->current_content),
bw->frag_id);
}
break;
@ -961,7 +958,7 @@ nserror browser_window_callback(hlcache_handle *c,
/* history */
if (bw->history_add && bw->history) {
const char *url = content_get_url(c);
const char *url = nsurl_access(content_get_url(c));
history_add(bw->history, c, bw->frag_id);
if (urldb_add_url(url)) {
@ -1192,14 +1189,14 @@ void browser_window_refresh(void *p)
/* Ignore if the refresh URL has gone
* (may happen if a fetch error occurred) */
refresh = content_get_refresh_url(bw->current_content);
refresh = nsurl_access(content_get_refresh_url(bw->current_content));
if (refresh == NULL)
return;
/* mark this content as invalid so it gets flushed from the cache */
content_invalidate_reuse_data(bw->current_content);
url = content_get_url(bw->current_content);
url = nsurl_access(content_get_url(bw->current_content));
if (url != NULL && strcmp(url, refresh) == 0)
history_add = false;
@ -1448,7 +1445,8 @@ void browser_window_stop(struct browser_window *bw)
if (bw->current_content != NULL) {
browser_window_refresh_url_bar(bw,
content_get_url(bw->current_content), bw->frag_id);
content_get_url(bw->current_content),
bw->frag_id);
}
browser_window_stop_throbber(bw);
@ -1499,7 +1497,8 @@ void browser_window_reload(struct browser_window *bw, bool all)
content_invalidate_reuse_data(bw->current_content);
browser_window_go(bw, content_get_url(bw->current_content), 0, false);
browser_window_go(bw, nsurl_access(
content_get_url(bw->current_content)), 0, false);
}
@ -1772,7 +1771,7 @@ void browser_window_set_scale_internal(struct browser_window *bw, float scale)
* \param frag Additional fragment. May be NULL if none.
*/
void browser_window_refresh_url_bar(struct browser_window *bw, const char *url,
void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url,
const char *frag)
{
char *url_buf;
@ -1789,15 +1788,15 @@ void browser_window_refresh_url_bar(struct browser_window *bw, const char *url,
/* With no fragment, we may as well pass url straight through
* saving a malloc, copy, free cycle.
*/
gui_window_set_url(bw->window, url);
gui_window_set_url(bw->window, nsurl_access(url));
} else {
url_buf = malloc(strlen(url) + 1 /* # */ +
url_buf = malloc(strlen(nsurl_access(url)) + 1 /* # */ +
strlen(frag) + 1 /* \0 */);
if (url_buf != NULL) {
/* This sprintf is safe because of the above size
* calculation, thus we don't need snprintf
*/
sprintf(url_buf, "%s#%s", url, frag);
sprintf(url_buf, "%s#%s", nsurl_access(url), frag);
gui_window_set_url(bw->window, url_buf);
free(url_buf);
} else {

View File

@ -242,7 +242,7 @@ void browser_window_set_scale(struct browser_window *bw, float scale, bool all);
void browser_window_get_contextual_content(struct browser_window *bw,
int x, int y, struct contextual_content *data);
void browser_window_refresh_url_bar(struct browser_window *bw, const char *url,
void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url,
const char *frag);
void browser_window_mouse_click(struct browser_window *bw,

View File

@ -243,7 +243,8 @@ void browser_window_create_iframes(struct browser_window *bw,
if (cur->url) {
/* fetch iframe's content */
browser_window_go_unverifiable(window, cur->url,
content_get_url(bw->current_content),
nsurl_access(content_get_url(
bw->current_content)),
false, bw->current_content);
}
}
@ -376,7 +377,8 @@ void browser_window_create_frameset(struct browser_window *bw,
if (frame->url) {
browser_window_go_unverifiable(window,
frame->url,
content_get_url(parent),
nsurl_access(content_get_url(
parent)),
true,
parent);
}

View File

@ -136,6 +136,19 @@ void gui_cert_verify(const char *url, const struct ssl_cert_info *certs,
unsigned long num, nserror (*cb)(bool proceed, void *pw),
void *cbpw);
/**
* Callback to translate resource to full url.
*
* Transforms a resource: filename into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
* the returned nsurl including unrefing it when finished with it.
*
* \param filename The filename of the resource to locate.
* \return A string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
char* gui_get_resource_url(const char *filename);
/** css callback to obtain named system colours from a frontend. */
css_error gui_system_colour(void *pw, lwc_string *name, css_color *color);

View File

@ -226,11 +226,12 @@ struct history_entry *history_clone_entry(struct history *history,
void history_add(struct history *history, hlcache_handle *content,
char *frag_id)
{
url_func_result res;
struct history_entry *entry;
char *url;
char *title;
struct bitmap *bitmap;
nserror error;
size_t url_len;
assert(history);
assert(content);
@ -240,8 +241,10 @@ void history_add(struct history *history, hlcache_handle *content,
if (entry == NULL)
return;
res = url_normalize(content_get_url(content), &url);
if (res != URL_FUNC_OK) {
/* TODO: use a nsurl? */
error = nsurl_get(content_get_url(content), NSURL_WITH_FRAGMENT,
&url, &url_len);
if (error != NSERROR_OK) {
warn_user("NoMemory", 0);
free(entry);
return;

View File

@ -227,7 +227,8 @@ static void hotlist_visited_internal(hlcache_handle *content, struct node *node)
hotlist_tree == NULL)
return;
url = content_get_url(content);
/* TODO: do this with a nsurl instead */
url = nsurl_access(content_get_url(content));
for (; node; node = tree_node_get_next(node)) {
if (!tree_node_is_folder(node)) {

View File

@ -171,7 +171,7 @@ bool save_complete_html(hlcache_handle *c, const char *path, bool index,
css_data = content_get_source_data(css, &css_size);
source = rewrite_stylesheet_urls(css_data, css_size,
&source_len, content_get_url(css),
&source_len, nsurl_access(content_get_url(css)),
*list);
if (!source) {
warn_user("NoMemory", 0);
@ -250,7 +250,8 @@ bool save_complete_html(hlcache_handle *c, const char *path, bool index,
}
/* rewrite all urls we know about */
if (!rewrite_document_urls(doc, html_get_base_url(c), *list)) {
if (!rewrite_document_urls(doc, nsurl_access(html_get_base_url(c)),
*list)) {
xmlFreeDoc(doc);
warn_user("NoMemory", 0);
return false;
@ -324,7 +325,7 @@ bool save_imported_sheets(struct nscss_import *imports, uint32_t count,
css_data = content_get_source_data(css, &css_size);
source = rewrite_stylesheet_urls(css_data, css_size,
&source_len, content_get_url(css),
&source_len, nsurl_access(content_get_url(css)),
*list);
if (!source) {
warn_user("NoMemory", 0);
@ -745,7 +746,8 @@ hlcache_handle * save_complete_list_find(const char *url,
{
struct save_complete_entry *entry;
for (entry = list; entry; entry = entry->next)
if (strcmp(url, content_get_url(entry->content)) == 0)
if (strcmp(url, nsurl_access(
content_get_url(entry->content))) == 0)
return entry->content;
return 0;
}
@ -811,7 +813,7 @@ bool save_complete_inventory(const char *path,
for (entry = list; entry; entry = entry->next) {
fprintf(fp, "%p %s\n", entry->content,
content_get_url(entry->content));
nsurl_access(content_get_url(entry->content)));
}
fclose(fp);

View File

@ -212,6 +212,7 @@ void search_web_retrieve_ico(bool localdefault)
content_type accept = CONTENT_IMAGE;
char *url;
nserror error;
nsurl *icon_nsurl;
if (localdefault) {
if (search_default_ico_location == NULL)
@ -233,9 +234,19 @@ void search_web_retrieve_ico(bool localdefault)
return;
}
error = hlcache_handle_retrieve(url, 0, NULL, NULL,
error = nsurl_create(url, &icon_nsurl);
if (error != NSERROR_OK) {
free(url);
search_ico = NULL;
return;
}
error = hlcache_handle_retrieve(icon_nsurl, 0, NULL, NULL,
search_web_ico_callback, NULL, NULL, accept,
&search_ico);
nsurl_unref(icon_nsurl);
if (error != NSERROR_OK)
search_ico = NULL;
@ -280,13 +291,14 @@ nserror search_web_ico_callback(hlcache_handle *ico,
break;
case CONTENT_MSG_DONE:
LOG(("got favicon '%s'", content_get_url(ico)));
LOG(("got favicon '%s'", nsurl_access(content_get_url(ico))));
gui_window_set_search_ico(search_ico);
break;
case CONTENT_MSG_ERROR:
LOG(("favicon %s error: %s",
content_get_url(ico), event->data.error));
nsurl_access(content_get_url(ico)),
event->data.error));
hlcache_handle_release(search_ico);
search_ico = NULL;
search_web_retrieve_ico(true);

View File

@ -2807,6 +2807,7 @@ hlcache_handle *tree_load_icon(const char *name)
int len;
hlcache_handle *c;
nserror err;
nsurl *icon_nsurl;
/** @todo something like bitmap_from_disc is needed here */
@ -2839,11 +2840,19 @@ hlcache_handle *tree_load_icon(const char *name)
icon_url = url;
}
err = nsurl_create(icon_url, &icon_nsurl);
if (err != NSERROR_OK) {
if (url != NULL)
free(url);
return NULL;
}
/* Fetch the icon */
err = hlcache_handle_retrieve(icon_url, 0, 0, 0,
err = hlcache_handle_retrieve(icon_nsurl, 0, 0, 0,
tree_icon_callback, 0, 0,
CONTENT_IMAGE, &c);
nsurl_unref(icon_nsurl);
/* If we built the URL here, free it */
if (url != NULL)

View File

@ -28,7 +28,7 @@
#include "utils/filepath.h"
#include "utils/log.h"
#include "utils/url.h"
#include "content/fetchers/resource.h"
#include "desktop/gui.h"
#include "framebuffer/findfile.h"

View File

@ -579,7 +579,8 @@ ENTRY_CHANGED(entryHomePageURL, option_homepage_url)
END_HANDLER
BUTTON_CLICKED(setCurrentPage)
const gchar *url = content_get_url(current_browser->current_content);
const gchar *url = nsurl_access(content_get_url(
current_browser->current_content));
gtk_entry_set_text(GTK_ENTRY(entryHomePageURL), url);
option_homepage_url =
strdup(gtk_entry_get_text(GTK_ENTRY(entryHomePageURL)));

View File

@ -166,7 +166,8 @@ void nsgtk_source_dialog_init(GtkWindow *parent, struct browser_window *bw)
return;
}
thiswindow->url = strdup(content_get_url(bw->current_content));
thiswindow->url = strdup(nsurl_access(content_get_url(
bw->current_content)));
if (thiswindow->url == NULL) {
free(thiswindow);
free(data);

View File

@ -619,8 +619,8 @@ MULTIHANDLER(savepage)
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fc), filter);
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fc), filter);
res = url_nice(content_get_url(nsgtk_get_browser_window(
g->top_level)->current_content), &path, false);
res = url_nice(nsurl_access(content_get_url(nsgtk_get_browser_window(
g->top_level)->current_content)), &path, false);
if (res != URL_FUNC_OK) {
path = strdup(messages_get("SaveText"));
if (path == NULL) {
@ -680,7 +680,8 @@ MULTIHANDLER(pdf)
LOG(("Print preview (generating PDF) started."));
res = url_nice(content_get_url(bw->current_content), &url_name, true);
res = url_nice(nsurl_access(content_get_url(bw->current_content)),
&url_name, true);
if (res != URL_FUNC_OK) {
warn_user(messages_get(res == URL_FUNC_NOMEM ? "NoMemory"
: "URIError"), 0);
@ -754,8 +755,8 @@ MULTIHANDLER(plaintext)
char *filename;
url_func_result res;
res = url_nice(content_get_url(nsgtk_get_browser_window(
g->top_level)->current_content), &filename, false);
res = url_nice(nsurl_access(content_get_url(nsgtk_get_browser_window(
g->top_level)->current_content)), &filename, false);
if (res != URL_FUNC_OK) {
filename = strdup(messages_get("SaveText"));
if (filename == NULL) {
@ -1407,7 +1408,7 @@ MULTIHANDLER(addbookmarks)
if (bw == NULL || bw->current_content == NULL ||
content_get_url(bw->current_content) == NULL)
return TRUE;
hotlist_add_page(content_get_url(bw->current_content));
hotlist_add_page(nsurl_access(content_get_url(bw->current_content)));
return TRUE;
}

View File

@ -132,7 +132,8 @@ static void svg_reformat(struct content *c, int width, int height)
source_data = content__get_source_data(c, &source_size);
svgtiny_parse(svg->diagram, source_data, source_size,
content__get_url(c), width, height);
nsurl_access(content__get_url(c)),
width, height);
svg->done_parse = true;
}

View File

@ -72,11 +72,10 @@ void *box_style_alloc(void *ptr, size_t len, void *pw)
/**
* Destructor for box nodes which own styles
*
* @param b The box being destroyed.
* @return 0 to allow talloc to continue destroying the tree.
* \param b The box being destroyed.
* \return 0 to allow talloc to continue destroying the tree.
*/
static int
free_box_style(struct box *b)
static int box_talloc_destructor(struct box *b)
{
if ((b->flags & STYLE_OWNED) && b->style != NULL) {
css_computed_style_destroy(b->style);
@ -119,10 +118,9 @@ struct box * box_create(css_select_results *styles, css_computed_style *style,
if (!box) {
return 0;
}
if (style_owned == true || styles != NULL)
talloc_set_destructor(box, free_box_style);
talloc_set_destructor(box, box_talloc_destructor);
box->type = BOX_INLINE;
box->flags = 0;
box->flags = style_owned ? (box->flags | STYLE_OWNED) : box->flags;
@ -935,7 +933,7 @@ void box_dump(FILE *stream, struct box *box, unsigned int depth)
fprintf(stream, "space ");
if (box->object) {
fprintf(stream, "(object '%s') ",
content_get_url(box->object));
nsurl_access(content_get_url(box->object)));
}
if (box->iframe) {
fprintf(stream, "(iframe) ");

View File

@ -1049,7 +1049,8 @@ css_select_results *box_get_style(html_content *c,
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "style"))) {
inline_style = nscss_create_inline_style(
(uint8_t *) s, strlen(s),
c->encoding, content__get_url(&c->base),
c->encoding,
nsurl_access(content__get_url(&c->base)),
c->quirks != BINDING_QUIRKS_MODE_NONE,
box_style_alloc, NULL);
@ -1232,7 +1233,7 @@ bool box_a(BOX_SPECIAL_PARAMS)
if ((s = xmlGetProp(n, (const xmlChar *) "href"))) {
ok = box_extract_link((const char *) s,
content->base_url, &url);
nsurl_access(content->base_url), &url);
xmlFree(s);
if (!ok)
return false;
@ -1317,7 +1318,8 @@ bool box_image(BOX_SPECIAL_PARAMS)
/* get image URL */
if (!(src = xmlGetProp(n, (const xmlChar *) "src")))
return true;
if (!box_extract_link((char *) src, content->base_url, &url))
if (!box_extract_link((char *) src, nsurl_access(content->base_url),
&url))
return false;
xmlFree(src);
if (!url)
@ -1376,13 +1378,16 @@ bool box_object(BOX_SPECIAL_PARAMS)
* (codebase is the base for the other two) */
if ((codebase = xmlGetProp(n, (const xmlChar *) "codebase"))) {
if (!box_extract_link((char *) codebase,
content->base_url,
nsurl_access(content->base_url),
&params->codebase))
return false;
xmlFree(codebase);
}
if (!params->codebase)
params->codebase = content->base_url;
params->codebase = strdup(nsurl_access(content->base_url));
if (!params->codebase)
return false;
if ((classid = xmlGetProp(n, (const xmlChar *) "classid"))) {
if (!box_extract_link((char *) classid, params->codebase,
@ -1403,10 +1408,12 @@ bool box_object(BOX_SPECIAL_PARAMS)
return true;
/* Don't include ourself */
if (params->classid && strcmp(content->base_url, params->classid) == 0)
if (params->classid && strcmp(nsurl_access(content->base_url),
params->classid) == 0)
return true;
if (params->data && strcmp(content->base_url, params->data) == 0)
if (params->data && strcmp(nsurl_access(content->base_url),
params->data) == 0)
return true;
/* codetype and type are MIME types */
@ -1658,14 +1665,17 @@ bool box_create_frameset(struct content_html_frames *f, xmlNode *n,
url = NULL;
if ((s = (char *) xmlGetProp(c,
(const xmlChar *) "src"))) {
box_extract_link(s, content->base_url, &url);
box_extract_link(s,
nsurl_access(content->base_url),
&url);
xmlFree(s);
}
/* copy url */
if (url) {
/* no self-references */
if (strcmp(content->base_url, url))
if (strcmp(nsurl_access(content->base_url),
url))
frame->url = talloc_strdup(content,
url);
free(url);
@ -1750,7 +1760,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS)
if (!(s = (char *) xmlGetProp(n,
(const xmlChar *) "src")))
return true;
if (!box_extract_link(s, content->base_url, &url)) {
if (!box_extract_link(s, nsurl_access(content->base_url), &url)) {
xmlFree(s);
return false;
}
@ -1759,7 +1769,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS)
return true;
/* don't include ourself */
if (strcmp(content->base_url, url) == 0) {
if (strcmp(nsurl_access(content->base_url), url) == 0) {
free(url);
return true;
}
@ -1907,7 +1917,9 @@ bool box_input(BOX_SPECIAL_PARAMS)
n->parent == NULL) != CSS_DISPLAY_NONE) {
if ((s = (char *) xmlGetProp(n,
(const xmlChar*) "src"))) {
res = url_join(s, content->base_url, &url);
res = url_join(s,
nsurl_access(content->base_url),
&url);
xmlFree(s);
/* if url is equivalent to the parent's url,
* we've got infinite inclusion. stop it here
@ -1915,7 +1927,8 @@ bool box_input(BOX_SPECIAL_PARAMS)
*/
if (res == URL_FUNC_OK &&
strcasecmp(url,
content->base_url) != 0) {
nsurl_access(
content->base_url)) != 0) {
if (!html_fetch_object(content, url,
box, image_types,
content->base.
@ -2302,14 +2315,15 @@ bool box_embed(BOX_SPECIAL_PARAMS)
/* src is a URL */
if (!(src = xmlGetProp(n, (const xmlChar *) "src")))
return true;
if (!box_extract_link((char *) src, content->base_url, &params->data))
if (!box_extract_link((char *) src, nsurl_access(content->base_url),
&params->data))
return false;
xmlFree(src);
if (!params->data)
return true;
/* Don't include ourself */
if (strcmp(content->base_url, params->data) == 0)
if (strcmp(nsurl_access(content->base_url), params->data) == 0)
return true;
/* add attributes as parameters to linked list */

View File

@ -1500,7 +1500,8 @@ void form_submit(hlcache_handle *h, struct browser_window *target,
url_destroy_components(&components);
browser_window_go(target, url, content_get_url(h), true);
browser_window_go(target, url, nsurl_access(content_get_url(h)),
true);
break;
case method_POST_URLENC:
@ -1512,13 +1513,13 @@ void form_submit(hlcache_handle *h, struct browser_window *target,
}
browser_window_go_post(target, form->action, data, 0,
true, content_get_url(h),
true, nsurl_access(content_get_url(h)),
false, true, 0);
break;
case method_POST_MULTIPART:
browser_window_go_post(target, form->action, 0,
success, true, content_get_url(h),
success, true, nsurl_access(content_get_url(h)),
false, true, 0);
break;
}

View File

@ -94,7 +94,7 @@ static bool html_process_style_element(html_content *c, unsigned int *index,
static void html_inline_style_done(struct content_css_data *css, void *pw);
static bool html_fetch_objects(html_content *c);
static bool html_replace_object(struct content_html_object *object,
const char *url);
nsurl *url);
static nserror html_object_callback(hlcache_handle *object,
const hlcache_event *event, void *pw);
static void html_object_done(struct box *box, hlcache_handle *object,
@ -233,7 +233,7 @@ nserror html_create_html_data(html_content *c, const http_parameter *params)
c->document = NULL;
c->quirks = BINDING_QUIRKS_MODE_NONE;
c->encoding = NULL;
c->base_url = (char *) content__get_url(&c->base);
c->base_url = nsurl_ref(content__get_url(&c->base));
c->base_target = NULL;
c->aborted = false;
c->layout = NULL;
@ -527,10 +527,11 @@ bool html_convert(struct content *c)
/* Make all actions absolute */
if (f->action == NULL || f->action[0] == '\0') {
/* HTML5 4.10.22.3 step 11 */
res = url_join(content__get_url(c),
htmlc->base_url, &action);
res = url_join(nsurl_access(content__get_url(c)),
nsurl_access(htmlc->base_url), &action);
} else {
res = url_join(f->action, htmlc->base_url, &action);
res = url_join(f->action, nsurl_access(htmlc->base_url),
&action);
}
if (res != URL_FUNC_OK) {
@ -749,12 +750,13 @@ bool html_head(html_content *c, xmlNode *head)
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) {
c->base_url = talloc_strdup(c, url);
free(url);
nsurl *url;
nserror error;
error = nsurl_create(href, &url);
if (error == NSERROR_OK) {
if (c->base_url != NULL)
nsurl_unref(c->base_url);
c->base_url = url;
}
xmlFree(href);
}
@ -800,7 +802,8 @@ bool html_meta_refresh(html_content *c, xmlNode *head)
xmlChar *equiv, *content;
union content_msg_data msg_data;
char *url, *end, *refresh = NULL, quote = 0;
url_func_result res;
nsurl *nsurl;
nserror error;
for (n = head == 0 ? 0 : head->children; n; n = n->next) {
if (n->type != XML_ELEMENT_NODE)
@ -881,14 +884,8 @@ bool html_meta_refresh(html_content *c, xmlNode *head)
/* Just delay specified, so refresh current page */
xmlFree(content);
c->base.refresh = talloc_strdup(c,
c->base.refresh = nsurl_ref(
content__get_url(&c->base));
if (!c->base.refresh) {
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base,
CONTENT_MSG_ERROR, msg_data);
return false;
}
content_broadcast(&c->base, CONTENT_MSG_REFRESH,
msg_data);
@ -954,30 +951,17 @@ bool html_meta_refresh(html_content *c, xmlNode *head)
if (url < end)
*url = '\0';
res = url_join(refresh, c->base_url, &refresh);
error = nsurl_join(c->base_url, refresh, &nsurl);
if (error != NSERROR_OK) {
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR,
msg_data);
return false;
}
xmlFree(content);
if (res == URL_FUNC_NOMEM) {
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR,
msg_data);
return false;
} else if (res == URL_FUNC_FAILED) {
/* This isn't fatal so carry on looking */
continue;
}
c->base.refresh = talloc_strdup(c, refresh);
free(refresh);
if (!c->base.refresh) {
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR,
msg_data);
return false;
}
c->base.refresh = nsurl;
content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
}
@ -1000,14 +984,19 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
{
content_type accept = CONTENT_CSS;
xmlNode *node;
char *rel, *type, *media, *href, *url, *url2;
char *rel, *type, *media, *href;
unsigned int i = STYLESHEET_START;
union content_msg_data msg_data;
url_func_result res;
struct html_stylesheet *stylesheets;
hlcache_child_context child;
nserror ns_error;
nsurl *html_default_css = NULL;
nsurl *html_quirks_css = NULL;
nsurl *html_adblock_css = NULL;
nsurl *joined;
child.charset = c->encoding;
child.quirks = c->base.quirks;
@ -1028,7 +1017,11 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
c->base.active = 0;
ns_error = hlcache_handle_retrieve(default_stylesheet_url, 0,
ns_error = nsurl_create(default_stylesheet_url, &html_default_css);
if (ns_error != NSERROR_OK)
goto no_memory;
ns_error = hlcache_handle_retrieve(html_default_css, 0,
content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child, accept,
&c->stylesheets[STYLESHEET_BASE].data.external);
@ -1038,7 +1031,12 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
c->base.active++;
if (c->quirks == BINDING_QUIRKS_MODE_FULL) {
ns_error = hlcache_handle_retrieve(quirks_stylesheet_url, 0,
ns_error = nsurl_create(quirks_stylesheet_url, &html_quirks_css);
if (ns_error != NSERROR_OK)
goto no_memory;
ns_error = hlcache_handle_retrieve(html_quirks_css, 0,
content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child, accept,
&c->stylesheets[STYLESHEET_QUIRKS].
@ -1050,7 +1048,12 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
}
if (option_block_ads) {
ns_error = hlcache_handle_retrieve(adblock_stylesheet_url, 0,
ns_error = nsurl_create(adblock_stylesheet_url, &html_adblock_css);
if (ns_error != NSERROR_OK)
goto no_memory;
ns_error = hlcache_handle_retrieve(html_adblock_css, 0,
content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child, accept,
&c->stylesheets[STYLESHEET_ADBLOCK].
@ -1061,6 +1064,13 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
c->base.active++;
}
if (html_default_css != NULL)
nsurl_unref(html_default_css);
if (html_adblock_css != NULL)
nsurl_unref(html_adblock_css);
if (html_quirks_css != NULL)
nsurl_unref(html_quirks_css);
node = html;
/* depth-first search the tree for link elements */
@ -1128,42 +1138,35 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
* those with a title attribute) should be loaded
* (see HTML4 14.3) */
res = url_join(href, c->base_url, &url);
xmlFree(href);
if (res != URL_FUNC_OK)
continue;
LOG(("linked stylesheet %i '%s'", i, url));
res = url_normalize(url, &url2);
free(url);
if (res != URL_FUNC_OK) {
if (res == URL_FUNC_NOMEM)
goto no_memory;
continue;
ns_error = nsurl_join(c->base_url, href, &joined);
if (ns_error != NSERROR_OK) {
xmlFree(href);
goto no_memory;
}
xmlFree(href);
LOG(("linked stylesheet %i '%s'", i,
nsurl_access(joined)));
/* start fetch */
stylesheets = talloc_realloc(c,
c->stylesheets,
struct html_stylesheet, i + 1);
if (stylesheets == NULL) {
free(url2);
nsurl_unref(joined);
goto no_memory;
}
c->stylesheets = stylesheets;
c->stylesheet_count++;
c->stylesheets[i].type = HTML_STYLESHEET_EXTERNAL;
ns_error = hlcache_handle_retrieve(url2, 0,
ns_error = hlcache_handle_retrieve(joined, 0,
content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child,
accept,
&c->stylesheets[i].data.external);
free(url2);
nsurl_unref(joined);
if (ns_error != NSERROR_OK)
goto no_memory;
@ -1182,6 +1185,13 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
return true;
no_memory:
if (html_default_css != NULL)
nsurl_unref(html_default_css);
if (html_adblock_css != NULL)
nsurl_unref(html_adblock_css);
if (html_quirks_css != NULL)
nsurl_unref(html_quirks_css);
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
return false;
@ -1247,7 +1257,7 @@ bool html_process_style_element(html_content *c, unsigned int *index,
}
error = nscss_create_css_data(sheet,
c->base_url, NULL, c->quirks,
nsurl_access(c->base_url), NULL, c->quirks,
html_inline_style_done, c);
if (error != NSERROR_OK) {
c->stylesheet_count--;
@ -1338,13 +1348,14 @@ nserror html_convert_css_callback(hlcache_handle *css,
break;
case CONTENT_MSG_DONE:
LOG(("got stylesheet '%s'", content_get_url(css)));
LOG(("got stylesheet '%s'", nsurl_access(content_get_url(css))));
parent->base.active--;
break;
case CONTENT_MSG_ERROR:
LOG(("stylesheet %s failed: %s",
content_get_url(css), event->data.error));
LOG(("stylesheet %s failed: %s",
nsurl_access(content_get_url(css)),
event->data.error));
hlcache_handle_release(css);
s->data.external = NULL;
parent->base.active--;
@ -1387,24 +1398,23 @@ bool html_fetch_object(html_content *c, const char *url, struct box *box,
bool background)
{
struct content_html_object *object;
nserror error;
nsurl *object_url;
struct content_html_object *ins_object; /* the object to insert after */
char *url2;
url_func_result res;
/* If we've already been aborted, don't bother attempting the fetch */
if (c->aborted)
return true;
/* Normalize the URL */
res = url_normalize(url, &url2);
if (res != URL_FUNC_OK) {
error = nsurl_create(url, &object_url);
if (error != NSERROR_OK) {
LOG(("failed to normalize url '%s'", url));
return res != URL_FUNC_NOMEM;
return false;
}
object = talloc(c, struct content_html_object);
if (object == NULL) {
free(url2);
nsurl_unref(object_url);
return false;
}
@ -1414,7 +1424,7 @@ bool html_fetch_object(html_content *c, const char *url, struct box *box,
object->box = box;
object->permitted_types = permitted_types;
object->background = background;
object->url = url2;
object->url = object_url;
/* add to content object list, this list determines fetch order */
if (c->object_list == NULL) {
@ -1451,11 +1461,13 @@ bool html_fetch_objects(html_content *c)
child.quirks = c->base.quirks;
for (object = c->object_list; object != NULL; object = object->next) {
error = hlcache_handle_retrieve(object->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)
c->base.active++;
}
@ -1472,13 +1484,11 @@ bool html_fetch_objects(html_content *c)
* \return true on success, false on memory exhaustion
*/
bool html_replace_object(struct content_html_object *object, const char *url)
bool html_replace_object(struct content_html_object *object, nsurl *url)
{
html_content *c;
hlcache_child_context child;
html_content *page;
char *url2;
url_func_result res;
nserror error;
assert(object != NULL);
@ -1499,19 +1509,13 @@ bool html_replace_object(struct content_html_object *object, const char *url)
object->box->object = NULL;
}
res = url_normalize(url, &url2);
if (res != URL_FUNC_OK)
return res != URL_FUNC_NOMEM;
/* initialise fetch */
error = hlcache_handle_retrieve(url2, HLCACHE_RETRIEVE_SNIFF_TYPE,
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);
free(url2);
if (error != NSERROR_OK)
return false;
@ -1737,7 +1741,7 @@ void html_object_failed(struct box *box, html_content *content,
void html_object_refresh(void *p)
{
struct content_html_object *object = p;
const char *refresh_url;
nsurl *refresh_url;
assert(content_get_type(object->content) == CONTENT_HTML);
@ -1909,6 +1913,12 @@ void html_destroy(struct content *c)
imagemap_destroy(html);
if (c->refresh)
nsurl_unref(c->refresh);
if (html->base_url)
nsurl_unref(html->base_url);
if (html->parser_binding != NULL)
binding_destroy_tree(html->parser_binding);
@ -1972,7 +1982,7 @@ void html_destroy_objects(html_content *html)
hlcache_handle_release(victim->content);
}
free(victim->url);
nsurl_unref(victim->url);
html->object_list = victim->next;
talloc_free(victim);
@ -2352,7 +2362,7 @@ struct content_html_iframe *html_get_iframe(hlcache_handle *h)
* \param h Content to retrieve base target from
* \return Pointer to URL
*/
const char *html_get_base_url(hlcache_handle *h)
nsurl *html_get_base_url(hlcache_handle *h)
{
html_content *c = (html_content *) hlcache_handle_get_content(h);

View File

@ -78,7 +78,7 @@ struct content_html_object {
struct content *parent; /**< Parent document */
struct content_html_object *next; /**< Next in chain */
char *url; /**< URL of content */
nsurl *url; /**< URL of content */
struct hlcache_handle *content; /**< Content, or 0. */
struct box *box; /**< Node in box tree containing it. */
/** Bitmap of acceptable content types */
@ -168,7 +168,7 @@ const char *html_get_encoding(struct hlcache_handle *h);
binding_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);
const char *html_get_base_url(struct hlcache_handle *h);
nsurl *html_get_base_url(struct hlcache_handle *h);
const char *html_get_base_target(struct hlcache_handle *h);
struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
unsigned int *n);

View File

@ -554,7 +554,8 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
mouse & BROWSER_MOUSE_MOD_1) {
/* force download of link */
browser_window_go_post(bw, url, 0, 0, false,
content_get_url(h), true, true, 0);
nsurl_access(content_get_url(h)),
true, true, 0);
} else if (mouse & BROWSER_MOUSE_CLICK_2 &&
mouse & BROWSER_MOUSE_MOD_1) {
gui_window_save_link(bw->window, url, title);
@ -689,7 +690,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
break;
case ACTION_GO:
browser_window_go(browser_window_find_target(bw, target, mouse),
url, content_get_url(h), true);
url, nsurl_access(content_get_url(h)), true);
break;
case ACTION_NONE:
break;

View File

@ -44,7 +44,7 @@ typedef struct html_content {
binding_encoding_source encoding_source;
/** Base URL (may be a copy of content->url). */
char *base_url;
nsurl *base_url;
/** Base target */
char *base_target;

View File

@ -77,7 +77,7 @@ static bool imagemap_add(html_content *c, const char *key,
static bool imagemap_create(html_content *c);
static bool imagemap_extract_map(xmlNode *node, html_content *c,
struct mapentry **entry);
static bool imagemap_addtolist(xmlNode *n, char *base_url,
static bool imagemap_addtolist(xmlNode *n, const char *base_url,
struct mapentry **entry);
static void imagemap_freelist(struct mapentry *list);
static unsigned int imagemap_hash(const char *key);
@ -316,7 +316,7 @@ bool imagemap_extract_map(xmlNode *node, html_content *c,
*/
if (strcmp((const char *) node->name, "area") == 0 ||
strcmp((const char *) node->name, "a") == 0) {
if (imagemap_addtolist(node, c->base_url,
if (imagemap_addtolist(node, nsurl_access(c->base_url),
entry) == false)
return false;
}
@ -341,7 +341,8 @@ bool imagemap_extract_map(xmlNode *node, html_content *c,
* \param entry Pointer to list of entries
* \return false on memory exhaustion, true otherwise
*/
bool imagemap_addtolist(xmlNode *n, char *base_url, struct mapentry **entry)
bool imagemap_addtolist(xmlNode *n, const char *base_url,
struct mapentry **entry)
{
char *shape, *coords = NULL, *href, *target = NULL;
struct mapentry *new_map, *temp;