Commit 955aabc0 authored by andersca@apple.com's avatar andersca@apple.com

Implement more KeyedEncoder functionality

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

Reviewed by Beth Dakin.

Source/WebCore:

* bindings/js/SerializedScriptValue.h:
* history/HistoryItem.cpp:
(WebCore::HistoryItem::encodeBackForwardTreeNode):
* platform/KeyedCoding.h:
(WebCore::KeyedEncoder::encodeConditionalObject):

Source/WebKit2:

* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::encodeBytes):
(WebKit::KeyedEncoder::encodeInt32):
(WebKit::KeyedEncoder::encodeFloat):
* Shared/cf/KeyedEncoder.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158980 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1ff486e6
2013-11-08 Anders Carlsson <andersca@apple.com>
Implement more KeyedEncoder functionality
https://bugs.webkit.org/show_bug.cgi?id=124089
Reviewed by Beth Dakin.
* bindings/js/SerializedScriptValue.h:
* history/HistoryItem.cpp:
(WebCore::HistoryItem::encodeBackForwardTreeNode):
* platform/KeyedCoding.h:
(WebCore::KeyedEncoder::encodeConditionalObject):
2013-11-08 Eric Carlson <eric.carlson@apple.com>
getCueAsHTML() on an empty cue should return a document fragment
......
......@@ -95,7 +95,7 @@ public:
ScriptValue deserializeForInspector(JSC::ExecState*);
#endif
const Vector<uint8_t>& data() { return m_data; }
const Vector<uint8_t>& data() const { return m_data; }
const Vector<String>& blobURLs() const { return m_blobURLs; }
#if ENABLE(INDEXED_DATABASE)
......
......@@ -739,6 +739,25 @@ void HistoryItem::encodeBackForwardTreeNode(KeyedEncoder& encoder) const
{
// FIXME: Implement.
encoder.encodeString("formContentType", m_formContentType);
encoder.encodeConditionalObject("formData", m_formData.get(), [](KeyedEncoder&, const FormData&) {
// FIXME: Implement.
});
encoder.encodeString("referrer", m_referrer);
encoder.encodeObject("scrollPoint", m_scrollPoint, [](KeyedEncoder& encoder, const IntPoint& scrollPoint) {
encoder.encodeInt32("x", scrollPoint.x());
encoder.encodeInt32("y", scrollPoint.y());
});
encoder.encodeFloat("pageScaleFactor", m_pageScaleFactor);
encoder.encodeConditionalObject("stateObject", m_stateObject.get(), [](KeyedEncoder& encoder, const SerializedScriptValue& stateObject) {
encoder.encodeBytes("data", stateObject.data().data(), stateObject.data().size());
});
encoder.encodeString("target", m_target);
}
......
......@@ -35,8 +35,10 @@ protected:
virtual ~KeyedEncoder() { }
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 encodeFloat(const String& key, float) = 0;
virtual void encodeString(const String& key, const String&) = 0;
template<typename T, typename F>
......@@ -47,6 +49,15 @@ public:
this->endObject();
}
template<typename T, typename F>
void encodeConditionalObject(const String& key, const T* object, F&& function)
{
if (!object)
return;
encodeObject(key, *object, std::forward<F>(function));
}
private:
virtual void beginObject(const String& key) = 0;
virtual void endObject() = 0;
......
2013-11-08 Anders Carlsson <andersca@apple.com>
Implement more KeyedEncoder functionality
https://bugs.webkit.org/show_bug.cgi?id=124089
Reviewed by Beth Dakin.
* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::encodeBytes):
(WebKit::KeyedEncoder::encodeInt32):
(WebKit::KeyedEncoder::encodeFloat):
* Shared/cf/KeyedEncoder.h:
2013-11-08 Anders Carlsson <andersca@apple.com>
KeyedEncoder should be able to encoder objects
......
......@@ -48,12 +48,30 @@ KeyedEncoder::~KeyedEncoder()
ASSERT(m_dictionaryStack.last() == m_rootDictionary);
}
void KeyedEncoder::encodeBytes(const String& key, const uint8_t* bytes, size_t size)
{
RetainPtr<CFDataRef> 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));
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));
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));
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());
......
......@@ -38,7 +38,11 @@ public:
~KeyedEncoder();
private:
virtual void encodeBytes(const String& key, const uint8_t*, size_t) OVERRIDE;
virtual void encodeUInt32(const String& key, uint32_t) OVERRIDE;
virtual void encodeInt32(const String& key, int32_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;
......
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