1 | /* |
2 | * Copyright (C) 2015, 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
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. |
12 | * |
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. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(INDEXED_DATABASE) |
29 | |
30 | #include "IDBConnectionProxy.h" |
31 | #include "IDBConnectionToServerDelegate.h" |
32 | #include "IDBResourceIdentifier.h" |
33 | #include <wtf/Function.h> |
34 | #include <wtf/HashMap.h> |
35 | #include <wtf/Ref.h> |
36 | #include <wtf/ThreadSafeRefCounted.h> |
37 | |
38 | namespace WebCore { |
39 | |
40 | class IDBCursorInfo; |
41 | class IDBDatabase; |
42 | class IDBError; |
43 | class IDBObjectStoreInfo; |
44 | class IDBResultData; |
45 | class IDBValue; |
46 | class SecurityOrigin; |
47 | |
48 | struct IDBGetAllRecordsData; |
49 | struct IDBGetRecordData; |
50 | struct IDBIterateCursorData; |
51 | |
52 | namespace IDBClient { |
53 | |
54 | class IDBConnectionToServer : public ThreadSafeRefCounted<IDBConnectionToServer> { |
55 | public: |
56 | WEBCORE_EXPORT static Ref<IDBConnectionToServer> create(IDBConnectionToServerDelegate&); |
57 | |
58 | WEBCORE_EXPORT uint64_t identifier() const; |
59 | |
60 | IDBConnectionProxy& proxy(); |
61 | |
62 | void deleteDatabase(const IDBRequestData&); |
63 | WEBCORE_EXPORT void didDeleteDatabase(const IDBResultData&); |
64 | |
65 | void openDatabase(const IDBRequestData&); |
66 | WEBCORE_EXPORT void didOpenDatabase(const IDBResultData&); |
67 | |
68 | void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&); |
69 | WEBCORE_EXPORT void didCreateObjectStore(const IDBResultData&); |
70 | |
71 | void deleteObjectStore(const IDBRequestData&, const String& objectStoreName); |
72 | WEBCORE_EXPORT void didDeleteObjectStore(const IDBResultData&); |
73 | |
74 | void renameObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName); |
75 | WEBCORE_EXPORT void didRenameObjectStore(const IDBResultData&); |
76 | |
77 | void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier); |
78 | WEBCORE_EXPORT void didClearObjectStore(const IDBResultData&); |
79 | |
80 | void createIndex(const IDBRequestData&, const IDBIndexInfo&); |
81 | WEBCORE_EXPORT void didCreateIndex(const IDBResultData&); |
82 | |
83 | void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName); |
84 | WEBCORE_EXPORT void didDeleteIndex(const IDBResultData&); |
85 | |
86 | void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName); |
87 | WEBCORE_EXPORT void didRenameIndex(const IDBResultData&); |
88 | |
89 | void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, const IndexedDB::ObjectStoreOverwriteMode); |
90 | WEBCORE_EXPORT void didPutOrAdd(const IDBResultData&); |
91 | |
92 | void getRecord(const IDBRequestData&, const IDBGetRecordData&); |
93 | WEBCORE_EXPORT void didGetRecord(const IDBResultData&); |
94 | |
95 | void getAllRecords(const IDBRequestData&, const IDBGetAllRecordsData&); |
96 | WEBCORE_EXPORT void didGetAllRecords(const IDBResultData&); |
97 | |
98 | void getCount(const IDBRequestData&, const IDBKeyRangeData&); |
99 | WEBCORE_EXPORT void didGetCount(const IDBResultData&); |
100 | |
101 | void deleteRecord(const IDBRequestData&, const IDBKeyRangeData&); |
102 | WEBCORE_EXPORT void didDeleteRecord(const IDBResultData&); |
103 | |
104 | void openCursor(const IDBRequestData&, const IDBCursorInfo&); |
105 | WEBCORE_EXPORT void didOpenCursor(const IDBResultData&); |
106 | |
107 | void iterateCursor(const IDBRequestData&, const IDBIterateCursorData&); |
108 | WEBCORE_EXPORT void didIterateCursor(const IDBResultData&); |
109 | |
110 | void commitTransaction(const IDBResourceIdentifier& transactionIdentifier); |
111 | WEBCORE_EXPORT void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&); |
112 | |
113 | void didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier&); |
114 | |
115 | void abortTransaction(const IDBResourceIdentifier& transactionIdentifier); |
116 | WEBCORE_EXPORT void didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&); |
117 | |
118 | WEBCORE_EXPORT void fireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion); |
119 | void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier); |
120 | |
121 | WEBCORE_EXPORT void didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&); |
122 | |
123 | WEBCORE_EXPORT void didCloseFromServer(uint64_t databaseConnectionIdentifier, const IDBError&); |
124 | void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier); |
125 | |
126 | WEBCORE_EXPORT void connectionToServerLost(const IDBError&); |
127 | |
128 | WEBCORE_EXPORT void notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion); |
129 | void openDBRequestCancelled(const IDBRequestData&); |
130 | |
131 | void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&); |
132 | |
133 | void databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier); |
134 | void databaseConnectionClosed(uint64_t databaseConnectionIdentifier); |
135 | |
136 | // To be used when an IDBOpenDBRequest gets a new database connection, optionally with a |
137 | // versionchange transaction, but the page is already torn down. |
138 | void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier); |
139 | |
140 | void getAllDatabaseNames(const SecurityOrigin& mainFrameOrigin, const SecurityOrigin& openingOrigin, WTF::Function<void (const Vector<String>&)>&&); |
141 | WEBCORE_EXPORT void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames); |
142 | |
143 | private: |
144 | IDBConnectionToServer(IDBConnectionToServerDelegate&); |
145 | |
146 | typedef void (IDBConnectionToServer::*ResultFunction)(const IDBResultData&); |
147 | void callResultFunctionWithErrorLater(ResultFunction, const IDBResourceIdentifier& requestIdentifier); |
148 | |
149 | WeakPtr<IDBConnectionToServerDelegate> m_delegate; |
150 | bool m_serverConnectionIsValid { true }; |
151 | |
152 | HashMap<uint64_t, WTF::Function<void (const Vector<String>&)>> m_getAllDatabaseNamesCallbacks; |
153 | |
154 | std::unique_ptr<IDBConnectionProxy> m_proxy; |
155 | }; |
156 | |
157 | } // namespace IDBClient |
158 | } // namespace WebCore |
159 | |
160 | #endif // ENABLE(INDEXED_DATABASE) |
161 | |