IDB: create object store support
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jan 2014 06:31:16 +0000 (06:31 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jan 2014 06:31:16 +0000 (06:31 +0000)
<rdar://problem/15779639> and https://bugs.webkit.org/show_bug.cgi?id=127011

Reviewed by Anders Carlsson.

Source/WebCore:

Split the 3 objects declared in IDBDatabaseMetadata into their own header files:
* Modules/indexeddb/IDBDatabaseMetadata.h:
* Modules/indexeddb/IDBIndexMetadata.h:
(WebCore::IDBIndexMetadata::IDBIndexMetadata):
* Modules/indexeddb/IDBObjectStoreMetadata.h:
(WebCore::IDBObjectStoreMetadata::IDBObjectStoreMetadata):

Add cross thread copying for IDBDatabaseMetadata:
* platform/CrossThreadCopier.cpp:
(WebCore::IDBIndexMetadata>::copy):
(WebCore::IDBObjectStoreMetadata>::copy):
* platform/CrossThreadCopier.h:

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:

Source/WebKit2:

Add messaging/callback infrastructure for creating object stores:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::createObjectStore):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:

* WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
(WebKit::WebIDBServerConnection::createObjectStore):
(WebKit::WebIDBServerConnection::didCreateObjectStore):
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:

* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::didChangeDatabaseVersion):
(WebKit::UniqueIDBDatabase::didCreateObjectStore):
(WebKit::UniqueIDBDatabase::didCompleteBoolRequest):
(WebKit::UniqueIDBDatabase::createObjectStore):
(WebKit::UniqueIDBDatabase::createObjectStoreInBackingStore):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:

* DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:

Add serialization helpers to save/restore an IDBKeyPath to/from disk:
* DatabaseProcess/IndexedDB/IDBSerialization.cpp:
(WebKit::serializeIDBKeyPath):
(WebKit::deserializeIDBKeyPath):
* DatabaseProcess/IndexedDB/IDBSerialization.h:

Add object store metadata to the schema, and save/restore the metadata:
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::extractExistingMetadata):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::createObjectStore):
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:

* Scripts/webkit2/messages.py:
(struct_or_class):
* WebKit2.xcodeproj/project.pbxproj:

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

24 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabaseMetadata.h
Source/WebCore/Modules/indexeddb/IDBIndexMetadata.h [new file with mode: 0644]
Source/WebCore/Modules/indexeddb/IDBObjectStoreMetadata.h [new file with mode: 0644]
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/CrossThreadCopier.cpp
Source/WebCore/platform/CrossThreadCopier.h
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in
Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.h
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h
Source/WebKit2/Scripts/webkit2/messages.py
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in

index 82bb701..8e1a996 100644 (file)
@@ -1,3 +1,26 @@
+2014-01-14  Brady Eidson  <beidson@apple.com>
+
+        IDB: create object store support
+        <rdar://problem/15779639> and https://bugs.webkit.org/show_bug.cgi?id=127011
+
+        Reviewed by Anders Carlsson.
+
+        Split the 3 objects declared in IDBDatabaseMetadata into their own header files:
+        * Modules/indexeddb/IDBDatabaseMetadata.h:
+        * Modules/indexeddb/IDBIndexMetadata.h:
+        (WebCore::IDBIndexMetadata::IDBIndexMetadata):
+        * Modules/indexeddb/IDBObjectStoreMetadata.h:
+        (WebCore::IDBObjectStoreMetadata::IDBObjectStoreMetadata):
+
+        Add cross thread copying for IDBDatabaseMetadata:
+        * platform/CrossThreadCopier.cpp:
+        (WebCore::IDBIndexMetadata>::copy):
+        (WebCore::IDBObjectStoreMetadata>::copy):
+        * platform/CrossThreadCopier.h:
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2014-01-14  Joseph Pecoraro  <pecoraro@apple.com>
 
         [iOS] Crash in NavigatorBase::vendor loading apple.com
index dda53b9..7571744 100644 (file)
 #ifndef IDBDatabaseMetadata_h
 #define IDBDatabaseMetadata_h
 
-#include "IDBKeyPath.h"
-#include <stdint.h>
-#include <wtf/HashMap.h>
-#include <wtf/text/StringHash.h>
-#include <wtf/text/WTFString.h>
+#include "IDBObjectStoreMetadata.h"
 
 #if ENABLE(INDEXED_DATABASE)
 
 namespace WebCore {
 
-struct IDBIndexMetadata {
-    IDBIndexMetadata() { }
-    IDBIndexMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
-        : name(name)
-        , id(id)
-        , keyPath(keyPath)
-        , unique(unique)
-        , multiEntry(multiEntry) { }
-    String name;
-    int64_t id;
-    IDBKeyPath keyPath;
-    bool unique;
-    bool multiEntry;
-
-    IDBIndexMetadata isolatedCopy() const;
-
-    static const int64_t InvalidId = -1;
-};
-
-struct IDBObjectStoreMetadata {
-    IDBObjectStoreMetadata() { }
-    IDBObjectStoreMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId)
-        : name(name)
-        , id(id)
-        , keyPath(keyPath)
-        , autoIncrement(autoIncrement)
-        , maxIndexId(maxIndexId)
-    {
-    }
-    String name;
-    int64_t id;
-    IDBKeyPath keyPath;
-    bool autoIncrement;
-    int64_t maxIndexId;
-
-    static const int64_t InvalidId = -1;
-
-    typedef HashMap<int64_t, IDBIndexMetadata> IndexMap;
-    IndexMap indexes;
-
-    IDBObjectStoreMetadata isolatedCopy() const;
-};
-
 struct IDBDatabaseMetadata {
 
     // FIXME: These are only here to support the LevelDB backend which incorrectly handles versioning.
@@ -100,8 +53,6 @@ struct IDBDatabaseMetadata {
         DefaultIntVersion = 0
     };
 
-    typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap;
-
     IDBDatabaseMetadata()
         : id(0)
         , version(0)
@@ -122,13 +73,13 @@ struct IDBDatabaseMetadata {
     uint64_t version;
     int64_t maxObjectStoreId;
 
+    typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap;
     ObjectStoreMap objectStores;
 
     IDBDatabaseMetadata isolatedCopy() const;
 };
 
-}
+} // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
-
 #endif // IDBDatabaseMetadata_h
diff --git a/Source/WebCore/Modules/indexeddb/IDBIndexMetadata.h b/Source/WebCore/Modules/indexeddb/IDBIndexMetadata.h
new file mode 100644 (file)
index 0000000..724bf09
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 Google 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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE 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 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 IDBIndexMetadata_h
+#define IDBIndexMetadata_h
+
+#include "IDBKeyPath.h"
+#include <wtf/HashMap.h>
+#include <wtf/text/WTFString.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+struct IDBIndexMetadata {
+    IDBIndexMetadata()
+    {
+    }
+
+    IDBIndexMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
+        : name(name)
+        , id(id)
+        , keyPath(keyPath)
+        , unique(unique)
+        , multiEntry(multiEntry)
+    {
+    }
+
+    String name;
+    int64_t id;
+    IDBKeyPath keyPath;
+    bool unique;
+    bool multiEntry;
+
+    IDBIndexMetadata isolatedCopy() const;
+
+    static const int64_t InvalidId = -1;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
+#endif // IDBIndexMetadata_h
diff --git a/Source/WebCore/Modules/indexeddb/IDBObjectStoreMetadata.h b/Source/WebCore/Modules/indexeddb/IDBObjectStoreMetadata.h
new file mode 100644 (file)
index 0000000..a1500a4
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 Google 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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE 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 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 IDBObjectStoreMetadata_h
+#define IDBObjectStoreMetadata_h
+
+#include "IDBIndexMetadata.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+struct IDBObjectStoreMetadata {
+    IDBObjectStoreMetadata()
+    {
+    }
+
+    IDBObjectStoreMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId)
+        : name(name)
+        , id(id)
+        , keyPath(keyPath)
+        , autoIncrement(autoIncrement)
+        , maxIndexId(maxIndexId)
+    {
+    }
+
+    String name;
+    int64_t id;
+    IDBKeyPath keyPath;
+    bool autoIncrement;
+    int64_t maxIndexId;
+
+    static const int64_t InvalidId = -1;
+
+    typedef HashMap<int64_t, IDBIndexMetadata> IndexMap;
+    IndexMap indexes;
+
+    IDBObjectStoreMetadata isolatedCopy() const;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
+#endif // IDBObjectStoreMetadata_h
index 0c68c65..f77c31b 100644 (file)
@@ -82,6 +82,8 @@ __ZN7WebCore10MouseEvent6createERKN3WTF12AtomicStringEbbdNS1_10PassRefPtrINS_9DO
 __ZN7WebCore10Pasteboard14writePlainTextERKN3WTF6StringENS0_18SmartReplaceOptionE
 __ZN7WebCore10RenderView10compositorEv
 __ZN7WebCore10RenderView7hitTestERKNS_14HitTestRequestERNS_13HitTestResultE
+__ZN7WebCore15SQLiteStatement13getColumnBlobEiRi
+__ZN7WebCore15SQLiteStatement14getColumnInt64Ei
 __ZN7WebCore10ScrollView16setParentVisibleEb
 __ZN7WebCore10ScrollView17setUseFixedLayoutEb
 __ZN7WebCore10ScrollView18setFixedLayoutSizeERKNS_7IntSizeE
@@ -595,6 +597,8 @@ __ZN7WebCore15SQLiteStatement22isColumnDeclaredAsBlobEi
 __ZN7WebCore15SQLiteStatement4stepEv
 __ZN7WebCore15SQLiteStatement5resetEv
 __ZN7WebCore15SQLiteStatement7bindIntEii
+__ZN7WebCore15SQLiteStatement8bindBlobEiPKvi
+__ZN7WebCore15SQLiteStatement9bindInt64Eix
 __ZN7WebCore15SQLiteStatement7prepareEv
 __ZN7WebCore15SQLiteStatement8bindBlobEiRKN3WTF6StringE
 __ZN7WebCore15SQLiteStatement8bindTextEiRKN3WTF6StringE
