Title: [163045] trunk/Source
Revision
163045
Author
beid...@apple.com
Date
2014-01-29 16:00:25 -0800 (Wed, 29 Jan 2014)

Log Message

IDB: Fully implement IDBKeyData encoding/decoding
https://bugs.webkit.org/show_bug.cgi?id=127863

Rubberstamped by Alexey Proskuryakov.

Source/WebCore:

* platform/KeyedCoding.h:

* Modules/indexeddb/IDBKeyData.cpp:
(WebCore::IDBKeyData::encode):
(WebCore::IDBKeyData::decode):

* WebCore.exp.in:

Source/WebKit2:

Handle invalid buffers, and pass IDBKeyData decoding along:
* DatabaseProcess/IndexedDB/IDBSerialization.cpp:
(WebKit::deserializeIDBKeyPath):
(WebKit::serializeIDBKeyData):
(WebKit::deserializeIDBKeyData):
* DatabaseProcess/IndexedDB/IDBSerialization.h:

Implement decodeBool and decodeDouble:
* Shared/cf/KeyedDecoder.cpp:
(WebKit::KeyedDecoder::decodeBool):
(WebKit::KeyedDecoder::decodeDouble):
* Shared/cf/KeyedDecoder.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (163044 => 163045)


--- trunk/Source/WebCore/ChangeLog	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebCore/ChangeLog	2014-01-30 00:00:25 UTC (rev 163045)
@@ -1,3 +1,18 @@
+2014-01-29  Brady Eidson  <beid...@apple.com>
+
+        IDB: Fully implement IDBKeyData encoding/decoding
+        https://bugs.webkit.org/show_bug.cgi?id=127863
+
+        Rubberstamped by Alexey Proskuryakov.
+
+        * platform/KeyedCoding.h:
+
+        * Modules/indexeddb/IDBKeyData.cpp:
+        (WebCore::IDBKeyData::encode):
+        (WebCore::IDBKeyData::decode):
+
+        * WebCore.exp.in:
+
 2014-01-29  Bem Jones-Bey  <bjone...@adobe.com>
 
         clip-path swaps bottom radii for the inset shape

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp (163044 => 163045)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp	2014-01-30 00:00:25 UTC (rev 163045)
@@ -141,9 +141,7 @@
         return;
     case IDBKey::ArrayType:
         encoder.encodeObjects("array", arrayValue.begin(), arrayValue.end(), [](KeyedEncoder& encoder, const IDBKeyData& key) {
-            encoder.encodeObject("idbKeyData", key, [](KeyedEncoder& encoder, const IDBKeyData& key) {
-                key.encode(encoder);
-            });
+            key.encode(encoder);
         });
         return;
     case IDBKey::StringType:
@@ -161,10 +159,45 @@
     ASSERT_NOT_REACHED();
 }
 
-bool IDBKeyData::decode(KeyedDecoder&, IDBKeyData&)
+bool IDBKeyData::decode(KeyedDecoder& decoder, IDBKeyData& result)
 {
-    // FIXME: Implement when IDB Get support is implemented (<rdar://problem/15779644>)
-    return false;
+    if (!decoder.decodeBool("null", result.isNull))
+        return false;
+
+    if (result.isNull)
+        return true;
+
+    auto enumFunction = [](int64_t value) {
+        return value == IDBKey::InvalidType
+            || value == IDBKey::ArrayType
+            || value == IDBKey::StringType
+            || value == IDBKey::DateType
+            || value == IDBKey::NumberType
+            || value == IDBKey::MinType;
+    };
+    if (!decoder.decodeVerifiedEnum("type", result.type, enumFunction))
+        return false;
+
+    if (result.type == IDBKey::InvalidType)
+        return true;
+
+    if (result.type == IDBKey::MinType) {
+        ASSERT_NOT_REACHED();
+        return true;
+    }
+
+    if (result.type == IDBKey::StringType)
+        return decoder.decodeString("string", result.stringValue);
+
+    if (result.type == IDBKey::NumberType || result.type == IDBKey::DateType)
+        return decoder.decodeDouble("number", result.numberValue);
+
+    ASSERT(result.type == IDBKey::ArrayType);
+
+    auto arrayFunction = [](KeyedDecoder& decoder, IDBKeyData& result) {
+        return decode(decoder, result);
+    };
+    return decoder.decodeObjects("array", result.arrayValue, arrayFunction);
 }
 
 }

