diff options
Diffstat (limited to 'WebCore/platform/network')
11 files changed, 130 insertions, 16 deletions
diff --git a/WebCore/platform/network/android/CookieJarAndroid.cpp b/WebCore/platform/network/android/CookieJarAndroid.cpp index ba4b5dc..dd324c5 100644 --- a/WebCore/platform/network/android/CookieJarAndroid.cpp +++ b/WebCore/platform/network/android/CookieJarAndroid.cpp @@ -41,6 +41,12 @@ String cookies(const Document*, const KURL& url) return PlatformBridge::cookies(url); } +String cookieRequestHeaderFieldValue(const Document*, const KURL& url) +{ + // FIXME: include HttpOnly cookie. + return PlatformBridge::cookies(url); +} + bool cookiesEnabled(const Document*) { return PlatformBridge::cookiesEnabled(); diff --git a/WebCore/platform/network/chromium/CookieJarChromium.cpp b/WebCore/platform/network/chromium/CookieJarChromium.cpp index 35f1c3f..41cf331 100644 --- a/WebCore/platform/network/chromium/CookieJarChromium.cpp +++ b/WebCore/platform/network/chromium/CookieJarChromium.cpp @@ -47,6 +47,25 @@ String cookies(const Document* document, const KURL& url) return ChromiumBridge::cookies(url, document->firstPartyForCookies()); } +String cookieRequestHeaderFieldValue(const Document* document, const KURL& url) +{ + // FIXME: move in ChromiumBridge? + Vector<Cookie> cookies; + getRawCookies(document, url, cookies); + String cookieLine; + // FIXME: Set $Version=v; + for (size_t i = 0; i < cookies.size(); i++) { + Cookie cookie = cookies[i]; + if (i > 0) + cookieLine += "; "; + if (!cookie.name.isEmpty()) + cookieLine += cookie.name + "="; + cookieLine += cookie.value; + // FIXME: set $Path, $Domain, ... + } + return cookieLine; +} + bool cookiesEnabled(const Document* document) { return ChromiumBridge::cookiesEnabled(document->cookieURL(), document->firstPartyForCookies()); diff --git a/WebCore/platform/network/curl/CookieJarCurl.cpp b/WebCore/platform/network/curl/CookieJarCurl.cpp index 3bad4e4..7c906a0 100644 --- a/WebCore/platform/network/curl/CookieJarCurl.cpp +++ b/WebCore/platform/network/curl/CookieJarCurl.cpp @@ -39,6 +39,12 @@ String cookies(const Document* /*document*/, const KURL& url) return cookieJar.get(url.string()); } +String cookieRequestHeaderFieldValue(const Document* /*document*/, const KURL& url) +{ + // FIXME: include HttpOnly cookie. + return cookieJar.get(url.string()); +} + bool cookiesEnabled(const Document* /*document*/) { return true; diff --git a/WebCore/platform/network/curl/ResourceHandleCurl.cpp b/WebCore/platform/network/curl/ResourceHandleCurl.cpp index 81ac1a3..4212562 100644 --- a/WebCore/platform/network/curl/ResourceHandleCurl.cpp +++ b/WebCore/platform/network/curl/ResourceHandleCurl.cpp @@ -91,7 +91,7 @@ static HashSet<String>& allowsAnyHTTPSCertificateHosts() ResourceHandleInternal::~ResourceHandleInternal() { - free(m_url); + fastFree(m_url); if (m_customHeaders) curl_slist_free_all(m_customHeaders); } diff --git a/WebCore/platform/network/curl/ResourceHandleManager.cpp b/WebCore/platform/network/curl/ResourceHandleManager.cpp index bcae67f..962754c 100644 --- a/WebCore/platform/network/curl/ResourceHandleManager.cpp +++ b/WebCore/platform/network/curl/ResourceHandleManager.cpp @@ -135,13 +135,13 @@ ResourceHandleManager::~ResourceHandleManager() curl_multi_cleanup(m_curlMultiHandle); curl_share_cleanup(m_curlShareHandle); if (m_cookieJarFileName) - free(m_cookieJarFileName); + fastFree(m_cookieJarFileName); curl_global_cleanup(); } void ResourceHandleManager::setCookieJarFileName(const char* cookieJarFileName) { - m_cookieJarFileName = strdup(cookieJarFileName); + m_cookieJarFileName = fastStrDup(cookieJarFileName); } ResourceHandleManager* ResourceHandleManager::sharedInstance() @@ -741,7 +741,7 @@ void ResourceHandleManager::initializeHandle(ResourceHandle* job) ASSERT(!d->m_url); // url is in ASCII so latin1() will only convert it to char* without character translation. - d->m_url = strdup(url.latin1().data()); + d->m_url = fastStrDup(url.latin1().data()); curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url); if (m_cookieJarFileName) { diff --git a/WebCore/platform/network/soup/CookieJarSoup.cpp b/WebCore/platform/network/soup/CookieJarSoup.cpp index 3eb578a..d6479b2 100644 --- a/WebCore/platform/network/soup/CookieJarSoup.cpp +++ b/WebCore/platform/network/soup/CookieJarSoup.cpp @@ -24,6 +24,7 @@ #include "Cookie.h" #include "CString.h" #include "Document.h" +#include "GOwnPtrGtk.h" #include "KURL.h" namespace WebCore { @@ -54,16 +55,26 @@ void setDefaultCookieJar(SoupCookieJar* jar) g_object_ref(cookieJar); } -void setCookies(Document* /*document*/, const KURL& url, const String& value) +void setCookies(Document* document, const KURL& url, const String& value) { SoupCookieJar* jar = defaultCookieJar(); if (!jar) return; - SoupURI* origin = soup_uri_new(url.string().utf8().data()); + GOwnPtr<SoupURI> origin(soup_uri_new(url.string().utf8().data())); - soup_cookie_jar_set_cookie(jar, origin, value.utf8().data()); - soup_uri_free(origin); +#ifdef HAVE_LIBSOUP_2_29_90 + GOwnPtr<SoupURI> firstParty(soup_uri_new(document->firstPartyForCookies().string().utf8().data())); + + soup_cookie_jar_set_cookie_with_first_party(jar, + origin.get(), + firstParty.get(), + value.utf8().data()); +#else + soup_cookie_jar_set_cookie(jar, + origin.get(), + value.utf8().data()); +#endif } String cookies(const Document* /*document*/, const KURL& url) @@ -82,6 +93,22 @@ String cookies(const Document* /*document*/, const KURL& url) return result; } +String cookieRequestHeaderFieldValue(const Document* /*document*/, const KURL& url) +{ + SoupCookieJar* jar = defaultCookieJar(); + if (!jar) + return String(); + + SoupURI* uri = soup_uri_new(url.string().utf8().data()); + char* cookies = soup_cookie_jar_get_cookies(jar, uri, TRUE); + soup_uri_free(uri); + + String result(String::fromUTF8(cookies)); + g_free(cookies); + + return result; +} + bool cookiesEnabled(const Document* /*document*/) { return defaultCookieJar(); diff --git a/WebCore/platform/network/soup/DNSSoup.cpp b/WebCore/platform/network/soup/DNSSoup.cpp index ce55143..7f47efd 100644 --- a/WebCore/platform/network/soup/DNSSoup.cpp +++ b/WebCore/platform/network/soup/DNSSoup.cpp @@ -28,18 +28,21 @@ #include "DNS.h" #include "CString.h" +#include "GOwnPtrGtk.h" #include "ResourceHandle.h" namespace WebCore { void prefetchDNS(const String& hostname) { - #ifdef HAVE_LIBSOUP_2_29_3 +#ifdef HAVE_LIBSOUP_2_29_90 String uri = "http://"+hostname; - SoupURI* soupUri = soup_uri_new(uri.utf8().data()); - soup_session_prepare_for_uri(ResourceHandle::defaultSession(), soupUri); - soup_uri_free(soupUri); - #endif + GOwnPtr<SoupURI> soupURI(soup_uri_new(uri.utf8().data())); + // We may get invalid hostnames, so NULL-check here. + if (!soupURI) + return; + soup_session_prepare_for_uri(ResourceHandle::defaultSession(), soupURI.get()); +#endif } } diff --git a/WebCore/platform/network/soup/ResourceHandleSoup.cpp b/WebCore/platform/network/soup/ResourceHandleSoup.cpp index da16f4a..ee8e7aa 100644 --- a/WebCore/platform/network/soup/ResourceHandleSoup.cpp +++ b/WebCore/platform/network/soup/ResourceHandleSoup.cpp @@ -34,6 +34,7 @@ #include "DocLoader.h" #include "FileSystem.h" #include "Frame.h" +#include "GOwnPtrGtk.h" #include "HTTPParsers.h" #include "Logging.h" #include "MIMETypeRegistry.h" @@ -209,6 +210,15 @@ static void restartedCallback(SoupMessage* msg, gpointer data) if (d->client()) d->client()->willSendRequest(handle, request, response); + +#ifdef HAVE_LIBSOUP_2_29_90 + // Update the first party in case the base URL changed with the redirect + String firstPartyString = request.firstPartyForCookies().string(); + if (!firstPartyString.isEmpty()) { + GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data())); + soup_message_set_first_party(d->m_msg, firstParty.get()); + } +#endif } static void gotHeadersCallback(SoupMessage* msg, gpointer data) @@ -484,6 +494,13 @@ static bool startHttp(ResourceHandle* handle) g_signal_connect(d->m_msg, "content-sniffed", G_CALLBACK(contentSniffedCallback), handle); g_signal_connect(d->m_msg, "got-chunk", G_CALLBACK(gotChunkCallback), handle); +#ifdef HAVE_LIBSOUP_2_29_90 + String firstPartyString = request.firstPartyForCookies().string(); + if (!firstPartyString.isEmpty()) { + GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data())); + soup_message_set_first_party(d->m_msg, firstParty.get()); + } +#endif g_object_set_data(G_OBJECT(d->m_msg), "resourceHandle", reinterpret_cast<void*>(handle)); FormData* httpBody = d->m_request.httpBody(); diff --git a/WebCore/platform/network/soup/ResourceRequestSoup.cpp b/WebCore/platform/network/soup/ResourceRequestSoup.cpp index 0d4e0f9..d2c46a6 100644 --- a/WebCore/platform/network/soup/ResourceRequestSoup.cpp +++ b/WebCore/platform/network/soup/ResourceRequestSoup.cpp @@ -22,6 +22,7 @@ #include "CString.h" #include "GOwnPtr.h" +#include "GOwnPtrGtk.h" #include "PlatformString.h" #include <libsoup/soup.h> @@ -44,6 +45,14 @@ SoupMessage* ResourceRequest::toSoupMessage() const soup_message_headers_append(soupHeaders, it->first.string().utf8().data(), it->second.utf8().data()); } +#ifdef HAVE_LIBSOUP_2_29_90 + String firstPartyString = firstPartyForCookies().string(); + if (!firstPartyString.isEmpty()) { + GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data())); + soup_message_set_first_party(soupMessage, firstParty.get()); + } +#endif + // Body data is only handled at ResourceHandleSoup::startHttp for // now; this is because this may not be a good place to go // openning and mmapping files. We should maybe revisit this. @@ -69,9 +78,16 @@ void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage) if (soupMessage->request_body->data) m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length); - // FIXME: m_allowCookies and m_firstPartyForCookies should - // probably be handled here and on doUpdatePlatformRequest - // somehow. +#ifdef HAVE_LIBSOUP_2_29_90 + SoupURI* firstParty = soup_message_get_first_party(soupMessage); + if (firstParty) { + GOwnPtr<gchar> firstPartyURI(soup_uri_to_string(firstParty, FALSE)); + m_firstPartyForCookies = KURL(KURL(), String::fromUTF8(firstPartyURI.get())); + } +#endif + + // FIXME: m_allowCookies should probably be handled here and on + // doUpdatePlatformRequest somehow. } unsigned initializeMaximumHTTPConnectionCountPerHost() diff --git a/WebCore/platform/network/win/CookieJarCFNetWin.cpp b/WebCore/platform/network/win/CookieJarCFNetWin.cpp index 33b795a..d431289 100644 --- a/WebCore/platform/network/win/CookieJarCFNetWin.cpp +++ b/WebCore/platform/network/win/CookieJarCFNetWin.cpp @@ -106,6 +106,20 @@ String cookies(const Document* /*document*/, const KURL& url) return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); } +String cookieRequestHeaderFieldValue(const Document* /*document*/, const KURL& url) +{ + CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); + if (!cookieStorage) + return String(); + + RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); + + bool secure = url.protocolIs("https"); + RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(cookieStorage, urlCF.get(), secure)); + RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get())); + return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); +} + bool cookiesEnabled(const Document* /*document*/) { CFHTTPCookieStorageAcceptPolicy policy = CFHTTPCookieStorageAcceptPolicyOnlyFromMainDocumentDomain; diff --git a/WebCore/platform/network/win/CookieJarWin.cpp b/WebCore/platform/network/win/CookieJarWin.cpp index 6576e07..2bdd6b3 100644 --- a/WebCore/platform/network/win/CookieJarWin.cpp +++ b/WebCore/platform/network/win/CookieJarWin.cpp @@ -59,6 +59,12 @@ String cookies(const Document* /*document*/, const KURL& url) return String::adopt(buffer); } +String cookieRequestHeaderFieldValue(const Document* document, const KURL& url) +{ + // FIXME: include HttpOnly cookie + return cookies(document, url); +} + bool cookiesEnabled(const Document* /*document*/) { return true; |