[Curl] setCookiesFromDOM function does not save cookies to disk.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Feb 2013 04:34:21 +0000 (04:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Feb 2013 04:34:21 +0000 (04:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109285

Patch by peavo@outlook.com <peavo@outlook.com> on 2013-02-11
Reviewed by Brent Fulgham.

Write cookies to disk by using the Curl easy api.

* platform/network/curl/CookieJarCurl.cpp:
(WebCore::setCookiesFromDOM):Write cookie to disk.
* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::ResourceHandleManager::getCurlShareHandle): Added method to get Curl share handle.
(WebCore::ResourceHandleManager::getCookieJarFileName): Added method to get cookie file name.
* platform/network/curl/ResourceHandleManager.h: Added methods to get cookie file name, and Curl share handle.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142574 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/curl/CookieJarCurl.cpp
Source/WebCore/platform/network/curl/ResourceHandleManager.cpp
Source/WebCore/platform/network/curl/ResourceHandleManager.h

index 313b23f976b9141dffbcb32195c60cd8df08f418..02fd4e27db9be5ba7e8607dbcb8e1ef5ece062e9 100644 (file)
@@ -1,3 +1,19 @@
+2013-02-11  peavo@outlook.com  <peavo@outlook.com>
+
+        [Curl] setCookiesFromDOM function does not save cookies to disk.
+        https://bugs.webkit.org/show_bug.cgi?id=109285
+
+        Reviewed by Brent Fulgham.
+
+        Write cookies to disk by using the Curl easy api.
+
+        * platform/network/curl/CookieJarCurl.cpp:
+        (WebCore::setCookiesFromDOM):Write cookie to disk.
+        * platform/network/curl/ResourceHandleManager.cpp:
+        (WebCore::ResourceHandleManager::getCurlShareHandle): Added method to get Curl share handle.
+        (WebCore::ResourceHandleManager::getCookieJarFileName): Added method to get cookie file name.
+        * platform/network/curl/ResourceHandleManager.h: Added methods to get cookie file name, and Curl share handle.
+
 2013-02-11  Hayato Ito  <hayato@chromium.org>
 
         Split each RuleSet and feature out from StyleResolver into its own class.
index e91459fa3f22a75172005f0bf4f6484299288406..0042e3c7543e3cac0c9919dc1a5188ded5b931ec 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "Cookie.h"
 #include "KURL.h"
+#include "ResourceHandleManager.h"
+
 #include <wtf/HashMap.h>
 #include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
@@ -30,6 +32,30 @@ static HashMap<String, String> cookieJar;
 void setCookiesFromDOM(const NetworkStorageSession&, const KURL&, const KURL& url, const String& value)
 {
     cookieJar.set(url.string(), value);
+
+    CURL* curl = curl_easy_init();
+
+    if (!curl)
+        return;
+
+    const char* cookieJarFileName = ResourceHandleManager::sharedInstance()->getCookieJarFileName();
+    CURLSH* curlsh = ResourceHandleManager::sharedInstance()->getCurlShareHandle();
+
+    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieJarFileName);
+    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieJarFileName);
+    curl_easy_setopt(curl, CURLOPT_SHARE, curlsh);
+
+    String cookie("Set-Cookie: ");
+    if (value.is8Bit())
+        cookie.append(value);
+    else
+        cookie.append(String::make8BitFrom16BitSource(value.characters16(), value.length()));
+
+    CString strCookie(reinterpret_cast<const char*>(cookie.characters8()), cookie.length());
+
+    curl_easy_setopt(curl, CURLOPT_COOKIELIST, strCookie.data());
+
+    curl_easy_cleanup(curl);
 }
 
 String cookiesForDOM(const NetworkStorageSession&, const KURL&, const KURL& url)
index 43f43fa76efd88ec5aaa9f27ab64b8d562271459..9d6885c9c9028df7d944a066aaee89c7ab0dcbdc 100644 (file)
@@ -151,11 +151,21 @@ ResourceHandleManager::~ResourceHandleManager()
     curl_global_cleanup();
 }
 
+CURLSH* ResourceHandleManager::getCurlShareHandle() const
+{
+    return m_curlShareHandle;
+}
+
 void ResourceHandleManager::setCookieJarFileName(const char* cookieJarFileName)
 {
     m_cookieJarFileName = fastStrDup(cookieJarFileName);
 }
 
+const char* ResourceHandleManager::getCookieJarFileName() const
+{
+    return m_cookieJarFileName;
+}
+
 ResourceHandleManager* ResourceHandleManager::sharedInstance()
 {
     static ResourceHandleManager* sharedInstance = 0;
index 1dc14efc1a2072dcb87eb01b7273dd5feff92665..86a4a5fa2c93cd8920ad5391ba24082849c053c6 100644 (file)
@@ -56,7 +56,11 @@ public:
     static ResourceHandleManager* sharedInstance();
     void add(ResourceHandle*);
     void cancel(ResourceHandle*);
+
+    CURLSH* getCurlShareHandle() const;
+
     void setCookieJarFileName(const char* cookieJarFileName);
+    const char* getCookieJarFileName() const;
 
     void dispatchSynchronousJob(ResourceHandle*);