Move local history over to nsurl.

This commit is contained in:
Michael Drake 2013-07-11 23:38:32 +01:00
parent 90231bd4b1
commit 3a0bda9771
3 changed files with 27 additions and 49 deletions

View File

@ -941,9 +941,7 @@ nserror browser_window_navigate(struct browser_window *bw,
if ((flags & BROWSER_WINDOW_HISTORY) != 0) {
history_add(bw->history,
bw->current_content,
bw->frag_id == NULL ? NULL :
lwc_string_data(bw->frag_id));
bw->current_content, bw->frag_id);
}
browser_window_update(bw, false);
@ -1285,8 +1283,7 @@ nserror browser_window_callback(hlcache_handle *c,
if (bw->history_add && bw->history) {
nsurl *url = hlcache_handle_get_url(c);
history_add(bw->history, c, bw->frag_id == NULL ? NULL :
lwc_string_data(bw->frag_id));
history_add(bw->history, c, bw->frag_id);
if (urldb_add_url(url)) {
urldb_set_url_title(url, content_get_title(c));
urldb_update_url_visit_data(url);

View File

@ -38,7 +38,7 @@
#include "image/bitmap.h"
#include "render/font.h"
#include "utils/log.h"
#include "utils/url.h"
#include "utils/nsurl.h"
#include "utils/utils.h"
@ -48,8 +48,8 @@
#define BOTTOM_MARGIN 30
struct history_page {
char *url; /**< Page URL, never 0. */
char *frag_id; /** Fragment identifier, or 0. */
nsurl *url; /**< Page URL, never 0. */
lwc_string *frag_id; /** Fragment identifier, or 0. */
char *title; /**< Page title, never 0. */
};
@ -175,15 +175,16 @@ struct history_entry *history_clone_entry(struct history *history,
if (!new_entry)
return 0;
memcpy(new_entry, entry, sizeof *entry);
new_entry->page.url = strdup(entry->page.url);
new_entry->page.url = nsurl_ref(entry->page.url);
if (entry->page.frag_id)
new_entry->page.frag_id = strdup(entry->page.frag_id);
new_entry->page.frag_id = lwc_string_ref(entry->page.frag_id);
new_entry->page.title = strdup(entry->page.title);
if (!new_entry->page.url || !new_entry->page.title ||
((entry->page.frag_id) && (!new_entry->page.frag_id))) {
free(new_entry->page.url);
nsurl_unref(new_entry->page.url);
if (new_entry->page.frag_id)
lwc_string_unref(new_entry->page.frag_id);
free(new_entry->page.title);
free(new_entry->page.frag_id);
free(new_entry);
return 0;
}
@ -218,21 +219,18 @@ struct history_entry *history_clone_entry(struct history *history,
*
* \param history opaque history structure, as returned by history_create()
* \param content content to add to history
* \param frag_id fragment identifier
* \param frag_id fragment identifier, or NULL.
*
* The page is added after the current entry and becomes current.
*/
void history_add(struct history *history, hlcache_handle *content,
const char *frag_id)
lwc_string *frag_id)
{
struct history_entry *entry;
nsurl *nsurl = hlcache_handle_get_url(content);
char *url;
char *title;
struct bitmap *bitmap;
nserror error;
size_t url_len;
assert(history);
assert(content);
@ -242,24 +240,16 @@ void history_add(struct history *history, hlcache_handle *content,
if (entry == NULL)
return;
/* TODO: use a nsurl? */
error = nsurl_get(nsurl, NSURL_WITH_FRAGMENT, &url, &url_len);
if (error != NSERROR_OK) {
warn_user("NoMemory", 0);
free(entry);
return;
}
title = strdup(content_get_title(content));
if (title == NULL) {
warn_user("NoMemory", 0);
free(url);
free(entry);
return;
}
entry->page.url = url;
entry->page.frag_id = frag_id ? strdup(frag_id) : 0;
entry->page.url = nsurl_ref(nsurl);
entry->page.frag_id = frag_id ? lwc_string_ref(frag_id) : 0;
entry->page.title = title;
entry->back = history->current;
entry->next = 0;
@ -358,9 +348,9 @@ void history_free_entry(struct history_entry *entry)
return;
history_free_entry(entry->forward);
history_free_entry(entry->next);
free(entry->page.url);
nsurl_unref(entry->page.url);
if (entry->page.frag_id)
free(entry->page.frag_id);
lwc_string_unref(entry->page.frag_id);
free(entry->page.title);
free(entry);
}
@ -428,7 +418,6 @@ void history_go(struct browser_window *bw,
struct history_entry *entry,
bool new_window)
{
char *full_url;
nsurl *url;
struct history_entry *current;
nserror error;
@ -438,24 +427,15 @@ void history_go(struct browser_window *bw,
// entry->page.url, entry->page.title, entry->page.frag_id));
if (entry->page.frag_id) {
full_url = malloc(strlen(entry->page.url) +
strlen(entry->page.frag_id) + 5);
if (full_url == NULL) {
error = nsurl_refragment(entry->page.url,
entry->page.frag_id, &url);
if (error != NSERROR_OK) {
warn_user("NoMemory", 0);
return;
}
sprintf(full_url, "%s#%s", entry->page.url, entry->page.frag_id);
error = nsurl_create(full_url, &url);
free(full_url);
} else {
error = nsurl_create(entry->page.url, &url);
}
if (error != NSERROR_OK) {
warn_user("NoMemory", 0);
return;
url = nsurl_ref(entry->page.url);
}
if (new_window) {
@ -747,7 +727,7 @@ const char *history_position_url(struct history *history, int x, int y)
if (!entry)
return 0;
return entry->page.url;
return nsurl_access(entry->page.url);
}
@ -848,13 +828,13 @@ static bool history_enumerate_entry(const struct history *history,
/* Documented in local_history.h */
const char *history_entry_get_url(const struct history_entry *entry)
{
return entry->page.url;
return nsurl_access(entry->page.url);
}
/* Documented in local_history.h */
const char *history_entry_get_fragment_id(const struct history_entry *entry)
{
return entry->page.frag_id;
return (entry->page.frag_id) ? lwc_string_data(entry->page.frag_id) : 0;
}
/* Documented in local_history.h */

View File

@ -24,6 +24,7 @@
#define _NETSURF_DESKTOP_HISTORY_H_
#include <stdbool.h>
#include <libwapcaplet/libwapcaplet.h>
struct hlcache_handle;
struct history;
@ -34,7 +35,7 @@ struct redraw_context;
struct history *history_create(void);
struct history *history_clone(struct history *history);
void history_add(struct history *history, struct hlcache_handle *content,
const char *frag_id);
lwc_string *frag_id);
void history_update(struct history *history, struct hlcache_handle *content);
void history_destroy(struct history *history);
void history_back(struct browser_window *bw, struct history *history);