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