Use KeyedCoding as a persistent storage mechanism for blobs
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jan 2014 21:45:34 +0000 (21:45 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jan 2014 21:45:34 +0000 (21:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127012

Reviewed by Anders Carlsson.

Source/WebCore:

Add basic KeyedDecoder interface that is the inverse of KeyedEncoder:
* platform/KeyedCoding.h:
(WebCore::KeyedDecoder::decodeVerifiedEnum):
(WebCore::KeyedDecoder::decodeObject):
(WebCore::KeyedDecoder::decodeObjects):

Use KeyedEncoder/Decoder to encode/decode IDBKeyPath:
* Modules/indexeddb/IDBKeyPath.cpp:
(WebCore::IDBKeyPath::encode):
(WebCore::IDBKeyPath::decode):
* Modules/indexeddb/IDBKeyPath.h:

* WebCore.exp.in:

Source/WebKit2:

Add a way to get the encoded buffer to save:
* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::finishEncoding):
* Shared/cf/KeyedEncoder.h:

Add a WebKit KeyedDecoder for CF platforms that can decode the previously encoded buffer:
* Shared/cf/KeyedDecoder.cpp: Added.
(WebKit::KeyedDecoder::KeyedDecoder):
(WebKit::KeyedDecoder::~KeyedDecoder):
(WebKit::KeyedDecoder::decodeInt64):
(WebKit::KeyedDecoder::decodeUInt32):
(WebKit::KeyedDecoder::decodeString):
(WebKit::KeyedDecoder::beginObject):
(WebKit::KeyedDecoder::endObject):
(WebKit::KeyedDecoder::beginArray):
(WebKit::KeyedDecoder::beginArrayElement):
(WebKit::KeyedDecoder::endArrayElement):
(WebKit::KeyedDecoder::endArray):
* Shared/cf/KeyedDecoder.h:

Create a WebKit KeyedEncoder/Decoder and use to encode/decode IDBKeyPaths:
* DatabaseProcess/IndexedDB/IDBSerialization.cpp:
(WebKit::serializeIDBKeyPath):
(WebKit::deserializeIDBKeyPath):
* DatabaseProcess/IndexedDB/IDBSerialization.h:

* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::createObjectStore):

* WebKit2.xcodeproj/project.pbxproj:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@162148 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp
Source/WebCore/Modules/indexeddb/IDBKeyPath.h
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/KeyedCoding.h
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp
Source/WebKit2/Shared/cf/KeyedDecoder.cpp [new file with mode: 0644]
Source/WebKit2/Shared/cf/KeyedDecoder.h [new file with mode: 0644]
Source/WebKit2/Shared/cf/KeyedEncoder.cpp
Source/WebKit2/Shared/cf/KeyedEncoder.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index f55c70f..adb1b80 100644 (file)
@@ -1,3 +1,24 @@
+2014-01-16  Brady Eidson  <beidson@apple.com>
+
+        Use KeyedCoding as a persistent storage mechanism for blobs
+        https://bugs.webkit.org/show_bug.cgi?id=127012
+
+        Reviewed by Anders Carlsson.
+
+        Add basic KeyedDecoder interface that is the inverse of KeyedEncoder:
+        * platform/KeyedCoding.h:
+        (WebCore::KeyedDecoder::decodeVerifiedEnum):
+        (WebCore::KeyedDecoder::decodeObject):
+        (WebCore::KeyedDecoder::decodeObjects):
+
+        Use KeyedEncoder/Decoder to encode/decode IDBKeyPath:
+        * Modules/indexeddb/IDBKeyPath.cpp:
+        (WebCore::IDBKeyPath::encode):
+        (WebCore::IDBKeyPath::decode):
+        * Modules/indexeddb/IDBKeyPath.h:
+
+        * WebCore.exp.in:
+
 2014-01-16  Eric Carlson  <eric.carlson@apple.com>
 
         Allow MediaSessionManager to restrict inline <video> playback
index 0a0f9a6..2b46ff8 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "KeyedCoding.h"
 #include <wtf/ASCIICType.h>
 #include <wtf/dtoa.h>
 #include <wtf/unicode/Unicode.h>
@@ -261,6 +262,49 @@ IDBKeyPath IDBKeyPath::isolatedCopy() const
     return result;
 }
 