@@ -3071,5 +3075,6 @@ __ZN7WebCore10IDBKeyPathC1ERKN3WTF6VectorINS1_6StringELm0ENS1_15CrashOnOverflowE
 __ZN7WebCore18IDBDatabaseBackend14openConnectionEN3WTF10PassRefPtrINS_12IDBCallbacksEEENS2_INS_20IDBDatabaseCallbacksEEExy
 __ZN7WebCore18IDBDatabaseBackend6createERKN3WTF6StringES4_PNS_26IDBFactoryBackendInterfaceERNS_19IDBServerConnectionE
 __ZN7WebCore18IDBDatabaseBackendD1Ev
+__ZN7WebCore21CrossThreadCopierBaseILb0ELb0ENS_22IDBObjectStoreMetadataEE4copyERKS1_
 __ZN7WebCore21CrossThreadCopierBaseILb0ELb0ENS_9IndexedDB15TransactionModeEE4copyERKS2_
 #endif
index 65e3913..49d7fd2 100644 (file)
                51ABAE1B103C18FF008C5260 /* SocketStreamError.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ABAE1A103C18FF008C5260 /* SocketStreamError.h */; };
                51ABAE1E103C1913008C5260 /* SocketStreamHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ABAE1C103C1913008C5260 /* SocketStreamHandle.h */; };
                51ABAE1F103C1913008C5260 /* SocketStreamHandleCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ABAE1D103C1913008C5260 /* SocketStreamHandleCFNet.cpp */; };
+               51ABB5B8186D0ED1008391A1 /* IDBIndexMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ABB5B6186D0ED1008391A1 /* IDBIndexMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51ABB5B9186D0ED1008391A1 /* IDBObjectStoreMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ABB5B7186D0ED1008391A1 /* IDBObjectStoreMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51ABF64D16392E2800132A7A /* LoaderStrategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ABF64C16392E2800132A7A /* LoaderStrategy.cpp */; };
                51AF503616F100F60095B2E8 /* ResourceLoaderTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51B07A441823248B00AA8D1A /* IDBPendingDeleteCall.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B07A431823248B00AA8D1A /* IDBPendingDeleteCall.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51ABAE1A103C18FF008C5260 /* SocketStreamError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketStreamError.h; sourceTree = "<group>"; };
                51ABAE1C103C1913008C5260 /* SocketStreamHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketStreamHandle.h; sourceTree = "<group>"; };
                51ABAE1D103C1913008C5260 /* SocketStreamHandleCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SocketStreamHandleCFNet.cpp; sourceTree = "<group>"; };
+               51ABB5B6186D0ED1008391A1 /* IDBIndexMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBIndexMetadata.h; sourceTree = "<group>"; };
+               51ABB5B7186D0ED1008391A1 /* IDBObjectStoreMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBObjectStoreMetadata.h; sourceTree = "<group>"; };
                51ABF64C16392E2800132A7A /* LoaderStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoaderStrategy.cpp; sourceTree = "<group>"; };
                51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoaderTypes.h; sourceTree = "<group>"; };
                51B07A431823248B00AA8D1A /* IDBPendingDeleteCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBPendingDeleteCall.h; sourceTree = "<group>"; };
                                51D7198E181106E00016DC51 /* IDBIndex.cpp */,
                                51D7198F181106E00016DC51 /* IDBIndex.h */,
                                51D71990181106E00016DC51 /* IDBIndex.idl */,
+                               51ABB5B6186D0ED1008391A1 /* IDBIndexMetadata.h */,
                                51D71991181106E00016DC51 /* IDBKey.cpp */,
                                51D71992181106E00016DC51 /* IDBKey.h */,
                                51D71993181106E00016DC51 /* IDBKeyPath.cpp */,
                                51D71999181106E00016DC51 /* IDBObjectStore.cpp */,
                                51D7199A181106E00016DC51 /* IDBObjectStore.h */,
                                51D7199B181106E00016DC51 /* IDBObjectStore.idl */,
+                               51ABB5B7186D0ED1008391A1 /* IDBObjectStoreMetadata.h */,
                                51D7199C181106E00016DC51 /* IDBOpenDBRequest.cpp */,
                                51D7199D181106E00016DC51 /* IDBOpenDBRequest.h */,
                                51D7199E181106E00016DC51 /* IDBOpenDBRequest.idl */,
                                FC9A0F75164094CF003D6B8D /* DOMWindowCSS.h in Headers */,
                                51FA2D78152132B300C1BA0B /* DOMWindowExtension.h in Headers */,
                                97B38E27151C4271004622E9 /* DOMWindowNotifications.h in Headers */,
