Merge lp:~kalikiana/midori/cookieswk2 into lp:midori
- cookieswk2
- Merge into trunk
Proposed by
Cris Dywan
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | André Stösel | ||||
Approved revision: | 6268 | ||||
Merged at revision: | 6295 | ||||
Proposed branch: | lp:~kalikiana/midori/cookieswk2 | ||||
Merge into: | lp:midori | ||||
Diff against target: |
1069 lines (+82/-766) 11 files modified
extensions/cookie-manager/cookie-manager.c (+10/-2) extensions/wscript_build (+1/-1) katze/katze-http-cookies-sqlite.c (+0/-292) katze/katze-http-cookies-sqlite.h (+0/-42) katze/katze-http-cookies.c (+0/-331) katze/katze-http-cookies.h (+0/-42) katze/katze.h (+0/-2) midori/midori-frontend.c (+0/-5) midori/midori-privatedata.c (+11/-10) midori/midori-session.c (+59/-38) wscript (+1/-1) |
||||
To merge this branch: | bzr merge lp:~kalikiana/midori/cookieswk2 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
André Stösel | Approve | ||
Review via email: mp+174885@code.launchpad.net |
Commit message
WebKit2 cookie support
Description of the change
To post a comment you must log in.
lp:~kalikiana/midori/cookieswk2
updated
- 6267. By Cris Dywan
-
Move gchar* cache and disable cookie/ session callbacks
- 6268. By Cris Dywan
-
Unblock cookie manager from WebKit2 build
Revision history for this message
Cris Dywan (kalikiana) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'extensions/cookie-manager/cookie-manager.c' | |||
2 | --- extensions/cookie-manager/cookie-manager.c 2013-02-21 21:36:30 +0000 | |||
3 | +++ extensions/cookie-manager/cookie-manager.c 2013-07-29 21:07:25 +0000 | |||
4 | @@ -12,6 +12,7 @@ | |||
5 | 12 | #include "config.h" | 12 | #include "config.h" |
6 | 13 | #include <midori/midori.h> | 13 | #include <midori/midori.h> |
7 | 14 | #include "katze/katze.h" | 14 | #include "katze/katze.h" |
8 | 15 | #include <libsoup/soup-cookie-jar-sqlite.h> | ||
9 | 15 | 16 | ||
10 | 16 | #include "cookie-manager.h" | 17 | #include "cookie-manager.h" |
11 | 17 | #include "cookie-manager-page.h" | 18 | #include "cookie-manager-page.h" |
12 | @@ -259,6 +260,7 @@ | |||
13 | 259 | 260 | ||
14 | 260 | g_object_unref(priv->store); | 261 | g_object_unref(priv->store); |
15 | 261 | g_free(priv->filter_text); | 262 | g_free(priv->filter_text); |
16 | 263 | g_object_unref(priv->jar); | ||
17 | 262 | 264 | ||
18 | 263 | G_OBJECT_CLASS(cookie_manager_parent_class)->finalize(object); | 265 | G_OBJECT_CLASS(cookie_manager_parent_class)->finalize(object); |
19 | 264 | } | 266 | } |
20 | @@ -267,7 +269,6 @@ | |||
21 | 267 | static void cookie_manager_init(CookieManager *self) | 269 | static void cookie_manager_init(CookieManager *self) |
22 | 268 | { | 270 | { |
23 | 269 | CookieManagerPrivate *priv; | 271 | CookieManagerPrivate *priv; |
24 | 270 | SoupSession *session; | ||
25 | 271 | 272 | ||
26 | 272 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, | 273 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, |
27 | 273 | COOKIE_MANAGER_TYPE, CookieManagerPrivate); | 274 | COOKIE_MANAGER_TYPE, CookieManagerPrivate); |
28 | @@ -279,8 +280,15 @@ | |||
29 | 279 | COOKIE_MANAGER_COL_NAME, GTK_SORT_ASCENDING); | 280 | COOKIE_MANAGER_COL_NAME, GTK_SORT_ASCENDING); |
30 | 280 | 281 | ||
31 | 281 | /* setup soup */ | 282 | /* setup soup */ |
33 | 282 | session = webkit_get_default_session(); | 283 | #ifdef HAVE_WEBKIT2 |
34 | 284 | gchar *filename = midori_paths_get_config_filename_for_writing ("cookies.db"); | ||
35 | 285 | priv->jar = soup_cookie_jar_sqlite_new (filename, FALSE); | ||
36 | 286 | g_free(filename); | ||
37 | 287 | #else | ||
38 | 288 | SoupSession *session = webkit_get_default_session(); | ||
39 | 283 | priv->jar = SOUP_COOKIE_JAR(soup_session_get_feature(session, soup_cookie_jar_get_type())); | 289 | priv->jar = SOUP_COOKIE_JAR(soup_session_get_feature(session, soup_cookie_jar_get_type())); |
40 | 290 | g_object_ref(priv->jar); | ||
41 | 291 | #endif | ||
42 | 284 | g_signal_connect(priv->jar, "changed", G_CALLBACK(cookie_manager_jar_changed_cb), self); | 292 | g_signal_connect(priv->jar, "changed", G_CALLBACK(cookie_manager_jar_changed_cb), self); |
43 | 285 | 293 | ||
44 | 286 | cookie_manager_refresh_store(self); | 294 | cookie_manager_refresh_store(self); |
45 | 287 | 295 | ||
46 | === modified file 'extensions/wscript_build' | |||
47 | --- extensions/wscript_build 2013-06-03 19:37:36 +0000 | |||
48 | +++ extensions/wscript_build 2013-07-29 21:07:25 +0000 | |||
49 | @@ -32,7 +32,7 @@ | |||
50 | 32 | source = extension | 32 | source = extension |
51 | 33 | 33 | ||
52 | 34 | # FIXME | 34 | # FIXME |
54 | 35 | if bld.env['HAVE_WEBKIT2'] and target in ['external-download-manager', 'nsplugin-manager', 'formhistory', 'adblock', 'cookie-permissions', 'addons', 'cookie-manager']: | 35 | if bld.env['HAVE_WEBKIT2'] and target in ['external-download-manager', 'nsplugin-manager', 'formhistory', 'adblock', 'cookie-permissions', 'addons']: |
55 | 36 | continue | 36 | continue |
56 | 37 | 37 | ||
57 | 38 | obj = bld.new_task_gen ('cc', 'shlib') | 38 | obj = bld.new_task_gen ('cc', 'shlib') |
58 | 39 | 39 | ||
59 | === removed file 'katze/katze-http-cookies-sqlite.c' | |||
60 | --- katze/katze-http-cookies-sqlite.c 2012-07-19 19:14:09 +0000 | |||
61 | +++ katze/katze-http-cookies-sqlite.c 1970-01-01 00:00:00 +0000 | |||
62 | @@ -1,292 +0,0 @@ | |||
63 | 1 | /* | ||
64 | 2 | Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de> | ||
65 | 3 | Copyright (C) 2011 Alexander Butenko <a.butenka@gmail.com> | ||
66 | 4 | |||
67 | 5 | This library is free software; you can redistribute it and/or | ||
68 | 6 | modify it under the terms of the GNU Lesser General Public | ||
69 | 7 | License as published by the Free Software Foundation; either | ||
70 | 8 | version 2.1 of the License, or (at your option) any later version. | ||
71 | 9 | |||
72 | 10 | See the file COPYING for the full license text. | ||
73 | 11 | */ | ||
74 | 12 | |||
75 | 13 | #if HAVE_CONFIG_H | ||
76 | 14 | #include <config.h> | ||
77 | 15 | #endif | ||
78 | 16 | |||
79 | 17 | #include "katze-http-cookies-sqlite.h" | ||
80 | 18 | |||
81 | 19 | #include <stdlib.h> | ||
82 | 20 | #ifdef HAVE_UNISTD_H | ||
83 | 21 | #include <unistd.h> | ||
84 | 22 | #endif | ||
85 | 23 | #include <glib/gi18n.h> | ||
86 | 24 | #include <libsoup/soup.h> | ||
87 | 25 | #include <gtk/gtk.h> | ||
88 | 26 | #include <glib/gstdio.h> | ||
89 | 27 | #include <sqlite3.h> | ||
90 | 28 | |||
91 | 29 | #define QUERY_ALL "SELECT id, name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly FROM moz_cookies;" | ||
92 | 30 | #define CREATE_TABLE "CREATE TABLE IF NOT EXISTS moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER)" | ||
93 | 31 | #define QUERY_INSERT "INSERT INTO moz_cookies VALUES(NULL, %Q, %Q, %Q, %Q, %d, NULL, %d, %d);" | ||
94 | 32 | #define QUERY_DELETE "DELETE FROM moz_cookies WHERE name=%Q AND host=%Q;" | ||
95 | 33 | |||
96 | 34 | enum { | ||
97 | 35 | COL_ID, | ||
98 | 36 | COL_NAME, | ||
99 | 37 | COL_VALUE, | ||
100 | 38 | COL_HOST, | ||
101 | 39 | COL_PATH, | ||
102 | 40 | COL_EXPIRY, | ||
103 | 41 | COL_LAST_ACCESS, | ||
104 | 42 | COL_SECURE, | ||
105 | 43 | COL_HTTP_ONLY, | ||
106 | 44 | N_COL, | ||
107 | 45 | }; | ||
108 | 46 | |||
109 | 47 | struct _KatzeHttpCookiesSqlite | ||
110 | 48 | { | ||
111 | 49 | GObject parent_instance; | ||
112 | 50 | gchar* filename; | ||
113 | 51 | SoupCookieJar* jar; | ||
114 | 52 | sqlite3 *db; | ||
115 | 53 | guint counter; | ||
116 | 54 | }; | ||
117 | 55 | |||
118 | 56 | struct _KatzeHttpCookiesSqliteClass | ||
119 | 57 | { | ||
120 | 58 | GObjectClass parent_class; | ||
121 | 59 | }; | ||
122 | 60 | |||
123 | 61 | static void | ||
124 | 62 | katze_http_cookies_sqlite_session_feature_iface_init (SoupSessionFeatureInterface *iface, | ||
125 | 63 | gpointer data); | ||
126 | 64 | |||
127 | 65 | G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookiesSqlite, katze_http_cookies_sqlite, G_TYPE_OBJECT, | ||
128 | 66 | G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, | ||
129 | 67 | katze_http_cookies_sqlite_session_feature_iface_init)); | ||
130 | 68 | |||
131 | 69 | /* Cookie jar saving into sqlite database | ||
132 | 70 | Copyright (C) 2008 Diego Escalante Urrelo | ||
133 | 71 | Copyright (C) 2009 Collabora Ltd. | ||
134 | 72 | Mostly copied from libSoup 2.30, coding style retained */ | ||
135 | 73 | |||
136 | 74 | /* Follows sqlite3 convention; returns TRUE on error */ | ||
137 | 75 | static gboolean | ||
138 | 76 | katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies) | ||
139 | 77 | { | ||
140 | 78 | char *error = NULL; | ||
141 | 79 | |||
142 | 80 | if (sqlite3_open (http_cookies->filename, &http_cookies->db)) { | ||
143 | 81 | sqlite3_close (http_cookies->db); | ||
144 | 82 | g_warning ("Can't open %s", http_cookies->filename); | ||
145 | 83 | return TRUE; | ||
146 | 84 | } | ||
147 | 85 | |||
148 | 86 | if (sqlite3_exec (http_cookies->db, CREATE_TABLE, NULL, NULL, &error)) { | ||
149 | 87 | g_warning ("Failed to execute query: %s", error); | ||
150 | 88 | sqlite3_free (error); | ||
151 | 89 | } | ||
152 | 90 | |||
153 | 91 | if (sqlite3_exec (http_cookies->db, "PRAGMA secure_delete = 1;", | ||
154 | 92 | NULL, NULL, &error)) { | ||
155 | 93 | g_warning ("Failed to execute query: %s", error); | ||
156 | 94 | sqlite3_free (error); | ||
157 | 95 | } | ||
158 | 96 | |||
159 | 97 | sqlite3_exec (http_cookies->db, | ||
160 | 98 | /* Arguably cookies are like a cache, so performance over integrity */ | ||
161 | 99 | "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" | ||
162 | 100 | "PRAGMA count_changes = OFF; PRAGMA journal_mode = TRUNCATE;", | ||
163 | 101 | NULL, NULL, &error); | ||
164 | 102 | |||
165 | 103 | return FALSE; | ||
166 | 104 | } | ||
167 | 105 | |||
168 | 106 | static void | ||
169 | 107 | katze_http_cookies_sqlite_load (KatzeHttpCookiesSqlite* http_cookies) | ||
170 | 108 | { | ||
171 | 109 | const char *name, *value, *host, *path; | ||
172 | 110 | sqlite3_stmt* stmt; | ||
173 | 111 | SoupCookie *cookie = NULL; | ||
174 | 112 | gint64 expire_time; | ||
175 | 113 | time_t now; | ||
176 | 114 | int max_age; | ||
177 | 115 | gboolean http_only = FALSE, secure = FALSE; | ||
178 | 116 | char *query; | ||
179 | 117 | int result; | ||
180 | 118 | |||
181 | 119 | if (http_cookies->db == NULL) { | ||
182 | 120 | if (katze_http_cookies_sqlite_open_db (http_cookies)) | ||
183 | 121 | return; | ||
184 | 122 | } | ||
185 | 123 | |||
186 | 124 | sqlite3_prepare_v2 (http_cookies->db, QUERY_ALL, strlen (QUERY_ALL) + 1, &stmt, NULL); | ||
187 | 125 | result = sqlite3_step (stmt); | ||
188 | 126 | if (result != SQLITE_ROW) | ||
189 | 127 | { | ||
190 | 128 | if (result == SQLITE_ERROR) | ||
191 | 129 | g_print (_("Failed to load cookies\n")); | ||
192 | 130 | sqlite3_reset (stmt); | ||
193 | 131 | return; | ||
194 | 132 | } | ||
195 | 133 | |||
196 | 134 | while (result == SQLITE_ROW) | ||
197 | 135 | { | ||
198 | 136 | now = time (NULL); | ||
199 | 137 | name = (const char*)sqlite3_column_text (stmt, COL_NAME); | ||
200 | 138 | value = (const char*)sqlite3_column_text (stmt, COL_VALUE); | ||
201 | 139 | host = (const char*)sqlite3_column_text (stmt, COL_HOST); | ||
202 | 140 | path = (const char*)sqlite3_column_text (stmt, COL_PATH); | ||
203 | 141 | expire_time = sqlite3_column_int64 (stmt,COL_EXPIRY); | ||
204 | 142 | secure = sqlite3_column_int (stmt, COL_SECURE); | ||
205 | 143 | http_only = sqlite3_column_int (stmt, COL_HTTP_ONLY); | ||
206 | 144 | |||
207 | 145 | if (now >= expire_time) | ||
208 | 146 | { | ||
209 | 147 | /* Cookie expired, remove it from database */ | ||
210 | 148 | query = sqlite3_mprintf (QUERY_DELETE, name, host); | ||
211 | 149 | sqlite3_exec (http_cookies->db, QUERY_DELETE, NULL, NULL, NULL); | ||
212 | 150 | sqlite3_free (query); | ||
213 | 151 | result = sqlite3_step (stmt); | ||
214 | 152 | continue; | ||
215 | 153 | } | ||
216 | 154 | max_age = (expire_time - now <= G_MAXINT ? expire_time - now : G_MAXINT); | ||
217 | 155 | cookie = soup_cookie_new (name, value, host, path, max_age); | ||
218 | 156 | |||
219 | 157 | if (secure) | ||
220 | 158 | soup_cookie_set_secure (cookie, TRUE); | ||
221 | 159 | if (http_only) | ||
222 | 160 | soup_cookie_set_http_only (cookie, TRUE); | ||
223 | 161 | |||
224 | 162 | soup_cookie_jar_add_cookie (http_cookies->jar, cookie); | ||
225 | 163 | result = sqlite3_step (stmt); | ||
226 | 164 | } | ||
227 | 165 | |||
228 | 166 | if (stmt) | ||
229 | 167 | { | ||
230 | 168 | sqlite3_reset (stmt); | ||
231 | 169 | sqlite3_clear_bindings (stmt); | ||
232 | 170 | } | ||
233 | 171 | } | ||
234 | 172 | static void | ||
235 | 173 | katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar, | ||
236 | 174 | SoupCookie* old_cookie, | ||
237 | 175 | SoupCookie* new_cookie, | ||
238 | 176 | KatzeHttpCookiesSqlite* http_cookies) | ||
239 | 177 | { | ||
240 | 178 | GObject* settings; | ||
241 | 179 | char *query; | ||
242 | 180 | time_t expires = 0; /* Avoid warning */ | ||
243 | 181 | |||
244 | 182 | if (http_cookies->db == NULL) { | ||
245 | 183 | if (katze_http_cookies_sqlite_open_db (http_cookies)) | ||
246 | 184 | return; | ||
247 | 185 | } | ||
248 | 186 | |||
249 | 187 | if (new_cookie && new_cookie->expires) | ||
250 | 188 | { | ||
251 | 189 | gint age; | ||
252 | 190 | |||
253 | 191 | expires = soup_date_to_time_t (new_cookie->expires); | ||
254 | 192 | settings = g_object_get_data (G_OBJECT (jar), "midori-settings"); | ||
255 | 193 | age = katze_object_get_int (settings, "maximum-cookie-age"); | ||
256 | 194 | if (age > 0) | ||
257 | 195 | { | ||
258 | 196 | SoupDate* max_date = soup_date_new_from_now ( | ||
259 | 197 | age * SOUP_COOKIE_MAX_AGE_ONE_DAY); | ||
260 | 198 | if (soup_date_to_time_t (new_cookie->expires) | ||
261 | 199 | > soup_date_to_time_t (max_date)) | ||
262 | 200 | soup_cookie_set_expires (new_cookie, max_date); | ||
263 | 201 | } | ||
264 | 202 | else | ||
265 | 203 | { | ||
266 | 204 | /* An age of 0 to SoupCookie means already-expired | ||
267 | 205 | A user choosing 0 days probably expects 1 hour. */ | ||
268 | 206 | soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); | ||
269 | 207 | } | ||
270 | 208 | } | ||
271 | 209 | |||
272 | 210 | if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) | ||
273 | 211 | http_cookies->counter++; | ||
274 | 212 | |||
275 | 213 | if (old_cookie) { | ||
276 | 214 | query = sqlite3_mprintf (QUERY_DELETE, | ||
277 | 215 | old_cookie->name, | ||
278 | 216 | old_cookie->domain); | ||
279 | 217 | sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL); | ||
280 | 218 | sqlite3_free (query); | ||
281 | 219 | } | ||
282 | 220 | |||
283 | 221 | if (new_cookie && new_cookie->expires) { | ||
284 | 222 | |||
285 | 223 | query = sqlite3_mprintf (QUERY_INSERT, | ||
286 | 224 | new_cookie->name, | ||
287 | 225 | new_cookie->value, | ||
288 | 226 | new_cookie->domain, | ||
289 | 227 | new_cookie->path, | ||
290 | 228 | expires, | ||
291 | 229 | new_cookie->secure, | ||
292 | 230 | new_cookie->http_only); | ||
293 | 231 | sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL); | ||
294 | 232 | sqlite3_free (query); | ||
295 | 233 | } | ||
296 | 234 | } | ||
297 | 235 | |||
298 | 236 | static void | ||
299 | 237 | katze_http_cookies_sqlite_attach (SoupSessionFeature* feature, | ||
300 | 238 | SoupSession* session) | ||
301 | 239 | { | ||
302 | 240 | KatzeHttpCookiesSqlite* http_cookies = (KatzeHttpCookiesSqlite*)feature; | ||
303 | 241 | const gchar* filename = g_object_get_data (G_OBJECT (feature), "filename"); | ||
304 | 242 | SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); | ||
305 | 243 | g_return_if_fail (jar != NULL); | ||
306 | 244 | g_return_if_fail (filename != NULL); | ||
307 | 245 | katze_assign (http_cookies->filename, g_strdup (filename)); | ||
308 | 246 | http_cookies->jar = g_object_ref (jar); | ||
309 | 247 | katze_http_cookies_sqlite_open_db (http_cookies); | ||
310 | 248 | katze_http_cookies_sqlite_load (http_cookies); | ||
311 | 249 | g_signal_connect (jar, "changed", | ||
312 | 250 | G_CALLBACK (katze_http_cookies_sqlite_jar_changed_cb), feature); | ||
313 | 251 | |||
314 | 252 | } | ||
315 | 253 | |||
316 | 254 | static void | ||
317 | 255 | katze_http_cookies_sqlite_detach (SoupSessionFeature* feature, | ||
318 | 256 | SoupSession* session) | ||
319 | 257 | { | ||
320 | 258 | KatzeHttpCookiesSqlite* http_cookies = (KatzeHttpCookiesSqlite*)feature; | ||
321 | 259 | katze_assign (http_cookies->filename, NULL); | ||
322 | 260 | katze_object_assign (http_cookies->jar, NULL); | ||
323 | 261 | sqlite3_close (http_cookies->db); | ||
324 | 262 | } | ||
325 | 263 | |||
326 | 264 | static void | ||
327 | 265 | katze_http_cookies_sqlite_session_feature_iface_init (SoupSessionFeatureInterface *iface, | ||
328 | 266 | gpointer data) | ||
329 | 267 | { | ||
330 | 268 | iface->attach = katze_http_cookies_sqlite_attach; | ||
331 | 269 | iface->detach = katze_http_cookies_sqlite_detach; | ||
332 | 270 | } | ||
333 | 271 | |||
334 | 272 | static void | ||
335 | 273 | katze_http_cookies_sqlite_finalize (GObject* object) | ||
336 | 274 | { | ||
337 | 275 | katze_http_cookies_sqlite_detach ((SoupSessionFeature*)object, NULL); | ||
338 | 276 | } | ||
339 | 277 | |||
340 | 278 | static void | ||
341 | 279 | katze_http_cookies_sqlite_class_init (KatzeHttpCookiesSqliteClass* class) | ||
342 | 280 | { | ||
343 | 281 | GObjectClass* gobject_class = (GObjectClass*)class; | ||
344 | 282 | gobject_class->finalize = katze_http_cookies_sqlite_finalize; | ||
345 | 283 | } | ||
346 | 284 | |||
347 | 285 | static void | ||
348 | 286 | katze_http_cookies_sqlite_init (KatzeHttpCookiesSqlite* http_cookies) | ||
349 | 287 | { | ||
350 | 288 | http_cookies->filename = NULL; | ||
351 | 289 | http_cookies->jar = NULL; | ||
352 | 290 | http_cookies->db = NULL; | ||
353 | 291 | http_cookies->counter = 0; | ||
354 | 292 | } | ||
355 | 293 | 0 | ||
356 | === removed file 'katze/katze-http-cookies-sqlite.h' | |||
357 | --- katze/katze-http-cookies-sqlite.h 2011-10-10 21:22:27 +0000 | |||
358 | +++ katze/katze-http-cookies-sqlite.h 1970-01-01 00:00:00 +0000 | |||
359 | @@ -1,42 +0,0 @@ | |||
360 | 1 | /* | ||
361 | 2 | Copyright (C) 2009 Christian Dywan <christian@twotoasts.de> | ||
362 | 3 | |||
363 | 4 | This library is free software; you can redistribute it and/or | ||
364 | 5 | modify it under the terms of the GNU Lesser General Public | ||
365 | 6 | License as published by the Free Software Foundation; either | ||
366 | 7 | version 2.1 of the License, or (at your option) any later version. | ||
367 | 8 | |||
368 | 9 | See the file COPYING for the full license text. | ||
369 | 10 | */ | ||
370 | 11 | |||
371 | 12 | #ifndef __KATZE_HTTP_COOKIES_SQLITE_H__ | ||
372 | 13 | #define __KATZE_HTTP_COOKIES_SQLITE_H__ | ||
373 | 14 | |||
374 | 15 | #include "katze-utils.h" | ||
375 | 16 | |||
376 | 17 | #include <glib-object.h> | ||
377 | 18 | |||
378 | 19 | G_BEGIN_DECLS | ||
379 | 20 | |||
380 | 21 | #define KATZE_TYPE_HTTP_COOKIES_SQLITE \ | ||
381 | 22 | (katze_http_cookies_sqlite_get_type ()) | ||
382 | 23 | #define KATZE_HTTP_COOKIES_SQLITE(obj) \ | ||
383 | 24 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqlite)) | ||
384 | 25 | #define KATZE_HTTP_COOKIES_SQLITE_CLASS(klass) \ | ||
385 | 26 | (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqliteClass)) | ||
386 | 27 | #define KATZE_IS_HTTP_COOKIES_SQLITE(obj) \ | ||
387 | 28 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE)) | ||
388 | 29 | #define KATZE_IS_HTTP_COOKIES_SQLITE_CLASS(klass) \ | ||
389 | 30 | (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_HTTP_COOKIES_SQLITE)) | ||
390 | 31 | #define KATZE_HTTP_COOKIES_SQLITE_GET_CLASS(obj) \ | ||
391 | 32 | (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqliteClass)) | ||
392 | 33 | |||
393 | 34 | typedef struct _KatzeHttpCookiesSqlite KatzeHttpCookiesSqlite; | ||
394 | 35 | typedef struct _KatzeHttpCookiesSqliteClass KatzeHttpCookiesSqliteClass; | ||
395 | 36 | |||
396 | 37 | GType | ||
397 | 38 | katze_http_cookies_sqlite_get_type (void) G_GNUC_CONST; | ||
398 | 39 | |||
399 | 40 | G_END_DECLS | ||
400 | 41 | |||
401 | 42 | #endif /* __KATZE_HTTP_COOKIES_SQLITE_H__ */ | ||
402 | 43 | 0 | ||
403 | === removed file 'katze/katze-http-cookies.c' | |||
404 | --- katze/katze-http-cookies.c 2013-04-16 23:16:24 +0000 | |||
405 | +++ katze/katze-http-cookies.c 1970-01-01 00:00:00 +0000 | |||
406 | @@ -1,331 +0,0 @@ | |||
407 | 1 | /* | ||
408 | 2 | Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de> | ||
409 | 3 | |||
410 | 4 | This library is free software; you can redistribute it and/or | ||
411 | 5 | modify it under the terms of the GNU Lesser General Public | ||
412 | 6 | License as published by the Free Software Foundation; either | ||
413 | 7 | version 2.1 of the License, or (at your option) any later version. | ||
414 | 8 | |||
415 | 9 | See the file COPYING for the full license text. | ||
416 | 10 | */ | ||
417 | 11 | |||
418 | 12 | #if HAVE_CONFIG_H | ||
419 | 13 | #include <config.h> | ||
420 | 14 | #endif | ||
421 | 15 | |||
422 | 16 | #include "katze-http-cookies.h" | ||
423 | 17 | #include "midori/midori-core.h" | ||
424 | 18 | |||
425 | 19 | #include <stdlib.h> | ||
426 | 20 | #ifdef HAVE_UNISTD_H | ||
427 | 21 | #include <unistd.h> | ||
428 | 22 | #endif | ||
429 | 23 | #include <glib/gi18n.h> | ||
430 | 24 | #include <libsoup/soup.h> | ||
431 | 25 | #include <gtk/gtk.h> | ||
432 | 26 | #include <glib/gstdio.h> | ||
433 | 27 | |||
434 | 28 | struct _KatzeHttpCookies | ||
435 | 29 | { | ||
436 | 30 | GObject parent_instance; | ||
437 | 31 | gchar* filename; | ||
438 | 32 | SoupCookieJar* jar; | ||
439 | 33 | guint timeout; | ||
440 | 34 | guint counter; | ||
441 | 35 | }; | ||
442 | 36 | |||
443 | 37 | struct _KatzeHttpCookiesClass | ||
444 | 38 | { | ||
445 | 39 | GObjectClass parent_class; | ||
446 | 40 | }; | ||
447 | 41 | |||
448 | 42 | static void | ||
449 | 43 | katze_http_cookies_session_feature_iface_init (SoupSessionFeatureInterface *iface, | ||
450 | 44 | gpointer data); | ||
451 | 45 | |||
452 | 46 | G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookies, katze_http_cookies, G_TYPE_OBJECT, | ||
453 | 47 | G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, | ||
454 | 48 | katze_http_cookies_session_feature_iface_init)); | ||
455 | 49 | |||
456 | 50 | /* Cookie jar saving to Mozilla format | ||
457 | 51 | Copyright (C) 2008 Xan Lopez <xan@gnome.org> | ||
458 | 52 | Copyright (C) 2008 Dan Winship <danw@gnome.org> | ||
459 | 53 | Mostly copied from libSoup 2.24, coding style adjusted */ | ||
460 | 54 | static SoupCookie* | ||
461 | 55 | parse_cookie (gchar* line, | ||
462 | 56 | time_t now) | ||
463 | 57 | { | ||
464 | 58 | gchar** result; | ||
465 | 59 | SoupCookie *cookie = NULL; | ||
466 | 60 | gboolean http_only; | ||
467 | 61 | time_t max_age; | ||
468 | 62 | gchar* host/*, *is_domain*/, *path, *secure, *expires, *name, *value; | ||
469 | 63 | |||
470 | 64 | if (g_str_has_prefix (line, "#HttpOnly_")) | ||
471 | 65 | { | ||
472 | 66 | http_only = TRUE; | ||
473 | 67 | line += strlen ("#HttpOnly_"); | ||
474 | 68 | } | ||
475 | 69 | else if (*line == '#' || g_ascii_isspace (*line)) | ||
476 | 70 | return cookie; | ||
477 | 71 | else | ||
478 | 72 | http_only = FALSE; | ||
479 | 73 | |||
480 | 74 | result = g_strsplit (line, "\t", -1); | ||
481 | 75 | if (g_strv_length (result) != 7) | ||
482 | 76 | goto out; | ||
483 | 77 | |||
484 | 78 | /* Check this first */ | ||
485 | 79 | expires = result[4]; | ||
486 | 80 | max_age = strtoul (expires, NULL, 10) - now; | ||
487 | 81 | if (max_age <= 0) | ||
488 | 82 | goto out; | ||
489 | 83 | |||
490 | 84 | host = result[0]; | ||
491 | 85 | /* is_domain = result[1]; */ | ||
492 | 86 | path = result[2]; | ||
493 | 87 | secure = result[3]; | ||
494 | 88 | |||
495 | 89 | name = result[5]; | ||
496 | 90 | value = result[6]; | ||
497 | 91 | |||
498 | 92 | cookie = soup_cookie_new (name, value, host, path, max_age); | ||
499 | 93 | |||
500 | 94 | if (strcmp (secure, "FALSE")) | ||
501 | 95 | soup_cookie_set_secure (cookie, TRUE); | ||
502 | 96 | if (http_only) | ||
503 | 97 | soup_cookie_set_http_only (cookie, TRUE); | ||
504 | 98 | |||
505 | 99 | out: | ||
506 | 100 | g_strfreev (result); | ||
507 | 101 | |||
508 | 102 | return cookie; | ||
509 | 103 | } | ||
510 | 104 | |||
511 | 105 | /* Cookie jar saving to Mozilla format | ||
512 | 106 | Copyright (C) 2008 Xan Lopez <xan@gnome.org> | ||
513 | 107 | Copyright (C) 2008 Dan Winship <danw@gnome.org> | ||
514 | 108 | Mostly copied from libSoup 2.24, coding style adjusted */ | ||
515 | 109 | static void | ||
516 | 110 | parse_line (SoupCookieJar* jar, | ||
517 | 111 | gchar* line, | ||
518 | 112 | time_t now) | ||
519 | 113 | { | ||
520 | 114 | SoupCookie* cookie; | ||
521 | 115 | |||
522 | 116 | if ((cookie = parse_cookie (line, now))) | ||
523 | 117 | soup_cookie_jar_add_cookie (jar, cookie); | ||
524 | 118 | } | ||
525 | 119 | |||
526 | 120 | /* Cookie jar saving to Mozilla format | ||
527 | 121 | Copyright (C) 2008 Xan Lopez <xan@gnome.org> | ||
528 | 122 | Copyright (C) 2008 Dan Winship <danw@gnome.org> | ||
529 | 123 | Mostly copied from libSoup 2.24, coding style adjusted */ | ||
530 | 124 | static void | ||
531 | 125 | cookie_jar_load (SoupCookieJar* jar, | ||
532 | 126 | const gchar* filename) | ||
533 | 127 | { | ||
534 | 128 | char* contents = NULL; | ||
535 | 129 | gchar* line; | ||
536 | 130 | gchar* p; | ||
537 | 131 | gsize length = 0; | ||
538 | 132 | time_t now; | ||
539 | 133 | |||
540 | 134 | if (!g_file_get_contents (filename, &contents, &length, NULL)) | ||
541 | 135 | return; | ||
542 | 136 | |||
543 | 137 | now = time (NULL); | ||
544 | 138 | line = contents; | ||
545 | 139 | for (p = contents; *p; p++) | ||
546 | 140 | { | ||
547 | 141 | /* \r\n comes out as an extra empty line and gets ignored */ | ||
548 | 142 | if (*p == '\r' || *p == '\n') | ||
549 | 143 | { | ||
550 | 144 | *p = '\0'; | ||
551 | 145 | parse_line (jar, line, now); | ||
552 | 146 | line = p + 1; | ||
553 | 147 | } | ||
554 | 148 | } | ||
555 | 149 | parse_line (jar, line, now); | ||
556 | 150 | |||
557 | 151 | g_free (contents); | ||
558 | 152 | } | ||
559 | 153 | |||
560 | 154 | /* Cookie jar saving to Mozilla format | ||
561 | 155 | Copyright (C) 2008 Xan Lopez <xan@gnome.org> | ||
562 | 156 | Copyright (C) 2008 Dan Winship <danw@gnome.org> | ||
563 | 157 | Copied from libSoup 2.24, coding style preserved */ | ||
564 | 158 | static gboolean | ||
565 | 159 | write_cookie (FILE *out, SoupCookie *cookie) | ||
566 | 160 | { | ||
567 | 161 | if (fprintf (out, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n", | ||
568 | 162 | cookie->http_only ? "#HttpOnly_" : "", | ||
569 | 163 | cookie->domain, | ||
570 | 164 | *cookie->domain == '.' ? "TRUE" : "FALSE", | ||
571 | 165 | cookie->path, | ||
572 | 166 | cookie->secure ? "TRUE" : "FALSE", | ||
573 | 167 | (gulong)soup_date_to_time_t (cookie->expires), | ||
574 | 168 | cookie->name, | ||
575 | 169 | cookie->value) < 0) | ||
576 | 170 | return FALSE; | ||
577 | 171 | return TRUE; | ||
578 | 172 | } | ||
579 | 173 | |||
580 | 174 | static gboolean | ||
581 | 175 | katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies) | ||
582 | 176 | { | ||
583 | 177 | gint fn = 0; | ||
584 | 178 | FILE* f = NULL; | ||
585 | 179 | gchar* temporary_filename = NULL; | ||
586 | 180 | GSList* cookies; | ||
587 | 181 | |||
588 | 182 | if (http_cookies->timeout > 0) | ||
589 | 183 | { | ||
590 | 184 | g_source_remove (http_cookies->timeout); | ||
591 | 185 | http_cookies->timeout = 0; | ||
592 | 186 | } | ||
593 | 187 | |||
594 | 188 | temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL); | ||
595 | 189 | if ((fn = g_mkstemp (temporary_filename)) == -1) | ||
596 | 190 | goto failed; | ||
597 | 191 | if (!((f = fdopen (fn, "wb")))) | ||
598 | 192 | goto failed; | ||
599 | 193 | |||
600 | 194 | cookies = soup_cookie_jar_all_cookies (http_cookies->jar); | ||
601 | 195 | for (; cookies != NULL; cookies = g_slist_next (cookies)) | ||
602 | 196 | { | ||
603 | 197 | SoupCookie* cookie = cookies->data; | ||
604 | 198 | if (cookie->expires && !soup_date_is_past (cookie->expires)) | ||
605 | 199 | write_cookie (f, cookie); | ||
606 | 200 | soup_cookie_free (cookie); | ||
607 | 201 | } | ||
608 | 202 | g_slist_free (cookies); | ||
609 | 203 | |||
610 | 204 | if (fclose (f) != 0) | ||
611 | 205 | { | ||
612 | 206 | f = NULL; | ||
613 | 207 | goto failed; | ||
614 | 208 | } | ||
615 | 209 | f = NULL; | ||
616 | 210 | |||
617 | 211 | if (g_rename (temporary_filename, http_cookies->filename) == -1) | ||
618 | 212 | goto failed; | ||
619 | 213 | g_free (temporary_filename); | ||
620 | 214 | |||
621 | 215 | if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) | ||
622 | 216 | { | ||
623 | 217 | g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter); | ||
624 | 218 | http_cookies->counter = 0; | ||
625 | 219 | } | ||
626 | 220 | return FALSE; | ||
627 | 221 | |||
628 | 222 | failed: | ||
629 | 223 | if (f) | ||
630 | 224 | fclose (f); | ||
631 | 225 | g_unlink (temporary_filename); | ||
632 | 226 | g_free (temporary_filename); | ||
633 | 227 | if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) | ||
634 | 228 | g_print ("KatzeHttpCookies: Failed to write '%s'\n", | ||
635 | 229 | http_cookies->filename); | ||
636 | 230 | return FALSE; | ||
637 | 231 | } | ||
638 | 232 | |||
639 | 233 | static void | ||
640 | 234 | katze_http_cookies_jar_changed_cb (SoupCookieJar* jar, | ||
641 | 235 | SoupCookie* old_cookie, | ||
642 | 236 | SoupCookie* new_cookie, | ||
643 | 237 | KatzeHttpCookies* http_cookies) | ||
644 | 238 | { | ||
645 | 239 | GObject* settings; | ||
646 | 240 | |||
647 | 241 | if (old_cookie) | ||
648 | 242 | soup_cookie_set_max_age (old_cookie, 0); | ||
649 | 243 | |||
650 | 244 | if (new_cookie) | ||
651 | 245 | { | ||
652 | 246 | settings = g_object_get_data (G_OBJECT (jar), "midori-settings"); | ||
653 | 247 | if (new_cookie->expires) | ||
654 | 248 | { | ||
655 | 249 | gint age = katze_object_get_int (settings, "maximum-cookie-age"); | ||
656 | 250 | if (age > 0) | ||
657 | 251 | { | ||
658 | 252 | SoupDate* max_date = soup_date_new_from_now ( | ||
659 | 253 | age * SOUP_COOKIE_MAX_AGE_ONE_DAY); | ||
660 | 254 | if (soup_date_to_time_t (new_cookie->expires) | ||
661 | 255 | > soup_date_to_time_t (max_date)) | ||
662 | 256 | soup_cookie_set_expires (new_cookie, max_date); | ||
663 | 257 | } | ||
664 | 258 | else | ||
665 | 259 | { | ||
666 | 260 | /* An age of 0 to SoupCookie means already-expired | ||
667 | 261 | A user choosing 0 days probably expects 1 hour. */ | ||
668 | 262 | soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); | ||
669 | 263 | } | ||
670 | 264 | } | ||
671 | 265 | } | ||
672 | 266 | |||
673 | 267 | if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) | ||
674 | 268 | http_cookies->counter++; | ||
675 | 269 | |||
676 | 270 | if (!http_cookies->timeout && (old_cookie || (new_cookie && new_cookie->expires))) | ||
677 | 271 | http_cookies->timeout = midori_timeout_add_seconds ( | ||
678 | 272 | 5, (GSourceFunc)katze_http_cookies_update_jar, http_cookies, NULL); | ||
679 | 273 | } | ||
680 | 274 | |||
681 | 275 | static void | ||
682 | 276 | katze_http_cookies_attach (SoupSessionFeature* feature, | ||
683 | 277 | SoupSession* session) | ||
684 | 278 | { | ||
685 | 279 | KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature; | ||
686 | 280 | const gchar* filename = g_object_get_data (G_OBJECT (feature), "filename"); | ||
687 | 281 | SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); | ||
688 | 282 | g_return_if_fail (jar != NULL); | ||
689 | 283 | g_return_if_fail (filename != NULL); | ||
690 | 284 | katze_assign (http_cookies->filename, g_strdup (filename)); | ||
691 | 285 | http_cookies->jar = g_object_ref (jar); | ||
692 | 286 | cookie_jar_load (http_cookies->jar, http_cookies->filename); | ||
693 | 287 | g_signal_connect (jar, "changed", | ||
694 | 288 | G_CALLBACK (katze_http_cookies_jar_changed_cb), feature); | ||
695 | 289 | |||
696 | 290 | } | ||
697 | 291 | |||
698 | 292 | static void | ||
699 | 293 | katze_http_cookies_detach (SoupSessionFeature* feature, | ||
700 | 294 | SoupSession* session) | ||
701 | 295 | { | ||
702 | 296 | KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature; | ||
703 | 297 | if (http_cookies->timeout > 0) | ||
704 | 298 | katze_http_cookies_update_jar (http_cookies); | ||
705 | 299 | katze_assign (http_cookies->filename, NULL); | ||
706 | 300 | katze_object_assign (http_cookies->jar, NULL); | ||
707 | 301 | } | ||
708 | 302 | |||
709 | 303 | static void | ||
710 | 304 | katze_http_cookies_session_feature_iface_init (SoupSessionFeatureInterface *iface, | ||
711 | 305 | gpointer data) | ||
712 | 306 | { | ||
713 | 307 | iface->attach = katze_http_cookies_attach; | ||
714 | 308 | iface->detach = katze_http_cookies_detach; | ||
715 | 309 | } | ||
716 | 310 | |||
717 | 311 | static void | ||
718 | 312 | katze_http_cookies_finalize (GObject* object) | ||
719 | 313 | { | ||
720 | 314 | katze_http_cookies_detach ((SoupSessionFeature*)object, NULL); | ||
721 | 315 | } | ||
722 | 316 | |||
723 | 317 | static void | ||
724 | 318 | katze_http_cookies_class_init (KatzeHttpCookiesClass* class) | ||
725 | 319 | { | ||
726 | 320 | GObjectClass* gobject_class = (GObjectClass*)class; | ||
727 | 321 | gobject_class->finalize = katze_http_cookies_finalize; | ||
728 | 322 | } | ||
729 | 323 | |||
730 | 324 | static void | ||
731 | 325 | katze_http_cookies_init (KatzeHttpCookies* http_cookies) | ||
732 | 326 | { | ||
733 | 327 | http_cookies->filename = NULL; | ||
734 | 328 | http_cookies->jar = NULL; | ||
735 | 329 | http_cookies->timeout = 0; | ||
736 | 330 | http_cookies->counter = 0; | ||
737 | 331 | } | ||
738 | 332 | 0 | ||
739 | === removed file 'katze/katze-http-cookies.h' | |||
740 | --- katze/katze-http-cookies.h 2010-01-17 17:14:48 +0000 | |||
741 | +++ katze/katze-http-cookies.h 1970-01-01 00:00:00 +0000 | |||
742 | @@ -1,42 +0,0 @@ | |||
743 | 1 | /* | ||
744 | 2 | Copyright (C) 2009 Christian Dywan <christian@twotoasts.de> | ||
745 | 3 | |||
746 | 4 | This library is free software; you can redistribute it and/or | ||
747 | 5 | modify it under the terms of the GNU Lesser General Public | ||
748 | 6 | License as published by the Free Software Foundation; either | ||
749 | 7 | version 2.1 of the License, or (at your option) any later version. | ||
750 | 8 | |||
751 | 9 | See the file COPYING for the full license text. | ||
752 | 10 | */ | ||
753 | 11 | |||
754 | 12 | #ifndef __KATZE_HTTP_COOKIES_H__ | ||
755 | 13 | #define __KATZE_HTTP_COOKIES_H__ | ||
756 | 14 | |||
757 | 15 | #include "katze-utils.h" | ||
758 | 16 | |||
759 | 17 | #include <glib-object.h> | ||
760 | 18 | |||
761 | 19 | G_BEGIN_DECLS | ||
762 | 20 | |||
763 | 21 | #define KATZE_TYPE_HTTP_COOKIES \ | ||
764 | 22 | (katze_http_cookies_get_type ()) | ||
765 | 23 | #define KATZE_HTTP_COOKIES(obj) \ | ||
766 | 24 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookies)) | ||
767 | 25 | #define KATZE_HTTP_COOKIES_CLASS(klass) \ | ||
768 | 26 | (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookiesClass)) | ||
769 | 27 | #define KATZE_IS_HTTP_COOKIES(obj) \ | ||
770 | 28 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_HTTP_COOKIES)) | ||
771 | 29 | #define KATZE_IS_HTTP_COOKIES_CLASS(klass) \ | ||
772 | 30 | (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_HTTP_COOKIES)) | ||
773 | 31 | #define KATZE_HTTP_COOKIES_GET_CLASS(obj) \ | ||
774 | 32 | (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookiesClass)) | ||
775 | 33 | |||
776 | 34 | typedef struct _KatzeHttpCookies KatzeHttpCookies; | ||
777 | 35 | typedef struct _KatzeHttpCookiesClass KatzeHttpCookiesClass; | ||
778 | 36 | |||
779 | 37 | GType | ||
780 | 38 | katze_http_cookies_get_type (void) G_GNUC_CONST; | ||
781 | 39 | |||
782 | 40 | G_END_DECLS | ||
783 | 41 | |||
784 | 42 | #endif /* __KATZE_HTTP_COOKIES_H__ */ | ||
785 | 43 | 0 | ||
786 | === modified file 'katze/katze.h' | |||
787 | --- katze/katze.h 2013-07-27 12:35:55 +0000 | |||
788 | +++ katze/katze.h 2013-07-29 21:07:25 +0000 | |||
789 | @@ -13,8 +13,6 @@ | |||
790 | 13 | #define __KATZE_H__ | 13 | #define __KATZE_H__ |
791 | 14 | 14 | ||
792 | 15 | #include "katze-http-auth.h" | 15 | #include "katze-http-auth.h" |
793 | 16 | #include "katze-http-cookies.h" | ||
794 | 17 | #include "katze-http-cookies-sqlite.h" | ||
795 | 18 | #include "katze-throbber.h" | 16 | #include "katze-throbber.h" |
796 | 19 | #include "katze-utils.h" | 17 | #include "katze-utils.h" |
797 | 20 | #include "katze-item.h" | 18 | #include "katze-item.h" |
798 | 21 | 19 | ||
799 | === modified file 'midori/midori-frontend.c' | |||
800 | --- midori/midori-frontend.c 2013-06-30 14:58:59 +0000 | |||
801 | +++ midori/midori-frontend.c 2013-07-29 21:07:25 +0000 | |||
802 | @@ -600,11 +600,6 @@ | |||
803 | 600 | midori_bookmarks_on_quit (bookmarks); | 600 | midori_bookmarks_on_quit (bookmarks); |
804 | 601 | midori_history_on_quit (history, settings); | 601 | midori_history_on_quit (history, settings); |
805 | 602 | midori_private_data_on_quit (settings); | 602 | midori_private_data_on_quit (settings); |
806 | 603 | /* Removing KatzeHttpCookies makes it save outstanding changes */ | ||
807 | 604 | #ifndef HAVE_WEBKIT2 | ||
808 | 605 | soup_session_remove_feature_by_type (webkit_get_default_session (), | ||
809 | 606 | KATZE_TYPE_HTTP_COOKIES); | ||
810 | 607 | #endif | ||
811 | 608 | 603 | ||
812 | 609 | MidoriStartup load_on_startup = katze_object_get_int (settings, "load-on-startup"); | 604 | MidoriStartup load_on_startup = katze_object_get_int (settings, "load-on-startup"); |
813 | 610 | if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES) | 605 | if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES) |
814 | 611 | 606 | ||
815 | === modified file 'midori/midori-privatedata.c' | |||
816 | --- midori/midori-privatedata.c 2013-06-19 20:23:55 +0000 | |||
817 | +++ midori/midori-privatedata.c 2013-07-29 21:07:25 +0000 | |||
818 | @@ -221,13 +221,17 @@ | |||
819 | 221 | static void | 221 | static void |
820 | 222 | midori_clear_web_cookies_cb (void) | 222 | midori_clear_web_cookies_cb (void) |
821 | 223 | { | 223 | { |
823 | 224 | #ifndef HAVE_WEBKIT2 | 224 | #ifdef HAVE_WEBKIT2 |
824 | 225 | WebKitWebContext* context = webkit_web_context_get_default (); | ||
825 | 226 | WebKitCookieManager* cookie_manager = webkit_web_context_get_cookie_manager (context); | ||
826 | 227 | webkit_cookie_manager_delete_all_cookies (cookie_manager); | ||
827 | 228 | /* FIXME: site data policy */ | ||
828 | 229 | #else | ||
829 | 225 | SoupSession* session = webkit_get_default_session (); | 230 | SoupSession* session = webkit_get_default_session (); |
830 | 226 | MidoriWebSettings* settings = g_object_get_data (G_OBJECT (session), "midori-settings"); | 231 | MidoriWebSettings* settings = g_object_get_data (G_OBJECT (session), "midori-settings"); |
831 | 227 | SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); | 232 | SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); |
832 | 228 | GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar)); | 233 | GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar)); |
833 | 229 | SoupSessionFeature* feature; | 234 | SoupSessionFeature* feature; |
834 | 230 | gchar* cache; | ||
835 | 231 | 235 | ||
836 | 232 | /* HTTP Cookies/ Web Cookies */ | 236 | /* HTTP Cookies/ Web Cookies */ |
837 | 233 | for (; cookies != NULL; cookies = g_slist_next (cookies)) | 237 | for (; cookies != NULL; cookies = g_slist_next (cookies)) |
838 | @@ -239,18 +243,12 @@ | |||
839 | 239 | soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookies->data); | 243 | soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookies->data); |
840 | 240 | } | 244 | } |
841 | 241 | soup_cookies_free (cookies); | 245 | soup_cookies_free (cookies); |
850 | 242 | /* Removing KatzeHttpCookies makes it save outstanding changes */ | 246 | #endif |
843 | 243 | if ((feature = soup_session_get_feature (session, KATZE_TYPE_HTTP_COOKIES))) | ||
844 | 244 | { | ||
845 | 245 | g_object_ref (feature); | ||
846 | 246 | soup_session_remove_feature (session, feature); | ||
847 | 247 | soup_session_add_feature (session, feature); | ||
848 | 248 | g_object_unref (feature); | ||
849 | 249 | } | ||
851 | 250 | 247 | ||
852 | 251 | /* Local shared objects/ Flash cookies */ | 248 | /* Local shared objects/ Flash cookies */ |
853 | 252 | if (midori_web_settings_has_plugin_support ()) | 249 | if (midori_web_settings_has_plugin_support ()) |
854 | 253 | { | 250 | { |
855 | 251 | gchar* cache; | ||
856 | 254 | #ifdef GDK_WINDOWING_X11 | 252 | #ifdef GDK_WINDOWING_X11 |
857 | 255 | cache = g_build_filename (g_get_home_dir (), ".macromedia", "Flash_Player", NULL); | 253 | cache = g_build_filename (g_get_home_dir (), ".macromedia", "Flash_Player", NULL); |
858 | 256 | midori_paths_remove_path (cache); | 254 | midori_paths_remove_path (cache); |
859 | @@ -267,6 +265,9 @@ | |||
860 | 267 | #endif | 265 | #endif |
861 | 268 | } | 266 | } |
862 | 269 | 267 | ||
863 | 268 | #ifdef HAVE_WEBKIT2 | ||
864 | 269 | /* TODO: clear databases and offline app caches */ | ||
865 | 270 | #else | ||
866 | 270 | /* HTML5 databases */ | 271 | /* HTML5 databases */ |
867 | 271 | webkit_remove_all_web_databases (); | 272 | webkit_remove_all_web_databases (); |
868 | 272 | 273 | ||
869 | 273 | 274 | ||
870 | === modified file 'midori/midori-session.c' | |||
871 | --- midori/midori-session.c 2013-07-11 08:40:04 +0000 | |||
872 | +++ midori/midori-session.c 2013-07-29 21:07:25 +0000 | |||
873 | @@ -17,10 +17,12 @@ | |||
874 | 17 | #include "sokoke.h" | 17 | #include "sokoke.h" |
875 | 18 | 18 | ||
876 | 19 | #include <glib/gi18n-lib.h> | 19 | #include <glib/gi18n-lib.h> |
877 | 20 | #include <libsoup/soup-cookie-jar-sqlite.h> | ||
878 | 20 | 21 | ||
879 | 21 | #define LIBSOUP_USE_UNSTABLE_REQUEST_API | 22 | #define LIBSOUP_USE_UNSTABLE_REQUEST_API |
880 | 22 | #include <libsoup/soup-cache.h> | 23 | #include <libsoup/soup-cache.h> |
881 | 23 | 24 | ||
882 | 25 | #ifndef HAVE_WEBKIT2 | ||
883 | 24 | static void | 26 | static void |
884 | 25 | midori_soup_session_set_proxy_uri (SoupSession* session, | 27 | midori_soup_session_set_proxy_uri (SoupSession* session, |
885 | 26 | const gchar* uri) | 28 | const gchar* uri) |
886 | @@ -83,18 +85,28 @@ | |||
887 | 83 | else | 85 | else |
888 | 84 | midori_soup_session_set_proxy_uri (session, NULL); | 86 | midori_soup_session_set_proxy_uri (session, NULL); |
889 | 85 | } | 87 | } |
890 | 88 | #endif | ||
891 | 86 | 89 | ||
893 | 87 | #ifdef HAVE_LIBSOUP_2_29_91 | 90 | #if defined(HAVE_LIBSOUP_2_29_91) && WEBKIT_CHECK_VERSION (1, 1, 21) |
894 | 88 | static void | 91 | static void |
895 | 89 | soup_session_settings_notify_first_party_cb (MidoriWebSettings* settings, | 92 | soup_session_settings_notify_first_party_cb (MidoriWebSettings* settings, |
896 | 90 | GParamSpec* pspec, | 93 | GParamSpec* pspec, |
898 | 91 | SoupSession* session) | 94 | gpointer user_data) |
899 | 92 | { | 95 | { |
900 | 96 | gboolean yes = katze_object_get_boolean (settings, "first-party-cookies-only"); | ||
901 | 97 | #ifdef HAVE_WEBKIT2 | ||
902 | 98 | WebKitWebContext* context = webkit_web_context_get_default (); | ||
903 | 99 | WebKitCookieManager* cookie_manager = webkit_web_context_get_cookie_manager (context); | ||
904 | 100 | webkit_cookie_manager_set_accept_policy (cookie_manager, | ||
905 | 101 | yes ? WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY | ||
906 | 102 | : WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); | ||
907 | 103 | #else | ||
908 | 104 | SoupSession* session = webkit_get_default_session (); | ||
909 | 93 | gpointer jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); | 105 | gpointer jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); |
910 | 94 | gboolean yes = katze_object_get_boolean (settings, "first-party-cookies-only"); | ||
911 | 95 | g_object_set (jar, "accept-policy", | 106 | g_object_set (jar, "accept-policy", |
912 | 96 | yes ? SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY | 107 | yes ? SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY |
913 | 97 | : SOUP_COOKIE_JAR_ACCEPT_ALWAYS, NULL); | 108 | : SOUP_COOKIE_JAR_ACCEPT_ALWAYS, NULL); |
914 | 109 | #endif | ||
915 | 98 | } | 110 | } |
916 | 99 | #endif | 111 | #endif |
917 | 100 | 112 | ||
918 | @@ -116,17 +128,14 @@ | |||
919 | 116 | #ifndef HAVE_WEBKIT2 | 128 | #ifndef HAVE_WEBKIT2 |
920 | 117 | const gchar* | 129 | const gchar* |
921 | 118 | midori_web_settings_get_accept_language (MidoriWebSettings* settings); | 130 | midori_web_settings_get_accept_language (MidoriWebSettings* settings); |
922 | 119 | #endif | ||
923 | 120 | 131 | ||
924 | 121 | static void | 132 | static void |
925 | 122 | midori_soup_session_settings_accept_language_cb (SoupSession* session, | 133 | midori_soup_session_settings_accept_language_cb (SoupSession* session, |
926 | 123 | SoupMessage* msg, | 134 | SoupMessage* msg, |
927 | 124 | MidoriWebSettings* settings) | 135 | MidoriWebSettings* settings) |
928 | 125 | { | 136 | { |
929 | 126 | #ifndef HAVE_WEBKIT2 | ||
930 | 127 | const gchar* accept = midori_web_settings_get_accept_language (settings); | 137 | const gchar* accept = midori_web_settings_get_accept_language (settings); |
931 | 128 | soup_message_headers_append (msg->request_headers, "Accept-Language", accept); | 138 | soup_message_headers_append (msg->request_headers, "Accept-Language", accept); |
932 | 129 | #endif | ||
933 | 130 | 139 | ||
934 | 131 | if (katze_object_get_boolean (settings, "strip-referer")) | 140 | if (katze_object_get_boolean (settings, "strip-referer")) |
935 | 132 | { | 141 | { |
936 | @@ -157,10 +166,16 @@ | |||
937 | 157 | soup_message_headers_remove (msg->request_headers, "Host"); | 166 | soup_message_headers_remove (msg->request_headers, "Host"); |
938 | 158 | } | 167 | } |
939 | 159 | } | 168 | } |
940 | 169 | #endif | ||
941 | 160 | 170 | ||
942 | 161 | gboolean | 171 | gboolean |
943 | 162 | midori_load_soup_session (gpointer settings) | 172 | midori_load_soup_session (gpointer settings) |
944 | 163 | { | 173 | { |
945 | 174 | #if defined(HAVE_LIBSOUP_2_29_91) && WEBKIT_CHECK_VERSION (1, 1, 21) | ||
946 | 175 | g_signal_connect (settings, "notify::first-party-cookies-only", | ||
947 | 176 | G_CALLBACK (soup_session_settings_notify_first_party_cb), NULL); | ||
948 | 177 | #endif | ||
949 | 178 | |||
950 | 164 | #ifndef HAVE_WEBKIT2 | 179 | #ifndef HAVE_WEBKIT2 |
951 | 165 | SoupSession* session = webkit_get_default_session (); | 180 | SoupSession* session = webkit_get_default_session (); |
952 | 166 | 181 | ||
953 | @@ -213,12 +228,6 @@ | |||
954 | 213 | G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session); | 228 | G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session); |
955 | 214 | g_signal_connect (settings, "notify::proxy-type", | 229 | g_signal_connect (settings, "notify::proxy-type", |
956 | 215 | G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session); | 230 | G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session); |
957 | 216 | #ifdef HAVE_LIBSOUP_2_29_91 | ||
958 | 217 | if (g_object_class_find_property (G_OBJECT_GET_CLASS (settings), | ||
959 | 218 | "enable-file-access-from-file-uris")) /* WebKitGTK+ >= 1.1.21 */ | ||
960 | 219 | g_signal_connect (settings, "notify::first-party-cookies-only", | ||
961 | 220 | G_CALLBACK (soup_session_settings_notify_first_party_cb), session); | ||
962 | 221 | #endif | ||
963 | 222 | 231 | ||
964 | 223 | #if defined (HAVE_LIBSOUP_2_34_0) | 232 | #if defined (HAVE_LIBSOUP_2_34_0) |
965 | 224 | g_signal_connect (session, "request-started", | 233 | g_signal_connect (session, "request-started", |
966 | @@ -247,10 +256,42 @@ | |||
967 | 247 | return FALSE; | 256 | return FALSE; |
968 | 248 | } | 257 | } |
969 | 249 | 258 | ||
970 | 259 | #ifndef HAVE_WEBKIT2 | ||
971 | 260 | static void | ||
972 | 261 | midori_session_cookie_jar_changed_cb (SoupCookieJar* jar, | ||
973 | 262 | SoupCookie* old_cookie, | ||
974 | 263 | SoupCookie* new_cookie, | ||
975 | 264 | MidoriWebSettings* settings) | ||
976 | 265 | { | ||
977 | 266 | if (new_cookie && new_cookie->expires) | ||
978 | 267 | { | ||
979 | 268 | time_t expires = soup_date_to_time_t (new_cookie->expires); | ||
980 | 269 | gint age = katze_object_get_int (settings, "maximum-cookie-age"); | ||
981 | 270 | if (age > 0) | ||
982 | 271 | { | ||
983 | 272 | SoupDate* max_date = soup_date_new_from_now ( | ||
984 | 273 | age * SOUP_COOKIE_MAX_AGE_ONE_DAY); | ||
985 | 274 | if (soup_date_to_time_t (new_cookie->expires) | ||
986 | 275 | > soup_date_to_time_t (max_date)) | ||
987 | 276 | soup_cookie_set_expires (new_cookie, max_date); | ||
988 | 277 | } | ||
989 | 278 | else | ||
990 | 279 | { | ||
991 | 280 | /* An age of 0 to SoupCookie means already-expired | ||
992 | 281 | A user choosing 0 days probably expects 1 hour. */ | ||
993 | 282 | soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); | ||
994 | 283 | } | ||
995 | 284 | } | ||
996 | 285 | |||
997 | 286 | if (midori_debug ("cookies")) | ||
998 | 287 | g_print ("cookie changed: old %p new %p\n", old_cookie, new_cookie); | ||
999 | 288 | } | ||
1000 | 289 | #endif | ||
1001 | 290 | |||
1002 | 250 | gboolean | 291 | gboolean |
1003 | 251 | midori_load_soup_session_full (gpointer settings) | 292 | midori_load_soup_session_full (gpointer settings) |
1004 | 252 | { | 293 | { |
1006 | 253 | #ifndef HAVE_WEBKIT2 | 294 | #ifndef HAVE_WEBKIT2 |
1007 | 254 | SoupSession* session = webkit_get_default_session (); | 295 | SoupSession* session = webkit_get_default_session (); |
1008 | 255 | SoupCookieJar* jar; | 296 | SoupCookieJar* jar; |
1009 | 256 | gchar* config_file; | 297 | gchar* config_file; |
1010 | @@ -265,33 +306,13 @@ | |||
1011 | 265 | soup_session_add_feature (session, feature); | 306 | soup_session_add_feature (session, feature); |
1012 | 266 | g_object_unref (feature); | 307 | g_object_unref (feature); |
1013 | 267 | 308 | ||
1016 | 268 | jar = soup_cookie_jar_new (); | 309 | katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db")); |
1017 | 269 | g_object_set_data (G_OBJECT (jar), "midori-settings", settings); | 310 | jar = soup_cookie_jar_sqlite_new (config_file, FALSE); |
1018 | 270 | soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar)); | 311 | soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar)); |
1019 | 312 | g_signal_connect (jar, "changed", | ||
1020 | 313 | G_CALLBACK (midori_session_cookie_jar_changed_cb), settings); | ||
1021 | 271 | g_object_unref (jar); | 314 | g_object_unref (jar); |
1022 | 272 | 315 | ||
1023 | 273 | katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db")); | ||
1024 | 274 | have_new_cookies = g_access (config_file, F_OK) == 0; | ||
1025 | 275 | feature = g_object_new (KATZE_TYPE_HTTP_COOKIES_SQLITE, NULL); | ||
1026 | 276 | g_object_set_data_full (G_OBJECT (feature), "filename", | ||
1027 | 277 | config_file, (GDestroyNotify)g_free); | ||
1028 | 278 | soup_session_add_feature (session, feature); | ||
1029 | 279 | g_object_unref (feature); | ||
1030 | 280 | |||
1031 | 281 | if (!have_new_cookies) | ||
1032 | 282 | { | ||
1033 | 283 | katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.txt")); | ||
1034 | 284 | if (g_access (config_file, F_OK) == 0) | ||
1035 | 285 | { | ||
1036 | 286 | g_message ("Importing cookies from txt to sqlite3"); | ||
1037 | 287 | feature_import = g_object_new (KATZE_TYPE_HTTP_COOKIES, NULL); | ||
1038 | 288 | g_object_set_data_full (G_OBJECT (feature_import), "filename", | ||
1039 | 289 | config_file, (GDestroyNotify)g_free); | ||
1040 | 290 | soup_session_add_feature (session, SOUP_SESSION_FEATURE (feature_import)); | ||
1041 | 291 | soup_session_remove_feature (session, SOUP_SESSION_FEATURE (feature_import)); | ||
1042 | 292 | } | ||
1043 | 293 | } | ||
1044 | 294 | |||
1045 | 295 | katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL)); | 316 | katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL)); |
1046 | 296 | feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0)); | 317 | feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0)); |
1047 | 297 | soup_session_add_feature (session, feature); | 318 | soup_session_add_feature (session, feature); |
1048 | @@ -299,7 +320,7 @@ | |||
1049 | 299 | katze_object_get_int (settings, "maximum-cache-size") * 1024 * 1024); | 320 | katze_object_get_int (settings, "maximum-cache-size") * 1024 * 1024); |
1050 | 300 | soup_cache_load (SOUP_CACHE (feature)); | 321 | soup_cache_load (SOUP_CACHE (feature)); |
1051 | 301 | g_free (config_file); | 322 | g_free (config_file); |
1053 | 302 | #endif | 323 | #endif |
1054 | 303 | return FALSE; | 324 | return FALSE; |
1055 | 304 | } | 325 | } |
1056 | 305 | 326 | ||
1057 | 306 | 327 | ||
1058 | === modified file 'wscript' | |||
1059 | --- wscript 2013-07-16 14:20:37 +0000 | |||
1060 | +++ wscript 2013-07-29 21:07:25 +0000 | |||
1061 | @@ -278,7 +278,7 @@ | |||
1062 | 278 | conf.check_message_custom ('unique', '', 'disabled') | 278 | conf.check_message_custom ('unique', '', 'disabled') |
1063 | 279 | conf.define ('HAVE_UNIQUE', [0,1][conf.env['UNIQUE_VERSION'] != 'No']) | 279 | conf.define ('HAVE_UNIQUE', [0,1][conf.env['UNIQUE_VERSION'] != 'No']) |
1064 | 280 | 280 | ||
1066 | 281 | check_pkg ('libsoup-2.4', '2.27.90', var='LIBSOUP') | 281 | check_pkg ('libsoup-gnome-2.4', '2.27.90', var='LIBSOUP') |
1067 | 282 | if check_version (conf.env['LIBSOUP_VERSION'], 2, 29, 91): | 282 | if check_version (conf.env['LIBSOUP_VERSION'], 2, 29, 91): |
1068 | 283 | conf.define ('HAVE_LIBSOUP_2_29_91', 1) | 283 | conf.define ('HAVE_LIBSOUP_2_29_91', 1) |
1069 | 284 | if check_version (conf.env['LIBSOUP_VERSION'], 2, 34, 0): | 284 | if check_version (conf.env['LIBSOUP_VERSION'], 2, 34, 0): |
As the question come up in IRC: the cookie manager does show cookies. It won't yet update in real-time. I haven't made up my mind what the best approach is since the WebKit2 API has a "changed" signal but doesn't say what happens…