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"
26 #include "GOwnPtrSoup.h"
28 #include <wtf/text/CString.h>
32 static bool cookiesInitialized;
33 static SoupCookieJar* cookieJar;
35 SoupCookieJar* defaultCookieJar()
37 if (!cookiesInitialized) {
38 cookiesInitialized = true;
40 cookieJar = soup_cookie_jar_new();
41 soup_cookie_jar_set_accept_policy(cookieJar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
47 void setDefaultCookieJar(SoupCookieJar* jar)
49 cookiesInitialized = true;
52 g_object_unref(cookieJar);
57 g_object_ref(cookieJar);
60 void setCookies(Document* document, const KURL& url, const String& value)
62 SoupCookieJar* jar = defaultCookieJar();
66 GOwnPtr<SoupURI> origin(soup_uri_new(url.string().utf8().data()));
68 GOwnPtr<SoupURI> firstParty(soup_uri_new(document->firstPartyForCookies().string().utf8().data()));
70 soup_cookie_jar_set_cookie_with_first_party(jar,
76 String cookies(const Document* /*document*/, const KURL& url)
78 SoupCookieJar* jar = defaultCookieJar();
82 SoupURI* uri = soup_uri_new(url.string().utf8().data());
83 char* cookies = soup_cookie_jar_get_cookies(jar, uri, FALSE);
86 String result(String::fromUTF8(cookies));
92 String cookieRequestHeaderFieldValue(const Document* /*document*/, const KURL& url)
94 SoupCookieJar* jar = defaultCookieJar();
98 SoupURI* uri = soup_uri_new(url.string().utf8().data());
99 char* cookies = soup_cookie_jar_get_cookies(jar, uri, TRUE);
102 String result(String::fromUTF8(cookies));
108 bool cookiesEnabled(const Document* /*document*/)
110 return defaultCookieJar();
113 bool getRawCookies(const Document*, const KURL&, Vector<Cookie>& rawCookies)
115 // FIXME: Not yet implemented
117 return false; // return true when implemented
120 void deleteCookie(const Document*, const KURL&, const String&)
122 // FIXME: Not yet implemented