Implement Accept Cookies and Maximum Cookie Age preferences
This commit is contained in:
parent
7e68ef90c0
commit
86dcb8b284
3 changed files with 56 additions and 22 deletions
|
@ -1234,6 +1234,10 @@ cookie_jar_changed_cb (SoupCookieJar* jar,
|
|||
SoupCookie* new_cookie,
|
||||
gchar* filename)
|
||||
{
|
||||
MidoriApp* app;
|
||||
MidoriWebSettings* settings;
|
||||
MidoriAcceptCookies accept_cookies;
|
||||
|
||||
if (old_cookie)
|
||||
delete_cookie (filename, old_cookie);
|
||||
|
||||
|
@ -1241,15 +1245,31 @@ cookie_jar_changed_cb (SoupCookieJar* jar,
|
|||
{
|
||||
FILE *out;
|
||||
|
||||
out = fopen (filename, "a");
|
||||
if (!out)
|
||||
return;
|
||||
app = g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-app"));
|
||||
settings = katze_object_get_object (G_OBJECT (app), "settings");
|
||||
accept_cookies = katze_object_get_enum (settings, "accept-cookies");
|
||||
if (accept_cookies == MIDORI_ACCEPT_COOKIES_NONE)
|
||||
{
|
||||
soup_cookie_jar_delete_cookie (jar, new_cookie);
|
||||
}
|
||||
else if (accept_cookies == MIDORI_ACCEPT_COOKIES_SESSION
|
||||
&& new_cookie->expires)
|
||||
{
|
||||
soup_cookie_jar_delete_cookie (jar, new_cookie);
|
||||
}
|
||||
else if (new_cookie->expires)
|
||||
{
|
||||
gint age = katze_object_get_int (settings, "maximum-cookie-age");
|
||||
soup_cookie_set_max_age (new_cookie,
|
||||
age * SOUP_COOKIE_MAX_AGE_ONE_DAY);
|
||||
|
||||
if (new_cookie->expires)
|
||||
if (!(out = fopen (filename, "a")))
|
||||
return;
|
||||
write_cookie (out, new_cookie);
|
||||
|
||||
if (fclose (out) != 0)
|
||||
return;
|
||||
if (fclose (out) != 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1268,6 +1288,8 @@ cookie_jar_constructed_cb (GObject* object)
|
|||
|
||||
if (old_jar_constructed_cb)
|
||||
old_jar_constructed_cb (object);
|
||||
g_type_set_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar"), (void*)1);
|
||||
|
||||
config_path = g_build_filename (g_get_user_config_dir (),
|
||||
PACKAGE_NAME, NULL);
|
||||
|
@ -1346,18 +1368,6 @@ main (int argc,
|
|||
stock_items_init ();
|
||||
g_set_application_name (_("Midori"));
|
||||
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
/* This is a nasty trick that allows us to manipulate cookies
|
||||
even without having a pointer to the jar. */
|
||||
soup_cookie_jar_get_type ();
|
||||
SoupCookieJarClass* jar_class = g_type_class_ref (SOUP_TYPE_COOKIE_JAR);
|
||||
if (jar_class)
|
||||
{
|
||||
old_jar_constructed_cb = G_OBJECT_CLASS (jar_class)->constructed;
|
||||
G_OBJECT_CLASS (jar_class)->constructed = cookie_jar_constructed_cb;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (version)
|
||||
{
|
||||
g_print (
|
||||
|
@ -1413,6 +1423,20 @@ main (int argc,
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
/* This is a nasty trick that allows us to manipulate cookies
|
||||
even without having a pointer to the jar. */
|
||||
soup_cookie_jar_get_type ();
|
||||
SoupCookieJarClass* jar_class = g_type_class_ref (SOUP_TYPE_COOKIE_JAR);
|
||||
if (jar_class)
|
||||
{
|
||||
g_type_set_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-app"), app);
|
||||
old_jar_constructed_cb = G_OBJECT_CLASS (jar_class)->constructed;
|
||||
G_OBJECT_CLASS (jar_class)->constructed = cookie_jar_constructed_cb;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Load configuration files */
|
||||
GString* error_messages = g_string_new (NULL);
|
||||
gchar* config_path = g_build_filename (g_get_user_config_dir (),
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#if HAVE_LIBSOUP
|
||||
#include <libsoup/soup.h>
|
||||
#endif
|
||||
|
||||
struct _MidoriPreferences
|
||||
{
|
||||
GtkDialog parent_instance;
|
||||
|
@ -496,12 +500,15 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
|
|||
|
||||
/* Page "Privacy" */
|
||||
PAGE_NEW (GTK_STOCK_INDEX, _("Privacy"));
|
||||
#if 0
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
FRAME_NEW (_("Web Cookies"));
|
||||
TABLE_NEW (3, 2);
|
||||
label = katze_property_label (settings, "accept-cookies");
|
||||
INDENTED_ADD (label, 0, 1, 0, 1);
|
||||
button = katze_property_proxy (settings, "accept-cookies", NULL);
|
||||
/* If a cookie jar was created, WebKit is using Soup */
|
||||
gtk_widget_set_sensitive (button, g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar")) != NULL);
|
||||
FILLED_ADD (button, 1, 2, 0, 1);
|
||||
button = katze_property_proxy (settings, "original-cookies-only", "blurb");
|
||||
SPANNED_ADD (button, 0, 2, 1, 2);
|
||||
|
@ -509,6 +516,9 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
|
|||
INDENTED_ADD (label, 0, 1, 2, 3);
|
||||
hbox = gtk_hbox_new (FALSE, 4);
|
||||
entry = katze_property_proxy (settings, "maximum-cookie-age", NULL);
|
||||
/* If a cookie jar was created, WebKit is using Soup */
|
||||
gtk_widget_set_sensitive (entry, g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar")) != NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("days")),
|
||||
FALSE, FALSE, 0);
|
||||
|
|
|
@ -538,7 +538,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
|
|||
_("What type of cookies to accept"),
|
||||
MIDORI_TYPE_ACCEPT_COOKIES,
|
||||
MIDORI_ACCEPT_COOKIES_ALL,
|
||||
G_PARAM_READABLE));
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ORIGINAL_COOKIES_ONLY,
|
||||
|
@ -556,7 +556,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
|
|||
_("Maximum cookie age"),
|
||||
_("The maximum number of days to save cookies for"),
|
||||
0, G_MAXINT, 30,
|
||||
G_PARAM_READABLE));
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue