<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[159432] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/159432">159432</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2013-11-18 10:35:10 -0800 (Mon, 18 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>[curl] Add file cache
https://bugs.webkit.org/show_bug.cgi?id=123333

Patch by Mátyás Mustoha &lt;mmatyas@inf.u-szeged.hu&gt; on 2013-11-18
Reviewed by Brent Fulgham.

Implementation of on disc file cache
for the curl network backend.

* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* platform/network/curl/CurlCacheEntry.cpp: Added.
(WebCore::CurlCacheEntry::CurlCacheEntry):
(WebCore::CurlCacheEntry::~CurlCacheEntry):
(WebCore::CurlCacheEntry::isCached):
(WebCore::CurlCacheEntry::requestHeaders):
(WebCore::CurlCacheEntry::saveCachedData):
(WebCore::CurlCacheEntry::loadCachedData):
(WebCore::CurlCacheEntry::saveResponseHeaders):
(WebCore::CurlCacheEntry::loadResponseHeaders):
(WebCore::CurlCacheEntry::setResponseFromCachedHeaders):
(WebCore::CurlCacheEntry::didFail):
(WebCore::CurlCacheEntry::didFinishLoading):
(WebCore::CurlCacheEntry::generateBaseFilename):
(WebCore::CurlCacheEntry::loadFileToBuffer):
(WebCore::CurlCacheEntry::invalidate):
(WebCore::CurlCacheEntry::parseResponseHeaders):
* platform/network/curl/CurlCacheEntry.h: Added.
(WebCore::CurlCacheEntry::isInMemory):
* platform/network/curl/CurlCacheManager.cpp: Added.
(WebCore::CurlCacheManager::getInstance):
(WebCore::CurlCacheManager::CurlCacheManager):
(WebCore::CurlCacheManager::~CurlCacheManager):
(WebCore::CurlCacheManager::setCacheDirectory):
(WebCore::CurlCacheManager::loadIndex):
(WebCore::CurlCacheManager::saveIndex):
(WebCore::CurlCacheManager::didReceiveResponse):
(WebCore::CurlCacheManager::didFinishLoading):
(WebCore::CurlCacheManager::isCached):
(WebCore::CurlCacheManager::requestHeaders):
(WebCore::CurlCacheManager::didReceiveData):
(WebCore::CurlCacheManager::saveResponseHeaders):
(WebCore::CurlCacheManager::invalidateCacheEntry):
(WebCore::CurlCacheManager::didFail):
(WebCore::CurlCacheManager::loadCachedData):
* platform/network/curl/CurlCacheManager.h: Added.
(WebCore::CurlCacheManager::getCacheDirectory):
* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::writeCallback):
(WebCore::headerCallback):
(WebCore::ResourceHandleManager::downloadTimerCallback):
(WebCore::ResourceHandleManager::initializeHandle):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkcurlResourceHandleManagercpp">trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformnetworkcurlCurlCacheEntrycpp">trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkcurlCurlCacheEntryh">trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkcurlCurlCacheManagercpp">trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkcurlCurlCacheManagerh">trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (159431 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2013-11-18 18:30:16 UTC (rev 159431)
+++ trunk/Source/WebCore/ChangeLog        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2013-11-18  Mátyás Mustoha  &lt;mmatyas@inf.u-szeged.hu&gt;
+
+        [curl] Add file cache
+        https://bugs.webkit.org/show_bug.cgi?id=123333
+
+        Reviewed by Brent Fulgham.
+
+        Implementation of on disc file cache
+        for the curl network backend.
+
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * platform/network/curl/CurlCacheEntry.cpp: Added.
+        (WebCore::CurlCacheEntry::CurlCacheEntry):
+        (WebCore::CurlCacheEntry::~CurlCacheEntry):
+        (WebCore::CurlCacheEntry::isCached):
+        (WebCore::CurlCacheEntry::requestHeaders):
+        (WebCore::CurlCacheEntry::saveCachedData):
+        (WebCore::CurlCacheEntry::loadCachedData):
+        (WebCore::CurlCacheEntry::saveResponseHeaders):
+        (WebCore::CurlCacheEntry::loadResponseHeaders):
+        (WebCore::CurlCacheEntry::setResponseFromCachedHeaders):
+        (WebCore::CurlCacheEntry::didFail):
+        (WebCore::CurlCacheEntry::didFinishLoading):
+        (WebCore::CurlCacheEntry::generateBaseFilename):
+        (WebCore::CurlCacheEntry::loadFileToBuffer):
+        (WebCore::CurlCacheEntry::invalidate):
+        (WebCore::CurlCacheEntry::parseResponseHeaders):
+        * platform/network/curl/CurlCacheEntry.h: Added.
+        (WebCore::CurlCacheEntry::isInMemory):
+        * platform/network/curl/CurlCacheManager.cpp: Added.
+        (WebCore::CurlCacheManager::getInstance):
+        (WebCore::CurlCacheManager::CurlCacheManager):
+        (WebCore::CurlCacheManager::~CurlCacheManager):
+        (WebCore::CurlCacheManager::setCacheDirectory):
+        (WebCore::CurlCacheManager::loadIndex):
+        (WebCore::CurlCacheManager::saveIndex):
+        (WebCore::CurlCacheManager::didReceiveResponse):
+        (WebCore::CurlCacheManager::didFinishLoading):
+        (WebCore::CurlCacheManager::isCached):
+        (WebCore::CurlCacheManager::requestHeaders):
+        (WebCore::CurlCacheManager::didReceiveData):
+        (WebCore::CurlCacheManager::saveResponseHeaders):
+        (WebCore::CurlCacheManager::invalidateCacheEntry):
+        (WebCore::CurlCacheManager::didFail):
+        (WebCore::CurlCacheManager::loadCachedData):
+        * platform/network/curl/CurlCacheManager.h: Added.
+        (WebCore::CurlCacheManager::getCacheDirectory):
+        * platform/network/curl/ResourceHandleManager.cpp:
+        (WebCore::writeCallback):
+        (WebCore::headerCallback):
+        (WebCore::ResourceHandleManager::downloadTimerCallback):
+        (WebCore::ResourceHandleManager::initializeHandle):
+
</ins><span class="cx"> 2013-11-18  peavo@outlook.com  &lt;peavo@outlook.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win] WebKit version in user agent string is incorrect.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (159431 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2013-11-18 18:30:16 UTC (rev 159431)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -8316,6 +8316,18 @@
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><ins>+    &lt;ClCompile Include=&quot;..\platform\network\curl\CurlCacheEntry.cpp&quot;&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+    &lt;/ClCompile&gt;
+    &lt;ClCompile Include=&quot;..\platform\network\curl\CurlCacheManager.cpp&quot;&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+    &lt;/ClCompile&gt;
</ins><span class="cx">     &lt;ClCompile Include=&quot;..\platform\network\curl\CurlDownload.cpp&quot;&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="lines">@@ -19474,6 +19486,18 @@
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">     &lt;/CustomBuildStep&gt;
</span><ins>+    &lt;CustomBuildStep Include=&quot;..\platform\network\curl\CurlCacheManager.h&quot;&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+    &lt;/CustomBuildStep&gt;
+    &lt;CustomBuildStep Include=&quot;..\platform\network\curl\CurlCacheEntry.h&quot;&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+    &lt;/CustomBuildStep&gt;
</ins><span class="cx">     &lt;CustomBuildStep Include=&quot;..\platform\network\curl\FormDataStreamCurl.h&quot;&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (159431 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2013-11-18 18:30:16 UTC (rev 159431)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -1896,6 +1896,12 @@
</span><span class="cx">     &lt;ClCompile Include=&quot;..\platform\network\curl\CredentialStorageCurl.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><ins>+    &lt;ClCompile Include=&quot;..\platform\network\curl\CurlCacheEntry.cpp&quot;&gt;
+      &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
+    &lt;/ClCompile&gt;
+    &lt;ClCompile Include=&quot;..\platform\network\curl\CurlCacheManager.cpp&quot;&gt;
+      &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
+    &lt;/ClCompile&gt;
</ins><span class="cx">     &lt;ClCompile Include=&quot;..\platform\network\curl\CurlDownload.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><span class="lines">@@ -15056,6 +15062,12 @@
</span><span class="cx">     &lt;CustomBuildStep Include=&quot;..\platform\network\curl\AuthenticationChallenge.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
</span><span class="cx">     &lt;/CustomBuildStep&gt;
</span><ins>+    &lt;CustomBuildStep Include=&quot;..\platform\network\curl\CurlCacheEntry.h&quot;&gt;
+      &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
+    &lt;/CustomBuildStep&gt;
+    &lt;CustomBuildStep Include=&quot;..\platform\network\curl\CurlCacheManager.h&quot;&gt;
+      &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
+    &lt;/CustomBuildStep&gt;
</ins><span class="cx">     &lt;CustomBuildStep Include=&quot;..\platform\network\curl\FormDataStreamCurl.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\network\curl&lt;/Filter&gt;
</span><span class="cx">     &lt;/CustomBuildStep&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkcurlCurlCacheEntrycpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp (0 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -0,0 +1,342 @@
</span><ins>+/*
+ * Copyright (C) 2013 University of Szeged
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+
+#include &quot;CurlCacheEntry.h&quot;
+
+#include &quot;FileSystem.h&quot;
+#include &quot;HTTPHeaderMap.h&quot;
+#include &quot;HTTPParsers.h&quot;
+#include &quot;Logging.h&quot;
+#include &quot;ResourceHandle.h&quot;
+#include &quot;ResourceHandleClient.h&quot;
+#include &quot;ResourceHandleInternal.h&quot;
+#include &quot;ResourceRequest.h&quot;
+#include &quot;ResourceResponse.h&quot;
+#include &lt;wtf/CurrentTime.h&gt;
+#include &lt;wtf/DateMath.h&gt;
+#include &lt;wtf/HexNumber.h&gt;
+#include &lt;wtf/MD5.h&gt;
+
+namespace WebCore {
+
+CurlCacheEntry::CurlCacheEntry(const String&amp; url, const String&amp; cacheDir)
+    : m_headerFilename(cacheDir)
+    , m_contentFilename(cacheDir)
+    , m_expireDate(-1)
+    , m_headerInMemory(false)
+{
+    generateBaseFilename(url.latin1());
+
+    m_headerFilename.append(m_basename);
+    m_headerFilename.append(&quot;.header&quot;);
+
+    m_contentFilename.append(m_basename);
+    m_contentFilename.append(&quot;.content&quot;);
+}
+
+CurlCacheEntry::~CurlCacheEntry()
+{
+}
+
+// cache manager should invalidate the entry on false
+bool CurlCacheEntry::isCached()
+{
+    if (!fileExists(m_contentFilename) || !fileExists(m_headerFilename))
+        return false;
+
+    if (!m_headerInMemory) {
+        if (!loadResponseHeaders())
+            return false;
+    }
+
+    if (m_expireDate &lt; currentTimeMS()) {
+        m_headerInMemory = false;
+        return false;
+    }
+
+    return true;
+}
+
+HTTPHeaderMap&amp; CurlCacheEntry::requestHeaders()
+{
+    return m_requestHeaders;
+}
+
+bool CurlCacheEntry::saveCachedData(const char* data, size_t size)
+{
+    PlatformFileHandle contentFile = openFile(m_contentFilename, OpenForWrite);
+    if (!isHandleValid(contentFile)) {
+        LOG(Network, &quot;Cache Error: Could not open %s for write\n&quot;, m_contentFilename.latin1().data());
+        return false;
+    }
+
+    // append
+    seekFile(contentFile, 0, SeekFromEnd);
+    writeToFile(contentFile, data, size);
+    closeFile(contentFile);
+    return true;
+}
+
+bool CurlCacheEntry::loadCachedData(ResourceHandle* job)
+{
+    ASSERT(job-&gt;client());
+
+    Vector&lt;char&gt; buffer;
+    if (!loadFileToBuffer(m_contentFilename, buffer))
+        return false;
+
+    job-&gt;getInternal()-&gt;client()-&gt;didReceiveData(job, buffer.data(), buffer.size(), 0);
+    return true;
+}
+
+bool CurlCacheEntry::saveResponseHeaders(ResourceResponse&amp; response)
+{
+    PlatformFileHandle headerFile = openFile(m_headerFilename, OpenForWrite);
+    if (!isHandleValid(headerFile)) {
+        LOG(Network, &quot;Cache Error: Could not open %s for write\n&quot;, m_headerFilename.latin1().data());
+        return false;
+    }
+
+    // Headers
+    HTTPHeaderMap::const_iterator it = response.httpHeaderFields().begin();
+    HTTPHeaderMap::const_iterator end = response.httpHeaderFields().end();
+    while (it != end) {
+        String headerField = it-&gt;key;
+        headerField.append(&quot;: &quot;);
+        headerField.append(it-&gt;value);
+        headerField.append(&quot;\n&quot;);
+        CString headerFieldLatin1 = headerField.latin1();
+        writeToFile(headerFile, headerFieldLatin1.data(), headerFieldLatin1.length());
+        ++it;
+    }
+
+    closeFile(headerFile);
+    return true;
+}
+
+bool CurlCacheEntry::loadResponseHeaders()
+{
+    Vector&lt;char&gt; buffer;
+    if (!loadFileToBuffer(m_headerFilename, buffer))
+        return false;
+
+    String headerContent = String(buffer.data());
+    Vector&lt;String&gt; headerFields;
+    headerContent.split(&quot;\n&quot;, headerFields);
+
+    Vector&lt;String&gt;::const_iterator it = headerFields.begin();
+    Vector&lt;String&gt;::const_iterator end = headerFields.end();
+    while (it != end) {
+        size_t splitPosition = it-&gt;find(&quot;:&quot;);
+        if (splitPosition != notFound)
+            m_cachedResponse.setHTTPHeaderField(it-&gt;left(splitPosition), it-&gt;substring(splitPosition+1).stripWhiteSpace());
+        ++it;
+    }
+
+    return parseResponseHeaders(m_cachedResponse);
+}
+
+// set response headers from memory
+void CurlCacheEntry::setResponseFromCachedHeaders(ResourceResponse&amp; response)
+{
+    response.setHTTPStatusCode(304);
+    response.setWasCached(true);
+
+    // Integrate the headers in the response with the cached ones.
+    HTTPHeaderMap::const_iterator it = m_cachedResponse.httpHeaderFields().begin();
+    HTTPHeaderMap::const_iterator end = m_cachedResponse.httpHeaderFields().end();
+    while (it != end) {
+        if (response.httpHeaderField(it-&gt;key).isNull())
+            response.setHTTPHeaderField(it-&gt;key, it-&gt;value);
+        ++it;
+    }
+
+    // Try to parse expected content length
+    long long contentLength = -1;
+    if (!response.httpHeaderField(&quot;Content-Length&quot;).isNull()) {
+        bool success = false;
+        long long parsedContentLength = response.httpHeaderField(&quot;Content-Length&quot;).toInt64(&amp;success);
+        if (success)
+            contentLength = parsedContentLength;
+    }
+    response.setExpectedContentLength(contentLength); // -1 on parse error or null
+
+    response.setMimeType(extractMIMETypeFromMediaType(response.httpHeaderField(&quot;Content-Type&quot;)));
+    response.setTextEncodingName(extractCharsetFromMediaType(response.httpHeaderField(&quot;Content-Type&quot;)));
+    response.setSuggestedFilename(filenameFromHTTPContentDisposition(response.httpHeaderField(&quot;Content-Disposition&quot;)));
+}
+
+void CurlCacheEntry::didFail()
+{
+    // the cache manager will call invalidate()
+}
+
+void CurlCacheEntry::didFinishLoading()
+{
+    // nothing to do here yet
+}
+
+void CurlCacheEntry::generateBaseFilename(const CString&amp; url)
+{
+    MD5 md5;
+    md5.addBytes(reinterpret_cast&lt;const uint8_t*&gt;(url.data()), url.length());
+
+    Vector&lt;uint8_t, 16&gt; sum;
+    md5.checksum(sum);
+    uint8_t* rawdata = sum.data();
+
+    for (unsigned i = 0; i &lt; 16; i++)
+        appendByteAsHex(rawdata[i], m_basename, Lowercase);
+}
+
+bool CurlCacheEntry::loadFileToBuffer(const String&amp; filepath, Vector&lt;char&gt;&amp; buffer)
+{
+    // open the file
+    PlatformFileHandle inputFile = openFile(filepath, OpenForRead);
+    if (!isHandleValid(inputFile)) {
+        LOG(Network, &quot;Cache Error: Could not open %s for read\n&quot;, filepath.latin1().data());
+        return false;
+    }
+
+    long long filesize = -1;
+    if (!getFileSize(filepath, filesize)) {
+        LOG(Network, &quot;Cache Error: Could not get file size of %s\n&quot;, filepath.latin1().data());
+        closeFile(inputFile);
+        return false;
+    }
+
+    // load the file content into buffer
+    buffer.resize(filesize);
+    int bufferPosition = 0;
+    int bufferReadSize = 4096;
+    int bytesRead = 0;
+    while (filesize &gt; bufferPosition) {
+        if (filesize - bufferPosition &lt; bufferReadSize)
+            bufferReadSize = filesize - bufferPosition;
+
+        bytesRead = readFromFile(inputFile, buffer.data() + bufferPosition, bufferReadSize);
+        if (bytesRead != bufferReadSize) {
+            LOG(Network, &quot;Cache Error: Could not read from %s\n&quot;, filepath.latin1().data());
+            closeFile(inputFile);
+            return false;
+        }
+
+        bufferPosition += bufferReadSize;
+    }
+    closeFile(inputFile);
+    return true;
+}
+
+void CurlCacheEntry::invalidate()
+{
+    deleteFile(m_headerFilename);
+    deleteFile(m_contentFilename);
+    LOG(Network, &quot;Cache: invalidated %s\n&quot;, m_basename.latin1().data());
+}
+
+bool CurlCacheEntry::parseResponseHeaders(ResourceResponse&amp; response)
+{
+    double fileTime;
+    time_t fileModificationDate;
+
+    if (getFileModificationTime(m_headerFilename, fileModificationDate)) {
+        fileTime = difftime(fileModificationDate, 0);
+        fileTime *= 1000.0;
+    } else
+        fileTime = currentTimeMS(); // GMT
+
+    if (response.cacheControlContainsNoCache() || response.cacheControlContainsNoStore())
+        return false;
+
+
+    double maxAge = 0;
+    bool maxAgeIsValid = false;
+
+    if (response.cacheControlContainsMustRevalidate())
+        maxAge = 0;
+    else {
+        maxAge = response.cacheControlMaxAge();
+        if (std::isnan(maxAge))
+            maxAge = 0;
+        else
+            maxAgeIsValid = true;
+    }
+
+    if (!response.hasCacheValidatorFields())
+        return false;
+
+
+    double lastModificationDate = 0;
+    double responseDate = 0;
+    double expirationDate = 0;
+
+    lastModificationDate = response.lastModified();
+    if (std::isnan(lastModificationDate))
+        lastModificationDate = 0;
+
+    responseDate = response.date();
+    if (std::isnan(responseDate))
+        responseDate = 0;
+
+    expirationDate = response.expires();
+    if (std::isnan(expirationDate))
+        expirationDate = 0;
+
+
+    if (maxAgeIsValid) {
+        // when both the cache entry and the response contain max-age, the lesser one takes priority
+        double expires = fileTime + maxAge * 1000;
+        if (m_expireDate == -1 || m_expireDate &gt; expires)
+            m_expireDate = expires;
+    } else if (responseDate &gt; 0 &amp;&amp; expirationDate &gt;= responseDate)
+        m_expireDate = fileTime + (expirationDate - responseDate);
+
+    // if there were no lifetime information
+    if (m_expireDate == -1) {
+        if (lastModificationDate &gt; 0)
+            m_expireDate = fileTime + (fileTime - lastModificationDate) * 0.1;
+        else
+            m_expireDate = 0;
+    }
+
+    String etag = response.httpHeaderField(&quot;ETag&quot;);
+    if (!etag.isNull())
+        m_requestHeaders.set(&quot;If-None-Match&quot;, etag);
+
+    String lastModified = response.httpHeaderField(&quot;Last-Modified&quot;);
+    if (!lastModified.isNull())
+        m_requestHeaders.set(&quot;If-Modified-Since&quot;, lastModified);
+
+    if (etag.isNull() &amp;&amp; lastModified.isNull())
+        return false;
+
+    m_headerInMemory = true;
+    return true;
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkcurlCurlCacheEntryh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h (0 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h                                (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -0,0 +1,80 @@
</span><ins>+/*
+ * Copyright (C) 2013 University of Szeged
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CurlCacheEntry_h
+#define CurlCacheEntry_h
+
+#include &quot;HTTPHeaderMap.h&quot;
+#include &quot;ResourceHandle.h&quot;
+#include &quot;ResourceRequest.h&quot;
+#include &quot;ResourceResponse.h&quot;
+#include &lt;wtf/Vector.h&gt;
+#include &lt;wtf/text/CString.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+namespace WebCore {
+
+class CurlCacheEntry {
+
+public:
+    CurlCacheEntry(const String&amp; url, const String&amp; cacheDir);
+    ~CurlCacheEntry();
+
+    bool isCached();
+    const bool&amp; isInMemory() { return m_headerInMemory; }
+    HTTPHeaderMap&amp; requestHeaders();
+
+    bool saveCachedData(const char* data, size_t);
+    bool loadCachedData(ResourceHandle*);
+
+    bool saveResponseHeaders(ResourceResponse&amp;);
+    void setResponseFromCachedHeaders(ResourceResponse&amp;);
+
+    void invalidate();
+    void didFail();
+    void didFinishLoading();
+
+    bool parseResponseHeaders(ResourceResponse&amp;);
+
+private:
+    String m_basename;
+    String m_headerFilename;
+    String m_contentFilename;
+
+    double m_expireDate;
+    bool m_headerInMemory;
+
+    ResourceResponse m_cachedResponse;
+    HTTPHeaderMap m_requestHeaders;
+
+    void generateBaseFilename(const CString&amp; url);
+    bool loadFileToBuffer(const String&amp; filepath, Vector&lt;char&gt;&amp; buffer);
+    bool loadResponseHeaders();
+};
+
+}
+
+#endif // CurlCacheEntry_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkcurlCurlCacheManagercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp (0 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -0,0 +1,275 @@
</span><ins>+/*
+ * Copyright (C) 2013 University of Szeged
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;CurlCacheManager.h&quot;
+
+#include &quot;FileSystem.h&quot;
+#include &quot;HTTPHeaderMap.h&quot;
+#include &quot;Logging.h&quot;
+#include &quot;ResourceHandleClient.h&quot;
+#include &quot;ResourceHandleInternal.h&quot;
+#include &quot;ResourceRequest.h&quot;
+#include &lt;wtf/HashMap.h&gt;
+#include &lt;wtf/text/CString.h&gt;
+
+#define IO_BUFFERSIZE 4096
+
+namespace WebCore {
+
+CurlCacheManager&amp; CurlCacheManager::getInstance()
+{
+    static CurlCacheManager instance;
+    return instance;
+}
+
+CurlCacheManager::CurlCacheManager()
+    : m_disabled(true)
+{
+    // call setCacheDirectory() to enable
+}
+
+CurlCacheManager::~CurlCacheManager()
+{
+    if (m_disabled)
+        return;
+
+    saveIndex();
+}
+
+void CurlCacheManager::setCacheDirectory(const String&amp; directory)
+{
+    m_cacheDir = directory;
+    m_cacheDir.append(&quot;/&quot;);
+    if (m_cacheDir.isEmpty()) {
+        LOG(Network, &quot;Cache Error: Cache location is not set! CacheManager disabled.\n&quot;);
+        m_disabled = true;
+        return;
+    }
+
+    if (!fileExists(m_cacheDir)) {
+        if (makeAllDirectories(m_cacheDir)) {
+            LOG(Network, &quot;Cache Error: Could not open or create cache directory! CacheManager disabled.\n&quot;);
+            m_disabled = true;
+            return;
+        }
+    }
+
+    m_disabled = false;
+    loadIndex();
+}
+
+void CurlCacheManager::loadIndex()
+{
+    if (m_disabled)
+        return;
+
+    String indexFilePath(m_cacheDir);
+    indexFilePath.append(&quot;index.dat&quot;);
+
+    PlatformFileHandle indexFile = openFile(indexFilePath, OpenForRead);
+    if (!isHandleValid(indexFile)) {
+        LOG(Network, &quot;Cache Warning: Could not open %s for read\n&quot;, indexFilePath.latin1().data());
+        return;
+    }
+
+    long long filesize = -1;
+    if (!getFileSize(indexFilePath, filesize)) {
+        LOG(Network, &quot;Cache Error: Could not get file size of %s\n&quot;, indexFilePath.latin1().data());
+        return;
+    }
+
+    // load the file content into buffer
+    Vector&lt;char&gt; buffer;
+    buffer.resize(filesize);
+    int bufferPosition = 0;
+    int bufferReadSize = IO_BUFFERSIZE;
+    while (filesize &gt; bufferPosition) {
+        if (filesize - bufferPosition &lt; bufferReadSize)
+            bufferReadSize = filesize - bufferPosition;
+
+        readFromFile(indexFile, buffer.data() + bufferPosition, bufferReadSize);
+        bufferPosition += bufferReadSize;
+    }
+    closeFile(indexFile);
+
+    // create strings from buffer
+    String headerContent = String(buffer.data());
+    Vector&lt;String&gt; indexURLs;
+    headerContent.split(&quot;\n&quot;, indexURLs);
+    buffer.clear();
+
+    // add entries to index
+    Vector&lt;String&gt;::const_iterator it = indexURLs.begin();
+    Vector&lt;String&gt;::const_iterator end = indexURLs.end();
+    if (indexURLs.size() &gt; 1)
+        --end; // last line is empty
+    while (it != end) {
+        String url = it-&gt;stripWhiteSpace();
+
+        std::unique_ptr&lt;CurlCacheEntry&gt; cacheEntry(new CurlCacheEntry(url, m_cacheDir));
+        if (cacheEntry-&gt;isCached())
+            m_index.set(url, std::move(cacheEntry));
+
+        ++it;
+    }
+}
+
+void CurlCacheManager::saveIndex()
+{
+    if (m_disabled)
+        return;
+
+    String indexFilePath(m_cacheDir);
+    indexFilePath.append(&quot;index.dat&quot;);
+
+    PlatformFileHandle indexFile = openFile(indexFilePath, OpenForWrite);
+    if (!isHandleValid(indexFile)) {
+        LOG(Network, &quot;Cache Error: Could not open %s for write\n&quot;, indexFilePath.latin1().data());
+        return;
+    }
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::const_iterator it = m_index.begin();
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::const_iterator end = m_index.end();
+    while (it != end) {
+        const CString&amp; urlLatin1 = it-&gt;key.latin1();
+        writeToFile(indexFile, urlLatin1.data(), urlLatin1.length());
+        writeToFile(indexFile, &quot;\n&quot;, 1);
+        ++it;
+    }
+
+    closeFile(indexFile);
+}
+
+void CurlCacheManager::didReceiveResponse(ResourceHandle* job, ResourceResponse&amp; response)
+{
+    if (m_disabled)
+        return;
+
+    String url = job-&gt;firstRequest().url().string();
+
+    if (response.httpStatusCode() == 304)
+        loadCachedData(url, job, response);
+    else if (response.httpStatusCode() == 200) {
+        HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+        if (it != m_index.end())
+            invalidateCacheEntry(url);
+
+        std::unique_ptr&lt;CurlCacheEntry&gt; entry(new CurlCacheEntry(url, m_cacheDir));
+        bool cacheable = entry-&gt;parseResponseHeaders(response);
+        if (cacheable) {
+            m_index.set(url, std::move(entry));
+            saveResponseHeaders(url, response);
+        } else
+            entry-&gt;invalidate();
+    } else
+        invalidateCacheEntry(url);
+}
+
+void CurlCacheManager::didFinishLoading(const String&amp; url)
+{
+    if (m_disabled)
+        return;
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+    if (it != m_index.end())
+        it-&gt;value-&gt;didFinishLoading();
+}
+
+bool CurlCacheManager::isCached(const String&amp; url)
+{
+    if (m_disabled)
+        return false;
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+    if (it != m_index.end()) {
+        if (it-&gt;value-&gt;isCached())
+            return true;
+
+        invalidateCacheEntry(url);
+    }
+    return false;
+}
+
+HTTPHeaderMap&amp; CurlCacheManager::requestHeaders(const String&amp; url)
+{
+    ASSERT(isCached(url));
+    return m_index.find(url)-&gt;value-&gt;requestHeaders();
+}
+
+void CurlCacheManager::didReceiveData(const String&amp; url, const char* data, size_t size)
+{
+    if (m_disabled)
+        return;
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+    if (it != m_index.end())
+        if (!it-&gt;value-&gt;saveCachedData(data, size))
+            invalidateCacheEntry(url);
+}
+
+void CurlCacheManager::saveResponseHeaders(const String&amp; url, ResourceResponse&amp; response)
+{
+    if (m_disabled)
+        return;
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+    if (it != m_index.end())
+        if (!it-&gt;value-&gt;saveResponseHeaders(response))
+            invalidateCacheEntry(url);
+}
+
+void CurlCacheManager::invalidateCacheEntry(const String&amp; url)
+{
+    if (m_disabled)
+        return;
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+    if (it != m_index.end()) {
+        it-&gt;value-&gt;invalidate();
+        m_index.remove(url);
+    }
+}
+
+void CurlCacheManager::didFail(const String&amp; url)
+{
+    invalidateCacheEntry(url);
+}
+
+void CurlCacheManager::loadCachedData(const String&amp; url, ResourceHandle* job, ResourceResponse&amp; response)
+{
+    if (m_disabled)
+        return;
+
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt;::iterator it = m_index.find(url);
+    if (it != m_index.end()) {
+        it-&gt;value-&gt;setResponseFromCachedHeaders(response);
+        if (!it-&gt;value-&gt;loadCachedData(job))
+            invalidateCacheEntry(url);
+    }
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkcurlCurlCacheManagerh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h (0 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h                                (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -0,0 +1,74 @@
</span><ins>+/*
+ * Copyright (C) 2013 University of Szeged
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CurlCacheManager_h
+#define CurlCacheManager_h
+
+#include &quot;CurlCacheEntry.h&quot;
+#include &quot;ResourceHandle.h&quot;
+#include &quot;ResourceResponse.h&quot;
+#include &lt;wtf/HashMap.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+namespace WebCore {
+
+class CurlCacheManager {
+
+public:
+    static CurlCacheManager&amp; getInstance();
+
+    const String&amp; getCacheDirectory() { return m_cacheDir; }
+    void setCacheDirectory(const String&amp;);
+
+    bool isCached(const String&amp;);
+    HTTPHeaderMap&amp; requestHeaders(const String&amp;); // load headers
+
+    void didReceiveResponse(ResourceHandle*, ResourceResponse&amp;);
+    void didReceiveData(const String&amp;, const char*, size_t); // save data
+    void didFail(const String&amp;);
+    void didFinishLoading(const String&amp;);
+
+private:
+    CurlCacheManager();
+    ~CurlCacheManager();
+    CurlCacheManager(CurlCacheManager const&amp;);
+    void operator=(CurlCacheManager const&amp;);
+
+    String m_cacheDir;
+    HashMap&lt;String, std::unique_ptr&lt;CurlCacheEntry&gt;&gt; m_index;
+    bool m_disabled;
+
+    void saveIndex();
+    void loadIndex();
+
+    void saveResponseHeaders(const String&amp;, ResourceResponse&amp;);
+    void invalidateCacheEntry(const String&amp;);
+    void loadCachedData(const String&amp;, ResourceHandle*, ResourceResponse&amp;);
+};
+
+}
+
+#endif // CurlCacheManager_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkcurlResourceHandleManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp (159431 => 159432)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp        2013-11-18 18:30:16 UTC (rev 159431)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp        2013-11-18 18:35:10 UTC (rev 159432)
</span><span class="lines">@@ -9,6 +9,7 @@
</span><span class="cx">  * Copyright (C) 2009 Brent Fulgham &lt;bfulgham@webkit.org&gt;
</span><span class="cx">  * Copyright (C) 2013 Peter Gal &lt;galpeter@inf.u-szeged.hu&gt;, University of Szeged
</span><span class="cx">  * Copyright (C) 2013 Alex Christensen &lt;achristensen@webkit.org&gt;
</span><ins>+ * Copyright (C) 2013 University of Szeged
</ins><span class="cx">  * All rights reserved.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -37,6 +38,7 @@
</span><span class="cx"> #include &quot;ResourceHandleManager.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CredentialStorage.h&quot;
</span><ins>+#include &quot;CurlCacheManager.h&quot;
</ins><span class="cx"> #include &quot;DataURL.h&quot;
</span><span class="cx"> #include &quot;HTTPParsers.h&quot;
</span><span class="cx"> #include &quot;MIMETypeRegistry.h&quot;
</span><span class="lines">@@ -268,8 +270,10 @@
</span><span class="cx"> 
</span><span class="cx">     if (d-&gt;m_multipartHandle)
</span><span class="cx">         d-&gt;m_multipartHandle-&gt;contentReceived(static_cast&lt;const char*&gt;(ptr), totalSize);
</span><del>-    else if (d-&gt;client())
</del><ins>+    else if (d-&gt;client()) {
</ins><span class="cx">         d-&gt;client()-&gt;didReceiveData(job, static_cast&lt;char*&gt;(ptr), totalSize, 0);
</span><ins>+        CurlCacheManager::getInstance().didReceiveData(job-&gt;firstRequest().url().string(), static_cast&lt;char*&gt;(ptr), totalSize);
+    }
</ins><span class="cx"> 
</span><span class="cx">     return totalSize;
</span><span class="cx"> }
</span><span class="lines">@@ -459,8 +463,10 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (client)
</del><ins>+        if (client) {
</ins><span class="cx">             client-&gt;didReceiveResponse(job, d-&gt;m_response);
</span><ins>+            CurlCacheManager::getInstance().didReceiveResponse(job, d-&gt;m_response);
+        }
</ins><span class="cx">         d-&gt;m_response.setResponseFired(true);
</span><span class="cx"> 
</span><span class="cx">     } else {
</span><span class="lines">@@ -605,16 +611,20 @@
</span><span class="cx">             if (d-&gt;m_multipartHandle)
</span><span class="cx">                 d-&gt;m_multipartHandle-&gt;contentEnded();
</span><span class="cx"> 
</span><del>-            if (d-&gt;client())
</del><ins>+            if (d-&gt;client()) {
</ins><span class="cx">                 d-&gt;client()-&gt;didFinishLoading(job, 0);
</span><ins>+                CurlCacheManager::getInstance().didFinishLoading(job-&gt;firstRequest().url().string());
+            }
</ins><span class="cx">         } else {
</span><span class="cx">             char* url = 0;
</span><span class="cx">             curl_easy_getinfo(d-&gt;m_handle, CURLINFO_EFFECTIVE_URL, &amp;url);
</span><span class="cx"> #ifndef NDEBUG
</span><span class="cx">             fprintf(stderr, &quot;Curl ERROR for url='%s', error: '%s'\n&quot;, url, curl_easy_strerror(msg-&gt;data.result));
</span><span class="cx"> #endif
</span><del>-            if (d-&gt;client())
</del><ins>+            if (d-&gt;client()) {
</ins><span class="cx">                 d-&gt;client()-&gt;didFail(job, ResourceError(String(), msg-&gt;data.result, String(url), String(curl_easy_strerror(msg-&gt;data.result))));
</span><ins>+                CurlCacheManager::getInstance().didFail(job-&gt;firstRequest().url().string());
+            }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         removeFromCurl(job);
</span><span class="lines">@@ -969,6 +979,19 @@
</span><span class="cx">     struct curl_slist* headers = 0;
</span><span class="cx">     if (job-&gt;firstRequest().httpHeaderFields().size() &gt; 0) {
</span><span class="cx">         HTTPHeaderMap customHeaders = job-&gt;firstRequest().httpHeaderFields();
</span><ins>+
+        if (CurlCacheManager::getInstance().isCached(url)) {
+            HTTPHeaderMap&amp; requestHeaders = CurlCacheManager::getInstance().requestHeaders(url);
+
+            // append additional cache information
+            HTTPHeaderMap::const_iterator it = requestHeaders.begin();
+            HTTPHeaderMap::const_iterator end = requestHeaders.end();
+            while (it != end) {
+                customHeaders.set(it-&gt;key, it-&gt;value);
+                ++it;
+            }
+        }
+
</ins><span class="cx">         HTTPHeaderMap::const_iterator end = customHeaders.end();
</span><span class="cx">         for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) {
</span><span class="cx">             String key = it-&gt;key;
</span></span></pre>
</div>
</div>

</body>
</html>