Commit d66ca8b7 authored by andersca@apple.com's avatar andersca@apple.com

KeyedEncoder should be able to encoder objects

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

Reviewed by Sam Weinig.

Source/WebCore:

* history/HistoryItem.cpp:
(WebCore::HistoryItem::encodeBackForwardTree):
Encode the root object.

(WebCore::HistoryItem::encodeBackForwardTreeNode):
Encode the target.

* history/HistoryItem.h:
Add new members.

* platform/KeyedCoding.h:
(WebCore::KeyedEncoder::encodeObject):
Call beginObject, call the functor and then call endObject().

Source/WebKit2:

Add a dictionary stack to KeyedEncoder that's pushed and popped by
beginObject/endObject.

* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::KeyedEncoder):
(WebKit::KeyedEncoder::~KeyedEncoder):
(WebKit::KeyedEncoder::encodeUInt32):
(WebKit::KeyedEncoder::encodeString):
(WebKit::KeyedEncoder::beginObject):
(WebKit::KeyedEncoder::endObject):
* Shared/cf/KeyedEncoder.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158978 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ae909c1e
2013-11-08 Anders Carlsson <andersca@apple.com>
KeyedEncoder should be able to encoder objects
https://bugs.webkit.org/show_bug.cgi?id=124085
Reviewed by Sam Weinig.
* history/HistoryItem.cpp:
(WebCore::HistoryItem::encodeBackForwardTree):
Encode the root object.
(WebCore::HistoryItem::encodeBackForwardTreeNode):
Encode the target.
* history/HistoryItem.h:
Add new members.
* platform/KeyedCoding.h:
(WebCore::KeyedEncoder::encodeObject):
Call beginObject, call the functor and then call endObject().
2013-11-08 Sam Weinig <sam@webkit.org>
Teach CanvasObserver about references
......
......@@ -687,7 +687,9 @@ void HistoryItem::encodeBackForwardTree(KeyedEncoder& encoder) const
{
encoder.encodeUInt32("version", backForwardTreeEncodingVersion);
// FIXME: Encode the tree.
encoder.encodeObject("root", *this, [](KeyedEncoder& encoder, const HistoryItem& item) {
item.encodeBackForwardTreeNode(encoder);
});
}
void HistoryItem::encodeBackForwardTreeNode(Encoder& encoder) const
......@@ -733,6 +735,13 @@ void HistoryItem::encodeBackForwardTreeNode(Encoder& encoder) const
encoder.encodeString(m_target);
}
void HistoryItem::encodeBackForwardTreeNode(KeyedEncoder& encoder) const
{
// FIXME: Implement.
encoder.encodeString("target", m_target);
}
struct DecodeRecursionStackElement {
RefPtr<HistoryItem> node;
size_t i;
......
......@@ -223,10 +223,7 @@ private:
HistoryItem* findTargetItem();
void encodeBackForwardTreeNode(Encoder&) const;
/* When adding new member variables to this class, please notify the Qt team.
* qt/HistoryItemQt.cpp contains code to serialize history items.
*/
void encodeBackForwardTreeNode(KeyedEncoder&) const;
String m_urlString;
String m_originalURLString;
......
......@@ -36,6 +36,20 @@ protected:
public:
virtual void encodeUInt32(const String& key, uint32_t) = 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)
{
this->beginObject(key);
function(*this, object);
this->endObject();
}
private:
virtual void beginObject(const String& key) = 0;
virtual void endObject() = 0;
};
} // namespace WebCore
......
2013-11-08 Anders Carlsson <andersca@apple.com>
KeyedEncoder should be able to encoder objects
https://bugs.webkit.org/show_bug.cgi?id=124085
Reviewed by Sam Weinig.
Add a dictionary stack to KeyedEncoder that's pushed and popped by
beginObject/endObject.
* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::KeyedEncoder):
(WebKit::KeyedEncoder::~KeyedEncoder):
(WebKit::KeyedEncoder::encodeUInt32):
(WebKit::KeyedEncoder::encodeString):
(WebKit::KeyedEncoder::beginObject):
(WebKit::KeyedEncoder::endObject):
* Shared/cf/KeyedEncoder.h:
2013-11-08 Alexandru Chiculita <achicu@adobe.com>
Web Inspector: It should be possible to debug the Inspector code
......
......@@ -39,16 +39,37 @@ static RetainPtr<CFMutableDictionaryRef> createDictionary()
KeyedEncoder::KeyedEncoder()
: m_rootDictionary(createDictionary())
{
m_dictionaryStack.append(m_rootDictionary.get());
}
KeyedEncoder::~KeyedEncoder()
{
ASSERT(m_dictionaryStack.size() == 1);
ASSERT(m_dictionaryStack.last() == m_rootDictionary);
}
void KeyedEncoder::encodeUInt32(const String& key, uint32_t value)
{
RetainPtr<CFNumberRef> number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
CFDictionarySetValue(m_rootDictionary.get(), key.createCFString().get(), number.get());
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), number.get());
}
void KeyedEncoder::encodeString(const String& key, const String& value)
{
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), value.createCFString().get());
}
void KeyedEncoder::beginObject(const String& key)
{
auto dictionary = createDictionary();
CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), dictionary.get());
m_dictionaryStack.append(dictionary.get());
}
void KeyedEncoder::endObject()
{
m_dictionaryStack.removeLast();
}
} // namespace WebKit
......@@ -28,6 +28,7 @@
#include <WebCore/KeyedCoding.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>
namespace WebKit {
......@@ -38,8 +39,13 @@ public:
private:
virtual void encodeUInt32(const String& key, uint32_t) OVERRIDE;
virtual void encodeString(const String& key, const String&) OVERRIDE;
virtual void beginObject(const String& key) OVERRIDE;
virtual void endObject() OVERRIDE;
RetainPtr<CFMutableDictionaryRef> m_rootDictionary;
Vector<CFMutableDictionaryRef, 16> m_dictionaryStack;
};
} // namespace WebKit
......
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