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