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 2ca4d0bb8c94686b440544201f3295968b664636..48af11a30f1ed4aa987bf334a1e406a577eccf82 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 8abc7fc36cc29182d7ae126a690f2a65a2b445ea..69d25f67ff67e95e24dfefc0d3eed69b3c5250a3 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 4b6a3470cc8362e3d51f2da6335b75716e5a373f..6c7acd5508b86d1bc4af974643e594f022b45754 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 a2f3867409f975ef68637979113109d8ec4546fe..49ef3f0897f1ce07e3d20b48c3f5888bfe89fb5d 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 4ac1986fe5d74876b60db967acf3be682ab77ccd..96ecc4bbc5fbd830ff7003f4d636558a3f1ec3c6 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.
+
+        * 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
index 438ff0fa0d510ee759d705ae55c78cad08391109..8fdc13f1ce5191b97e2d56ee63197260ce4e65d9 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 d399da266db9ef2d15cb6c4ff8cb10c957556599..91c9b35a4a788bc5b0bc048a3ff4aca12d3982d1 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;