Improve handling of cookie updates

Be sure to remove outstanding times, use libsoup API
to free the list of cookies and use the cookie jar to
delete cookies.

Fixes: https://bugs.launchpad.net/midori/+bug/712770
This commit is contained in:
Christian Dywan 2011-02-20 20:55:34 +01:00
parent bb34927092
commit ea8b9ee7fe
2 changed files with 15 additions and 8 deletions

View file

@ -178,7 +178,11 @@ katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies)
gchar* temporary_filename = NULL; gchar* temporary_filename = NULL;
GSList* cookies; GSList* cookies;
if (http_cookies->timeout > 0)
{
g_source_remove (http_cookies->timeout);
http_cookies->timeout = 0; http_cookies->timeout = 0;
}
temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL); temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL);
if ((fn = g_mkstemp (temporary_filename)) == -1) if ((fn = g_mkstemp (temporary_filename)) == -1)
@ -299,7 +303,7 @@ katze_http_cookies_detach (SoupSessionFeature* feature,
SoupSession* session) SoupSession* session)
{ {
KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature; KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature;
if (http_cookies->timeout) if (http_cookies->timeout > 0)
katze_http_cookies_update_jar (http_cookies); katze_http_cookies_update_jar (http_cookies);
katze_assign (http_cookies->filename, NULL); katze_assign (http_cookies->filename, NULL);
katze_object_assign (http_cookies->jar, NULL); katze_object_assign (http_cookies->jar, NULL);

View file

@ -1563,18 +1563,21 @@ midori_clear_web_cookies_cb (void)
SoupSession* session = webkit_get_default_session (); SoupSession* session = webkit_get_default_session ();
SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar)); GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar));
SoupSessionFeature* feature;
for (; cookies != NULL; cookies = g_slist_next (cookies)) for (; cookies != NULL; cookies = g_slist_next (cookies))
{ {
SoupCookie* cookie = cookies->data; SoupCookie* cookie = cookies->data;
soup_cookie_set_max_age (cookie, 0); soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookie);
soup_cookie_free (cookie);
} }
g_slist_free (cookies); soup_cookies_free (cookies);
/* Removing KatzeHttpCookies makes it save outstanding changes */ /* Removing KatzeHttpCookies makes it save outstanding changes */
if (soup_session_get_feature (session, KATZE_TYPE_HTTP_COOKIES)) if ((feature = soup_session_get_feature (session, KATZE_TYPE_HTTP_COOKIES)))
{ {
soup_session_remove_feature_by_type (session, KATZE_TYPE_HTTP_COOKIES); g_object_ref (feature);
soup_session_add_feature_by_type (session, KATZE_TYPE_HTTP_COOKIES); soup_session_remove_feature (session, feature);
soup_session_add_feature (session, feature);
g_object_unref (feature);
} }
} }