diff options
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/browser.c | 23 | ||||
-rw-r--r-- | desktop/browser.h | 4 | ||||
-rw-r--r-- | desktop/history_core.c | 34 |
3 files changed, 42 insertions, 19 deletions
diff --git a/desktop/browser.c b/desktop/browser.c index dacea8e1d..a814e68aa 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -97,10 +97,12 @@ static void browser_window_scroll_box(struct browser_window *bw, */ void browser_window_create(const char *url, struct browser_window *clone, - char *referer) + char *referer, bool history_add) { struct browser_window *bw; + assert(clone || history_add); + if ((bw = malloc(sizeof *bw)) == NULL) { warn_user("NoMemory", 0); return; @@ -126,7 +128,7 @@ void browser_window_create(const char *url, struct browser_window *clone, return; } bw->refresh_interval = -1; - browser_window_go(bw, url, referer); + browser_window_go(bw, url, referer, history_add); } @@ -141,9 +143,9 @@ void browser_window_create(const char *url, struct browser_window *clone, */ void browser_window_go(struct browser_window *bw, const char *url, - char* referer) + char* referer, bool history_add) { - browser_window_go_post(bw, url, 0, 0, true, referer, false); + browser_window_go_post(bw, url, 0, 0, history_add, referer, false); } @@ -475,15 +477,20 @@ void browser_window_callback(content_msg msg, struct content *c, void browser_window_refresh(void *p) { struct browser_window *bw = p; + bool history_add = true; assert(bw->current_content->status == CONTENT_STATUS_READY || bw->current_content->status == CONTENT_STATUS_DONE); /* mark this content as invalid so it gets flushed from the cache */ bw->current_content->fresh = false; + if ((bw->current_content->url) && + (bw->current_content->refresh) && + (!strcmp(bw->current_content->url, bw->current_content->refresh))) + history_add = false; browser_window_go(bw, bw->current_content->refresh, - bw->current_content->url); + bw->current_content->url, history_add); } /** @@ -1073,7 +1080,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, if (!html_replace_object(page, i, url, 0, 0)) warn_user("NoMemory", 0); } else { - browser_window_go(bw, url, c->url); + browser_window_go(bw, url, c->url, true); } } else if (mouse & BROWSER_MOUSE_CLICK_2 && @@ -1083,7 +1090,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, } else if (mouse & BROWSER_MOUSE_CLICK_2) { /* open link in new window */ - browser_window_create(url, bw, c->url); + browser_window_create(url, bw, c->url, true); } } else { @@ -1905,7 +1912,7 @@ void browser_form_submit(struct browser_window *bw, struct form *form, res = url_join(url, base, &url1); if (res != URL_FUNC_OK) break; - browser_window_go(bw, url1, bw->current_content->url); + browser_window_go(bw, url1, bw->current_content->url, true); break; case method_POST_URLENC: diff --git a/desktop/browser.h b/desktop/browser.h index 8edc699a6..c046290b1 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -120,9 +120,9 @@ typedef enum { extern struct browser_window *current_redraw_browser; void browser_window_create(const char *url, struct browser_window *clone, - char *referer); + char *referer, bool history_add); void browser_window_go(struct browser_window *bw, const char *url, - char *referer); + char *referer, bool history_add); void browser_window_go_post(struct browser_window *bw, const char *url, char *post_urlenc, struct form_successful_control *post_multipart, diff --git a/desktop/history_core.c b/desktop/history_core.c index 197596853..749f54808 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -122,7 +122,8 @@ struct history *history_clone(struct history *history) if (!history_clone_entry(new_history, &new_history->start)) { warn_user("NoMemory", 0); - return 0; + history_destroy(new_history); + return 0; } return new_history; @@ -147,16 +148,24 @@ bool history_clone_entry(struct history *history, struct history_entry **start) /* clone the entry */ new_entry = malloc(sizeof *entry); - if (!new_entry) + if (!new_entry) { + *start = 0; return false; + } memcpy(new_entry, entry, sizeof *entry); new_entry->url = strdup(entry->url); - new_entry->frag_id = strdup(entry->frag_id); + if (entry->frag_id) + new_entry->frag_id = strdup(entry->frag_id); new_entry->title = strdup(entry->title); if (((entry->url) && (!new_entry->url)) || ((entry->title) && (!new_entry->title)) || - ((entry->frag_id) && (!new_entry->frag_id))) + ((entry->frag_id) && (!new_entry->frag_id))) { + free(entry->url); + free(entry->title); + free(entry->frag_id); + *start = 0; return false; + } if (history->current == entry) history->current = new_entry; *start = new_entry; @@ -180,8 +189,11 @@ bool history_clone_entry(struct history *history, struct history_entry **start) for (child = entry->forward; child; child = child->next) { child->back = new_entry; - if (!history_clone_entry(history, &child)) + if (!history_clone_entry(history, &child)) { + entry->next = 0; + entry->forward = 0; return false; + } } return true; @@ -384,6 +396,7 @@ void history_go(struct browser_window *bw, struct history *history, struct history_entry *entry, bool new_window) { char *url; + struct history_entry *current; if (entry->frag_id) { url = malloc(strlen(entry->url) + strlen(entry->frag_id) + 5); @@ -396,11 +409,14 @@ void history_go(struct browser_window *bw, struct history *history, else url = entry->url; - if (new_window) - browser_window_create(url, bw, 0); - else { + if (new_window) { + current = history->current; + history->current = entry; + browser_window_create(url, bw, 0, false); + history->current = current; + } else { history->current = entry; - browser_window_go_post(bw, url, 0, 0, false, 0, false); + browser_window_go(bw, url, 0, false); } if (entry->frag_id) |