#define MAXLENGTH 1024 * 1024
+static gchar*
+web_cache_get_cache_dir (void)
+{
+ static gchar* cache_dir = NULL;
+ if (!cache_dir)
+ cache_dir = g_build_filename (g_get_user_cache_dir (),
+ PACKAGE_NAME, "web", NULL);
+ return cache_dir;
+}
+
static gchar*
web_cache_get_cached_path (MidoriExtension* extension,
const gchar* uri)
{
- static const gchar* cache_path = NULL;
gchar* checksum;
gchar* folder;
gchar* sub_path;
gchar* cached_filename;
gchar* cached_path;
- if (!cache_path)
- cache_path = g_build_filename (g_get_user_cache_dir (),
- PACKAGE_NAME, "web", NULL);
checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
folder = g_strdup_printf ("%c%c", checksum[0], checksum[1]);
- sub_path = g_build_path (G_DIR_SEPARATOR_S, cache_path, folder, NULL);
- /* FIXME: Wrong place? */
+ sub_path = g_build_path (G_DIR_SEPARATOR_S,
+ web_cache_get_cache_dir (), folder, NULL);
katze_mkdir_with_parents (sub_path, 0700);
g_free (folder);
web_cache_activate_cb (MidoriExtension* extension,
MidoriApp* app)
{
- gchar* cache_path = g_build_filename (g_get_user_cache_dir (),
- PACKAGE_NAME, "web", NULL);
KatzeArray* browsers;
MidoriBrowser* browser;
SoupSession* session = webkit_get_default_session ();
- katze_mkdir_with_parents (cache_path, 0700);
- g_free (cache_path);
+ katze_mkdir_with_parents (web_cache_get_cache_dir (), 0700);
g_signal_connect (session, "request-queued",
G_CALLBACK (web_cache_session_request_queued_cb), extension);
g_object_unref (browsers);
}
+static void
+web_cache_clear_cache_cb (void)
+{
+ sokoke_remove_path (web_cache_get_cache_dir (), TRUE);
+}
+
MidoriExtension*
extension_init (void)
{
g_signal_connect (extension, "activate",
G_CALLBACK (web_cache_activate_cb), NULL);
+ sokoke_register_privacy_item ("web-cache", _("Web Cache"),
+ G_CALLBACK (web_cache_clear_cache_cb));
+
return extension;
}
}
}
+static void
+midori_clear_page_icons_cb (void)
+{
+ gchar* cache = g_build_filename (g_get_user_cache_dir (),
+ PACKAGE_NAME, "icons", NULL);
+ sokoke_remove_path (cache, TRUE);
+ g_free (cache);
+}
+
+static void
+midori_clear_web_cookies_cb (void)
+{
+ SoupSession* session = webkit_get_default_session ();
+ SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
+ GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar));
+ for (; cookies != NULL; cookies = g_slist_next (cookies))
+ {
+ SoupCookie* cookie = cookies->data;
+ soup_cookie_set_max_age (cookie, 0);
+ soup_cookie_free (cookie);
+ }
+ g_slist_free (cookies);
+ /* Removing KatzeHttpCookies makes it save outstanding changes */
+ soup_session_remove_feature_by_type (session, KATZE_TYPE_HTTP_COOKIES);
+ soup_session_add_feature_by_type (session, KATZE_TYPE_HTTP_COOKIES);
+}
+
+#ifdef GDK_WINDOWING_X11
+static void
+midori_clear_flash_cookies_cb (void)
+{
+ gchar* cache = g_build_filename (g_get_home_dir (), ".macromedia",
+ "Flash_Player", NULL);
+ sokoke_remove_path (cache, TRUE);
+ g_free (cache);
+}
+#endif
+
int
main (int argc,
char** argv)
}
#endif
+ sokoke_register_privacy_item ("page-icons", _("Website icons"),
+ G_CALLBACK (midori_clear_page_icons_cb));
+ sokoke_register_privacy_item ("web-cookies", _("Cookies"),
+ G_CALLBACK (midori_clear_web_cookies_cb));
+ #ifdef GDK_WINDOWING_X11
+ sokoke_register_privacy_item ("flash-cookies", _("'Flash' Cookies"),
+ G_CALLBACK (midori_clear_flash_cookies_cb));
+ #endif
+
/* Web Application support */
if (webapp)
{
g_object_get (settings, "clear-private-data", &clear_prefs, NULL);
if (clear_prefs & MIDORI_CLEAR_ON_QUIT)
{
+ GList* data_items = sokoke_register_privacy_item (NULL, NULL, NULL);
+ gchar* clear_data = katze_object_get_string (settings, "clear-data");
+
midori_remove_config_file (clear_prefs, MIDORI_CLEAR_HISTORY, "history.db");
- midori_remove_config_file (clear_prefs, MIDORI_CLEAR_COOKIES, "cookies.txt");
- if ((clear_prefs & MIDORI_CLEAR_FLASH_COOKIES) == MIDORI_CLEAR_FLASH_COOKIES)
- {
- gchar* cache = g_build_filename (g_get_home_dir (), ".macromedia",
- "Flash_Player", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- }
- if ((clear_prefs & MIDORI_CLEAR_WEBSITE_ICONS) == MIDORI_CLEAR_WEBSITE_ICONS)
- {
- gchar* cache = g_build_filename (g_get_user_cache_dir (),
- PACKAGE_NAME, "icons", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- }
midori_remove_config_file (clear_prefs, MIDORI_CLEAR_TRASH, "tabtrash.xbel");
- if ((clear_prefs & MIDORI_CLEAR_WEB_CACHE) == MIDORI_CLEAR_WEB_CACHE)
+
+ for (; data_items != NULL; data_items = g_list_next (data_items))
{
- gchar* cache = g_build_filename (g_get_user_cache_dir (),
- PACKAGE_NAME, "web", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
+ SokokePrivacyItem* privacy = data_items->data;
+ if (clear_data && strstr (clear_data, privacy->name))
+ privacy->clear ();
}
+ g_free (clear_data);
}
if (katze_object_get_int (settings, "load-on-startup")
GtkToggleButton* button;
gint clear_prefs = MIDORI_CLEAR_NONE;
gint saved_prefs = MIDORI_CLEAR_NONE;
-
+ GList* data_items = sokoke_register_privacy_item (NULL, NULL, NULL);
+ GString* clear_data = g_string_new (NULL);
g_object_get (browser->settings, "clear-private-data", &saved_prefs, NULL);
button = g_object_get_data (G_OBJECT (dialog), "history");
if (gtk_toggle_button_get_active (button))
{
- const gchar* sqlcmd;
- sqlite3* db;
+ const gchar* sqlcmd = "DELETE FROM history";
+ sqlite3* db = g_object_get_data (G_OBJECT (browser->history), "db");
char* errmsg = NULL;
- db = g_object_get_data (G_OBJECT (browser->history), "db");
- sqlcmd = "DELETE FROM history";
-
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
{
g_printerr (_("Failed to clear history: %s\n"), errmsg);
}
clear_prefs |= MIDORI_CLEAR_HISTORY;
}
- button = g_object_get_data (G_OBJECT (dialog), "cookies");
- if (gtk_toggle_button_get_active (button))
- {
- SoupSession* session = webkit_get_default_session ();
- SoupSessionFeature* jar = soup_session_get_feature (session,
- SOUP_TYPE_COOKIE_JAR);
- GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar));
- SoupCookie* cookie;
- gsize i = 0;
- while ((cookie = g_slist_nth_data (cookies, i++)))
- {
- soup_cookie_jar_delete_cookie (SOUP_COOKIE_JAR (jar), cookie);
- soup_cookie_free (cookie);
- }
- g_slist_free (cookies);
- clear_prefs |= MIDORI_CLEAR_COOKIES;
- }
- button = g_object_get_data (G_OBJECT (dialog), "flash-cookies");
- if (gtk_toggle_button_get_active (button))
- {
- gchar* cache = g_build_filename (g_get_home_dir (), ".macromedia",
- "Flash_Player", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- clear_prefs |= MIDORI_CLEAR_FLASH_COOKIES;
- }
- button = g_object_get_data (G_OBJECT (dialog), "website-icons");
- if (gtk_toggle_button_get_active (button))
- {
- gchar* cache = g_build_filename (g_get_user_cache_dir (),
- PACKAGE_NAME, "icons", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- clear_prefs |= MIDORI_CLEAR_WEBSITE_ICONS;
- }
button = g_object_get_data (G_OBJECT (dialog), "trash");
- if (gtk_toggle_button_get_active (button))
+ if (gtk_toggle_button_get_active (button) && browser->trash)
{
- if (browser->trash)
- {
- katze_array_clear (browser->trash);
- _midori_browser_update_actions (browser);
- }
+ katze_array_clear (browser->trash);
+ _midori_browser_update_actions (browser);
clear_prefs |= MIDORI_CLEAR_TRASH;
}
- button = g_object_get_data (G_OBJECT (dialog), "web-cache");
- if (gtk_toggle_button_get_active (button))
- {
- gchar* cache = g_build_filename (g_get_user_cache_dir (),
- PACKAGE_NAME, "web", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- clear_prefs |= MIDORI_CLEAR_WEB_CACHE;
- }
-
if (clear_prefs != saved_prefs)
{
clear_prefs |= (saved_prefs & MIDORI_CLEAR_ON_QUIT);
g_object_set (browser->settings, "clear-private-data", clear_prefs, NULL);
}
+ for (; data_items != NULL; data_items = g_list_next (data_items))
+ {
+ SokokePrivacyItem* privacy = data_items->data;
+ button = g_object_get_data (G_OBJECT (dialog), privacy->name);
+ g_return_if_fail (button != NULL && GTK_IS_TOGGLE_BUTTON (button));
+ if (gtk_toggle_button_get_active (button))
+ {
+ privacy->clear ();
+ g_string_append (clear_data, privacy->name);
+ g_string_append_c (clear_data, ',');
+ }
+ }
+ g_object_set (browser->settings, "clear-data", clear_data->str, NULL);
+ g_string_free (clear_data, TRUE);
}
if (response_id != GTK_RESPONSE_DELETE_EVENT)
gtk_widget_destroy (dialog);
GtkWidget* icon;
GtkWidget* label;
GtkWidget* button;
+ GList* data_items;
+ gchar* clear_data = katze_object_get_string (browser->settings, "clear-data");
gint clear_prefs = MIDORI_CLEAR_NONE;
g_object_get (browser->settings, "clear-private-data", &clear_prefs, NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
g_object_set_data (G_OBJECT (dialog), "history", button);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
- button = gtk_check_button_new_with_mnemonic (_("Cookies"));
- if ((clear_prefs & MIDORI_CLEAR_COOKIES) == MIDORI_CLEAR_COOKIES)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_object_set_data (G_OBJECT (dialog), "cookies", button);
- gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
- button = gtk_check_button_new_with_mnemonic (_("'Flash' Cookies"));
- if ((clear_prefs & MIDORI_CLEAR_FLASH_COOKIES) == MIDORI_CLEAR_FLASH_COOKIES)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_object_set_data (G_OBJECT (dialog), "flash-cookies", button);
- gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
- button = gtk_check_button_new_with_mnemonic (_("Website icons"));
- if ((clear_prefs & MIDORI_CLEAR_WEBSITE_ICONS) == MIDORI_CLEAR_WEBSITE_ICONS)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_object_set_data (G_OBJECT (dialog), "website-icons", button);
- gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
button = gtk_check_button_new_with_mnemonic (_("_Closed Tabs"));
if ((clear_prefs & MIDORI_CLEAR_TRASH) == MIDORI_CLEAR_TRASH)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
g_object_set_data (G_OBJECT (dialog), "trash", button);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
- button = gtk_check_button_new_with_mnemonic (_("Web Cache"));
- if ((clear_prefs & MIDORI_CLEAR_WEB_CACHE) == MIDORI_CLEAR_WEB_CACHE)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_object_set_data (G_OBJECT (dialog), "web-cache", button);
- gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+
+ data_items = sokoke_register_privacy_item (NULL, NULL, NULL);
+ for (; data_items != NULL; data_items = g_list_next (data_items))
+ {
+ SokokePrivacyItem* privacy = data_items->data;
+ button = gtk_check_button_new_with_mnemonic (privacy->label);
+ gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+ g_object_set_data (G_OBJECT (dialog), privacy->name, button);
+ if (clear_data && strstr (clear_data, privacy->name))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ }
+ g_free (clear_data);
gtk_container_add (GTK_CONTAINER (alignment), vbox);
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, FALSE, 0);
gchar* ident_string;
gint clear_private_data;
+ gchar* clear_data;
};
struct _MidoriWebSettingsClass
PROP_USER_AGENT,
PROP_PREFERRED_LANGUAGES,
- PROP_CLEAR_PRIVATE_DATA
+ PROP_CLEAR_PRIVATE_DATA,
+ PROP_CLEAR_DATA
};
GType
/**
* MidoriWebSettings:clear-private-data:
*
- * The private data selected for deletion.
+ * The core data selected for deletion.
*
* Since: 0.1.7
*/
0, G_MAXINT, 0,
flags));
+ /**
+ * MidoriWebSettings:clear-data:
+ *
+ * The data selected for deletion, including extensions.
+ *
+ * Since: 0.2.9
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_CLEAR_DATA,
+ g_param_spec_string (
+ "clear-data",
+ _("Clear data"),
+ _("The data selected for deletion"),
+ NULL,
+ flags));
+
}
static void
case PROP_CLEAR_PRIVATE_DATA:
web_settings->clear_private_data = g_value_get_int (value);
break;
+ case PROP_CLEAR_DATA:
+ katze_assign (web_settings->clear_data, g_value_dup_string (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_CLEAR_PRIVATE_DATA:
g_value_set_int (value, web_settings->clear_private_data);
break;
+ case PROP_CLEAR_DATA:
+ g_value_set_string (value, web_settings->clear_data);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
{
MIDORI_CLEAR_NONE = 0,
MIDORI_CLEAR_HISTORY = 1,
- MIDORI_CLEAR_COOKIES = 2,
- MIDORI_CLEAR_FLASH_COOKIES = 4,
- MIDORI_CLEAR_WEBSITE_ICONS = 8,
+ MIDORI_CLEAR_COOKIES = 2, /* deprecated */
+ MIDORI_CLEAR_FLASH_COOKIES = 4, /* deprecated */
+ MIDORI_CLEAR_WEBSITE_ICONS = 8, /* deprecated */
MIDORI_CLEAR_TRASH = 16,
MIDORI_CLEAR_ON_QUIT = 32,
- MIDORI_CLEAR_WEB_CACHE = 64,
+ MIDORI_CLEAR_WEB_CACHE = 64, /* deprecated */
};
typedef enum
return langs_str;
}
+
+/**
+ * sokoke_register_privacy_item:
+ * @name: the name of the privacy item
+ * @label: a user visible, localized label
+ * @clear: a callback clearing data
+ *
+ * Registers an item to clear data, either via the
+ * Clear Private Data dialogue or when Midori quits.
+ *
+ * Return value: a #GList if all arguments are %NULL
+ **/
+GList*
+sokoke_register_privacy_item (const gchar* name,
+ const gchar* label,
+ GCallback clear)
+{
+ static GList* items = NULL;
+ SokokePrivacyItem* item;
+
+ if (name == NULL && label == NULL && clear == NULL)
+ return items;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (clear != NULL, NULL);
+
+ item = g_new (SokokePrivacyItem, 1);
+ item->name = g_strdup (name);
+ item->label = g_strdup (label);
+ item->clear = clear;
+ items = g_list_append (items, item);
+ return NULL;
+}
sokoke_recursive_fork_protection (const gchar* uri,
gboolean set_uri);
+typedef struct
+{
+ gchar* name;
+ gchar* label;
+ GCallback clear;
+} SokokePrivacyItem;
+
+GList*
+sokoke_register_privacy_item (const gchar* name,
+ const gchar* label,
+ GCallback clear);
+
#endif /* !__SOKOKE_H__ */