2006-07-13 16:46:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-07-13 16:46:02 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Cookies (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "oslib/wimp.h"
|
|
|
|
#include "oslib/wimpspriteop.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/cookies.h"
|
|
|
|
#include "desktop/tree.h"
|
|
|
|
#include "riscos/cookies.h"
|
|
|
|
#include "riscos/dialog.h"
|
|
|
|
#include "riscos/menus.h"
|
|
|
|
#include "riscos/options.h"
|
|
|
|
#include "riscos/theme.h"
|
|
|
|
#include "riscos/treeview.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
2006-07-13 16:46:02 +04:00
|
|
|
|
|
|
|
static bool ro_gui_cookies_click(wimp_pointer *pointer);
|
|
|
|
static struct node *ro_gui_cookies_find(const char *url);
|
|
|
|
|
|
|
|
/* The history window, toolbar and plot origins */
|
|
|
|
static wimp_w cookies_window;
|
|
|
|
struct tree *cookies_tree;
|
|
|
|
static bool cookies_init;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise cookies tree
|
|
|
|
*/
|
|
|
|
void ro_gui_cookies_initialise(void)
|
|
|
|
{
|
|
|
|
/* create our window */
|
|
|
|
cookies_window = ro_gui_dialog_create("tree");
|
|
|
|
ro_gui_set_window_title(cookies_window,
|
|
|
|
messages_get("Cookies"));
|
|
|
|
ro_gui_wimp_event_register_redraw_window(cookies_window,
|
|
|
|
ro_gui_tree_redraw);
|
|
|
|
ro_gui_wimp_event_register_open_window(cookies_window,
|
|
|
|
ro_gui_tree_open);
|
|
|
|
ro_gui_wimp_event_register_mouse_click(cookies_window,
|
|
|
|
ro_gui_cookies_click);
|
|
|
|
|
|
|
|
/* Create an empty tree */
|
|
|
|
cookies_tree = calloc(sizeof(struct tree), 1);
|
|
|
|
if (!cookies_tree) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cookies_tree->root = tree_create_folder_node(NULL, "Root");
|
|
|
|
if (!cookies_tree->root) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
free(cookies_tree);
|
|
|
|
cookies_tree = NULL;
|
2009-05-30 02:58:13 +04:00
|
|
|
return;
|
2006-07-13 16:46:02 +04:00
|
|
|
}
|
|
|
|
cookies_tree->root->expanded = true;
|
|
|
|
cookies_tree->handle = (int)cookies_window;
|
|
|
|
cookies_tree->movable = false;
|
2006-07-17 01:42:37 +04:00
|
|
|
cookies_tree->no_drag = true;
|
2006-07-13 16:46:02 +04:00
|
|
|
ro_gui_wimp_event_set_user_data(cookies_window,
|
|
|
|
cookies_tree);
|
|
|
|
ro_gui_wimp_event_register_keypress(cookies_window,
|
|
|
|
ro_gui_tree_keypress);
|
|
|
|
|
|
|
|
/* Create our toolbar */
|
|
|
|
cookies_tree->toolbar = ro_gui_theme_create_toolbar(NULL,
|
|
|
|
THEME_COOKIES_TOOLBAR);
|
|
|
|
if (cookies_tree->toolbar)
|
|
|
|
ro_gui_theme_attach_toolbar(cookies_tree->toolbar,
|
|
|
|
cookies_window);
|
|
|
|
|
|
|
|
cookies_init = true;
|
|
|
|
urldb_iterate_cookies(cookies_update);
|
|
|
|
cookies_init = false;
|
|
|
|
tree_initialise(cookies_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to a mouse click
|
|
|
|
*
|
|
|
|
* \param pointer the pointer state
|
|
|
|
* \return true to indicate click handled
|
|
|
|
*/
|
|
|
|
bool ro_gui_cookies_click(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
ro_gui_tree_click(pointer, cookies_tree);
|
|
|
|
if (pointer->buttons == wimp_CLICK_MENU)
|
|
|
|
ro_gui_menu_create(cookies_menu, pointer->pos.x,
|
|
|
|
pointer->pos.y, pointer->w);
|
|
|
|
else
|
|
|
|
ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform cookie addition
|
|
|
|
*
|
2006-07-16 20:10:43 +04:00
|
|
|
* \param data Cookie data for a domain, or NULL
|
2006-07-13 16:46:02 +04:00
|
|
|
* \return true (for urldb_iterate_entries)
|
|
|
|
*/
|
2006-07-16 20:10:43 +04:00
|
|
|
bool cookies_update(const char *domain, const struct cookie_data *data)
|
2006-07-13 16:46:02 +04:00
|
|
|
{
|
|
|
|
struct node *parent;
|
|
|
|
struct node *node = NULL;
|
|
|
|
struct node *child;
|
2006-07-16 20:10:43 +04:00
|
|
|
struct node *add;
|
|
|
|
const struct cookie_data *cookie = NULL;
|
2006-07-17 01:42:37 +04:00
|
|
|
bool expanded;
|
2006-07-13 16:46:02 +04:00
|
|
|
|
2006-07-16 20:10:43 +04:00
|
|
|
assert(domain);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-13 16:46:02 +04:00
|
|
|
/* check if we're a domain, and add get the first cookie */
|
2006-07-16 20:10:43 +04:00
|
|
|
if (data)
|
|
|
|
for (cookie = data; cookie->prev; cookie = cookie->prev);
|
2006-07-13 16:46:02 +04:00
|
|
|
|
|
|
|
if (!cookies_init) {
|
2006-07-16 20:10:43 +04:00
|
|
|
node = ro_gui_cookies_find(domain);
|
2006-07-13 16:46:02 +04:00
|
|
|
if (node) {
|
|
|
|
/* mark as deleted so we don't remove the cookies */
|
2006-07-17 01:42:37 +04:00
|
|
|
expanded = node->expanded;
|
2006-07-13 16:46:02 +04:00
|
|
|
for (child = node->child; child; child = child->next)
|
|
|
|
child->deleted = true;
|
|
|
|
if (node->child)
|
|
|
|
tree_delete_node(cookies_tree, node->child,
|
|
|
|
true);
|
2006-07-17 01:42:37 +04:00
|
|
|
/* deleting will have contracted our node */
|
|
|
|
node->expanded = expanded;
|
2006-07-13 16:46:02 +04:00
|
|
|
}
|
2006-07-16 20:10:43 +04:00
|
|
|
if (!data) {
|
2007-04-08 02:44:46 +04:00
|
|
|
if (!node)
|
|
|
|
return true;
|
|
|
|
tree_delete_node(cookies_tree, node, false);
|
2006-07-16 20:10:43 +04:00
|
|
|
tree_handle_node_changed(cookies_tree,
|
|
|
|
cookies_tree->root, true, false);
|
|
|
|
return true;
|
|
|
|
}
|
2006-07-13 16:46:02 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-13 16:46:02 +04:00
|
|
|
if (!node) {
|
|
|
|
for (parent = cookies_tree->root->child; parent;
|
|
|
|
parent = parent->next) {
|
2007-04-08 02:44:46 +04:00
|
|
|
if (strcmp(domain, parent->data.text) == 0)
|
2006-11-27 18:35:18 +03:00
|
|
|
break;
|
2006-07-13 16:46:02 +04:00
|
|
|
}
|
|
|
|
if (!parent) {
|
|
|
|
node = tree_create_folder_node(cookies_tree->root,
|
2006-07-16 20:10:43 +04:00
|
|
|
domain);
|
2006-07-13 16:46:02 +04:00
|
|
|
} else {
|
2007-04-08 02:44:46 +04:00
|
|
|
node = parent;
|
2006-07-13 16:46:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!node)
|
|
|
|
return true;
|
|
|
|
node->editable = false;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-16 20:10:43 +04:00
|
|
|
for (; cookie; cookie = cookie->next) {
|
|
|
|
add = tree_create_cookie_node(node, cookie);
|
2006-07-17 01:42:37 +04:00
|
|
|
if (add && !cookies_init)
|
2006-07-16 20:10:43 +04:00
|
|
|
tree_handle_node_changed(cookies_tree, add,
|
|
|
|
true, false);
|
|
|
|
}
|
2006-07-13 16:46:02 +04:00
|
|
|
if (!cookies_init) {
|
|
|
|
tree_handle_node_changed(cookies_tree, node,
|
|
|
|
true, false);
|
|
|
|
tree_redraw_area(cookies_tree,
|
|
|
|
node->box.x - NODE_INSTEP,
|
|
|
|
0, NODE_INSTEP, 16384);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an entry in the cookie tree
|
|
|
|
*
|
|
|
|
* \param url The URL to find
|
|
|
|
* \return Pointer to node, or NULL if not found
|
|
|
|
*/
|
|
|
|
struct node *ro_gui_cookies_find(const char *url)
|
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
|
|
|
|
for (node = cookies_tree->root->child; node; node = node->next) {
|
|
|
|
if (!strcmp(url, node->data.text))
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|