summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c127
-rw-r--r--desktop/browser.h2
-rw-r--r--desktop/frames.c6
-rw-r--r--desktop/gui.h13
-rw-r--r--desktop/history_core.c9
-rw-r--r--desktop/hotlist.c3
-rw-r--r--desktop/save_complete.c12
-rw-r--r--desktop/searchweb.c18
-rw-r--r--desktop/tree.c11
9 files changed, 121 insertions, 80 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 4cf79fba6..fbcac5297 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -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;
}
- /* Get download out of the way */
- if (download) {
- llcache_handle *l;
- nsurl *nsref = NULL;
- nsurl *nsurl;
-
- error = nsurl_create(url2, &nsurl);
+ if (referer != NULL) {
+ error = nsurl_create(referer, &nsref);
if (error != NSERROR_OK) {
- free(url2);
+ nsurl_unref(nsurl);
return;
}
+ }
- if (referer != NULL) {
- error = nsurl_create(referer, &nsref);
- if (error != NSERROR_OK) {
- free(url2);
- nsurl_unref(nsurl);
- return;
- }
- }
+ /* Get download out of the way */
+ if (download) {
+ llcache_handle *l;
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 {
diff --git a/desktop/browser.h b/desktop/browser.h
index cb3b22bb0..d7d996c5e 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -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,
diff --git a/desktop/frames.c b/desktop/frames.c
index ccf055bff..7ff7c00bc 100644
--- a/desktop/frames.c
+++ b/desktop/frames.c
@@ -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);
}
diff --git a/desktop/gui.h b/desktop/gui.h
index 9f49e7fe0..0b2c6c0c0 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -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);
diff --git a/desktop/history_core.c b/desktop/history_core.c
index 70e8f158c..11db6b7f9 100644
--- a/desktop/history_core.c
+++ b/desktop/history_core.c
@@ -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;
diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index 16e249ee1..1f4028595 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -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)) {
diff --git a/desktop/save_complete.c b/desktop/save_complete.c
index 48e38e7f1..9e123ce17 100644
--- a/desktop/save_complete.c
+++ b/desktop/save_complete.c
@@ -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);
diff --git a/desktop/searchweb.c b/desktop/searchweb.c
index 0313859e0..b4493ab31 100644
--- a/desktop/searchweb.c
+++ b/desktop/searchweb.c
@@ -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);
diff --git a/desktop/tree.c b/desktop/tree.c
index e0193c4da..bf7b643b9 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -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)