2 * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(INDEXED_DATABASE)
30 #include "IDBConnectionProxy.h"
31 #include "IDBConnectionToServerDelegate.h"
32 #include "IDBResourceIdentifier.h"
33 #include <wtf/HashMap.h>
35 #include <wtf/ThreadSafeRefCounted.h>
42 class IDBObjectStoreInfo;
47 struct IDBGetAllRecordsData;
48 struct IDBGetRecordData;
49 struct IDBIterateCursorData;
53 class IDBConnectionToServer : public ThreadSafeRefCounted<IDBConnectionToServer> {
55 WEBCORE_EXPORT static Ref<IDBConnectionToServer> create(IDBConnectionToServerDelegate&);
57 uint64_t identifier() const;
59 IDBConnectionProxy& proxy();
61 void deleteDatabase(const IDBRequestData&);
62 WEBCORE_EXPORT void didDeleteDatabase(const IDBResultData&);
64 void openDatabase(const IDBRequestData&);
65 WEBCORE_EXPORT void didOpenDatabase(const IDBResultData&);
67 void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&);
68 WEBCORE_EXPORT void didCreateObjectStore(const IDBResultData&);
70 void deleteObjectStore(const IDBRequestData&, const String& objectStoreName);
71 WEBCORE_EXPORT void didDeleteObjectStore(const IDBResultData&);
73 void renameObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName);
74 WEBCORE_EXPORT void didRenameObjectStore(const IDBResultData&);
76 void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier);
77 WEBCORE_EXPORT void didClearObjectStore(const IDBResultData&);
79 void createIndex(const IDBRequestData&, const IDBIndexInfo&);
80 WEBCORE_EXPORT void didCreateIndex(const IDBResultData&);
82 void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName);
83 WEBCORE_EXPORT void didDeleteIndex(const IDBResultData&);
85 void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
86 WEBCORE_EXPORT void didRenameIndex(const IDBResultData&);
88 void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, const IndexedDB::ObjectStoreOverwriteMode);
89 WEBCORE_EXPORT void didPutOrAdd(const IDBResultData&);
91 void getRecord(const IDBRequestData&, const IDBGetRecordData&);
92 WEBCORE_EXPORT void didGetRecord(const IDBResultData&);
94 void getAllRecords(const IDBRequestData&, const IDBGetAllRecordsData&);
95 WEBCORE_EXPORT void didGetAllRecords(const IDBResultData&);
97 void getCount(const IDBRequestData&, const IDBKeyRangeData&);
98 WEBCORE_EXPORT void didGetCount(const IDBResultData&);
100 void deleteRecord(const IDBRequestData&, const IDBKeyRangeData&);
101 WEBCORE_EXPORT void didDeleteRecord(const IDBResultData&);
103 void openCursor(const IDBRequestData&, const IDBCursorInfo&);
104 WEBCORE_EXPORT void didOpenCursor(const IDBResultData&);
106 void iterateCursor(const IDBRequestData&, const IDBIterateCursorData&);
107 WEBCORE_EXPORT void didIterateCursor(const IDBResultData&);
109 void commitTransaction(const IDBResourceIdentifier& transactionIdentifier);
110 WEBCORE_EXPORT void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&);
112 void didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier&);
114 void abortTransaction(const IDBResourceIdentifier& transactionIdentifier);
115 WEBCORE_EXPORT void didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&);
117 WEBCORE_EXPORT void fireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);
118 void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier);
120 WEBCORE_EXPORT void didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&);
122 WEBCORE_EXPORT void didCloseFromServer(uint64_t databaseConnectionIdentifier, const IDBError&);
123 void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier);
125 WEBCORE_EXPORT void connectionToServerLost(const IDBError&);
127 WEBCORE_EXPORT void notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion);
128 void openDBRequestCancelled(const IDBRequestData&);
130 void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&);
132 void databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier);
133 void databaseConnectionClosed(uint64_t databaseConnectionIdentifier);
135 // To be used when an IDBOpenDBRequest gets a new database connection, optionally with a
136 // versionchange transaction, but the page is already torn down.
137 void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier);
139 void getAllDatabaseNames(const SecurityOrigin& mainFrameOrigin, const SecurityOrigin& openingOrigin, std::function<void (const Vector<String>&)>);
140 WEBCORE_EXPORT void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames);
143 IDBConnectionToServer(IDBConnectionToServerDelegate&);
145 Ref<IDBConnectionToServerDelegate> m_delegate;
147 HashMap<uint64_t, std::function<void (const Vector<String>&)>> m_getAllDatabaseNamesCallbacks;
149 std::unique_ptr<IDBConnectionProxy> m_proxy;
152 } // namespace IDBClient
153 } // namespace WebCore
155 #endif // ENABLE(INDEXED_DATABASE)