+void IDBKeyPath::encode(KeyedEncoder& encoder) const
+{
+    encoder.encodeEnum("type", m_type);
+    switch (m_type) {
+    case IDBKeyPath::NullType:
+        break;
+    case IDBKeyPath::StringType:
+        encoder.encodeString("string", m_string);
+        break;
+    case IDBKeyPath::ArrayType:
+        encoder.encodeObjects("array", m_array.begin(), m_array.end(), [](WebCore::KeyedEncoder& encoder, const String& string) {
+            encoder.encodeString("string", string);
+        });
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    };
+}
+
+bool IDBKeyPath::decode(KeyedDecoder& decoder, IDBKeyPath& result)
+{
+    auto enumFunction = [](int64_t value) {
+        return value == NullType || value == StringType || value == ArrayType;
+    };
+
+    if (!decoder.decodeVerifiedEnum("type", result.m_type, enumFunction))
+        return false;
+
+    if (result.m_type == NullType)
+        return true;
+
+    if (result.m_type == StringType)
+        return decoder.decodeString("string", result.m_string);
+
+    ASSERT(result.m_type == ArrayType);
+
+    auto arrayFunction = [](KeyedDecoder& decoder, String& result) {
+        return decoder.decodeString("string", result);
+    };
+
+    return decoder.decodeObjects("array", result.m_array, arrayFunction);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index 135f613..6dcd7de 100644 (file)
@@ -33,6 +33,9 @@
 
 namespace WebCore {
 
+class KeyedDecoder;
+class KeyedEncoder;
+
 enum IDBKeyPathParseError {
     IDBKeyPathParseErrorNone,
     IDBKeyPathParseErrorStart,
@@ -74,6 +77,9 @@ public:
 
     IDBKeyPath isolatedCopy() const;
 
+    void encode(KeyedEncoder&) const;
+    static bool decode(KeyedDecoder&, IDBKeyPath&);
+
 private:
     Type m_type;
     String m_string;
index cfdb971..c38f918 100644 (file)
@@ -3074,8 +3074,10 @@ __ZN7WebCore26MockMediaPlayerMediaSource19registerMediaEngineEPFvPFN3WTF10PassOw
 #endif
 
 #if ENABLE(INDEXED_DATABASE)
+__ZNK7WebCore10IDBKeyPath6encodeERNS_12KeyedEncoderE
 __ZN7WebCore10IDBKeyPathC1ERKN3WTF6StringE
 __ZN7WebCore10IDBKeyPathC1ERKN3WTF6VectorINS1_6StringELm0ENS1_15CrashOnOverflowEEE
+__ZN7WebCore10IDBKeyPath6decodeERNS_12KeyedDecoderERS0_
 __ZN7WebCore18IDBDatabaseBackend14openConnectionEN3WTF10PassRefPtrINS_12IDBCallbacksEEENS2_INS_20IDBDatabaseCallbacksEEExy
 __ZN7WebCore18IDBDatabaseBackend6createERKN3WTF6StringES4_PNS_26IDBFactoryBackendInterfaceERNS_19IDBServerConnectionE
 __ZN7WebCore18IDBDatabaseBackendD1Ev
index 8f2eb68..47e2b72 100644 (file)
 #ifndef KeyedCoding_h
 #define KeyedCoding_h
 
+#include <functional>
 #include <wtf/Forward.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
+class SharedBuffer;
+
 class KeyedDecoder {
 protected:
     virtual ~KeyedDecoder() { }
 
 public:
+    virtual bool decodeInt64(const String& key, int64_t&) = 0;
     virtual bool decodeUInt32(const String& key, uint32_t&) = 0;
+    virtual bool decodeString(const String& key, String&) = 0;
+
+    template<typename T, typename F>
+    bool decodeVerifiedEnum(const String& key, T& value, F&& function)
+    {
+        static_assert(std::is_enum<T>::value, "T must be an enum type");
+
+        int64_t intValue;
+        if (!decodeInt64(key, intValue))
+            return false;
+
+        if (!function(intValue))
+            return false;
+
+        value = static_cast<T>(intValue);
+        return true;
+    }
+
+    template<typename T, typename F>
+    bool decodeObject(const String& key, T& object, F&& function)
+    {
+        if (!beginObject(key))
+            return false;
+        bool result = function(*this, object);
+        endObject();
+        return result;
+    }
+
+    template<typename T, typename F>
+    bool decodeObjects(const String& key, Vector<T>& objects, F&& function)
+    {
+        if (!beginArray(key))
+            return false;
+
+        bool result = true;
+        while (beginArrayElement()) {
+            T element;
+            if (!function(*this, element)) {
+                result = false;
+                break;
+            }
+            objects.append(std::move(element));
+            endArrayElement();
+        }
+
+        endArray();
+        return result;
+    }
+
+private:
+    virtual bool beginObject(const String& key) = 0;
+    virtual void endObject() = 0;
+
+    virtual bool beginArray(const String& key) = 0;
+    virtual bool beginArrayElement() = 0;
+    virtual void endArrayElement() = 0;
+    virtual void endArray() = 0;
 };
 
 class KeyedEncoder {
@@ -52,6 +114,8 @@ public:
     virtual void encodeDouble(const String& key, double) = 0;
     virtual void encodeString(const String& key, const String&) = 0;
 
+    virtual PassRefPtr<SharedBuffer> finishEncoding() = 0;
+
     template<typename T>
     void encodeEnum(const String& key, T value)
     {
index 9624044..172789b 100644 (file)
@@ -1,3 +1,41 @@
+2014-01-15  Brady Eidson  <beidson@apple.com>
+
+        Use KeyedCoding as a persistent storage mechanism for blobs
+        https://bugs.webkit.org/show_bug.cgi?id=127012
+
+        Reviewed by Anders Carlsson.
+
+        Add a way to get the encoded buffer to save:
+        * Shared/cf/KeyedEncoder.cpp:
+        (WebKit::KeyedEncoder::finishEncoding):
+        * Shared/cf/KeyedEncoder.h:
+
+        Add a WebKit KeyedDecoder for CF platforms that can decode the previously encoded buffer:
+        * Shared/cf/KeyedDecoder.cpp: Added.
+        (WebKit::KeyedDecoder::KeyedDecoder):
+        (WebKit::KeyedDecoder::~KeyedDecoder):
+        (WebKit::KeyedDecoder::decodeInt64):
+        (WebKit::KeyedDecoder::decodeUInt32):
+        (WebKit::KeyedDecoder::decodeString):
+        (WebKit::KeyedDecoder::beginObject):
+        (WebKit::KeyedDecoder::endObject):
+        (WebKit::KeyedDecoder::beginArray):
+        (WebKit::KeyedDecoder::beginArrayElement):
+        (WebKit::KeyedDecoder::endArrayElement):
+        (WebKit::KeyedDecoder::endArray):
+        * Shared/cf/KeyedDecoder.h:
+
+        Create a WebKit KeyedEncoder/Decoder and use to encode/decode IDBKeyPaths:
+        * DatabaseProcess/IndexedDB/IDBSerialization.cpp:
+        (WebKit::serializeIDBKeyPath):
+        (WebKit::deserializeIDBKeyPath):
+        * DatabaseProcess/IndexedDB/IDBSerialization.h:
+
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::createObjectStore):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2014-01-16  Andy Estes  <aestes@apple.com>
 
         Stop copying WKOriginDataManager.cpp into WebKit2.framework
index 8c6ed10..620a186 100644 (file)
 #if ENABLE(INDEXED_DATABASE)
 
 #include "ArgumentEncoder.h"
+#include "KeyedDecoder.h"
+#include "KeyedEncoder.h"
 #include <WebCore/IDBKeyPath.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-std::unique_ptr<Vector<uint8_t>> serializeIDBKeyPath(const WebCore::IDBKeyPath&)
+RefPtr<SharedBuffer> serializeIDBKeyPath(const WebCore::IDBKeyPath& keyPath)
 {
-    // FIXME: Once we have a serialization solution appropriate for persistent storage to disk, use that here.
-
-    return nullptr;
+    KeyedEncoder encoder;
+    keyPath.encode(encoder);
+    return encoder.finishEncoding();
 }
 
-std::unique_ptr<WebCore::IDBKeyPath> deserializeIDBKeyPath(const uint8_t*, size_t)
+std::unique_ptr<WebCore::IDBKeyPath> deserializeIDBKeyPath(const uint8_t* data, size_t size)
 {
-    // FIXME: Once we have a serialization solution appropriate for persistent storage to disk, use that here.
+    KeyedDecoder decoder(data, size);
+    std::unique_ptr<IDBKeyPath> result = std::make_unique<IDBKeyPath>();
+    if (!IDBKeyPath::decode(decoder, *result))
+        return nullptr;
 
-    return nullptr;
+    return result;
 }
 
 } // namespace WebKit
index ff9ad06..a6c73df 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include <WebCore/SharedBuffer.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -36,7 +37,7 @@ class IDBKeyPath;
 
 namespace WebKit {
 
-std::unique_ptr<Vector<uint8_t>> serializeIDBKeyPath(const WebCore::IDBKeyPath&);
+RefPtr<WebCore::SharedBuffer> serializeIDBKeyPath(const WebCore::IDBKeyPath&);
 std::unique_ptr<WebCore::IDBKeyPath> deserializeIDBKeyPath(const uint8_t* buffer, size_t bufferSize);
 
 } // namespace WebKit
index 8b217aa..0b05bf4 100644 (file)
@@ -362,7 +362,7 @@ bool UniqueIDBDatabaseBackingStoreSQLite::createObjectStore(const IDBTransaction
         return false;
     }
 
-    std::unique_ptr<Vector<uint8_t>> keyPathBlob = serializeIDBKeyPath(metadata.keyPath);
+    RefPtr<SharedBuffer> keyPathBlob = serializeIDBKeyPath(metadata.keyPath);
     if (!keyPathBlob) {
         LOG_ERROR("Unable to serialize IDBKeyPath to save in database");
         return false;
diff --git a/Source/WebKit2/Shared/cf/KeyedDecoder.cpp b/Source/WebKit2/Shared/cf/KeyedDecoder.cpp
new file mode 100644 (file)
index 0000000..0eb1ef2
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "KeyedDecoder.h"
+
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+KeyedDecoder::KeyedDecoder(const uint8_t* data, size_t size)
+{
+    auto cfData = adoptCF(CFDataCreate(kCFAllocatorDefault, data, size));
+    m_rootDictionary = adoptCF(static_cast<CFDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, cfData.get(), kCFPropertyListImmutable, 0, 0)));
+
+    if (m_rootDictionary && CFGetTypeID(m_rootDictionary.get()) != CFDictionaryGetTypeID())
+        m_rootDictionary = nullptr;
+
+    if (m_rootDictionary)
+        m_dictionaryStack.append(m_rootDictionary.get());
+}
+
+KeyedDecoder::~KeyedDecoder()
+{
+    ASSERT(m_dictionaryStack.size() == 1);
+    ASSERT(m_dictionaryStack.last() == m_rootDictionary);
+    ASSERT(m_arrayStack.isEmpty());
+    ASSERT(m_arrayIndexStack.isEmpty());
+}
+
+bool KeyedDecoder::decodeInt64(const String& key, int64_t& result)
+{
+    if (!m_dictionaryStack.last())
+        return false;
+
+    CFNumberRef number = static_cast<CFNumberRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!number || CFGetTypeID(number) != CFNumberGetTypeID() || CFNumberGetType(number) != kCFNumberSInt64Type)
+        return false;
+
+    return CFNumberGetValue(number, kCFNumberSInt64Type, &result);
+}
+
+bool KeyedDecoder::decodeUInt32(const String& key, uint32_t& result)
+{
+    if (!m_dictionaryStack.last())
+        return false;
+
+    CFNumberRef number = static_cast<CFNumberRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!number || CFGetTypeID(number) != CFNumberGetTypeID() || CFNumberGetType(number) != kCFNumberSInt32Type)
+        return false;
+
+    return CFNumberGetValue(number, kCFNumberSInt32Type, &result);
+}
+
+bool KeyedDecoder::decodeString(const String& key, String& result)
+{
+    if (!m_dictionaryStack.last())
+        return false;
+
+    CFStringRef string = static_cast<CFStringRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!string || CFGetTypeID(string) != CFStringGetTypeID())
+        return false;
+
+    result = string;
+    return true;
+}
+
+bool KeyedDecoder::beginObject(const String& key)
+{
+    if (!m_dictionaryStack.last())
+        return false;
+
+    CFDictionaryRef dictionary = static_cast<CFDictionaryRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!dictionary || CFGetTypeID(dictionary) != CFDictionaryGetTypeID())
+        return false;
+
+    m_dictionaryStack.append(dictionary);
+    return true;
+}
+
+void KeyedDecoder::endObject()
+{
+    m_dictionaryStack.removeLast();
+}
+
+bool KeyedDecoder::beginArray(const String& key)
+{
+    if (!m_dictionaryStack.last())
+        return false;
+
+    CFArrayRef array = static_cast<CFArrayRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!array || CFGetTypeID(array) != CFArrayGetTypeID())
+        return false;
+
+    for (CFIndex i = 0; i < CFArrayGetCount(array); ++i) {
+        CFTypeRef object = CFArrayGetValueAtIndex(array, i);
+        if (CFGetTypeID(object) != CFDictionaryGetTypeID())
+            return false;
+    }
+
+    m_arrayStack.append(array);
+    m_arrayIndexStack.append(0);
+    return true;
+}
+
+bool KeyedDecoder::beginArrayElement()
+{
+    ASSERT(m_dictionaryStack.last());
+
+    if (m_arrayIndexStack.last() >= CFArrayGetCount(m_arrayStack.last()))
+        return false;
+
+    CFDictionaryRef dictionary = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(m_arrayStack.last(), m_arrayIndexStack.last()++));
+    m_dictionaryStack.append(dictionary);
+    return true;
+}
+
+void KeyedDecoder::endArrayElement()
+{
+    m_dictionaryStack.removeLast();
+}
+
+void KeyedDecoder::endArray()
+{
+    m_arrayStack.removeLast();
+    m_arrayIndexStack.removeLast();
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Shared/cf/KeyedDecoder.h b/Source/WebKit2/Shared/cf/KeyedDecoder.h
new file mode 100644 (file)
index 0000000..0be79da
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef KeyedDecoder_h
+#define KeyedDecoder_h
+
+#include <WebCore/KeyedCoding.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebKit {
+
+class KeyedDecoder FINAL : public WebCore::KeyedDecoder {
+public:
+    KeyedDecoder(const uint8_t* data, size_t);
+    virtual ~KeyedDecoder();
+
+private:
+    virtual bool decodeInt64(const String& key, int64_t&);
+    virtual bool decodeUInt32(const String& key, uint32_t&);
+    virtual bool decodeString(const String& key, String&);
+
+    virtual bool beginObject(const String& key);
+    virtual void endObject();
+
+    virtual bool beginArray(const String& key);
+    virtual bool beginArrayElement();
+    virtual void endArrayElement();
+    virtual void endArray();
+
+    RetainPtr<CFDictionaryRef> m_rootDictionary;
+
+    Vector<CFDictionaryRef, 16> m_dictionaryStack;
+    Vector<CFArrayRef, 16> m_arrayStack;
+    Vector<CFIndex> m_arrayIndexStack;
+};
+
+} // namespace WebKit
+
+#endif // KeyedDecoder_h
index 3c327ea..afbb2ff 100644 (file)
 #include "KeyedEncoder.h"
 
 #include <CoreFoundation/CoreFoundation.h>