+                               51ABB5B9186D0ED1008391A1 /* IDBObjectStoreMetadata.h in Headers */,
                                97D2AD0414B823A60093DF32 /* DOMWindowProperty.h in Headers */,
                                0779BF0E18453168000B6AE7 /* HTMLMediaElementMediaStream.h in Headers */,
                                89F60B11157F686E0075E157 /* DOMWindowQuota.h in Headers */,
                                14CF78A609F58CD800EB3665 /* JSCSSValue.h in Headers */,
                                A8D05FAC0A23B30F005E7203 /* JSCSSValueList.h in Headers */,
                                E4778B80115A581A00B5D372 /* JSCustomEvent.h in Headers */,
+                               51ABB5B8186D0ED1008391A1 /* IDBIndexMetadata.h in Headers */,
                                E10B937C0B73C00A003ED890 /* JSCustomXPathNSResolver.h in Headers */,
                                073BE34117D17E01002BD431 /* JSNavigatorMediaStream.h in Headers */,
                                1AE82F900CAAFA9D002237AE /* JSDatabase.h in Headers */,
index 043ed0f..0aaea79 100644 (file)
@@ -93,6 +93,16 @@ CrossThreadCopierBase<false, false, IDBDatabaseMetadata>::Type CrossThreadCopier
     return metadata.isolatedCopy();
 }
 
+CrossThreadCopierBase<false, false, IDBIndexMetadata>::Type CrossThreadCopierBase<false, false, IDBIndexMetadata>::copy(const IDBIndexMetadata& metadata)
+{
+    return metadata.isolatedCopy();
+}
+
+CrossThreadCopierBase<false, false, IDBObjectStoreMetadata>::Type CrossThreadCopierBase<false, false, IDBObjectStoreMetadata>::copy(const IDBObjectStoreMetadata& metadata)
+{
+    return metadata.isolatedCopy();
+}
+
 #endif
 
 // Test CrossThreadCopier using COMPILE_ASSERT.
index 0fb069c..59d0ac2 100644 (file)
@@ -166,6 +166,18 @@ namespace WebCore {
         typedef IDBDatabaseMetadata Type;
         static Type copy(const IDBDatabaseMetadata&);
     };
+
+    struct IDBIndexMetadata;
+    template<> struct CrossThreadCopierBase<false, false, IDBIndexMetadata> {
+        typedef IDBIndexMetadata Type;
+        static Type copy(const IDBIndexMetadata&);
+    };
+
+    struct IDBObjectStoreMetadata;
+    template<> struct CrossThreadCopierBase<false, false, IDBObjectStoreMetadata> {
+        typedef IDBObjectStoreMetadata Type;
+        static Type copy(const IDBObjectStoreMetadata&);
+    };
 #endif
 
     template<typename T>
index 5e29199..c84a3f5 100644 (file)
@@ -1,3 +1,49 @@
+2014-01-14  Brady Eidson  <beidson@apple.com>
+
+        IDB: create object store support
+        <rdar://problem/15779639> and https://bugs.webkit.org/show_bug.cgi?id=127011
+
+        Reviewed by Anders Carlsson.
+
+        Add messaging/callback infrastructure for creating object stores:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
+        (WebKit::DatabaseProcessIDBConnection::createObjectStore):
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:
+
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
+        (WebKit::WebIDBServerConnection::createObjectStore):
+        (WebKit::WebIDBServerConnection::didCreateObjectStore):
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:
+
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::didChangeDatabaseVersion):
+        (WebKit::UniqueIDBDatabase::didCreateObjectStore):
+        (WebKit::UniqueIDBDatabase::didCompleteBoolRequest):
+        (WebKit::UniqueIDBDatabase::createObjectStore):
+        (WebKit::UniqueIDBDatabase::createObjectStoreInBackingStore):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
+
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
+
+        Add serialization helpers to save/restore an IDBKeyPath to/from disk:
+        * DatabaseProcess/IndexedDB/IDBSerialization.cpp:
+        (WebKit::serializeIDBKeyPath):
+        (WebKit::deserializeIDBKeyPath):
+        * DatabaseProcess/IndexedDB/IDBSerialization.h:
+
+        Add object store metadata to the schema, and save/restore the metadata:
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::extractExistingMetadata):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::createObjectStore):
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:
+
+        * Scripts/webkit2/messages.py:
+        (struct_or_class):
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2014-01-14  Jae Hyun Park  <jae.park@company100.net>
 
         [GTK] Unreviewed build fix after r162034
index dbd9e00..9699b65 100644 (file)
@@ -155,6 +155,17 @@ void DatabaseProcessIDBConnection::changeDatabaseVersion(uint64_t requestID, int
     });
 }
 
