1/*
2 * Copyright (C) 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#include "config.h"
27#include "WebIDBConnectionToServer.h"
28
29#if ENABLE(INDEXED_DATABASE)
30
31#include "DataReference.h"
32#include "NetworkConnectionToWebProcessMessages.h"
33#include "NetworkProcessConnection.h"
34#include "WebCoreArgumentCoders.h"
35#include "WebIDBConnectionToClientMessages.h"
36#include "WebIDBResult.h"
37#include "WebProcess.h"
38#include <WebCore/IDBConnectionToServer.h>
39#include <WebCore/IDBCursorInfo.h>
40#include <WebCore/IDBError.h>
41#include <WebCore/IDBIndexInfo.h>
42#include <WebCore/IDBIterateCursorData.h>
43#include <WebCore/IDBKeyRangeData.h>
44#include <WebCore/IDBObjectStoreInfo.h>
45#include <WebCore/IDBOpenDBRequest.h>
46#include <WebCore/IDBRequestData.h>
47#include <WebCore/IDBResourceIdentifier.h>
48#include <WebCore/IDBResultData.h>
49#include <WebCore/IDBTransactionInfo.h>
50#include <WebCore/IDBValue.h>
51
52namespace WebKit {
53using namespace WebCore;
54
55Ref<WebIDBConnectionToServer> WebIDBConnectionToServer::create(PAL::SessionID sessionID)
56{
57 return adoptRef(*new WebIDBConnectionToServer(sessionID));
58}
59
60WebIDBConnectionToServer::WebIDBConnectionToServer(PAL::SessionID sessionID)
61 : m_sessionID(sessionID)
62{
63 relaxAdoptionRequirement();
64
65 m_isOpenInServer = sendSync(Messages::NetworkConnectionToWebProcess::EstablishIDBConnectionToServer(sessionID), Messages::NetworkConnectionToWebProcess::EstablishIDBConnectionToServer::Reply(m_identifier));
66
67 m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
68}
69
70WebIDBConnectionToServer::~WebIDBConnectionToServer()
71{
72}
73
74IPC::Connection* WebIDBConnectionToServer::messageSenderConnection() const
75{
76 return &WebProcess::singleton().ensureNetworkProcessConnection().connection();
77}
78
79IDBClient::IDBConnectionToServer& WebIDBConnectionToServer::coreConnectionToServer()
80{
81 return *m_connectionToServer;
82}
83
84void WebIDBConnectionToServer::deleteDatabase(const IDBRequestData& requestData)
85{
86 send(Messages::WebIDBConnectionToClient::DeleteDatabase(requestData));
87}
88
89void WebIDBConnectionToServer::openDatabase(const IDBRequestData& requestData)
90{
91 send(Messages::WebIDBConnectionToClient::OpenDatabase(requestData));
92}
93
94void WebIDBConnectionToServer::abortTransaction(const IDBResourceIdentifier& transactionIdentifier)
95{
96 send(Messages::WebIDBConnectionToClient::AbortTransaction(transactionIdentifier));
97}
98
99void WebIDBConnectionToServer::commitTransaction(const IDBResourceIdentifier& transactionIdentifier)
100{
101 send(Messages::WebIDBConnectionToClient::CommitTransaction(transactionIdentifier));
102}
103
104void WebIDBConnectionToServer::didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
105{
106 send(Messages::WebIDBConnectionToClient::DidFinishHandlingVersionChangeTransaction(databaseConnectionIdentifier, transactionIdentifier));
107}
108
109void WebIDBConnectionToServer::createObjectStore(const IDBRequestData& requestData, const IDBObjectStoreInfo& info)
110{
111 send(Messages::WebIDBConnectionToClient::CreateObjectStore(requestData, info));
112}
113
114void WebIDBConnectionToServer::deleteObjectStore(const IDBRequestData& requestData, const String& objectStoreName)
115{
116 send(Messages::WebIDBConnectionToClient::DeleteObjectStore(requestData, objectStoreName));
117}
118
119void WebIDBConnectionToServer::renameObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, const String& newName)
120{
121 send(Messages::WebIDBConnectionToClient::RenameObjectStore(requestData, objectStoreIdentifier, newName));
122}
123
124void WebIDBConnectionToServer::clearObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier)
125{
126 send(Messages::WebIDBConnectionToClient::ClearObjectStore(requestData, objectStoreIdentifier));
127}
128
129void WebIDBConnectionToServer::createIndex(const IDBRequestData& requestData, const IDBIndexInfo& info)
130{
131 send(Messages::WebIDBConnectionToClient::CreateIndex(requestData, info));
132}
133
134void WebIDBConnectionToServer::deleteIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, const String& indexName)
135{
136 send(Messages::WebIDBConnectionToClient::DeleteIndex(requestData, objectStoreIdentifier, indexName));
137}
138
139void WebIDBConnectionToServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
140{
141 send(Messages::WebIDBConnectionToClient::RenameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName));
142}
143
144void WebIDBConnectionToServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, const IndexedDB::ObjectStoreOverwriteMode mode)
145{
146 send(Messages::WebIDBConnectionToClient::PutOrAdd(requestData, keyData, value, mode));
147}
148
149void WebIDBConnectionToServer::getRecord(const IDBRequestData& requestData, const IDBGetRecordData& getRecordData)
150{
151 send(Messages::WebIDBConnectionToClient::GetRecord(requestData, getRecordData));
152}
153
154void WebIDBConnectionToServer::getAllRecords(const IDBRequestData& requestData, const IDBGetAllRecordsData& getAllRecordsData)
155{
156 send(Messages::WebIDBConnectionToClient::GetAllRecords(requestData, getAllRecordsData));
157}
158
159void WebIDBConnectionToServer::getCount(const IDBRequestData& requestData, const IDBKeyRangeData& range)
160{
161 send(Messages::WebIDBConnectionToClient::GetCount(requestData, range));
162}
163
164void WebIDBConnectionToServer::deleteRecord(const IDBRequestData& requestData, const IDBKeyRangeData& range)
165{
166 send(Messages::WebIDBConnectionToClient::DeleteRecord(requestData, range));
167}
168
169void WebIDBConnectionToServer::openCursor(const IDBRequestData& requestData, const IDBCursorInfo& info)
170{
171 send(Messages::WebIDBConnectionToClient::OpenCursor(requestData, info));
172}
173
174void WebIDBConnectionToServer::iterateCursor(const IDBRequestData& requestData, const IDBIterateCursorData& data)
175{
176 send(Messages::WebIDBConnectionToClient::IterateCursor(requestData, data));
177}
178
179void WebIDBConnectionToServer::establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo& info)
180{
181 send(Messages::WebIDBConnectionToClient::EstablishTransaction(databaseConnectionIdentifier, info));
182}
183
184void WebIDBConnectionToServer::databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier)
185{
186 send(Messages::WebIDBConnectionToClient::DatabaseConnectionPendingClose(databaseConnectionIdentifier));
187}
188
189void WebIDBConnectionToServer::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
190{
191 send(Messages::WebIDBConnectionToClient::DatabaseConnectionClosed(databaseConnectionIdentifier));
192}
193
194void WebIDBConnectionToServer::abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
195{
196 send(Messages::WebIDBConnectionToClient::AbortOpenAndUpgradeNeeded(databaseConnectionIdentifier, transactionIdentifier));
197}
198
199void WebIDBConnectionToServer::didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier)
200{
201 send(Messages::WebIDBConnectionToClient::DidFireVersionChangeEvent(databaseConnectionIdentifier, requestIdentifier));
202}
203
204void WebIDBConnectionToServer::openDBRequestCancelled(const IDBRequestData& requestData)
205{
206 send(Messages::WebIDBConnectionToClient::OpenDBRequestCancelled(requestData));
207}
208
209void WebIDBConnectionToServer::confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier)
210{
211 send(Messages::WebIDBConnectionToClient::ConfirmDidCloseFromServer(databaseConnectionIdentifier));
212}
213
214void WebIDBConnectionToServer::getAllDatabaseNames(const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& openingOrigin, uint64_t callbackID)
215{
216 send(Messages::WebIDBConnectionToClient::GetAllDatabaseNames(m_identifier, topOrigin, openingOrigin, callbackID));
217}
218
219void WebIDBConnectionToServer::didDeleteDatabase(const IDBResultData& result)
220{
221 m_connectionToServer->didDeleteDatabase(result);
222}
223
224void WebIDBConnectionToServer::didOpenDatabase(const IDBResultData& result)
225{
226 m_connectionToServer->didOpenDatabase(result);
227}
228
229void WebIDBConnectionToServer::didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
230{
231 m_connectionToServer->didAbortTransaction(transactionIdentifier, error);
232}
233
234void WebIDBConnectionToServer::didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
235{
236 m_connectionToServer->didCommitTransaction(transactionIdentifier, error);
237}
238
239void WebIDBConnectionToServer::didCreateObjectStore(const IDBResultData& result)
240{
241 m_connectionToServer->didCreateObjectStore(result);
242}
243
244void WebIDBConnectionToServer::didDeleteObjectStore(const IDBResultData& result)
245{
246 m_connectionToServer->didDeleteObjectStore(result);
247}
248
249void WebIDBConnectionToServer::didRenameObjectStore(const IDBResultData& result)
250{
251 m_connectionToServer->didRenameObjectStore(result);
252}
253
254void WebIDBConnectionToServer::didClearObjectStore(const IDBResultData& result)
255{
256 m_connectionToServer->didClearObjectStore(result);
257}
258
259void WebIDBConnectionToServer::didCreateIndex(const IDBResultData& result)
260{
261 m_connectionToServer->didCreateIndex(result);
262}
263
264void WebIDBConnectionToServer::didDeleteIndex(const IDBResultData& result)
265{
266 m_connectionToServer->didDeleteIndex(result);
267}
268
269void WebIDBConnectionToServer::didRenameIndex(const IDBResultData& result)
270{
271 m_connectionToServer->didRenameIndex(result);
272}
273
274void WebIDBConnectionToServer::didPutOrAdd(const IDBResultData& result)
275{
276 m_connectionToServer->didPutOrAdd(result);
277}
278
279void WebIDBConnectionToServer::didGetRecord(const WebIDBResult& result)
280{
281 m_connectionToServer->didGetRecord(result.resultData());
282}
283
284void WebIDBConnectionToServer::didGetAllRecords(const WebIDBResult& result)
285{
286 m_connectionToServer->didGetAllRecords(result.resultData());
287}
288
289void WebIDBConnectionToServer::didGetCount(const IDBResultData& result)
290{
291 m_connectionToServer->didGetCount(result);
292}
293
294void WebIDBConnectionToServer::didDeleteRecord(const IDBResultData& result)
295{
296 m_connectionToServer->didDeleteRecord(result);
297}
298
299void WebIDBConnectionToServer::didOpenCursor(const WebIDBResult& result)
300{
301 m_connectionToServer->didOpenCursor(result.resultData());
302}
303
304void WebIDBConnectionToServer::didIterateCursor(const WebIDBResult& result)
305{
306 m_connectionToServer->didIterateCursor(result.resultData());
307}
308
309void WebIDBConnectionToServer::fireVersionChangeEvent(uint64_t uniqueDatabaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion)
310{
311 m_connectionToServer->fireVersionChangeEvent(uniqueDatabaseConnectionIdentifier, requestIdentifier, requestedVersion);
312}
313
314void WebIDBConnectionToServer::didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
315{
316 m_connectionToServer->didStartTransaction(transactionIdentifier, error);
317}
318
319void WebIDBConnectionToServer::didCloseFromServer(uint64_t databaseConnectionIdentifier, const IDBError& error)
320{
321 m_connectionToServer->didCloseFromServer(databaseConnectionIdentifier, error);
322}
323
324void WebIDBConnectionToServer::notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
325{
326 m_connectionToServer->notifyOpenDBRequestBlocked(requestIdentifier, oldVersion, newVersion);
327}
328
329void WebIDBConnectionToServer::didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames)
330{
331 m_connectionToServer->didGetAllDatabaseNames(callbackID, databaseNames);
332}
333
334void WebIDBConnectionToServer::connectionToServerLost()
335{
336 m_connectionToServer->connectionToServerLost(IDBError { WebCore::UnknownError, "An internal error was encountered in the Indexed Database server"_s });
337}
338
339} // namespace WebKit
340
341#endif // ENABLE(INDEXED_DATABASE)
342