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 "WebAutomationSessionProxy.h" |
28 | |
29 | #include "ArgumentCoders.h" |
30 | #include "CoordinateSystem.h" |
31 | #include "Decoder.h" |
32 | #include "HandleMessage.h" |
33 | #include "WebAutomationSessionProxyMessages.h" |
34 | #include "WebCoreArgumentCoders.h" |
35 | #include <WebCore/Cookie.h> |
36 | #include <WebCore/IntPoint.h> |
37 | #include <WebCore/IntRect.h> |
38 | #include <WebCore/PageIdentifier.h> |
39 | #include <wtf/Optional.h> |
40 | #include <wtf/Vector.h> |
41 | #include <wtf/text/WTFString.h> |
42 | |
43 | namespace Messages { |
44 | |
45 | namespace WebAutomationSessionProxy { |
46 | |
47 | void ResolveChildFrameWithOrdinal::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
48 | { |
49 | Optional<Optional<String>> errorType; |
50 | decoder >> errorType; |
51 | if (!errorType) { |
52 | ASSERT_NOT_REACHED(); |
53 | cancelReply(WTFMove(completionHandler)); |
54 | return; |
55 | } |
56 | Optional<uint64_t> frameID; |
57 | decoder >> frameID; |
58 | if (!frameID) { |
59 | ASSERT_NOT_REACHED(); |
60 | cancelReply(WTFMove(completionHandler)); |
61 | return; |
62 | } |
63 | completionHandler(WTFMove(*errorType), WTFMove(*frameID)); |
64 | } |
65 | |
66 | void ResolveChildFrameWithOrdinal::cancelReply(CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
67 | { |
68 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create(), IPC::AsyncReplyError<uint64_t>::create()); |
69 | } |
70 | |
71 | void ResolveChildFrameWithOrdinal::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType, uint64_t frameID) |
72 | { |
73 | *encoder << errorType; |
74 | *encoder << frameID; |
75 | connection.sendSyncReply(WTFMove(encoder)); |
76 | } |
77 | |
78 | void ResolveChildFrameWithNodeHandle::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
79 | { |
80 | Optional<Optional<String>> errorType; |
81 | decoder >> errorType; |
82 | if (!errorType) { |
83 | ASSERT_NOT_REACHED(); |
84 | cancelReply(WTFMove(completionHandler)); |
85 | return; |
86 | } |
87 | Optional<uint64_t> frameID; |
88 | decoder >> frameID; |
89 | if (!frameID) { |
90 | ASSERT_NOT_REACHED(); |
91 | cancelReply(WTFMove(completionHandler)); |
92 | return; |
93 | } |
94 | completionHandler(WTFMove(*errorType), WTFMove(*frameID)); |
95 | } |
96 | |
97 | void ResolveChildFrameWithNodeHandle::cancelReply(CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
98 | { |
99 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create(), IPC::AsyncReplyError<uint64_t>::create()); |
100 | } |
101 | |
102 | void ResolveChildFrameWithNodeHandle::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType, uint64_t frameID) |
103 | { |
104 | *encoder << errorType; |
105 | *encoder << frameID; |
106 | connection.sendSyncReply(WTFMove(encoder)); |
107 | } |
108 | |
109 | void ResolveChildFrameWithName::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
110 | { |
111 | Optional<Optional<String>> errorType; |
112 | decoder >> errorType; |
113 | if (!errorType) { |
114 | ASSERT_NOT_REACHED(); |
115 | cancelReply(WTFMove(completionHandler)); |
116 | return; |
117 | } |
118 | Optional<uint64_t> frameID; |
119 | decoder >> frameID; |
120 | if (!frameID) { |
121 | ASSERT_NOT_REACHED(); |
122 | cancelReply(WTFMove(completionHandler)); |
123 | return; |
124 | } |
125 | completionHandler(WTFMove(*errorType), WTFMove(*frameID)); |
126 | } |
127 | |
128 | void ResolveChildFrameWithName::cancelReply(CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
129 | { |
130 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create(), IPC::AsyncReplyError<uint64_t>::create()); |
131 | } |
132 | |
133 | void ResolveChildFrameWithName::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType, uint64_t frameID) |
134 | { |
135 | *encoder << errorType; |
136 | *encoder << frameID; |
137 | connection.sendSyncReply(WTFMove(encoder)); |
138 | } |
139 | |
140 | void ResolveParentFrame::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
141 | { |
142 | Optional<Optional<String>> errorType; |
143 | decoder >> errorType; |
144 | if (!errorType) { |
145 | ASSERT_NOT_REACHED(); |
146 | cancelReply(WTFMove(completionHandler)); |
147 | return; |
148 | } |
149 | Optional<uint64_t> frameID; |
150 | decoder >> frameID; |
151 | if (!frameID) { |
152 | ASSERT_NOT_REACHED(); |
153 | cancelReply(WTFMove(completionHandler)); |
154 | return; |
155 | } |
156 | completionHandler(WTFMove(*errorType), WTFMove(*frameID)); |
157 | } |
158 | |
159 | void ResolveParentFrame::cancelReply(CompletionHandler<void(Optional<String>&&, uint64_t&&)>&& completionHandler) |
160 | { |
161 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create(), IPC::AsyncReplyError<uint64_t>::create()); |
162 | } |
163 | |
164 | void ResolveParentFrame::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType, uint64_t frameID) |
165 | { |
166 | *encoder << errorType; |
167 | *encoder << frameID; |
168 | connection.sendSyncReply(WTFMove(encoder)); |
169 | } |
170 | |
171 | void ComputeElementLayout::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&, WebCore::IntRect&&, Optional<WebCore::IntPoint>&&, bool&&)>&& completionHandler) |
172 | { |
173 | Optional<Optional<String>> errorType; |
174 | decoder >> errorType; |
175 | if (!errorType) { |
176 | ASSERT_NOT_REACHED(); |
177 | cancelReply(WTFMove(completionHandler)); |
178 | return; |
179 | } |
180 | Optional<WebCore::IntRect> rect; |
181 | decoder >> rect; |
182 | if (!rect) { |
183 | ASSERT_NOT_REACHED(); |
184 | cancelReply(WTFMove(completionHandler)); |
185 | return; |
186 | } |
187 | Optional<Optional<WebCore::IntPoint>> inViewCenterPoint; |
188 | decoder >> inViewCenterPoint; |
189 | if (!inViewCenterPoint) { |
190 | ASSERT_NOT_REACHED(); |
191 | cancelReply(WTFMove(completionHandler)); |
192 | return; |
193 | } |
194 | Optional<bool> isObscured; |
195 | decoder >> isObscured; |
196 | if (!isObscured) { |
197 | ASSERT_NOT_REACHED(); |
198 | cancelReply(WTFMove(completionHandler)); |
199 | return; |
200 | } |
201 | completionHandler(WTFMove(*errorType), WTFMove(*rect), WTFMove(*inViewCenterPoint), WTFMove(*isObscured)); |
202 | } |
203 | |
204 | void ComputeElementLayout::cancelReply(CompletionHandler<void(Optional<String>&&, WebCore::IntRect&&, Optional<WebCore::IntPoint>&&, bool&&)>&& completionHandler) |
205 | { |
206 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create(), IPC::AsyncReplyError<WebCore::IntRect>::create(), IPC::AsyncReplyError<Optional<WebCore::IntPoint>>::create(), IPC::AsyncReplyError<bool>::create()); |
207 | } |
208 | |
209 | void ComputeElementLayout::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType, const WebCore::IntRect& rect, const Optional<WebCore::IntPoint>& inViewCenterPoint, bool isObscured) |
210 | { |
211 | *encoder << errorType; |
212 | *encoder << rect; |
213 | *encoder << inViewCenterPoint; |
214 | *encoder << isObscured; |
215 | connection.sendSyncReply(WTFMove(encoder)); |
216 | } |
217 | |
218 | void SelectOptionElement::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&)>&& completionHandler) |
219 | { |
220 | Optional<Optional<String>> errorType; |
221 | decoder >> errorType; |
222 | if (!errorType) { |
223 | ASSERT_NOT_REACHED(); |
224 | cancelReply(WTFMove(completionHandler)); |
225 | return; |
226 | } |
227 | completionHandler(WTFMove(*errorType)); |
228 | } |
229 | |
230 | void SelectOptionElement::cancelReply(CompletionHandler<void(Optional<String>&&)>&& completionHandler) |
231 | { |
232 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create()); |
233 | } |
234 | |
235 | void SelectOptionElement::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType) |
236 | { |
237 | *encoder << errorType; |
238 | connection.sendSyncReply(WTFMove(encoder)); |
239 | } |
240 | |
241 | void GetCookiesForFrame::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&, Vector<WebCore::Cookie>&&)>&& completionHandler) |
242 | { |
243 | Optional<Optional<String>> errorType; |
244 | decoder >> errorType; |
245 | if (!errorType) { |
246 | ASSERT_NOT_REACHED(); |
247 | cancelReply(WTFMove(completionHandler)); |
248 | return; |
249 | } |
250 | Optional<Vector<WebCore::Cookie>> cookies; |
251 | decoder >> cookies; |
252 | if (!cookies) { |
253 | ASSERT_NOT_REACHED(); |
254 | cancelReply(WTFMove(completionHandler)); |
255 | return; |
256 | } |
257 | completionHandler(WTFMove(*errorType), WTFMove(*cookies)); |
258 | } |
259 | |
260 | void GetCookiesForFrame::cancelReply(CompletionHandler<void(Optional<String>&&, Vector<WebCore::Cookie>&&)>&& completionHandler) |
261 | { |
262 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create(), IPC::AsyncReplyError<Vector<WebCore::Cookie>>::create()); |
263 | } |
264 | |
265 | void GetCookiesForFrame::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType, const Vector<WebCore::Cookie>& cookies) |
266 | { |
267 | *encoder << errorType; |
268 | *encoder << cookies; |
269 | connection.sendSyncReply(WTFMove(encoder)); |
270 | } |
271 | |
272 | void DeleteCookie::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<String>&&)>&& completionHandler) |
273 | { |
274 | Optional<Optional<String>> errorType; |
275 | decoder >> errorType; |
276 | if (!errorType) { |
277 | ASSERT_NOT_REACHED(); |
278 | cancelReply(WTFMove(completionHandler)); |
279 | return; |
280 | } |
281 | completionHandler(WTFMove(*errorType)); |
282 | } |
283 | |
284 | void DeleteCookie::cancelReply(CompletionHandler<void(Optional<String>&&)>&& completionHandler) |
285 | { |
286 | completionHandler(IPC::AsyncReplyError<Optional<String>>::create()); |
287 | } |
288 | |
289 | void DeleteCookie::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<String>& errorType) |
290 | { |
291 | *encoder << errorType; |
292 | connection.sendSyncReply(WTFMove(encoder)); |
293 | } |
294 | |
295 | } // namespace WebAutomationSessionProxy |
296 | |
297 | } // namespace Messages |
298 | |
299 | namespace WebKit { |
300 | |
301 | void WebAutomationSessionProxy::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
302 | { |
303 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::EvaluateJavaScriptFunction::name()) { |
304 | IPC::handleMessage<Messages::WebAutomationSessionProxy::EvaluateJavaScriptFunction>(decoder, this, &WebAutomationSessionProxy::evaluateJavaScriptFunction); |
305 | return; |
306 | } |
307 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::ResolveChildFrameWithOrdinal::name()) { |
308 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::ResolveChildFrameWithOrdinal>(connection, decoder, this, &WebAutomationSessionProxy::resolveChildFrameWithOrdinal); |
309 | return; |
310 | } |
311 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::ResolveChildFrameWithNodeHandle::name()) { |
312 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::ResolveChildFrameWithNodeHandle>(connection, decoder, this, &WebAutomationSessionProxy::resolveChildFrameWithNodeHandle); |
313 | return; |
314 | } |
315 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::ResolveChildFrameWithName::name()) { |
316 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::ResolveChildFrameWithName>(connection, decoder, this, &WebAutomationSessionProxy::resolveChildFrameWithName); |
317 | return; |
318 | } |
319 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::ResolveParentFrame::name()) { |
320 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::ResolveParentFrame>(connection, decoder, this, &WebAutomationSessionProxy::resolveParentFrame); |
321 | return; |
322 | } |
323 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::FocusFrame::name()) { |
324 | IPC::handleMessage<Messages::WebAutomationSessionProxy::FocusFrame>(decoder, this, &WebAutomationSessionProxy::focusFrame); |
325 | return; |
326 | } |
327 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::ComputeElementLayout::name()) { |
328 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::ComputeElementLayout>(connection, decoder, this, &WebAutomationSessionProxy::computeElementLayout); |
329 | return; |
330 | } |
331 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::SelectOptionElement::name()) { |
332 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::SelectOptionElement>(connection, decoder, this, &WebAutomationSessionProxy::selectOptionElement); |
333 | return; |
334 | } |
335 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::TakeScreenshot::name()) { |
336 | IPC::handleMessage<Messages::WebAutomationSessionProxy::TakeScreenshot>(decoder, this, &WebAutomationSessionProxy::takeScreenshot); |
337 | return; |
338 | } |
339 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::GetCookiesForFrame::name()) { |
340 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::GetCookiesForFrame>(connection, decoder, this, &WebAutomationSessionProxy::getCookiesForFrame); |
341 | return; |
342 | } |
343 | if (decoder.messageName() == Messages::WebAutomationSessionProxy::DeleteCookie::name()) { |
344 | IPC::handleMessageAsync<Messages::WebAutomationSessionProxy::DeleteCookie>(connection, decoder, this, &WebAutomationSessionProxy::deleteCookie); |
345 | return; |
346 | } |
347 | UNUSED_PARAM(connection); |
348 | UNUSED_PARAM(decoder); |
349 | ASSERT_NOT_REACHED(); |
350 | } |
351 | |
352 | } // namespace WebKit |
353 | |
354 | |