Modified: trunk/Source/WebCore/WebCore.exp.in (163044 => 163045)


--- trunk/Source/WebCore/WebCore.exp.in	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-01-30 00:00:25 UTC (rev 163045)
@@ -3081,6 +3081,7 @@
 __ZNK7WebCore11IDBKeyRange9isOnlyKeyEv
 __ZNK7WebCore15IDBKeyRangeData22maybeCreateIDBKeyRangeEv
 __ZNK7WebCore6IDBKey7isValidEv
+__ZN7WebCore10IDBKeyData6decodeERNS_12KeyedDecoderERS0_
 __ZN7WebCore10IDBKeyDataC1EPKNS_6IDBKeyE
 __ZN7WebCore10IDBKeyPathC1ERKN3WTF6StringE
 __ZN7WebCore10IDBKeyPathC1ERKN3WTF6VectorINS1_6StringELm0ENS1_15CrashOnOverflowEEE

Modified: trunk/Source/WebCore/platform/KeyedCoding.h (163044 => 163045)


--- trunk/Source/WebCore/platform/KeyedCoding.h	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebCore/platform/KeyedCoding.h	2014-01-30 00:00:25 UTC (rev 163045)
@@ -39,6 +39,8 @@
     virtual ~KeyedDecoder() { }
 
 public:
+    virtual bool decodeBool(const String& key, bool&) = 0;
+    virtual bool decodeDouble(const String& key, double&) = 0;
     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;

Modified: trunk/Source/WebKit2/ChangeLog (163044 => 163045)


--- trunk/Source/WebKit2/ChangeLog	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebKit2/ChangeLog	2014-01-30 00:00:25 UTC (rev 163045)
@@ -1,3 +1,23 @@
+2014-01-29  Brady Eidson  <beid...@apple.com>
+
+        IDB: Fully implement IDBKeyData encoding/decoding
+        https://bugs.webkit.org/show_bug.cgi?id=127863
+
+        Rubberstamped by Alexey Proskuryakov.
+
+        Handle invalid buffers, and pass IDBKeyData decoding along:
+        * DatabaseProcess/IndexedDB/IDBSerialization.cpp:
+        (WebKit::deserializeIDBKeyPath):
+        (WebKit::serializeIDBKeyData):
+        (WebKit::deserializeIDBKeyData):
+        * DatabaseProcess/IndexedDB/IDBSerialization.h:
+
+        Implement decodeBool and decodeDouble:
+        * Shared/cf/KeyedDecoder.cpp:
+        (WebKit::KeyedDecoder::decodeBool):
+        (WebKit::KeyedDecoder::decodeDouble):
+        * Shared/cf/KeyedDecoder.h:
+
 2014-01-29  Tim Horton  <timothy_hor...@apple.com>
 
         WebKit2 View Gestures (Swipe): Update rubberBandsAt{Left,Right} when WebKit swipe is enabled

Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp (163044 => 163045)


--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp	2014-01-30 00:00:25 UTC (rev 163045)
@@ -46,17 +46,29 @@
 
 bool deserializeIDBKeyPath(const uint8_t* data, size_t size, IDBKeyPath& result)
 {
+    if (!data || !size)
+        return false;
+
     KeyedDecoder decoder(data, size);
     return IDBKeyPath::decode(decoder, result);
 }
 
