summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/indexeddb/shared
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/indexeddb/shared')
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.cpp114
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h137
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBCursorRecord.h67
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp178
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.h111
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBError.cpp73
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBError.h87
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.cpp51
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h88
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.cpp49
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.h74
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.cpp70
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.h103
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.cpp47
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.h78
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp163
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.h115
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp160
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h175
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.cpp108
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h150
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp244
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBResultData.h231
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp121
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h130
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp451
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h131
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IndexKey.cpp89
-rw-r--r--Source/WebCore/Modules/indexeddb/shared/IndexKey.h54
29 files changed, 3649 insertions, 0 deletions
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.cpp
new file mode 100644
index 000000000..0d3e3388f
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2015 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 "IDBCursorInfo.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBDatabase.h"
+#include "IDBTransaction.h"
+#include "IndexedDB.h"
+
+namespace WebCore {
+
+IDBCursorInfo IDBCursorInfo::objectStoreCursor(IDBTransaction& transaction, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type)
+{
+ return { transaction, objectStoreIdentifier, range, direction, type };
+}
+
+IDBCursorInfo IDBCursorInfo::indexCursor(IDBTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type)
+{
+ return { transaction, objectStoreIdentifier, indexIdentifier, range, direction, type };
+}
+
+IDBCursorInfo::IDBCursorInfo()
+{
+}
+
+IDBCursorInfo::IDBCursorInfo(IDBTransaction& transaction, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type)
+ : m_cursorIdentifier(transaction.database().connectionProxy())
+ , m_transactionIdentifier(transaction.info().identifier())
+ , m_objectStoreIdentifier(objectStoreIdentifier)
+ , m_sourceIdentifier(objectStoreIdentifier)
+ , m_range(range)
+ , m_source(IndexedDB::CursorSource::ObjectStore)
+ , m_direction(direction)
+ , m_type(type)
+{
+}
+
+IDBCursorInfo::IDBCursorInfo(IDBTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type)
+ : m_cursorIdentifier(transaction.database().connectionProxy())
+ , m_transactionIdentifier(transaction.info().identifier())
+ , m_objectStoreIdentifier(objectStoreIdentifier)
+ , m_sourceIdentifier(indexIdentifier)
+ , m_range(range)
+ , m_source(IndexedDB::CursorSource::Index)
+ , m_direction(direction)
+ , m_type(type)
+{
+}
+
+IDBCursorInfo::IDBCursorInfo(const IDBResourceIdentifier& cursorIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t sourceIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorSource source, IndexedDB::CursorDirection direction, IndexedDB::CursorType type)
+ : m_cursorIdentifier(cursorIdentifier)
+ , m_transactionIdentifier(transactionIdentifier)
+ , m_objectStoreIdentifier(objectStoreIdentifier)
+ , m_sourceIdentifier(sourceIdentifier)
+ , m_range(range)
+ , m_source(source)
+ , m_direction(direction)
+ , m_type(type)
+{
+}
+
+bool IDBCursorInfo::isDirectionForward() const
+{
+ return m_direction == IndexedDB::CursorDirection::Next || m_direction == IndexedDB::CursorDirection::Nextunique;
+}
+
+CursorDuplicity IDBCursorInfo::duplicity() const
+{
+ return m_direction == IndexedDB::CursorDirection::Nextunique || m_direction == IndexedDB::CursorDirection::Prevunique ? CursorDuplicity::NoDuplicates : CursorDuplicity::Duplicates;
+}
+
+IDBCursorInfo IDBCursorInfo::isolatedCopy() const
+{
+ return { m_cursorIdentifier.isolatedCopy(), m_transactionIdentifier.isolatedCopy(), m_objectStoreIdentifier, m_sourceIdentifier, m_range.isolatedCopy(), m_source, m_direction, m_type };
+}
+
+#if !LOG_DISABLED
+String IDBCursorInfo::loggingString() const
+{
+ if (m_source == IndexedDB::CursorSource::Index)
+ return String::format("<Crsr: %s Idx %" PRIu64 ", OS %" PRIu64 ", tx %s>", m_cursorIdentifier.loggingString().utf8().data(), m_sourceIdentifier, m_objectStoreIdentifier, m_transactionIdentifier.loggingString().utf8().data());
+
+ return String::format("<Crsr: %s OS %" PRIu64 ", tx %s>", m_cursorIdentifier.loggingString().utf8().data(), m_objectStoreIdentifier, m_transactionIdentifier.loggingString().utf8().data());
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h b/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h
new file mode 100644
index 000000000..84b439be3
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyRangeData.h"
+#include "IDBResourceIdentifier.h"
+
+namespace WebCore {
+
+class IDBTransaction;
+
+namespace IndexedDB {
+enum class CursorDirection;
+enum class CursorSource;
+enum class CursorType;
+}
+
+struct IDBKeyRangeData;
+
+enum class CursorDuplicity {
+ Duplicates,
+ NoDuplicates,
+};
+
+class IDBCursorInfo {
+public:
+ static IDBCursorInfo objectStoreCursor(IDBTransaction&, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType);
+ static IDBCursorInfo indexCursor(IDBTransaction&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType);
+
+ IDBResourceIdentifier identifier() const { return m_cursorIdentifier; }
+ uint64_t sourceIdentifier() const { return m_sourceIdentifier; }
+ uint64_t objectStoreIdentifier() const { return m_objectStoreIdentifier; }
+
+ IndexedDB::CursorSource cursorSource() const { return m_source; }
+ IndexedDB::CursorDirection cursorDirection() const { return m_direction; }
+ IndexedDB::CursorType cursorType() const { return m_type; }
+ const IDBKeyRangeData& range() const { return m_range; }
+
+ bool isDirectionForward() const;
+ CursorDuplicity duplicity() const;
+
+ IDBCursorInfo isolatedCopy() const;
+
+ WEBCORE_EXPORT IDBCursorInfo();
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBCursorInfo&);
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+private:
+ IDBCursorInfo(IDBTransaction&, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType);
+ IDBCursorInfo(IDBTransaction&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType);
+
+ IDBCursorInfo(const IDBResourceIdentifier&, const IDBResourceIdentifier&, uint64_t, uint64_t, const IDBKeyRangeData&, IndexedDB::CursorSource, IndexedDB::CursorDirection, IndexedDB::CursorType);
+
+ IDBResourceIdentifier m_cursorIdentifier;
+ IDBResourceIdentifier m_transactionIdentifier;
+ uint64_t m_objectStoreIdentifier { 0 };
+ uint64_t m_sourceIdentifier { 0 };
+
+ IDBKeyRangeData m_range;
+
+ IndexedDB::CursorSource m_source;
+ IndexedDB::CursorDirection m_direction;
+ IndexedDB::CursorType m_type;
+};
+
+template<class Encoder>
+void IDBCursorInfo::encode(Encoder& encoder) const
+{
+ encoder << m_cursorIdentifier << m_transactionIdentifier << m_objectStoreIdentifier << m_sourceIdentifier << m_range;
+
+ encoder.encodeEnum(m_source);
+ encoder.encodeEnum(m_direction);
+ encoder.encodeEnum(m_type);
+}
+
+template<class Decoder>
+bool IDBCursorInfo::decode(Decoder& decoder, IDBCursorInfo& info)
+{
+ if (!decoder.decode(info.m_cursorIdentifier))
+ return false;
+
+ if (!decoder.decode(info.m_transactionIdentifier))
+ return false;
+
+ if (!decoder.decode(info.m_objectStoreIdentifier))
+ return false;
+
+ if (!decoder.decode(info.m_sourceIdentifier))
+ return false;
+
+ if (!decoder.decode(info.m_range))
+ return false;
+
+ if (!decoder.decodeEnum(info.m_source))
+ return false;
+
+ if (!decoder.decodeEnum(info.m_direction))
+ return false;
+
+ if (!decoder.decodeEnum(info.m_type))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBCursorRecord.h b/Source/WebCore/Modules/indexeddb/shared/IDBCursorRecord.h
new file mode 100644
index 000000000..b4f55fd66
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBCursorRecord.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyData.h"
+#include "IDBValue.h"
+
+namespace WebCore {
+
+struct IDBCursorRecord {
+ IDBKeyData key;
+ IDBKeyData primaryKey;
+ std::unique_ptr<IDBValue> value;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBCursorRecord&);
+};
+
+template<class Encoder>
+void IDBCursorRecord::encode(Encoder& encoder) const
+{
+ encoder << key << primaryKey << value;
+}
+
+template<class Decoder>
+bool IDBCursorRecord::decode(Decoder& decoder, IDBCursorRecord& record)
+{
+ if (!decoder.decode(record.key))
+ return false;
+
+ if (!decoder.decode(record.primaryKey))
+ return false;
+
+ if (!decoder.decode(record.value))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp
new file mode 100644
index 000000000..e5df15c44
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2015 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 "IDBDatabaseInfo.h"
+
+#include <wtf/text/StringBuilder.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+IDBDatabaseInfo::IDBDatabaseInfo()
+{
+}
+
+IDBDatabaseInfo::IDBDatabaseInfo(const String& name, uint64_t version)
+ : m_name(name)
+ , m_version(version)
+{
+}
+
+IDBDatabaseInfo::IDBDatabaseInfo(const IDBDatabaseInfo& other, IsolatedCopyTag)
+ : m_name(other.m_name.isolatedCopy())
+ , m_version(other.m_version)
+ , m_maxObjectStoreID(other.m_maxObjectStoreID)
+{
+ for (auto entry : other.m_objectStoreMap)
+ m_objectStoreMap.set(entry.key, entry.value.isolatedCopy());
+}
+
+IDBDatabaseInfo IDBDatabaseInfo::isolatedCopy() const
+{
+ return { *this, IDBDatabaseInfo::IsolatedCopy };
+}
+
+bool IDBDatabaseInfo::hasObjectStore(const String& name) const
+{
+ for (auto& objectStore : m_objectStoreMap.values()) {
+ if (objectStore.name() == name)
+ return true;
+ }
+
+ return false;
+}
+
+IDBObjectStoreInfo IDBDatabaseInfo::createNewObjectStore(const String& name, std::optional<IDBKeyPath>&& keyPath, bool autoIncrement)
+{
+ IDBObjectStoreInfo info(++m_maxObjectStoreID, name, WTFMove(keyPath), autoIncrement);
+ m_objectStoreMap.set(info.identifier(), info);
+ return info;
+}
+
+void IDBDatabaseInfo::addExistingObjectStore(const IDBObjectStoreInfo& info)
+{
+ ASSERT(!m_objectStoreMap.contains(info.identifier()));
+
+ if (info.identifier() > m_maxObjectStoreID)
+ m_maxObjectStoreID = info.identifier();
+
+ m_objectStoreMap.set(info.identifier(), info);
+}
+
+IDBObjectStoreInfo* IDBDatabaseInfo::getInfoForExistingObjectStore(uint64_t objectStoreIdentifier)
+{
+ auto iterator = m_objectStoreMap.find(objectStoreIdentifier);
+ if (iterator == m_objectStoreMap.end())
+ return nullptr;
+
+ return &iterator->value;
+}
+
+IDBObjectStoreInfo* IDBDatabaseInfo::getInfoForExistingObjectStore(const String& name)
+{
+ for (auto& objectStore : m_objectStoreMap.values()) {
+ if (objectStore.name() == name)
+ return &objectStore;
+ }
+
+ return nullptr;
+}
+
+const IDBObjectStoreInfo* IDBDatabaseInfo::infoForExistingObjectStore(uint64_t objectStoreIdentifier) const
+{
+ return const_cast<IDBDatabaseInfo*>(this)->getInfoForExistingObjectStore(objectStoreIdentifier);
+}
+
+IDBObjectStoreInfo* IDBDatabaseInfo::infoForExistingObjectStore(uint64_t objectStoreIdentifier)
+{
+ return getInfoForExistingObjectStore(objectStoreIdentifier);
+}
+
+const IDBObjectStoreInfo* IDBDatabaseInfo::infoForExistingObjectStore(const String& name) const
+{
+ return const_cast<IDBDatabaseInfo*>(this)->getInfoForExistingObjectStore(name);
+}
+
+IDBObjectStoreInfo* IDBDatabaseInfo::infoForExistingObjectStore(const String& name)
+{
+ return getInfoForExistingObjectStore(name);
+}
+
+void IDBDatabaseInfo::renameObjectStore(uint64_t objectStoreIdentifier, const String& newName)
+{
+ auto* info = infoForExistingObjectStore(objectStoreIdentifier);
+ if (!info)
+ return;
+
+ info->rename(newName);
+}
+
+Vector<String> IDBDatabaseInfo::objectStoreNames() const
+{
+ Vector<String> names;
+ names.reserveCapacity(m_objectStoreMap.size());
+ for (auto& objectStore : m_objectStoreMap.values())
+ names.uncheckedAppend(objectStore.name());
+
+ return names;
+}
+
+void IDBDatabaseInfo::deleteObjectStore(const String& objectStoreName)
+{
+ auto* info = infoForExistingObjectStore(objectStoreName);
+ if (!info)
+ return;
+
+ m_objectStoreMap.remove(info->identifier());
+}
+
+void IDBDatabaseInfo::deleteObjectStore(uint64_t objectStoreIdentifier)
+{
+ m_objectStoreMap.remove(objectStoreIdentifier);
+}
+
+#if !LOG_DISABLED
+String IDBDatabaseInfo::loggingString() const
+{
+ StringBuilder builder;
+ builder.appendLiteral("Database:");
+ builder.append(m_name);
+ builder.appendLiteral(" version ");
+ builder.appendNumber(m_version);
+ builder.append('\n');
+ for (auto objectStore : m_objectStoreMap.values()) {
+ builder.append(objectStore.loggingString(1));
+ builder.append('\n');
+ }
+
+ return builder.toString();
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.h b/Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.h
new file mode 100644
index 000000000..db8ff2c77
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBObjectStoreInfo.h"
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+class IDBDatabaseInfo {
+public:
+ IDBDatabaseInfo(const String& name, uint64_t version);
+
+ enum IsolatedCopyTag { IsolatedCopy };
+ IDBDatabaseInfo(const IDBDatabaseInfo&, IsolatedCopyTag);
+
+ IDBDatabaseInfo isolatedCopy() const;
+
+ const String& name() const { return m_name; }
+
+ void setVersion(uint64_t version) { m_version = version; }
+ uint64_t version() const { return m_version; }
+
+ bool hasObjectStore(const String& name) const;
+ IDBObjectStoreInfo createNewObjectStore(const String& name, std::optional<IDBKeyPath>&&, bool autoIncrement);
+ void addExistingObjectStore(const IDBObjectStoreInfo&);
+ IDBObjectStoreInfo* infoForExistingObjectStore(uint64_t objectStoreIdentifier);
+ IDBObjectStoreInfo* infoForExistingObjectStore(const String& objectStoreName);
+ const IDBObjectStoreInfo* infoForExistingObjectStore(uint64_t objectStoreIdentifier) const;
+ const IDBObjectStoreInfo* infoForExistingObjectStore(const String& objectStoreName) const;
+
+ void renameObjectStore(uint64_t objectStoreIdentifier, const String& newName);
+
+ Vector<String> objectStoreNames() const;
+
+ void deleteObjectStore(const String& objectStoreName);
+ void deleteObjectStore(uint64_t objectStoreIdentifier);
+
+ WEBCORE_EXPORT IDBDatabaseInfo();
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBDatabaseInfo&);
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+private:
+ IDBObjectStoreInfo* getInfoForExistingObjectStore(const String& objectStoreName);
+ IDBObjectStoreInfo* getInfoForExistingObjectStore(uint64_t objectStoreIdentifier);
+
+ String m_name;
+ uint64_t m_version { 0 };
+ uint64_t m_maxObjectStoreID { 0 };
+
+ HashMap<uint64_t, IDBObjectStoreInfo> m_objectStoreMap;
+
+};
+
+template<class Encoder>
+void IDBDatabaseInfo::encode(Encoder& encoder) const
+{
+ encoder << m_name << m_version << m_maxObjectStoreID << m_objectStoreMap;
+}
+
+template<class Decoder>
+bool IDBDatabaseInfo::decode(Decoder& decoder, IDBDatabaseInfo& info)
+{
+ if (!decoder.decode(info.m_name))
+ return false;
+
+ if (!decoder.decode(info.m_version))
+ return false;
+
+ if (!decoder.decode(info.m_maxObjectStoreID))
+ return false;
+
+ if (!decoder.decode(info.m_objectStoreMap))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBError.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBError.cpp
new file mode 100644
index 000000000..7da9486b1
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBError.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2015, 2016 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. ``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
+ * 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 "IDBError.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+IDBError::IDBError(ExceptionCode code)
+ : IDBError(code, emptyString())
+{
+}
+
+IDBError::IDBError(ExceptionCode code, const String& message)
+ : m_code(code)
+ , m_message(message)
+{
+}
+
+IDBError IDBError::isolatedCopy() const
+{
+ return { m_code, m_message.isolatedCopy() };
+}
+
+IDBError& IDBError::operator=(const IDBError& other)
+{
+ m_code = other.m_code;
+ m_message = other.m_message;
+ return *this;
+}
+
+String IDBError::name() const
+{
+ return IDBDatabaseException::getErrorName(m_code);
+}
+
+String IDBError::message() const
+{
+ return IDBDatabaseException::getErrorDescription(m_code);
+}
+
+RefPtr<DOMError> IDBError::toDOMError() const
+{
+ return DOMError::create(IDBDatabaseException::getErrorName(m_code), m_message);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBError.h b/Source/WebCore/Modules/indexeddb/shared/IDBError.h
new file mode 100644
index 000000000..bb5531bba
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBError.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2015, 2016 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. ``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
+ * 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "DOMError.h"
+#include "IDBDatabaseException.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class IDBError {
+public:
+ IDBError() { }
+ IDBError(ExceptionCode);
+ WEBCORE_EXPORT IDBError(ExceptionCode, const String& message);
+
+ static IDBError userDeleteError()
+ {
+ return { IDBDatabaseException::UnknownError, ASCIILiteral("Database deleted by request of the user") };
+ }
+
+ IDBError& operator=(const IDBError&);
+
+ RefPtr<DOMError> toDOMError() const;
+
+ ExceptionCode code() const { return m_code; }
+ String name() const;
+ String message() const;
+
+ bool isNull() const { return m_code == IDBDatabaseException::NoError; }
+
+ IDBError isolatedCopy() const;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBError&);
+
+private:
+ ExceptionCode m_code { IDBDatabaseException::NoError };
+ String m_message;
+};
+
+template<class Encoder>
+void IDBError::encode(Encoder& encoder) const
+{
+ encoder << m_code << m_message;
+}
+
+template<class Decoder>
+bool IDBError::decode(Decoder& decoder, IDBError& error)
+{
+ if (!decoder.decode(error.m_code))
+ return false;
+
+ if (!decoder.decode(error.m_message))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.cpp
new file mode 100644
index 000000000..92b6b923d
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 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 "IDBGetAllRecordsData.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyRangeData.h"
+
+namespace WebCore {
+
+IDBGetAllRecordsData IDBGetAllRecordsData::isolatedCopy() const
+{
+ return { keyRangeData.isolatedCopy(), getAllType, count, objectStoreIdentifier, indexIdentifier };
+}
+
+#if !LOG_DISABLED
+String IDBGetAllRecordsData::loggingString() const
+{
+ if (indexIdentifier)
+ return String::format("<GetAllRecords: Idx %" PRIu64 ", OS %" PRIu64 ", %s, range %s>", indexIdentifier, objectStoreIdentifier, getAllType == IndexedDB::GetAllType::Keys ? "Keys" : "Values", keyRangeData.loggingString().utf8().data());
+ return String::format("<GetAllRecords: OS %" PRIu64 ", %s, range %s>", objectStoreIdentifier, getAllType == IndexedDB::GetAllType::Keys ? "Keys" : "Values", keyRangeData.loggingString().utf8().data());
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h b/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h
new file mode 100644
index 000000000..e9b459800
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyRangeData.h"
+#include <wtf/Optional.h>
+
+namespace WebCore {
+
+namespace IndexedDB {
+enum class DataSource;
+enum class GetAllType;
+}
+
+struct IDBGetAllRecordsData {
+ IDBKeyRangeData keyRangeData;
+ IndexedDB::GetAllType getAllType;
+ std::optional<uint32_t> count;
+ uint64_t objectStoreIdentifier;
+ uint64_t indexIdentifier;
+
+ IDBGetAllRecordsData isolatedCopy() const;
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBGetAllRecordsData&);
+};
+
+template<class Encoder>
+void IDBGetAllRecordsData::encode(Encoder& encoder) const
+{
+ encoder << keyRangeData;
+ encoder.encodeEnum(getAllType);
+ encoder << count << objectStoreIdentifier << indexIdentifier;
+}
+
+template<class Decoder>
+bool IDBGetAllRecordsData::decode(Decoder& decoder, IDBGetAllRecordsData& getAllRecordsData)
+{
+ if (!decoder.decode(getAllRecordsData.keyRangeData))
+ return false;
+
+ if (!decoder.decodeEnum(getAllRecordsData.getAllType))
+ return false;
+
+ if (!decoder.decode(getAllRecordsData.count))
+ return false;
+
+ if (!decoder.decode(getAllRecordsData.objectStoreIdentifier))
+ return false;
+
+ if (!decoder.decode(getAllRecordsData.indexIdentifier))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.cpp
new file mode 100644
index 000000000..d78962604
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 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 "IDBGetRecordData.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyRangeData.h"
+
+namespace WebCore {
+
+IDBGetRecordData IDBGetRecordData::isolatedCopy() const
+{
+ return { keyRangeData.isolatedCopy(), type };
+}
+
+#if !LOG_DISABLED
+String IDBGetRecordData::loggingString() const
+{
+ return String::format("<GetRecord: %s %s>", type == IDBGetRecordDataType::KeyOnly ? "KeyOnly" : "Key+Value", keyRangeData.loggingString().utf8().data());
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.h b/Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.h
new file mode 100644
index 000000000..e82ab54e8
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyRangeData.h"
+
+namespace WebCore {
+
+enum class IDBGetRecordDataType {
+ KeyOnly,
+ KeyAndValue,
+};
+
+struct IDBGetRecordData {
+ IDBKeyRangeData keyRangeData;
+ IDBGetRecordDataType type;
+
+ IDBGetRecordData isolatedCopy() const;
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBGetRecordData&);
+};
+
+template<class Encoder>
+void IDBGetRecordData::encode(Encoder& encoder) const
+{
+ encoder << keyRangeData;
+ encoder.encodeEnum(type);
+}
+
+template<class Decoder>
+bool IDBGetRecordData::decode(Decoder& decoder, IDBGetRecordData& getRecordData)
+{
+ if (!decoder.decode(getRecordData.keyRangeData))
+ return false;
+
+ if (!decoder.decodeEnum(getRecordData.type))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.cpp
new file mode 100644
index 000000000..27290f4a4
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2015 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 "IDBIndexInfo.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+IDBIndexInfo::IDBIndexInfo()
+{
+}
+
+IDBIndexInfo::IDBIndexInfo(uint64_t identifier, uint64_t objectStoreIdentifier, const String& name, IDBKeyPath&& keyPath, bool unique, bool multiEntry)
+ : m_identifier(identifier)
+ , m_objectStoreIdentifier(objectStoreIdentifier)
+ , m_name(name)
+ , m_keyPath(WTFMove(keyPath))
+ , m_unique(unique)
+ , m_multiEntry(multiEntry)
+{
+}
+
+IDBIndexInfo IDBIndexInfo::isolatedCopy() const
+{
+ return { m_identifier, m_objectStoreIdentifier, m_name.isolatedCopy(), WebCore::isolatedCopy(m_keyPath), m_unique, m_multiEntry };
+}
+
+#if !LOG_DISABLED
+String IDBIndexInfo::loggingString(int indent) const
+{
+ String indentString;
+ for (int i = 0; i < indent; ++i)
+ indentString.append(" ");
+
+ return makeString(indentString, "Index: ", m_name, String::format(" (%" PRIu64 ") keyPath: %s\n", m_identifier, WebCore::loggingString(m_keyPath).utf8().data()));
+}
+
+String IDBIndexInfo::condensedLoggingString() const
+{
+ return String::format("<Idx: %s (%" PRIu64 "), OS (%" PRIu64 ")>", m_name.utf8().data(), m_identifier, m_objectStoreIdentifier);
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.h b/Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.h
new file mode 100644
index 000000000..1e3741792
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyPath.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class IDBIndexInfo {
+public:
+ WEBCORE_EXPORT IDBIndexInfo();
+ IDBIndexInfo(uint64_t identifier, uint64_t objectStoreIdentifier, const String& name, IDBKeyPath&&, bool unique, bool multiEntry);
+
+ IDBIndexInfo isolatedCopy() const;
+
+ uint64_t identifier() const { return m_identifier; }
+ uint64_t objectStoreIdentifier() const { return m_objectStoreIdentifier; }
+ const String& name() const { return m_name; }
+ const IDBKeyPath& keyPath() const { return m_keyPath; }
+ bool unique() const { return m_unique; }
+ bool multiEntry() const { return m_multiEntry; }
+
+ void rename(const String& newName) { m_name = newName; }
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBIndexInfo&);
+
+#if !LOG_DISABLED
+ String loggingString(int indent = 0) const;
+ String condensedLoggingString() const;
+#endif
+
+ // FIXME: Remove the need for this.
+ static const int64_t InvalidId = -1;
+
+private:
+ uint64_t m_identifier { 0 };
+ uint64_t m_objectStoreIdentifier { 0 };
+ String m_name;
+ IDBKeyPath m_keyPath;
+ bool m_unique { true };
+ bool m_multiEntry { false };
+};
+
+template<class Encoder>
+void IDBIndexInfo::encode(Encoder& encoder) const
+{
+ encoder << m_identifier << m_objectStoreIdentifier << m_name << m_keyPath << m_unique << m_multiEntry;
+}
+
+template<class Decoder>
+bool IDBIndexInfo::decode(Decoder& decoder, IDBIndexInfo& info)
+{
+ if (!decoder.decode(info.m_identifier))
+ return false;
+
+ if (!decoder.decode(info.m_objectStoreIdentifier))
+ return false;
+
+ if (!decoder.decode(info.m_name))
+ return false;
+
+ if (!decoder.decode(info.m_keyPath))
+ return false;
+
+ if (!decoder.decode(info.m_unique))
+ return false;
+
+ if (!decoder.decode(info.m_multiEntry))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.cpp
new file mode 100644
index 000000000..faaeda9fe
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2016 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 "IDBIterateCursorData.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+IDBIterateCursorData IDBIterateCursorData::isolatedCopy() const
+{
+ return { keyData.isolatedCopy(), primaryKeyData.isolatedCopy(), count };
+}
+
+#if !LOG_DISABLED
+String IDBIterateCursorData::loggingString() const
+{
+ return String::format("<Itr8Crsr: key %s, primaryKey %s, count %u>", keyData.loggingString().utf8().data(), primaryKeyData.loggingString().utf8().data(), count);
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.h b/Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.h
new file mode 100644
index 000000000..609f74876
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyData.h"
+
+namespace WebCore {
+
+struct IDBIterateCursorData {
+ IDBKeyData keyData;
+ IDBKeyData primaryKeyData;
+ unsigned count;
+
+ IDBIterateCursorData isolatedCopy() const;
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBIterateCursorData&);
+};
+
+template<class Encoder>
+void IDBIterateCursorData::encode(Encoder& encoder) const
+{
+ encoder << keyData << primaryKeyData << static_cast<uint64_t>(count);
+}
+
+template<class Decoder>
+bool IDBIterateCursorData::decode(Decoder& decoder, IDBIterateCursorData& iteratorCursorData)
+{
+ if (!decoder.decode(iteratorCursorData.keyData))
+ return false;
+
+ if (!decoder.decode(iteratorCursorData.primaryKeyData))
+ return false;
+
+ uint64_t count;
+ if (!decoder.decode(count))
+ return false;
+
+ if (count > std::numeric_limits<unsigned>::max())
+ return false;
+
+ iteratorCursorData.count = static_cast<unsigned>(count);
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp
new file mode 100644
index 000000000..b0075fe37
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2015 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 "IDBObjectStoreInfo.h"
+#include <wtf/text/StringBuilder.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+IDBObjectStoreInfo::IDBObjectStoreInfo()
+{
+}
+
+IDBObjectStoreInfo::IDBObjectStoreInfo(uint64_t identifier, const String& name, std::optional<IDBKeyPath>&& keyPath, bool autoIncrement)
+ : m_identifier(identifier)
+ , m_name(name)
+ , m_keyPath(WTFMove(keyPath))
+ , m_autoIncrement(autoIncrement)
+{
+}
+
+IDBIndexInfo IDBObjectStoreInfo::createNewIndex(const String& name, IDBKeyPath&& keyPath, bool unique, bool multiEntry)
+{
+ IDBIndexInfo info(++m_maxIndexID, m_identifier, name, WTFMove(keyPath), unique, multiEntry);
+ m_indexMap.set(info.identifier(), info);
+ return info;
+}
+
+void IDBObjectStoreInfo::addExistingIndex(const IDBIndexInfo& info)
+{
+ ASSERT(!m_indexMap.contains(info.identifier()));
+
+ if (info.identifier() > m_maxIndexID)
+ m_maxIndexID = info.identifier();
+
+ m_indexMap.set(info.identifier(), info);
+}
+
+bool IDBObjectStoreInfo::hasIndex(const String& name) const
+{
+ for (auto& index : m_indexMap.values()) {
+ if (index.name() == name)
+ return true;
+ }
+
+ return false;
+}
+
+bool IDBObjectStoreInfo::hasIndex(uint64_t indexIdentifier) const
+{
+ return m_indexMap.contains(indexIdentifier);
+}
+
+IDBIndexInfo* IDBObjectStoreInfo::infoForExistingIndex(const String& name)
+{
+ for (auto& index : m_indexMap.values()) {
+ if (index.name() == name)
+ return &index;
+ }
+
+ return nullptr;
+}
+
+IDBIndexInfo* IDBObjectStoreInfo::infoForExistingIndex(uint64_t identifier)
+{
+ auto iterator = m_indexMap.find(identifier);
+ if (iterator == m_indexMap.end())
+ return nullptr;
+
+ return &iterator->value;
+}
+
+IDBObjectStoreInfo IDBObjectStoreInfo::isolatedCopy() const
+{
+ IDBObjectStoreInfo result = { m_identifier, m_name.isolatedCopy(), WebCore::isolatedCopy(m_keyPath), m_autoIncrement };
+
+ for (auto& iterator : m_indexMap) {
+ result.m_indexMap.set(iterator.key, iterator.value.isolatedCopy());
+ if (iterator.key > result.m_maxIndexID)
+ result.m_maxIndexID = iterator.key;
+ }
+
+ ASSERT(result.m_maxIndexID == m_maxIndexID);
+
+ return result;
+}
+
+Vector<String> IDBObjectStoreInfo::indexNames() const
+{
+ Vector<String> names;
+ names.reserveCapacity(m_indexMap.size());
+ for (auto& index : m_indexMap.values())
+ names.uncheckedAppend(index.name());
+
+ return names;
+}
+
+void IDBObjectStoreInfo::deleteIndex(const String& indexName)
+{
+ auto* info = infoForExistingIndex(indexName);
+ if (!info)
+ return;
+
+ m_indexMap.remove(info->identifier());
+}
+
+void IDBObjectStoreInfo::deleteIndex(uint64_t indexIdentifier)
+{
+ m_indexMap.remove(indexIdentifier);
+}
+
+#if !LOG_DISABLED
+String IDBObjectStoreInfo::loggingString(int indent) const
+{
+ StringBuilder builder;
+ for (int i = 0; i < indent; ++i)
+ builder.append(' ');
+
+ builder.appendLiteral("Object store: ");
+ builder.append(m_name);
+ builder.appendNumber(m_identifier);
+ for (auto index : m_indexMap.values()) {
+ builder.append(index.loggingString(indent + 1));
+ builder.append('\n');
+ }
+
+ return builder.toString();
+}
+
+String IDBObjectStoreInfo::condensedLoggingString() const
+{
+ return String::format("<OS: %s (%" PRIu64 ")>", m_name.utf8().data(), m_identifier);
+}
+
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.h b/Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.h
new file mode 100644
index 000000000..0b8525909
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBIndexInfo.h"
+#include "IDBKeyPath.h"
+#include <wtf/HashMap.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class IDBObjectStoreInfo {
+public:
+ WEBCORE_EXPORT IDBObjectStoreInfo();
+ IDBObjectStoreInfo(uint64_t identifier, const String& name, std::optional<IDBKeyPath>&&, bool autoIncrement);
+
+ uint64_t identifier() const { return m_identifier; }
+ const String& name() const { return m_name; }
+ const std::optional<IDBKeyPath>& keyPath() const { return m_keyPath; }
+ bool autoIncrement() const { return m_autoIncrement; }
+ uint64_t maxIndexID() const { return m_maxIndexID; }
+
+ void rename(const String& newName) { m_name = newName; }
+
+ IDBObjectStoreInfo isolatedCopy() const;
+
+ IDBIndexInfo createNewIndex(const String& name, IDBKeyPath&&, bool unique, bool multiEntry);
+ void addExistingIndex(const IDBIndexInfo&);
+ bool hasIndex(const String& name) const;
+ bool hasIndex(uint64_t indexIdentifier) const;
+ IDBIndexInfo* infoForExistingIndex(const String& name);
+ IDBIndexInfo* infoForExistingIndex(uint64_t identifier);
+
+ Vector<String> indexNames() const;
+ const HashMap<uint64_t, IDBIndexInfo>& indexMap() const { return m_indexMap; }
+
+ void deleteIndex(const String& indexName);
+ void deleteIndex(uint64_t indexIdentifier);
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBObjectStoreInfo&);
+
+#if !LOG_DISABLED
+ String loggingString(int indent = 0) const;
+ String condensedLoggingString() const;
+#endif
+
+private:
+ uint64_t m_identifier { 0 };
+ String m_name;
+ std::optional<IDBKeyPath> m_keyPath;
+ bool m_autoIncrement { false };
+ uint64_t m_maxIndexID { 0 };
+
+ HashMap<uint64_t, IDBIndexInfo> m_indexMap;
+};
+
+template<class Encoder>
+void IDBObjectStoreInfo::encode(Encoder& encoder) const
+{
+ encoder << m_identifier << m_name << m_keyPath << m_autoIncrement << m_maxIndexID << m_indexMap;
+}
+
+template<class Decoder>
+bool IDBObjectStoreInfo::decode(Decoder& decoder, IDBObjectStoreInfo& info)
+{
+ if (!decoder.decode(info.m_identifier))
+ return false;
+
+ if (!decoder.decode(info.m_name))
+ return false;
+
+ if (!decoder.decode(info.m_keyPath))
+ return false;
+
+ if (!decoder.decode(info.m_autoIncrement))
+ return false;
+
+ if (!decoder.decode(info.m_maxIndexID))
+ return false;
+
+ if (!decoder.decode(info.m_indexMap))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp
new file mode 100644
index 000000000..574ea8b01
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2015 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 "IDBRequestData.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBConnectionToServer.h"
+#include "IDBDatabase.h"
+#include "IDBOpenDBRequest.h"
+
+namespace WebCore {
+
+IDBRequestData::IDBRequestData()
+{
+}
+
+IDBRequestData::IDBRequestData(const IDBClient::IDBConnectionProxy& connectionProxy, const IDBOpenDBRequest& request)
+ : m_serverConnectionIdentifier(connectionProxy.serverConnectionIdentifier())
+ , m_requestIdentifier(std::make_unique<IDBResourceIdentifier>(connectionProxy, request))
+ , m_databaseIdentifier(request.databaseIdentifier())
+ , m_requestedVersion(request.version())
+ , m_requestType(request.requestType())
+{
+}
+
+IDBRequestData::IDBRequestData(IDBClient::TransactionOperation& operation)
+ : m_serverConnectionIdentifier(operation.transaction().database().connectionProxy().serverConnectionIdentifier())
+ , m_requestIdentifier(std::make_unique<IDBResourceIdentifier>(operation.identifier()))
+ , m_transactionIdentifier(std::make_unique<IDBResourceIdentifier>(operation.transactionIdentifier()))
+ , m_objectStoreIdentifier(operation.objectStoreIdentifier())
+ , m_indexIdentifier(operation.indexIdentifier())
+{
+ if (m_indexIdentifier)
+ m_indexRecordType = operation.indexRecordType();
+
+ if (operation.cursorIdentifier())
+ m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(*operation.cursorIdentifier());
+}
+
+IDBRequestData::IDBRequestData(const IDBRequestData& other)
+ : m_serverConnectionIdentifier(other.m_serverConnectionIdentifier)
+ , m_objectStoreIdentifier(other.m_objectStoreIdentifier)
+ , m_indexIdentifier(other.m_indexIdentifier)
+ , m_indexRecordType(other.m_indexRecordType)
+ , m_databaseIdentifier(other.m_databaseIdentifier)
+ , m_requestedVersion(other.m_requestedVersion)
+ , m_requestType(other.m_requestType)
+{
+ if (other.m_requestIdentifier)
+ m_requestIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_requestIdentifier);
+ if (other.m_transactionIdentifier)
+ m_transactionIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_transactionIdentifier);
+ if (other.m_cursorIdentifier)
+ m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_cursorIdentifier);
+}
+
+IDBRequestData::IDBRequestData(const IDBRequestData& that, IsolatedCopyTag)
+{
+ isolatedCopy(that, *this);
+}
+
+
+IDBRequestData IDBRequestData::isolatedCopy() const
+{
+ return { *this, IsolatedCopy };
+}
+
+void IDBRequestData::isolatedCopy(const IDBRequestData& source, IDBRequestData& destination)
+{
+ destination.m_serverConnectionIdentifier = source.m_serverConnectionIdentifier;
+ destination.m_objectStoreIdentifier = source.m_objectStoreIdentifier;
+ destination.m_indexIdentifier = source.m_indexIdentifier;
+ destination.m_indexRecordType = source.m_indexRecordType;
+ destination.m_requestedVersion = source.m_requestedVersion;
+ destination.m_requestType = source.m_requestType;
+
+ destination.m_databaseIdentifier = source.m_databaseIdentifier.isolatedCopy();
+
+ if (source.m_requestIdentifier)
+ destination.m_requestIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_requestIdentifier);
+ if (source.m_transactionIdentifier)
+ destination.m_transactionIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_transactionIdentifier);
+ if (source.m_cursorIdentifier)
+ destination.m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_cursorIdentifier);
+}
+
+uint64_t IDBRequestData::serverConnectionIdentifier() const
+{
+ ASSERT(m_serverConnectionIdentifier);
+ return m_serverConnectionIdentifier;
+}
+
+IDBResourceIdentifier IDBRequestData::requestIdentifier() const
+{
+ ASSERT(m_requestIdentifier);
+ return *m_requestIdentifier;
+}
+
+IDBResourceIdentifier IDBRequestData::transactionIdentifier() const
+{
+ ASSERT(m_transactionIdentifier);
+ return *m_transactionIdentifier;
+}
+
+IDBResourceIdentifier IDBRequestData::cursorIdentifier() const
+{
+ ASSERT(m_cursorIdentifier);
+ return *m_cursorIdentifier;
+}
+
+uint64_t IDBRequestData::objectStoreIdentifier() const
+{
+ ASSERT(m_objectStoreIdentifier);
+ return m_objectStoreIdentifier;
+}
+
+uint64_t IDBRequestData::indexIdentifier() const
+{
+ ASSERT(m_objectStoreIdentifier || m_indexIdentifier);
+ return m_indexIdentifier;
+}
+
+IndexedDB::IndexRecordType IDBRequestData::indexRecordType() const
+{
+ ASSERT(m_indexIdentifier);
+ return m_indexRecordType;
+}
+
+uint64_t IDBRequestData::requestedVersion() const
+{
+ return m_requestedVersion;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h b/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h
new file mode 100644
index 000000000..8948bb909
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBDatabaseIdentifier.h"
+#include "IDBResourceIdentifier.h"
+#include "IndexedDB.h"
+
+namespace WebCore {
+
+class IDBOpenDBRequest;
+class IDBTransaction;
+
+namespace IndexedDB {
+enum class IndexRecordType;
+}
+
+namespace IDBClient {
+class IDBConnectionProxy;
+class TransactionOperation;
+}
+
+class IDBRequestData {
+public:
+ IDBRequestData(const IDBClient::IDBConnectionProxy&, const IDBOpenDBRequest&);
+ explicit IDBRequestData(IDBClient::TransactionOperation&);
+ IDBRequestData(const IDBRequestData&);
+
+ enum IsolatedCopyTag { IsolatedCopy };
+ IDBRequestData(const IDBRequestData&, IsolatedCopyTag);
+ IDBRequestData isolatedCopy() const;
+
+ uint64_t serverConnectionIdentifier() const;
+ IDBResourceIdentifier requestIdentifier() const;
+ IDBResourceIdentifier transactionIdentifier() const;
+ uint64_t objectStoreIdentifier() const;
+ uint64_t indexIdentifier() const;
+ IndexedDB::IndexRecordType indexRecordType() const;
+ IDBResourceIdentifier cursorIdentifier() const;
+
+ const IDBDatabaseIdentifier& databaseIdentifier() const { return m_databaseIdentifier; }
+ uint64_t requestedVersion() const;
+
+ bool isOpenRequest() const { return m_requestType == IndexedDB::RequestType::Open; }
+ bool isDeleteRequest() const { return m_requestType == IndexedDB::RequestType::Delete; }
+
+ IDBRequestData isolatedCopy();
+
+ WEBCORE_EXPORT IDBRequestData();
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBRequestData&);
+
+private:
+ static void isolatedCopy(const IDBRequestData& source, IDBRequestData& destination);
+
+ uint64_t m_serverConnectionIdentifier { 0 };
+ std::unique_ptr<IDBResourceIdentifier> m_requestIdentifier;
+ std::unique_ptr<IDBResourceIdentifier> m_transactionIdentifier;
+ std::unique_ptr<IDBResourceIdentifier> m_cursorIdentifier;
+ uint64_t m_objectStoreIdentifier { 0 };
+ uint64_t m_indexIdentifier { 0 };
+ IndexedDB::IndexRecordType m_indexRecordType;
+
+ IDBDatabaseIdentifier m_databaseIdentifier;
+ uint64_t m_requestedVersion { 0 };
+
+ IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
+};
+
+template<class Encoder>
+void IDBRequestData::encode(Encoder& encoder) const
+{
+ encoder << m_serverConnectionIdentifier << m_objectStoreIdentifier << m_indexIdentifier << m_databaseIdentifier << m_requestedVersion;
+
+ encoder.encodeEnum(m_indexRecordType);
+ encoder.encodeEnum(m_requestType);
+
+ encoder << !!m_requestIdentifier;
+ if (m_requestIdentifier)
+ encoder << *m_requestIdentifier;
+
+ encoder << !!m_transactionIdentifier;
+ if (m_transactionIdentifier)
+ encoder << *m_transactionIdentifier;
+
+ encoder << !!m_cursorIdentifier;
+ if (m_cursorIdentifier)
+ encoder << *m_cursorIdentifier;
+}
+
+template<class Decoder>
+bool IDBRequestData::decode(Decoder& decoder, IDBRequestData& request)
+{
+ if (!decoder.decode(request.m_serverConnectionIdentifier))
+ return false;
+
+ if (!decoder.decode(request.m_objectStoreIdentifier))
+ return false;
+
+ if (!decoder.decode(request.m_indexIdentifier))
+ return false;
+
+ if (!decoder.decode(request.m_databaseIdentifier))
+ return false;
+
+ if (!decoder.decode(request.m_requestedVersion))
+ return false;
+
+ if (!decoder.decodeEnum(request.m_indexRecordType))
+ return false;
+
+ if (!decoder.decodeEnum(request.m_requestType))
+ return false;
+
+ bool hasObject;
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ std::unique_ptr<IDBResourceIdentifier> object = std::make_unique<IDBResourceIdentifier>();
+ if (!decoder.decode(*object))
+ return false;
+ request.m_requestIdentifier = WTFMove(object);
+ }
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ std::unique_ptr<IDBResourceIdentifier> object = std::make_unique<IDBResourceIdentifier>();
+ if (!decoder.decode(*object))
+ return false;
+ request.m_transactionIdentifier = WTFMove(object);
+ }
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ std::unique_ptr<IDBResourceIdentifier> object = std::make_unique<IDBResourceIdentifier>();
+ if (!decoder.decode(*object))
+ return false;
+ request.m_cursorIdentifier = WTFMove(object);
+ }
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.cpp
new file mode 100644
index 000000000..d7e3f1742
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2015 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 "IDBResourceIdentifier.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBConnectionToClient.h"
+#include "IDBConnectionToServer.h"
+#include "IDBRequest.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+static uint64_t nextClientResourceNumber()
+{
+ static std::atomic<uint64_t> currentNumber(1);
+ return currentNumber += 2;
+}
+
+static uint64_t nextServerResourceNumber()
+{
+ ASSERT(isMainThread());
+ static uint64_t currentNumber = 0;
+ return currentNumber += 2;
+}
+
+IDBResourceIdentifier::IDBResourceIdentifier()
+{
+}
+
+IDBResourceIdentifier::IDBResourceIdentifier(uint64_t connectionIdentifier, uint64_t resourceIdentifier)
+ : m_idbConnectionIdentifier(connectionIdentifier)
+ , m_resourceNumber(resourceIdentifier)
+{
+}
+
+IDBResourceIdentifier::IDBResourceIdentifier(const IDBClient::IDBConnectionProxy& connectionProxy)
+ : m_idbConnectionIdentifier(connectionProxy.serverConnectionIdentifier())
+ , m_resourceNumber(nextClientResourceNumber())
+{
+}
+
+IDBResourceIdentifier::IDBResourceIdentifier(const IDBClient::IDBConnectionProxy& connectionProxy, const IDBRequest& request)
+ : m_idbConnectionIdentifier(connectionProxy.serverConnectionIdentifier())
+ , m_resourceNumber(request.resourceIdentifier().m_resourceNumber)
+{
+}
+
+IDBResourceIdentifier::IDBResourceIdentifier(const IDBServer::IDBConnectionToClient& connection)
+ : m_idbConnectionIdentifier(connection.identifier())
+ , m_resourceNumber(nextServerResourceNumber())
+{
+}
+
+IDBResourceIdentifier IDBResourceIdentifier::isolatedCopy() const
+{
+ return IDBResourceIdentifier(m_idbConnectionIdentifier, m_resourceNumber);
+}
+
+IDBResourceIdentifier IDBResourceIdentifier::emptyValue()
+{
+ return IDBResourceIdentifier(0, 0);
+}
+
+IDBResourceIdentifier IDBResourceIdentifier::deletedValue()
+{
+ return IDBResourceIdentifier(std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::max());
+}
+
+bool IDBResourceIdentifier::isHashTableDeletedValue() const
+{
+ return m_idbConnectionIdentifier == std::numeric_limits<uint64_t>::max()
+ && m_resourceNumber == std::numeric_limits<uint64_t>::max();
+}
+
+#if !LOG_DISABLED
+String IDBResourceIdentifier::loggingString() const
+{
+ return String::format("<%" PRIu64", %" PRIu64">", m_idbConnectionIdentifier, m_resourceNumber);
+}
+#endif
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h b/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h
new file mode 100644
index 000000000..91d7810cc
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2015, 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+class IDBRequest;
+
+namespace IDBClient {
+class IDBConnectionProxy;
+}
+
+namespace IDBServer {
+class IDBConnectionToClient;
+}
+
+class IDBResourceIdentifier {
+public:
+ explicit IDBResourceIdentifier(const IDBClient::IDBConnectionProxy&);
+ IDBResourceIdentifier(const IDBClient::IDBConnectionProxy&, const IDBRequest&);
+ explicit IDBResourceIdentifier(const IDBServer::IDBConnectionToClient&);
+
+ static IDBResourceIdentifier deletedValue();
+ WEBCORE_EXPORT bool isHashTableDeletedValue() const;
+
+ static IDBResourceIdentifier emptyValue();
+ bool isEmpty() const
+ {
+ return !m_resourceNumber && !m_idbConnectionIdentifier;
+ }
+
+ unsigned hash() const
+ {
+ uint64_t hashCodes[2] = { m_idbConnectionIdentifier, m_resourceNumber };
+ return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+ }
+
+ bool operator==(const IDBResourceIdentifier& other) const
+ {
+ return m_idbConnectionIdentifier == other.m_idbConnectionIdentifier
+ && m_resourceNumber == other.m_resourceNumber;
+ }
+
+ uint64_t connectionIdentifier() const { return m_idbConnectionIdentifier; }
+
+ IDBResourceIdentifier isolatedCopy() const;
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+ WEBCORE_EXPORT IDBResourceIdentifier();
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBResourceIdentifier&);
+
+private:
+ IDBResourceIdentifier(uint64_t connectionIdentifier, uint64_t resourceIdentifier);
+ uint64_t m_idbConnectionIdentifier { 0 };
+ uint64_t m_resourceNumber { 0 };
+};
+
+struct IDBResourceIdentifierHash {
+ static unsigned hash(const IDBResourceIdentifier& a) { return a.hash(); }
+ static bool equal(const IDBResourceIdentifier& a, const IDBResourceIdentifier& b) { return a == b; }
+ static const bool safeToCompareToEmptyOrDeleted = false;
+};
+
+struct IDBResourceIdentifierHashTraits : WTF::CustomHashTraits<IDBResourceIdentifier> {
+ static const bool hasIsEmptyValueFunction = true;
+ static const bool emptyValueIsZero = false;
+
+ static IDBResourceIdentifier emptyValue()
+ {
+ return IDBResourceIdentifier::emptyValue();
+ }
+
+ static bool isEmptyValue(const IDBResourceIdentifier& identifier)
+ {
+ return identifier.isEmpty();
+ }
+
+ static void constructDeletedValue(IDBResourceIdentifier& identifier)
+ {
+ identifier = IDBResourceIdentifier::deletedValue();
+ }
+
+ static bool isDeletedValue(const IDBResourceIdentifier& identifier)
+ {
+ return identifier.isHashTableDeletedValue();
+ }
+};
+
+template<class Encoder>
+void IDBResourceIdentifier::encode(Encoder& encoder) const
+{
+ encoder << m_idbConnectionIdentifier << m_resourceNumber;
+}
+
+template<class Decoder>
+bool IDBResourceIdentifier::decode(Decoder& decoder, IDBResourceIdentifier& identifier)
+{
+ if (!decoder.decode(identifier.m_idbConnectionIdentifier))
+ return false;
+
+ if (!decoder.decode(identifier.m_resourceNumber))
+ return false;
+
+ return true;
+}
+
+} // namespace WebCore
+
+namespace WTF {
+
+template<> struct HashTraits<WebCore::IDBResourceIdentifier> : WebCore::IDBResourceIdentifierHashTraits { };
+template<> struct DefaultHash<WebCore::IDBResourceIdentifier> {
+ typedef WebCore::IDBResourceIdentifierHash Hash;
+};
+
+} // namespace WTF
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
new file mode 100644
index 000000000..6c6ae6ba0
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2015 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 "IDBResultData.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "UniqueIDBDatabase.h"
+#include "UniqueIDBDatabaseConnection.h"
+#include "UniqueIDBDatabaseTransaction.h"
+
+namespace WebCore {
+
+IDBResultData::IDBResultData()
+{
+}
+
+IDBResultData::IDBResultData(const IDBResourceIdentifier& requestIdentifier)
+ : m_requestIdentifier(requestIdentifier)
+{
+}
+
+IDBResultData::IDBResultData(IDBResultType type, const IDBResourceIdentifier& requestIdentifier)
+ : m_type(type)
+ , m_requestIdentifier(requestIdentifier)
+{
+}
+
+IDBResultData::IDBResultData(const IDBResultData& other)
+ : m_type(other.m_type)
+ , m_requestIdentifier(other.m_requestIdentifier)
+ , m_error(other.m_error)
+ , m_databaseConnectionIdentifier(other.m_databaseConnectionIdentifier)
+ , m_resultInteger(other.m_resultInteger)
+{
+ if (other.m_databaseInfo)
+ m_databaseInfo = std::make_unique<IDBDatabaseInfo>(*other.m_databaseInfo);
+ if (other.m_transactionInfo)
+ m_transactionInfo = std::make_unique<IDBTransactionInfo>(*other.m_transactionInfo);
+ if (other.m_resultKey)
+ m_resultKey = std::make_unique<IDBKeyData>(*other.m_resultKey);
+ if (other.m_getResult)
+ m_getResult = std::make_unique<IDBGetResult>(*other.m_getResult);
+ if (other.m_getAllResult)
+ m_getAllResult = std::make_unique<IDBGetAllResult>(*other.m_getAllResult);
+}
+
+IDBResultData::IDBResultData(const IDBResultData& that, IsolatedCopyTag)
+{
+ isolatedCopy(that, *this);
+}
+
+IDBResultData IDBResultData::isolatedCopy() const
+{
+ return { *this, IsolatedCopy };
+}
+
+void IDBResultData::isolatedCopy(const IDBResultData& source, IDBResultData& destination)
+{
+ destination.m_type = source.m_type;
+ destination.m_requestIdentifier = source.m_requestIdentifier.isolatedCopy();
+ destination.m_error = source.m_error.isolatedCopy();
+ destination.m_databaseConnectionIdentifier = source.m_databaseConnectionIdentifier;
+ destination.m_resultInteger = source.m_resultInteger;
+
+ if (source.m_databaseInfo)
+ destination.m_databaseInfo = std::make_unique<IDBDatabaseInfo>(*source.m_databaseInfo, IDBDatabaseInfo::IsolatedCopy);
+ if (source.m_transactionInfo)
+ destination.m_transactionInfo = std::make_unique<IDBTransactionInfo>(*source.m_transactionInfo, IDBTransactionInfo::IsolatedCopy);
+ if (source.m_resultKey)
+ destination.m_resultKey = std::make_unique<IDBKeyData>(*source.m_resultKey, IDBKeyData::IsolatedCopy);
+ if (source.m_getResult)
+ destination.m_getResult = std::make_unique<IDBGetResult>(*source.m_getResult, IDBGetResult::IsolatedCopy);
+ if (source.m_getAllResult)
+ destination.m_getAllResult = std::make_unique<IDBGetAllResult>(*source.m_getAllResult, IDBGetAllResult::IsolatedCopy);
+}
+
+IDBResultData IDBResultData::error(const IDBResourceIdentifier& requestIdentifier, const IDBError& error)
+{
+ IDBResultData result { requestIdentifier };
+ result.m_type = IDBResultType::Error;
+ result.m_error = error;
+ return result;
+}
+
+IDBResultData IDBResultData::openDatabaseSuccess(const IDBResourceIdentifier& requestIdentifier, IDBServer::UniqueIDBDatabaseConnection& connection)
+{
+ IDBResultData result { requestIdentifier };
+ result.m_type = IDBResultType::OpenDatabaseSuccess;
+ result.m_databaseConnectionIdentifier = connection.identifier();
+ result.m_databaseInfo = std::make_unique<IDBDatabaseInfo>(connection.database().info());
+ return result;
+}
+
+
+IDBResultData IDBResultData::openDatabaseUpgradeNeeded(const IDBResourceIdentifier& requestIdentifier, IDBServer::UniqueIDBDatabaseTransaction& transaction)
+{
+ IDBResultData result { requestIdentifier };
+ result.m_type = IDBResultType::OpenDatabaseUpgradeNeeded;
+ result.m_databaseConnectionIdentifier = transaction.databaseConnection().identifier();
+ result.m_databaseInfo = std::make_unique<IDBDatabaseInfo>(transaction.databaseConnection().database().info());
+ result.m_transactionInfo = std::make_unique<IDBTransactionInfo>(transaction.info());
+ return result;
+}
+
+IDBResultData IDBResultData::deleteDatabaseSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBDatabaseInfo& info)
+{
+ IDBResultData result {IDBResultType::DeleteDatabaseSuccess, requestIdentifier };
+ result.m_databaseInfo = std::make_unique<IDBDatabaseInfo>(info);
+ return result;
+}
+
+IDBResultData IDBResultData::createObjectStoreSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::CreateObjectStoreSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::deleteObjectStoreSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::DeleteObjectStoreSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::renameObjectStoreSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::RenameObjectStoreSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::clearObjectStoreSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::ClearObjectStoreSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::createIndexSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::CreateIndexSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::deleteIndexSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::DeleteIndexSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::renameIndexSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::RenameIndexSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::putOrAddSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBKeyData& resultKey)
+{
+ IDBResultData result { IDBResultType::PutOrAddSuccess, requestIdentifier };
+ result.m_resultKey = std::make_unique<IDBKeyData>(resultKey);
+ return result;
+}
+
+IDBResultData IDBResultData::getRecordSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBGetResult& getResult)
+{
+ IDBResultData result { IDBResultType::GetRecordSuccess, requestIdentifier };
+ result.m_getResult = std::make_unique<IDBGetResult>(getResult);
+ return result;
+}
+
+IDBResultData IDBResultData::getAllRecordsSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBGetAllResult& getAllResult)
+{
+ IDBResultData result { IDBResultType::GetAllRecordsSuccess, requestIdentifier };
+ result.m_getAllResult = std::make_unique<IDBGetAllResult>(getAllResult);
+ return result;
+}
+
+IDBResultData IDBResultData::getCountSuccess(const IDBResourceIdentifier& requestIdentifier, uint64_t count)
+{
+ IDBResultData result { IDBResultType::GetRecordSuccess, requestIdentifier };
+ result.m_resultInteger = count;
+ return result;
+}
+
+IDBResultData IDBResultData::deleteRecordSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+ return { IDBResultType::DeleteRecordSuccess, requestIdentifier };
+}
+
+IDBResultData IDBResultData::openCursorSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBGetResult& getResult)
+{
+ IDBResultData result { IDBResultType::OpenCursorSuccess, requestIdentifier };
+ result.m_getResult = std::make_unique<IDBGetResult>(getResult);
+ return result;
+}
+
+IDBResultData IDBResultData::iterateCursorSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBGetResult& getResult)
+{
+ IDBResultData result { IDBResultType::IterateCursorSuccess, requestIdentifier };
+ result.m_getResult = std::make_unique<IDBGetResult>(getResult);
+ return result;
+}
+
+const IDBDatabaseInfo& IDBResultData::databaseInfo() const
+{
+ RELEASE_ASSERT(m_databaseInfo);
+ return *m_databaseInfo;
+}
+
+const IDBTransactionInfo& IDBResultData::transactionInfo() const
+{
+ RELEASE_ASSERT(m_transactionInfo);
+ return *m_transactionInfo;
+}
+
+const IDBGetResult& IDBResultData::getResult() const
+{
+ RELEASE_ASSERT(m_getResult);
+ return *m_getResult;
+}
+
+const IDBGetAllResult& IDBResultData::getAllResult() const
+{
+ RELEASE_ASSERT(m_getAllResult);
+ return *m_getAllResult;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
new file mode 100644
index 000000000..217c9a3ca
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBDatabaseInfo.h"
+#include "IDBError.h"
+#include "IDBGetAllResult.h"
+#include "IDBGetResult.h"
+#include "IDBKeyData.h"
+#include "IDBResourceIdentifier.h"
+#include "IDBTransactionInfo.h"
+#include "ThreadSafeDataBuffer.h"
+
+namespace WebCore {
+
+class ThreadSafeDataBuffer;
+
+enum class IDBResultType {
+ Error,
+ OpenDatabaseSuccess,
+ OpenDatabaseUpgradeNeeded,
+ DeleteDatabaseSuccess,
+ CreateObjectStoreSuccess,
+ DeleteObjectStoreSuccess,
+ ClearObjectStoreSuccess,
+ PutOrAddSuccess,
+ GetRecordSuccess,
+ GetAllRecordsSuccess,
+ GetCountSuccess,
+ DeleteRecordSuccess,
+ CreateIndexSuccess,
+ DeleteIndexSuccess,
+ OpenCursorSuccess,
+ IterateCursorSuccess,
+ RenameObjectStoreSuccess,
+ RenameIndexSuccess,
+};
+
+namespace IDBServer {
+class UniqueIDBDatabaseConnection;
+class UniqueIDBDatabaseTransaction;
+}
+
+class IDBResultData {
+public:
+ static IDBResultData error(const IDBResourceIdentifier&, const IDBError&);
+ static IDBResultData openDatabaseSuccess(const IDBResourceIdentifier&, IDBServer::UniqueIDBDatabaseConnection&);
+ static IDBResultData openDatabaseUpgradeNeeded(const IDBResourceIdentifier&, IDBServer::UniqueIDBDatabaseTransaction&);
+ static IDBResultData deleteDatabaseSuccess(const IDBResourceIdentifier&, const IDBDatabaseInfo&);
+ static IDBResultData createObjectStoreSuccess(const IDBResourceIdentifier&);
+ static IDBResultData deleteObjectStoreSuccess(const IDBResourceIdentifier&);
+ static IDBResultData renameObjectStoreSuccess(const IDBResourceIdentifier&);
+ static IDBResultData clearObjectStoreSuccess(const IDBResourceIdentifier&);
+ static IDBResultData createIndexSuccess(const IDBResourceIdentifier&);
+ static IDBResultData deleteIndexSuccess(const IDBResourceIdentifier&);
+ static IDBResultData renameIndexSuccess(const IDBResourceIdentifier&);
+ static IDBResultData putOrAddSuccess(const IDBResourceIdentifier&, const IDBKeyData&);
+ static IDBResultData getRecordSuccess(const IDBResourceIdentifier&, const IDBGetResult&);
+ static IDBResultData getAllRecordsSuccess(const IDBResourceIdentifier&, const IDBGetAllResult&);
+ static IDBResultData getCountSuccess(const IDBResourceIdentifier&, uint64_t count);
+ static IDBResultData deleteRecordSuccess(const IDBResourceIdentifier&);
+ static IDBResultData openCursorSuccess(const IDBResourceIdentifier&, const IDBGetResult&);
+ static IDBResultData iterateCursorSuccess(const IDBResourceIdentifier&, const IDBGetResult&);
+
+ WEBCORE_EXPORT IDBResultData(const IDBResultData&);
+
+ enum IsolatedCopyTag { IsolatedCopy };
+ IDBResultData(const IDBResultData&, IsolatedCopyTag);
+ IDBResultData isolatedCopy() const;
+
+ IDBResultType type() const { return m_type; }
+ IDBResourceIdentifier requestIdentifier() const { return m_requestIdentifier; }
+
+ const IDBError& error() const { return m_error; }
+ uint64_t databaseConnectionIdentifier() const { return m_databaseConnectionIdentifier; }
+
+ const IDBDatabaseInfo& databaseInfo() const;
+ const IDBTransactionInfo& transactionInfo() const;
+
+ const IDBKeyData* resultKey() const { return m_resultKey.get(); }
+ uint64_t resultInteger() const { return m_resultInteger; }
+
+ WEBCORE_EXPORT const IDBGetResult& getResult() const;
+ WEBCORE_EXPORT const IDBGetAllResult& getAllResult() const;
+
+ WEBCORE_EXPORT IDBResultData();
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBResultData&);
+
+private:
+ IDBResultData(const IDBResourceIdentifier&);
+ IDBResultData(IDBResultType, const IDBResourceIdentifier&);
+
+ static void isolatedCopy(const IDBResultData& source, IDBResultData& destination);
+
+ IDBResultType m_type { IDBResultType::Error };
+ IDBResourceIdentifier m_requestIdentifier;
+
+ IDBError m_error;
+ uint64_t m_databaseConnectionIdentifier { 0 };
+ std::unique_ptr<IDBDatabaseInfo> m_databaseInfo;
+ std::unique_ptr<IDBTransactionInfo> m_transactionInfo;
+ std::unique_ptr<IDBKeyData> m_resultKey;
+ std::unique_ptr<IDBGetResult> m_getResult;
+ std::unique_ptr<IDBGetAllResult> m_getAllResult;
+ uint64_t m_resultInteger { 0 };
+};
+
+template<class Encoder>
+void IDBResultData::encode(Encoder& encoder) const
+{
+ encoder << m_requestIdentifier << m_error << m_databaseConnectionIdentifier << m_resultInteger;
+
+ encoder.encodeEnum(m_type);
+
+ encoder << !!m_databaseInfo;
+ if (m_databaseInfo)
+ encoder << *m_databaseInfo;
+
+ encoder << !!m_transactionInfo;
+ if (m_transactionInfo)
+ encoder << *m_transactionInfo;
+
+ encoder << !!m_resultKey;
+ if (m_resultKey)
+ encoder << *m_resultKey;
+
+ encoder << !!m_getResult;
+ if (m_getResult)
+ encoder << *m_getResult;
+
+ encoder << !!m_getAllResult;
+ if (m_getAllResult)
+ encoder << *m_getAllResult;
+}
+
+template<class Decoder> bool IDBResultData::decode(Decoder& decoder, IDBResultData& result)
+{
+ if (!decoder.decode(result.m_requestIdentifier))
+ return false;
+
+ if (!decoder.decode(result.m_error))
+ return false;
+
+ if (!decoder.decode(result.m_databaseConnectionIdentifier))
+ return false;
+
+ if (!decoder.decode(result.m_resultInteger))
+ return false;
+
+ if (!decoder.decodeEnum(result.m_type))
+ return false;
+
+ bool hasObject;
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ auto object = std::make_unique<IDBDatabaseInfo>();
+ if (!decoder.decode(*object))
+ return false;
+ result.m_databaseInfo = WTFMove(object);
+ }
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ auto object = std::make_unique<IDBTransactionInfo>();
+ if (!decoder.decode(*object))
+ return false;
+ result.m_transactionInfo = WTFMove(object);
+ }
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ auto object = std::make_unique<IDBKeyData>();
+ if (!decoder.decode(*object))
+ return false;
+ result.m_resultKey = WTFMove(object);
+ }
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ auto object = std::make_unique<IDBGetResult>();
+ if (!decoder.decode(*object))
+ return false;
+ result.m_getResult = WTFMove(object);
+ }
+
+ if (!decoder.decode(hasObject))
+ return false;
+ if (hasObject) {
+ auto object = std::make_unique<IDBGetAllResult>();
+ if (!decoder.decode(*object))
+ return false;
+ result.m_getAllResult = WTFMove(object);
+ }
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp
new file mode 100644
index 000000000..0010c2443
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2015 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 "IDBTransactionInfo.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBTransaction.h"
+
+namespace WebCore {
+
+IDBTransactionInfo::IDBTransactionInfo()
+{
+}
+
+IDBTransactionInfo::IDBTransactionInfo(const IDBResourceIdentifier& identifier)
+ : m_identifier(identifier)
+{
+}
+
+IDBTransactionInfo IDBTransactionInfo::clientTransaction(const IDBClient::IDBConnectionProxy& connectionProxy, const Vector<String>& objectStores, IDBTransactionMode mode)
+{
+ IDBTransactionInfo result((IDBResourceIdentifier(connectionProxy)));
+ result.m_mode = mode;
+ result.m_objectStores = objectStores;
+
+ return result;
+}
+
+IDBTransactionInfo IDBTransactionInfo::versionChange(const IDBServer::IDBConnectionToClient& connection, const IDBDatabaseInfo& originalDatabaseInfo, uint64_t newVersion)
+{
+ IDBTransactionInfo result((IDBResourceIdentifier(connection)));
+ result.m_mode = IDBTransactionMode::Versionchange;
+ result.m_newVersion = newVersion;
+ result.m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(originalDatabaseInfo);
+
+ return result;
+}
+
+IDBTransactionInfo::IDBTransactionInfo(const IDBTransactionInfo& info)
+ : m_identifier(info.identifier())
+ , m_mode(info.m_mode)
+ , m_newVersion(info.m_newVersion)
+ , m_objectStores(info.m_objectStores)
+{
+ if (info.m_originalDatabaseInfo)
+ m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(*info.m_originalDatabaseInfo);
+}
+
+IDBTransactionInfo::IDBTransactionInfo(const IDBTransactionInfo& that, IsolatedCopyTag)
+{
+ isolatedCopy(that, *this);
+}
+
+IDBTransactionInfo IDBTransactionInfo::isolatedCopy() const
+{
+ return { *this, IsolatedCopy };
+}
+
+void IDBTransactionInfo::isolatedCopy(const IDBTransactionInfo& source, IDBTransactionInfo& destination)
+{
+ destination.m_identifier = source.m_identifier.isolatedCopy();
+ destination.m_mode = source.m_mode;
+ destination.m_newVersion = source.m_newVersion;
+
+ destination.m_objectStores.reserveCapacity(source.m_objectStores.size());
+ for (auto& objectStore : source.m_objectStores)
+ destination.m_objectStores.uncheckedAppend(objectStore.isolatedCopy());
+
+ if (source.m_originalDatabaseInfo)
+ destination.m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(*source.m_originalDatabaseInfo, IDBDatabaseInfo::IsolatedCopy);
+}
+
+#if !LOG_DISABLED
+String IDBTransactionInfo::loggingString() const
+{
+ String modeString;
+ switch (m_mode) {
+ case IDBTransactionMode::Readonly:
+ modeString = ASCIILiteral("readonly");
+ break;
+ case IDBTransactionMode::Readwrite:
+ modeString = ASCIILiteral("readwrite");
+ break;
+ case IDBTransactionMode::Versionchange:
+ modeString = ASCIILiteral("versionchange");
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ return makeString("Transaction: ", m_identifier.loggingString(), " mode ", modeString, " newVersion ", String::number(m_newVersion));
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h b/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h
new file mode 100644
index 000000000..636286c86
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBDatabaseInfo.h"
+#include "IDBResourceIdentifier.h"
+#include "IDBTransactionMode.h"
+#include "IndexedDB.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+namespace IDBClient {
+class IDBConnectionProxy;
+}
+
+namespace IDBServer {
+class IDBConnectionToClient;
+}
+
+class IDBTransactionInfo {
+public:
+ static IDBTransactionInfo clientTransaction(const IDBClient::IDBConnectionProxy&, const Vector<String>& objectStores, IDBTransactionMode);
+ static IDBTransactionInfo versionChange(const IDBServer::IDBConnectionToClient&, const IDBDatabaseInfo& originalDatabaseInfo, uint64_t newVersion);
+
+ IDBTransactionInfo(const IDBTransactionInfo&);
+
+ enum IsolatedCopyTag { IsolatedCopy };
+ IDBTransactionInfo(const IDBTransactionInfo&, IsolatedCopyTag);
+
+ IDBTransactionInfo isolatedCopy() const;
+
+ const IDBResourceIdentifier& identifier() const { return m_identifier; }
+
+ IDBTransactionMode mode() const { return m_mode; }
+ uint64_t newVersion() const { return m_newVersion; }
+
+ const Vector<String>& objectStores() const { return m_objectStores; }
+
+ IDBDatabaseInfo* originalDatabaseInfo() const { return m_originalDatabaseInfo.get(); }
+
+ WEBCORE_EXPORT IDBTransactionInfo();
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static bool decode(Decoder&, IDBTransactionInfo&);
+
+#if !LOG_DISABLED
+ String loggingString() const;
+#endif
+
+private:
+ IDBTransactionInfo(const IDBResourceIdentifier&);
+
+ static void isolatedCopy(const IDBTransactionInfo& source, IDBTransactionInfo& destination);
+
+ IDBResourceIdentifier m_identifier;
+
+ IDBTransactionMode m_mode { IDBTransactionMode::Readonly };
+ uint64_t m_newVersion { 0 };
+ Vector<String> m_objectStores;
+ std::unique_ptr<IDBDatabaseInfo> m_originalDatabaseInfo;
+};
+
+template<class Encoder>
+void IDBTransactionInfo::encode(Encoder& encoder) const
+{
+ encoder << m_identifier << m_newVersion << m_objectStores;
+ encoder.encodeEnum(m_mode);
+
+ encoder << !!m_originalDatabaseInfo;
+ if (m_originalDatabaseInfo)
+ encoder << *m_originalDatabaseInfo;
+}
+
+template<class Decoder>
+bool IDBTransactionInfo::decode(Decoder& decoder, IDBTransactionInfo& info)
+{
+ if (!decoder.decode(info.m_identifier))
+ return false;
+
+ if (!decoder.decode(info.m_newVersion))
+ return false;
+
+ if (!decoder.decode(info.m_objectStores))
+ return false;
+
+ if (!decoder.decodeEnum(info.m_mode))
+ return false;
+
+ bool hasObject;
+ if (!decoder.decode(hasObject))
+ return false;
+
+ if (hasObject) {
+ std::unique_ptr<IDBDatabaseInfo> object = std::make_unique<IDBDatabaseInfo>();
+ if (!decoder.decode(*object))
+ return false;
+ info.m_originalDatabaseInfo = WTFMove(object);
+ }
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp b/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp
new file mode 100644
index 000000000..addd1f8c0
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 2015 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 "InProcessIDBServer.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "FileSystem.h"
+#include "IDBConnectionToClient.h"
+#include "IDBConnectionToServer.h"
+#include "IDBCursorInfo.h"
+#include "IDBGetRecordData.h"
+#include "IDBIterateCursorData.h"
+#include "IDBKeyRangeData.h"
+#include "IDBOpenDBRequest.h"
+#include "IDBRequestData.h"
+#include "IDBResultData.h"
+#include "IDBValue.h"
+#include "Logging.h"
+#include <wtf/RunLoop.h>
+
+namespace WebCore {
+
+Ref<InProcessIDBServer> InProcessIDBServer::create()
+{
+ Ref<InProcessIDBServer> server = adoptRef(*new InProcessIDBServer);
+ server->m_server->registerConnection(server->connectionToClient());
+ return server;
+}
+
+Ref<InProcessIDBServer> InProcessIDBServer::create(const String& databaseDirectoryPath)
+{
+ Ref<InProcessIDBServer> server = adoptRef(*new InProcessIDBServer(databaseDirectoryPath));
+ server->m_server->registerConnection(server->connectionToClient());
+ return server;
+}
+
+InProcessIDBServer::InProcessIDBServer()
+ : m_server(IDBServer::IDBServer::create(*this))
+{
+ relaxAdoptionRequirement();
+ m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
+ m_connectionToClient = IDBServer::IDBConnectionToClient::create(*this);
+}
+
+InProcessIDBServer::InProcessIDBServer(const String& databaseDirectoryPath)
+ : m_server(IDBServer::IDBServer::create(databaseDirectoryPath, *this))
+{
+ relaxAdoptionRequirement();
+ m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
+ m_connectionToClient = IDBServer::IDBConnectionToClient::create(*this);
+}
+
+uint64_t InProcessIDBServer::identifier() const
+{
+ // An instance of InProcessIDBServer always has a 1:1 relationship with its instance of IDBServer.
+ // Therefore the connection identifier between the two can always be "1".
+ return 1;
+}
+
+IDBClient::IDBConnectionToServer& InProcessIDBServer::connectionToServer() const
+{
+ return *m_connectionToServer;
+}
+
+IDBServer::IDBConnectionToClient& InProcessIDBServer::connectionToClient() const
+{
+ return *m_connectionToClient;
+}
+
+void InProcessIDBServer::deleteDatabase(const IDBRequestData& requestData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData] {
+ m_server->deleteDatabase(requestData);
+ });
+}
+
+void InProcessIDBServer::didDeleteDatabase(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didDeleteDatabase(resultData);
+ });
+}
+
+void InProcessIDBServer::openDatabase(const IDBRequestData& requestData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData] {
+ m_server->openDatabase(requestData);
+ });
+}
+
+void InProcessIDBServer::didOpenDatabase(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didOpenDatabase(resultData);
+ });
+}
+
+void InProcessIDBServer::didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), transactionIdentifier, error] {
+ m_connectionToServer->didAbortTransaction(transactionIdentifier, error);
+ });
+}
+
+void InProcessIDBServer::didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), transactionIdentifier, error] {
+ m_connectionToServer->didCommitTransaction(transactionIdentifier, error);
+ });
+}
+
+void InProcessIDBServer::didCreateObjectStore(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didCreateObjectStore(resultData);
+ });
+}
+
+void InProcessIDBServer::didDeleteObjectStore(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didDeleteObjectStore(resultData);
+ });
+}
+
+void InProcessIDBServer::didRenameObjectStore(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didRenameObjectStore(resultData);
+ });
+}
+
+void InProcessIDBServer::didClearObjectStore(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didClearObjectStore(resultData);
+ });
+}
+
+void InProcessIDBServer::didCreateIndex(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didCreateIndex(resultData);
+ });
+}
+
+void InProcessIDBServer::didDeleteIndex(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didDeleteIndex(resultData);
+ });
+}
+
+void InProcessIDBServer::didRenameIndex(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didRenameIndex(resultData);
+ });
+}
+
+void InProcessIDBServer::didPutOrAdd(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didPutOrAdd(resultData);
+ });
+}
+
+void InProcessIDBServer::didGetRecord(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didGetRecord(resultData);
+ });
+}
+
+void InProcessIDBServer::didGetAllRecords(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didGetAllRecords(resultData);
+ });
+}
+
+void InProcessIDBServer::didGetCount(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didGetCount(resultData);
+ });
+}
+
+void InProcessIDBServer::didDeleteRecord(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didDeleteRecord(resultData);
+ });
+}
+
+void InProcessIDBServer::didOpenCursor(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didOpenCursor(resultData);
+ });
+}
+
+void InProcessIDBServer::didIterateCursor(const IDBResultData& resultData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+ m_connectionToServer->didIterateCursor(resultData);
+ });
+}
+
+void InProcessIDBServer::abortTransaction(const IDBResourceIdentifier& resourceIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resourceIdentifier] {
+ m_server->abortTransaction(resourceIdentifier);
+ });
+}
+
+void InProcessIDBServer::commitTransaction(const IDBResourceIdentifier& resourceIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resourceIdentifier] {
+ m_server->commitTransaction(resourceIdentifier);
+ });
+}
+
+void InProcessIDBServer::didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier, transactionIdentifier] {
+ m_server->didFinishHandlingVersionChangeTransaction(databaseConnectionIdentifier, transactionIdentifier);
+ });
+}
+
+void InProcessIDBServer::createObjectStore(const IDBRequestData& resultData, const IDBObjectStoreInfo& info)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData, info] {
+ m_server->createObjectStore(resultData, info);
+ });
+}
+
+void InProcessIDBServer::deleteObjectStore(const IDBRequestData& requestData, const String& objectStoreName)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreName] {
+ m_server->deleteObjectStore(requestData, objectStoreName);
+ });
+}
+
+void InProcessIDBServer::renameObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, const String& newName)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier, newName] {
+ m_server->renameObjectStore(requestData, objectStoreIdentifier, newName);
+ });
+}
+
+void InProcessIDBServer::clearObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier] {
+ m_server->clearObjectStore(requestData, objectStoreIdentifier);
+ });
+}
+
+void InProcessIDBServer::createIndex(const IDBRequestData& requestData, const IDBIndexInfo& info)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, info] {
+ m_server->createIndex(requestData, info);
+ });
+}
+
+void InProcessIDBServer::deleteIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, const String& indexName)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier, indexName] {
+ m_server->deleteIndex(requestData, objectStoreIdentifier, indexName);
+ });
+}
+
+void InProcessIDBServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier, indexIdentifier, newName] {
+ m_server->renameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName);
+ });
+}
+
+void InProcessIDBServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, keyData, value, overwriteMode] {
+ m_server->putOrAdd(requestData, keyData, value, overwriteMode);
+ });
+}
+
+void InProcessIDBServer::getRecord(const IDBRequestData& requestData, const IDBGetRecordData& getRecordData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, getRecordData] {
+ m_server->getRecord(requestData, getRecordData);
+ });
+}
+
+void InProcessIDBServer::getAllRecords(const IDBRequestData& requestData, const IDBGetAllRecordsData& getAllRecordsData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, getAllRecordsData] {
+ m_server->getAllRecords(requestData, getAllRecordsData);
+ });
+}
+
+void InProcessIDBServer::getCount(const IDBRequestData& requestData, const IDBKeyRangeData& keyRangeData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, keyRangeData] {
+ m_server->getCount(requestData, keyRangeData);
+ });
+}
+
+void InProcessIDBServer::deleteRecord(const IDBRequestData& requestData, const IDBKeyRangeData& keyRangeData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, keyRangeData] {
+ m_server->deleteRecord(requestData, keyRangeData);
+ });
+}
+
+void InProcessIDBServer::openCursor(const IDBRequestData& requestData, const IDBCursorInfo& info)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, info] {
+ m_server->openCursor(requestData, info);
+ });
+}
+
+void InProcessIDBServer::iterateCursor(const IDBRequestData& requestData, const IDBIterateCursorData& data)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, data] {
+ m_server->iterateCursor(requestData, data);
+ });
+}
+
+void InProcessIDBServer::establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo& info)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier, info] {
+ m_server->establishTransaction(databaseConnectionIdentifier, info);
+ });
+}
+
+void InProcessIDBServer::fireVersionChangeEvent(IDBServer::UniqueIDBDatabaseConnection& connection, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier = connection.identifier(), requestIdentifier, requestedVersion] {
+ m_connectionToServer->fireVersionChangeEvent(databaseConnectionIdentifier, requestIdentifier, requestedVersion);
+ });
+}
+
+void InProcessIDBServer::didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), transactionIdentifier, error] {
+ m_connectionToServer->didStartTransaction(transactionIdentifier, error);
+ });
+}
+
+void InProcessIDBServer::didCloseFromServer(IDBServer::UniqueIDBDatabaseConnection& connection, const IDBError& error)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier = connection.identifier(), error] {
+ m_connectionToServer->didCloseFromServer(databaseConnectionIdentifier, error);
+ });
+}
+
+void InProcessIDBServer::notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestIdentifier, oldVersion, newVersion] {
+ m_connectionToServer->notifyOpenDBRequestBlocked(requestIdentifier, oldVersion, newVersion);
+ });
+}
+
+void InProcessIDBServer::databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier] {
+ m_server->databaseConnectionPendingClose(databaseConnectionIdentifier);
+ });
+}
+
+void InProcessIDBServer::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier] {
+ m_server->databaseConnectionClosed(databaseConnectionIdentifier);
+ });
+}
+
+void InProcessIDBServer::abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier, transactionIdentifier] {
+ m_server->abortOpenAndUpgradeNeeded(databaseConnectionIdentifier, transactionIdentifier);
+ });
+}
+
+void InProcessIDBServer::didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier, requestIdentifier] {
+ m_server->didFireVersionChangeEvent(databaseConnectionIdentifier, requestIdentifier);
+ });
+}
+
+void InProcessIDBServer::openDBRequestCancelled(const IDBRequestData& requestData)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData] {
+ m_server->openDBRequestCancelled(requestData);
+ });
+}
+
+void InProcessIDBServer::confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier] {
+ m_server->confirmDidCloseFromServer(databaseConnectionIdentifier);
+ });
+}
+
+void InProcessIDBServer::getAllDatabaseNames(const SecurityOriginData& mainFrameOrigin, const SecurityOriginData& openingOrigin, uint64_t callbackID)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), mainFrameOrigin, openingOrigin, callbackID] {
+ m_server->getAllDatabaseNames(m_connectionToServer->identifier(), mainFrameOrigin, openingOrigin, callbackID);
+ });
+}
+
+void InProcessIDBServer::didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames)
+{
+ RunLoop::current().dispatch([this, protectedThis = makeRef(*this), callbackID, databaseNames] {
+ m_connectionToServer->didGetAllDatabaseNames(callbackID, databaseNames);
+ });
+}
+
+void InProcessIDBServer::accessToTemporaryFileComplete(const String& path)
+{
+ deleteFile(path);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h b/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h
new file mode 100644
index 000000000..d0dc2ec02
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBConnectionToClient.h"
+#include "IDBConnectionToServer.h"
+#include "IDBOpenDBRequest.h"
+#include "IDBServer.h"
+#include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+namespace IDBClient {
+class IDBConnectionToServer;
+}
+
+namespace IDBServer {
+class IDBServer;
+}
+
+class InProcessIDBServer final : public IDBClient::IDBConnectionToServerDelegate, public IDBServer::IDBConnectionToClientDelegate, public RefCounted<InProcessIDBServer>, public IDBServer::IDBBackingStoreTemporaryFileHandler {
+public:
+ WEBCORE_EXPORT static Ref<InProcessIDBServer> create();
+ WEBCORE_EXPORT static Ref<InProcessIDBServer> create(const String& databaseDirectoryPath);
+
+ WEBCORE_EXPORT IDBClient::IDBConnectionToServer& connectionToServer() const;
+ IDBServer::IDBConnectionToClient& connectionToClient() const;
+ IDBServer::IDBServer& server() { return m_server.get(); }
+
+ IDBServer::IDBServer& idbServer() { return m_server.get(); }
+
+ // IDBConnectionToServer
+ void deleteDatabase(const IDBRequestData&) final;
+ void openDatabase(const IDBRequestData&) final;
+ void abortTransaction(const IDBResourceIdentifier&) final;
+ void commitTransaction(const IDBResourceIdentifier&) final;
+ void didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier&) final;
+ void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&) final;
+ void deleteObjectStore(const IDBRequestData&, const String& objectStoreName) final;
+ void renameObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName) final;
+ void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier) final;
+ void createIndex(const IDBRequestData&, const IDBIndexInfo&) final;
+ void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName) final;
+ void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final;
+ void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, const IndexedDB::ObjectStoreOverwriteMode) final;
+ void getRecord(const IDBRequestData&, const IDBGetRecordData&) final;
+ void getAllRecords(const IDBRequestData&, const IDBGetAllRecordsData&) final;
+ void getCount(const IDBRequestData&, const IDBKeyRangeData&) final;
+ void deleteRecord(const IDBRequestData&, const IDBKeyRangeData&) final;
+ void openCursor(const IDBRequestData&, const IDBCursorInfo&) final;
+ void iterateCursor(const IDBRequestData&, const IDBIterateCursorData&) final;
+ void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&) final;
+ void databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier) final;
+ void databaseConnectionClosed(uint64_t databaseConnectionIdentifier) final;
+ void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier) final;
+ void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier) final;
+ void openDBRequestCancelled(const IDBRequestData&) final;
+ void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier) final;
+ void getAllDatabaseNames(const SecurityOriginData& mainFrameOrigin, const SecurityOriginData& openingOrigin, uint64_t callbackID) final;
+
+ // IDBConnectionToClient
+ uint64_t identifier() const override;
+ void didDeleteDatabase(const IDBResultData&) final;
+ void didOpenDatabase(const IDBResultData&) final;
+ void didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&) final;
+ void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&) final;
+ void didCreateObjectStore(const IDBResultData&) final;
+ void didDeleteObjectStore(const IDBResultData&) final;
+ void didRenameObjectStore(const IDBResultData&) final;
+ void didClearObjectStore(const IDBResultData&) final;
+ void didCreateIndex(const IDBResultData&) final;
+ void didDeleteIndex(const IDBResultData&) final;
+ void didRenameIndex(const IDBResultData&) final;
+ void didPutOrAdd(const IDBResultData&) final;
+ void didGetRecord(const IDBResultData&) final;
+ void didGetAllRecords(const IDBResultData&) final;
+ void didGetCount(const IDBResultData&) final;
+ void didDeleteRecord(const IDBResultData&) final;
+ void didOpenCursor(const IDBResultData&) final;
+ void didIterateCursor(const IDBResultData&) final;
+ void fireVersionChangeEvent(IDBServer::UniqueIDBDatabaseConnection&, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion) final;
+ void didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&) final;
+ void didCloseFromServer(IDBServer::UniqueIDBDatabaseConnection&, const IDBError&) final;
+ void notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion) final;
+ void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames) final;
+
+ void ref() override { RefCounted<InProcessIDBServer>::ref(); }
+ void deref() override { RefCounted<InProcessIDBServer>::deref(); }
+
+ void prepareForAccessToTemporaryFile(const String&) override { }
+ void accessToTemporaryFileComplete(const String& path) override;
+
+private:
+ InProcessIDBServer();
+ InProcessIDBServer(const String& databaseDirectoryPath);
+
+ Ref<IDBServer::IDBServer> m_server;
+ RefPtr<IDBClient::IDBConnectionToServer> m_connectionToServer;
+ RefPtr<IDBServer::IDBConnectionToClient> m_connectionToClient;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IndexKey.cpp b/Source/WebCore/Modules/indexeddb/shared/IndexKey.cpp
new file mode 100644
index 000000000..a40f90120
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IndexKey.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 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 "IndexKey.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+IndexKey::IndexKey()
+{
+}
+
+IndexKey::IndexKey(Vector<IDBKeyData>&& keys)
+{
+ m_keys.swap(keys);
+}
+
+IndexKey IndexKey::isolatedCopy() const
+{
+ Vector<IDBKeyData> keys;
+ keys.reserveInitialCapacity(m_keys.size());
+ for (auto& key : m_keys)
+ keys.uncheckedAppend(key.isolatedCopy());
+
+ return { WTFMove(keys) };
+}
+
+IDBKeyData IndexKey::asOneKey() const
+{
+ if (m_keys.isEmpty())
+ return { };
+
+ if (m_keys.size() == 1)
+ return m_keys[0];
+
+ IDBKeyData result;
+ result.setArrayValue(m_keys);
+ return result;
+}
+
+Vector<IDBKeyData> IndexKey::multiEntry() const
+{
+ Vector<IDBKeyData> multiEntry;
+ for (auto& key : m_keys) {
+ if (!key.isValid())
+ continue;
+
+ bool skip = false;
+ for (auto& otherKey : multiEntry) {
+ if (key == otherKey) {
+ skip = true;
+ break;
+ }
+ }
+
+ if (!skip)
+ multiEntry.append(key);
+ }
+
+ return multiEntry;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/Source/WebCore/Modules/indexeddb/shared/IndexKey.h b/Source/WebCore/Modules/indexeddb/shared/IndexKey.h
new file mode 100644
index 000000000..ad80e86f1
--- /dev/null
+++ b/Source/WebCore/Modules/indexeddb/shared/IndexKey.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyData.h"
+#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class IndexKey {
+public:
+ IndexKey();
+ IndexKey(Vector<IDBKeyData>&&);
+
+ IndexKey isolatedCopy() const;
+
+ IDBKeyData asOneKey() const;
+ Vector<IDBKeyData> multiEntry() const;
+
+ bool isNull() const { return m_keys.isEmpty(); }
+
+private:
+ Vector<IDBKeyData> m_keys;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)