+void DatabaseProcessIDBConnection::createObjectStore(uint64_t requestID, int64_t transactionID, WebCore::IDBObjectStoreMetadata metadata)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    LOG(IDB, "DatabaseProcess createObjectStore request ID %llu, object store name '%s'", requestID, metadata.name.utf8().data());
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->createObjectStore(IDBTransactionIdentifier(*this, transactionID), metadata, [connection, requestID](bool success) {
+        connection->send(Messages::WebIDBServerConnection::DidCreateObjectStore(requestID, success));
+    });
+}
+
 IPC::Connection* DatabaseProcessIDBConnection::messageSenderConnection()
 {
     return m_connection->connection();
index 64754ec..8d37c6b 100644 (file)
@@ -69,7 +69,7 @@ private:
     void resetTransaction(uint64_t requestID, int64_t transactionID);
     void rollbackTransaction(uint64_t requestID, int64_t transactionID);
     void changeDatabaseVersion(uint64_t requestID, int64_t transactionID, uint64_t newVersion);
-
+    void createObjectStore(uint64_t requestID, int64_t transactionID, WebCore::IDBObjectStoreMetadata);
 
     Ref<DatabaseToWebProcessConnection> m_connection;
     uint64_t m_serverConnectionIdentifier;
index da6e524..63a200e 100644 (file)
@@ -33,6 +33,7 @@ messages -> DatabaseProcessIDBConnection LegacyReceiver {
     RollbackTransaction(uint64_t requestID, int64_t transactionID)
     
     ChangeDatabaseVersion(uint64_t requestID, int64_t transactionID, uint64_t newVersion)
+    CreateObjectStore(uint64_t requestID, int64_t transactionID, WebCore::IDBObjectStoreMetadata objectStoreMetadata)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp b/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.cpp
new file mode 100644 (file)
index 0000000..8c6ed10
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 "IDBSerialization.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "ArgumentEncoder.h"
+#include <WebCore/IDBKeyPath.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+std::unique_ptr<Vector<uint8_t>> serializeIDBKeyPath(const WebCore::IDBKeyPath&)
+{
+    // FIXME: Once we have a serialization solution appropriate for persistent storage to disk, use that here.
+
+    return nullptr;
+}
+
+std::unique_ptr<WebCore::IDBKeyPath> deserializeIDBKeyPath(const uint8_t*, size_t)
+{
+    // FIXME: Once we have a serialization solution appropriate for persistent storage to disk, use that here.
+
+    return nullptr;
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h b/Source/WebKit2/DatabaseProcess/IndexedDB/IDBSerialization.h
new file mode 100644 (file)
index 0000000..ff9ad06
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 IDBSerialization_h
+#define IDBSerialization_h
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include <wtf/Vector.h>
+
+namespace WebCore {
+class IDBKeyPath;
+}
+
+namespace WebKit {
+
+std::unique_ptr<Vector<uint8_t>> serializeIDBKeyPath(const WebCore::IDBKeyPath&);
+std::unique_ptr<WebCore::IDBKeyPath> deserializeIDBKeyPath(const uint8_t* buffer, size_t bufferSize);
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE)
+#endif // IDBSerialization_h
index ae16f9d..38c0db6 100644 (file)
@@ -313,12 +313,50 @@ void UniqueIDBDatabase::changeDatabaseVersion(const IDBTransactionIdentifier& id
 
 void UniqueIDBDatabase::didChangeDatabaseVersion(uint64_t requestID, bool success)
 {
+    didCompleteBoolRequest(requestID, success);
+}
+
+void UniqueIDBDatabase::didCreateObjectStore(uint64_t requestID, bool success)
+{
+    didCompleteBoolRequest(requestID, success);
+}
+
+void UniqueIDBDatabase::didCompleteBoolRequest(uint64_t requestID, bool success)
+{
     RefPtr<AsyncRequest> request = m_pendingDatabaseTasks.take(requestID);
     ASSERT(request);
 
     request->completeRequest(success);
 }
 
+void UniqueIDBDatabase::createObjectStore(const IDBTransactionIdentifier& identifier, const WebCore::IDBObjectStoreMetadata& metadata, std::function<void(bool)> successCallback)
+{
+    ASSERT(isMainThread());
+
+    if (!m_acceptingNewRequests) {
+        successCallback(false);
+        return;
+    }
+
+    ASSERT(!m_metadata->objectStores.contains(metadata.id));
+    m_metadata->objectStores.set(metadata.id, metadata);
+    int64_t addedObjectStoreID = metadata.id;
+
+    RefPtr<AsyncRequest> request = AsyncRequestImpl<bool>::create([this, addedObjectStoreID, successCallback](bool success) {
+        if (!success)
+            m_metadata->objectStores.remove(addedObjectStoreID);
+        successCallback(success);
+    }, [this, addedObjectStoreID, successCallback]() {
+        m_metadata->objectStores.remove(addedObjectStoreID);
+        successCallback(false);
+    });
+
+    uint64_t requestID = request->requestID();
+    m_pendingDatabaseTasks.add(requestID, request.release());
+
+    postDatabaseTask(createAsyncTask(*this, &UniqueIDBDatabase::createObjectStoreInBackingStore, requestID, identifier, metadata));
+}
+
 void UniqueIDBDatabase::openBackingStoreTransaction(const IDBTransactionIdentifier& identifier, const Vector<int64_t>& objectStoreIDs, WebCore::IndexedDB::TransactionMode mode)
 {
     ASSERT(!isMainThread());
@@ -379,6 +417,16 @@ void UniqueIDBDatabase::changeDatabaseVersionInBackingStore(uint64_t requestID,
     postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didChangeDatabaseVersion, requestID, success));
 }
 
+void UniqueIDBDatabase::createObjectStoreInBackingStore(uint64_t requestID, const IDBTransactionIdentifier& identifier, const IDBObjectStoreMetadata& metadata)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
+
+    bool success = m_backingStore->createObjectStore(identifier, metadata);
+
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didCreateObjectStore, requestID, success));
+}
+
 String UniqueIDBDatabase::absoluteDatabaseDirectory() const
 {
     ASSERT(isMainThread());
index a2a57cd..d679d11 100644 (file)
@@ -74,6 +74,7 @@ public:
     void rollbackTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
 
     void changeDatabaseVersion(const IDBTransactionIdentifier&, uint64_t newVersion, std::function<void(bool)> successCallback);
+    void createObjectStore(const IDBTransactionIdentifier&, const WebCore::IDBObjectStoreMetadata&, std::function<void(bool)> successCallback);
 
 private:
     UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
@@ -113,6 +114,7 @@ private:
     void rollbackBackingStoreTransaction(const IDBTransactionIdentifier&);
 
     void changeDatabaseVersionInBackingStore(uint64_t requestID, const IDBTransactionIdentifier&, uint64_t newVersion);
+    void createObjectStoreInBackingStore(uint64_t requestID, const IDBTransactionIdentifier&, const WebCore::IDBObjectStoreMetadata&);
 
     void shutdownBackingStore();
 
@@ -121,7 +123,9 @@ private:
     void didOpenBackingStoreAndReadMetadata(const WebCore::IDBDatabaseMetadata&, bool success);
     void didCompleteTransactionOperation(const IDBTransactionIdentifier&, bool success);
     void didChangeDatabaseVersion(uint64_t requestID, bool success);
+    void didCreateObjectStore(uint64_t requestID, bool success);
     void didShutdownBackingStore();
+    void didCompleteBoolRequest(uint64_t requestID, bool success);
 
     bool m_acceptingNewRequests;
 
index de0c661..25fa1f7 100644 (file)
@@ -33,6 +33,7 @@
 
 namespace WebCore {
 struct IDBDatabaseMetadata;
+struct IDBObjectStoreMetadata;
 }
 
 namespace WebKit {
@@ -52,6 +53,7 @@ public:
     virtual bool rollbackTransaction(const IDBTransactionIdentifier&) = 0;
 
     virtual bool changeDatabaseVersion(const IDBTransactionIdentifier&, uint64_t newVersion) = 0;
+    virtual bool createObjectStore(const IDBTransactionIdentifier&, const WebCore::IDBObjectStoreMetadata&) = 0;
 };
 
 } // namespace WebKit
