9c74a58ee18dd695312760593a7356145591849e
[WebKit-https.git] / Source / WebKit / NetworkProcess / IndexedDB / WebIDBConnectionToClient.h
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 "NetworkConnectionToWebProcess.h"
32 #include <WebCore/IDBConnectionToClient.h>
33 #include <pal/SessionID.h>
34
35 namespace WebCore {
36 class IDBCursorInfo;
37 class IDBIndexInfo;
38 class IDBKeyData;
39 class IDBObjectStoreInfo;
40 class IDBRequestData;
41 class IDBTransactionInfo;
42 class IDBValue;
43 class SerializedScriptValue;
44 struct IDBGetAllRecordsData;
45 struct IDBGetRecordData;
46 struct IDBIterateCursorData;
47 struct IDBKeyRangeData;
48 struct SecurityOriginData;
49 }
50
51 namespace WebKit {
52
53 class NetworkProcess;
54
55 class WebIDBConnectionToClient final : public WebCore::IDBServer::IDBConnectionToClientDelegate, public IPC::MessageSender, public RefCounted<WebIDBConnectionToClient> {
56 public:
57     static Ref<WebIDBConnectionToClient> create(NetworkProcess&, NetworkConnectionToWebProcess&, uint64_t serverConnectionIdentifier, PAL::SessionID);
58
59     virtual ~WebIDBConnectionToClient();
60
61     WebCore::IDBServer::IDBConnectionToClient& connectionToClient();
62     uint64_t identifier() const final { return m_identifier; }
63     uint64_t messageSenderDestinationID() final { return m_identifier; }
64
65     // IDBConnectionToClientDelegate
66     void didDeleteDatabase(const WebCore::IDBResultData&) final;
67     void didOpenDatabase(const WebCore::IDBResultData&) final;
68     void didAbortTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&) final;
69     void didCommitTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&) final;
70     void didCreateObjectStore(const WebCore::IDBResultData&) final;
71     void didDeleteObjectStore(const WebCore::IDBResultData&) final;
72     void didRenameObjectStore(const WebCore::IDBResultData&) final;
73     void didClearObjectStore(const WebCore::IDBResultData&) final;
74     void didCreateIndex(const WebCore::IDBResultData&) final;
75     void didDeleteIndex(const WebCore::IDBResultData&) final;
76     void didRenameIndex(const WebCore::IDBResultData&) final;
77     void didPutOrAdd(const WebCore::IDBResultData&) final;
78     void didGetRecord(const WebCore::IDBResultData&) final;
79     void didGetAllRecords(const WebCore::IDBResultData&) final;
80     void didGetCount(const WebCore::IDBResultData&) final;
81     void didDeleteRecord(const WebCore::IDBResultData&) final;
82     void didOpenCursor(const WebCore::IDBResultData&) final;
83     void didIterateCursor(const WebCore::IDBResultData&) final;
84
85     void fireVersionChangeEvent(WebCore::IDBServer::UniqueIDBDatabaseConnection&, const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion) final;
86     void didStartTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&) final;
87     void didCloseFromServer(WebCore::IDBServer::UniqueIDBDatabaseConnection&, const WebCore::IDBError&) final;
88     void notifyOpenDBRequestBlocked(const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion) final;
89
90     void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames) final;
91
92     void ref() override { RefCounted<WebIDBConnectionToClient>::ref(); }
93     void deref() override { RefCounted<WebIDBConnectionToClient>::deref(); }
94
95     // Messages received from WebProcess
96     void deleteDatabase(const WebCore::IDBRequestData&);
97     void openDatabase(const WebCore::IDBRequestData&);
98     void abortTransaction(const WebCore::IDBResourceIdentifier&);
99     void commitTransaction(const WebCore::IDBResourceIdentifier&);
100     void didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier&);
101     void createObjectStore(const WebCore::IDBRequestData&, const WebCore::IDBObjectStoreInfo&);
102     void deleteObjectStore(const WebCore::IDBRequestData&, const String& objectStoreName);
103     void renameObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName);
104     void clearObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier);
105     void createIndex(const WebCore::IDBRequestData&, const WebCore::IDBIndexInfo&);
106     void deleteIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName);
107     void renameIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
108     void putOrAdd(const WebCore::IDBRequestData&, const WebCore::IDBKeyData&, const WebCore::IDBValue&, unsigned overwriteMode);
109     void getRecord(const WebCore::IDBRequestData&, const WebCore::IDBGetRecordData&);
110     void getAllRecords(const WebCore::IDBRequestData&, const WebCore::IDBGetAllRecordsData&);
111     void getCount(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&);
112     void deleteRecord(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&);
113     void openCursor(const WebCore::IDBRequestData&, const WebCore::IDBCursorInfo&);
114     void iterateCursor(const WebCore::IDBRequestData&, const WebCore::IDBIterateCursorData&);
115
116     void establishTransaction(uint64_t databaseConnectionIdentifier, const WebCore::IDBTransactionInfo&);
117     void databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier);
118     void databaseConnectionClosed(uint64_t databaseConnectionIdentifier);
119     void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& transactionIdentifier);
120     void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& requestIdentifier);
121     void openDBRequestCancelled(const WebCore::IDBRequestData&);
122     void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier);
123
124     void getAllDatabaseNames(uint64_t serverConnectionIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& openingOrigin, uint64_t callbackID);
125
126     void disconnectedFromWebProcess();
127
128     void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
129
130 private:
131     WebIDBConnectionToClient(NetworkProcess&, NetworkConnectionToWebProcess&, uint64_t serverConnectionIdentifier, PAL::SessionID);
132
133     IPC::Connection* messageSenderConnection() final;
134
135     template<class MessageType> void handleGetResult(const WebCore::IDBResultData&);
136
137     Ref<NetworkConnectionToWebProcess> m_connection;
138     Ref<NetworkProcess> m_networkProcess;
139
140     uint64_t m_identifier;
141     PAL::SessionID m_sessionID;
142     RefPtr<WebCore::IDBServer::IDBConnectionToClient> m_connectionToClient;
143 };
144
145 } // namespace WebKit
146
147 #endif // ENABLE(INDEXED_DATABASE)