REGRESSION (r243606): Interacting with date and time pickers hangs the UI process...
[WebKit-https.git] / Source / WebCore / Modules / indexeddb / server / IDBConnectionToClient.cpp
1 /*
2  * Copyright (C) 2015 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 "IDBConnectionToClient.h"
28
29 #if ENABLE(INDEXED_DATABASE)
30
31 #include "UniqueIDBDatabaseConnection.h"
32
33 namespace WebCore {
34 namespace IDBServer {
35
36 Ref<IDBConnectionToClient> IDBConnectionToClient::create(IDBConnectionToClientDelegate& delegate)
37 {
38     return adoptRef(*new IDBConnectionToClient(delegate));
39 }
40
41 IDBConnectionToClient::IDBConnectionToClient(IDBConnectionToClientDelegate& delegate)
42     : m_delegate(makeWeakPtr(delegate))
43 {
44 }
45
46 IDBConnectionIdentifier IDBConnectionToClient::identifier() const
47 {
48     ASSERT(m_delegate);
49     return m_delegate->identifier();
50 }
51
52 void IDBConnectionToClient::didDeleteDatabase(const IDBResultData& result)
53 {
54     if (m_delegate)
55         m_delegate->didDeleteDatabase(result);
56 }
57
58 void IDBConnectionToClient::didOpenDatabase(const IDBResultData& result)
59 {
60     if (m_delegate)
61         m_delegate->didOpenDatabase(result);
62 }
63
64 void IDBConnectionToClient::didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
65 {
66     if (m_delegate)
67         m_delegate->didAbortTransaction(transactionIdentifier, error);
68 }
69
70 void IDBConnectionToClient::didCreateObjectStore(const IDBResultData& result)
71 {
72     if (m_delegate)
73         m_delegate->didCreateObjectStore(result);
74 }
75
76 void IDBConnectionToClient::didDeleteObjectStore(const IDBResultData& result)
77 {
78     if (m_delegate)
79         m_delegate->didDeleteObjectStore(result);
80 }
81
82 void IDBConnectionToClient::didRenameObjectStore(const IDBResultData& result)
83 {
84     if (m_delegate)
85         m_delegate->didRenameObjectStore(result);
86 }
87
88 void IDBConnectionToClient::didClearObjectStore(const IDBResultData& result)
89 {
90     if (m_delegate)
91         m_delegate->didClearObjectStore(result);
92 }
93
94 void IDBConnectionToClient::didCreateIndex(const IDBResultData& result)
95 {
96     if (m_delegate)
97         m_delegate->didCreateIndex(result);
98 }
99
100 void IDBConnectionToClient::didDeleteIndex(const IDBResultData& result)
101 {
102     if (m_delegate)
103         m_delegate->didDeleteIndex(result);
104 }
105
106 void IDBConnectionToClient::didRenameIndex(const IDBResultData& result)
107 {
108     if (m_delegate)
109         m_delegate->didRenameIndex(result);
110 }
111
112 void IDBConnectionToClient::didPutOrAdd(const IDBResultData& result)
113 {
114     if (m_delegate)
115         m_delegate->didPutOrAdd(result);
116 }
117
118 void IDBConnectionToClient::didGetRecord(const IDBResultData& result)
119 {
120     if (m_delegate)
121         m_delegate->didGetRecord(result);
122 }
123
124 void IDBConnectionToClient::didGetAllRecords(const IDBResultData& result)
125 {
126     if (m_delegate)
127         m_delegate->didGetAllRecords(result);
128 }
129
130 void IDBConnectionToClient::didGetCount(const IDBResultData& result)
131 {
132     if (m_delegate)
133         m_delegate->didGetCount(result);
134 }
135
136 void IDBConnectionToClient::didDeleteRecord(const IDBResultData& result)
137 {
138     if (m_delegate)
139         m_delegate->didDeleteRecord(result);
140 }
141
142 void IDBConnectionToClient::didOpenCursor(const IDBResultData& result)
143 {
144     if (m_delegate)
145         m_delegate->didOpenCursor(result);
146 }
147
148 void IDBConnectionToClient::didIterateCursor(const IDBResultData& result)
149 {
150     if (m_delegate)
151         m_delegate->didIterateCursor(result);
152 }
153
154 void IDBConnectionToClient::didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
155 {
156     if (m_delegate)
157         m_delegate->didCommitTransaction(transactionIdentifier, error);
158 }
159
160 void IDBConnectionToClient::fireVersionChangeEvent(UniqueIDBDatabaseConnection& connection, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion)
161 {
162     if (m_delegate)
163         m_delegate->fireVersionChangeEvent(connection, requestIdentifier, requestedVersion);
164 }
165
166 void IDBConnectionToClient::didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError& error)
167 {
168     if (m_delegate)
169         m_delegate->didStartTransaction(transactionIdentifier, error);
170 }
171
172 void IDBConnectionToClient::didCloseFromServer(UniqueIDBDatabaseConnection& connection, const IDBError& error)
173 {
174     if (m_delegate)
175         m_delegate->didCloseFromServer(connection, error);
176 }
177
178 void IDBConnectionToClient::notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
179 {
180     if (m_delegate)
181         m_delegate->notifyOpenDBRequestBlocked(requestIdentifier, oldVersion, newVersion);
182 }
183
184 void IDBConnectionToClient::didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames)
185 {
186     if (m_delegate)
187         m_delegate->didGetAllDatabaseNames(callbackID, databaseNames);
188 }
189
190 void IDBConnectionToClient::registerDatabaseConnection(UniqueIDBDatabaseConnection& connection)
191 {
192     ASSERT(!m_databaseConnections.contains(&connection));
193     m_databaseConnections.add(&connection);
194 }
195
196 void IDBConnectionToClient::unregisterDatabaseConnection(UniqueIDBDatabaseConnection& connection)
197 {
198     m_databaseConnections.remove(&connection);
199 }
200
201 void IDBConnectionToClient::connectionToClientClosed()
202 {
203     auto databaseConnections = m_databaseConnections;
204
205     for (auto connection : databaseConnections) {
206         if (m_databaseConnections.contains(connection))
207             connection->connectionClosedFromClient();
208     }
209
210     m_isClosed = true;
211     m_databaseConnections.clear();
212 }
213
214 } // namespace IDBServer
215 } // namespace WebCore
216
217 #endif // ENABLE(INDEXED_DATABASE)