From c7f77b0165254152498a13749f8c3572b56efb00 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Sat, 22 Apr 2006 18:24:18 +0000 Subject: Finish history cloning. svn path=/trunk/netsurf/; revision=2547 --- desktop/browser.c | 23 +++++++++++++++-------- desktop/browser.h | 4 ++-- desktop/history_core.c | 34 +++++++++++++++++++++++++--------- riscos/401login.c | 2 +- riscos/dialog.c | 2 +- riscos/gui.c | 14 +++++++------- riscos/menus.c | 10 +++++----- riscos/plugin.c | 4 ++-- riscos/sslcert.c | 2 +- riscos/treeview.c | 4 ++-- riscos/uri.c | 2 +- riscos/url_complete.c | 2 +- riscos/url_protocol.c | 2 +- riscos/window.c | 2 +- 14 files changed, 65 insertions(+), 42 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) diff --git a/riscos/401login.c b/riscos/401login.c index 92bfe0f1a..b2e8b525d 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -191,7 +191,7 @@ bool ro_gui_401login_apply(wimp_w w) free(auth); - browser_window_go(session->bwin, session->url, 0); + browser_window_go(session->bwin, session->url, 0, true); return true; } diff --git a/riscos/dialog.c b/riscos/dialog.c index ee159229c..aa46f19b2 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -705,7 +705,7 @@ bool ro_gui_dialog_openurl_apply(wimp_w w) { url = ro_gui_get_icon_string(w, ICON_OPENURL_URL); res = url_normalize(url, &url2); if (res == URL_FUNC_OK) { - browser_window_create(url2, 0, 0); + browser_window_create(url2, 0, 0, true); global_history_add_recent(url2); free(url2); return true; diff --git a/riscos/gui.c b/riscos/gui.c index 619a27548..9a6405d18 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -704,7 +704,7 @@ void gui_init2(int argc, char** argv) #endif if (open_window) - browser_window_create(url, NULL, 0); + browser_window_create(url, NULL, 0, true); free(url); } @@ -1196,12 +1196,12 @@ bool ro_gui_icon_bar_click(wimp_pointer *pointer) } else if (pointer->buttons == wimp_CLICK_SELECT) { if (option_homepage_url && option_homepage_url[0]) { - browser_window_create(option_homepage_url, NULL, 0); + browser_window_create(option_homepage_url, NULL, 0, true); } else { snprintf(url, sizeof url, "file:////Docs/intro_%s", option_language); - browser_window_create(url, NULL, 0); + browser_window_create(url, NULL, 0, true); } } else if (pointer->buttons == wimp_CLICK_ADJUST) { @@ -1522,7 +1522,7 @@ void ro_msg_dataload(wimp_message *message) return; if (g) { - browser_window_go(g->bw, url, 0); + browser_window_go(g->bw, url, 0, true); } else if ((hotlist_tree) && ((wimp_w)hotlist_tree->handle == message->data.data_xfer.w)) { data = urldb_get_url_data(url); @@ -1546,7 +1546,7 @@ void ro_msg_dataload(wimp_message *message) ro_gui_tree_start_edit(hotlist_tree, &node->data, NULL); } } else { - browser_window_create(url, 0, 0); + browser_window_create(url, 0, 0, true); } /* send DataLoadAck */ @@ -1904,7 +1904,7 @@ void ro_msg_dataopen(wimp_message *message) return; /* create a new window with the file */ - browser_window_create(url, NULL, 0); + browser_window_create(url, NULL, 0, true); free(url); } @@ -2129,7 +2129,7 @@ void ro_gui_open_help_page(const char *page) if ((length = snprintf(url, sizeof url, "file:////Docs/%s_%s", page, option_language)) >= 0 && length < (int)sizeof(url)) - browser_window_create(url, NULL, 0); + browser_window_create(url, NULL, 0, true); } /** diff --git a/riscos/menus.c b/riscos/menus.c index f3d247d95..83fc09e3b 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -628,7 +628,7 @@ void ro_gui_menu_selection(wimp_selection *selection) { if (g) { url = url_suggest_menu->entries[selection->items[0]].data.indirected_text.text; gui_window_set_url(g, url); - browser_window_go(g->bw, url, 0); + browser_window_go(g->bw, url, 0, true); global_history_add_recent(url); } } else if ((current_menu == gui_form_select_menu) && @@ -1388,7 +1388,7 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, case HELP_OPEN_ABOUT: browser_window_create( "file:////Docs/about", - 0, 0); + 0, 0, true); return true; case HELP_LAUNCH_INTERACTIVE: ro_gui_interactive_help_start(); @@ -1446,7 +1446,7 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, case BROWSER_NEW_WINDOW: if (!c) return false; - browser_window_create(c->url, bw, 0); + browser_window_create(c->url, bw, 0, false); return true; case BROWSER_VIEW_SOURCE: if (!c) @@ -1500,12 +1500,12 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, if ((option_homepage_url) && (option_homepage_url[0])) { browser_window_go(g->bw, - option_homepage_url, 0); + option_homepage_url, 0, true); } else { snprintf(url, sizeof url, "file:////Docs/intro_%s", option_language); - browser_window_go(g->bw, url, 0); + browser_window_go(g->bw, url, 0, true); } return true; case BROWSER_NAVIGATE_BACK: diff --git a/riscos/plugin.c b/riscos/plugin.c index 115045b7c..8fb683386 100644 --- a/riscos/plugin.c +++ b/riscos/plugin.c @@ -916,12 +916,12 @@ void plugin_url_access(wimp_message *message) * end up in an infinite loop of fetching * the same page */ - browser_window_go(c->data.plugin.bw, url, 0); + browser_window_go(c->data.plugin.bw, url, 0, true); } else if (!option_block_popups && strcasecmp(window, "_blank") == 0) { /* don't do this if popups are blocked */ - browser_window_create(url, NULL, 0); + browser_window_create(url, NULL, 0, true); } } else { /* POST request */ diff --git a/riscos/sslcert.c b/riscos/sslcert.c index 678b78a0e..0f75dd863 100644 --- a/riscos/sslcert.c +++ b/riscos/sslcert.c @@ -171,7 +171,7 @@ bool ro_gui_cert_apply(wimp_w w) urldb_set_cert_permissions(session->url, true); - browser_window_go(session->bw, session->url, 0); + browser_window_go(session->bw, session->url, 0, true); return true; } diff --git a/riscos/treeview.c b/riscos/treeview.c index d91771907..8d6965f88 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -1371,7 +1371,7 @@ void ro_gui_tree_move_drag_end(wimp_dragged *drag) { /* \todo:send datasave for element */ g = ro_gui_window_lookup(pointer.w); if (g) - browser_window_go(g->bw, element->text, 0); + browser_window_go(g->bw, element->text, 0, true); return; } else { /* \todo:update save.c to handle multiple concurrent saves */ @@ -1431,7 +1431,7 @@ bool ro_gui_tree_launch_node(struct node *node) { element = tree_find_element(node, TREE_ELEMENT_URL); if (element) { - browser_window_create(element->text, NULL, 0); + browser_window_create(element->text, NULL, 0, true); return true; } diff --git a/riscos/uri.c b/riscos/uri.c index a396cc3f4..248838517 100644 --- a/riscos/uri.c +++ b/riscos/uri.c @@ -52,7 +52,7 @@ void ro_uri_message_received(uri_full_message_process* uri_message) xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL); - browser_window_create(uri_requested, NULL, 0); + browser_window_create(uri_requested, NULL, 0, true); free(uri_requested); } diff --git a/riscos/url_complete.c b/riscos/url_complete.c index 1a179f21e..47ebf906d 100644 --- a/riscos/url_complete.c +++ b/riscos/url_complete.c @@ -704,7 +704,7 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer) browser_window_go(g->bw, url_complete_matches[ url_complete_matches_selection], - 0); + 0, true); global_history_add_recent(url_complete_matches[ url_complete_matches_selection]); ro_gui_url_complete_close(NULL, 0); diff --git a/riscos/url_protocol.c b/riscos/url_protocol.c index fe293fe46..fe56341bd 100644 --- a/riscos/url_protocol.c +++ b/riscos/url_protocol.c @@ -104,7 +104,7 @@ void ro_url_message_received(wimp_message *message) } /* create new browser window */ - browser_window_create(url, 0, 0); + browser_window_create(url, 0, 0, true); free(url); } diff --git a/riscos/window.c b/riscos/window.c index eebc8103d..a83fe9dfd 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -1076,7 +1076,7 @@ void ro_gui_window_launch_url(struct gui_window *g, const char *url) res = url_normalize(url, &url_norm); if (res == URL_FUNC_OK) { gui_window_set_url(g, url_norm); - browser_window_go(g->bw, url_norm, 0); + browser_window_go(g->bw, url_norm, 0, true); global_history_add_recent(url_norm); free(url_norm); } -- cgit v1.2.3