From: Christian Dywan Date: Sun, 17 Oct 2010 20:48:32 +0000 (+0200) Subject: Implement sokoke_register_privacy_item facility X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d73b471ec4c97d361603481547159089391edb2e;p=midori Implement sokoke_register_privacy_item facility The new function allows registering callbacks which clear data, with a name and label so they show up in the Clear Private Data dialogue and the chosen items are saved. The old enumeration still keeps history, trash and the flag whether to clear when Midori quits. --- diff --git a/extensions/web-cache.c b/extensions/web-cache.c index a0266fad..d82d355e 100644 --- a/extensions/web-cache.c +++ b/extensions/web-cache.c @@ -23,11 +23,20 @@ #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; @@ -36,13 +45,10 @@ web_cache_get_cached_path (MidoriExtension* extension, 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); @@ -436,14 +442,11 @@ static void 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); @@ -456,6 +459,12 @@ web_cache_activate_cb (MidoriExtension* 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) { @@ -469,5 +478,8 @@ 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; } diff --git a/midori/main.c b/midori/main.c index 64a7583e..e5084b25 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1516,6 +1516,44 @@ midori_setup_inactivity_reset (MidoriBrowser* browser, } } +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) @@ -1736,6 +1774,15 @@ main (int argc, } #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) { @@ -2158,30 +2205,19 @@ main (int argc, 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") diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 56102bda..e0db6784 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -4164,19 +4164,17 @@ midori_browser_clear_private_data_response_cb (GtkWidget* dialog, 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); @@ -4193,66 +4191,32 @@ midori_browser_clear_private_data_response_cb (GtkWidget* dialog, } 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); @@ -4289,6 +4253,8 @@ _action_clear_private_data_activate (GtkAction* action, 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); @@ -4327,31 +4293,23 @@ _action_clear_private_data_activate (GtkAction* action, 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); diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index d6d17e4e..4aa20e72 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -87,6 +87,7 @@ struct _MidoriWebSettings gchar* ident_string; gint clear_private_data; + gchar* clear_data; }; struct _MidoriWebSettingsClass @@ -169,7 +170,8 @@ enum PROP_USER_AGENT, PROP_PREFERRED_LANGUAGES, - PROP_CLEAR_PRIVATE_DATA + PROP_CLEAR_PRIVATE_DATA, + PROP_CLEAR_DATA }; GType @@ -1085,7 +1087,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class) /** * MidoriWebSettings:clear-private-data: * - * The private data selected for deletion. + * The core data selected for deletion. * * Since: 0.1.7 */ @@ -1098,6 +1100,22 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class) 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 @@ -1505,6 +1523,9 @@ midori_web_settings_set_property (GObject* object, 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; @@ -1733,6 +1754,9 @@ midori_web_settings_get_property (GObject* object, 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; diff --git a/midori/midori-websettings.h b/midori/midori-websettings.h index a8f36788..bf621371 100644 --- a/midori/midori-websettings.h +++ b/midori/midori-websettings.h @@ -38,12 +38,12 @@ enum { 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 diff --git a/midori/sokoke.c b/midori/sokoke.c index af346c94..2389b184 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -2022,3 +2022,37 @@ sokoke_accept_languages (const gchar* const * lang_names) 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; +} diff --git a/midori/sokoke.h b/midori/sokoke.h index bd1a23e7..1788882c 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -261,4 +261,16 @@ gboolean 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__ */