-RefPtr<WebCore::SharedBuffer> serializeIDBKeyData(const IDBKeyData& key)
+RefPtr<SharedBuffer> serializeIDBKeyData(const IDBKeyData& key)
 {
     KeyedEncoder encoder;
     key.encode(encoder);
     return encoder.finishEncoding();
 }
 
+bool deserializeIDBKeyData(const uint8_t* data, size_t size, IDBKeyData& result)
+{
+    if (!data || !size)
+        return false;
+
+    KeyedDecoder decoder(data, size);
+    return IDBKeyData::decode(decoder, result);
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(INDEXED_DATABASE)

Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h (163044 => 163045)


--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h	2014-01-30 00:00:25 UTC (rev 163045)
@@ -43,7 +43,7 @@
 bool deserializeIDBKeyPath(const uint8_t* buffer, size_t bufferSize, WebCore::IDBKeyPath&);
 
 RefPtr<WebCore::SharedBuffer> serializeIDBKeyData(const WebCore::IDBKeyData&);
-bool deserializeIDBKey(const uint8_t* buffer, size_t bufferSize, WebCore::IDBKeyData&);
+bool deserializeIDBKeyData(const uint8_t* buffer, size_t bufferSize, WebCore::IDBKeyData&);
 
 } // namespace WebKit
 

Modified: trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp (163044 => 163045)


--- trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp	2014-01-30 00:00:25 UTC (rev 163045)
@@ -50,6 +50,31 @@
     ASSERT(m_arrayIndexStack.isEmpty());
 }
 
+bool KeyedDecoder::decodeBool(const String& key, bool& result)
+{
+    if (!m_dictionaryStack.last())
+        return false;
+
+    CFBooleanRef boolean = static_cast<CFBooleanRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
+    if (!boolean || CFGetTypeID(boolean) != CFBooleanGetTypeID())
+        return false;
+
+    result = CFBooleanGetValue(boolean);
+    return true;
+}
+
+bool KeyedDecoder::decodeDouble(const String& key, double& 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) != kCFNumberDoubleType && CFNumberGetType(number) != kCFNumberFloat64Type))
+        return false;
+
+    return CFNumberGetValue(number, kCFNumberDoubleType, &result);
+}
+
 bool KeyedDecoder::decodeInt64(const String& key, int64_t& result)
 {
     if (!m_dictionaryStack.last())

Modified: trunk/Source/WebKit2/Shared/cf/KeyedDecoder.h (163044 => 163045)


--- trunk/Source/WebKit2/Shared/cf/KeyedDecoder.h	2014-01-29 23:30:18 UTC (rev 163044)
+++ trunk/Source/WebKit2/Shared/cf/KeyedDecoder.h	2014-01-30 00:00:25 UTC (rev 163045)
@@ -35,20 +35,22 @@
 class KeyedDecoder final : public WebCore::KeyedDecoder {
 public:
     KeyedDecoder(const uint8_t* data, size_t);
-    virtual ~KeyedDecoder();
+    virtual ~KeyedDecoder() override;
 
 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 decodeBool(const String& key, bool&) override;
+    virtual bool decodeDouble(const String& key, double&) override;
+    virtual bool decodeInt64(const String& key, int64_t&) override;
+    virtual bool decodeUInt32(const String& key, uint32_t&) override;
+    virtual bool decodeString(const String& key, String&) override;
 
-    virtual bool beginObject(const String& key);
-    virtual void endObject();
+    virtual bool beginObject(const String& key) override;
+    virtual void endObject() override;
 
-    virtual bool beginArray(const String& key);
-    virtual bool beginArrayElement();
-    virtual void endArrayElement();
-    virtual void endArray();
+    virtual bool beginArray(const String& key) override;
+    virtual bool beginArrayElement() override;
+    virtual void endArrayElement() override;
+    virtual void endArray() override;
 
     RetainPtr<CFDictionaryRef> m_rootDictionary;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to