<!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>[175748] trunk/Source/WebKit2</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/175748">175748</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2014-11-07 03:29:55 -0800 (Fri, 07 Nov 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add cache coders
https://bugs.webkit.org/show_bug.cgi?id=138413
Reviewed by Anders Carlsson.
Add encoding and decoding support for cache types.
This is largely a copy of the IPC coder classes with some unnecessary features removed.
The coders compute a type-sensitive checksum that can be used to verify the data integrity.
The code is behind ENABLE(NETWORK_CACHE) and not yet used.
* NetworkProcess/cache: Added.
* NetworkProcess/cache/NetworkCacheCoder.h: Added.
* NetworkProcess/cache/NetworkCacheCoders.cpp: Added.
* NetworkProcess/cache/NetworkCacheCoders.h: Added.
* NetworkProcess/cache/NetworkCacheDecoder.cpp: Added.
* NetworkProcess/cache/NetworkCacheDecoder.h: Added.
* NetworkProcess/cache/NetworkCacheEncoder.cpp: Added.
* NetworkProcess/cache/NetworkCacheEncoder.h: Added.
* WebKit2.xcodeproj/project.pbxproj:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>trunk/Source/WebKit2/NetworkProcess/cache/</li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheCoderh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheCoderscpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheCodersh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheDecodercpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheDecoderh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEncodercpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEncoderh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (175747 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-11-07 11:28:53 UTC (rev 175747)
+++ trunk/Source/WebKit2/ChangeLog        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-11-07 Antti Koivisto <antti@apple.com>
+
+ Add cache coders
+ https://bugs.webkit.org/show_bug.cgi?id=138413
+
+ Reviewed by Anders Carlsson.
+
+ Add encoding and decoding support for cache types.
+
+ This is largely a copy of the IPC coder classes with some unnecessary features removed.
+ The coders compute a type-sensitive checksum that can be used to verify the data integrity.
+
+ The code is behind ENABLE(NETWORK_CACHE) and not yet used.
+
+ * NetworkProcess/cache: Added.
+ * NetworkProcess/cache/NetworkCacheCoder.h: Added.
+ * NetworkProcess/cache/NetworkCacheCoders.cpp: Added.
+ * NetworkProcess/cache/NetworkCacheCoders.h: Added.
+ * NetworkProcess/cache/NetworkCacheDecoder.cpp: Added.
+ * NetworkProcess/cache/NetworkCacheDecoder.h: Added.
+ * NetworkProcess/cache/NetworkCacheEncoder.cpp: Added.
+ * NetworkProcess/cache/NetworkCacheEncoder.h: Added.
+ * WebKit2.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2014-11-06 Conrad Shultz <conrad_shultz@apple.com>
</span><span class="cx">
</span><span class="cx"> Clients should be able to customize the view used for page previews
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheCoderh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,51 @@
</span><ins>+/*
+ * Copyright (C) 2010, 2014 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 NetworkCacheCoder_h
+#define NetworkCacheCoder_h
+
+#if ENABLE(NETWORK_CACHE)
+
+namespace WebKit {
+
+class NetworkCacheDecoder;
+class NetworkCacheEncoder;
+
+template<typename T> struct NetworkCacheCoder {
+ static void encode(NetworkCacheEncoder& encoder, const T& t)
+ {
+ t.encode(encoder);
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, T& t)
+ {
+ return T::decode(decoder, t);
+ }
+};
+
+}
+
+#endif
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheCoderscpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,178 @@
</span><ins>+/*
+ * Copyright (C) 2011, 2014 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 "config.h"
+#include "NetworkCacheCoders.h"
+
+#if ENABLE(NETWORK_CACHE)
+
+#include "WebCoreArgumentCoders.h"
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+void NetworkCacheCoder<AtomicString>::encode(NetworkCacheEncoder& encoder, const AtomicString& atomicString)
+{
+ encoder << atomicString.string();
+}
+
+bool NetworkCacheCoder<AtomicString>::decode(NetworkCacheDecoder& decoder, AtomicString& atomicString)
+{
+ String string;
+ if (!decoder.decode(string))
+ return false;
+
+ atomicString = string;
+ return true;
+}
+
+void NetworkCacheCoder<CString>::encode(NetworkCacheEncoder& encoder, const CString& string)
+{
+ // Special case the null string.
+ if (string.isNull()) {
+ encoder << std::numeric_limits<uint32_t>::max();
+ return;
+ }
+
+ uint32_t length = string.length();
+ encoder << length;
+ encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length, 1);
+}
+
+bool NetworkCacheCoder<CString>::decode(NetworkCacheDecoder& decoder, CString& result)
+{
+ uint32_t length;
+ if (!decoder.decode(length))
+ return false;
+
+ if (length == std::numeric_limits<uint32_t>::max()) {
+ // This is the null string.
+ result = CString();
+ return true;
+ }
+
+ // Before allocating the string, make sure that the decoder buffer is big enough.
+ if (!decoder.bufferIsLargeEnoughToContain<char>(length)) {
+ decoder.markInvalid();
+ return false;
+ }
+
+ char* buffer;
+ CString string = CString::newUninitialized(length, buffer);
+ if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length, 1))
+ return false;
+
+ result = string;
+ return true;
+}
+
+
+void NetworkCacheCoder<String>::encode(NetworkCacheEncoder& encoder, const String& string)
+{
+ // Special case the null string.
+ if (string.isNull()) {
+ encoder << std::numeric_limits<uint32_t>::max();
+ return;
+ }
+
+ uint32_t length = string.length();
+ bool is8Bit = string.is8Bit();
+
+ encoder << length << is8Bit;
+
+ if (is8Bit)
+ encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar), alignof(LChar));
+ else
+ encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), alignof(UChar));
+}
+
+template <typename CharacterType>
+static inline bool decodeStringText(NetworkCacheDecoder& decoder, uint32_t length, String& result)
+{
+ // Before allocating the string, make sure that the decoder buffer is big enough.
+ if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length)) {
+ decoder.markInvalid();
+ return false;
+ }
+
+ CharacterType* buffer;
+ String string = String::createUninitialized(length, buffer);
+ if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType), alignof(CharacterType)))
+ return false;
+
+ result = string;
+ return true;
+}
+
+bool NetworkCacheCoder<String>::decode(NetworkCacheDecoder& decoder, String& result)
+{
+ uint32_t length;
+ if (!decoder.decode(length))
+ return false;
+
+ if (length == std::numeric_limits<uint32_t>::max()) {
+ // This is the null string.
+ result = String();
+ return true;
+ }
+
+ bool is8Bit;
+ if (!decoder.decode(is8Bit))
+ return false;
+
+ if (is8Bit)
+ return decodeStringText<LChar>(decoder, length, result);
+ return decodeStringText<UChar>(decoder, length, result);
+}
+
+void NetworkCacheCoder<WebCore::CertificateInfo>::encode(NetworkCacheEncoder& encoder, const WebCore::CertificateInfo& certificateInfo)
+{
+ // FIXME: Cocoa CertificateInfo is a CF object tree. Generalize CF type coding so we don't need to use ArgumentCoder here.
+ IPC::ArgumentEncoder argumentEncoder;
+ argumentEncoder << certificateInfo;
+ encoder << static_cast<uint64_t>(argumentEncoder.bufferSize());
+ encoder.encodeFixedLengthData(argumentEncoder.buffer(), argumentEncoder.bufferSize(), 1);
+}
+
+bool NetworkCacheCoder<WebCore::CertificateInfo>::decode(NetworkCacheDecoder& decoder, WebCore::CertificateInfo& certificateInfo)
+{
+ uint64_t certificateSize;
+ if (!decoder.decode(certificateSize))
+ return false;
+ Vector<uint8_t> data(certificateSize);
+ if (!decoder.decodeFixedLengthData(data.data(), data.size(), 1))
+ return false;
+ IPC::ArgumentDecoder argumentDecoder(data.data(), data.size());
+ if (!argumentDecoder.decode(certificateInfo)) {
+ decoder.markInvalid();
+ return false;
+ }
+ return true;
+}
+
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheCodersh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,261 @@
</span><ins>+/*
+ * Copyright (C) 2010, 2014 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 NetworkCacheCoders_h
+#define NetworkCacheCoders_h
+
+#if ENABLE(NETWORK_CACHE)
+
+#include "NetworkCacheDecoder.h"
+#include "NetworkCacheEncoder.h"
+#include <WebCore/CertificateInfo.h>
+#include <utility>
+#include <wtf/Forward.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/Vector.h>
+
+namespace WebKit {
+
+template<typename T, typename U> struct NetworkCacheCoder<std::pair<T, U>> {
+ static void encode(NetworkCacheEncoder& encoder, const std::pair<T, U>& pair)
+ {
+ encoder << pair.first << pair.second;
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, std::pair<T, U>& pair)
+ {
+ T first;
+ if (!decoder.decode(first))
+ return false;
+
+ U second;
+ if (!decoder.decode(second))
+ return false;
+
+ pair.first = first;
+ pair.second = second;
+ return true;
+ }
+};
+
+template<typename Rep, typename Period> struct NetworkCacheCoder<std::chrono::duration<Rep, Period>> {
+ static void encode(NetworkCacheEncoder& encoder, const std::chrono::duration<Rep, Period>& duration)
+ {
+ static_assert(std::is_integral<Rep>::value && std::is_signed<Rep>::value && sizeof(Rep) <= sizeof(int64_t), "Serialization of this Rep type is not supported yet. Only signed integer type which can be fit in an int64_t is currently supported.");
+ encoder << static_cast<int64_t>(duration.count());
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, std::chrono::duration<Rep, Period>& result)
+ {
+ int64_t count;
+ if (!decoder.decode(count))
+ return false;
+ result = std::chrono::duration<Rep, Period>(static_cast<Rep>(count));
+ return true;
+ }
+};
+
+template<typename KeyType, typename ValueType> struct NetworkCacheCoder<WTF::KeyValuePair<KeyType, ValueType>> {
+ static void encode(NetworkCacheEncoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)
+ {
+ encoder << pair.key << pair.value;
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
+ {
+ KeyType key;
+ if (!decoder.decode(key))
+ return false;
+
+ ValueType value;
+ if (!decoder.decode(value))
+ return false;
+
+ pair.key = key;
+ pair.value = value;
+ return true;
+ }
+};
+
+template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct VectorNetworkCacheCoder;
+
+template<typename T, size_t inlineCapacity> struct VectorNetworkCacheCoder<false, T, inlineCapacity> {
+ static void encode(NetworkCacheEncoder& encoder, const Vector<T, inlineCapacity>& vector)
+ {
+ encoder << static_cast<uint64_t>(vector.size());
+ for (size_t i = 0; i < vector.size(); ++i)
+ encoder << vector[i];
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, Vector<T, inlineCapacity>& vector)
+ {
+ uint64_t size;
+ if (!decoder.decode(size))
+ return false;
+
+ Vector<T, inlineCapacity> tmp;
+ for (size_t i = 0; i < size; ++i) {
+ T element;
+ if (!decoder.decode(element))
+ return false;
+
+ tmp.append(WTF::move(element));
+ }
+
+ tmp.shrinkToFit();
+ vector.swap(tmp);
+ return true;
+ }
+};
+
+template<typename T, size_t inlineCapacity> struct VectorNetworkCacheCoder<true, T, inlineCapacity> {
+ static void encode(NetworkCacheEncoder& encoder, const Vector<T, inlineCapacity>& vector)
+ {
+ encoder << static_cast<uint64_t>(vector.size());
+ encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T), alignof(T));
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, Vector<T, inlineCapacity>& vector)
+ {
+ uint64_t size;
+ if (!decoder.decode(size))
+ return false;
+
+ // Since we know the total size of the elements, we can allocate the vector in
+ // one fell swoop. Before allocating we must however make sure that the decoder buffer
+ // is big enough.
+ if (!decoder.bufferIsLargeEnoughToContain<T>(size)) {
+ decoder.markInvalid();
+ return false;
+ }
+
+ Vector<T, inlineCapacity> temp;
+ temp.resize(size);
+
+ decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T), alignof(T));
+
+ vector.swap(temp);
+ return true;
+ }
+};
+
+template<typename T, size_t inlineCapacity> struct NetworkCacheCoder<Vector<T, inlineCapacity>> : VectorNetworkCacheCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { };
+
+template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct NetworkCacheCoder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> {
+ typedef HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> HashMapType;
+
+ static void encode(NetworkCacheEncoder& encoder, const HashMapType& hashMap)
+ {
+ encoder << static_cast<uint64_t>(hashMap.size());
+ for (typename HashMapType::const_iterator it = hashMap.begin(), end = hashMap.end(); it != end; ++it)
+ encoder << *it;
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, HashMapType& hashMap)
+ {
+ uint64_t hashMapSize;
+ if (!decoder.decode(hashMapSize))
+ return false;
+
+ HashMapType tempHashMap;
+ for (uint64_t i = 0; i < hashMapSize; ++i) {
+ KeyArg key;
+ MappedArg value;
+ if (!decoder.decode(key))
+ return false;
+ if (!decoder.decode(value))
+ return false;
+
+ if (!tempHashMap.add(key, value).isNewEntry) {
+ // The hash map already has the specified key, bail.
+ decoder.markInvalid();
+ return false;
+ }
+ }
+
+ hashMap.swap(tempHashMap);
+ return true;
+ }
+};
+
+template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct NetworkCacheCoder<HashSet<KeyArg, HashArg, KeyTraitsArg>> {
+ typedef HashSet<KeyArg, HashArg, KeyTraitsArg> HashSetType;
+
+ static void encode(NetworkCacheEncoder& encoder, const HashSetType& hashSet)
+ {
+ encoder << static_cast<uint64_t>(hashSet.size());
+ for (typename HashSetType::const_iterator it = hashSet.begin(), end = hashSet.end(); it != end; ++it)
+ encoder << *it;
+ }
+
+ static bool decode(NetworkCacheDecoder& decoder, HashSetType& hashSet)
+ {
+ uint64_t hashSetSize;
+ if (!decoder.decode(hashSetSize))
+ return false;
+
+ HashSetType tempHashSet;
+ for (uint64_t i = 0; i < hashSetSize; ++i) {
+ KeyArg key;
+ if (!decoder.decode(key))
+ return false;
+
+ if (!tempHashSet.add(key).isNewEntry) {
+ // The hash map already has the specified key, bail.
+ decoder.markInvalid();
+ return false;
+ }
+ }
+
+ hashSet.swap(tempHashSet);
+ return true;
+ }
+};
+
+template<> struct NetworkCacheCoder<AtomicString> {
+ static void encode(NetworkCacheEncoder&, const AtomicString&);
+ static bool decode(NetworkCacheDecoder&, AtomicString&);
+};
+
+template<> struct NetworkCacheCoder<CString> {
+ static void encode(NetworkCacheEncoder&, const CString&);
+ static bool decode(NetworkCacheDecoder&, CString&);
+};
+
+template<> struct NetworkCacheCoder<String> {
+ static void encode(NetworkCacheEncoder&, const String&);
+ static bool decode(NetworkCacheDecoder&, String&);
+};
+
+template<> struct NetworkCacheCoder<WebCore::CertificateInfo> {
+ static void encode(NetworkCacheEncoder&, const WebCore::CertificateInfo&);
+ static bool decode(NetworkCacheDecoder&, WebCore::CertificateInfo&);
+};
+
+}
+
+#endif
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheDecodercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,160 @@
</span><ins>+/*
+ * Copyright (C) 2010, 2011, 2014 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 "config.h"
+#include "NetworkCacheDecoder.h"
+
+#if ENABLE(NETWORK_CACHE)
+
+#include "NetworkCacheEncoder.h"
+
+namespace WebKit {
+
+NetworkCacheDecoder::NetworkCacheDecoder(const uint8_t* buffer, size_t bufferSize)
+ : m_buffer(buffer)
+ , m_bufferPos(buffer)
+ , m_bufferEnd(buffer + bufferSize)
+ , m_checksum(0)
+{
+}
+
+NetworkCacheDecoder::~NetworkCacheDecoder()
+{
+}
+
+static inline uint8_t* roundUpToAlignment(const uint8_t* ptr, unsigned alignment)
+{
+ // Assert that the alignment is a power of 2.
+ ASSERT(alignment && !(alignment & (alignment - 1)));
+
+ uintptr_t alignmentMask = alignment - 1;
+ return reinterpret_cast<uint8_t*>((reinterpret_cast<uintptr_t>(ptr) + alignmentMask) & ~alignmentMask);
+}
+
+static inline bool alignedBufferIsLargeEnoughToContain(const uint8_t* alignedPosition, const uint8_t* bufferEnd, size_t size)
+{
+ return bufferEnd >= alignedPosition && static_cast<size_t>(bufferEnd - alignedPosition) >= size;
+}
+
+bool NetworkCacheDecoder::alignBufferPosition(unsigned alignment, size_t size)
+{
+ uint8_t* alignedPosition = roundUpToAlignment(m_bufferPos, alignment);
+ if (!alignedBufferIsLargeEnoughToContain(alignedPosition, m_bufferEnd, size)) {
+ // We've walked off the end of this buffer.
+ markInvalid();
+ return false;
+ }
+
+ m_bufferPos = alignedPosition;
+ return true;
+}
+
+bool NetworkCacheDecoder::bufferIsLargeEnoughToContain(unsigned alignment, size_t size) const
+{
+ return alignedBufferIsLargeEnoughToContain(roundUpToAlignment(m_bufferPos, alignment), m_bufferEnd, size);
+}
+
+bool NetworkCacheDecoder::decodeFixedLengthData(uint8_t* data, size_t size, unsigned alignment)
+{
+ if (!alignBufferPosition(alignment, size))
+ return false;
+
+ memcpy(data, m_bufferPos, size);
+ m_bufferPos += size;
+
+ NetworkCacheEncoder::updateChecksumForData(m_checksum, data, size);
+ return true;
+}
+
+template<typename Type>
+bool NetworkCacheDecoder::decodeNumber(Type& value)
+{
+ if (!alignBufferPosition(sizeof(value), sizeof(value)))
+ return false;
+
+ memcpy(&value, m_bufferPos, sizeof(value));
+ m_bufferPos += sizeof(Type);
+
+ NetworkCacheEncoder::updateChecksumForNumber(m_checksum, value);
+ return true;
+}
+
+bool NetworkCacheDecoder::decode(bool& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(uint8_t& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(uint16_t& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(uint32_t& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(uint64_t& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(int32_t& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(int64_t& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(float& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::decode(double& result)
+{
+ return decodeNumber(result);
+}
+
+bool NetworkCacheDecoder::verifyChecksum()
+{
+ unsigned computedChecksum = m_checksum;
+ unsigned decodedChecksum;
+ if (!decodeNumber(decodedChecksum))
+ return false;
+ return computedChecksum == decodedChecksum;
+}
+
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheDecoderh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,104 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 NetworkCacheDecoder_h
+#define NetworkCacheDecoder_h
+
+#if ENABLE(NETWORK_CACHE)
+
+#include "NetworkCacheCoder.h"
+
+namespace WebKit {
+
+class NetworkCacheDecoder {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ NetworkCacheDecoder(const uint8_t* buffer, size_t bufferSize);
+ virtual ~NetworkCacheDecoder();
+
+ size_t length() const { return m_bufferEnd - m_buffer; }
+ size_t currentOffset() const { return m_bufferPos - m_buffer; }
+
+ bool isInvalid() const { return m_bufferPos > m_bufferEnd; }
+ void markInvalid() { m_bufferPos = m_bufferEnd + 1; }
+
+ bool verifyChecksum();
+
+ bool decodeFixedLengthData(uint8_t*, size_t, unsigned alignment);
+
+ bool decode(bool&);
+ bool decode(uint8_t&);
+ bool decode(uint16_t&);
+ bool decode(uint32_t&);
+ bool decode(uint64_t&);
+ bool decode(int32_t&);
+ bool decode(int64_t&);
+ bool decode(float&);
+ bool decode(double&);
+
+ template<typename T> bool decodeEnum(T& result)
+ {
+ static_assert(sizeof(T) <= 8, "Enum type T must not be larger than 64 bits!");
+
+ uint64_t value;
+ if (!decode(value))
+ return false;
+
+ result = static_cast<T>(value);
+ return true;
+ }
+
+ template<typename T> bool decode(T& t)
+ {
+ return NetworkCacheCoder<T>::decode(*this, t);
+ }
+
+ template<typename T>
+ bool bufferIsLargeEnoughToContain(size_t numElements) const
+ {
+ static_assert(std::is_arithmetic<T>::value, "Type T must have a fixed, known encoded size!");
+
+ if (numElements > std::numeric_limits<size_t>::max() / sizeof(T))
+ return false;
+
+ return bufferIsLargeEnoughToContain(alignof(T), numElements * sizeof(T));
+ }
+
+private:
+ bool alignBufferPosition(unsigned alignment, size_t);
+ bool bufferIsLargeEnoughToContain(unsigned alignment, size_t) const;
+ template<typename Type> bool decodeNumber(Type&);
+
+ const uint8_t* m_buffer;
+ const uint8_t* m_bufferPos;
+ const uint8_t* m_bufferEnd;
+
+ unsigned m_checksum;
+};
+
+}
+
+#endif
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEncodercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,136 @@
</span><ins>+/*
+ * Copyright (C) 2010, 2014 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 "config.h"
+#include "NetworkCacheEncoder.h"
+
+#if ENABLE(NETWORK_CACHE)
+
+namespace WebKit {
+
+NetworkCacheEncoder::NetworkCacheEncoder()
+ : m_checksum(0)
+{
+}
+
+NetworkCacheEncoder::~NetworkCacheEncoder()
+{
+}
+
+static inline size_t roundUpToAlignment(size_t value, unsigned alignment)
+{
+ return ((value + alignment - 1) / alignment) * alignment;
+}
+
+uint8_t* NetworkCacheEncoder::grow(unsigned alignment, size_t size)
+{
+ size_t alignedSize = roundUpToAlignment(m_buffer.size(), alignment);
+
+ m_buffer.grow(alignedSize + size);
+
+ return m_buffer.data() + alignedSize;
+}
+
+void NetworkCacheEncoder::updateChecksumForData(unsigned& checksum, const uint8_t* data, size_t size)
+{
+ // FIXME: hashMemory should not require alignment.
+ size_t hashSize = size - size % 2;
+ unsigned hash = StringHasher::hashMemory(data, hashSize) ^ NetworkCacheEncoder::Salt<uint8_t*>::value;
+ checksum = WTF::pairIntHash(checksum, hash);
+}
+
+void NetworkCacheEncoder::encodeFixedLengthData(const uint8_t* data, size_t size, unsigned alignment)
+{
+ ASSERT(!(reinterpret_cast<uintptr_t>(data) % alignment));
+
+ updateChecksumForData(m_checksum, data, size);
+
+ uint8_t* buffer = grow(alignment, size);
+ memcpy(buffer, data, size);
+}
+
+template<typename Type>
+void NetworkCacheEncoder::encodeNumber(Type value)
+{
+ uint8_t* buffer = grow(sizeof(Type), sizeof(Type));
+
+ NetworkCacheEncoder::updateChecksumForNumber(m_checksum, value);
+
+ memcpy(buffer, &value, sizeof(Type));
+}
+
+void NetworkCacheEncoder::encode(bool value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(uint8_t value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(uint16_t value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(uint32_t value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(uint64_t value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(int32_t value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(int64_t value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(float value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encode(double value)
+{
+ encodeNumber(value);
+}
+
+void NetworkCacheEncoder::encodeChecksum()
+{
+ encodeNumber(m_checksum);
+}
+
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEncoderh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h (0 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -0,0 +1,116 @@
</span><ins>+/*
+ * Copyright (C) 2010 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 NetworkCacheEncoder_h
+#define NetworkCacheEncoder_h
+
+#if ENABLE(NETWORK_CACHE)
+
+#include "NetworkCacheCoder.h"
+
+#include <wtf/StringHasher.h>
+#include <wtf/Vector.h>
+
+namespace WebKit {
+
+class NetworkCacheEncoder;
+class DataReference;
+
+class NetworkCacheEncoder {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ NetworkCacheEncoder();
+ virtual ~NetworkCacheEncoder();
+
+ void encodeChecksum();
+ void encodeFixedLengthData(const uint8_t*, size_t, unsigned alignment);
+
+ template<typename T> void encodeEnum(T t)
+ {
+ COMPILE_ASSERT(sizeof(T) <= sizeof(uint64_t), enum_type_must_not_be_larger_than_64_bits);
+
+ encode(static_cast<uint64_t>(t));
+ }
+
+ template<typename T> void encode(const T& t)
+ {
+ NetworkCacheCoder<T>::encode(*this, t);
+ }
+
+ template<typename T> NetworkCacheEncoder& operator<<(const T& t)
+ {
+ encode(t);
+ return *this;
+ }
+
+ const uint8_t* buffer() const { return m_buffer.data(); }
+ size_t bufferSize() const { return m_buffer.size(); }
+
+ static void updateChecksumForData(unsigned& checksum, const uint8_t*, size_t);
+ template <typename Type> static void updateChecksumForNumber(unsigned& checksum, Type);
+
+private:
+ void encode(bool);
+ void encode(uint8_t);
+ void encode(uint16_t);
+ void encode(uint32_t);
+ void encode(uint64_t);
+ void encode(int32_t);
+ void encode(int64_t);
+ void encode(float);
+ void encode(double);
+
+ template<typename Type> void encodeNumber(Type);
+
+ uint8_t* grow(unsigned alignment, size_t);
+
+ template <typename Type> struct Salt;
+
+ Vector<uint8_t, 4096> m_buffer;
+ unsigned m_checksum;
+};
+
+template <> struct NetworkCacheEncoder::Salt<bool> { static const unsigned value = 3; };
+template <> struct NetworkCacheEncoder::Salt<uint8_t> { static const unsigned value = 5; };
+template <> struct NetworkCacheEncoder::Salt<uint16_t> { static const unsigned value = 7; };
+template <> struct NetworkCacheEncoder::Salt<uint32_t> { static const unsigned value = 11; };
+template <> struct NetworkCacheEncoder::Salt<uint64_t> { static const unsigned value = 13; };
+template <> struct NetworkCacheEncoder::Salt<int32_t> { static const unsigned value = 17; };
+template <> struct NetworkCacheEncoder::Salt<int64_t> { static const unsigned value = 19; };
+template <> struct NetworkCacheEncoder::Salt<float> { static const unsigned value = 23; };
+template <> struct NetworkCacheEncoder::Salt<double> { static const unsigned value = 29; };
+template <> struct NetworkCacheEncoder::Salt<uint8_t*> { static const unsigned value = 101; };
+
+template <typename Type>
+void NetworkCacheEncoder::updateChecksumForNumber(unsigned& checksum, Type value)
+{
+ unsigned hash = WTF::intHash(static_cast<uint64_t>(value)) ^ NetworkCacheEncoder::Salt<Type>::value;
+ checksum = WTF::pairIntHash(checksum, hash);
+}
+
+}
+
+#endif
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (175747 => 175748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-11-07 11:28:53 UTC (rev 175747)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-11-07 11:29:55 UTC (rev 175748)
</span><span class="lines">@@ -1652,6 +1652,13 @@
</span><span class="cx">                 E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E552C316AE065E004ED653 /* SandboxInitializationParameters.h */; };
</span><span class="cx">                 E1EE53E311F8CFC000CCBEE4 /* InjectedBundlePageEditorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE53DC11F8CF9F00CCBEE4 /* InjectedBundlePageEditorClient.h */; };
</span><span class="cx">                 E1EE53E711F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE53E611F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp */; };
</span><ins>+                E489D28A1A0A2DB80078C06A /* NetworkCacheCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */; };
+                E489D28B1A0A2DB80078C06A /* NetworkCacheCoders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */; };
+                E489D28C1A0A2DB80078C06A /* NetworkCacheCoders.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2851A0A2DB80078C06A /* NetworkCacheCoders.h */; };
+                E489D28D1A0A2DB80078C06A /* NetworkCacheDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2861A0A2DB80078C06A /* NetworkCacheDecoder.cpp */; };
+                E489D28E1A0A2DB80078C06A /* NetworkCacheDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */; };
+                E489D28F1A0A2DB80078C06A /* NetworkCacheEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */; };
+                E489D2901A0A2DB80078C06A /* NetworkCacheEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */; };
</ins><span class="cx">                 ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 EDCA71B7128DDA8C00201B26 /* WKBundlePageOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A22F1001289FCD90085E74F /* WKBundlePageOverlay.cpp */; };
</span><span class="cx">                 F036978815F4BF0500C3A80E /* WebColorPicker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F036978715F4BF0500C3A80E /* WebColorPicker.cpp */; };
</span><span class="lines">@@ -3752,6 +3759,13 @@
</span><span class="cx">                 E1EE53E611F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageEditorClient.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 E1FEF39A190F76F300731658 /* com.apple.WebKit.Databases.sb.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = com.apple.WebKit.Databases.sb.in; sourceTree = "<group>"; };
</span><span class="cx">                 E1FEF39C190F791C00731658 /* DatabaseProcessIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseProcessIOS.mm; sourceTree = "<group>"; };
</span><ins>+                E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheCoder.h; sourceTree = "<group>"; };
+                E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheCoders.cpp; sourceTree = "<group>"; };
+                E489D2851A0A2DB80078C06A /* NetworkCacheCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheCoders.h; sourceTree = "<group>"; };
+                E489D2861A0A2DB80078C06A /* NetworkCacheDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheDecoder.cpp; sourceTree = "<group>"; };
+                E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheDecoder.h; sourceTree = "<group>"; };
+                E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheEncoder.cpp; sourceTree = "<group>"; };
+                E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheEncoder.h; sourceTree = "<group>"; };
</ins><span class="cx">                 F036978715F4BF0500C3A80E /* WebColorPicker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebColorPicker.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 F6113E24126CE1820057D0A7 /* WebUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUserContentURLPattern.h; sourceTree = "<group>"; };
</span><span class="cx">                 F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserContentURLPattern.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -5182,6 +5196,7 @@
</span><span class="cx">                 510CC7DA16138E0100D03ED3 /* NetworkProcess */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                E489D2821A0A2BE80078C06A /* cache */,
</ins><span class="cx">                                 7EC4F0F818E4A922008056AF /* cocoa */,
</span><span class="cx">                                 2DA944BB188511DD00ED86DB /* ios */,
</span><span class="cx">                                 BC82837C16B45DA500A278FE /* EntryPoint */,
</span><span class="lines">@@ -7004,6 +7019,21 @@
</span><span class="cx">                         path = ios;
</span><span class="cx">                         sourceTree = "<group>";
</span><span class="cx">                 };
</span><ins>+                E489D2821A0A2BE80078C06A /* cache */ = {
+                        isa = PBXGroup;
+                        children = (
+                                E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */,
+                                E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */,
+                                E489D2851A0A2DB80078C06A /* NetworkCacheCoders.h */,
+                                E489D2861A0A2DB80078C06A /* NetworkCacheDecoder.cpp */,
+                                E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */,
+                                E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */,
+                                E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */,
+                        );
+                        name = cache;
+                        path = NetworkProcess/cache;
+                        sourceTree = "<group>";
+                };
</ins><span class="cx">                 F638955A133BF57D008941D5 /* mac */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="lines">@@ -7109,6 +7139,7 @@
</span><span class="cx">                                 293EBEAB1627D9C9005F89F1 /* WKDOMText.h in Headers */,
</span><span class="cx">                                 BC017D2116263308007054F5 /* WKDOMTextIterator.h in Headers */,
</span><span class="cx">                                 37DFA7001810BB92001F4A9F /* WKFoundation.h in Headers */,
</span><ins>+                                E489D28E1A0A2DB80078C06A /* NetworkCacheDecoder.h in Headers */,
</ins><span class="cx">                                 1ABC3DF11899C6B6004F0626 /* WKNavigationInternal.h in Headers */,
</span><span class="cx">                                 0F0C365A18C0555800F607D7 /* LayerRepresentation.h in Headers */,
</span><span class="cx">                                 1F604BA81889FA7400EE0395 /* WKRenderingProgressEvents.h in Headers */,
</span><span class="lines">@@ -7243,6 +7274,7 @@
</span><span class="cx">                                 BCB0AEE9122F53E300B1341E /* MutableDictionary.h in Headers */,
</span><span class="cx">                                 1A6FBA2A11E6862700DB1371 /* NetscapeBrowserFuncs.h in Headers */,
</span><span class="cx">                                 1A6FBD2811E69BC200DB1371 /* NetscapePlugin.h in Headers */,
</span><ins>+                                E489D28C1A0A2DB80078C06A /* NetworkCacheCoders.h in Headers */,
</ins><span class="cx">                                 A1C512C9190656E500448914 /* WebQuickLookHandleClient.h in Headers */,
</span><span class="cx">                                 1A4A9C5612B816CF008FE984 /* NetscapePluginModule.h in Headers */,
</span><span class="cx">                                 1AA5889211EE70400061B882 /* NetscapePluginStream.h in Headers */,
</span><span class="lines">@@ -7441,6 +7473,7 @@
</span><span class="cx">                                 BCDE059B11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h in Headers */,
</span><span class="cx">                                 1A6509CE18B4146200614332 /* WKProcessPoolPrivate.h in Headers */,
</span><span class="cx">                                 51871B5C127CB89D00F76232 /* WebContextMenu.h in Headers */,
</span><ins>+                                E489D2901A0A2DB80078C06A /* NetworkCacheEncoder.h in Headers */,
</ins><span class="cx">                                 BC032D7710F4378D0058C15A /* WebContextMenuClient.h in Headers */,
</span><span class="cx">                                 75E749EC180DBB9800088BA6 /* WebOriginDataManagerProxyMessages.h in Headers */,
</span><span class="cx">                                 512935D81288D19400A4B695 /* WebContextMenuItem.h in Headers */,
</span><span class="lines">@@ -7450,6 +7483,7 @@
</span><span class="cx">                                 51ACBB82127A8BAD00D203B9 /* WebContextMenuProxy.h in Headers */,
</span><span class="cx">                                 1AB8A1F418400B8F00E9AE69 /* WKPageFindClient.h in Headers */,
</span><span class="cx">                                 75E749EA180DBB9800088BA6 /* WebOriginDataManagerMessages.h in Headers */,
</span><ins>+                                E489D28A1A0A2DB80078C06A /* NetworkCacheCoder.h in Headers */,
</ins><span class="cx">                                 37A64E5518F38E3C00EB30F1 /* _WKFormDelegate.h in Headers */,
</span><span class="cx">                                 51ACBBA0127A8F2C00D203B9 /* WebContextMenuProxyMac.h in Headers */,
</span><span class="cx">                                 BCCB75C61203A1CE00222D1B /* WebContextMessageKinds.h in Headers */,
</span><span class="lines">@@ -8851,6 +8885,7 @@
</span><span class="cx">                                 2684054C18B86C350022C38B /* VisibleContentRectUpdateInfo.cpp in Sources */,
</span><span class="cx">                                 BC4BEEAC120A0A5F00FBA0C7 /* InjectedBundleNodeHandle.cpp in Sources */,
</span><span class="cx">                                 512935E31288D97800A4B695 /* InjectedBundlePageContextMenuClient.cpp in Sources */,
</span><ins>+                                E489D28B1A0A2DB80078C06A /* NetworkCacheCoders.cpp in Sources */,
</ins><span class="cx">                                 CD67D30E15C08F9A00843ADF /* InjectedBundlePageDiagnosticLoggingClient.cpp in Sources */,
</span><span class="cx">                                 E1EE53E711F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp in Sources */,
</span><span class="cx">                                 BC14E109120B905E00826C0C /* InjectedBundlePageFormClient.cpp in Sources */,
</span><span class="lines">@@ -8965,7 +9000,9 @@
</span><span class="cx">                                 CEDBA84719FDA00A006866A5 /* WebSQLiteDatabaseTracker.cpp in Sources */,
</span><span class="cx">                                 31A67E0C165B2A99006CBA66 /* PlugInAutoStartProvider.cpp in Sources */,
</span><span class="cx">                                 1A8EF4CC1252403700F7067F /* PluginControllerProxy.cpp in Sources */,
</span><ins>+                                E489D28D1A0A2DB80078C06A /* NetworkCacheDecoder.cpp in Sources */,
</ins><span class="cx">                                 1A2D91A61281D739001EB962 /* PluginControllerProxyMac.mm in Sources */,
</span><ins>+                                E489D28F1A0A2DB80078C06A /* NetworkCacheEncoder.cpp in Sources */,
</ins><span class="cx">                                 1A8EF96E1252AF6B00F7067F /* PluginControllerProxyMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 1A17977F137EE82C00F97D45 /* PluginCreationParameters.cpp in Sources */,
</span><span class="cx">                                 C55CB5B718C269CF00CA81E1 /* WKFormSelectPopover.mm in Sources */,
</span></span></pre>
</div>
</div>
</body>
</html>