+#include <WebCore/SharedBuffer.h>
 #include <wtf/text/WTFString.h>
 
+using namespace WebCore;
+
 namespace WebKit {
 
 static RetainPtr<CFMutableDictionaryRef> createDictionary()
@@ -134,4 +137,14 @@ void KeyedEncoder::endArray()
     m_arrayStack.removeLast();
 }
 
+PassRefPtr<SharedBuffer> KeyedEncoder::finishEncoding()
+{
+    CFErrorRef error = nullptr;
+    RetainPtr<CFDataRef> data = adoptCF(CFPropertyListCreateData(kCFAllocatorDefault, m_rootDictionary.get(), kCFPropertyListBinaryFormat_v1_0, 0, &error));
+    if (error)
+        return nullptr;
+
+    return SharedBuffer::wrapCFData(data.get());
+}
+
 } // namespace WebKit
index 13fe736..fcfadd4 100644 (file)
@@ -37,6 +37,8 @@ public:
     KeyedEncoder();
     ~KeyedEncoder();
 
+    virtual PassRefPtr<WebCore::SharedBuffer> finishEncoding() OVERRIDE;
+
 private:
     virtual void encodeBytes(const String& key, const uint8_t*, size_t) override;
     virtual void encodeBool(const String& key, bool) override;
