Create cookie jar on startup instead of waiting for an HTTP request

This commit is contained in:
Christian Dywan 2009-03-24 01:10:15 +01:00
parent 1aa158d78f
commit 15790565e8
2 changed files with 20 additions and 45 deletions

View file

@ -218,7 +218,6 @@ cookie_jar_changed_cb (SoupCookieJar* jar,
SoupCookie* new_cookie, SoupCookie* new_cookie,
gchar* filename) gchar* filename)
{ {
GObject* app;
GObject* settings; GObject* settings;
guint accept_cookies; guint accept_cookies;
@ -229,10 +228,7 @@ cookie_jar_changed_cb (SoupCookieJar* jar,
{ {
FILE *out; FILE *out;
/* FIXME: This is really a hack */ settings = g_object_get_data (G_OBJECT (jar), "midori-settings");
app = g_type_get_qdata (SOUP_TYPE_SESSION,
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"); accept_cookies = katze_object_get_enum (settings, "accept-cookies");
if (accept_cookies == 2 /* MIDORI_ACCEPT_COOKIES_NONE */) if (accept_cookies == 2 /* MIDORI_ACCEPT_COOKIES_NONE */)
{ {
@ -259,45 +255,28 @@ cookie_jar_changed_cb (SoupCookieJar* jar,
} }
static void static void
katze_http_cookies_session_request_queued_cb (SoupSession* session, katze_http_cookies_attach (SoupSessionFeature* feature,
SoupMessage* msg, SoupSession* session)
SoupSessionFeature* feature)
{ {
const gchar* filename;
SoupSessionFeature* cookie_jar; SoupSessionFeature* cookie_jar;
gchar* filename;
filename = g_object_get_data (G_OBJECT (feature), "filename");
if (!filename)
return;
cookie_jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); cookie_jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
if (!cookie_jar) g_return_if_fail (cookie_jar != NULL);
return; filename = g_object_get_data (G_OBJECT (feature), "filename");
g_return_if_fail (filename != NULL);
g_type_set_qdata (SOUP_TYPE_COOKIE_JAR,
g_quark_from_static_string ("midori-has-jar"), (void*)1);
cookie_jar_load (SOUP_COOKIE_JAR (cookie_jar), filename); cookie_jar_load (SOUP_COOKIE_JAR (cookie_jar), filename);
g_signal_connect_data (cookie_jar, "changed", g_signal_connect_data (cookie_jar, "changed",
G_CALLBACK (cookie_jar_changed_cb), g_strdup (filename), G_CALLBACK (cookie_jar_changed_cb), g_strdup (filename),
(GClosureNotify)g_free, 0); (GClosureNotify)g_free, 0);
g_signal_handlers_disconnect_by_func (session,
katze_http_cookies_session_request_queued_cb, feature);
}
static void
katze_http_cookies_attach (SoupSessionFeature* feature,
SoupSession* session)
{
g_signal_connect (session, "request-queued",
G_CALLBACK (katze_http_cookies_session_request_queued_cb), feature);
} }
static void static void
katze_http_cookies_detach (SoupSessionFeature* feature, katze_http_cookies_detach (SoupSessionFeature* feature,
SoupSession* session) SoupSession* session)
{ {
g_signal_handlers_disconnect_by_func (session, /* Nothing to do. */
katze_http_cookies_session_request_queued_cb, feature);
} }
static void static void

View file

@ -1320,6 +1320,7 @@ midori_soup_session_debug (SoupSession* session)
static void static void
midori_soup_session_prepare (SoupSession* session, midori_soup_session_prepare (SoupSession* session,
SoupCookieJar* cookie_jar,
MidoriWebSettings* settings) MidoriWebSettings* settings)
{ {
SoupSessionFeature* feature; SoupSessionFeature* feature;
@ -1341,6 +1342,7 @@ midori_soup_session_prepare (SoupSession* session,
config_file = build_config_filename ("cookies.txt"); config_file = build_config_filename ("cookies.txt");
g_object_set_data_full (G_OBJECT (feature), "filename", g_object_set_data_full (G_OBJECT (feature), "filename",
config_file, (GDestroyNotify)g_free); config_file, (GDestroyNotify)g_free);
soup_session_add_feature (session, SOUP_SESSION_FEATURE (cookie_jar));
soup_session_add_feature (session, feature); soup_session_add_feature (session, feature);
} }
@ -1644,6 +1646,7 @@ main (int argc,
KatzeItem* item; KatzeItem* item;
gchar* uri_ready; gchar* uri_ready;
KatzeNet* net; KatzeNet* net;
SoupSession* webkit_session;
SoupSession* s_session; SoupSession* s_session;
SoupCookieJar* jar; SoupCookieJar* jar;
#if HAVE_SQLITE #if HAVE_SQLITE
@ -1869,22 +1872,15 @@ main (int argc,
} }
g_string_free (error_messages, TRUE); g_string_free (error_messages, TRUE);
if (1) webkit_session = webkit_get_default_session ();
{
SoupSession* webkit_session = webkit_get_default_session ();
net = katze_net_new (); net = katze_net_new ();
s_session = katze_net_get_session (net); s_session = katze_net_get_session (net);
g_type_set_qdata (SOUP_TYPE_SESSION,
g_quark_from_static_string ("midori-app"), app);
jar = soup_cookie_jar_new (); jar = soup_cookie_jar_new ();
soup_session_add_feature (s_session, SOUP_SESSION_FEATURE (jar)); g_object_set_data (G_OBJECT (jar), "midori-settings", settings);
soup_session_add_feature (webkit_session, SOUP_SESSION_FEATURE (jar)); midori_soup_session_prepare (s_session, jar, settings);
midori_soup_session_prepare (webkit_session, jar, settings);
g_object_unref (jar); g_object_unref (jar);
midori_soup_session_prepare (s_session, settings);
midori_soup_session_prepare (webkit_session, settings);
g_object_unref (net); g_object_unref (net);
}
/* Open as many tabs as we have uris, seperated by pipes */ /* Open as many tabs as we have uris, seperated by pipes */
i = 0; i = 0;