index 1903758..8b217aa 100644 (file)
@@ -28,6 +28,8 @@
 
 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
 
+#include "ArgumentDecoder.h"
+#include "IDBSerialization.h"
 #include "SQLiteIDBTransaction.h"
 #include <WebCore/FileSystem.h>
 #include <WebCore/IDBDatabaseMetadata.h>
@@ -75,6 +77,18 @@ std::unique_ptr<WebCore::IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLit
         return nullptr;
     }
 
+    if (!m_sqliteDB->executeCommand("CREATE TABLE ObjectStoreInfo (id INTEGER PRIMARY KEY NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT FAIL, name TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT FAIL, keyPath BLOB NOT NULL ON CONFLICT FAIL, autoInc INTEGER NOT NULL ON CONFLICT FAIL, maxIndexID INTEGER NOT NULL ON CONFLICT FAIL);")) {
+        LOG_ERROR("Could not create ObjectStoreInfo table in database (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+        m_sqliteDB = nullptr;
+        return nullptr;
+    }
+
+    if (!m_sqliteDB->executeCommand("CREATE TABLE IndexInfo (id INTEGER PRIMARY KEY NOT NULL ON CONFLICT FAIL, name TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT FAIL, objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, keyPath BLOB NOT NULL ON CONFLICT FAIL, isUnique INTEGER NOT NULL ON CONFLICT FAIL, multiEntry INTEGER NOT NULL ON CONFLICT FAIL);")) {
+        LOG_ERROR("Could not create IndexInfo table in database (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+        m_sqliteDB = nullptr;
+        return nullptr;
+    }
+
     {
         SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO IDBDatabaseInfo VALUES ('MetadataVersion', ?);"));
         if (sql.prepare() != SQLResultOk
@@ -108,10 +122,17 @@ std::unique_ptr<WebCore::IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLit
         }
     }
 
+    if (!m_sqliteDB->executeCommand(ASCIILiteral("INSERT INTO IDBDatabaseInfo VALUES ('MaxObjectStoreID', 1);"))) {
+        LOG_ERROR("Could not insert default version into IDBDatabaseInfo table (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+        m_sqliteDB = nullptr;
+        return nullptr;
+    }
+
     // This initial metadata matches the default values we just put into the metadata database.
     auto metadata = std::make_unique<IDBDatabaseMetadata>();
     metadata->name = m_identifier.databaseName();
     metadata->version = 0;
+    metadata->maxObjectStoreId = 1;
 
     return metadata;
 }
@@ -154,7 +175,42 @@ std::unique_ptr<IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLite::extrac
         }
     }
 
