1 | /* |
2 | * Copyright (C) 2010-2018 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'' AND |
14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR |
17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
21 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | */ |
24 | |
25 | #include "config.h" |
26 | |
27 | #include "CacheStorageEngineConnection.h" |
28 | |
29 | #include "ArgumentCoders.h" |
30 | #include "CacheStorageEngineConnectionMessages.h" |
31 | #include "Decoder.h" |
32 | #include "HandleMessage.h" |
33 | #include "WebCoreArgumentCoders.h" |
34 | #include <WebCore/CacheQueryOptions.h> |
35 | #include <WebCore/ClientOrigin.h> |
36 | #include <WebCore/DOMCacheEngine.h> |
37 | #include <WebCore/ResourceRequest.h> |
38 | #include <pal/SessionID.h> |
39 | #include <wtf/Optional.h> |
40 | #include <wtf/Vector.h> |
41 | #include <wtf/text/WTFString.h> |
42 | |
43 | namespace Messages { |
44 | |
45 | namespace CacheStorageEngineConnection { |
46 | |
47 | void Open::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebCore::DOMCacheEngine::CacheIdentifierOrError&&)>&& completionHandler) |
48 | { |
49 | Optional<WebCore::DOMCacheEngine::CacheIdentifierOrError> result; |
50 | decoder >> result; |
51 | if (!result) { |
52 | ASSERT_NOT_REACHED(); |
53 | cancelReply(WTFMove(completionHandler)); |
54 | return; |
55 | } |
56 | completionHandler(WTFMove(*result)); |
57 | } |
58 | |
59 | void Open::cancelReply(CompletionHandler<void(WebCore::DOMCacheEngine::CacheIdentifierOrError&&)>&& completionHandler) |
60 | { |
61 | completionHandler(IPC::AsyncReplyError<WebCore::DOMCacheEngine::CacheIdentifierOrError>::create()); |
62 | } |
63 | |
64 | void Open::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebCore::DOMCacheEngine::CacheIdentifierOrError& result) |
65 | { |
66 | *encoder << result; |
67 | connection.sendSyncReply(WTFMove(encoder)); |
68 | } |
69 | |
70 | void Remove::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebCore::DOMCacheEngine::CacheIdentifierOrError&&)>&& completionHandler) |
71 | { |
72 | Optional<WebCore::DOMCacheEngine::CacheIdentifierOrError> result; |
73 | decoder >> result; |
74 | if (!result) { |
75 | ASSERT_NOT_REACHED(); |
76 | cancelReply(WTFMove(completionHandler)); |
77 | return; |
78 | } |
79 | completionHandler(WTFMove(*result)); |
80 | } |
81 | |
82 | void Remove::cancelReply(CompletionHandler<void(WebCore::DOMCacheEngine::CacheIdentifierOrError&&)>&& completionHandler) |
83 | { |
84 | completionHandler(IPC::AsyncReplyError<WebCore::DOMCacheEngine::CacheIdentifierOrError>::create()); |
85 | } |
86 | |
87 | void Remove::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebCore::DOMCacheEngine::CacheIdentifierOrError& result) |
88 | { |
89 | *encoder << result; |
90 | connection.sendSyncReply(WTFMove(encoder)); |
91 | } |
92 | |
93 | void Caches::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebCore::DOMCacheEngine::CacheInfosOrError&&)>&& completionHandler) |
94 | { |
95 | Optional<WebCore::DOMCacheEngine::CacheInfosOrError> result; |
96 | decoder >> result; |
97 | if (!result) { |
98 | ASSERT_NOT_REACHED(); |
99 | cancelReply(WTFMove(completionHandler)); |
100 | return; |
101 | } |
102 | completionHandler(WTFMove(*result)); |
103 | } |
104 | |
105 | void Caches::cancelReply(CompletionHandler<void(WebCore::DOMCacheEngine::CacheInfosOrError&&)>&& completionHandler) |
106 | { |
107 | completionHandler(IPC::AsyncReplyError<WebCore::DOMCacheEngine::CacheInfosOrError>::create()); |
108 | } |
109 | |
110 | void Caches::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebCore::DOMCacheEngine::CacheInfosOrError& result) |
111 | { |
112 | *encoder << result; |
113 | connection.sendSyncReply(WTFMove(encoder)); |
114 | } |
115 | |
116 | void RetrieveRecords::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebCore::DOMCacheEngine::RecordsOrError&&)>&& completionHandler) |
117 | { |
118 | Optional<WebCore::DOMCacheEngine::RecordsOrError> result; |
119 | decoder >> result; |
120 | if (!result) { |
121 | ASSERT_NOT_REACHED(); |
122 | cancelReply(WTFMove(completionHandler)); |
123 | return; |
124 | } |
125 | completionHandler(WTFMove(*result)); |
126 | } |
127 | |
128 | void RetrieveRecords::cancelReply(CompletionHandler<void(WebCore::DOMCacheEngine::RecordsOrError&&)>&& completionHandler) |
129 | { |
130 | completionHandler(IPC::AsyncReplyError<WebCore::DOMCacheEngine::RecordsOrError>::create()); |
131 | } |
132 | |
133 | void RetrieveRecords::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebCore::DOMCacheEngine::RecordsOrError& result) |
134 | { |
135 | *encoder << result; |
136 | connection.sendSyncReply(WTFMove(encoder)); |
137 | } |
138 | |
139 | void DeleteMatchingRecords::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebCore::DOMCacheEngine::RecordIdentifiersOrError&&)>&& completionHandler) |
140 | { |
141 | Optional<WebCore::DOMCacheEngine::RecordIdentifiersOrError> result; |
142 | decoder >> result; |
143 | if (!result) { |
144 | ASSERT_NOT_REACHED(); |
145 | cancelReply(WTFMove(completionHandler)); |
146 | return; |
147 | } |
148 | completionHandler(WTFMove(*result)); |
149 | } |
150 | |
151 | void DeleteMatchingRecords::cancelReply(CompletionHandler<void(WebCore::DOMCacheEngine::RecordIdentifiersOrError&&)>&& completionHandler) |
152 | { |
153 | completionHandler(IPC::AsyncReplyError<WebCore::DOMCacheEngine::RecordIdentifiersOrError>::create()); |
154 | } |
155 | |
156 | void DeleteMatchingRecords::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebCore::DOMCacheEngine::RecordIdentifiersOrError& result) |
157 | { |
158 | *encoder << result; |
159 | connection.sendSyncReply(WTFMove(encoder)); |
160 | } |
161 | |
162 | void PutRecords::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebCore::DOMCacheEngine::RecordIdentifiersOrError&&)>&& completionHandler) |
163 | { |
164 | Optional<WebCore::DOMCacheEngine::RecordIdentifiersOrError> result; |
165 | decoder >> result; |
166 | if (!result) { |
167 | ASSERT_NOT_REACHED(); |
168 | cancelReply(WTFMove(completionHandler)); |
169 | return; |
170 | } |
171 | completionHandler(WTFMove(*result)); |
172 | } |
173 | |
174 | void PutRecords::cancelReply(CompletionHandler<void(WebCore::DOMCacheEngine::RecordIdentifiersOrError&&)>&& completionHandler) |
175 | { |
176 | completionHandler(IPC::AsyncReplyError<WebCore::DOMCacheEngine::RecordIdentifiersOrError>::create()); |
177 | } |
178 | |
179 | void PutRecords::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebCore::DOMCacheEngine::RecordIdentifiersOrError& result) |
180 | { |
181 | *encoder << result; |
182 | connection.sendSyncReply(WTFMove(encoder)); |
183 | } |
184 | |
185 | void ClearMemoryRepresentation::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<WebCore::DOMCacheEngine::Error>&&)>&& completionHandler) |
186 | { |
187 | Optional<Optional<WebCore::DOMCacheEngine::Error>> error; |
188 | decoder >> error; |
189 | if (!error) { |
190 | ASSERT_NOT_REACHED(); |
191 | cancelReply(WTFMove(completionHandler)); |
192 | return; |
193 | } |
194 | completionHandler(WTFMove(*error)); |
195 | } |
196 | |
197 | void ClearMemoryRepresentation::cancelReply(CompletionHandler<void(Optional<WebCore::DOMCacheEngine::Error>&&)>&& completionHandler) |
198 | { |
199 | completionHandler(IPC::AsyncReplyError<Optional<WebCore::DOMCacheEngine::Error>>::create()); |
200 | } |
201 | |
202 | void ClearMemoryRepresentation::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<WebCore::DOMCacheEngine::Error>& error) |
203 | { |
204 | *encoder << error; |
205 | connection.sendSyncReply(WTFMove(encoder)); |
206 | } |
207 | |
208 | void EngineRepresentation::callReply(IPC::Decoder& decoder, CompletionHandler<void(String&&)>&& completionHandler) |
209 | { |
210 | Optional<String> representation; |
211 | decoder >> representation; |
212 | if (!representation) { |
213 | ASSERT_NOT_REACHED(); |
214 | cancelReply(WTFMove(completionHandler)); |
215 | return; |
216 | } |
217 | completionHandler(WTFMove(*representation)); |
218 | } |
219 | |
220 | void EngineRepresentation::cancelReply(CompletionHandler<void(String&&)>&& completionHandler) |
221 | { |
222 | completionHandler(IPC::AsyncReplyError<String>::create()); |
223 | } |
224 | |
225 | void EngineRepresentation::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const String& representation) |
226 | { |
227 | *encoder << representation; |
228 | connection.sendSyncReply(WTFMove(encoder)); |
229 | } |
230 | |
231 | } // namespace CacheStorageEngineConnection |
232 | |
233 | } // namespace Messages |
234 | |
235 | namespace WebKit { |
236 | |
237 | void CacheStorageEngineConnection::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
238 | { |
239 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::Reference::name()) { |
240 | IPC::handleMessage<Messages::CacheStorageEngineConnection::Reference>(decoder, this, &CacheStorageEngineConnection::reference); |
241 | return; |
242 | } |
243 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::Dereference::name()) { |
244 | IPC::handleMessage<Messages::CacheStorageEngineConnection::Dereference>(decoder, this, &CacheStorageEngineConnection::dereference); |
245 | return; |
246 | } |
247 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::Open::name()) { |
248 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::Open>(connection, decoder, this, &CacheStorageEngineConnection::open); |
249 | return; |
250 | } |
251 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::Remove::name()) { |
252 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::Remove>(connection, decoder, this, &CacheStorageEngineConnection::remove); |
253 | return; |
254 | } |
255 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::Caches::name()) { |
256 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::Caches>(connection, decoder, this, &CacheStorageEngineConnection::caches); |
257 | return; |
258 | } |
259 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::RetrieveRecords::name()) { |
260 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::RetrieveRecords>(connection, decoder, this, &CacheStorageEngineConnection::retrieveRecords); |
261 | return; |
262 | } |
263 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::DeleteMatchingRecords::name()) { |
264 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::DeleteMatchingRecords>(connection, decoder, this, &CacheStorageEngineConnection::deleteMatchingRecords); |
265 | return; |
266 | } |
267 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::PutRecords::name()) { |
268 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::PutRecords>(connection, decoder, this, &CacheStorageEngineConnection::putRecords); |
269 | return; |
270 | } |
271 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::ClearMemoryRepresentation::name()) { |
272 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::ClearMemoryRepresentation>(connection, decoder, this, &CacheStorageEngineConnection::clearMemoryRepresentation); |
273 | return; |
274 | } |
275 | if (decoder.messageName() == Messages::CacheStorageEngineConnection::EngineRepresentation::name()) { |
276 | IPC::handleMessageAsync<Messages::CacheStorageEngineConnection::EngineRepresentation>(connection, decoder, this, &CacheStorageEngineConnection::engineRepresentation); |
277 | return; |
278 | } |
279 | UNUSED_PARAM(connection); |
280 | UNUSED_PARAM(decoder); |
281 | ASSERT_NOT_REACHED(); |
282 | } |
283 | |
284 | } // namespace WebKit |
285 | |
286 | |