diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index 566fcbe72..8e00b308a 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -39,7 +39,6 @@ Quit:Beenden # Iconbar -> Open menu # OpenURL:Öffne URL -ShowCookies:Show cookies... # Main menu # @@ -134,6 +133,10 @@ HotlistShow:Hotlist zeigen... F6 HistLocal:History (lokal) zeigen... F7 HistGlobal:History (global) zeigen... ^F7 +# Main -> Utilities -> Cookies menu +ShowCookies:Show cookies... +DeleteCookies:Delete all cookies + # Main -> Utilities -> Window menu # WindowSave:aktuelle Fensterposition speichern diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index c518364cf..d5fac292d 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -39,7 +39,6 @@ Quit:Quit # Iconbar -> Open menu # OpenURL:Open URL -ShowCookies:Show cookies... # Main menu # @@ -134,6 +133,10 @@ HotlistShow:Show hotlist... F6 HistLocal:Show local history... F7 HistGlobal:Show global history... ^F7 +# Main -> Utilities -> Cookies menu +ShowCookies:Show cookies... +DeleteCookies:Delete all cookies + # Main -> Utilities -> Window menu # WindowSave:Set as default position diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index 73a973ae2..55be93cce 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -39,7 +39,6 @@ Quit:Quitter # Iconbar -> Open menu # OpenURL:Ouvrir l'URL... -ShowCookies:Show cookies... # Main menu # @@ -134,6 +133,10 @@ HotlistShow:Montrer les favoris... F6 HistLocal:Montrer l'historique local... F7 HistGlobal:Montrer l'historique global... ^F7 +# Main -> Utilities -> Cookies menu +ShowCookies:Show cookies... +DeleteCookies:Delete all cookies + # Main -> Utilities -> Window menu # WindowSave:Définir comme position par défaut diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index 1fc72d3b6..8d41c6019 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -39,7 +39,6 @@ Quit:Stop # Iconbar -> Open menu # OpenURL:Open URL -ShowCookies:Show cookies... # Main menu # @@ -141,6 +140,10 @@ WindowStagr:Nieuw venster verplaatsen WindowSize:Copieer venster positie WindowReset:Venster positie terugzetten +# Main -> Utilities -> Cookies menu +ShowCookies:Show cookies... +DeleteCookies:Delete all cookies + # Main -> Help menu # HelpContent:Inhoud F1 diff --git a/content/urldb.c b/content/urldb.c index 11cfe2ca8..a405d7e3d 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -245,6 +245,8 @@ static bool urldb_insert_cookie(struct cookie_internal_data *c, const char *sche static void urldb_free_cookie(struct cookie_internal_data *c); static bool urldb_concat_cookie(struct cookie_internal_data *c, int *used, int *alloc, char **buf); +static void urldb_delete_cookie_hosts(const char *domain, const char *path, const char *name, struct host_part *parent); +static void urldb_delete_cookie_paths(const char *domain, const char *path, const char *name, struct path_data *parent); static void urldb_save_cookie_hosts(FILE *fp, struct host_part *parent); static void urldb_save_cookie_paths(FILE *fp, struct path_data *parent); @@ -2372,6 +2374,7 @@ char *urldb_get_cookie(const char *url, const char *referer) version = c->version; c->last_used = now; + cookies_update(c->domain, (struct cookie_data *)c); count++; } @@ -2411,7 +2414,7 @@ char *urldb_get_cookie(const char *url, const char *referer) version = c->version; c->last_used = now; - + cookies_update(c->domain, (struct cookie_data *)c); count++; } } @@ -2454,6 +2457,7 @@ char *urldb_get_cookie(const char *url, const char *referer) version = c->version; c->last_used = now; + cookies_update(c->domain, (struct cookie_data *)c); count++; } @@ -3189,6 +3193,54 @@ void urldb_load_cookies(const char *filename) fclose(fp); } +/** + * Delete a cookie + * + * \param domain The cookie's domain + * \param path The cookie's path + * \param name The cookie's name + */ +void urldb_delete_cookie(const char *domain, const char *path, const char *name) +{ + urldb_delete_cookie_hosts(domain, path, name, &db_root); +} + +void urldb_delete_cookie_hosts(const char *domain, const char *path, const char *name, struct host_part *parent) +{ + assert(parent); + + urldb_delete_cookie_paths(domain, path, name, &parent->paths); + + for (struct host_part *h = parent->children; h; h = h->next) + urldb_delete_cookie_hosts(domain, path, name, h); +} + +void urldb_delete_cookie_paths(const char *domain, const char *path, const char *name, struct path_data *parent) +{ + struct cookie_internal_data *c; + + assert(parent); + + for (c = parent->cookies; c; c = c->next) { + if (!strcmp(c->domain, domain) && !strcmp(c->path, path) && + !strcmp(c->name, name)) { + if (c->prev) + c->prev->next = c->next; + else + parent->cookies = c->next; + if (c->next) + c->next->prev = c->prev; + if (!parent->cookies) + cookies_update(domain, NULL); + urldb_free_cookie(c); + return; + } + } + + for (struct path_data *p = parent->children; p; p = p->next) + urldb_delete_cookie_paths(domain, path, name, p); +} + /** * Save persistent cookies to file * diff --git a/content/urldb.h b/content/urldb.h index 699c89674..20d97ebca 100644 --- a/content/urldb.h +++ b/content/urldb.h @@ -96,6 +96,7 @@ void urldb_dump(void); /* Cookies */ bool urldb_set_cookie(const char *header, const char *url); char *urldb_get_cookie(const char *url, const char *referer); +void urldb_delete_cookie(const char *domain, const char *path, const char *name); void urldb_load_cookies(const char *filename); void urldb_save_cookies(const char *filename); diff --git a/desktop/tree.c b/desktop/tree.c index 965aacec4..ea3797d03 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -843,8 +843,11 @@ void tree_delink_node(struct node *node) { node->parent->child = node->next; if (node->parent->last_child == node) node->parent->last_child = node->previous; - if (node->parent->child == NULL) - node->parent->expanded = false; + if (node->parent->child == NULL) { + /* don't contract top-level node */ + if (node->parent->parent) + node->parent->expanded = false; + } node->parent = NULL; } if (node->previous) @@ -884,9 +887,7 @@ void tree_delete_selected_nodes(struct tree *tree, struct node *node) { * \param siblings whether to delete all siblings */ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) { - tree_delete_node_internal(tree, node, siblings); - if (tree->root) tree_recalculate_node_positions(tree, tree->root); tree_redraw_area(tree, 0, 0, 16384, 16384); /* \todo correct area */ @@ -902,51 +903,78 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) { * \param siblings whether to delete all siblings */ void tree_delete_node_internal(struct tree *tree, struct node *node, bool siblings) { - struct node *next; - struct node *parent; - struct node_element *e, *f; + struct node *next, *child; + struct node_element *e, *f, *domain, *path; + char *domain_t, *path_t, name_t; + char *space; assert(node); - + if (tree->temp_selection == node) tree->temp_selection = NULL; if (tree->root == node) tree->root = NULL; next = node->next; - if (node->child) - tree_delete_node_internal(tree, node->child, true); - node->child = NULL; - parent = node->parent; tree_delink_node(node); + child = node->child; + node->child = NULL; + if (child) + tree_delete_node_internal(tree, child, true); if (!node->retain_in_memory) { + node->retain_in_memory = true; for (e = &node->data; e; e = f) { - f = e->next; - if (e->text) { /* we don't free non-editable titles or URLs */ if ((node->editable) || (node->folder)) free(e->text); else { - if (e->data == TREE_ELEMENT_URL) { - /* reset URL characteristics */ - urldb_reset_url_visit_data(e->text); - } - - /* if not already 'deleted' then delete cookie */ + /* only reset non-deleted items */ if (!node->deleted) { - /* todo: delete cookie data */ + if (e->data == TREE_ELEMENT_URL) { + /* reset URL characteristics */ + urldb_reset_url_visit_data(e->text); + } else if (e->data == TREE_ELEMENT_NAME) { + /* get the rest of the cookie data */ + domain = tree_find_element(node, + TREE_ELEMENT_DOMAIN); + path = tree_find_element(node, + TREE_ELEMENT_PATH); + if (domain && path) { + domain_t = domain->text + + strlen(messages_get( + "TreeDomain")) - 4; + space = strchr(domain_t, ' '); + if (space) + *space = '\0'; + path_t = path->text + + strlen(messages_get( + "TreePath")) - 4; + space = strchr(path_t, ' '); + if (space) + *space = '\0'; + name_t = e->text; + urldb_delete_cookie( + domain_t, + path_t, + e->text); + } + } } if (e->data != TREE_ELEMENT_TITLE && - e->data != TREE_ELEMENT_URL) + e->data != TREE_ELEMENT_URL) { free(e->text); + e->text = NULL; + } } } - if (e->sprite) + if (e->sprite) { free(e->sprite); /* \todo platform specific bits */ - + e->sprite = NULL; + } + f = e->next; if (e != &node->data) free(e); } @@ -1002,7 +1030,7 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) { node->folder = false; node->data.parent = node; node->data.type = NODE_ELEMENT_TEXT; - node->data.text = squash_whitespace(title); + node->data.text = strdup(squash_whitespace(title)); node->data.data = TREE_ELEMENT_TITLE; node->editable = true; if (parent) @@ -1055,15 +1083,7 @@ struct node *tree_create_URL_node(struct node *parent, assert(data); - if (!title) { - if (data->title) - title = strdup(data->title); - else - title = strdup(url); - if (!title) - return NULL; - } - node = tree_create_leaf_node(parent, title); + node = tree_create_leaf_node(parent, title ? title : url); if (!node) return NULL; @@ -1077,7 +1097,6 @@ struct node *tree_create_URL_node(struct node *parent, element->text = strdup(url); tree_update_URL_node(node, url, NULL); - return node; } @@ -1119,7 +1138,6 @@ struct node *tree_create_URL_node_shared(struct node *parent, element->text = url; tree_update_URL_node(node, url, data); - return node; } @@ -1201,7 +1219,6 @@ struct node *tree_create_cookie_node(struct node *parent, element->text = strdup(buffer); } if ((data->comment) && (strcmp(data->comment, ""))) { - LOG(("Comment: '%s'", data->comment)); element = tree_create_node_element(node, TREE_ELEMENT_COMMENT); if (element) { snprintf(buffer, 256, messages_get("TreeComment"), data->comment); diff --git a/desktop/tree.h b/desktop/tree.h index 1315099b7..5ebb906ac 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -97,6 +97,7 @@ struct tree { int height; /* <-- Tree height */ int window_width; /* <-- Tree window width */ int window_height; /* <-- Tree window height */ + bool no_drag; /* <-- Tree items can't be dragged out */ bool no_vscroll; /* <-- Tree has a vertical scroll only when needed */ bool no_furniture; /* <-- Tree does not have connecting lines */ bool single_selection; /* <-- There can only be one item selected */ diff --git a/riscos/cookies.c b/riscos/cookies.c index 173f73d69..b51720c14 100644 --- a/riscos/cookies.c +++ b/riscos/cookies.c @@ -72,6 +72,7 @@ void ro_gui_cookies_initialise(void) cookies_tree->root->expanded = true; cookies_tree->handle = (int)cookies_window; cookies_tree->movable = false; + cookies_tree->no_drag = true; ro_gui_wimp_event_set_user_data(cookies_window, cookies_tree); ro_gui_wimp_event_register_keypress(cookies_window, @@ -122,9 +123,10 @@ bool cookies_update(const char *domain, const struct cookie_data *data) struct node *child; struct node *add; const struct cookie_data *cookie = NULL; + bool expanded; assert(domain); - + /* check if we're a domain, and add get the first cookie */ if (data) for (cookie = data; cookie->prev; cookie = cookie->prev); @@ -133,11 +135,14 @@ bool cookies_update(const char *domain, const struct cookie_data *data) node = ro_gui_cookies_find(domain); if (node) { /* mark as deleted so we don't remove the cookies */ + expanded = node->expanded; for (child = node->child; child; child = child->next) child->deleted = true; if (node->child) tree_delete_node(cookies_tree, node->child, true); + /* deleting will have contracted our node */ + node->expanded = expanded; } if (!data) { if (!node) @@ -148,7 +153,7 @@ bool cookies_update(const char *domain, const struct cookie_data *data) return true; } } - + if (!node) { for (parent = cookies_tree->root->child; parent; parent = parent->next) { @@ -170,7 +175,7 @@ bool cookies_update(const char *domain, const struct cookie_data *data) for (; cookie; cookie = cookie->next) { add = tree_create_cookie_node(node, cookie); - if (!cookies_init) + if (add && !cookies_init) tree_handle_node_changed(cookies_tree, add, true, false); } diff --git a/riscos/menus.c b/riscos/menus.c index 0d71b6f3b..7b936521e 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -168,7 +168,7 @@ void ro_gui_menu_init(void) (struct ns_menu *)&iconbar_definition); /* browser menu */ - NS_MENU(68) browser_definition = { + NS_MENU(69) browser_definition = { "NetSurf", { { "Page", BROWSER_PAGE, 0 }, { "Page.PageInfo",BROWSER_PAGE_INFO, dialog_pageinfo }, @@ -225,6 +225,7 @@ void ro_gui_menu_init(void) { "Utilities.History.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, { "Utilities.Cookies", COOKIES_SHOW, 0 }, { "Utilities.Cookies.ShowCookies", COOKIES_SHOW, 0 }, + { "Utilities.Cookies.DeleteCookies", COOKIES_DELETE, 0 }, { "Utilities.FindText", BROWSER_FIND_TEXT, dialog_search }, { "Utilities.Window", NO_ACTION, 0 }, { "Utilities.Window.WindowSave", BROWSER_WINDOW_DEFAULT, 0 }, @@ -1470,6 +1471,11 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, ro_gui_tree_show(cookies_tree); return true; + case COOKIES_DELETE: + if (cookies_tree->root->child) + tree_delete_node(cookies_tree, cookies_tree->root->child, true); + return true; + /* page actions */ case BROWSER_PAGE_INFO: if (!c) @@ -1832,6 +1838,10 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, ro_gui_menu_set_entry_shaded(current_menu, action, !cookies_tree); break; + case COOKIES_DELETE: + ro_gui_menu_set_entry_shaded(current_menu, action, + !(cookies_tree && cookies_tree->root->child)); + break; /* page actions */ case BROWSER_PAGE_INFO: diff --git a/riscos/menus.h b/riscos/menus.h index 9b68fcf8a..8ce3a9d71 100644 --- a/riscos/menus.h +++ b/riscos/menus.h @@ -42,6 +42,7 @@ typedef enum { /* cookie actions */ COOKIES_SHOW, + COOKIES_DELETE, /* page actions */ BROWSER_PAGE, diff --git a/riscos/sslcert.c b/riscos/sslcert.c index 705e3f4b0..b1e4146bd 100644 --- a/riscos/sslcert.c +++ b/riscos/sslcert.c @@ -197,6 +197,7 @@ void gui_cert_verify(struct browser_window *bw, struct content *c, tree->root->expanded = true; tree->handle = (int)w; tree->movable = false; + tree->no_drag = true; tree->no_vscroll = true; tree->no_furniture = true; tree->single_selection = true; diff --git a/riscos/treeview.c b/riscos/treeview.c index ca03372f7..69b323a20 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -851,7 +851,7 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) { /* drag starts a drag operation */ if ((!tree->editing) && ((pointer->buttons == (wimp_CLICK_SELECT << 4)) || (pointer->buttons == (wimp_CLICK_ADJUST << 4)))) { - if (tree->single_selection) + if (tree->no_drag) return true; if (!node->selected) {