-    // FIXME: Once we save ObjectStores and indexes we need to extract their metadata, also.
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("SELECT id, name, keyPath, autoInc, maxIndexID FROM ObjectStoreInfo;"));
+        if (sql.prepare() != SQLResultOk)
+            return nullptr;
+
+        int result = sql.step();
+        while (result == SQLResultRow) {
+            IDBObjectStoreMetadata metadata;
+            metadata.id = sql.getColumnInt64(0);
+            metadata.name = sql.getColumnText(1);
+
+            int keyPathSize;
+            const uint8_t* keyPathBuffer = static_cast<const uint8_t*>(sql.getColumnBlob(2, keyPathSize));
+
+            std::unique_ptr<IDBKeyPath> keyPath = deserializeIDBKeyPath(keyPathBuffer, keyPathSize);
+
+            if (!keyPath) {
+                LOG_ERROR("Unable to extract key path metadata from database");
+                return nullptr;
+            }
+
+            metadata.keyPath = *keyPath;
+            metadata.autoIncrement = sql.getColumnInt(3);
+            metadata.maxIndexId = sql.getColumnInt64(4);
+
+            result = sql.step();
+        }
+
+        if (result != SQLResultDone) {
+            LOG_ERROR("Error fetching object store metadata from database on disk");
+            return nullptr;
+        }
+    }
+
+    // FIXME: Once we save indexes we need to extract their metadata, also.
+
     return metadata;
 }
 
@@ -290,6 +346,43 @@ bool UniqueIDBDatabaseBackingStoreSQLite::changeDatabaseVersion(const IDBTransac
     return true;
 }
 
+bool UniqueIDBDatabaseBackingStoreSQLite::createObjectStore(const IDBTransactionIdentifier& identifier, const IDBObjectStoreMetadata& metadata)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB->isOpen());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction || !transaction->inProgress()) {
+        LOG_ERROR("Attempt to change database version with an establish, in-progress transaction");
+        return false;
+    }
+    if (transaction->mode() != IndexedDB::TransactionMode::VersionChange) {
+        LOG_ERROR("Attempt to change database version during a non version-change transaction");
+        return false;
+    }
+
+    std::unique_ptr<Vector<uint8_t>> keyPathBlob = serializeIDBKeyPath(metadata.keyPath);
+    if (!keyPathBlob) {
+        LOG_ERROR("Unable to serialize IDBKeyPath to save in database");
+        return false;
+    }
+
+    SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO ObjectStoreInfo VALUES (?, ?, ?, ?, ?);"));
+    if (sql.prepare() != SQLResultOk
+        || sql.bindInt64(1, metadata.id) != SQLResultOk
+        || sql.bindText(2, metadata.name) != SQLResultOk
+        || sql.bindBlob(3, keyPathBlob->data(), keyPathBlob->size()) != SQLResultOk
+        || sql.bindInt(4, metadata.autoIncrement) != SQLResultOk
+        || sql.bindInt64(5, metadata.maxIndexId) != SQLResultOk
+        || sql.step() != SQLResultDone) {
+        LOG_ERROR("Could not add object store '%s' to in ObjectStoreInfo table (%i) - %s", metadata.name.utf8().data(), m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+        return false;
+    }
+
+    return true;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
index b35677e..cd1198c 100644 (file)
@@ -61,6 +61,7 @@ public:
     virtual bool rollbackTransaction(const IDBTransactionIdentifier&) OVERRIDE;
 
     virtual bool changeDatabaseVersion(const IDBTransactionIdentifier&, uint64_t newVersion) OVERRIDE;
+    virtual bool createObjectStore(const IDBTransactionIdentifier&, const WebCore::IDBObjectStoreMetadata&) OVERRIDE;
 
 private:
     UniqueIDBDatabaseBackingStoreSQLite(const UniqueIDBDatabaseIdentifier&, const String& databaseDirectory);
index a4664ff..87864f5 100644 (file)
@@ -177,6 +177,7 @@ def struct_or_class(namespace, type):
         'WebCore::FileChooserSettings',
         'WebCore::GrammarDetail',
         'WebCore::IDBDatabaseMetadata',
+        'WebCore::IDBObjectStoreMetadata',
         'WebCore::IdentityTransformOperation',
         'WebCore::KeypressCommand',
         'WebCore::Length',
index ed22952..5c196dc 100644 (file)
                51829DA61637C70C000953D6 /* NetworkResourceLoadScheduler.h in Headers */ = {isa = PBXBuildFile; fileRef = 51829DA41637C70C000953D6 /* NetworkResourceLoadScheduler.h */; };
                51834592134532E90092B696 /* WebIconDatabaseClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51834590134532E80092B696 /* WebIconDatabaseClient.cpp */; };
                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 */; };
                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 */; };
                51829DA41637C70C000953D6 /* NetworkResourceLoadScheduler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkResourceLoadScheduler.h; path = NetworkProcess/NetworkResourceLoadScheduler.h; sourceTree = "<group>"; };
                51834590134532E80092B696 /* WebIconDatabaseClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebIconDatabaseClient.cpp; sourceTree = "<group>"; };
                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>"; };
                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>"; };
                                51D0D42E183B34130097041D /* DatabaseProcessIDBConnection.cpp */,
                                51D0D42F183B34130097041D /* DatabaseProcessIDBConnection.h */,
                                51D0D430183B34130097041D /* DatabaseProcessIDBConnection.messages.in */,
