Commit 01434c4e authored by andersca@apple.com's avatar andersca@apple.com

Implement encoding of arrays of objects

https://bugs.webkit.org/show_bug.cgi?id=124091

Reviewed by Beth Dakin.

Source/WebCore:

* history/HistoryItem.cpp:
(WebCore::HistoryItem::encodeBackForwardTreeNode):
Encode the rest of the members.

* platform/KeyedCoding.h:
(WebCore::KeyedEncoder::encodeObjects):
Call beginArray, then beginArrayElement/endArrayElement for every element and lastly endArray.

Source/WebKit2:

Add a new array stack and push and pop from it accordingly.

* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::~KeyedEncoder):
(WebKit::KeyedEncoder::encodeBytes):
(WebKit::KeyedEncoder::encodeUInt32):
(WebKit::KeyedEncoder::encodeInt32):
(WebKit::KeyedEncoder::encodeInt64):
(WebKit::KeyedEncoder::encodeFloat):
(WebKit::KeyedEncoder::beginArray):
(WebKit::KeyedEncoder::beginArrayElement):
(WebKit::KeyedEncoder::endArrayElement):
(WebKit::KeyedEncoder::endArray):
* Shared/cf/KeyedEncoder.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158984 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e962af34
2013-11-08 Anders Carlsson <andersca@apple.com>
Implement encoding of arrays of objects
https://bugs.webkit.org/show_bug.cgi?id=124091
Reviewed by Beth Dakin.
* history/HistoryItem.cpp:
(WebCore::HistoryItem::encodeBackForwardTreeNode):
Encode the rest of the members.
* platform/KeyedCoding.h:
(WebCore::KeyedEncoder::encodeObjects):
Call beginArray, then beginArrayElement/endArrayElement for every element and lastly endArray.
2013-11-08 Tim Horton <timothy_horton@apple.com>
Remote Layer Tree: RemoteLayerBackingStore partial repaint is broken for the tile cache
......
......@@ -737,7 +737,18 @@ void HistoryItem::encodeBackForwardTreeNode(Encoder& encoder) const
void HistoryItem::encodeBackForwardTreeNode(KeyedEncoder& encoder) const
{
// FIXME: Implement.
encoder.encodeObjects("children", m_children.begin(), m_children.end(), [](KeyedEncoder& encoder, const RefPtr<HistoryItem>& child) {
encoder.encodeString("originalURLString", child->m_originalURLString);
encoder.encodeString("urlString", child->m_urlString);
child->encodeBackForwardTreeNode(encoder);
});
encoder.encodeInt64("documentSequenceNumber", m_documentSequenceNumber);
encoder.encodeObjects("documentState", m_documentState.begin(), m_documentState.end(), [](KeyedEncoder& encoder, const String& string) {
encoder.encodeString("string", string);
});
encoder.encodeString("formContentType", m_formContentType);
......@@ -745,6 +756,8 @@ void HistoryItem::encodeBackForwardTreeNode(KeyedEncoder& encoder) const
// FIXME: Implement.
});
encoder.encodeInt64("itemSequenceNumber", m_itemSequenceNumber);
encoder.encodeString("referrer", m_referrer);
encoder.encodeObject("scrollPoint", m_scrollPoint, [](KeyedEncoder& encoder, const IntPoint& scrollPoint) {
......
......@@ -38,15 +38,16 @@ public:
virtual void encodeBytes(const String& key, const uint8_t*, size_t) = 0;
virtual void encodeUInt32(const String& key, uint32_t) = 0;
virtual void encodeInt32(const String& key, int32_t) = 0;
virtual void encodeInt64(const String& key, int64_t) = 0;
virtual void encodeFloat(const String& key, float) = 0;
virtual void encodeString(const String& key, const String&) = 0;
template<typename T, typename F>
void encodeObject(const String& key, const T& object, F function)
void encodeObject(const String& key, const T& object, F&& function)
{
this->beginObject(key);
beginObject(key);
function(*this, object);
this->endObject();
endObject();
}
template<typename T, typename F>
......@@ -58,9 +59,29 @@ public:
encodeObject(key, *object, std::forward<F>(function));
}
template<typename T, typename F>
void encodeObjects(const String& key, T begin, T end, F&& function)
{
if (begin == end)
return;
beginArray(key);
for (T it = begin; it != end; ++it) {
beginArrayElement();
function(*this, *it);
endArrayElement();
}
endArray();
}
private:
virtual void beginObject(const String& key) = 0;
virtual void endObject() = 0;
virtual void beginArray(const String& key) = 0;
virtual void beginArrayElement() = 0;
virtual void endArrayElement() = 0;
virtual void endArray() = 0;
};
} // namespace WebCore
......
2013-11-08 Anders Carlsson <andersca@apple.com>
Implement encoding of arrays of objects
https://bugs.webkit.org/show_bug.cgi?id=124091
Reviewed by Beth Dakin.
Add a new array stack and push and pop from it accordingly.
* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::~KeyedEncoder):
(WebKit::KeyedEncoder::encodeBytes):
(WebKit::KeyedEncoder::encodeUInt32):
(WebKit::KeyedEncoder::encodeInt32):
(WebKit::KeyedEncoder::encodeInt64):
(WebKit::KeyedEncoder::encodeFloat):
(WebKit::KeyedEncoder::beginArray):
(WebKit::KeyedEncoder::beginArrayElement):
(WebKit::KeyedEncoder::endArrayElement):
(WebKit::KeyedEncoder::endArray):
* Shared/cf/KeyedEncoder.h:
2013-11-08 Tim Horton <timothy_horton@apple.com>
Remote Layer Tree: RemoteLayerBackingStore partial repaint is broken for the tile cache
......
......@@ -46,29 +46,36 @@ KeyedEncoder::~KeyedEncoder()
{
ASSERT(m_dictionaryStack.size() == 1);
ASSERT(m_dictionaryStack.last() == m_rootDictionary);
ASSERT(m_arrayStack.isEmpty());
}
void KeyedEncoder::encodeBytes(const String& key, const uint8_t* bytes, size_t size)
{
RetainPtr<CFDataRef> data = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, bytes, size, kCFAllocatorNull));
auto data = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, bytes, size, kCFAllocatorNull));
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), data.get());
}
void KeyedEncoder::encodeUInt32(const String& key, uint32_t value)
{
RetainPtr<CFNumberRef> number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), number.get());
}
void KeyedEncoder::encodeInt32(const String& key, int32_t value)
{
RetainPtr<CFNumberRef> number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), number.get());
}
void KeyedEncoder::encodeInt64(const String& key, int64_t value)
{
auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), number.get());
}
void KeyedEncoder::encodeFloat(const String& key, float value)
{
RetainPtr<CFNumberRef> number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &value));
auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &value));
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), number.get());
}
......@@ -90,4 +97,30 @@ void KeyedEncoder::endObject()
m_dictionaryStack.removeLast();
}
void KeyedEncoder::beginArray(const String& key)
{
auto array = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), array.get());
m_arrayStack.append(array.get());
}
void KeyedEncoder::beginArrayElement()
{
auto dictionary = createDictionary();
CFArrayAppendValue(m_arrayStack.last(), dictionary.get());
m_dictionaryStack.append(dictionary.get());
}
void KeyedEncoder::endArrayElement()
{
m_dictionaryStack.removeLast();
}
void KeyedEncoder::endArray()
{
m_arrayStack.removeLast();
}
} // namespace WebKit
......@@ -42,14 +42,22 @@ private:
virtual void encodeUInt32(const String& key, uint32_t) OVERRIDE;
virtual void encodeInt32(const String& key, int32_t) OVERRIDE;
virtual void encodeInt64(const String& key, int64_t) OVERRIDE;
virtual void encodeFloat(const String& key, float) OVERRIDE;
virtual void encodeString(const String& key, const String&) OVERRIDE;
virtual void beginObject(const String& key) OVERRIDE;
virtual void endObject() OVERRIDE;
virtual void beginArray(const String& key) OVERRIDE;
virtual void beginArrayElement() OVERRIDE;
virtual void endArrayElement() OVERRIDE;
virtual void endArray() OVERRIDE;
RetainPtr<CFMutableDictionaryRef> m_rootDictionary;
Vector<CFMutableDictionaryRef, 16> m_dictionaryStack;
Vector<CFMutableArrayRef, 16> m_arrayStack;
};
} // namespace WebKit
......
......@@ -84,9 +84,6 @@ void WebBackForwardListProxy::setHighestItemIDFromUIProcess(uint64_t itemID)
static void updateBackForwardItem(uint64_t itemID, HistoryItem* item)
{
KeyedEncoder keyedEncoder;
item->encodeBackForwardTree(keyedEncoder);
EncoderAdapter encoder;
item->encodeBackForwardTree(encoder);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment