Use KeyedCoding as a persistent storage mechanism for blobs
[WebKit-https.git] / Source / WebKit2 / Shared / cf / KeyedEncoder.cpp
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