+                               518353D81885BF8C00D9FE44 /* IDBSerialization.cpp */,
+                               518353D91885BF8C00D9FE44 /* IDBSerialization.h */,
                                51D54A72185BAC42000CAED2 /* IDBTransactionIdentifier.h */,
                                515E772D184015800007203F /* UniqueIDBDatabase.cpp */,
                                515E772E184015800007203F /* UniqueIDBDatabase.h */,
                                31D5929F166E060000E6BF02 /* WebPlugInClient.h in Headers */,
                                1AC8702D130B49A2002C1257 /* WebPluginSiteDataManager.h in Headers */,
                                BCB9F8B01124E07700A137E0 /* WebPolicyClient.h in Headers */,
+                               518353DB1885BF8C00D9FE44 /* IDBSerialization.h in Headers */,
                                BC5744F012638FB3006F0F12 /* WebPopupItem.h in Headers */,
                                51D54A73185BAC42000CAED2 /* IDBTransactionIdentifier.h in Headers */,
                                D3B9484711FF4B6500032B39 /* WebPopupMenu.h in Headers */,
                                51DD9F2816367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp in Sources */,
                                51795568162876CF00FA43B6 /* NetworkProcess.cpp in Sources */,
                                5183DDEC1630BDFC008BE5C7 /* NetworkProcessConnection.cpp in Sources */,
+                               518353DA1885BF8C00D9FE44 /* IDBSerialization.cpp in Sources */,
                                517CF0E3163A486C00C2950E /* NetworkProcessConnectionMessageReceiver.cpp in Sources */,
                                51795570162877CF00FA43B6 /* NetworkProcessCreationParameters.cpp in Sources */,
                                51795567162876CB00FA43B6 /* NetworkProcessMac.mm in Sources */,
index 170e2b3..c92d3f2 100644 (file)
@@ -258,8 +258,34 @@ void WebIDBServerConnection::setIndexKeys(int64_t transactionID, int64_t databas
 {
 }
 
-void WebIDBServerConnection::createObjectStore(IDBTransactionBackend&, const CreateObjectStoreOperation&, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
+void WebIDBServerConnection::createObjectStore(IDBTransactionBackend& transaction, const CreateObjectStoreOperation& operation, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
 {
+    RefPtr<AsyncRequest> serverRequest = AsyncRequestImpl<PassRefPtr<IDBDatabaseError>>::create(completionCallback);
+
+    String objectStoreName = operation.objectStoreMetadata().name;
+    serverRequest->setAbortHandler([objectStoreName, completionCallback]() {
+        completionCallback(IDBDatabaseError::create(IDBDatabaseException::UnknownError, String::format("Unknown error occured creating object store '%s'", objectStoreName.utf8().data())));
+    });
+
+    uint64_t requestID = serverRequest->requestID();
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
+
+    LOG(IDB, "WebProcess createObjectStore '%s' in transaction ID %llu (request ID %llu)", operation.objectStoreMetadata().name.utf8().data(), transaction.id(), requestID);
+
+    send(Messages::DatabaseProcessIDBConnection::CreateObjectStore(requestID, transaction.id(), operation.objectStoreMetadata()));
+}
+
+void WebIDBServerConnection::didCreateObjectStore(uint64_t requestID, bool success)
+{
+    LOG(IDB, "WebProcess didCreateObjectStore request ID %llu", requestID);
+
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest(success ? nullptr : IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Unknown error occured creating object store"));
 }
 
 void WebIDBServerConnection::createIndex(IDBTransactionBackend&, const CreateIndexOperation&, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
index 5062564..35b6774 100644 (file)
@@ -100,6 +100,7 @@ private:
     void didResetTransaction(uint64_t requestID, bool success);
     void didRollbackTransaction(uint64_t requestID, bool success);
     void didChangeDatabaseVersion(uint64_t requestID, bool success);
+    void didCreateObjectStore(uint64_t requestID, bool success);
 
     uint64_t m_serverConnectionIdentifier;
 
index 41aaa19..42857ce 100644 (file)
@@ -32,6 +32,7 @@ messages -> WebIDBServerConnection LegacyReceiver {
     DidRollbackTransaction(uint64_t requestID, bool success)
 
     DidChangeDatabaseVersion(uint64_t requestID, bool success)
+    DidCreateObjectStore(uint64_t requestID, bool success)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)