index 5e2d485..cb7274e 100644 (file)
                51834593134532E90092B696 /* WebIconDatabaseClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 51834591134532E80092B696 /* WebIconDatabaseClient.h */; };
                518353DA1885BF8C00D9FE44 /* IDBSerialization.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 518353D81885BF8C00D9FE44 /* IDBSerialization.cpp */; };
                518353DB1885BF8C00D9FE44 /* IDBSerialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 518353D91885BF8C00D9FE44 /* IDBSerialization.h */; };
+               518353DE1887128B00D9FE44 /* KeyedDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 518353DC1887128B00D9FE44 /* KeyedDecoder.cpp */; };
+               518353DF1887128B00D9FE44 /* KeyedDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 518353DD1887128B00D9FE44 /* KeyedDecoder.h */; };
                5183DDEC1630BDFC008BE5C7 /* NetworkProcessConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5105B0D4162F7A7A00E27709 /* NetworkProcessConnection.cpp */; };
                51871B5B127CB89D00F76232 /* WebContextMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51871B59127CB89D00F76232 /* WebContextMenu.cpp */; };
                51871B5C127CB89D00F76232 /* WebContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 51871B5A127CB89D00F76232 /* WebContextMenu.h */; };
                51834591134532E80092B696 /* WebIconDatabaseClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIconDatabaseClient.h; sourceTree = "<group>"; };
                518353D81885BF8C00D9FE44 /* IDBSerialization.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBSerialization.cpp; sourceTree = "<group>"; };
                518353D91885BF8C00D9FE44 /* IDBSerialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBSerialization.h; sourceTree = "<group>"; };
+               518353DC1887128B00D9FE44 /* KeyedDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoder.cpp; sourceTree = "<group>"; };
+               518353DD1887128B00D9FE44 /* KeyedDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoder.h; sourceTree = "<group>"; };
                5183B3931379F85C00E8754E /* Shim.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Shim.xcconfig; sourceTree = "<group>"; };
                5184BC4A132E907A006B9E28 /* WebIconDatabase.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebIconDatabase.messages.in; sourceTree = "<group>"; };
                51871B59127CB89D00F76232 /* WebContextMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenu.cpp; sourceTree = "<group>"; };
                        children = (
                                1AAF0C4912B16334008E49E2 /* ArgumentCodersCF.cpp */,
                                1AAF0C4812B16334008E49E2 /* ArgumentCodersCF.h */,
