mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 04:02:34 +03:00
Allow the user to delete cookies.
svn path=/trunk/netsurf/; revision=2770
This commit is contained in:
parent
81512fa939
commit
0309e937e6
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -42,6 +42,7 @@ typedef enum {
|
||||
|
||||
/* cookie actions */
|
||||
COOKIES_SHOW,
|
||||
COOKIES_DELETE,
|
||||
|
||||
/* page actions */
|
||||
BROWSER_PAGE,
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user