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#pragma once
27
28#if ENABLE(INDEXED_DATABASE)
29
30#include "MessageSender.h"
31#include "SandboxExtension.h"
32#include <WebCore/IDBConnectionToServer.h>
33#include <pal/SessionID.h>
34
35namespace WebKit {
36
37class WebIDBResult;
38
39class WebIDBConnectionToServer final : private WebCore::IDBClient::IDBConnectionToServerDelegate, private IPC::MessageSender, public RefCounted<WebIDBConnectionToServer> {
40public:
41 static Ref<WebIDBConnectionToServer> create(PAL::SessionID);
42
43 virtual ~WebIDBConnectionToServer();
44
45 WebCore::IDBClient::IDBConnectionToServer& coreConnectionToServer();
46 uint64_t identifier() const final { return m_identifier; }
47 uint64_t messageSenderDestinationID() const final { return m_identifier; }
48
49 // IDBConnectionToServerDelegate
50 void deleteDatabase(const WebCore::IDBRequestData&) final;
51 void openDatabase(const WebCore::IDBRequestData&) final;
52 void abortTransaction(const WebCore::IDBResourceIdentifier&) final;
53 void commitTransaction(const WebCore::IDBResourceIdentifier&) final;
54 void didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier&) final;
55 void createObjectStore(const WebCore::IDBRequestData&, const WebCore::IDBObjectStoreInfo&) final;
56 void deleteObjectStore(const WebCore::IDBRequestData&, const String& objectStoreName) final;
57 void renameObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName) final;
58 void clearObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier) final;
59 void createIndex(const WebCore::IDBRequestData&, const WebCore::IDBIndexInfo&) final;
60 void deleteIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName) final;
61 void renameIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final;
62 void putOrAdd(const WebCore::IDBRequestData&, const WebCore::IDBKeyData&, const WebCore::IDBValue&, const WebCore::IndexedDB::ObjectStoreOverwriteMode) final;
63 void getRecord(const WebCore::IDBRequestData&, const WebCore::IDBGetRecordData&) final;
64 void getAllRecords(const WebCore::IDBRequestData&, const WebCore::IDBGetAllRecordsData&) final;
65 void getCount(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&) final;
66 void deleteRecord(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&) final;
67 void openCursor(const WebCore::IDBRequestData&, const WebCore::IDBCursorInfo&) final;
68 void iterateCursor(const WebCore::IDBRequestData&, const WebCore::IDBIterateCursorData&) final;
69 void establishTransaction(uint64_t databaseConnectionIdentifier, const WebCore::IDBTransactionInfo&) final;
70 void databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier) final;
71 void databaseConnectionClosed(uint64_t databaseConnectionIdentifier) final;
72 void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& transactionIdentifier) final;
73 void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& requestIdentifier) final;
74 void openDBRequestCancelled(const WebCore::IDBRequestData&) final;
75 void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier) final;
76
77 void getAllDatabaseNames(const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& openingOrigin, uint64_t callbackID) final;
78
79 void ref() override { RefCounted<WebIDBConnectionToServer>::ref(); }
80 void deref() override { RefCounted<WebIDBConnectionToServer>::deref(); }
81
82 // Messages received from Network Process
83 void didDeleteDatabase(const WebCore::IDBResultData&);
84 void didOpenDatabase(const WebCore::IDBResultData&);
85 void didAbortTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&);
86 void didCommitTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&);
87 void didCreateObjectStore(const WebCore::IDBResultData&);
88 void didDeleteObjectStore(const WebCore::IDBResultData&);
89 void didRenameObjectStore(const WebCore::IDBResultData&);
90 void didClearObjectStore(const WebCore::IDBResultData&);
91 void didCreateIndex(const WebCore::IDBResultData&);
92 void didDeleteIndex(const WebCore::IDBResultData&);
93 void didRenameIndex(const WebCore::IDBResultData&);
94 void didPutOrAdd(const WebCore::IDBResultData&);
95 void didGetRecord(const WebIDBResult&);
96 void didGetAllRecords(const WebIDBResult&);
97 void didGetCount(const WebCore::IDBResultData&);
98 void didDeleteRecord(const WebCore::IDBResultData&);
99 void didOpenCursor(const WebIDBResult&);
100 void didIterateCursor(const WebIDBResult&);
101 void fireVersionChangeEvent(uint64_t uniqueDatabaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);
102 void didStartTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&);
103 void didCloseFromServer(uint64_t databaseConnectionIdentifier, const WebCore::IDBError&);
104 void notifyOpenDBRequestBlocked(const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion);
105 void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames);
106
107 void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
108
109 void connectionToServerLost();
110
111private:
112 WebIDBConnectionToServer(PAL::SessionID);
113
114 IPC::Connection* messageSenderConnection() const final;
115
116 uint64_t m_identifier { 0 };
117 bool m_isOpenInServer { false };
118 RefPtr<WebCore::IDBClient::IDBConnectionToServer> m_connectionToServer;
119 PAL::SessionID m_sessionID;
120};
121
122} // namespace WebKit
123
124#endif // ENABLE(INDEXED_DATABASE)
125