+                               518353DC1887128B00D9FE44 /* KeyedDecoder.cpp */,
+                               518353DD1887128B00D9FE44 /* KeyedDecoder.h */,
                                1AE00D5A182DADE100087DD7 /* KeyedEncoder.cpp */,
                                1AE00D5B182DADE100087DD7 /* KeyedEncoder.h */,
                        );
                                2984F589164BA095004BC0C6 /* CustomProtocolManagerMessages.h in Headers */,
                                29AD3093164B4C5D0072DEA9 /* CustomProtocolManagerProxy.h in Headers */,
                                2984F57D164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h in Headers */,
+                               518353DF1887128B00D9FE44 /* KeyedDecoder.h in Headers */,
                                93FC67BE12D3CCF200A60610 /* DecoderAdapter.h in Headers */,
                                BCE81D99131AE02100241910 /* DictionaryPopupInfo.h in Headers */,
                                C58CDF2E1887609F00871536 /* InteractionInformationAtPosition.h in Headers */,
                                BCA0EF8012331E78007D3CFB /* WebUndoStep.cpp in Sources */,
                                2DA944AF1884E9BA00ED86DB /* WebPageProxyIOS.mm in Sources */,
                                BCE2315E122C30CA00D5C35A /* APIURLRequest.cpp in Sources */,
+                               518353DE1887128B00D9FE44 /* KeyedDecoder.cpp in Sources */,
                                BC90A1D3122DD55E00CC8C50 /* APIURLResponse.cpp in Sources */,
                                C0337DD1127A2980008FF4F4 /* WebWheelEvent.cpp in Sources */,
                                51FCB18517BBFE0300394CD8 /* AsynchronousNetworkLoaderClient.cpp in Sources */,