2 * Copyright (C) 2008 Xan Lopez <xan@gnome.org>
3 * Copyright (C) 2009 Igalia S.L.
4 * Copyright (C) 2008 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "CookieJarSoup.h"
29 static bool cookiesInitialized;
30 static SoupCookieJar* cookieJar;
32 SoupCookieJar* defaultCookieJar()
34 if (!cookiesInitialized) {
35 cookiesInitialized = true;
36 setDefaultCookieJar(soup_cookie_jar_new());
42 void setDefaultCookieJar(SoupCookieJar* jar)
44 cookiesInitialized = true;
47 g_object_unref(cookieJar);
52 g_object_ref(cookieJar);
55 void setCookies(Document* /*document*/, const KURL& url, const KURL& /*policyURL*/, const String& value)
57 SoupCookieJar* jar = defaultCookieJar();
61 SoupURI* origin = soup_uri_new(url.string().utf8().data());
63 soup_cookie_jar_set_cookie(jar, origin, value.utf8().data());
64 soup_uri_free(origin);
67 String cookies(const Document* /*document*/, const KURL& url)
69 SoupCookieJar* jar = defaultCookieJar();
73 SoupURI* uri = soup_uri_new(url.string().utf8().data());
74 char* cookies = soup_cookie_jar_get_cookies(jar, uri, FALSE);
77 String result(String::fromUTF8(cookies));
83 bool cookiesEnabled(const Document* /*document*/)
85 return defaultCookieJar();