Implement more KeyedEncoder functionality
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Nov 2013 01:16:26 +0000 (01:16 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Nov 2013 01:16:26 +0000 (01:16 +0000)
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: https://svn.webkit.org/repository/webkit/trunk@158980 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/SerializedScriptValue.h
Source/WebCore/history/HistoryItem.cpp
Source/WebCore/platform/KeyedCoding.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/cf/KeyedEncoder.cpp
Source/WebKit2/Shared/cf/KeyedEncoder.h

index 2ca4d0b..48af11a 100644 (file)
@@ -1,3 +1,16 @@
+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
index 8abc7fc..69d25f6 100644 (file)
@@ -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)
index 4b6a347..6c7acd5 100644 (file)
@@ -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);
 }
 
index a2f3867..49ef3f0 100644 (file)
@@ -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;
index 4ac1986..96ecc4b 100644 (file)
@@ -1,5 +1,18 @@
 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
         https://bugs.webkit.org/show_bug.cgi?id=124085
 
index 438ff0f..8fdc13f 100644 (file)
@@ -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());
index d399da2..91c9b35 100644 (file)
@@ -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;