<!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>[170599] trunk/Source</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/170599">170599</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-06-30 14:53:58 -0700 (Mon, 30 Jun 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add code for encoding legacy session history entries
https://bugs.webkit.org/show_bug.cgi?id=134452
Reviewed by Andreas Kling.
Source/WebKit2:
* UIProcess/mac/LegacySessionStateCoding.cpp:
(WebKit::HistoryEntryDataEncoder::HistoryEntryDataEncoder):
(WebKit::HistoryEntryDataEncoder::operator<<):
(WebKit::HistoryEntryDataEncoder::finishEncoding):
(WebKit::HistoryEntryDataEncoder::encodeArithmeticType):
(WebKit::HistoryEntryDataEncoder::encodeFixedLengthData):
(WebKit::HistoryEntryDataEncoder::grow):
(WebKit::HistoryEntryDataEncoder::growCapacity):
(WebKit::encodeFrameStateNode):
(WebKit::encodeLegacySessionHistoryEntryData):
(WebKit::decodeSessionHistoryEntryData):
(WebKit::decodeLegacySessionHistoryEntryData):
* UIProcess/mac/LegacySessionStateCoding.h:
Source/WTF:
* wtf/MallocPtr.h:
(WTF::MallocPtr::malloc):
(WTF::MallocPtr::realloc):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfMallocPtrh">trunk/Source/WTF/wtf/MallocPtr.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacLegacySessionStateCodingcpp">trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacLegacySessionStateCodingh">trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (170598 => 170599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-06-30 21:25:33 UTC (rev 170598)
+++ trunk/Source/WTF/ChangeLog        2014-06-30 21:53:58 UTC (rev 170599)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2014-06-30 Anders Carlsson <andersca@apple.com>
+
+ Add code for encoding legacy session history entries
+ https://bugs.webkit.org/show_bug.cgi?id=134452
+
+ Reviewed by Andreas Kling.
+
+ * wtf/MallocPtr.h:
+ (WTF::MallocPtr::malloc):
+ (WTF::MallocPtr::realloc):
+
</ins><span class="cx"> 2014-06-27 Andreas Kling <akling@apple.com>
</span><span class="cx">
</span><span class="cx"> [ARMv7] Skip one particularly expensive fastFree() alignment check.
</span></span></pre></div>
<a id="trunkSourceWTFwtfMallocPtrh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/MallocPtr.h (170598 => 170599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MallocPtr.h        2014-06-30 21:25:33 UTC (rev 170598)
+++ trunk/Source/WTF/wtf/MallocPtr.h        2014-06-30 21:53:58 UTC (rev 170599)
</span><span class="lines">@@ -86,6 +86,19 @@
</span><span class="cx">
</span><span class="cx"> template<typename U> friend MallocPtr<U> adoptMallocPtr(U*);
</span><span class="cx">
</span><ins>+ static MallocPtr malloc(size_t size)
+ {
+ MallocPtr mallocPtr;
+ mallocPtr.m_ptr = static_cast<T*>(fastMalloc(size));
+
+ return mallocPtr;
+ }
+
+ void realloc(size_t newSize)
+ {
+ m_ptr = static_cast<T*>(fastRealloc(m_ptr, newSize));
+ }
+
</ins><span class="cx"> private:
</span><span class="cx"> explicit MallocPtr(T* ptr)
</span><span class="cx"> : m_ptr(ptr)
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (170598 => 170599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-06-30 21:25:33 UTC (rev 170598)
+++ trunk/Source/WebKit2/ChangeLog        2014-06-30 21:53:58 UTC (rev 170599)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2014-06-30 Anders Carlsson <andersca@apple.com>
+
+ Add code for encoding legacy session history entries
+ https://bugs.webkit.org/show_bug.cgi?id=134452
+
+ Reviewed by Andreas Kling.
+
+ * UIProcess/mac/LegacySessionStateCoding.cpp:
+ (WebKit::HistoryEntryDataEncoder::HistoryEntryDataEncoder):
+ (WebKit::HistoryEntryDataEncoder::operator<<):
+ (WebKit::HistoryEntryDataEncoder::finishEncoding):
+ (WebKit::HistoryEntryDataEncoder::encodeArithmeticType):
+ (WebKit::HistoryEntryDataEncoder::encodeFixedLengthData):
+ (WebKit::HistoryEntryDataEncoder::grow):
+ (WebKit::HistoryEntryDataEncoder::growCapacity):
+ (WebKit::encodeFrameStateNode):
+ (WebKit::encodeLegacySessionHistoryEntryData):
+ (WebKit::decodeSessionHistoryEntryData):
+ (WebKit::decodeLegacySessionHistoryEntryData):
+ * UIProcess/mac/LegacySessionStateCoding.h:
+
</ins><span class="cx"> 2014-06-29 Yoav Weiss <yoav@yoav.ws>
</span><span class="cx">
</span><span class="cx"> Add support for HTMLImageElement's sizes attribute
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacLegacySessionStateCodingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp (170598 => 170599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp        2014-06-30 21:25:33 UTC (rev 170598)
+++ trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp        2014-06-30 21:53:58 UTC (rev 170599)
</span><span class="lines">@@ -28,7 +28,9 @@
</span><span class="cx">
</span><span class="cx"> #include "APIData.h"
</span><span class="cx"> #include "SessionState.h"
</span><ins>+#include <wtf/MallocPtr.h>
</ins><span class="cx"> #include <wtf/cf/TypeCasts.h>
</span><ins>+#include <wtf/text/StringView.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><span class="lines">@@ -55,6 +57,233 @@
</span><span class="cx">
</span><span class="cx"> template<typename T> void isValidEnum(T);
</span><span class="cx">
</span><ins>+class HistoryEntryDataEncoder {
+public:
+ HistoryEntryDataEncoder()
+ : m_bufferSize(0)
+ , m_bufferCapacity(512)
+ , m_buffer(MallocPtr<uint8_t>::malloc(m_bufferCapacity))
+ , m_bufferPointer(m_buffer.get())
+ {
+ // Keep format compatibility by encoding an unused uint64_t here.
+ *this << static_cast<uint64_t>(0);
+ }
+
+ HistoryEntryDataEncoder& operator<<(uint32_t value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(int32_t value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(uint64_t value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(int64_t value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(float value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(double value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(bool value)
+ {
+ return encodeArithmeticType(value);
+ }
+
+ HistoryEntryDataEncoder& operator<<(const String& value)
+ {
+ // Special case the null string.
+ if (value.isNull())
+ return *this << std::numeric_limits<uint32_t>::max();
+
+ uint32_t length = value.length();
+ *this << length;
+
+ *this << static_cast<uint64_t>(length * sizeof(UChar));
+ encodeFixedLengthData(reinterpret_cast<const uint8_t*>(StringView(value).upconvertedCharacters().get()), length * sizeof(UChar), alignof(UChar));
+
+ return *this;
+ }
+
+#if PLATFORM(IOS)
+ HistoryEntryDataEncoder& operator<<(WebCore::FloatRect value)
+ {
+ *this << value.x();
+ *this << value.y();
+ *this << value.width();
+ *this << value.height();
+
+ return *this;
+ }
+
+ HistoryEntryDataEncoder& operator<<(WebCore::IntRect value)
+ {
+ *this << value.x();
+ *this << value.y();
+ *this << value.width();
+ *this << value.height();
+
+ return *this;
+ }
+
+ HistoryEntryDataEncoder& operator<<(WebCore::FloatSize value)
+ {
+ *this << value.width();
+ *this << value.height();
+
+ return *this;
+ }
+
+ HistoryEntryDataEncoder& operator<<(WebCore::IntSize value)
+ {
+ *this << value.width();
+ *this << value.height();
+
+ return *this;
+ }
+#endif
+
+ MallocPtr<uint8_t> finishEncoding(size_t& size)
+ {
+ size = m_bufferSize;
+ return std::move(m_buffer);
+ }
+
+private:
+ template<typename Type>
+ HistoryEntryDataEncoder& encodeArithmeticType(Type value)
+ {
+ static_assert(std::is_arithmetic<Type>::value, "");
+
+ encodeFixedLengthData(reinterpret_cast<uint8_t*>(&value), sizeof(value), sizeof(value));
+ return *this;
+ }
+
+ void encodeFixedLengthData(const uint8_t* data, size_t size, unsigned alignment)
+ {
+ ASSERT(!(reinterpret_cast<uintptr_t>(data) % alignment));
+
+ uint8_t* buffer = grow(alignment, size);
+ memcpy(buffer, data, size);
+ }
+
+ uint8_t* grow(unsigned alignment, size_t size)
+ {
+ size_t alignedSize = ((m_bufferSize + alignment - 1) / alignment) * alignment;
+
+ growCapacity(alignedSize + size);
+
+ m_bufferSize = alignedSize + size;
+ m_bufferPointer = m_buffer.get() + m_bufferSize;
+
+ return m_buffer.get() + alignedSize;
+ }
+
+ void growCapacity(size_t newSize)
+ {
+ if (newSize <= m_bufferCapacity)
+ return;
+
+ size_t newCapacity = m_bufferCapacity * 2;
+ while (newCapacity < newSize)
+ newCapacity *= 2;
+
+ m_buffer.realloc(newCapacity);
+ m_bufferCapacity = newCapacity;
+ }
+
+ size_t m_bufferSize;
+ size_t m_bufferCapacity;
+ MallocPtr<uint8_t> m_buffer;
+ uint8_t* m_bufferPointer;
+};
+
+static void encodeFrameStateNode(HistoryEntryDataEncoder& encoder, const FrameState& frameState)
+{
+ encoder << static_cast<uint64_t>(frameState.children.size());
+
+ for (const auto& childFrameState : frameState.children) {
+ // FIXME: Implement.
+ (void)childFrameState;
+ ASSERT_NOT_REACHED();
+ }
+
+ encoder << frameState.documentSequenceNumber;
+
+ encoder << static_cast<uint64_t>(frameState.documentState.size());
+ for (const auto& documentState : frameState.documentState) {
+ // FIXME: Implement.
+ (void)documentState;
+ ASSERT_NOT_REACHED();
+ }
+
+ encoder << !!frameState.httpBody;
+ if (frameState.httpBody) {
+ // FIXME: Implement.
+ ASSERT_NOT_REACHED();
+ }
+
+ encoder << frameState.itemSequenceNumber;
+
+ encoder << frameState.referrer;
+
+ encoder << frameState.scrollPoint.x();
+ encoder << frameState.scrollPoint.y();
+
+ encoder << frameState.pageScaleFactor;
+
+ encoder << !!frameState.stateObjectData;
+ if (frameState.stateObjectData) {
+ // FIXME: Implement.
+ ASSERT_NOT_REACHED();
+ }
+
+ encoder << frameState.target;
+
+#if PLATFORM(IOS)
+ // FIXME: iOS should not use the legacy session state encoder.
+ encoder << frameState.exposedContentRect;
+ encoder << frameState.unobscuredContentRect;
+ encoder << frameState.minimumLayoutSizeInScrollViewCoordinates;
+ encoder << frameState.contentSize;
+ encoder << frameState.scaleIsInitial;
+#endif
+}
+
+static MallocPtr<uint8_t> encodeLegacySessionHistoryEntryData(const FrameState& frameState, size_t& bufferSize)
+{
+ HistoryEntryDataEncoder encoder;
+
+ encoder << sessionHistoryEntryDataVersion;
+ encodeFrameStateNode(encoder, frameState);
+
+ return encoder.finishEncoding(bufferSize);
+}
+
+RefPtr<API::Data> encodeLegacySessionHistoryEntryData(const FrameState& frameState)
+{
+ size_t bufferSize;
+ auto buffer = encodeLegacySessionHistoryEntryData(frameState, bufferSize);
+
+ return API::Data::createWithoutCopying(buffer.leakPtr(), bufferSize, [] (unsigned char* buffer, const void* context) {
+ fastFree(buffer);
+ }, nullptr);
+}
+
</ins><span class="cx"> class HistoryEntryDataDecoder {
</span><span class="cx"> public:
</span><span class="cx"> HistoryEntryDataDecoder(const uint8_t* buffer, size_t bufferSize)
</span><span class="lines">@@ -496,9 +725,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool decodeSessionHistoryEntryData(CFDataRef historyEntryData, FrameState& mainFrameState)
</del><ins>+static bool decodeSessionHistoryEntryData(const uint8_t* buffer, size_t bufferSize, FrameState& mainFrameState)
</ins><span class="cx"> {
</span><del>- HistoryEntryDataDecoder decoder { CFDataGetBytePtr(historyEntryData), static_cast<size_t>(CFDataGetLength(historyEntryData)) };
</del><ins>+ HistoryEntryDataDecoder decoder { buffer, bufferSize };
</ins><span class="cx">
</span><span class="cx"> uint32_t version;
</span><span class="cx"> decoder >> version;
</span><span class="lines">@@ -511,6 +740,11 @@
</span><span class="cx"> return decoder.finishDecoding();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool decodeSessionHistoryEntryData(CFDataRef historyEntryData, FrameState& mainFrameState)
+{
+ return decodeSessionHistoryEntryData(CFDataGetBytePtr(historyEntryData), static_cast<size_t>(CFDataGetLength(historyEntryData)), mainFrameState);
+}
+
</ins><span class="cx"> static bool decodeSessionHistoryEntry(CFDictionaryRef entryDictionary, PageState& pageState)
</span><span class="cx"> {
</span><span class="cx"> auto title = dynamic_cf_cast<CFStringRef>(CFDictionaryGetValue(entryDictionary, sessionHistoryEntryTitleKey));
</span><span class="lines">@@ -672,4 +906,9 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool decodeLegacySessionHistoryEntryData(const API::Data& historyEntryData, FrameState& mainFrameState)
+{
+ return decodeSessionHistoryEntryData(historyEntryData.bytes(), historyEntryData.size(), mainFrameState);
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacLegacySessionStateCodingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h (170598 => 170599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h        2014-06-30 21:25:33 UTC (rev 170598)
+++ trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h        2014-06-30 21:53:58 UTC (rev 170599)
</span><span class="lines">@@ -34,9 +34,13 @@
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+struct FrameState;
</ins><span class="cx"> struct SessionState;
</span><span class="cx">
</span><ins>+RefPtr<API::Data> encodeLegacySessionHistoryEntryData(const FrameState&);
+
</ins><span class="cx"> bool decodeLegacySessionState(const API::Data&, SessionState&);
</span><ins>+bool decodeLegacySessionHistoryEntryData(const API::Data&, FrameState&);
</ins><span class="cx">
</span><span class="cx"> } // namespace WebKit
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>