1 | /* |
2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
3 | * Copyright (C) 2013-2016 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2014 University of Washington. All rights reserved. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
17 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
19 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | * THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | // DO NOT EDIT THIS FILE. It is automatically generated from CombinedDomains.json |
29 | // by the script: Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py |
30 | |
31 | #include "config.h" |
32 | #include "InspectorBackendDispatchers.h" |
33 | |
34 | #include "InspectorFrontendRouter.h" |
35 | #include <wtf/JSONValues.h> |
36 | #include <wtf/NeverDestroyed.h> |
37 | #include <wtf/text/CString.h> |
38 | |
39 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
40 | #include "InspectorAlternateBackendDispatchers.h" |
41 | #endif |
42 | |
43 | namespace Inspector { |
44 | |
45 | ApplicationCacheBackendDispatcherHandler::~ApplicationCacheBackendDispatcherHandler() { } |
46 | AuditBackendDispatcherHandler::~AuditBackendDispatcherHandler() { } |
47 | #if ENABLE(RESOURCE_USAGE) |
48 | CPUProfilerBackendDispatcherHandler::~CPUProfilerBackendDispatcherHandler() { } |
49 | #endif // ENABLE(RESOURCE_USAGE) |
50 | CSSBackendDispatcherHandler::~CSSBackendDispatcherHandler() { } |
51 | CanvasBackendDispatcherHandler::~CanvasBackendDispatcherHandler() { } |
52 | ConsoleBackendDispatcherHandler::~ConsoleBackendDispatcherHandler() { } |
53 | DOMBackendDispatcherHandler::~DOMBackendDispatcherHandler() { } |
54 | DOMDebuggerBackendDispatcherHandler::~DOMDebuggerBackendDispatcherHandler() { } |
55 | DOMStorageBackendDispatcherHandler::~DOMStorageBackendDispatcherHandler() { } |
56 | DatabaseBackendDispatcherHandler::~DatabaseBackendDispatcherHandler() { } |
57 | DebuggerBackendDispatcherHandler::~DebuggerBackendDispatcherHandler() { } |
58 | HeapBackendDispatcherHandler::~HeapBackendDispatcherHandler() { } |
59 | #if ENABLE(INDEXED_DATABASE) |
60 | IndexedDBBackendDispatcherHandler::~IndexedDBBackendDispatcherHandler() { } |
61 | #endif // ENABLE(INDEXED_DATABASE) |
62 | InspectorBackendDispatcherHandler::~InspectorBackendDispatcherHandler() { } |
63 | LayerTreeBackendDispatcherHandler::~LayerTreeBackendDispatcherHandler() { } |
64 | #if ENABLE(RESOURCE_USAGE) |
65 | MemoryBackendDispatcherHandler::~MemoryBackendDispatcherHandler() { } |
66 | #endif // ENABLE(RESOURCE_USAGE) |
67 | NetworkBackendDispatcherHandler::~NetworkBackendDispatcherHandler() { } |
68 | PageBackendDispatcherHandler::~PageBackendDispatcherHandler() { } |
69 | RuntimeBackendDispatcherHandler::~RuntimeBackendDispatcherHandler() { } |
70 | ScriptProfilerBackendDispatcherHandler::~ScriptProfilerBackendDispatcherHandler() { } |
71 | ServiceWorkerBackendDispatcherHandler::~ServiceWorkerBackendDispatcherHandler() { } |
72 | TargetBackendDispatcherHandler::~TargetBackendDispatcherHandler() { } |
73 | TimelineBackendDispatcherHandler::~TimelineBackendDispatcherHandler() { } |
74 | WorkerBackendDispatcherHandler::~WorkerBackendDispatcherHandler() { } |
75 | |
76 | Ref<ApplicationCacheBackendDispatcher> ApplicationCacheBackendDispatcher::create(BackendDispatcher& backendDispatcher, ApplicationCacheBackendDispatcherHandler* agent) |
77 | { |
78 | return adoptRef(*new ApplicationCacheBackendDispatcher(backendDispatcher, agent)); |
79 | } |
80 | |
81 | ApplicationCacheBackendDispatcher::ApplicationCacheBackendDispatcher(BackendDispatcher& backendDispatcher, ApplicationCacheBackendDispatcherHandler* agent) |
82 | : SupplementalBackendDispatcher(backendDispatcher) |
83 | , m_agent(agent) |
84 | { |
85 | m_backendDispatcher->registerDispatcherForDomain("ApplicationCache"_s , this); |
86 | } |
87 | |
88 | void ApplicationCacheBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
89 | { |
90 | Ref<ApplicationCacheBackendDispatcher> protect(*this); |
91 | |
92 | RefPtr<JSON::Object> parameters; |
93 | message->getObject("params"_s , parameters); |
94 | |
95 | if (method == "getFramesWithManifests" ) |
96 | getFramesWithManifests(requestId, WTFMove(parameters)); |
97 | else if (method == "enable" ) |
98 | enable(requestId, WTFMove(parameters)); |
99 | else if (method == "getManifestForFrame" ) |
100 | getManifestForFrame(requestId, WTFMove(parameters)); |
101 | else if (method == "getApplicationCacheForFrame" ) |
102 | getApplicationCacheForFrame(requestId, WTFMove(parameters)); |
103 | else |
104 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'ApplicationCache." + method + "' was not found" ); |
105 | } |
106 | |
107 | void ApplicationCacheBackendDispatcher::getFramesWithManifests(long requestId, RefPtr<JSON::Object>&&) |
108 | { |
109 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
110 | if (m_alternateDispatcher) { |
111 | m_alternateDispatcher->getFramesWithManifests(requestId); |
112 | return; |
113 | } |
114 | #endif |
115 | |
116 | ErrorString error; |
117 | Ref<JSON::Object> result = JSON::Object::create(); |
118 | RefPtr<JSON::ArrayOf<Inspector::Protocol::ApplicationCache::FrameWithManifest>> out_frameIds; |
119 | m_agent->getFramesWithManifests(error, out_frameIds); |
120 | |
121 | if (!error.length()) |
122 | result->setArray("frameIds"_s , out_frameIds); |
123 | |
124 | if (!error.length()) |
125 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
126 | else |
127 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
128 | } |
129 | |
130 | void ApplicationCacheBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
131 | { |
132 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
133 | if (m_alternateDispatcher) { |
134 | m_alternateDispatcher->enable(requestId); |
135 | return; |
136 | } |
137 | #endif |
138 | |
139 | ErrorString error; |
140 | Ref<JSON::Object> result = JSON::Object::create(); |
141 | m_agent->enable(error); |
142 | |
143 | if (!error.length()) |
144 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
145 | else |
146 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
147 | } |
148 | |
149 | void ApplicationCacheBackendDispatcher::getManifestForFrame(long requestId, RefPtr<JSON::Object>&& parameters) |
150 | { |
151 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
152 | if (m_backendDispatcher->hasProtocolErrors()) { |
153 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'ApplicationCache.getManifestForFrame' can't be processed"_s ); |
154 | return; |
155 | } |
156 | |
157 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
158 | if (m_alternateDispatcher) { |
159 | m_alternateDispatcher->getManifestForFrame(requestId, in_frameId); |
160 | return; |
161 | } |
162 | #endif |
163 | |
164 | ErrorString error; |
165 | Ref<JSON::Object> result = JSON::Object::create(); |
166 | String out_manifestURL; |
167 | m_agent->getManifestForFrame(error, in_frameId, &out_manifestURL); |
168 | |
169 | if (!error.length()) |
170 | result->setString("manifestURL"_s , out_manifestURL); |
171 | |
172 | if (!error.length()) |
173 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
174 | else |
175 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
176 | } |
177 | |
178 | void ApplicationCacheBackendDispatcher::getApplicationCacheForFrame(long requestId, RefPtr<JSON::Object>&& parameters) |
179 | { |
180 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
181 | if (m_backendDispatcher->hasProtocolErrors()) { |
182 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'ApplicationCache.getApplicationCacheForFrame' can't be processed"_s ); |
183 | return; |
184 | } |
185 | |
186 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
187 | if (m_alternateDispatcher) { |
188 | m_alternateDispatcher->getApplicationCacheForFrame(requestId, in_frameId); |
189 | return; |
190 | } |
191 | #endif |
192 | |
193 | ErrorString error; |
194 | Ref<JSON::Object> result = JSON::Object::create(); |
195 | RefPtr<Inspector::Protocol::ApplicationCache::ApplicationCache> out_applicationCache; |
196 | m_agent->getApplicationCacheForFrame(error, in_frameId, out_applicationCache); |
197 | |
198 | if (!error.length()) |
199 | result->setObject("applicationCache"_s , out_applicationCache); |
200 | |
201 | if (!error.length()) |
202 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
203 | else |
204 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
205 | } |
206 | |
207 | Ref<AuditBackendDispatcher> AuditBackendDispatcher::create(BackendDispatcher& backendDispatcher, AuditBackendDispatcherHandler* agent) |
208 | { |
209 | return adoptRef(*new AuditBackendDispatcher(backendDispatcher, agent)); |
210 | } |
211 | |
212 | AuditBackendDispatcher::AuditBackendDispatcher(BackendDispatcher& backendDispatcher, AuditBackendDispatcherHandler* agent) |
213 | : SupplementalBackendDispatcher(backendDispatcher) |
214 | , m_agent(agent) |
215 | { |
216 | m_backendDispatcher->registerDispatcherForDomain("Audit"_s , this); |
217 | } |
218 | |
219 | void AuditBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
220 | { |
221 | Ref<AuditBackendDispatcher> protect(*this); |
222 | |
223 | RefPtr<JSON::Object> parameters; |
224 | message->getObject("params"_s , parameters); |
225 | |
226 | if (method == "setup" ) |
227 | setup(requestId, WTFMove(parameters)); |
228 | else if (method == "run" ) |
229 | run(requestId, WTFMove(parameters)); |
230 | else if (method == "teardown" ) |
231 | teardown(requestId, WTFMove(parameters)); |
232 | else |
233 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Audit." + method + "' was not found" ); |
234 | } |
235 | |
236 | void AuditBackendDispatcher::setup(long requestId, RefPtr<JSON::Object>&& parameters) |
237 | { |
238 | bool opt_in_contextId_valueFound = false; |
239 | int opt_in_contextId = m_backendDispatcher->getInteger(parameters.get(), "contextId"_s , &opt_in_contextId_valueFound); |
240 | if (m_backendDispatcher->hasProtocolErrors()) { |
241 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Audit.setup' can't be processed"_s ); |
242 | return; |
243 | } |
244 | |
245 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
246 | if (m_alternateDispatcher) { |
247 | m_alternateDispatcher->setup(requestId, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr); |
248 | return; |
249 | } |
250 | #endif |
251 | |
252 | ErrorString error; |
253 | Ref<JSON::Object> result = JSON::Object::create(); |
254 | m_agent->setup(error, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr); |
255 | |
256 | if (!error.length()) |
257 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
258 | else |
259 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
260 | } |
261 | |
262 | void AuditBackendDispatcher::run(long requestId, RefPtr<JSON::Object>&& parameters) |
263 | { |
264 | String in_test = m_backendDispatcher->getString(parameters.get(), "test"_s , nullptr); |
265 | bool opt_in_contextId_valueFound = false; |
266 | int opt_in_contextId = m_backendDispatcher->getInteger(parameters.get(), "contextId"_s , &opt_in_contextId_valueFound); |
267 | if (m_backendDispatcher->hasProtocolErrors()) { |
268 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Audit.run' can't be processed"_s ); |
269 | return; |
270 | } |
271 | |
272 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
273 | if (m_alternateDispatcher) { |
274 | m_alternateDispatcher->run(requestId, in_test, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr); |
275 | return; |
276 | } |
277 | #endif |
278 | |
279 | ErrorString error; |
280 | Ref<JSON::Object> result = JSON::Object::create(); |
281 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_result; |
282 | Optional<bool> out_wasThrown; |
283 | m_agent->run(error, in_test, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr, out_result, out_wasThrown); |
284 | |
285 | if (!error.length()) { |
286 | result->setObject("result"_s , out_result); |
287 | if (out_wasThrown.hasValue()) |
288 | result->setBoolean("wasThrown"_s , *out_wasThrown); |
289 | } |
290 | if (!error.length()) |
291 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
292 | else |
293 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
294 | } |
295 | |
296 | void AuditBackendDispatcher::teardown(long requestId, RefPtr<JSON::Object>&&) |
297 | { |
298 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
299 | if (m_alternateDispatcher) { |
300 | m_alternateDispatcher->teardown(requestId); |
301 | return; |
302 | } |
303 | #endif |
304 | |
305 | ErrorString error; |
306 | Ref<JSON::Object> result = JSON::Object::create(); |
307 | m_agent->teardown(error); |
308 | |
309 | if (!error.length()) |
310 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
311 | else |
312 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
313 | } |
314 | |
315 | #if ENABLE(RESOURCE_USAGE) |
316 | Ref<CPUProfilerBackendDispatcher> CPUProfilerBackendDispatcher::create(BackendDispatcher& backendDispatcher, CPUProfilerBackendDispatcherHandler* agent) |
317 | { |
318 | return adoptRef(*new CPUProfilerBackendDispatcher(backendDispatcher, agent)); |
319 | } |
320 | |
321 | CPUProfilerBackendDispatcher::CPUProfilerBackendDispatcher(BackendDispatcher& backendDispatcher, CPUProfilerBackendDispatcherHandler* agent) |
322 | : SupplementalBackendDispatcher(backendDispatcher) |
323 | , m_agent(agent) |
324 | { |
325 | m_backendDispatcher->registerDispatcherForDomain("CPUProfiler"_s , this); |
326 | } |
327 | |
328 | void CPUProfilerBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
329 | { |
330 | Ref<CPUProfilerBackendDispatcher> protect(*this); |
331 | |
332 | RefPtr<JSON::Object> parameters; |
333 | message->getObject("params"_s , parameters); |
334 | |
335 | if (method == "startTracking" ) |
336 | startTracking(requestId, WTFMove(parameters)); |
337 | else if (method == "stopTracking" ) |
338 | stopTracking(requestId, WTFMove(parameters)); |
339 | else |
340 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'CPUProfiler." + method + "' was not found" ); |
341 | } |
342 | |
343 | void CPUProfilerBackendDispatcher::startTracking(long requestId, RefPtr<JSON::Object>&&) |
344 | { |
345 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
346 | if (m_alternateDispatcher) { |
347 | m_alternateDispatcher->startTracking(requestId); |
348 | return; |
349 | } |
350 | #endif |
351 | |
352 | ErrorString error; |
353 | Ref<JSON::Object> result = JSON::Object::create(); |
354 | m_agent->startTracking(error); |
355 | |
356 | if (!error.length()) |
357 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
358 | else |
359 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
360 | } |
361 | |
362 | void CPUProfilerBackendDispatcher::stopTracking(long requestId, RefPtr<JSON::Object>&&) |
363 | { |
364 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
365 | if (m_alternateDispatcher) { |
366 | m_alternateDispatcher->stopTracking(requestId); |
367 | return; |
368 | } |
369 | #endif |
370 | |
371 | ErrorString error; |
372 | Ref<JSON::Object> result = JSON::Object::create(); |
373 | m_agent->stopTracking(error); |
374 | |
375 | if (!error.length()) |
376 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
377 | else |
378 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
379 | } |
380 | #endif // ENABLE(RESOURCE_USAGE) |
381 | |
382 | Ref<CSSBackendDispatcher> CSSBackendDispatcher::create(BackendDispatcher& backendDispatcher, CSSBackendDispatcherHandler* agent) |
383 | { |
384 | return adoptRef(*new CSSBackendDispatcher(backendDispatcher, agent)); |
385 | } |
386 | |
387 | CSSBackendDispatcher::CSSBackendDispatcher(BackendDispatcher& backendDispatcher, CSSBackendDispatcherHandler* agent) |
388 | : SupplementalBackendDispatcher(backendDispatcher) |
389 | , m_agent(agent) |
390 | { |
391 | m_backendDispatcher->registerDispatcherForDomain("CSS"_s , this); |
392 | } |
393 | |
394 | void CSSBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
395 | { |
396 | Ref<CSSBackendDispatcher> protect(*this); |
397 | |
398 | RefPtr<JSON::Object> parameters; |
399 | message->getObject("params"_s , parameters); |
400 | |
401 | typedef void (CSSBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
402 | typedef HashMap<String, CallHandler> DispatchMap; |
403 | static NeverDestroyed<DispatchMap> dispatchMap; |
404 | if (dispatchMap.get().isEmpty()) { |
405 | static const struct MethodTable { |
406 | const char* name; |
407 | CallHandler handler; |
408 | } commands[] = { |
409 | { "enable" , &CSSBackendDispatcher::enable }, |
410 | { "disable" , &CSSBackendDispatcher::disable }, |
411 | { "getMatchedStylesForNode" , &CSSBackendDispatcher::getMatchedStylesForNode }, |
412 | { "getInlineStylesForNode" , &CSSBackendDispatcher::getInlineStylesForNode }, |
413 | { "getComputedStyleForNode" , &CSSBackendDispatcher::getComputedStyleForNode }, |
414 | { "getAllStyleSheets" , &CSSBackendDispatcher::getAllStyleSheets }, |
415 | { "getStyleSheet" , &CSSBackendDispatcher::getStyleSheet }, |
416 | { "getStyleSheetText" , &CSSBackendDispatcher::getStyleSheetText }, |
417 | { "setStyleSheetText" , &CSSBackendDispatcher::setStyleSheetText }, |
418 | { "setStyleText" , &CSSBackendDispatcher::setStyleText }, |
419 | { "setRuleSelector" , &CSSBackendDispatcher::setRuleSelector }, |
420 | { "createStyleSheet" , &CSSBackendDispatcher::createStyleSheet }, |
421 | { "addRule" , &CSSBackendDispatcher::addRule }, |
422 | { "getSupportedCSSProperties" , &CSSBackendDispatcher::getSupportedCSSProperties }, |
423 | { "getSupportedSystemFontFamilyNames" , &CSSBackendDispatcher::getSupportedSystemFontFamilyNames }, |
424 | { "forcePseudoState" , &CSSBackendDispatcher::forcePseudoState }, |
425 | }; |
426 | size_t length = WTF_ARRAY_LENGTH(commands); |
427 | for (size_t i = 0; i < length; ++i) |
428 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
429 | } |
430 | |
431 | auto findResult = dispatchMap.get().find(method); |
432 | if (findResult == dispatchMap.get().end()) { |
433 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'CSS." + method + "' was not found" ); |
434 | return; |
435 | } |
436 | |
437 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
438 | } |
439 | |
440 | void CSSBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
441 | { |
442 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
443 | if (m_alternateDispatcher) { |
444 | m_alternateDispatcher->enable(requestId); |
445 | return; |
446 | } |
447 | #endif |
448 | |
449 | ErrorString error; |
450 | Ref<JSON::Object> result = JSON::Object::create(); |
451 | m_agent->enable(error); |
452 | |
453 | if (!error.length()) |
454 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
455 | else |
456 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
457 | } |
458 | |
459 | void CSSBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
460 | { |
461 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
462 | if (m_alternateDispatcher) { |
463 | m_alternateDispatcher->disable(requestId); |
464 | return; |
465 | } |
466 | #endif |
467 | |
468 | ErrorString error; |
469 | Ref<JSON::Object> result = JSON::Object::create(); |
470 | m_agent->disable(error); |
471 | |
472 | if (!error.length()) |
473 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
474 | else |
475 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
476 | } |
477 | |
478 | void CSSBackendDispatcher::getMatchedStylesForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
479 | { |
480 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
481 | bool opt_in_includePseudo_valueFound = false; |
482 | bool opt_in_includePseudo = m_backendDispatcher->getBoolean(parameters.get(), "includePseudo"_s , &opt_in_includePseudo_valueFound); |
483 | bool opt_in_includeInherited_valueFound = false; |
484 | bool opt_in_includeInherited = m_backendDispatcher->getBoolean(parameters.get(), "includeInherited"_s , &opt_in_includeInherited_valueFound); |
485 | if (m_backendDispatcher->hasProtocolErrors()) { |
486 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getMatchedStylesForNode' can't be processed"_s ); |
487 | return; |
488 | } |
489 | |
490 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
491 | if (m_alternateDispatcher) { |
492 | m_alternateDispatcher->getMatchedStylesForNode(requestId, in_nodeId, opt_in_includePseudo_valueFound ? &opt_in_includePseudo : nullptr, opt_in_includeInherited_valueFound ? &opt_in_includeInherited : nullptr); |
493 | return; |
494 | } |
495 | #endif |
496 | |
497 | ErrorString error; |
498 | Ref<JSON::Object> result = JSON::Object::create(); |
499 | RefPtr<JSON::ArrayOf<Inspector::Protocol::CSS::RuleMatch>> out_matchedCSSRules; |
500 | RefPtr<JSON::ArrayOf<Inspector::Protocol::CSS::PseudoIdMatches>> out_pseudoElements; |
501 | RefPtr<JSON::ArrayOf<Inspector::Protocol::CSS::InheritedStyleEntry>> out_inherited; |
502 | m_agent->getMatchedStylesForNode(error, in_nodeId, opt_in_includePseudo_valueFound ? &opt_in_includePseudo : nullptr, opt_in_includeInherited_valueFound ? &opt_in_includeInherited : nullptr, out_matchedCSSRules, out_pseudoElements, out_inherited); |
503 | |
504 | if (!error.length()) { |
505 | if (out_matchedCSSRules) |
506 | result->setArray("matchedCSSRules"_s , out_matchedCSSRules); |
507 | if (out_pseudoElements) |
508 | result->setArray("pseudoElements"_s , out_pseudoElements); |
509 | if (out_inherited) |
510 | result->setArray("inherited"_s , out_inherited); |
511 | } |
512 | if (!error.length()) |
513 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
514 | else |
515 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
516 | } |
517 | |
518 | void CSSBackendDispatcher::getInlineStylesForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
519 | { |
520 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
521 | if (m_backendDispatcher->hasProtocolErrors()) { |
522 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getInlineStylesForNode' can't be processed"_s ); |
523 | return; |
524 | } |
525 | |
526 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
527 | if (m_alternateDispatcher) { |
528 | m_alternateDispatcher->getInlineStylesForNode(requestId, in_nodeId); |
529 | return; |
530 | } |
531 | #endif |
532 | |
533 | ErrorString error; |
534 | Ref<JSON::Object> result = JSON::Object::create(); |
535 | RefPtr<Inspector::Protocol::CSS::CSSStyle> out_inlineStyle; |
536 | RefPtr<Inspector::Protocol::CSS::CSSStyle> out_attributesStyle; |
537 | m_agent->getInlineStylesForNode(error, in_nodeId, out_inlineStyle, out_attributesStyle); |
538 | |
539 | if (!error.length()) { |
540 | if (out_inlineStyle) |
541 | result->setObject("inlineStyle"_s , out_inlineStyle); |
542 | if (out_attributesStyle) |
543 | result->setObject("attributesStyle"_s , out_attributesStyle); |
544 | } |
545 | if (!error.length()) |
546 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
547 | else |
548 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
549 | } |
550 | |
551 | void CSSBackendDispatcher::getComputedStyleForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
552 | { |
553 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
554 | if (m_backendDispatcher->hasProtocolErrors()) { |
555 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getComputedStyleForNode' can't be processed"_s ); |
556 | return; |
557 | } |
558 | |
559 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
560 | if (m_alternateDispatcher) { |
561 | m_alternateDispatcher->getComputedStyleForNode(requestId, in_nodeId); |
562 | return; |
563 | } |
564 | #endif |
565 | |
566 | ErrorString error; |
567 | Ref<JSON::Object> result = JSON::Object::create(); |
568 | RefPtr<JSON::ArrayOf<Inspector::Protocol::CSS::CSSComputedStyleProperty>> out_computedStyle; |
569 | m_agent->getComputedStyleForNode(error, in_nodeId, out_computedStyle); |
570 | |
571 | if (!error.length()) |
572 | result->setArray("computedStyle"_s , out_computedStyle); |
573 | |
574 | if (!error.length()) |
575 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
576 | else |
577 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
578 | } |
579 | |
580 | void CSSBackendDispatcher::getAllStyleSheets(long requestId, RefPtr<JSON::Object>&&) |
581 | { |
582 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
583 | if (m_alternateDispatcher) { |
584 | m_alternateDispatcher->getAllStyleSheets(requestId); |
585 | return; |
586 | } |
587 | #endif |
588 | |
589 | ErrorString error; |
590 | Ref<JSON::Object> result = JSON::Object::create(); |
591 | RefPtr<JSON::ArrayOf<Inspector::Protocol::CSS::CSSStyleSheetHeader>> ; |
592 | m_agent->getAllStyleSheets(error, out_headers); |
593 | |
594 | if (!error.length()) |
595 | result->setArray("headers"_s , out_headers); |
596 | |
597 | if (!error.length()) |
598 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
599 | else |
600 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
601 | } |
602 | |
603 | void CSSBackendDispatcher::getStyleSheet(long requestId, RefPtr<JSON::Object>&& parameters) |
604 | { |
605 | String in_styleSheetId = m_backendDispatcher->getString(parameters.get(), "styleSheetId"_s , nullptr); |
606 | if (m_backendDispatcher->hasProtocolErrors()) { |
607 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getStyleSheet' can't be processed"_s ); |
608 | return; |
609 | } |
610 | |
611 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
612 | if (m_alternateDispatcher) { |
613 | m_alternateDispatcher->getStyleSheet(requestId, in_styleSheetId); |
614 | return; |
615 | } |
616 | #endif |
617 | |
618 | ErrorString error; |
619 | Ref<JSON::Object> result = JSON::Object::create(); |
620 | RefPtr<Inspector::Protocol::CSS::CSSStyleSheetBody> out_styleSheet; |
621 | m_agent->getStyleSheet(error, in_styleSheetId, out_styleSheet); |
622 | |
623 | if (!error.length()) |
624 | result->setObject("styleSheet"_s , out_styleSheet); |
625 | |
626 | if (!error.length()) |
627 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
628 | else |
629 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
630 | } |
631 | |
632 | void CSSBackendDispatcher::getStyleSheetText(long requestId, RefPtr<JSON::Object>&& parameters) |
633 | { |
634 | String in_styleSheetId = m_backendDispatcher->getString(parameters.get(), "styleSheetId"_s , nullptr); |
635 | if (m_backendDispatcher->hasProtocolErrors()) { |
636 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getStyleSheetText' can't be processed"_s ); |
637 | return; |
638 | } |
639 | |
640 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
641 | if (m_alternateDispatcher) { |
642 | m_alternateDispatcher->getStyleSheetText(requestId, in_styleSheetId); |
643 | return; |
644 | } |
645 | #endif |
646 | |
647 | ErrorString error; |
648 | Ref<JSON::Object> result = JSON::Object::create(); |
649 | String out_text; |
650 | m_agent->getStyleSheetText(error, in_styleSheetId, &out_text); |
651 | |
652 | if (!error.length()) |
653 | result->setString("text"_s , out_text); |
654 | |
655 | if (!error.length()) |
656 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
657 | else |
658 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
659 | } |
660 | |
661 | void CSSBackendDispatcher::setStyleSheetText(long requestId, RefPtr<JSON::Object>&& parameters) |
662 | { |
663 | String in_styleSheetId = m_backendDispatcher->getString(parameters.get(), "styleSheetId"_s , nullptr); |
664 | String in_text = m_backendDispatcher->getString(parameters.get(), "text"_s , nullptr); |
665 | if (m_backendDispatcher->hasProtocolErrors()) { |
666 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setStyleSheetText' can't be processed"_s ); |
667 | return; |
668 | } |
669 | |
670 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
671 | if (m_alternateDispatcher) { |
672 | m_alternateDispatcher->setStyleSheetText(requestId, in_styleSheetId, in_text); |
673 | return; |
674 | } |
675 | #endif |
676 | |
677 | ErrorString error; |
678 | Ref<JSON::Object> result = JSON::Object::create(); |
679 | m_agent->setStyleSheetText(error, in_styleSheetId, in_text); |
680 | |
681 | if (!error.length()) |
682 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
683 | else |
684 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
685 | } |
686 | |
687 | void CSSBackendDispatcher::setStyleText(long requestId, RefPtr<JSON::Object>&& parameters) |
688 | { |
689 | RefPtr<JSON::Object> in_styleId = m_backendDispatcher->getObject(parameters.get(), "styleId"_s , nullptr); |
690 | String in_text = m_backendDispatcher->getString(parameters.get(), "text"_s , nullptr); |
691 | if (m_backendDispatcher->hasProtocolErrors()) { |
692 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setStyleText' can't be processed"_s ); |
693 | return; |
694 | } |
695 | |
696 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
697 | if (m_alternateDispatcher) { |
698 | m_alternateDispatcher->setStyleText(requestId, *in_styleId, in_text); |
699 | return; |
700 | } |
701 | #endif |
702 | |
703 | ErrorString error; |
704 | Ref<JSON::Object> result = JSON::Object::create(); |
705 | RefPtr<Inspector::Protocol::CSS::CSSStyle> out_style; |
706 | m_agent->setStyleText(error, *in_styleId, in_text, out_style); |
707 | |
708 | if (!error.length()) |
709 | result->setObject("style"_s , out_style); |
710 | |
711 | if (!error.length()) |
712 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
713 | else |
714 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
715 | } |
716 | |
717 | void CSSBackendDispatcher::setRuleSelector(long requestId, RefPtr<JSON::Object>&& parameters) |
718 | { |
719 | RefPtr<JSON::Object> in_ruleId = m_backendDispatcher->getObject(parameters.get(), "ruleId"_s , nullptr); |
720 | String in_selector = m_backendDispatcher->getString(parameters.get(), "selector"_s , nullptr); |
721 | if (m_backendDispatcher->hasProtocolErrors()) { |
722 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setRuleSelector' can't be processed"_s ); |
723 | return; |
724 | } |
725 | |
726 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
727 | if (m_alternateDispatcher) { |
728 | m_alternateDispatcher->setRuleSelector(requestId, *in_ruleId, in_selector); |
729 | return; |
730 | } |
731 | #endif |
732 | |
733 | ErrorString error; |
734 | Ref<JSON::Object> result = JSON::Object::create(); |
735 | RefPtr<Inspector::Protocol::CSS::CSSRule> out_rule; |
736 | m_agent->setRuleSelector(error, *in_ruleId, in_selector, out_rule); |
737 | |
738 | if (!error.length()) |
739 | result->setObject("rule"_s , out_rule); |
740 | |
741 | if (!error.length()) |
742 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
743 | else |
744 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
745 | } |
746 | |
747 | void CSSBackendDispatcher::createStyleSheet(long requestId, RefPtr<JSON::Object>&& parameters) |
748 | { |
749 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
750 | if (m_backendDispatcher->hasProtocolErrors()) { |
751 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.createStyleSheet' can't be processed"_s ); |
752 | return; |
753 | } |
754 | |
755 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
756 | if (m_alternateDispatcher) { |
757 | m_alternateDispatcher->createStyleSheet(requestId, in_frameId); |
758 | return; |
759 | } |
760 | #endif |
761 | |
762 | ErrorString error; |
763 | Ref<JSON::Object> result = JSON::Object::create(); |
764 | String out_styleSheetId; |
765 | m_agent->createStyleSheet(error, in_frameId, &out_styleSheetId); |
766 | |
767 | if (!error.length()) |
768 | result->setString("styleSheetId"_s , out_styleSheetId); |
769 | |
770 | if (!error.length()) |
771 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
772 | else |
773 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
774 | } |
775 | |
776 | void CSSBackendDispatcher::addRule(long requestId, RefPtr<JSON::Object>&& parameters) |
777 | { |
778 | String in_styleSheetId = m_backendDispatcher->getString(parameters.get(), "styleSheetId"_s , nullptr); |
779 | String in_selector = m_backendDispatcher->getString(parameters.get(), "selector"_s , nullptr); |
780 | if (m_backendDispatcher->hasProtocolErrors()) { |
781 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.addRule' can't be processed"_s ); |
782 | return; |
783 | } |
784 | |
785 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
786 | if (m_alternateDispatcher) { |
787 | m_alternateDispatcher->addRule(requestId, in_styleSheetId, in_selector); |
788 | return; |
789 | } |
790 | #endif |
791 | |
792 | ErrorString error; |
793 | Ref<JSON::Object> result = JSON::Object::create(); |
794 | RefPtr<Inspector::Protocol::CSS::CSSRule> out_rule; |
795 | m_agent->addRule(error, in_styleSheetId, in_selector, out_rule); |
796 | |
797 | if (!error.length()) |
798 | result->setObject("rule"_s , out_rule); |
799 | |
800 | if (!error.length()) |
801 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
802 | else |
803 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
804 | } |
805 | |
806 | void CSSBackendDispatcher::getSupportedCSSProperties(long requestId, RefPtr<JSON::Object>&&) |
807 | { |
808 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
809 | if (m_alternateDispatcher) { |
810 | m_alternateDispatcher->getSupportedCSSProperties(requestId); |
811 | return; |
812 | } |
813 | #endif |
814 | |
815 | ErrorString error; |
816 | Ref<JSON::Object> result = JSON::Object::create(); |
817 | RefPtr<JSON::ArrayOf<Inspector::Protocol::CSS::CSSPropertyInfo>> out_cssProperties; |
818 | m_agent->getSupportedCSSProperties(error, out_cssProperties); |
819 | |
820 | if (!error.length()) |
821 | result->setArray("cssProperties"_s , out_cssProperties); |
822 | |
823 | if (!error.length()) |
824 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
825 | else |
826 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
827 | } |
828 | |
829 | void CSSBackendDispatcher::getSupportedSystemFontFamilyNames(long requestId, RefPtr<JSON::Object>&&) |
830 | { |
831 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
832 | if (m_alternateDispatcher) { |
833 | m_alternateDispatcher->getSupportedSystemFontFamilyNames(requestId); |
834 | return; |
835 | } |
836 | #endif |
837 | |
838 | ErrorString error; |
839 | Ref<JSON::Object> result = JSON::Object::create(); |
840 | RefPtr<JSON::ArrayOf<String>> out_fontFamilyNames; |
841 | m_agent->getSupportedSystemFontFamilyNames(error, out_fontFamilyNames); |
842 | |
843 | if (!error.length()) |
844 | result->setArray("fontFamilyNames"_s , out_fontFamilyNames); |
845 | |
846 | if (!error.length()) |
847 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
848 | else |
849 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
850 | } |
851 | |
852 | void CSSBackendDispatcher::forcePseudoState(long requestId, RefPtr<JSON::Object>&& parameters) |
853 | { |
854 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
855 | RefPtr<JSON::Array> in_forcedPseudoClasses = m_backendDispatcher->getArray(parameters.get(), "forcedPseudoClasses"_s , nullptr); |
856 | if (m_backendDispatcher->hasProtocolErrors()) { |
857 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.forcePseudoState' can't be processed"_s ); |
858 | return; |
859 | } |
860 | |
861 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
862 | if (m_alternateDispatcher) { |
863 | m_alternateDispatcher->forcePseudoState(requestId, in_nodeId, *in_forcedPseudoClasses); |
864 | return; |
865 | } |
866 | #endif |
867 | |
868 | ErrorString error; |
869 | Ref<JSON::Object> result = JSON::Object::create(); |
870 | m_agent->forcePseudoState(error, in_nodeId, *in_forcedPseudoClasses); |
871 | |
872 | if (!error.length()) |
873 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
874 | else |
875 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
876 | } |
877 | |
878 | Ref<CanvasBackendDispatcher> CanvasBackendDispatcher::create(BackendDispatcher& backendDispatcher, CanvasBackendDispatcherHandler* agent) |
879 | { |
880 | return adoptRef(*new CanvasBackendDispatcher(backendDispatcher, agent)); |
881 | } |
882 | |
883 | CanvasBackendDispatcher::CanvasBackendDispatcher(BackendDispatcher& backendDispatcher, CanvasBackendDispatcherHandler* agent) |
884 | : SupplementalBackendDispatcher(backendDispatcher) |
885 | , m_agent(agent) |
886 | { |
887 | m_backendDispatcher->registerDispatcherForDomain("Canvas"_s , this); |
888 | } |
889 | |
890 | void CanvasBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
891 | { |
892 | Ref<CanvasBackendDispatcher> protect(*this); |
893 | |
894 | RefPtr<JSON::Object> parameters; |
895 | message->getObject("params"_s , parameters); |
896 | |
897 | typedef void (CanvasBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
898 | typedef HashMap<String, CallHandler> DispatchMap; |
899 | static NeverDestroyed<DispatchMap> dispatchMap; |
900 | if (dispatchMap.get().isEmpty()) { |
901 | static const struct MethodTable { |
902 | const char* name; |
903 | CallHandler handler; |
904 | } commands[] = { |
905 | { "enable" , &CanvasBackendDispatcher::enable }, |
906 | { "disable" , &CanvasBackendDispatcher::disable }, |
907 | { "requestNode" , &CanvasBackendDispatcher::requestNode }, |
908 | { "requestContent" , &CanvasBackendDispatcher::requestContent }, |
909 | { "requestCSSCanvasClientNodes" , &CanvasBackendDispatcher::requestCSSCanvasClientNodes }, |
910 | { "resolveCanvasContext" , &CanvasBackendDispatcher::resolveCanvasContext }, |
911 | { "setRecordingAutoCaptureFrameCount" , &CanvasBackendDispatcher::setRecordingAutoCaptureFrameCount }, |
912 | { "startRecording" , &CanvasBackendDispatcher::startRecording }, |
913 | { "stopRecording" , &CanvasBackendDispatcher::stopRecording }, |
914 | { "requestShaderSource" , &CanvasBackendDispatcher::requestShaderSource }, |
915 | { "updateShader" , &CanvasBackendDispatcher::updateShader }, |
916 | { "setShaderProgramDisabled" , &CanvasBackendDispatcher::setShaderProgramDisabled }, |
917 | { "setShaderProgramHighlighted" , &CanvasBackendDispatcher::setShaderProgramHighlighted }, |
918 | }; |
919 | size_t length = WTF_ARRAY_LENGTH(commands); |
920 | for (size_t i = 0; i < length; ++i) |
921 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
922 | } |
923 | |
924 | auto findResult = dispatchMap.get().find(method); |
925 | if (findResult == dispatchMap.get().end()) { |
926 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Canvas." + method + "' was not found" ); |
927 | return; |
928 | } |
929 | |
930 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
931 | } |
932 | |
933 | void CanvasBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
934 | { |
935 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
936 | if (m_alternateDispatcher) { |
937 | m_alternateDispatcher->enable(requestId); |
938 | return; |
939 | } |
940 | #endif |
941 | |
942 | ErrorString error; |
943 | Ref<JSON::Object> result = JSON::Object::create(); |
944 | m_agent->enable(error); |
945 | |
946 | if (!error.length()) |
947 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
948 | else |
949 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
950 | } |
951 | |
952 | void CanvasBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
953 | { |
954 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
955 | if (m_alternateDispatcher) { |
956 | m_alternateDispatcher->disable(requestId); |
957 | return; |
958 | } |
959 | #endif |
960 | |
961 | ErrorString error; |
962 | Ref<JSON::Object> result = JSON::Object::create(); |
963 | m_agent->disable(error); |
964 | |
965 | if (!error.length()) |
966 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
967 | else |
968 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
969 | } |
970 | |
971 | void CanvasBackendDispatcher::requestNode(long requestId, RefPtr<JSON::Object>&& parameters) |
972 | { |
973 | String in_canvasId = m_backendDispatcher->getString(parameters.get(), "canvasId"_s , nullptr); |
974 | if (m_backendDispatcher->hasProtocolErrors()) { |
975 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestNode' can't be processed"_s ); |
976 | return; |
977 | } |
978 | |
979 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
980 | if (m_alternateDispatcher) { |
981 | m_alternateDispatcher->requestNode(requestId, in_canvasId); |
982 | return; |
983 | } |
984 | #endif |
985 | |
986 | ErrorString error; |
987 | Ref<JSON::Object> result = JSON::Object::create(); |
988 | int out_nodeId; |
989 | m_agent->requestNode(error, in_canvasId, &out_nodeId); |
990 | |
991 | if (!error.length()) |
992 | result->setInteger("nodeId"_s , out_nodeId); |
993 | |
994 | if (!error.length()) |
995 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
996 | else |
997 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
998 | } |
999 | |
1000 | void CanvasBackendDispatcher::requestContent(long requestId, RefPtr<JSON::Object>&& parameters) |
1001 | { |
1002 | String in_canvasId = m_backendDispatcher->getString(parameters.get(), "canvasId"_s , nullptr); |
1003 | if (m_backendDispatcher->hasProtocolErrors()) { |
1004 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestContent' can't be processed"_s ); |
1005 | return; |
1006 | } |
1007 | |
1008 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1009 | if (m_alternateDispatcher) { |
1010 | m_alternateDispatcher->requestContent(requestId, in_canvasId); |
1011 | return; |
1012 | } |
1013 | #endif |
1014 | |
1015 | ErrorString error; |
1016 | Ref<JSON::Object> result = JSON::Object::create(); |
1017 | String out_content; |
1018 | m_agent->requestContent(error, in_canvasId, &out_content); |
1019 | |
1020 | if (!error.length()) |
1021 | result->setString("content"_s , out_content); |
1022 | |
1023 | if (!error.length()) |
1024 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1025 | else |
1026 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1027 | } |
1028 | |
1029 | void CanvasBackendDispatcher::requestCSSCanvasClientNodes(long requestId, RefPtr<JSON::Object>&& parameters) |
1030 | { |
1031 | String in_canvasId = m_backendDispatcher->getString(parameters.get(), "canvasId"_s , nullptr); |
1032 | if (m_backendDispatcher->hasProtocolErrors()) { |
1033 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestCSSCanvasClientNodes' can't be processed"_s ); |
1034 | return; |
1035 | } |
1036 | |
1037 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1038 | if (m_alternateDispatcher) { |
1039 | m_alternateDispatcher->requestCSSCanvasClientNodes(requestId, in_canvasId); |
1040 | return; |
1041 | } |
1042 | #endif |
1043 | |
1044 | ErrorString error; |
1045 | Ref<JSON::Object> result = JSON::Object::create(); |
1046 | RefPtr<JSON::ArrayOf<int>> out_clientNodeIds; |
1047 | m_agent->requestCSSCanvasClientNodes(error, in_canvasId, out_clientNodeIds); |
1048 | |
1049 | if (!error.length()) |
1050 | result->setArray("clientNodeIds"_s , out_clientNodeIds); |
1051 | |
1052 | if (!error.length()) |
1053 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1054 | else |
1055 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1056 | } |
1057 | |
1058 | void CanvasBackendDispatcher::resolveCanvasContext(long requestId, RefPtr<JSON::Object>&& parameters) |
1059 | { |
1060 | String in_canvasId = m_backendDispatcher->getString(parameters.get(), "canvasId"_s , nullptr); |
1061 | bool opt_in_objectGroup_valueFound = false; |
1062 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
1063 | if (m_backendDispatcher->hasProtocolErrors()) { |
1064 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.resolveCanvasContext' can't be processed"_s ); |
1065 | return; |
1066 | } |
1067 | |
1068 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1069 | if (m_alternateDispatcher) { |
1070 | m_alternateDispatcher->resolveCanvasContext(requestId, in_canvasId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr); |
1071 | return; |
1072 | } |
1073 | #endif |
1074 | |
1075 | ErrorString error; |
1076 | Ref<JSON::Object> result = JSON::Object::create(); |
1077 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_object; |
1078 | m_agent->resolveCanvasContext(error, in_canvasId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, out_object); |
1079 | |
1080 | if (!error.length()) |
1081 | result->setObject("object"_s , out_object); |
1082 | |
1083 | if (!error.length()) |
1084 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1085 | else |
1086 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1087 | } |
1088 | |
1089 | void CanvasBackendDispatcher::setRecordingAutoCaptureFrameCount(long requestId, RefPtr<JSON::Object>&& parameters) |
1090 | { |
1091 | int in_count = m_backendDispatcher->getInteger(parameters.get(), "count"_s , nullptr); |
1092 | if (m_backendDispatcher->hasProtocolErrors()) { |
1093 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.setRecordingAutoCaptureFrameCount' can't be processed"_s ); |
1094 | return; |
1095 | } |
1096 | |
1097 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1098 | if (m_alternateDispatcher) { |
1099 | m_alternateDispatcher->setRecordingAutoCaptureFrameCount(requestId, in_count); |
1100 | return; |
1101 | } |
1102 | #endif |
1103 | |
1104 | ErrorString error; |
1105 | Ref<JSON::Object> result = JSON::Object::create(); |
1106 | m_agent->setRecordingAutoCaptureFrameCount(error, in_count); |
1107 | |
1108 | if (!error.length()) |
1109 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1110 | else |
1111 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1112 | } |
1113 | |
1114 | void CanvasBackendDispatcher::startRecording(long requestId, RefPtr<JSON::Object>&& parameters) |
1115 | { |
1116 | String in_canvasId = m_backendDispatcher->getString(parameters.get(), "canvasId"_s , nullptr); |
1117 | bool opt_in_frameCount_valueFound = false; |
1118 | int opt_in_frameCount = m_backendDispatcher->getInteger(parameters.get(), "frameCount"_s , &opt_in_frameCount_valueFound); |
1119 | bool opt_in_memoryLimit_valueFound = false; |
1120 | int opt_in_memoryLimit = m_backendDispatcher->getInteger(parameters.get(), "memoryLimit"_s , &opt_in_memoryLimit_valueFound); |
1121 | if (m_backendDispatcher->hasProtocolErrors()) { |
1122 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.startRecording' can't be processed"_s ); |
1123 | return; |
1124 | } |
1125 | |
1126 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1127 | if (m_alternateDispatcher) { |
1128 | m_alternateDispatcher->startRecording(requestId, in_canvasId, opt_in_frameCount_valueFound ? &opt_in_frameCount : nullptr, opt_in_memoryLimit_valueFound ? &opt_in_memoryLimit : nullptr); |
1129 | return; |
1130 | } |
1131 | #endif |
1132 | |
1133 | ErrorString error; |
1134 | Ref<JSON::Object> result = JSON::Object::create(); |
1135 | m_agent->startRecording(error, in_canvasId, opt_in_frameCount_valueFound ? &opt_in_frameCount : nullptr, opt_in_memoryLimit_valueFound ? &opt_in_memoryLimit : nullptr); |
1136 | |
1137 | if (!error.length()) |
1138 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1139 | else |
1140 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1141 | } |
1142 | |
1143 | void CanvasBackendDispatcher::stopRecording(long requestId, RefPtr<JSON::Object>&& parameters) |
1144 | { |
1145 | String in_canvasId = m_backendDispatcher->getString(parameters.get(), "canvasId"_s , nullptr); |
1146 | if (m_backendDispatcher->hasProtocolErrors()) { |
1147 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.stopRecording' can't be processed"_s ); |
1148 | return; |
1149 | } |
1150 | |
1151 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1152 | if (m_alternateDispatcher) { |
1153 | m_alternateDispatcher->stopRecording(requestId, in_canvasId); |
1154 | return; |
1155 | } |
1156 | #endif |
1157 | |
1158 | ErrorString error; |
1159 | Ref<JSON::Object> result = JSON::Object::create(); |
1160 | m_agent->stopRecording(error, in_canvasId); |
1161 | |
1162 | if (!error.length()) |
1163 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1164 | else |
1165 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1166 | } |
1167 | |
1168 | void CanvasBackendDispatcher::requestShaderSource(long requestId, RefPtr<JSON::Object>&& parameters) |
1169 | { |
1170 | String in_programId = m_backendDispatcher->getString(parameters.get(), "programId"_s , nullptr); |
1171 | String in_shaderType = m_backendDispatcher->getString(parameters.get(), "shaderType"_s , nullptr); |
1172 | if (m_backendDispatcher->hasProtocolErrors()) { |
1173 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestShaderSource' can't be processed"_s ); |
1174 | return; |
1175 | } |
1176 | |
1177 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1178 | if (m_alternateDispatcher) { |
1179 | m_alternateDispatcher->requestShaderSource(requestId, in_programId, in_shaderType); |
1180 | return; |
1181 | } |
1182 | #endif |
1183 | |
1184 | ErrorString error; |
1185 | Ref<JSON::Object> result = JSON::Object::create(); |
1186 | String out_content; |
1187 | m_agent->requestShaderSource(error, in_programId, in_shaderType, &out_content); |
1188 | |
1189 | if (!error.length()) |
1190 | result->setString("content"_s , out_content); |
1191 | |
1192 | if (!error.length()) |
1193 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1194 | else |
1195 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1196 | } |
1197 | |
1198 | void CanvasBackendDispatcher::updateShader(long requestId, RefPtr<JSON::Object>&& parameters) |
1199 | { |
1200 | String in_programId = m_backendDispatcher->getString(parameters.get(), "programId"_s , nullptr); |
1201 | String in_shaderType = m_backendDispatcher->getString(parameters.get(), "shaderType"_s , nullptr); |
1202 | String in_source = m_backendDispatcher->getString(parameters.get(), "source"_s , nullptr); |
1203 | if (m_backendDispatcher->hasProtocolErrors()) { |
1204 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.updateShader' can't be processed"_s ); |
1205 | return; |
1206 | } |
1207 | |
1208 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1209 | if (m_alternateDispatcher) { |
1210 | m_alternateDispatcher->updateShader(requestId, in_programId, in_shaderType, in_source); |
1211 | return; |
1212 | } |
1213 | #endif |
1214 | |
1215 | ErrorString error; |
1216 | Ref<JSON::Object> result = JSON::Object::create(); |
1217 | m_agent->updateShader(error, in_programId, in_shaderType, in_source); |
1218 | |
1219 | if (!error.length()) |
1220 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1221 | else |
1222 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1223 | } |
1224 | |
1225 | void CanvasBackendDispatcher::setShaderProgramDisabled(long requestId, RefPtr<JSON::Object>&& parameters) |
1226 | { |
1227 | String in_programId = m_backendDispatcher->getString(parameters.get(), "programId"_s , nullptr); |
1228 | bool in_disabled = m_backendDispatcher->getBoolean(parameters.get(), "disabled"_s , nullptr); |
1229 | if (m_backendDispatcher->hasProtocolErrors()) { |
1230 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.setShaderProgramDisabled' can't be processed"_s ); |
1231 | return; |
1232 | } |
1233 | |
1234 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1235 | if (m_alternateDispatcher) { |
1236 | m_alternateDispatcher->setShaderProgramDisabled(requestId, in_programId, in_disabled); |
1237 | return; |
1238 | } |
1239 | #endif |
1240 | |
1241 | ErrorString error; |
1242 | Ref<JSON::Object> result = JSON::Object::create(); |
1243 | m_agent->setShaderProgramDisabled(error, in_programId, in_disabled); |
1244 | |
1245 | if (!error.length()) |
1246 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1247 | else |
1248 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1249 | } |
1250 | |
1251 | void CanvasBackendDispatcher::setShaderProgramHighlighted(long requestId, RefPtr<JSON::Object>&& parameters) |
1252 | { |
1253 | String in_programId = m_backendDispatcher->getString(parameters.get(), "programId"_s , nullptr); |
1254 | bool in_highlighted = m_backendDispatcher->getBoolean(parameters.get(), "highlighted"_s , nullptr); |
1255 | if (m_backendDispatcher->hasProtocolErrors()) { |
1256 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.setShaderProgramHighlighted' can't be processed"_s ); |
1257 | return; |
1258 | } |
1259 | |
1260 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1261 | if (m_alternateDispatcher) { |
1262 | m_alternateDispatcher->setShaderProgramHighlighted(requestId, in_programId, in_highlighted); |
1263 | return; |
1264 | } |
1265 | #endif |
1266 | |
1267 | ErrorString error; |
1268 | Ref<JSON::Object> result = JSON::Object::create(); |
1269 | m_agent->setShaderProgramHighlighted(error, in_programId, in_highlighted); |
1270 | |
1271 | if (!error.length()) |
1272 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1273 | else |
1274 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1275 | } |
1276 | |
1277 | Ref<ConsoleBackendDispatcher> ConsoleBackendDispatcher::create(BackendDispatcher& backendDispatcher, ConsoleBackendDispatcherHandler* agent) |
1278 | { |
1279 | return adoptRef(*new ConsoleBackendDispatcher(backendDispatcher, agent)); |
1280 | } |
1281 | |
1282 | ConsoleBackendDispatcher::ConsoleBackendDispatcher(BackendDispatcher& backendDispatcher, ConsoleBackendDispatcherHandler* agent) |
1283 | : SupplementalBackendDispatcher(backendDispatcher) |
1284 | , m_agent(agent) |
1285 | { |
1286 | m_backendDispatcher->registerDispatcherForDomain("Console"_s , this); |
1287 | } |
1288 | |
1289 | void ConsoleBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
1290 | { |
1291 | Ref<ConsoleBackendDispatcher> protect(*this); |
1292 | |
1293 | RefPtr<JSON::Object> parameters; |
1294 | message->getObject("params"_s , parameters); |
1295 | |
1296 | if (method == "enable" ) |
1297 | enable(requestId, WTFMove(parameters)); |
1298 | else if (method == "disable" ) |
1299 | disable(requestId, WTFMove(parameters)); |
1300 | else if (method == "clearMessages" ) |
1301 | clearMessages(requestId, WTFMove(parameters)); |
1302 | else if (method == "getLoggingChannels" ) |
1303 | getLoggingChannels(requestId, WTFMove(parameters)); |
1304 | else if (method == "setLoggingChannelLevel" ) |
1305 | setLoggingChannelLevel(requestId, WTFMove(parameters)); |
1306 | else |
1307 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Console." + method + "' was not found" ); |
1308 | } |
1309 | |
1310 | void ConsoleBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
1311 | { |
1312 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1313 | if (m_alternateDispatcher) { |
1314 | m_alternateDispatcher->enable(requestId); |
1315 | return; |
1316 | } |
1317 | #endif |
1318 | |
1319 | ErrorString error; |
1320 | Ref<JSON::Object> result = JSON::Object::create(); |
1321 | m_agent->enable(error); |
1322 | |
1323 | if (!error.length()) |
1324 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1325 | else |
1326 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1327 | } |
1328 | |
1329 | void ConsoleBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
1330 | { |
1331 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1332 | if (m_alternateDispatcher) { |
1333 | m_alternateDispatcher->disable(requestId); |
1334 | return; |
1335 | } |
1336 | #endif |
1337 | |
1338 | ErrorString error; |
1339 | Ref<JSON::Object> result = JSON::Object::create(); |
1340 | m_agent->disable(error); |
1341 | |
1342 | if (!error.length()) |
1343 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1344 | else |
1345 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1346 | } |
1347 | |
1348 | void ConsoleBackendDispatcher::clearMessages(long requestId, RefPtr<JSON::Object>&&) |
1349 | { |
1350 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1351 | if (m_alternateDispatcher) { |
1352 | m_alternateDispatcher->clearMessages(requestId); |
1353 | return; |
1354 | } |
1355 | #endif |
1356 | |
1357 | ErrorString error; |
1358 | Ref<JSON::Object> result = JSON::Object::create(); |
1359 | m_agent->clearMessages(error); |
1360 | |
1361 | if (!error.length()) |
1362 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1363 | else |
1364 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1365 | } |
1366 | |
1367 | void ConsoleBackendDispatcher::getLoggingChannels(long requestId, RefPtr<JSON::Object>&&) |
1368 | { |
1369 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1370 | if (m_alternateDispatcher) { |
1371 | m_alternateDispatcher->getLoggingChannels(requestId); |
1372 | return; |
1373 | } |
1374 | #endif |
1375 | |
1376 | ErrorString error; |
1377 | Ref<JSON::Object> result = JSON::Object::create(); |
1378 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Console::Channel>> out_channels; |
1379 | m_agent->getLoggingChannels(error, out_channels); |
1380 | |
1381 | if (!error.length()) |
1382 | result->setArray("channels"_s , out_channels); |
1383 | |
1384 | if (!error.length()) |
1385 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1386 | else |
1387 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1388 | } |
1389 | |
1390 | void ConsoleBackendDispatcher::setLoggingChannelLevel(long requestId, RefPtr<JSON::Object>&& parameters) |
1391 | { |
1392 | String in_source = m_backendDispatcher->getString(parameters.get(), "source"_s , nullptr); |
1393 | String in_level = m_backendDispatcher->getString(parameters.get(), "level"_s , nullptr); |
1394 | if (m_backendDispatcher->hasProtocolErrors()) { |
1395 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Console.setLoggingChannelLevel' can't be processed"_s ); |
1396 | return; |
1397 | } |
1398 | |
1399 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1400 | if (m_alternateDispatcher) { |
1401 | m_alternateDispatcher->setLoggingChannelLevel(requestId, in_source, in_level); |
1402 | return; |
1403 | } |
1404 | #endif |
1405 | |
1406 | ErrorString error; |
1407 | Ref<JSON::Object> result = JSON::Object::create(); |
1408 | m_agent->setLoggingChannelLevel(error, in_source, in_level); |
1409 | |
1410 | if (!error.length()) |
1411 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1412 | else |
1413 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1414 | } |
1415 | |
1416 | Ref<DOMBackendDispatcher> DOMBackendDispatcher::create(BackendDispatcher& backendDispatcher, DOMBackendDispatcherHandler* agent) |
1417 | { |
1418 | return adoptRef(*new DOMBackendDispatcher(backendDispatcher, agent)); |
1419 | } |
1420 | |
1421 | DOMBackendDispatcher::DOMBackendDispatcher(BackendDispatcher& backendDispatcher, DOMBackendDispatcherHandler* agent) |
1422 | : SupplementalBackendDispatcher(backendDispatcher) |
1423 | , m_agent(agent) |
1424 | { |
1425 | m_backendDispatcher->registerDispatcherForDomain("DOM"_s , this); |
1426 | } |
1427 | |
1428 | void DOMBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
1429 | { |
1430 | Ref<DOMBackendDispatcher> protect(*this); |
1431 | |
1432 | RefPtr<JSON::Object> parameters; |
1433 | message->getObject("params"_s , parameters); |
1434 | |
1435 | typedef void (DOMBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
1436 | typedef HashMap<String, CallHandler> DispatchMap; |
1437 | static NeverDestroyed<DispatchMap> dispatchMap; |
1438 | if (dispatchMap.get().isEmpty()) { |
1439 | static const struct MethodTable { |
1440 | const char* name; |
1441 | CallHandler handler; |
1442 | } commands[] = { |
1443 | { "getDocument" , &DOMBackendDispatcher::getDocument }, |
1444 | { "requestChildNodes" , &DOMBackendDispatcher::requestChildNodes }, |
1445 | { "querySelector" , &DOMBackendDispatcher::querySelector }, |
1446 | { "querySelectorAll" , &DOMBackendDispatcher::querySelectorAll }, |
1447 | { "setNodeName" , &DOMBackendDispatcher::setNodeName }, |
1448 | { "setNodeValue" , &DOMBackendDispatcher::setNodeValue }, |
1449 | { "removeNode" , &DOMBackendDispatcher::removeNode }, |
1450 | { "setAttributeValue" , &DOMBackendDispatcher::setAttributeValue }, |
1451 | { "setAttributesAsText" , &DOMBackendDispatcher::setAttributesAsText }, |
1452 | { "removeAttribute" , &DOMBackendDispatcher::removeAttribute }, |
1453 | { "getSupportedEventNames" , &DOMBackendDispatcher::getSupportedEventNames }, |
1454 | { "getDataBindingsForNode" , &DOMBackendDispatcher::getDataBindingsForNode }, |
1455 | { "getAssociatedDataForNode" , &DOMBackendDispatcher::getAssociatedDataForNode }, |
1456 | { "getEventListenersForNode" , &DOMBackendDispatcher::getEventListenersForNode }, |
1457 | { "setEventListenerDisabled" , &DOMBackendDispatcher::setEventListenerDisabled }, |
1458 | { "setBreakpointForEventListener" , &DOMBackendDispatcher::setBreakpointForEventListener }, |
1459 | { "removeBreakpointForEventListener" , &DOMBackendDispatcher::removeBreakpointForEventListener }, |
1460 | { "getAccessibilityPropertiesForNode" , &DOMBackendDispatcher::getAccessibilityPropertiesForNode }, |
1461 | { "getOuterHTML" , &DOMBackendDispatcher::getOuterHTML }, |
1462 | { "setOuterHTML" , &DOMBackendDispatcher::setOuterHTML }, |
1463 | { "insertAdjacentHTML" , &DOMBackendDispatcher::insertAdjacentHTML }, |
1464 | { "performSearch" , &DOMBackendDispatcher::performSearch }, |
1465 | { "getSearchResults" , &DOMBackendDispatcher::getSearchResults }, |
1466 | { "discardSearchResults" , &DOMBackendDispatcher::discardSearchResults }, |
1467 | { "requestNode" , &DOMBackendDispatcher::requestNode }, |
1468 | { "setInspectModeEnabled" , &DOMBackendDispatcher::setInspectModeEnabled }, |
1469 | { "highlightRect" , &DOMBackendDispatcher::highlightRect }, |
1470 | { "highlightQuad" , &DOMBackendDispatcher::highlightQuad }, |
1471 | { "highlightSelector" , &DOMBackendDispatcher::highlightSelector }, |
1472 | { "highlightNode" , &DOMBackendDispatcher::highlightNode }, |
1473 | { "highlightNodeList" , &DOMBackendDispatcher::highlightNodeList }, |
1474 | { "hideHighlight" , &DOMBackendDispatcher::hideHighlight }, |
1475 | { "highlightFrame" , &DOMBackendDispatcher::highlightFrame }, |
1476 | { "pushNodeByPathToFrontend" , &DOMBackendDispatcher::pushNodeByPathToFrontend }, |
1477 | { "resolveNode" , &DOMBackendDispatcher::resolveNode }, |
1478 | { "getAttributes" , &DOMBackendDispatcher::getAttributes }, |
1479 | { "moveTo" , &DOMBackendDispatcher::moveTo }, |
1480 | { "undo" , &DOMBackendDispatcher::undo }, |
1481 | { "redo" , &DOMBackendDispatcher::redo }, |
1482 | { "markUndoableState" , &DOMBackendDispatcher::markUndoableState }, |
1483 | { "focus" , &DOMBackendDispatcher::focus }, |
1484 | { "setInspectedNode" , &DOMBackendDispatcher::setInspectedNode }, |
1485 | }; |
1486 | size_t length = WTF_ARRAY_LENGTH(commands); |
1487 | for (size_t i = 0; i < length; ++i) |
1488 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
1489 | } |
1490 | |
1491 | auto findResult = dispatchMap.get().find(method); |
1492 | if (findResult == dispatchMap.get().end()) { |
1493 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'DOM." + method + "' was not found" ); |
1494 | return; |
1495 | } |
1496 | |
1497 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
1498 | } |
1499 | |
1500 | void DOMBackendDispatcher::getDocument(long requestId, RefPtr<JSON::Object>&&) |
1501 | { |
1502 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1503 | if (m_alternateDispatcher) { |
1504 | m_alternateDispatcher->getDocument(requestId); |
1505 | return; |
1506 | } |
1507 | #endif |
1508 | |
1509 | ErrorString error; |
1510 | Ref<JSON::Object> result = JSON::Object::create(); |
1511 | RefPtr<Inspector::Protocol::DOM::Node> out_root; |
1512 | m_agent->getDocument(error, out_root); |
1513 | |
1514 | if (!error.length()) |
1515 | result->setObject("root"_s , out_root); |
1516 | |
1517 | if (!error.length()) |
1518 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1519 | else |
1520 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1521 | } |
1522 | |
1523 | void DOMBackendDispatcher::requestChildNodes(long requestId, RefPtr<JSON::Object>&& parameters) |
1524 | { |
1525 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1526 | bool opt_in_depth_valueFound = false; |
1527 | int opt_in_depth = m_backendDispatcher->getInteger(parameters.get(), "depth"_s , &opt_in_depth_valueFound); |
1528 | if (m_backendDispatcher->hasProtocolErrors()) { |
1529 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.requestChildNodes' can't be processed"_s ); |
1530 | return; |
1531 | } |
1532 | |
1533 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1534 | if (m_alternateDispatcher) { |
1535 | m_alternateDispatcher->requestChildNodes(requestId, in_nodeId, opt_in_depth_valueFound ? &opt_in_depth : nullptr); |
1536 | return; |
1537 | } |
1538 | #endif |
1539 | |
1540 | ErrorString error; |
1541 | Ref<JSON::Object> result = JSON::Object::create(); |
1542 | m_agent->requestChildNodes(error, in_nodeId, opt_in_depth_valueFound ? &opt_in_depth : nullptr); |
1543 | |
1544 | if (!error.length()) |
1545 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1546 | else |
1547 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1548 | } |
1549 | |
1550 | void DOMBackendDispatcher::querySelector(long requestId, RefPtr<JSON::Object>&& parameters) |
1551 | { |
1552 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1553 | String in_selector = m_backendDispatcher->getString(parameters.get(), "selector"_s , nullptr); |
1554 | if (m_backendDispatcher->hasProtocolErrors()) { |
1555 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.querySelector' can't be processed"_s ); |
1556 | return; |
1557 | } |
1558 | |
1559 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1560 | if (m_alternateDispatcher) { |
1561 | m_alternateDispatcher->querySelector(requestId, in_nodeId, in_selector); |
1562 | return; |
1563 | } |
1564 | #endif |
1565 | |
1566 | ErrorString error; |
1567 | Ref<JSON::Object> result = JSON::Object::create(); |
1568 | int out_nodeId; |
1569 | m_agent->querySelector(error, in_nodeId, in_selector, &out_nodeId); |
1570 | |
1571 | if (!error.length()) |
1572 | result->setInteger("nodeId"_s , out_nodeId); |
1573 | |
1574 | if (!error.length()) |
1575 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1576 | else |
1577 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1578 | } |
1579 | |
1580 | void DOMBackendDispatcher::querySelectorAll(long requestId, RefPtr<JSON::Object>&& parameters) |
1581 | { |
1582 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1583 | String in_selector = m_backendDispatcher->getString(parameters.get(), "selector"_s , nullptr); |
1584 | if (m_backendDispatcher->hasProtocolErrors()) { |
1585 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.querySelectorAll' can't be processed"_s ); |
1586 | return; |
1587 | } |
1588 | |
1589 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1590 | if (m_alternateDispatcher) { |
1591 | m_alternateDispatcher->querySelectorAll(requestId, in_nodeId, in_selector); |
1592 | return; |
1593 | } |
1594 | #endif |
1595 | |
1596 | ErrorString error; |
1597 | Ref<JSON::Object> result = JSON::Object::create(); |
1598 | RefPtr<JSON::ArrayOf<int>> out_nodeIds; |
1599 | m_agent->querySelectorAll(error, in_nodeId, in_selector, out_nodeIds); |
1600 | |
1601 | if (!error.length()) |
1602 | result->setArray("nodeIds"_s , out_nodeIds); |
1603 | |
1604 | if (!error.length()) |
1605 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1606 | else |
1607 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1608 | } |
1609 | |
1610 | void DOMBackendDispatcher::setNodeName(long requestId, RefPtr<JSON::Object>&& parameters) |
1611 | { |
1612 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1613 | String in_name = m_backendDispatcher->getString(parameters.get(), "name"_s , nullptr); |
1614 | if (m_backendDispatcher->hasProtocolErrors()) { |
1615 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setNodeName' can't be processed"_s ); |
1616 | return; |
1617 | } |
1618 | |
1619 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1620 | if (m_alternateDispatcher) { |
1621 | m_alternateDispatcher->setNodeName(requestId, in_nodeId, in_name); |
1622 | return; |
1623 | } |
1624 | #endif |
1625 | |
1626 | ErrorString error; |
1627 | Ref<JSON::Object> result = JSON::Object::create(); |
1628 | int out_nodeId; |
1629 | m_agent->setNodeName(error, in_nodeId, in_name, &out_nodeId); |
1630 | |
1631 | if (!error.length()) |
1632 | result->setInteger("nodeId"_s , out_nodeId); |
1633 | |
1634 | if (!error.length()) |
1635 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1636 | else |
1637 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1638 | } |
1639 | |
1640 | void DOMBackendDispatcher::setNodeValue(long requestId, RefPtr<JSON::Object>&& parameters) |
1641 | { |
1642 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1643 | String in_value = m_backendDispatcher->getString(parameters.get(), "value"_s , nullptr); |
1644 | if (m_backendDispatcher->hasProtocolErrors()) { |
1645 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setNodeValue' can't be processed"_s ); |
1646 | return; |
1647 | } |
1648 | |
1649 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1650 | if (m_alternateDispatcher) { |
1651 | m_alternateDispatcher->setNodeValue(requestId, in_nodeId, in_value); |
1652 | return; |
1653 | } |
1654 | #endif |
1655 | |
1656 | ErrorString error; |
1657 | Ref<JSON::Object> result = JSON::Object::create(); |
1658 | m_agent->setNodeValue(error, in_nodeId, in_value); |
1659 | |
1660 | if (!error.length()) |
1661 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1662 | else |
1663 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1664 | } |
1665 | |
1666 | void DOMBackendDispatcher::removeNode(long requestId, RefPtr<JSON::Object>&& parameters) |
1667 | { |
1668 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1669 | if (m_backendDispatcher->hasProtocolErrors()) { |
1670 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.removeNode' can't be processed"_s ); |
1671 | return; |
1672 | } |
1673 | |
1674 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1675 | if (m_alternateDispatcher) { |
1676 | m_alternateDispatcher->removeNode(requestId, in_nodeId); |
1677 | return; |
1678 | } |
1679 | #endif |
1680 | |
1681 | ErrorString error; |
1682 | Ref<JSON::Object> result = JSON::Object::create(); |
1683 | m_agent->removeNode(error, in_nodeId); |
1684 | |
1685 | if (!error.length()) |
1686 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1687 | else |
1688 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1689 | } |
1690 | |
1691 | void DOMBackendDispatcher::setAttributeValue(long requestId, RefPtr<JSON::Object>&& parameters) |
1692 | { |
1693 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1694 | String in_name = m_backendDispatcher->getString(parameters.get(), "name"_s , nullptr); |
1695 | String in_value = m_backendDispatcher->getString(parameters.get(), "value"_s , nullptr); |
1696 | if (m_backendDispatcher->hasProtocolErrors()) { |
1697 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setAttributeValue' can't be processed"_s ); |
1698 | return; |
1699 | } |
1700 | |
1701 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1702 | if (m_alternateDispatcher) { |
1703 | m_alternateDispatcher->setAttributeValue(requestId, in_nodeId, in_name, in_value); |
1704 | return; |
1705 | } |
1706 | #endif |
1707 | |
1708 | ErrorString error; |
1709 | Ref<JSON::Object> result = JSON::Object::create(); |
1710 | m_agent->setAttributeValue(error, in_nodeId, in_name, in_value); |
1711 | |
1712 | if (!error.length()) |
1713 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1714 | else |
1715 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1716 | } |
1717 | |
1718 | void DOMBackendDispatcher::setAttributesAsText(long requestId, RefPtr<JSON::Object>&& parameters) |
1719 | { |
1720 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1721 | String in_text = m_backendDispatcher->getString(parameters.get(), "text"_s , nullptr); |
1722 | bool opt_in_name_valueFound = false; |
1723 | String opt_in_name = m_backendDispatcher->getString(parameters.get(), "name"_s , &opt_in_name_valueFound); |
1724 | if (m_backendDispatcher->hasProtocolErrors()) { |
1725 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setAttributesAsText' can't be processed"_s ); |
1726 | return; |
1727 | } |
1728 | |
1729 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1730 | if (m_alternateDispatcher) { |
1731 | m_alternateDispatcher->setAttributesAsText(requestId, in_nodeId, in_text, opt_in_name_valueFound ? &opt_in_name : nullptr); |
1732 | return; |
1733 | } |
1734 | #endif |
1735 | |
1736 | ErrorString error; |
1737 | Ref<JSON::Object> result = JSON::Object::create(); |
1738 | m_agent->setAttributesAsText(error, in_nodeId, in_text, opt_in_name_valueFound ? &opt_in_name : nullptr); |
1739 | |
1740 | if (!error.length()) |
1741 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1742 | else |
1743 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1744 | } |
1745 | |
1746 | void DOMBackendDispatcher::removeAttribute(long requestId, RefPtr<JSON::Object>&& parameters) |
1747 | { |
1748 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1749 | String in_name = m_backendDispatcher->getString(parameters.get(), "name"_s , nullptr); |
1750 | if (m_backendDispatcher->hasProtocolErrors()) { |
1751 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.removeAttribute' can't be processed"_s ); |
1752 | return; |
1753 | } |
1754 | |
1755 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1756 | if (m_alternateDispatcher) { |
1757 | m_alternateDispatcher->removeAttribute(requestId, in_nodeId, in_name); |
1758 | return; |
1759 | } |
1760 | #endif |
1761 | |
1762 | ErrorString error; |
1763 | Ref<JSON::Object> result = JSON::Object::create(); |
1764 | m_agent->removeAttribute(error, in_nodeId, in_name); |
1765 | |
1766 | if (!error.length()) |
1767 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1768 | else |
1769 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1770 | } |
1771 | |
1772 | void DOMBackendDispatcher::getSupportedEventNames(long requestId, RefPtr<JSON::Object>&&) |
1773 | { |
1774 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1775 | if (m_alternateDispatcher) { |
1776 | m_alternateDispatcher->getSupportedEventNames(requestId); |
1777 | return; |
1778 | } |
1779 | #endif |
1780 | |
1781 | ErrorString error; |
1782 | Ref<JSON::Object> result = JSON::Object::create(); |
1783 | RefPtr<JSON::ArrayOf<String>> out_eventNames; |
1784 | m_agent->getSupportedEventNames(error, out_eventNames); |
1785 | |
1786 | if (!error.length()) |
1787 | result->setArray("eventNames"_s , out_eventNames); |
1788 | |
1789 | if (!error.length()) |
1790 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1791 | else |
1792 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1793 | } |
1794 | |
1795 | void DOMBackendDispatcher::getDataBindingsForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
1796 | { |
1797 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1798 | if (m_backendDispatcher->hasProtocolErrors()) { |
1799 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getDataBindingsForNode' can't be processed"_s ); |
1800 | return; |
1801 | } |
1802 | |
1803 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1804 | if (m_alternateDispatcher) { |
1805 | m_alternateDispatcher->getDataBindingsForNode(requestId, in_nodeId); |
1806 | return; |
1807 | } |
1808 | #endif |
1809 | |
1810 | ErrorString error; |
1811 | Ref<JSON::Object> result = JSON::Object::create(); |
1812 | RefPtr<JSON::ArrayOf<Inspector::Protocol::DOM::DataBinding>> out_dataBindings; |
1813 | m_agent->getDataBindingsForNode(error, in_nodeId, out_dataBindings); |
1814 | |
1815 | if (!error.length()) |
1816 | result->setArray("dataBindings"_s , out_dataBindings); |
1817 | |
1818 | if (!error.length()) |
1819 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1820 | else |
1821 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1822 | } |
1823 | |
1824 | void DOMBackendDispatcher::getAssociatedDataForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
1825 | { |
1826 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1827 | if (m_backendDispatcher->hasProtocolErrors()) { |
1828 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getAssociatedDataForNode' can't be processed"_s ); |
1829 | return; |
1830 | } |
1831 | |
1832 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1833 | if (m_alternateDispatcher) { |
1834 | m_alternateDispatcher->getAssociatedDataForNode(requestId, in_nodeId); |
1835 | return; |
1836 | } |
1837 | #endif |
1838 | |
1839 | ErrorString error; |
1840 | Ref<JSON::Object> result = JSON::Object::create(); |
1841 | Optional<String> out_associatedData; |
1842 | m_agent->getAssociatedDataForNode(error, in_nodeId, out_associatedData); |
1843 | |
1844 | if (!error.length()) |
1845 | if (out_associatedData.hasValue()) |
1846 | result->setString("associatedData"_s , *out_associatedData); |
1847 | |
1848 | if (!error.length()) |
1849 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1850 | else |
1851 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1852 | } |
1853 | |
1854 | void DOMBackendDispatcher::getEventListenersForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
1855 | { |
1856 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1857 | if (m_backendDispatcher->hasProtocolErrors()) { |
1858 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getEventListenersForNode' can't be processed"_s ); |
1859 | return; |
1860 | } |
1861 | |
1862 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1863 | if (m_alternateDispatcher) { |
1864 | m_alternateDispatcher->getEventListenersForNode(requestId, in_nodeId); |
1865 | return; |
1866 | } |
1867 | #endif |
1868 | |
1869 | ErrorString error; |
1870 | Ref<JSON::Object> result = JSON::Object::create(); |
1871 | RefPtr<JSON::ArrayOf<Inspector::Protocol::DOM::EventListener>> out_listeners; |
1872 | m_agent->getEventListenersForNode(error, in_nodeId, out_listeners); |
1873 | |
1874 | if (!error.length()) |
1875 | result->setArray("listeners"_s , out_listeners); |
1876 | |
1877 | if (!error.length()) |
1878 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1879 | else |
1880 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1881 | } |
1882 | |
1883 | void DOMBackendDispatcher::setEventListenerDisabled(long requestId, RefPtr<JSON::Object>&& parameters) |
1884 | { |
1885 | int in_eventListenerId = m_backendDispatcher->getInteger(parameters.get(), "eventListenerId"_s , nullptr); |
1886 | bool in_disabled = m_backendDispatcher->getBoolean(parameters.get(), "disabled"_s , nullptr); |
1887 | if (m_backendDispatcher->hasProtocolErrors()) { |
1888 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setEventListenerDisabled' can't be processed"_s ); |
1889 | return; |
1890 | } |
1891 | |
1892 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1893 | if (m_alternateDispatcher) { |
1894 | m_alternateDispatcher->setEventListenerDisabled(requestId, in_eventListenerId, in_disabled); |
1895 | return; |
1896 | } |
1897 | #endif |
1898 | |
1899 | ErrorString error; |
1900 | Ref<JSON::Object> result = JSON::Object::create(); |
1901 | m_agent->setEventListenerDisabled(error, in_eventListenerId, in_disabled); |
1902 | |
1903 | if (!error.length()) |
1904 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1905 | else |
1906 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1907 | } |
1908 | |
1909 | void DOMBackendDispatcher::setBreakpointForEventListener(long requestId, RefPtr<JSON::Object>&& parameters) |
1910 | { |
1911 | int in_eventListenerId = m_backendDispatcher->getInteger(parameters.get(), "eventListenerId"_s , nullptr); |
1912 | if (m_backendDispatcher->hasProtocolErrors()) { |
1913 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setBreakpointForEventListener' can't be processed"_s ); |
1914 | return; |
1915 | } |
1916 | |
1917 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1918 | if (m_alternateDispatcher) { |
1919 | m_alternateDispatcher->setBreakpointForEventListener(requestId, in_eventListenerId); |
1920 | return; |
1921 | } |
1922 | #endif |
1923 | |
1924 | ErrorString error; |
1925 | Ref<JSON::Object> result = JSON::Object::create(); |
1926 | m_agent->setBreakpointForEventListener(error, in_eventListenerId); |
1927 | |
1928 | if (!error.length()) |
1929 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1930 | else |
1931 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1932 | } |
1933 | |
1934 | void DOMBackendDispatcher::removeBreakpointForEventListener(long requestId, RefPtr<JSON::Object>&& parameters) |
1935 | { |
1936 | int in_eventListenerId = m_backendDispatcher->getInteger(parameters.get(), "eventListenerId"_s , nullptr); |
1937 | if (m_backendDispatcher->hasProtocolErrors()) { |
1938 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.removeBreakpointForEventListener' can't be processed"_s ); |
1939 | return; |
1940 | } |
1941 | |
1942 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1943 | if (m_alternateDispatcher) { |
1944 | m_alternateDispatcher->removeBreakpointForEventListener(requestId, in_eventListenerId); |
1945 | return; |
1946 | } |
1947 | #endif |
1948 | |
1949 | ErrorString error; |
1950 | Ref<JSON::Object> result = JSON::Object::create(); |
1951 | m_agent->removeBreakpointForEventListener(error, in_eventListenerId); |
1952 | |
1953 | if (!error.length()) |
1954 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1955 | else |
1956 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1957 | } |
1958 | |
1959 | void DOMBackendDispatcher::getAccessibilityPropertiesForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
1960 | { |
1961 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1962 | if (m_backendDispatcher->hasProtocolErrors()) { |
1963 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getAccessibilityPropertiesForNode' can't be processed"_s ); |
1964 | return; |
1965 | } |
1966 | |
1967 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1968 | if (m_alternateDispatcher) { |
1969 | m_alternateDispatcher->getAccessibilityPropertiesForNode(requestId, in_nodeId); |
1970 | return; |
1971 | } |
1972 | #endif |
1973 | |
1974 | ErrorString error; |
1975 | Ref<JSON::Object> result = JSON::Object::create(); |
1976 | RefPtr<Inspector::Protocol::DOM::AccessibilityProperties> out_properties; |
1977 | m_agent->getAccessibilityPropertiesForNode(error, in_nodeId, out_properties); |
1978 | |
1979 | if (!error.length()) |
1980 | result->setObject("properties"_s , out_properties); |
1981 | |
1982 | if (!error.length()) |
1983 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
1984 | else |
1985 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
1986 | } |
1987 | |
1988 | void DOMBackendDispatcher::getOuterHTML(long requestId, RefPtr<JSON::Object>&& parameters) |
1989 | { |
1990 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
1991 | if (m_backendDispatcher->hasProtocolErrors()) { |
1992 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getOuterHTML' can't be processed"_s ); |
1993 | return; |
1994 | } |
1995 | |
1996 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
1997 | if (m_alternateDispatcher) { |
1998 | m_alternateDispatcher->getOuterHTML(requestId, in_nodeId); |
1999 | return; |
2000 | } |
2001 | #endif |
2002 | |
2003 | ErrorString error; |
2004 | Ref<JSON::Object> result = JSON::Object::create(); |
2005 | String out_outerHTML; |
2006 | m_agent->getOuterHTML(error, in_nodeId, &out_outerHTML); |
2007 | |
2008 | if (!error.length()) |
2009 | result->setString("outerHTML"_s , out_outerHTML); |
2010 | |
2011 | if (!error.length()) |
2012 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2013 | else |
2014 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2015 | } |
2016 | |
2017 | void DOMBackendDispatcher::setOuterHTML(long requestId, RefPtr<JSON::Object>&& parameters) |
2018 | { |
2019 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2020 | String in_outerHTML = m_backendDispatcher->getString(parameters.get(), "outerHTML"_s , nullptr); |
2021 | if (m_backendDispatcher->hasProtocolErrors()) { |
2022 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setOuterHTML' can't be processed"_s ); |
2023 | return; |
2024 | } |
2025 | |
2026 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2027 | if (m_alternateDispatcher) { |
2028 | m_alternateDispatcher->setOuterHTML(requestId, in_nodeId, in_outerHTML); |
2029 | return; |
2030 | } |
2031 | #endif |
2032 | |
2033 | ErrorString error; |
2034 | Ref<JSON::Object> result = JSON::Object::create(); |
2035 | m_agent->setOuterHTML(error, in_nodeId, in_outerHTML); |
2036 | |
2037 | if (!error.length()) |
2038 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2039 | else |
2040 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2041 | } |
2042 | |
2043 | void DOMBackendDispatcher::insertAdjacentHTML(long requestId, RefPtr<JSON::Object>&& parameters) |
2044 | { |
2045 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2046 | String in_position = m_backendDispatcher->getString(parameters.get(), "position"_s , nullptr); |
2047 | String in_html = m_backendDispatcher->getString(parameters.get(), "html"_s , nullptr); |
2048 | if (m_backendDispatcher->hasProtocolErrors()) { |
2049 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.insertAdjacentHTML' can't be processed"_s ); |
2050 | return; |
2051 | } |
2052 | |
2053 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2054 | if (m_alternateDispatcher) { |
2055 | m_alternateDispatcher->insertAdjacentHTML(requestId, in_nodeId, in_position, in_html); |
2056 | return; |
2057 | } |
2058 | #endif |
2059 | |
2060 | ErrorString error; |
2061 | Ref<JSON::Object> result = JSON::Object::create(); |
2062 | m_agent->insertAdjacentHTML(error, in_nodeId, in_position, in_html); |
2063 | |
2064 | if (!error.length()) |
2065 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2066 | else |
2067 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2068 | } |
2069 | |
2070 | void DOMBackendDispatcher::performSearch(long requestId, RefPtr<JSON::Object>&& parameters) |
2071 | { |
2072 | String in_query = m_backendDispatcher->getString(parameters.get(), "query"_s , nullptr); |
2073 | bool opt_in_nodeIds_valueFound = false; |
2074 | RefPtr<JSON::Array> opt_in_nodeIds = m_backendDispatcher->getArray(parameters.get(), "nodeIds"_s , &opt_in_nodeIds_valueFound); |
2075 | bool opt_in_caseSensitive_valueFound = false; |
2076 | bool opt_in_caseSensitive = m_backendDispatcher->getBoolean(parameters.get(), "caseSensitive"_s , &opt_in_caseSensitive_valueFound); |
2077 | if (m_backendDispatcher->hasProtocolErrors()) { |
2078 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.performSearch' can't be processed"_s ); |
2079 | return; |
2080 | } |
2081 | |
2082 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2083 | if (m_alternateDispatcher) { |
2084 | m_alternateDispatcher->performSearch(requestId, in_query, opt_in_nodeIds_valueFound ? opt_in_nodeIds.get() : nullptr, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr); |
2085 | return; |
2086 | } |
2087 | #endif |
2088 | |
2089 | ErrorString error; |
2090 | Ref<JSON::Object> result = JSON::Object::create(); |
2091 | String out_searchId; |
2092 | int out_resultCount; |
2093 | m_agent->performSearch(error, in_query, opt_in_nodeIds_valueFound ? opt_in_nodeIds.get() : nullptr, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, &out_searchId, &out_resultCount); |
2094 | |
2095 | if (!error.length()) { |
2096 | result->setString("searchId"_s , out_searchId); |
2097 | result->setInteger("resultCount"_s , out_resultCount); |
2098 | } |
2099 | if (!error.length()) |
2100 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2101 | else |
2102 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2103 | } |
2104 | |
2105 | void DOMBackendDispatcher::getSearchResults(long requestId, RefPtr<JSON::Object>&& parameters) |
2106 | { |
2107 | String in_searchId = m_backendDispatcher->getString(parameters.get(), "searchId"_s , nullptr); |
2108 | int in_fromIndex = m_backendDispatcher->getInteger(parameters.get(), "fromIndex"_s , nullptr); |
2109 | int in_toIndex = m_backendDispatcher->getInteger(parameters.get(), "toIndex"_s , nullptr); |
2110 | if (m_backendDispatcher->hasProtocolErrors()) { |
2111 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getSearchResults' can't be processed"_s ); |
2112 | return; |
2113 | } |
2114 | |
2115 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2116 | if (m_alternateDispatcher) { |
2117 | m_alternateDispatcher->getSearchResults(requestId, in_searchId, in_fromIndex, in_toIndex); |
2118 | return; |
2119 | } |
2120 | #endif |
2121 | |
2122 | ErrorString error; |
2123 | Ref<JSON::Object> result = JSON::Object::create(); |
2124 | RefPtr<JSON::ArrayOf<int>> out_nodeIds; |
2125 | m_agent->getSearchResults(error, in_searchId, in_fromIndex, in_toIndex, out_nodeIds); |
2126 | |
2127 | if (!error.length()) |
2128 | result->setArray("nodeIds"_s , out_nodeIds); |
2129 | |
2130 | if (!error.length()) |
2131 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2132 | else |
2133 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2134 | } |
2135 | |
2136 | void DOMBackendDispatcher::discardSearchResults(long requestId, RefPtr<JSON::Object>&& parameters) |
2137 | { |
2138 | String in_searchId = m_backendDispatcher->getString(parameters.get(), "searchId"_s , nullptr); |
2139 | if (m_backendDispatcher->hasProtocolErrors()) { |
2140 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.discardSearchResults' can't be processed"_s ); |
2141 | return; |
2142 | } |
2143 | |
2144 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2145 | if (m_alternateDispatcher) { |
2146 | m_alternateDispatcher->discardSearchResults(requestId, in_searchId); |
2147 | return; |
2148 | } |
2149 | #endif |
2150 | |
2151 | ErrorString error; |
2152 | Ref<JSON::Object> result = JSON::Object::create(); |
2153 | m_agent->discardSearchResults(error, in_searchId); |
2154 | |
2155 | if (!error.length()) |
2156 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2157 | else |
2158 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2159 | } |
2160 | |
2161 | void DOMBackendDispatcher::requestNode(long requestId, RefPtr<JSON::Object>&& parameters) |
2162 | { |
2163 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
2164 | if (m_backendDispatcher->hasProtocolErrors()) { |
2165 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.requestNode' can't be processed"_s ); |
2166 | return; |
2167 | } |
2168 | |
2169 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2170 | if (m_alternateDispatcher) { |
2171 | m_alternateDispatcher->requestNode(requestId, in_objectId); |
2172 | return; |
2173 | } |
2174 | #endif |
2175 | |
2176 | ErrorString error; |
2177 | Ref<JSON::Object> result = JSON::Object::create(); |
2178 | int out_nodeId; |
2179 | m_agent->requestNode(error, in_objectId, &out_nodeId); |
2180 | |
2181 | if (!error.length()) |
2182 | result->setInteger("nodeId"_s , out_nodeId); |
2183 | |
2184 | if (!error.length()) |
2185 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2186 | else |
2187 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2188 | } |
2189 | |
2190 | void DOMBackendDispatcher::setInspectModeEnabled(long requestId, RefPtr<JSON::Object>&& parameters) |
2191 | { |
2192 | bool in_enabled = m_backendDispatcher->getBoolean(parameters.get(), "enabled"_s , nullptr); |
2193 | bool opt_in_highlightConfig_valueFound = false; |
2194 | RefPtr<JSON::Object> opt_in_highlightConfig = m_backendDispatcher->getObject(parameters.get(), "highlightConfig"_s , &opt_in_highlightConfig_valueFound); |
2195 | if (m_backendDispatcher->hasProtocolErrors()) { |
2196 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setInspectModeEnabled' can't be processed"_s ); |
2197 | return; |
2198 | } |
2199 | |
2200 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2201 | if (m_alternateDispatcher) { |
2202 | m_alternateDispatcher->setInspectModeEnabled(requestId, in_enabled, opt_in_highlightConfig_valueFound ? opt_in_highlightConfig.get() : nullptr); |
2203 | return; |
2204 | } |
2205 | #endif |
2206 | |
2207 | ErrorString error; |
2208 | Ref<JSON::Object> result = JSON::Object::create(); |
2209 | m_agent->setInspectModeEnabled(error, in_enabled, opt_in_highlightConfig_valueFound ? opt_in_highlightConfig.get() : nullptr); |
2210 | |
2211 | if (!error.length()) |
2212 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2213 | else |
2214 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2215 | } |
2216 | |
2217 | void DOMBackendDispatcher::highlightRect(long requestId, RefPtr<JSON::Object>&& parameters) |
2218 | { |
2219 | int in_x = m_backendDispatcher->getInteger(parameters.get(), "x"_s , nullptr); |
2220 | int in_y = m_backendDispatcher->getInteger(parameters.get(), "y"_s , nullptr); |
2221 | int in_width = m_backendDispatcher->getInteger(parameters.get(), "width"_s , nullptr); |
2222 | int in_height = m_backendDispatcher->getInteger(parameters.get(), "height"_s , nullptr); |
2223 | bool opt_in_color_valueFound = false; |
2224 | RefPtr<JSON::Object> opt_in_color = m_backendDispatcher->getObject(parameters.get(), "color"_s , &opt_in_color_valueFound); |
2225 | bool opt_in_outlineColor_valueFound = false; |
2226 | RefPtr<JSON::Object> opt_in_outlineColor = m_backendDispatcher->getObject(parameters.get(), "outlineColor"_s , &opt_in_outlineColor_valueFound); |
2227 | bool opt_in_usePageCoordinates_valueFound = false; |
2228 | bool opt_in_usePageCoordinates = m_backendDispatcher->getBoolean(parameters.get(), "usePageCoordinates"_s , &opt_in_usePageCoordinates_valueFound); |
2229 | if (m_backendDispatcher->hasProtocolErrors()) { |
2230 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightRect' can't be processed"_s ); |
2231 | return; |
2232 | } |
2233 | |
2234 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2235 | if (m_alternateDispatcher) { |
2236 | m_alternateDispatcher->highlightRect(requestId, in_x, in_y, in_width, in_height, opt_in_color_valueFound ? opt_in_color.get() : nullptr, opt_in_outlineColor_valueFound ? opt_in_outlineColor.get() : nullptr, opt_in_usePageCoordinates_valueFound ? &opt_in_usePageCoordinates : nullptr); |
2237 | return; |
2238 | } |
2239 | #endif |
2240 | |
2241 | ErrorString error; |
2242 | Ref<JSON::Object> result = JSON::Object::create(); |
2243 | m_agent->highlightRect(error, in_x, in_y, in_width, in_height, opt_in_color_valueFound ? opt_in_color.get() : nullptr, opt_in_outlineColor_valueFound ? opt_in_outlineColor.get() : nullptr, opt_in_usePageCoordinates_valueFound ? &opt_in_usePageCoordinates : nullptr); |
2244 | |
2245 | if (!error.length()) |
2246 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2247 | else |
2248 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2249 | } |
2250 | |
2251 | void DOMBackendDispatcher::highlightQuad(long requestId, RefPtr<JSON::Object>&& parameters) |
2252 | { |
2253 | RefPtr<JSON::Array> in_quad = m_backendDispatcher->getArray(parameters.get(), "quad"_s , nullptr); |
2254 | bool opt_in_color_valueFound = false; |
2255 | RefPtr<JSON::Object> opt_in_color = m_backendDispatcher->getObject(parameters.get(), "color"_s , &opt_in_color_valueFound); |
2256 | bool opt_in_outlineColor_valueFound = false; |
2257 | RefPtr<JSON::Object> opt_in_outlineColor = m_backendDispatcher->getObject(parameters.get(), "outlineColor"_s , &opt_in_outlineColor_valueFound); |
2258 | bool opt_in_usePageCoordinates_valueFound = false; |
2259 | bool opt_in_usePageCoordinates = m_backendDispatcher->getBoolean(parameters.get(), "usePageCoordinates"_s , &opt_in_usePageCoordinates_valueFound); |
2260 | if (m_backendDispatcher->hasProtocolErrors()) { |
2261 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightQuad' can't be processed"_s ); |
2262 | return; |
2263 | } |
2264 | |
2265 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2266 | if (m_alternateDispatcher) { |
2267 | m_alternateDispatcher->highlightQuad(requestId, *in_quad, opt_in_color_valueFound ? opt_in_color.get() : nullptr, opt_in_outlineColor_valueFound ? opt_in_outlineColor.get() : nullptr, opt_in_usePageCoordinates_valueFound ? &opt_in_usePageCoordinates : nullptr); |
2268 | return; |
2269 | } |
2270 | #endif |
2271 | |
2272 | ErrorString error; |
2273 | Ref<JSON::Object> result = JSON::Object::create(); |
2274 | m_agent->highlightQuad(error, *in_quad, opt_in_color_valueFound ? opt_in_color.get() : nullptr, opt_in_outlineColor_valueFound ? opt_in_outlineColor.get() : nullptr, opt_in_usePageCoordinates_valueFound ? &opt_in_usePageCoordinates : nullptr); |
2275 | |
2276 | if (!error.length()) |
2277 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2278 | else |
2279 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2280 | } |
2281 | |
2282 | void DOMBackendDispatcher::highlightSelector(long requestId, RefPtr<JSON::Object>&& parameters) |
2283 | { |
2284 | RefPtr<JSON::Object> in_highlightConfig = m_backendDispatcher->getObject(parameters.get(), "highlightConfig"_s , nullptr); |
2285 | String in_selectorString = m_backendDispatcher->getString(parameters.get(), "selectorString"_s , nullptr); |
2286 | bool opt_in_frameId_valueFound = false; |
2287 | String opt_in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , &opt_in_frameId_valueFound); |
2288 | if (m_backendDispatcher->hasProtocolErrors()) { |
2289 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightSelector' can't be processed"_s ); |
2290 | return; |
2291 | } |
2292 | |
2293 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2294 | if (m_alternateDispatcher) { |
2295 | m_alternateDispatcher->highlightSelector(requestId, *in_highlightConfig, in_selectorString, opt_in_frameId_valueFound ? &opt_in_frameId : nullptr); |
2296 | return; |
2297 | } |
2298 | #endif |
2299 | |
2300 | ErrorString error; |
2301 | Ref<JSON::Object> result = JSON::Object::create(); |
2302 | m_agent->highlightSelector(error, *in_highlightConfig, in_selectorString, opt_in_frameId_valueFound ? &opt_in_frameId : nullptr); |
2303 | |
2304 | if (!error.length()) |
2305 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2306 | else |
2307 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2308 | } |
2309 | |
2310 | void DOMBackendDispatcher::highlightNode(long requestId, RefPtr<JSON::Object>&& parameters) |
2311 | { |
2312 | RefPtr<JSON::Object> in_highlightConfig = m_backendDispatcher->getObject(parameters.get(), "highlightConfig"_s , nullptr); |
2313 | bool opt_in_nodeId_valueFound = false; |
2314 | int opt_in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , &opt_in_nodeId_valueFound); |
2315 | bool opt_in_objectId_valueFound = false; |
2316 | String opt_in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , &opt_in_objectId_valueFound); |
2317 | if (m_backendDispatcher->hasProtocolErrors()) { |
2318 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightNode' can't be processed"_s ); |
2319 | return; |
2320 | } |
2321 | |
2322 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2323 | if (m_alternateDispatcher) { |
2324 | m_alternateDispatcher->highlightNode(requestId, *in_highlightConfig, opt_in_nodeId_valueFound ? &opt_in_nodeId : nullptr, opt_in_objectId_valueFound ? &opt_in_objectId : nullptr); |
2325 | return; |
2326 | } |
2327 | #endif |
2328 | |
2329 | ErrorString error; |
2330 | Ref<JSON::Object> result = JSON::Object::create(); |
2331 | m_agent->highlightNode(error, *in_highlightConfig, opt_in_nodeId_valueFound ? &opt_in_nodeId : nullptr, opt_in_objectId_valueFound ? &opt_in_objectId : nullptr); |
2332 | |
2333 | if (!error.length()) |
2334 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2335 | else |
2336 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2337 | } |
2338 | |
2339 | void DOMBackendDispatcher::highlightNodeList(long requestId, RefPtr<JSON::Object>&& parameters) |
2340 | { |
2341 | RefPtr<JSON::Array> in_nodeIds = m_backendDispatcher->getArray(parameters.get(), "nodeIds"_s , nullptr); |
2342 | RefPtr<JSON::Object> in_highlightConfig = m_backendDispatcher->getObject(parameters.get(), "highlightConfig"_s , nullptr); |
2343 | if (m_backendDispatcher->hasProtocolErrors()) { |
2344 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightNodeList' can't be processed"_s ); |
2345 | return; |
2346 | } |
2347 | |
2348 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2349 | if (m_alternateDispatcher) { |
2350 | m_alternateDispatcher->highlightNodeList(requestId, *in_nodeIds, *in_highlightConfig); |
2351 | return; |
2352 | } |
2353 | #endif |
2354 | |
2355 | ErrorString error; |
2356 | Ref<JSON::Object> result = JSON::Object::create(); |
2357 | m_agent->highlightNodeList(error, *in_nodeIds, *in_highlightConfig); |
2358 | |
2359 | if (!error.length()) |
2360 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2361 | else |
2362 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2363 | } |
2364 | |
2365 | void DOMBackendDispatcher::hideHighlight(long requestId, RefPtr<JSON::Object>&&) |
2366 | { |
2367 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2368 | if (m_alternateDispatcher) { |
2369 | m_alternateDispatcher->hideHighlight(requestId); |
2370 | return; |
2371 | } |
2372 | #endif |
2373 | |
2374 | ErrorString error; |
2375 | Ref<JSON::Object> result = JSON::Object::create(); |
2376 | m_agent->hideHighlight(error); |
2377 | |
2378 | if (!error.length()) |
2379 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2380 | else |
2381 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2382 | } |
2383 | |
2384 | void DOMBackendDispatcher::highlightFrame(long requestId, RefPtr<JSON::Object>&& parameters) |
2385 | { |
2386 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
2387 | bool opt_in_contentColor_valueFound = false; |
2388 | RefPtr<JSON::Object> opt_in_contentColor = m_backendDispatcher->getObject(parameters.get(), "contentColor"_s , &opt_in_contentColor_valueFound); |
2389 | bool opt_in_contentOutlineColor_valueFound = false; |
2390 | RefPtr<JSON::Object> opt_in_contentOutlineColor = m_backendDispatcher->getObject(parameters.get(), "contentOutlineColor"_s , &opt_in_contentOutlineColor_valueFound); |
2391 | if (m_backendDispatcher->hasProtocolErrors()) { |
2392 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightFrame' can't be processed"_s ); |
2393 | return; |
2394 | } |
2395 | |
2396 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2397 | if (m_alternateDispatcher) { |
2398 | m_alternateDispatcher->highlightFrame(requestId, in_frameId, opt_in_contentColor_valueFound ? opt_in_contentColor.get() : nullptr, opt_in_contentOutlineColor_valueFound ? opt_in_contentOutlineColor.get() : nullptr); |
2399 | return; |
2400 | } |
2401 | #endif |
2402 | |
2403 | ErrorString error; |
2404 | Ref<JSON::Object> result = JSON::Object::create(); |
2405 | m_agent->highlightFrame(error, in_frameId, opt_in_contentColor_valueFound ? opt_in_contentColor.get() : nullptr, opt_in_contentOutlineColor_valueFound ? opt_in_contentOutlineColor.get() : nullptr); |
2406 | |
2407 | if (!error.length()) |
2408 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2409 | else |
2410 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2411 | } |
2412 | |
2413 | void DOMBackendDispatcher::pushNodeByPathToFrontend(long requestId, RefPtr<JSON::Object>&& parameters) |
2414 | { |
2415 | String in_path = m_backendDispatcher->getString(parameters.get(), "path"_s , nullptr); |
2416 | if (m_backendDispatcher->hasProtocolErrors()) { |
2417 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.pushNodeByPathToFrontend' can't be processed"_s ); |
2418 | return; |
2419 | } |
2420 | |
2421 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2422 | if (m_alternateDispatcher) { |
2423 | m_alternateDispatcher->pushNodeByPathToFrontend(requestId, in_path); |
2424 | return; |
2425 | } |
2426 | #endif |
2427 | |
2428 | ErrorString error; |
2429 | Ref<JSON::Object> result = JSON::Object::create(); |
2430 | int out_nodeId; |
2431 | m_agent->pushNodeByPathToFrontend(error, in_path, &out_nodeId); |
2432 | |
2433 | if (!error.length()) |
2434 | result->setInteger("nodeId"_s , out_nodeId); |
2435 | |
2436 | if (!error.length()) |
2437 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2438 | else |
2439 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2440 | } |
2441 | |
2442 | void DOMBackendDispatcher::resolveNode(long requestId, RefPtr<JSON::Object>&& parameters) |
2443 | { |
2444 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2445 | bool opt_in_objectGroup_valueFound = false; |
2446 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
2447 | if (m_backendDispatcher->hasProtocolErrors()) { |
2448 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.resolveNode' can't be processed"_s ); |
2449 | return; |
2450 | } |
2451 | |
2452 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2453 | if (m_alternateDispatcher) { |
2454 | m_alternateDispatcher->resolveNode(requestId, in_nodeId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr); |
2455 | return; |
2456 | } |
2457 | #endif |
2458 | |
2459 | ErrorString error; |
2460 | Ref<JSON::Object> result = JSON::Object::create(); |
2461 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_object; |
2462 | m_agent->resolveNode(error, in_nodeId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, out_object); |
2463 | |
2464 | if (!error.length()) |
2465 | result->setObject("object"_s , out_object); |
2466 | |
2467 | if (!error.length()) |
2468 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2469 | else |
2470 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2471 | } |
2472 | |
2473 | void DOMBackendDispatcher::getAttributes(long requestId, RefPtr<JSON::Object>&& parameters) |
2474 | { |
2475 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2476 | if (m_backendDispatcher->hasProtocolErrors()) { |
2477 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getAttributes' can't be processed"_s ); |
2478 | return; |
2479 | } |
2480 | |
2481 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2482 | if (m_alternateDispatcher) { |
2483 | m_alternateDispatcher->getAttributes(requestId, in_nodeId); |
2484 | return; |
2485 | } |
2486 | #endif |
2487 | |
2488 | ErrorString error; |
2489 | Ref<JSON::Object> result = JSON::Object::create(); |
2490 | RefPtr<JSON::ArrayOf<String>> out_attributes; |
2491 | m_agent->getAttributes(error, in_nodeId, out_attributes); |
2492 | |
2493 | if (!error.length()) |
2494 | result->setArray("attributes"_s , out_attributes); |
2495 | |
2496 | if (!error.length()) |
2497 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2498 | else |
2499 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2500 | } |
2501 | |
2502 | void DOMBackendDispatcher::moveTo(long requestId, RefPtr<JSON::Object>&& parameters) |
2503 | { |
2504 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2505 | int in_targetNodeId = m_backendDispatcher->getInteger(parameters.get(), "targetNodeId"_s , nullptr); |
2506 | bool opt_in_insertBeforeNodeId_valueFound = false; |
2507 | int opt_in_insertBeforeNodeId = m_backendDispatcher->getInteger(parameters.get(), "insertBeforeNodeId"_s , &opt_in_insertBeforeNodeId_valueFound); |
2508 | if (m_backendDispatcher->hasProtocolErrors()) { |
2509 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.moveTo' can't be processed"_s ); |
2510 | return; |
2511 | } |
2512 | |
2513 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2514 | if (m_alternateDispatcher) { |
2515 | m_alternateDispatcher->moveTo(requestId, in_nodeId, in_targetNodeId, opt_in_insertBeforeNodeId_valueFound ? &opt_in_insertBeforeNodeId : nullptr); |
2516 | return; |
2517 | } |
2518 | #endif |
2519 | |
2520 | ErrorString error; |
2521 | Ref<JSON::Object> result = JSON::Object::create(); |
2522 | int out_nodeId; |
2523 | m_agent->moveTo(error, in_nodeId, in_targetNodeId, opt_in_insertBeforeNodeId_valueFound ? &opt_in_insertBeforeNodeId : nullptr, &out_nodeId); |
2524 | |
2525 | if (!error.length()) |
2526 | result->setInteger("nodeId"_s , out_nodeId); |
2527 | |
2528 | if (!error.length()) |
2529 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2530 | else |
2531 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2532 | } |
2533 | |
2534 | void DOMBackendDispatcher::undo(long requestId, RefPtr<JSON::Object>&&) |
2535 | { |
2536 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2537 | if (m_alternateDispatcher) { |
2538 | m_alternateDispatcher->undo(requestId); |
2539 | return; |
2540 | } |
2541 | #endif |
2542 | |
2543 | ErrorString error; |
2544 | Ref<JSON::Object> result = JSON::Object::create(); |
2545 | m_agent->undo(error); |
2546 | |
2547 | if (!error.length()) |
2548 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2549 | else |
2550 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2551 | } |
2552 | |
2553 | void DOMBackendDispatcher::redo(long requestId, RefPtr<JSON::Object>&&) |
2554 | { |
2555 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2556 | if (m_alternateDispatcher) { |
2557 | m_alternateDispatcher->redo(requestId); |
2558 | return; |
2559 | } |
2560 | #endif |
2561 | |
2562 | ErrorString error; |
2563 | Ref<JSON::Object> result = JSON::Object::create(); |
2564 | m_agent->redo(error); |
2565 | |
2566 | if (!error.length()) |
2567 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2568 | else |
2569 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2570 | } |
2571 | |
2572 | void DOMBackendDispatcher::markUndoableState(long requestId, RefPtr<JSON::Object>&&) |
2573 | { |
2574 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2575 | if (m_alternateDispatcher) { |
2576 | m_alternateDispatcher->markUndoableState(requestId); |
2577 | return; |
2578 | } |
2579 | #endif |
2580 | |
2581 | ErrorString error; |
2582 | Ref<JSON::Object> result = JSON::Object::create(); |
2583 | m_agent->markUndoableState(error); |
2584 | |
2585 | if (!error.length()) |
2586 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2587 | else |
2588 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2589 | } |
2590 | |
2591 | void DOMBackendDispatcher::focus(long requestId, RefPtr<JSON::Object>&& parameters) |
2592 | { |
2593 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2594 | if (m_backendDispatcher->hasProtocolErrors()) { |
2595 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.focus' can't be processed"_s ); |
2596 | return; |
2597 | } |
2598 | |
2599 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2600 | if (m_alternateDispatcher) { |
2601 | m_alternateDispatcher->focus(requestId, in_nodeId); |
2602 | return; |
2603 | } |
2604 | #endif |
2605 | |
2606 | ErrorString error; |
2607 | Ref<JSON::Object> result = JSON::Object::create(); |
2608 | m_agent->focus(error, in_nodeId); |
2609 | |
2610 | if (!error.length()) |
2611 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2612 | else |
2613 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2614 | } |
2615 | |
2616 | void DOMBackendDispatcher::setInspectedNode(long requestId, RefPtr<JSON::Object>&& parameters) |
2617 | { |
2618 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2619 | if (m_backendDispatcher->hasProtocolErrors()) { |
2620 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setInspectedNode' can't be processed"_s ); |
2621 | return; |
2622 | } |
2623 | |
2624 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2625 | if (m_alternateDispatcher) { |
2626 | m_alternateDispatcher->setInspectedNode(requestId, in_nodeId); |
2627 | return; |
2628 | } |
2629 | #endif |
2630 | |
2631 | ErrorString error; |
2632 | Ref<JSON::Object> result = JSON::Object::create(); |
2633 | m_agent->setInspectedNode(error, in_nodeId); |
2634 | |
2635 | if (!error.length()) |
2636 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2637 | else |
2638 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2639 | } |
2640 | |
2641 | Ref<DOMDebuggerBackendDispatcher> DOMDebuggerBackendDispatcher::create(BackendDispatcher& backendDispatcher, DOMDebuggerBackendDispatcherHandler* agent) |
2642 | { |
2643 | return adoptRef(*new DOMDebuggerBackendDispatcher(backendDispatcher, agent)); |
2644 | } |
2645 | |
2646 | DOMDebuggerBackendDispatcher::DOMDebuggerBackendDispatcher(BackendDispatcher& backendDispatcher, DOMDebuggerBackendDispatcherHandler* agent) |
2647 | : SupplementalBackendDispatcher(backendDispatcher) |
2648 | , m_agent(agent) |
2649 | { |
2650 | m_backendDispatcher->registerDispatcherForDomain("DOMDebugger"_s , this); |
2651 | } |
2652 | |
2653 | void DOMDebuggerBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
2654 | { |
2655 | Ref<DOMDebuggerBackendDispatcher> protect(*this); |
2656 | |
2657 | RefPtr<JSON::Object> parameters; |
2658 | message->getObject("params"_s , parameters); |
2659 | |
2660 | typedef void (DOMDebuggerBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
2661 | typedef HashMap<String, CallHandler> DispatchMap; |
2662 | static NeverDestroyed<DispatchMap> dispatchMap; |
2663 | if (dispatchMap.get().isEmpty()) { |
2664 | static const struct MethodTable { |
2665 | const char* name; |
2666 | CallHandler handler; |
2667 | } commands[] = { |
2668 | { "setDOMBreakpoint" , &DOMDebuggerBackendDispatcher::setDOMBreakpoint }, |
2669 | { "removeDOMBreakpoint" , &DOMDebuggerBackendDispatcher::removeDOMBreakpoint }, |
2670 | { "setEventBreakpoint" , &DOMDebuggerBackendDispatcher::setEventBreakpoint }, |
2671 | { "removeEventBreakpoint" , &DOMDebuggerBackendDispatcher::removeEventBreakpoint }, |
2672 | { "setURLBreakpoint" , &DOMDebuggerBackendDispatcher::setURLBreakpoint }, |
2673 | { "removeURLBreakpoint" , &DOMDebuggerBackendDispatcher::removeURLBreakpoint }, |
2674 | }; |
2675 | size_t length = WTF_ARRAY_LENGTH(commands); |
2676 | for (size_t i = 0; i < length; ++i) |
2677 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
2678 | } |
2679 | |
2680 | auto findResult = dispatchMap.get().find(method); |
2681 | if (findResult == dispatchMap.get().end()) { |
2682 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'DOMDebugger." + method + "' was not found" ); |
2683 | return; |
2684 | } |
2685 | |
2686 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
2687 | } |
2688 | |
2689 | void DOMDebuggerBackendDispatcher::setDOMBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
2690 | { |
2691 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2692 | String in_type = m_backendDispatcher->getString(parameters.get(), "type"_s , nullptr); |
2693 | if (m_backendDispatcher->hasProtocolErrors()) { |
2694 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.setDOMBreakpoint' can't be processed"_s ); |
2695 | return; |
2696 | } |
2697 | |
2698 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2699 | if (m_alternateDispatcher) { |
2700 | m_alternateDispatcher->setDOMBreakpoint(requestId, in_nodeId, in_type); |
2701 | return; |
2702 | } |
2703 | #endif |
2704 | |
2705 | ErrorString error; |
2706 | Ref<JSON::Object> result = JSON::Object::create(); |
2707 | m_agent->setDOMBreakpoint(error, in_nodeId, in_type); |
2708 | |
2709 | if (!error.length()) |
2710 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2711 | else |
2712 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2713 | } |
2714 | |
2715 | void DOMDebuggerBackendDispatcher::removeDOMBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
2716 | { |
2717 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
2718 | String in_type = m_backendDispatcher->getString(parameters.get(), "type"_s , nullptr); |
2719 | if (m_backendDispatcher->hasProtocolErrors()) { |
2720 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.removeDOMBreakpoint' can't be processed"_s ); |
2721 | return; |
2722 | } |
2723 | |
2724 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2725 | if (m_alternateDispatcher) { |
2726 | m_alternateDispatcher->removeDOMBreakpoint(requestId, in_nodeId, in_type); |
2727 | return; |
2728 | } |
2729 | #endif |
2730 | |
2731 | ErrorString error; |
2732 | Ref<JSON::Object> result = JSON::Object::create(); |
2733 | m_agent->removeDOMBreakpoint(error, in_nodeId, in_type); |
2734 | |
2735 | if (!error.length()) |
2736 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2737 | else |
2738 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2739 | } |
2740 | |
2741 | void DOMDebuggerBackendDispatcher::setEventBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
2742 | { |
2743 | String in_breakpointType = m_backendDispatcher->getString(parameters.get(), "breakpointType"_s , nullptr); |
2744 | String in_eventName = m_backendDispatcher->getString(parameters.get(), "eventName"_s , nullptr); |
2745 | if (m_backendDispatcher->hasProtocolErrors()) { |
2746 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.setEventBreakpoint' can't be processed"_s ); |
2747 | return; |
2748 | } |
2749 | |
2750 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2751 | if (m_alternateDispatcher) { |
2752 | m_alternateDispatcher->setEventBreakpoint(requestId, in_breakpointType, in_eventName); |
2753 | return; |
2754 | } |
2755 | #endif |
2756 | |
2757 | ErrorString error; |
2758 | Ref<JSON::Object> result = JSON::Object::create(); |
2759 | m_agent->setEventBreakpoint(error, in_breakpointType, in_eventName); |
2760 | |
2761 | if (!error.length()) |
2762 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2763 | else |
2764 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2765 | } |
2766 | |
2767 | void DOMDebuggerBackendDispatcher::removeEventBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
2768 | { |
2769 | String in_breakpointType = m_backendDispatcher->getString(parameters.get(), "breakpointType"_s , nullptr); |
2770 | String in_eventName = m_backendDispatcher->getString(parameters.get(), "eventName"_s , nullptr); |
2771 | if (m_backendDispatcher->hasProtocolErrors()) { |
2772 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.removeEventBreakpoint' can't be processed"_s ); |
2773 | return; |
2774 | } |
2775 | |
2776 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2777 | if (m_alternateDispatcher) { |
2778 | m_alternateDispatcher->removeEventBreakpoint(requestId, in_breakpointType, in_eventName); |
2779 | return; |
2780 | } |
2781 | #endif |
2782 | |
2783 | ErrorString error; |
2784 | Ref<JSON::Object> result = JSON::Object::create(); |
2785 | m_agent->removeEventBreakpoint(error, in_breakpointType, in_eventName); |
2786 | |
2787 | if (!error.length()) |
2788 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2789 | else |
2790 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2791 | } |
2792 | |
2793 | void DOMDebuggerBackendDispatcher::setURLBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
2794 | { |
2795 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
2796 | bool opt_in_isRegex_valueFound = false; |
2797 | bool opt_in_isRegex = m_backendDispatcher->getBoolean(parameters.get(), "isRegex"_s , &opt_in_isRegex_valueFound); |
2798 | if (m_backendDispatcher->hasProtocolErrors()) { |
2799 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.setURLBreakpoint' can't be processed"_s ); |
2800 | return; |
2801 | } |
2802 | |
2803 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2804 | if (m_alternateDispatcher) { |
2805 | m_alternateDispatcher->setURLBreakpoint(requestId, in_url, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr); |
2806 | return; |
2807 | } |
2808 | #endif |
2809 | |
2810 | ErrorString error; |
2811 | Ref<JSON::Object> result = JSON::Object::create(); |
2812 | m_agent->setURLBreakpoint(error, in_url, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr); |
2813 | |
2814 | if (!error.length()) |
2815 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2816 | else |
2817 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2818 | } |
2819 | |
2820 | void DOMDebuggerBackendDispatcher::removeURLBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
2821 | { |
2822 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
2823 | if (m_backendDispatcher->hasProtocolErrors()) { |
2824 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.removeURLBreakpoint' can't be processed"_s ); |
2825 | return; |
2826 | } |
2827 | |
2828 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2829 | if (m_alternateDispatcher) { |
2830 | m_alternateDispatcher->removeURLBreakpoint(requestId, in_url); |
2831 | return; |
2832 | } |
2833 | #endif |
2834 | |
2835 | ErrorString error; |
2836 | Ref<JSON::Object> result = JSON::Object::create(); |
2837 | m_agent->removeURLBreakpoint(error, in_url); |
2838 | |
2839 | if (!error.length()) |
2840 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2841 | else |
2842 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2843 | } |
2844 | |
2845 | Ref<DOMStorageBackendDispatcher> DOMStorageBackendDispatcher::create(BackendDispatcher& backendDispatcher, DOMStorageBackendDispatcherHandler* agent) |
2846 | { |
2847 | return adoptRef(*new DOMStorageBackendDispatcher(backendDispatcher, agent)); |
2848 | } |
2849 | |
2850 | DOMStorageBackendDispatcher::DOMStorageBackendDispatcher(BackendDispatcher& backendDispatcher, DOMStorageBackendDispatcherHandler* agent) |
2851 | : SupplementalBackendDispatcher(backendDispatcher) |
2852 | , m_agent(agent) |
2853 | { |
2854 | m_backendDispatcher->registerDispatcherForDomain("DOMStorage"_s , this); |
2855 | } |
2856 | |
2857 | void DOMStorageBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
2858 | { |
2859 | Ref<DOMStorageBackendDispatcher> protect(*this); |
2860 | |
2861 | RefPtr<JSON::Object> parameters; |
2862 | message->getObject("params"_s , parameters); |
2863 | |
2864 | if (method == "enable" ) |
2865 | enable(requestId, WTFMove(parameters)); |
2866 | else if (method == "disable" ) |
2867 | disable(requestId, WTFMove(parameters)); |
2868 | else if (method == "getDOMStorageItems" ) |
2869 | getDOMStorageItems(requestId, WTFMove(parameters)); |
2870 | else if (method == "setDOMStorageItem" ) |
2871 | setDOMStorageItem(requestId, WTFMove(parameters)); |
2872 | else if (method == "removeDOMStorageItem" ) |
2873 | removeDOMStorageItem(requestId, WTFMove(parameters)); |
2874 | else |
2875 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'DOMStorage." + method + "' was not found" ); |
2876 | } |
2877 | |
2878 | void DOMStorageBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
2879 | { |
2880 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2881 | if (m_alternateDispatcher) { |
2882 | m_alternateDispatcher->enable(requestId); |
2883 | return; |
2884 | } |
2885 | #endif |
2886 | |
2887 | ErrorString error; |
2888 | Ref<JSON::Object> result = JSON::Object::create(); |
2889 | m_agent->enable(error); |
2890 | |
2891 | if (!error.length()) |
2892 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2893 | else |
2894 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2895 | } |
2896 | |
2897 | void DOMStorageBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
2898 | { |
2899 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2900 | if (m_alternateDispatcher) { |
2901 | m_alternateDispatcher->disable(requestId); |
2902 | return; |
2903 | } |
2904 | #endif |
2905 | |
2906 | ErrorString error; |
2907 | Ref<JSON::Object> result = JSON::Object::create(); |
2908 | m_agent->disable(error); |
2909 | |
2910 | if (!error.length()) |
2911 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2912 | else |
2913 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2914 | } |
2915 | |
2916 | void DOMStorageBackendDispatcher::getDOMStorageItems(long requestId, RefPtr<JSON::Object>&& parameters) |
2917 | { |
2918 | RefPtr<JSON::Object> in_storageId = m_backendDispatcher->getObject(parameters.get(), "storageId"_s , nullptr); |
2919 | if (m_backendDispatcher->hasProtocolErrors()) { |
2920 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.getDOMStorageItems' can't be processed"_s ); |
2921 | return; |
2922 | } |
2923 | |
2924 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2925 | if (m_alternateDispatcher) { |
2926 | m_alternateDispatcher->getDOMStorageItems(requestId, *in_storageId); |
2927 | return; |
2928 | } |
2929 | #endif |
2930 | |
2931 | ErrorString error; |
2932 | Ref<JSON::Object> result = JSON::Object::create(); |
2933 | RefPtr<JSON::ArrayOf<Inspector::Protocol::DOMStorage::Item>> out_entries; |
2934 | m_agent->getDOMStorageItems(error, *in_storageId, out_entries); |
2935 | |
2936 | if (!error.length()) |
2937 | result->setArray("entries"_s , out_entries); |
2938 | |
2939 | if (!error.length()) |
2940 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2941 | else |
2942 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2943 | } |
2944 | |
2945 | void DOMStorageBackendDispatcher::setDOMStorageItem(long requestId, RefPtr<JSON::Object>&& parameters) |
2946 | { |
2947 | RefPtr<JSON::Object> in_storageId = m_backendDispatcher->getObject(parameters.get(), "storageId"_s , nullptr); |
2948 | String in_key = m_backendDispatcher->getString(parameters.get(), "key"_s , nullptr); |
2949 | String in_value = m_backendDispatcher->getString(parameters.get(), "value"_s , nullptr); |
2950 | if (m_backendDispatcher->hasProtocolErrors()) { |
2951 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.setDOMStorageItem' can't be processed"_s ); |
2952 | return; |
2953 | } |
2954 | |
2955 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2956 | if (m_alternateDispatcher) { |
2957 | m_alternateDispatcher->setDOMStorageItem(requestId, *in_storageId, in_key, in_value); |
2958 | return; |
2959 | } |
2960 | #endif |
2961 | |
2962 | ErrorString error; |
2963 | Ref<JSON::Object> result = JSON::Object::create(); |
2964 | m_agent->setDOMStorageItem(error, *in_storageId, in_key, in_value); |
2965 | |
2966 | if (!error.length()) |
2967 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2968 | else |
2969 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2970 | } |
2971 | |
2972 | void DOMStorageBackendDispatcher::removeDOMStorageItem(long requestId, RefPtr<JSON::Object>&& parameters) |
2973 | { |
2974 | RefPtr<JSON::Object> in_storageId = m_backendDispatcher->getObject(parameters.get(), "storageId"_s , nullptr); |
2975 | String in_key = m_backendDispatcher->getString(parameters.get(), "key"_s , nullptr); |
2976 | if (m_backendDispatcher->hasProtocolErrors()) { |
2977 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.removeDOMStorageItem' can't be processed"_s ); |
2978 | return; |
2979 | } |
2980 | |
2981 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
2982 | if (m_alternateDispatcher) { |
2983 | m_alternateDispatcher->removeDOMStorageItem(requestId, *in_storageId, in_key); |
2984 | return; |
2985 | } |
2986 | #endif |
2987 | |
2988 | ErrorString error; |
2989 | Ref<JSON::Object> result = JSON::Object::create(); |
2990 | m_agent->removeDOMStorageItem(error, *in_storageId, in_key); |
2991 | |
2992 | if (!error.length()) |
2993 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
2994 | else |
2995 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
2996 | } |
2997 | |
2998 | Ref<DatabaseBackendDispatcher> DatabaseBackendDispatcher::create(BackendDispatcher& backendDispatcher, DatabaseBackendDispatcherHandler* agent) |
2999 | { |
3000 | return adoptRef(*new DatabaseBackendDispatcher(backendDispatcher, agent)); |
3001 | } |
3002 | |
3003 | DatabaseBackendDispatcher::DatabaseBackendDispatcher(BackendDispatcher& backendDispatcher, DatabaseBackendDispatcherHandler* agent) |
3004 | : SupplementalBackendDispatcher(backendDispatcher) |
3005 | , m_agent(agent) |
3006 | { |
3007 | m_backendDispatcher->registerDispatcherForDomain("Database"_s , this); |
3008 | } |
3009 | |
3010 | void DatabaseBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
3011 | { |
3012 | Ref<DatabaseBackendDispatcher> protect(*this); |
3013 | |
3014 | RefPtr<JSON::Object> parameters; |
3015 | message->getObject("params"_s , parameters); |
3016 | |
3017 | if (method == "enable" ) |
3018 | enable(requestId, WTFMove(parameters)); |
3019 | else if (method == "disable" ) |
3020 | disable(requestId, WTFMove(parameters)); |
3021 | else if (method == "getDatabaseTableNames" ) |
3022 | getDatabaseTableNames(requestId, WTFMove(parameters)); |
3023 | else if (method == "executeSQL" ) |
3024 | executeSQL(requestId, WTFMove(parameters)); |
3025 | else |
3026 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Database." + method + "' was not found" ); |
3027 | } |
3028 | |
3029 | void DatabaseBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
3030 | { |
3031 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3032 | if (m_alternateDispatcher) { |
3033 | m_alternateDispatcher->enable(requestId); |
3034 | return; |
3035 | } |
3036 | #endif |
3037 | |
3038 | ErrorString error; |
3039 | Ref<JSON::Object> result = JSON::Object::create(); |
3040 | m_agent->enable(error); |
3041 | |
3042 | if (!error.length()) |
3043 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3044 | else |
3045 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3046 | } |
3047 | |
3048 | void DatabaseBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
3049 | { |
3050 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3051 | if (m_alternateDispatcher) { |
3052 | m_alternateDispatcher->disable(requestId); |
3053 | return; |
3054 | } |
3055 | #endif |
3056 | |
3057 | ErrorString error; |
3058 | Ref<JSON::Object> result = JSON::Object::create(); |
3059 | m_agent->disable(error); |
3060 | |
3061 | if (!error.length()) |
3062 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3063 | else |
3064 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3065 | } |
3066 | |
3067 | void DatabaseBackendDispatcher::getDatabaseTableNames(long requestId, RefPtr<JSON::Object>&& parameters) |
3068 | { |
3069 | String in_databaseId = m_backendDispatcher->getString(parameters.get(), "databaseId"_s , nullptr); |
3070 | if (m_backendDispatcher->hasProtocolErrors()) { |
3071 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Database.getDatabaseTableNames' can't be processed"_s ); |
3072 | return; |
3073 | } |
3074 | |
3075 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3076 | if (m_alternateDispatcher) { |
3077 | m_alternateDispatcher->getDatabaseTableNames(requestId, in_databaseId); |
3078 | return; |
3079 | } |
3080 | #endif |
3081 | |
3082 | ErrorString error; |
3083 | Ref<JSON::Object> result = JSON::Object::create(); |
3084 | RefPtr<JSON::ArrayOf<String>> out_tableNames; |
3085 | m_agent->getDatabaseTableNames(error, in_databaseId, out_tableNames); |
3086 | |
3087 | if (!error.length()) |
3088 | result->setArray("tableNames"_s , out_tableNames); |
3089 | |
3090 | if (!error.length()) |
3091 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3092 | else |
3093 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3094 | } |
3095 | |
3096 | DatabaseBackendDispatcherHandler::ExecuteSQLCallback::ExecuteSQLCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
3097 | |
3098 | void DatabaseBackendDispatcherHandler::ExecuteSQLCallback::sendSuccess(RefPtr<JSON::ArrayOf<String>>&& columnNames, RefPtr<JSON::ArrayOf<JSON::Value>>&& values, RefPtr<Inspector::Protocol::Database::Error>&& sqlError) |
3099 | { |
3100 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
3101 | if (columnNames) |
3102 | jsonMessage->setArray("columnNames"_s , columnNames); |
3103 | if (values) |
3104 | jsonMessage->setArray("values"_s , values); |
3105 | if (sqlError) |
3106 | jsonMessage->setObject("sqlError"_s , sqlError); |
3107 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
3108 | } |
3109 | |
3110 | void DatabaseBackendDispatcher::executeSQL(long requestId, RefPtr<JSON::Object>&& parameters) |
3111 | { |
3112 | String in_databaseId = m_backendDispatcher->getString(parameters.get(), "databaseId"_s , nullptr); |
3113 | String in_query = m_backendDispatcher->getString(parameters.get(), "query"_s , nullptr); |
3114 | if (m_backendDispatcher->hasProtocolErrors()) { |
3115 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Database.executeSQL' can't be processed"_s ); |
3116 | return; |
3117 | } |
3118 | |
3119 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3120 | if (m_alternateDispatcher) { |
3121 | m_alternateDispatcher->executeSQL(requestId, in_databaseId, in_query); |
3122 | return; |
3123 | } |
3124 | #endif |
3125 | |
3126 | Ref<DatabaseBackendDispatcherHandler::ExecuteSQLCallback> callback = adoptRef(*new DatabaseBackendDispatcherHandler::ExecuteSQLCallback(m_backendDispatcher.copyRef(), requestId)); |
3127 | m_agent->executeSQL(in_databaseId, in_query, callback.copyRef()); |
3128 | |
3129 | } |
3130 | |
3131 | Ref<DebuggerBackendDispatcher> DebuggerBackendDispatcher::create(BackendDispatcher& backendDispatcher, DebuggerBackendDispatcherHandler* agent) |
3132 | { |
3133 | return adoptRef(*new DebuggerBackendDispatcher(backendDispatcher, agent)); |
3134 | } |
3135 | |
3136 | DebuggerBackendDispatcher::DebuggerBackendDispatcher(BackendDispatcher& backendDispatcher, DebuggerBackendDispatcherHandler* agent) |
3137 | : SupplementalBackendDispatcher(backendDispatcher) |
3138 | , m_agent(agent) |
3139 | { |
3140 | m_backendDispatcher->registerDispatcherForDomain("Debugger"_s , this); |
3141 | } |
3142 | |
3143 | void DebuggerBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
3144 | { |
3145 | Ref<DebuggerBackendDispatcher> protect(*this); |
3146 | |
3147 | RefPtr<JSON::Object> parameters; |
3148 | message->getObject("params"_s , parameters); |
3149 | |
3150 | typedef void (DebuggerBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
3151 | typedef HashMap<String, CallHandler> DispatchMap; |
3152 | static NeverDestroyed<DispatchMap> dispatchMap; |
3153 | if (dispatchMap.get().isEmpty()) { |
3154 | static const struct MethodTable { |
3155 | const char* name; |
3156 | CallHandler handler; |
3157 | } commands[] = { |
3158 | { "enable" , &DebuggerBackendDispatcher::enable }, |
3159 | { "disable" , &DebuggerBackendDispatcher::disable }, |
3160 | { "setAsyncStackTraceDepth" , &DebuggerBackendDispatcher::setAsyncStackTraceDepth }, |
3161 | { "setBreakpointsActive" , &DebuggerBackendDispatcher::setBreakpointsActive }, |
3162 | { "setBreakpointByUrl" , &DebuggerBackendDispatcher::setBreakpointByUrl }, |
3163 | { "setBreakpoint" , &DebuggerBackendDispatcher::setBreakpoint }, |
3164 | { "removeBreakpoint" , &DebuggerBackendDispatcher::removeBreakpoint }, |
3165 | { "continueUntilNextRunLoop" , &DebuggerBackendDispatcher::continueUntilNextRunLoop }, |
3166 | { "continueToLocation" , &DebuggerBackendDispatcher::continueToLocation }, |
3167 | { "stepOver" , &DebuggerBackendDispatcher::stepOver }, |
3168 | { "stepInto" , &DebuggerBackendDispatcher::stepInto }, |
3169 | { "stepOut" , &DebuggerBackendDispatcher::stepOut }, |
3170 | { "pause" , &DebuggerBackendDispatcher::pause }, |
3171 | { "resume" , &DebuggerBackendDispatcher::resume }, |
3172 | { "searchInContent" , &DebuggerBackendDispatcher::searchInContent }, |
3173 | { "getScriptSource" , &DebuggerBackendDispatcher::getScriptSource }, |
3174 | { "getFunctionDetails" , &DebuggerBackendDispatcher::getFunctionDetails }, |
3175 | { "setPauseOnExceptions" , &DebuggerBackendDispatcher::setPauseOnExceptions }, |
3176 | { "setPauseOnAssertions" , &DebuggerBackendDispatcher::setPauseOnAssertions }, |
3177 | { "setPauseForInternalScripts" , &DebuggerBackendDispatcher::setPauseForInternalScripts }, |
3178 | { "evaluateOnCallFrame" , &DebuggerBackendDispatcher::evaluateOnCallFrame }, |
3179 | }; |
3180 | size_t length = WTF_ARRAY_LENGTH(commands); |
3181 | for (size_t i = 0; i < length; ++i) |
3182 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
3183 | } |
3184 | |
3185 | auto findResult = dispatchMap.get().find(method); |
3186 | if (findResult == dispatchMap.get().end()) { |
3187 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Debugger." + method + "' was not found" ); |
3188 | return; |
3189 | } |
3190 | |
3191 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
3192 | } |
3193 | |
3194 | void DebuggerBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
3195 | { |
3196 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3197 | if (m_alternateDispatcher) { |
3198 | m_alternateDispatcher->enable(requestId); |
3199 | return; |
3200 | } |
3201 | #endif |
3202 | |
3203 | ErrorString error; |
3204 | Ref<JSON::Object> result = JSON::Object::create(); |
3205 | m_agent->enable(error); |
3206 | |
3207 | if (!error.length()) |
3208 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3209 | else |
3210 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3211 | } |
3212 | |
3213 | void DebuggerBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
3214 | { |
3215 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3216 | if (m_alternateDispatcher) { |
3217 | m_alternateDispatcher->disable(requestId); |
3218 | return; |
3219 | } |
3220 | #endif |
3221 | |
3222 | ErrorString error; |
3223 | Ref<JSON::Object> result = JSON::Object::create(); |
3224 | m_agent->disable(error); |
3225 | |
3226 | if (!error.length()) |
3227 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3228 | else |
3229 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3230 | } |
3231 | |
3232 | void DebuggerBackendDispatcher::setAsyncStackTraceDepth(long requestId, RefPtr<JSON::Object>&& parameters) |
3233 | { |
3234 | int in_depth = m_backendDispatcher->getInteger(parameters.get(), "depth"_s , nullptr); |
3235 | if (m_backendDispatcher->hasProtocolErrors()) { |
3236 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setAsyncStackTraceDepth' can't be processed"_s ); |
3237 | return; |
3238 | } |
3239 | |
3240 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3241 | if (m_alternateDispatcher) { |
3242 | m_alternateDispatcher->setAsyncStackTraceDepth(requestId, in_depth); |
3243 | return; |
3244 | } |
3245 | #endif |
3246 | |
3247 | ErrorString error; |
3248 | Ref<JSON::Object> result = JSON::Object::create(); |
3249 | m_agent->setAsyncStackTraceDepth(error, in_depth); |
3250 | |
3251 | if (!error.length()) |
3252 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3253 | else |
3254 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3255 | } |
3256 | |
3257 | void DebuggerBackendDispatcher::setBreakpointsActive(long requestId, RefPtr<JSON::Object>&& parameters) |
3258 | { |
3259 | bool in_active = m_backendDispatcher->getBoolean(parameters.get(), "active"_s , nullptr); |
3260 | if (m_backendDispatcher->hasProtocolErrors()) { |
3261 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setBreakpointsActive' can't be processed"_s ); |
3262 | return; |
3263 | } |
3264 | |
3265 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3266 | if (m_alternateDispatcher) { |
3267 | m_alternateDispatcher->setBreakpointsActive(requestId, in_active); |
3268 | return; |
3269 | } |
3270 | #endif |
3271 | |
3272 | ErrorString error; |
3273 | Ref<JSON::Object> result = JSON::Object::create(); |
3274 | m_agent->setBreakpointsActive(error, in_active); |
3275 | |
3276 | if (!error.length()) |
3277 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3278 | else |
3279 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3280 | } |
3281 | |
3282 | void DebuggerBackendDispatcher::setBreakpointByUrl(long requestId, RefPtr<JSON::Object>&& parameters) |
3283 | { |
3284 | int in_lineNumber = m_backendDispatcher->getInteger(parameters.get(), "lineNumber"_s , nullptr); |
3285 | bool opt_in_url_valueFound = false; |
3286 | String opt_in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , &opt_in_url_valueFound); |
3287 | bool opt_in_urlRegex_valueFound = false; |
3288 | String opt_in_urlRegex = m_backendDispatcher->getString(parameters.get(), "urlRegex"_s , &opt_in_urlRegex_valueFound); |
3289 | bool opt_in_columnNumber_valueFound = false; |
3290 | int opt_in_columnNumber = m_backendDispatcher->getInteger(parameters.get(), "columnNumber"_s , &opt_in_columnNumber_valueFound); |
3291 | bool opt_in_options_valueFound = false; |
3292 | RefPtr<JSON::Object> opt_in_options = m_backendDispatcher->getObject(parameters.get(), "options"_s , &opt_in_options_valueFound); |
3293 | if (m_backendDispatcher->hasProtocolErrors()) { |
3294 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setBreakpointByUrl' can't be processed"_s ); |
3295 | return; |
3296 | } |
3297 | |
3298 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3299 | if (m_alternateDispatcher) { |
3300 | m_alternateDispatcher->setBreakpointByUrl(requestId, in_lineNumber, opt_in_url_valueFound ? &opt_in_url : nullptr, opt_in_urlRegex_valueFound ? &opt_in_urlRegex : nullptr, opt_in_columnNumber_valueFound ? &opt_in_columnNumber : nullptr, opt_in_options_valueFound ? opt_in_options.get() : nullptr); |
3301 | return; |
3302 | } |
3303 | #endif |
3304 | |
3305 | ErrorString error; |
3306 | Ref<JSON::Object> result = JSON::Object::create(); |
3307 | String out_breakpointId; |
3308 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Debugger::Location>> out_locations; |
3309 | m_agent->setBreakpointByUrl(error, in_lineNumber, opt_in_url_valueFound ? &opt_in_url : nullptr, opt_in_urlRegex_valueFound ? &opt_in_urlRegex : nullptr, opt_in_columnNumber_valueFound ? &opt_in_columnNumber : nullptr, opt_in_options_valueFound ? opt_in_options.get() : nullptr, &out_breakpointId, out_locations); |
3310 | |
3311 | if (!error.length()) { |
3312 | result->setString("breakpointId"_s , out_breakpointId); |
3313 | result->setArray("locations"_s , out_locations); |
3314 | } |
3315 | if (!error.length()) |
3316 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3317 | else |
3318 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3319 | } |
3320 | |
3321 | void DebuggerBackendDispatcher::setBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
3322 | { |
3323 | RefPtr<JSON::Object> in_location = m_backendDispatcher->getObject(parameters.get(), "location"_s , nullptr); |
3324 | bool opt_in_options_valueFound = false; |
3325 | RefPtr<JSON::Object> opt_in_options = m_backendDispatcher->getObject(parameters.get(), "options"_s , &opt_in_options_valueFound); |
3326 | if (m_backendDispatcher->hasProtocolErrors()) { |
3327 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setBreakpoint' can't be processed"_s ); |
3328 | return; |
3329 | } |
3330 | |
3331 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3332 | if (m_alternateDispatcher) { |
3333 | m_alternateDispatcher->setBreakpoint(requestId, *in_location, opt_in_options_valueFound ? opt_in_options.get() : nullptr); |
3334 | return; |
3335 | } |
3336 | #endif |
3337 | |
3338 | ErrorString error; |
3339 | Ref<JSON::Object> result = JSON::Object::create(); |
3340 | String out_breakpointId; |
3341 | RefPtr<Inspector::Protocol::Debugger::Location> out_actualLocation; |
3342 | m_agent->setBreakpoint(error, *in_location, opt_in_options_valueFound ? opt_in_options.get() : nullptr, &out_breakpointId, out_actualLocation); |
3343 | |
3344 | if (!error.length()) { |
3345 | result->setString("breakpointId"_s , out_breakpointId); |
3346 | result->setObject("actualLocation"_s , out_actualLocation); |
3347 | } |
3348 | if (!error.length()) |
3349 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3350 | else |
3351 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3352 | } |
3353 | |
3354 | void DebuggerBackendDispatcher::removeBreakpoint(long requestId, RefPtr<JSON::Object>&& parameters) |
3355 | { |
3356 | String in_breakpointId = m_backendDispatcher->getString(parameters.get(), "breakpointId"_s , nullptr); |
3357 | if (m_backendDispatcher->hasProtocolErrors()) { |
3358 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.removeBreakpoint' can't be processed"_s ); |
3359 | return; |
3360 | } |
3361 | |
3362 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3363 | if (m_alternateDispatcher) { |
3364 | m_alternateDispatcher->removeBreakpoint(requestId, in_breakpointId); |
3365 | return; |
3366 | } |
3367 | #endif |
3368 | |
3369 | ErrorString error; |
3370 | Ref<JSON::Object> result = JSON::Object::create(); |
3371 | m_agent->removeBreakpoint(error, in_breakpointId); |
3372 | |
3373 | if (!error.length()) |
3374 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3375 | else |
3376 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3377 | } |
3378 | |
3379 | void DebuggerBackendDispatcher::continueUntilNextRunLoop(long requestId, RefPtr<JSON::Object>&&) |
3380 | { |
3381 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3382 | if (m_alternateDispatcher) { |
3383 | m_alternateDispatcher->continueUntilNextRunLoop(requestId); |
3384 | return; |
3385 | } |
3386 | #endif |
3387 | |
3388 | ErrorString error; |
3389 | Ref<JSON::Object> result = JSON::Object::create(); |
3390 | m_agent->continueUntilNextRunLoop(error); |
3391 | |
3392 | if (!error.length()) |
3393 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3394 | else |
3395 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3396 | } |
3397 | |
3398 | void DebuggerBackendDispatcher::continueToLocation(long requestId, RefPtr<JSON::Object>&& parameters) |
3399 | { |
3400 | RefPtr<JSON::Object> in_location = m_backendDispatcher->getObject(parameters.get(), "location"_s , nullptr); |
3401 | if (m_backendDispatcher->hasProtocolErrors()) { |
3402 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.continueToLocation' can't be processed"_s ); |
3403 | return; |
3404 | } |
3405 | |
3406 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3407 | if (m_alternateDispatcher) { |
3408 | m_alternateDispatcher->continueToLocation(requestId, *in_location); |
3409 | return; |
3410 | } |
3411 | #endif |
3412 | |
3413 | ErrorString error; |
3414 | Ref<JSON::Object> result = JSON::Object::create(); |
3415 | m_agent->continueToLocation(error, *in_location); |
3416 | |
3417 | if (!error.length()) |
3418 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3419 | else |
3420 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3421 | } |
3422 | |
3423 | void DebuggerBackendDispatcher::stepOver(long requestId, RefPtr<JSON::Object>&&) |
3424 | { |
3425 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3426 | if (m_alternateDispatcher) { |
3427 | m_alternateDispatcher->stepOver(requestId); |
3428 | return; |
3429 | } |
3430 | #endif |
3431 | |
3432 | ErrorString error; |
3433 | Ref<JSON::Object> result = JSON::Object::create(); |
3434 | m_agent->stepOver(error); |
3435 | |
3436 | if (!error.length()) |
3437 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3438 | else |
3439 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3440 | } |
3441 | |
3442 | void DebuggerBackendDispatcher::stepInto(long requestId, RefPtr<JSON::Object>&&) |
3443 | { |
3444 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3445 | if (m_alternateDispatcher) { |
3446 | m_alternateDispatcher->stepInto(requestId); |
3447 | return; |
3448 | } |
3449 | #endif |
3450 | |
3451 | ErrorString error; |
3452 | Ref<JSON::Object> result = JSON::Object::create(); |
3453 | m_agent->stepInto(error); |
3454 | |
3455 | if (!error.length()) |
3456 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3457 | else |
3458 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3459 | } |
3460 | |
3461 | void DebuggerBackendDispatcher::stepOut(long requestId, RefPtr<JSON::Object>&&) |
3462 | { |
3463 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3464 | if (m_alternateDispatcher) { |
3465 | m_alternateDispatcher->stepOut(requestId); |
3466 | return; |
3467 | } |
3468 | #endif |
3469 | |
3470 | ErrorString error; |
3471 | Ref<JSON::Object> result = JSON::Object::create(); |
3472 | m_agent->stepOut(error); |
3473 | |
3474 | if (!error.length()) |
3475 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3476 | else |
3477 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3478 | } |
3479 | |
3480 | void DebuggerBackendDispatcher::pause(long requestId, RefPtr<JSON::Object>&&) |
3481 | { |
3482 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3483 | if (m_alternateDispatcher) { |
3484 | m_alternateDispatcher->pause(requestId); |
3485 | return; |
3486 | } |
3487 | #endif |
3488 | |
3489 | ErrorString error; |
3490 | Ref<JSON::Object> result = JSON::Object::create(); |
3491 | m_agent->pause(error); |
3492 | |
3493 | if (!error.length()) |
3494 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3495 | else |
3496 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3497 | } |
3498 | |
3499 | void DebuggerBackendDispatcher::resume(long requestId, RefPtr<JSON::Object>&&) |
3500 | { |
3501 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3502 | if (m_alternateDispatcher) { |
3503 | m_alternateDispatcher->resume(requestId); |
3504 | return; |
3505 | } |
3506 | #endif |
3507 | |
3508 | ErrorString error; |
3509 | Ref<JSON::Object> result = JSON::Object::create(); |
3510 | m_agent->resume(error); |
3511 | |
3512 | if (!error.length()) |
3513 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3514 | else |
3515 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3516 | } |
3517 | |
3518 | void DebuggerBackendDispatcher::searchInContent(long requestId, RefPtr<JSON::Object>&& parameters) |
3519 | { |
3520 | String in_scriptId = m_backendDispatcher->getString(parameters.get(), "scriptId"_s , nullptr); |
3521 | String in_query = m_backendDispatcher->getString(parameters.get(), "query"_s , nullptr); |
3522 | bool opt_in_caseSensitive_valueFound = false; |
3523 | bool opt_in_caseSensitive = m_backendDispatcher->getBoolean(parameters.get(), "caseSensitive"_s , &opt_in_caseSensitive_valueFound); |
3524 | bool opt_in_isRegex_valueFound = false; |
3525 | bool opt_in_isRegex = m_backendDispatcher->getBoolean(parameters.get(), "isRegex"_s , &opt_in_isRegex_valueFound); |
3526 | if (m_backendDispatcher->hasProtocolErrors()) { |
3527 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.searchInContent' can't be processed"_s ); |
3528 | return; |
3529 | } |
3530 | |
3531 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3532 | if (m_alternateDispatcher) { |
3533 | m_alternateDispatcher->searchInContent(requestId, in_scriptId, in_query, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr); |
3534 | return; |
3535 | } |
3536 | #endif |
3537 | |
3538 | ErrorString error; |
3539 | Ref<JSON::Object> result = JSON::Object::create(); |
3540 | RefPtr<JSON::ArrayOf<Inspector::Protocol::GenericTypes::SearchMatch>> out_result; |
3541 | m_agent->searchInContent(error, in_scriptId, in_query, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr, out_result); |
3542 | |
3543 | if (!error.length()) |
3544 | result->setArray("result"_s , out_result); |
3545 | |
3546 | if (!error.length()) |
3547 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3548 | else |
3549 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3550 | } |
3551 | |
3552 | void DebuggerBackendDispatcher::getScriptSource(long requestId, RefPtr<JSON::Object>&& parameters) |
3553 | { |
3554 | String in_scriptId = m_backendDispatcher->getString(parameters.get(), "scriptId"_s , nullptr); |
3555 | if (m_backendDispatcher->hasProtocolErrors()) { |
3556 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.getScriptSource' can't be processed"_s ); |
3557 | return; |
3558 | } |
3559 | |
3560 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3561 | if (m_alternateDispatcher) { |
3562 | m_alternateDispatcher->getScriptSource(requestId, in_scriptId); |
3563 | return; |
3564 | } |
3565 | #endif |
3566 | |
3567 | ErrorString error; |
3568 | Ref<JSON::Object> result = JSON::Object::create(); |
3569 | String out_scriptSource; |
3570 | m_agent->getScriptSource(error, in_scriptId, &out_scriptSource); |
3571 | |
3572 | if (!error.length()) |
3573 | result->setString("scriptSource"_s , out_scriptSource); |
3574 | |
3575 | if (!error.length()) |
3576 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3577 | else |
3578 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3579 | } |
3580 | |
3581 | void DebuggerBackendDispatcher::getFunctionDetails(long requestId, RefPtr<JSON::Object>&& parameters) |
3582 | { |
3583 | String in_functionId = m_backendDispatcher->getString(parameters.get(), "functionId"_s , nullptr); |
3584 | if (m_backendDispatcher->hasProtocolErrors()) { |
3585 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.getFunctionDetails' can't be processed"_s ); |
3586 | return; |
3587 | } |
3588 | |
3589 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3590 | if (m_alternateDispatcher) { |
3591 | m_alternateDispatcher->getFunctionDetails(requestId, in_functionId); |
3592 | return; |
3593 | } |
3594 | #endif |
3595 | |
3596 | ErrorString error; |
3597 | Ref<JSON::Object> result = JSON::Object::create(); |
3598 | RefPtr<Inspector::Protocol::Debugger::FunctionDetails> out_details; |
3599 | m_agent->getFunctionDetails(error, in_functionId, out_details); |
3600 | |
3601 | if (!error.length()) |
3602 | result->setObject("details"_s , out_details); |
3603 | |
3604 | if (!error.length()) |
3605 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3606 | else |
3607 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3608 | } |
3609 | |
3610 | void DebuggerBackendDispatcher::setPauseOnExceptions(long requestId, RefPtr<JSON::Object>&& parameters) |
3611 | { |
3612 | String in_state = m_backendDispatcher->getString(parameters.get(), "state"_s , nullptr); |
3613 | if (m_backendDispatcher->hasProtocolErrors()) { |
3614 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseOnExceptions' can't be processed"_s ); |
3615 | return; |
3616 | } |
3617 | |
3618 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3619 | if (m_alternateDispatcher) { |
3620 | m_alternateDispatcher->setPauseOnExceptions(requestId, in_state); |
3621 | return; |
3622 | } |
3623 | #endif |
3624 | |
3625 | ErrorString error; |
3626 | Ref<JSON::Object> result = JSON::Object::create(); |
3627 | m_agent->setPauseOnExceptions(error, in_state); |
3628 | |
3629 | if (!error.length()) |
3630 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3631 | else |
3632 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3633 | } |
3634 | |
3635 | void DebuggerBackendDispatcher::setPauseOnAssertions(long requestId, RefPtr<JSON::Object>&& parameters) |
3636 | { |
3637 | bool in_enabled = m_backendDispatcher->getBoolean(parameters.get(), "enabled"_s , nullptr); |
3638 | if (m_backendDispatcher->hasProtocolErrors()) { |
3639 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseOnAssertions' can't be processed"_s ); |
3640 | return; |
3641 | } |
3642 | |
3643 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3644 | if (m_alternateDispatcher) { |
3645 | m_alternateDispatcher->setPauseOnAssertions(requestId, in_enabled); |
3646 | return; |
3647 | } |
3648 | #endif |
3649 | |
3650 | ErrorString error; |
3651 | Ref<JSON::Object> result = JSON::Object::create(); |
3652 | m_agent->setPauseOnAssertions(error, in_enabled); |
3653 | |
3654 | if (!error.length()) |
3655 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3656 | else |
3657 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3658 | } |
3659 | |
3660 | void DebuggerBackendDispatcher::setPauseForInternalScripts(long requestId, RefPtr<JSON::Object>&& parameters) |
3661 | { |
3662 | bool in_shouldPause = m_backendDispatcher->getBoolean(parameters.get(), "shouldPause"_s , nullptr); |
3663 | if (m_backendDispatcher->hasProtocolErrors()) { |
3664 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseForInternalScripts' can't be processed"_s ); |
3665 | return; |
3666 | } |
3667 | |
3668 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3669 | if (m_alternateDispatcher) { |
3670 | m_alternateDispatcher->setPauseForInternalScripts(requestId, in_shouldPause); |
3671 | return; |
3672 | } |
3673 | #endif |
3674 | |
3675 | ErrorString error; |
3676 | Ref<JSON::Object> result = JSON::Object::create(); |
3677 | m_agent->setPauseForInternalScripts(error, in_shouldPause); |
3678 | |
3679 | if (!error.length()) |
3680 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3681 | else |
3682 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3683 | } |
3684 | |
3685 | void DebuggerBackendDispatcher::evaluateOnCallFrame(long requestId, RefPtr<JSON::Object>&& parameters) |
3686 | { |
3687 | String in_callFrameId = m_backendDispatcher->getString(parameters.get(), "callFrameId"_s , nullptr); |
3688 | String in_expression = m_backendDispatcher->getString(parameters.get(), "expression"_s , nullptr); |
3689 | bool opt_in_objectGroup_valueFound = false; |
3690 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
3691 | bool opt_in_includeCommandLineAPI_valueFound = false; |
3692 | bool opt_in_includeCommandLineAPI = m_backendDispatcher->getBoolean(parameters.get(), "includeCommandLineAPI"_s , &opt_in_includeCommandLineAPI_valueFound); |
3693 | bool opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound = false; |
3694 | bool opt_in_doNotPauseOnExceptionsAndMuteConsole = m_backendDispatcher->getBoolean(parameters.get(), "doNotPauseOnExceptionsAndMuteConsole"_s , &opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound); |
3695 | bool opt_in_returnByValue_valueFound = false; |
3696 | bool opt_in_returnByValue = m_backendDispatcher->getBoolean(parameters.get(), "returnByValue"_s , &opt_in_returnByValue_valueFound); |
3697 | bool opt_in_generatePreview_valueFound = false; |
3698 | bool opt_in_generatePreview = m_backendDispatcher->getBoolean(parameters.get(), "generatePreview"_s , &opt_in_generatePreview_valueFound); |
3699 | bool opt_in_saveResult_valueFound = false; |
3700 | bool opt_in_saveResult = m_backendDispatcher->getBoolean(parameters.get(), "saveResult"_s , &opt_in_saveResult_valueFound); |
3701 | if (m_backendDispatcher->hasProtocolErrors()) { |
3702 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.evaluateOnCallFrame' can't be processed"_s ); |
3703 | return; |
3704 | } |
3705 | |
3706 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3707 | if (m_alternateDispatcher) { |
3708 | m_alternateDispatcher->evaluateOnCallFrame(requestId, in_callFrameId, in_expression, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, opt_in_includeCommandLineAPI_valueFound ? &opt_in_includeCommandLineAPI : nullptr, opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound ? &opt_in_doNotPauseOnExceptionsAndMuteConsole : nullptr, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, opt_in_saveResult_valueFound ? &opt_in_saveResult : nullptr); |
3709 | return; |
3710 | } |
3711 | #endif |
3712 | |
3713 | ErrorString error; |
3714 | Ref<JSON::Object> result = JSON::Object::create(); |
3715 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_result; |
3716 | Optional<bool> out_wasThrown; |
3717 | Optional<int> out_savedResultIndex; |
3718 | m_agent->evaluateOnCallFrame(error, in_callFrameId, in_expression, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, opt_in_includeCommandLineAPI_valueFound ? &opt_in_includeCommandLineAPI : nullptr, opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound ? &opt_in_doNotPauseOnExceptionsAndMuteConsole : nullptr, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, opt_in_saveResult_valueFound ? &opt_in_saveResult : nullptr, out_result, out_wasThrown, out_savedResultIndex); |
3719 | |
3720 | if (!error.length()) { |
3721 | result->setObject("result"_s , out_result); |
3722 | if (out_wasThrown.hasValue()) |
3723 | result->setBoolean("wasThrown"_s , *out_wasThrown); |
3724 | if (out_savedResultIndex.hasValue()) |
3725 | result->setInteger("savedResultIndex"_s , *out_savedResultIndex); |
3726 | } |
3727 | if (!error.length()) |
3728 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3729 | else |
3730 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3731 | } |
3732 | |
3733 | Ref<HeapBackendDispatcher> HeapBackendDispatcher::create(BackendDispatcher& backendDispatcher, HeapBackendDispatcherHandler* agent) |
3734 | { |
3735 | return adoptRef(*new HeapBackendDispatcher(backendDispatcher, agent)); |
3736 | } |
3737 | |
3738 | HeapBackendDispatcher::HeapBackendDispatcher(BackendDispatcher& backendDispatcher, HeapBackendDispatcherHandler* agent) |
3739 | : SupplementalBackendDispatcher(backendDispatcher) |
3740 | , m_agent(agent) |
3741 | { |
3742 | m_backendDispatcher->registerDispatcherForDomain("Heap"_s , this); |
3743 | } |
3744 | |
3745 | void HeapBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
3746 | { |
3747 | Ref<HeapBackendDispatcher> protect(*this); |
3748 | |
3749 | RefPtr<JSON::Object> parameters; |
3750 | message->getObject("params"_s , parameters); |
3751 | |
3752 | typedef void (HeapBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
3753 | typedef HashMap<String, CallHandler> DispatchMap; |
3754 | static NeverDestroyed<DispatchMap> dispatchMap; |
3755 | if (dispatchMap.get().isEmpty()) { |
3756 | static const struct MethodTable { |
3757 | const char* name; |
3758 | CallHandler handler; |
3759 | } commands[] = { |
3760 | { "enable" , &HeapBackendDispatcher::enable }, |
3761 | { "disable" , &HeapBackendDispatcher::disable }, |
3762 | { "gc" , &HeapBackendDispatcher::gc }, |
3763 | { "snapshot" , &HeapBackendDispatcher::snapshot }, |
3764 | { "startTracking" , &HeapBackendDispatcher::startTracking }, |
3765 | { "stopTracking" , &HeapBackendDispatcher::stopTracking }, |
3766 | { "getPreview" , &HeapBackendDispatcher::getPreview }, |
3767 | { "getRemoteObject" , &HeapBackendDispatcher::getRemoteObject }, |
3768 | }; |
3769 | size_t length = WTF_ARRAY_LENGTH(commands); |
3770 | for (size_t i = 0; i < length; ++i) |
3771 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
3772 | } |
3773 | |
3774 | auto findResult = dispatchMap.get().find(method); |
3775 | if (findResult == dispatchMap.get().end()) { |
3776 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Heap." + method + "' was not found" ); |
3777 | return; |
3778 | } |
3779 | |
3780 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
3781 | } |
3782 | |
3783 | void HeapBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
3784 | { |
3785 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3786 | if (m_alternateDispatcher) { |
3787 | m_alternateDispatcher->enable(requestId); |
3788 | return; |
3789 | } |
3790 | #endif |
3791 | |
3792 | ErrorString error; |
3793 | Ref<JSON::Object> result = JSON::Object::create(); |
3794 | m_agent->enable(error); |
3795 | |
3796 | if (!error.length()) |
3797 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3798 | else |
3799 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3800 | } |
3801 | |
3802 | void HeapBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
3803 | { |
3804 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3805 | if (m_alternateDispatcher) { |
3806 | m_alternateDispatcher->disable(requestId); |
3807 | return; |
3808 | } |
3809 | #endif |
3810 | |
3811 | ErrorString error; |
3812 | Ref<JSON::Object> result = JSON::Object::create(); |
3813 | m_agent->disable(error); |
3814 | |
3815 | if (!error.length()) |
3816 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3817 | else |
3818 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3819 | } |
3820 | |
3821 | void HeapBackendDispatcher::gc(long requestId, RefPtr<JSON::Object>&&) |
3822 | { |
3823 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3824 | if (m_alternateDispatcher) { |
3825 | m_alternateDispatcher->gc(requestId); |
3826 | return; |
3827 | } |
3828 | #endif |
3829 | |
3830 | ErrorString error; |
3831 | Ref<JSON::Object> result = JSON::Object::create(); |
3832 | m_agent->gc(error); |
3833 | |
3834 | if (!error.length()) |
3835 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3836 | else |
3837 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3838 | } |
3839 | |
3840 | void HeapBackendDispatcher::snapshot(long requestId, RefPtr<JSON::Object>&&) |
3841 | { |
3842 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3843 | if (m_alternateDispatcher) { |
3844 | m_alternateDispatcher->snapshot(requestId); |
3845 | return; |
3846 | } |
3847 | #endif |
3848 | |
3849 | ErrorString error; |
3850 | Ref<JSON::Object> result = JSON::Object::create(); |
3851 | double out_timestamp; |
3852 | String out_snapshotData; |
3853 | m_agent->snapshot(error, &out_timestamp, &out_snapshotData); |
3854 | |
3855 | if (!error.length()) { |
3856 | result->setDouble("timestamp"_s , out_timestamp); |
3857 | result->setString("snapshotData"_s , out_snapshotData); |
3858 | } |
3859 | if (!error.length()) |
3860 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3861 | else |
3862 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3863 | } |
3864 | |
3865 | void HeapBackendDispatcher::startTracking(long requestId, RefPtr<JSON::Object>&&) |
3866 | { |
3867 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3868 | if (m_alternateDispatcher) { |
3869 | m_alternateDispatcher->startTracking(requestId); |
3870 | return; |
3871 | } |
3872 | #endif |
3873 | |
3874 | ErrorString error; |
3875 | Ref<JSON::Object> result = JSON::Object::create(); |
3876 | m_agent->startTracking(error); |
3877 | |
3878 | if (!error.length()) |
3879 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3880 | else |
3881 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3882 | } |
3883 | |
3884 | void HeapBackendDispatcher::stopTracking(long requestId, RefPtr<JSON::Object>&&) |
3885 | { |
3886 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3887 | if (m_alternateDispatcher) { |
3888 | m_alternateDispatcher->stopTracking(requestId); |
3889 | return; |
3890 | } |
3891 | #endif |
3892 | |
3893 | ErrorString error; |
3894 | Ref<JSON::Object> result = JSON::Object::create(); |
3895 | m_agent->stopTracking(error); |
3896 | |
3897 | if (!error.length()) |
3898 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3899 | else |
3900 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3901 | } |
3902 | |
3903 | void HeapBackendDispatcher::getPreview(long requestId, RefPtr<JSON::Object>&& parameters) |
3904 | { |
3905 | int in_heapObjectId = m_backendDispatcher->getInteger(parameters.get(), "heapObjectId"_s , nullptr); |
3906 | if (m_backendDispatcher->hasProtocolErrors()) { |
3907 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Heap.getPreview' can't be processed"_s ); |
3908 | return; |
3909 | } |
3910 | |
3911 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3912 | if (m_alternateDispatcher) { |
3913 | m_alternateDispatcher->getPreview(requestId, in_heapObjectId); |
3914 | return; |
3915 | } |
3916 | #endif |
3917 | |
3918 | ErrorString error; |
3919 | Ref<JSON::Object> result = JSON::Object::create(); |
3920 | Optional<String> out_string; |
3921 | RefPtr<Inspector::Protocol::Debugger::FunctionDetails> out_functionDetails; |
3922 | RefPtr<Inspector::Protocol::Runtime::ObjectPreview> out_preview; |
3923 | m_agent->getPreview(error, in_heapObjectId, out_string, out_functionDetails, out_preview); |
3924 | |
3925 | if (!error.length()) { |
3926 | if (out_string.hasValue()) |
3927 | result->setString("string"_s , *out_string); |
3928 | if (out_functionDetails) |
3929 | result->setObject("functionDetails"_s , out_functionDetails); |
3930 | if (out_preview) |
3931 | result->setObject("preview"_s , out_preview); |
3932 | } |
3933 | if (!error.length()) |
3934 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3935 | else |
3936 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3937 | } |
3938 | |
3939 | void HeapBackendDispatcher::getRemoteObject(long requestId, RefPtr<JSON::Object>&& parameters) |
3940 | { |
3941 | int in_heapObjectId = m_backendDispatcher->getInteger(parameters.get(), "heapObjectId"_s , nullptr); |
3942 | bool opt_in_objectGroup_valueFound = false; |
3943 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
3944 | if (m_backendDispatcher->hasProtocolErrors()) { |
3945 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Heap.getRemoteObject' can't be processed"_s ); |
3946 | return; |
3947 | } |
3948 | |
3949 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
3950 | if (m_alternateDispatcher) { |
3951 | m_alternateDispatcher->getRemoteObject(requestId, in_heapObjectId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr); |
3952 | return; |
3953 | } |
3954 | #endif |
3955 | |
3956 | ErrorString error; |
3957 | Ref<JSON::Object> result = JSON::Object::create(); |
3958 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_result; |
3959 | m_agent->getRemoteObject(error, in_heapObjectId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, out_result); |
3960 | |
3961 | if (!error.length()) |
3962 | result->setObject("result"_s , out_result); |
3963 | |
3964 | if (!error.length()) |
3965 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
3966 | else |
3967 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
3968 | } |
3969 | |
3970 | #if ENABLE(INDEXED_DATABASE) |
3971 | Ref<IndexedDBBackendDispatcher> IndexedDBBackendDispatcher::create(BackendDispatcher& backendDispatcher, IndexedDBBackendDispatcherHandler* agent) |
3972 | { |
3973 | return adoptRef(*new IndexedDBBackendDispatcher(backendDispatcher, agent)); |
3974 | } |
3975 | |
3976 | IndexedDBBackendDispatcher::IndexedDBBackendDispatcher(BackendDispatcher& backendDispatcher, IndexedDBBackendDispatcherHandler* agent) |
3977 | : SupplementalBackendDispatcher(backendDispatcher) |
3978 | , m_agent(agent) |
3979 | { |
3980 | m_backendDispatcher->registerDispatcherForDomain("IndexedDB"_s , this); |
3981 | } |
3982 | |
3983 | void IndexedDBBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
3984 | { |
3985 | Ref<IndexedDBBackendDispatcher> protect(*this); |
3986 | |
3987 | RefPtr<JSON::Object> parameters; |
3988 | message->getObject("params"_s , parameters); |
3989 | |
3990 | typedef void (IndexedDBBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
3991 | typedef HashMap<String, CallHandler> DispatchMap; |
3992 | static NeverDestroyed<DispatchMap> dispatchMap; |
3993 | if (dispatchMap.get().isEmpty()) { |
3994 | static const struct MethodTable { |
3995 | const char* name; |
3996 | CallHandler handler; |
3997 | } commands[] = { |
3998 | { "enable" , &IndexedDBBackendDispatcher::enable }, |
3999 | { "disable" , &IndexedDBBackendDispatcher::disable }, |
4000 | { "requestDatabaseNames" , &IndexedDBBackendDispatcher::requestDatabaseNames }, |
4001 | { "requestDatabase" , &IndexedDBBackendDispatcher::requestDatabase }, |
4002 | { "requestData" , &IndexedDBBackendDispatcher::requestData }, |
4003 | { "clearObjectStore" , &IndexedDBBackendDispatcher::clearObjectStore }, |
4004 | }; |
4005 | size_t length = WTF_ARRAY_LENGTH(commands); |
4006 | for (size_t i = 0; i < length; ++i) |
4007 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
4008 | } |
4009 | |
4010 | auto findResult = dispatchMap.get().find(method); |
4011 | if (findResult == dispatchMap.get().end()) { |
4012 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'IndexedDB." + method + "' was not found" ); |
4013 | return; |
4014 | } |
4015 | |
4016 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
4017 | } |
4018 | |
4019 | void IndexedDBBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
4020 | { |
4021 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4022 | if (m_alternateDispatcher) { |
4023 | m_alternateDispatcher->enable(requestId); |
4024 | return; |
4025 | } |
4026 | #endif |
4027 | |
4028 | ErrorString error; |
4029 | Ref<JSON::Object> result = JSON::Object::create(); |
4030 | m_agent->enable(error); |
4031 | |
4032 | if (!error.length()) |
4033 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4034 | else |
4035 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4036 | } |
4037 | |
4038 | void IndexedDBBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
4039 | { |
4040 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4041 | if (m_alternateDispatcher) { |
4042 | m_alternateDispatcher->disable(requestId); |
4043 | return; |
4044 | } |
4045 | #endif |
4046 | |
4047 | ErrorString error; |
4048 | Ref<JSON::Object> result = JSON::Object::create(); |
4049 | m_agent->disable(error); |
4050 | |
4051 | if (!error.length()) |
4052 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4053 | else |
4054 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4055 | } |
4056 | |
4057 | IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback::RequestDatabaseNamesCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
4058 | |
4059 | void IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback::sendSuccess(RefPtr<JSON::ArrayOf<String>>&& databaseNames) |
4060 | { |
4061 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
4062 | jsonMessage->setArray("databaseNames"_s , databaseNames); |
4063 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
4064 | } |
4065 | |
4066 | void IndexedDBBackendDispatcher::requestDatabaseNames(long requestId, RefPtr<JSON::Object>&& parameters) |
4067 | { |
4068 | String in_securityOrigin = m_backendDispatcher->getString(parameters.get(), "securityOrigin"_s , nullptr); |
4069 | if (m_backendDispatcher->hasProtocolErrors()) { |
4070 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.requestDatabaseNames' can't be processed"_s ); |
4071 | return; |
4072 | } |
4073 | |
4074 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4075 | if (m_alternateDispatcher) { |
4076 | m_alternateDispatcher->requestDatabaseNames(requestId, in_securityOrigin); |
4077 | return; |
4078 | } |
4079 | #endif |
4080 | |
4081 | Ref<IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback> callback = adoptRef(*new IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback(m_backendDispatcher.copyRef(), requestId)); |
4082 | m_agent->requestDatabaseNames(in_securityOrigin, callback.copyRef()); |
4083 | |
4084 | } |
4085 | |
4086 | IndexedDBBackendDispatcherHandler::RequestDatabaseCallback::RequestDatabaseCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
4087 | |
4088 | void IndexedDBBackendDispatcherHandler::RequestDatabaseCallback::sendSuccess(RefPtr<Inspector::Protocol::IndexedDB::DatabaseWithObjectStores>&& databaseWithObjectStores) |
4089 | { |
4090 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
4091 | jsonMessage->setObject("databaseWithObjectStores"_s , databaseWithObjectStores); |
4092 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
4093 | } |
4094 | |
4095 | void IndexedDBBackendDispatcher::requestDatabase(long requestId, RefPtr<JSON::Object>&& parameters) |
4096 | { |
4097 | String in_securityOrigin = m_backendDispatcher->getString(parameters.get(), "securityOrigin"_s , nullptr); |
4098 | String in_databaseName = m_backendDispatcher->getString(parameters.get(), "databaseName"_s , nullptr); |
4099 | if (m_backendDispatcher->hasProtocolErrors()) { |
4100 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.requestDatabase' can't be processed"_s ); |
4101 | return; |
4102 | } |
4103 | |
4104 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4105 | if (m_alternateDispatcher) { |
4106 | m_alternateDispatcher->requestDatabase(requestId, in_securityOrigin, in_databaseName); |
4107 | return; |
4108 | } |
4109 | #endif |
4110 | |
4111 | Ref<IndexedDBBackendDispatcherHandler::RequestDatabaseCallback> callback = adoptRef(*new IndexedDBBackendDispatcherHandler::RequestDatabaseCallback(m_backendDispatcher.copyRef(), requestId)); |
4112 | m_agent->requestDatabase(in_securityOrigin, in_databaseName, callback.copyRef()); |
4113 | |
4114 | } |
4115 | |
4116 | IndexedDBBackendDispatcherHandler::RequestDataCallback::RequestDataCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
4117 | |
4118 | void IndexedDBBackendDispatcherHandler::RequestDataCallback::sendSuccess(RefPtr<JSON::ArrayOf<Inspector::Protocol::IndexedDB::DataEntry>>&& objectStoreDataEntries, bool hasMore) |
4119 | { |
4120 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
4121 | jsonMessage->setArray("objectStoreDataEntries"_s , objectStoreDataEntries); |
4122 | jsonMessage->setBoolean("hasMore"_s , hasMore); |
4123 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
4124 | } |
4125 | |
4126 | void IndexedDBBackendDispatcher::requestData(long requestId, RefPtr<JSON::Object>&& parameters) |
4127 | { |
4128 | String in_securityOrigin = m_backendDispatcher->getString(parameters.get(), "securityOrigin"_s , nullptr); |
4129 | String in_databaseName = m_backendDispatcher->getString(parameters.get(), "databaseName"_s , nullptr); |
4130 | String in_objectStoreName = m_backendDispatcher->getString(parameters.get(), "objectStoreName"_s , nullptr); |
4131 | String in_indexName = m_backendDispatcher->getString(parameters.get(), "indexName"_s , nullptr); |
4132 | int in_skipCount = m_backendDispatcher->getInteger(parameters.get(), "skipCount"_s , nullptr); |
4133 | int in_pageSize = m_backendDispatcher->getInteger(parameters.get(), "pageSize"_s , nullptr); |
4134 | bool opt_in_keyRange_valueFound = false; |
4135 | RefPtr<JSON::Object> opt_in_keyRange = m_backendDispatcher->getObject(parameters.get(), "keyRange"_s , &opt_in_keyRange_valueFound); |
4136 | if (m_backendDispatcher->hasProtocolErrors()) { |
4137 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.requestData' can't be processed"_s ); |
4138 | return; |
4139 | } |
4140 | |
4141 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4142 | if (m_alternateDispatcher) { |
4143 | m_alternateDispatcher->requestData(requestId, in_securityOrigin, in_databaseName, in_objectStoreName, in_indexName, in_skipCount, in_pageSize, opt_in_keyRange_valueFound ? opt_in_keyRange.get() : nullptr); |
4144 | return; |
4145 | } |
4146 | #endif |
4147 | |
4148 | Ref<IndexedDBBackendDispatcherHandler::RequestDataCallback> callback = adoptRef(*new IndexedDBBackendDispatcherHandler::RequestDataCallback(m_backendDispatcher.copyRef(), requestId)); |
4149 | m_agent->requestData(in_securityOrigin, in_databaseName, in_objectStoreName, in_indexName, in_skipCount, in_pageSize, opt_in_keyRange_valueFound ? opt_in_keyRange.get() : nullptr, callback.copyRef()); |
4150 | |
4151 | } |
4152 | |
4153 | IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback::ClearObjectStoreCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
4154 | |
4155 | void IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback::sendSuccess() |
4156 | { |
4157 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
4158 | |
4159 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
4160 | } |
4161 | |
4162 | void IndexedDBBackendDispatcher::clearObjectStore(long requestId, RefPtr<JSON::Object>&& parameters) |
4163 | { |
4164 | String in_securityOrigin = m_backendDispatcher->getString(parameters.get(), "securityOrigin"_s , nullptr); |
4165 | String in_databaseName = m_backendDispatcher->getString(parameters.get(), "databaseName"_s , nullptr); |
4166 | String in_objectStoreName = m_backendDispatcher->getString(parameters.get(), "objectStoreName"_s , nullptr); |
4167 | if (m_backendDispatcher->hasProtocolErrors()) { |
4168 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.clearObjectStore' can't be processed"_s ); |
4169 | return; |
4170 | } |
4171 | |
4172 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4173 | if (m_alternateDispatcher) { |
4174 | m_alternateDispatcher->clearObjectStore(requestId, in_securityOrigin, in_databaseName, in_objectStoreName); |
4175 | return; |
4176 | } |
4177 | #endif |
4178 | |
4179 | Ref<IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback> callback = adoptRef(*new IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback(m_backendDispatcher.copyRef(), requestId)); |
4180 | m_agent->clearObjectStore(in_securityOrigin, in_databaseName, in_objectStoreName, callback.copyRef()); |
4181 | |
4182 | } |
4183 | #endif // ENABLE(INDEXED_DATABASE) |
4184 | |
4185 | Ref<InspectorBackendDispatcher> InspectorBackendDispatcher::create(BackendDispatcher& backendDispatcher, InspectorBackendDispatcherHandler* agent) |
4186 | { |
4187 | return adoptRef(*new InspectorBackendDispatcher(backendDispatcher, agent)); |
4188 | } |
4189 | |
4190 | InspectorBackendDispatcher::InspectorBackendDispatcher(BackendDispatcher& backendDispatcher, InspectorBackendDispatcherHandler* agent) |
4191 | : SupplementalBackendDispatcher(backendDispatcher) |
4192 | , m_agent(agent) |
4193 | { |
4194 | m_backendDispatcher->registerDispatcherForDomain("Inspector"_s , this); |
4195 | } |
4196 | |
4197 | void InspectorBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
4198 | { |
4199 | Ref<InspectorBackendDispatcher> protect(*this); |
4200 | |
4201 | RefPtr<JSON::Object> parameters; |
4202 | message->getObject("params"_s , parameters); |
4203 | |
4204 | if (method == "enable" ) |
4205 | enable(requestId, WTFMove(parameters)); |
4206 | else if (method == "disable" ) |
4207 | disable(requestId, WTFMove(parameters)); |
4208 | else if (method == "initialized" ) |
4209 | initialized(requestId, WTFMove(parameters)); |
4210 | else |
4211 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Inspector." + method + "' was not found" ); |
4212 | } |
4213 | |
4214 | void InspectorBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
4215 | { |
4216 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4217 | if (m_alternateDispatcher) { |
4218 | m_alternateDispatcher->enable(requestId); |
4219 | return; |
4220 | } |
4221 | #endif |
4222 | |
4223 | ErrorString error; |
4224 | Ref<JSON::Object> result = JSON::Object::create(); |
4225 | m_agent->enable(error); |
4226 | |
4227 | if (!error.length()) |
4228 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4229 | else |
4230 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4231 | } |
4232 | |
4233 | void InspectorBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
4234 | { |
4235 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4236 | if (m_alternateDispatcher) { |
4237 | m_alternateDispatcher->disable(requestId); |
4238 | return; |
4239 | } |
4240 | #endif |
4241 | |
4242 | ErrorString error; |
4243 | Ref<JSON::Object> result = JSON::Object::create(); |
4244 | m_agent->disable(error); |
4245 | |
4246 | if (!error.length()) |
4247 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4248 | else |
4249 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4250 | } |
4251 | |
4252 | void InspectorBackendDispatcher::initialized(long requestId, RefPtr<JSON::Object>&&) |
4253 | { |
4254 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4255 | if (m_alternateDispatcher) { |
4256 | m_alternateDispatcher->initialized(requestId); |
4257 | return; |
4258 | } |
4259 | #endif |
4260 | |
4261 | ErrorString error; |
4262 | Ref<JSON::Object> result = JSON::Object::create(); |
4263 | m_agent->initialized(error); |
4264 | |
4265 | if (!error.length()) |
4266 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4267 | else |
4268 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4269 | } |
4270 | |
4271 | Ref<LayerTreeBackendDispatcher> LayerTreeBackendDispatcher::create(BackendDispatcher& backendDispatcher, LayerTreeBackendDispatcherHandler* agent) |
4272 | { |
4273 | return adoptRef(*new LayerTreeBackendDispatcher(backendDispatcher, agent)); |
4274 | } |
4275 | |
4276 | LayerTreeBackendDispatcher::LayerTreeBackendDispatcher(BackendDispatcher& backendDispatcher, LayerTreeBackendDispatcherHandler* agent) |
4277 | : SupplementalBackendDispatcher(backendDispatcher) |
4278 | , m_agent(agent) |
4279 | { |
4280 | m_backendDispatcher->registerDispatcherForDomain("LayerTree"_s , this); |
4281 | } |
4282 | |
4283 | void LayerTreeBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
4284 | { |
4285 | Ref<LayerTreeBackendDispatcher> protect(*this); |
4286 | |
4287 | RefPtr<JSON::Object> parameters; |
4288 | message->getObject("params"_s , parameters); |
4289 | |
4290 | if (method == "enable" ) |
4291 | enable(requestId, WTFMove(parameters)); |
4292 | else if (method == "disable" ) |
4293 | disable(requestId, WTFMove(parameters)); |
4294 | else if (method == "layersForNode" ) |
4295 | layersForNode(requestId, WTFMove(parameters)); |
4296 | else if (method == "reasonsForCompositingLayer" ) |
4297 | reasonsForCompositingLayer(requestId, WTFMove(parameters)); |
4298 | else |
4299 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'LayerTree." + method + "' was not found" ); |
4300 | } |
4301 | |
4302 | void LayerTreeBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
4303 | { |
4304 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4305 | if (m_alternateDispatcher) { |
4306 | m_alternateDispatcher->enable(requestId); |
4307 | return; |
4308 | } |
4309 | #endif |
4310 | |
4311 | ErrorString error; |
4312 | Ref<JSON::Object> result = JSON::Object::create(); |
4313 | m_agent->enable(error); |
4314 | |
4315 | if (!error.length()) |
4316 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4317 | else |
4318 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4319 | } |
4320 | |
4321 | void LayerTreeBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
4322 | { |
4323 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4324 | if (m_alternateDispatcher) { |
4325 | m_alternateDispatcher->disable(requestId); |
4326 | return; |
4327 | } |
4328 | #endif |
4329 | |
4330 | ErrorString error; |
4331 | Ref<JSON::Object> result = JSON::Object::create(); |
4332 | m_agent->disable(error); |
4333 | |
4334 | if (!error.length()) |
4335 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4336 | else |
4337 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4338 | } |
4339 | |
4340 | void LayerTreeBackendDispatcher::layersForNode(long requestId, RefPtr<JSON::Object>&& parameters) |
4341 | { |
4342 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
4343 | if (m_backendDispatcher->hasProtocolErrors()) { |
4344 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'LayerTree.layersForNode' can't be processed"_s ); |
4345 | return; |
4346 | } |
4347 | |
4348 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4349 | if (m_alternateDispatcher) { |
4350 | m_alternateDispatcher->layersForNode(requestId, in_nodeId); |
4351 | return; |
4352 | } |
4353 | #endif |
4354 | |
4355 | ErrorString error; |
4356 | Ref<JSON::Object> result = JSON::Object::create(); |
4357 | RefPtr<JSON::ArrayOf<Inspector::Protocol::LayerTree::Layer>> out_layers; |
4358 | m_agent->layersForNode(error, in_nodeId, out_layers); |
4359 | |
4360 | if (!error.length()) |
4361 | result->setArray("layers"_s , out_layers); |
4362 | |
4363 | if (!error.length()) |
4364 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4365 | else |
4366 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4367 | } |
4368 | |
4369 | void LayerTreeBackendDispatcher::reasonsForCompositingLayer(long requestId, RefPtr<JSON::Object>&& parameters) |
4370 | { |
4371 | String in_layerId = m_backendDispatcher->getString(parameters.get(), "layerId"_s , nullptr); |
4372 | if (m_backendDispatcher->hasProtocolErrors()) { |
4373 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'LayerTree.reasonsForCompositingLayer' can't be processed"_s ); |
4374 | return; |
4375 | } |
4376 | |
4377 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4378 | if (m_alternateDispatcher) { |
4379 | m_alternateDispatcher->reasonsForCompositingLayer(requestId, in_layerId); |
4380 | return; |
4381 | } |
4382 | #endif |
4383 | |
4384 | ErrorString error; |
4385 | Ref<JSON::Object> result = JSON::Object::create(); |
4386 | RefPtr<Inspector::Protocol::LayerTree::CompositingReasons> out_compositingReasons; |
4387 | m_agent->reasonsForCompositingLayer(error, in_layerId, out_compositingReasons); |
4388 | |
4389 | if (!error.length()) |
4390 | result->setObject("compositingReasons"_s , out_compositingReasons); |
4391 | |
4392 | if (!error.length()) |
4393 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4394 | else |
4395 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4396 | } |
4397 | |
4398 | #if ENABLE(RESOURCE_USAGE) |
4399 | Ref<MemoryBackendDispatcher> MemoryBackendDispatcher::create(BackendDispatcher& backendDispatcher, MemoryBackendDispatcherHandler* agent) |
4400 | { |
4401 | return adoptRef(*new MemoryBackendDispatcher(backendDispatcher, agent)); |
4402 | } |
4403 | |
4404 | MemoryBackendDispatcher::MemoryBackendDispatcher(BackendDispatcher& backendDispatcher, MemoryBackendDispatcherHandler* agent) |
4405 | : SupplementalBackendDispatcher(backendDispatcher) |
4406 | , m_agent(agent) |
4407 | { |
4408 | m_backendDispatcher->registerDispatcherForDomain("Memory"_s , this); |
4409 | } |
4410 | |
4411 | void MemoryBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
4412 | { |
4413 | Ref<MemoryBackendDispatcher> protect(*this); |
4414 | |
4415 | RefPtr<JSON::Object> parameters; |
4416 | message->getObject("params"_s , parameters); |
4417 | |
4418 | if (method == "enable" ) |
4419 | enable(requestId, WTFMove(parameters)); |
4420 | else if (method == "disable" ) |
4421 | disable(requestId, WTFMove(parameters)); |
4422 | else if (method == "startTracking" ) |
4423 | startTracking(requestId, WTFMove(parameters)); |
4424 | else if (method == "stopTracking" ) |
4425 | stopTracking(requestId, WTFMove(parameters)); |
4426 | else |
4427 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Memory." + method + "' was not found" ); |
4428 | } |
4429 | |
4430 | void MemoryBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
4431 | { |
4432 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4433 | if (m_alternateDispatcher) { |
4434 | m_alternateDispatcher->enable(requestId); |
4435 | return; |
4436 | } |
4437 | #endif |
4438 | |
4439 | ErrorString error; |
4440 | Ref<JSON::Object> result = JSON::Object::create(); |
4441 | m_agent->enable(error); |
4442 | |
4443 | if (!error.length()) |
4444 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4445 | else |
4446 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4447 | } |
4448 | |
4449 | void MemoryBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
4450 | { |
4451 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4452 | if (m_alternateDispatcher) { |
4453 | m_alternateDispatcher->disable(requestId); |
4454 | return; |
4455 | } |
4456 | #endif |
4457 | |
4458 | ErrorString error; |
4459 | Ref<JSON::Object> result = JSON::Object::create(); |
4460 | m_agent->disable(error); |
4461 | |
4462 | if (!error.length()) |
4463 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4464 | else |
4465 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4466 | } |
4467 | |
4468 | void MemoryBackendDispatcher::startTracking(long requestId, RefPtr<JSON::Object>&&) |
4469 | { |
4470 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4471 | if (m_alternateDispatcher) { |
4472 | m_alternateDispatcher->startTracking(requestId); |
4473 | return; |
4474 | } |
4475 | #endif |
4476 | |
4477 | ErrorString error; |
4478 | Ref<JSON::Object> result = JSON::Object::create(); |
4479 | m_agent->startTracking(error); |
4480 | |
4481 | if (!error.length()) |
4482 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4483 | else |
4484 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4485 | } |
4486 | |
4487 | void MemoryBackendDispatcher::stopTracking(long requestId, RefPtr<JSON::Object>&&) |
4488 | { |
4489 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4490 | if (m_alternateDispatcher) { |
4491 | m_alternateDispatcher->stopTracking(requestId); |
4492 | return; |
4493 | } |
4494 | #endif |
4495 | |
4496 | ErrorString error; |
4497 | Ref<JSON::Object> result = JSON::Object::create(); |
4498 | m_agent->stopTracking(error); |
4499 | |
4500 | if (!error.length()) |
4501 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4502 | else |
4503 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4504 | } |
4505 | #endif // ENABLE(RESOURCE_USAGE) |
4506 | |
4507 | Ref<NetworkBackendDispatcher> NetworkBackendDispatcher::create(BackendDispatcher& backendDispatcher, NetworkBackendDispatcherHandler* agent) |
4508 | { |
4509 | return adoptRef(*new NetworkBackendDispatcher(backendDispatcher, agent)); |
4510 | } |
4511 | |
4512 | NetworkBackendDispatcher::NetworkBackendDispatcher(BackendDispatcher& backendDispatcher, NetworkBackendDispatcherHandler* agent) |
4513 | : SupplementalBackendDispatcher(backendDispatcher) |
4514 | , m_agent(agent) |
4515 | { |
4516 | m_backendDispatcher->registerDispatcherForDomain("Network"_s , this); |
4517 | } |
4518 | |
4519 | void NetworkBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
4520 | { |
4521 | Ref<NetworkBackendDispatcher> protect(*this); |
4522 | |
4523 | RefPtr<JSON::Object> parameters; |
4524 | message->getObject("params"_s , parameters); |
4525 | |
4526 | typedef void (NetworkBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
4527 | typedef HashMap<String, CallHandler> DispatchMap; |
4528 | static NeverDestroyed<DispatchMap> dispatchMap; |
4529 | if (dispatchMap.get().isEmpty()) { |
4530 | static const struct MethodTable { |
4531 | const char* name; |
4532 | CallHandler handler; |
4533 | } commands[] = { |
4534 | { "enable" , &NetworkBackendDispatcher::enable }, |
4535 | { "disable" , &NetworkBackendDispatcher::disable }, |
4536 | { "setExtraHTTPHeaders" , &NetworkBackendDispatcher::setExtraHTTPHeaders }, |
4537 | { "getResponseBody" , &NetworkBackendDispatcher::getResponseBody }, |
4538 | { "setResourceCachingDisabled" , &NetworkBackendDispatcher::setResourceCachingDisabled }, |
4539 | { "loadResource" , &NetworkBackendDispatcher::loadResource }, |
4540 | { "getSerializedCertificate" , &NetworkBackendDispatcher::getSerializedCertificate }, |
4541 | { "resolveWebSocket" , &NetworkBackendDispatcher::resolveWebSocket }, |
4542 | }; |
4543 | size_t length = WTF_ARRAY_LENGTH(commands); |
4544 | for (size_t i = 0; i < length; ++i) |
4545 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
4546 | } |
4547 | |
4548 | auto findResult = dispatchMap.get().find(method); |
4549 | if (findResult == dispatchMap.get().end()) { |
4550 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network." + method + "' was not found" ); |
4551 | return; |
4552 | } |
4553 | |
4554 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
4555 | } |
4556 | |
4557 | void NetworkBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
4558 | { |
4559 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4560 | if (m_alternateDispatcher) { |
4561 | m_alternateDispatcher->enable(requestId); |
4562 | return; |
4563 | } |
4564 | #endif |
4565 | |
4566 | ErrorString error; |
4567 | Ref<JSON::Object> result = JSON::Object::create(); |
4568 | m_agent->enable(error); |
4569 | |
4570 | if (!error.length()) |
4571 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4572 | else |
4573 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4574 | } |
4575 | |
4576 | void NetworkBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
4577 | { |
4578 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4579 | if (m_alternateDispatcher) { |
4580 | m_alternateDispatcher->disable(requestId); |
4581 | return; |
4582 | } |
4583 | #endif |
4584 | |
4585 | ErrorString error; |
4586 | Ref<JSON::Object> result = JSON::Object::create(); |
4587 | m_agent->disable(error); |
4588 | |
4589 | if (!error.length()) |
4590 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4591 | else |
4592 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4593 | } |
4594 | |
4595 | void NetworkBackendDispatcher::(long requestId, RefPtr<JSON::Object>&& parameters) |
4596 | { |
4597 | RefPtr<JSON::Object> = m_backendDispatcher->getObject(parameters.get(), "headers"_s , nullptr); |
4598 | if (m_backendDispatcher->hasProtocolErrors()) { |
4599 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.setExtraHTTPHeaders' can't be processed"_s ); |
4600 | return; |
4601 | } |
4602 | |
4603 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4604 | if (m_alternateDispatcher) { |
4605 | m_alternateDispatcher->setExtraHTTPHeaders(requestId, *in_headers); |
4606 | return; |
4607 | } |
4608 | #endif |
4609 | |
4610 | ErrorString error; |
4611 | Ref<JSON::Object> result = JSON::Object::create(); |
4612 | m_agent->setExtraHTTPHeaders(error, *in_headers); |
4613 | |
4614 | if (!error.length()) |
4615 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4616 | else |
4617 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4618 | } |
4619 | |
4620 | void NetworkBackendDispatcher::getResponseBody(long requestId, RefPtr<JSON::Object>&& parameters) |
4621 | { |
4622 | String in_requestId = m_backendDispatcher->getString(parameters.get(), "requestId"_s , nullptr); |
4623 | if (m_backendDispatcher->hasProtocolErrors()) { |
4624 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.getResponseBody' can't be processed"_s ); |
4625 | return; |
4626 | } |
4627 | |
4628 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4629 | if (m_alternateDispatcher) { |
4630 | m_alternateDispatcher->getResponseBody(requestId, in_requestId); |
4631 | return; |
4632 | } |
4633 | #endif |
4634 | |
4635 | ErrorString error; |
4636 | Ref<JSON::Object> result = JSON::Object::create(); |
4637 | String out_body; |
4638 | bool out_base64Encoded; |
4639 | m_agent->getResponseBody(error, in_requestId, &out_body, &out_base64Encoded); |
4640 | |
4641 | if (!error.length()) { |
4642 | result->setString("body"_s , out_body); |
4643 | result->setBoolean("base64Encoded"_s , out_base64Encoded); |
4644 | } |
4645 | if (!error.length()) |
4646 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4647 | else |
4648 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4649 | } |
4650 | |
4651 | void NetworkBackendDispatcher::setResourceCachingDisabled(long requestId, RefPtr<JSON::Object>&& parameters) |
4652 | { |
4653 | bool in_disabled = m_backendDispatcher->getBoolean(parameters.get(), "disabled"_s , nullptr); |
4654 | if (m_backendDispatcher->hasProtocolErrors()) { |
4655 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.setResourceCachingDisabled' can't be processed"_s ); |
4656 | return; |
4657 | } |
4658 | |
4659 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4660 | if (m_alternateDispatcher) { |
4661 | m_alternateDispatcher->setResourceCachingDisabled(requestId, in_disabled); |
4662 | return; |
4663 | } |
4664 | #endif |
4665 | |
4666 | ErrorString error; |
4667 | Ref<JSON::Object> result = JSON::Object::create(); |
4668 | m_agent->setResourceCachingDisabled(error, in_disabled); |
4669 | |
4670 | if (!error.length()) |
4671 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4672 | else |
4673 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4674 | } |
4675 | |
4676 | NetworkBackendDispatcherHandler::LoadResourceCallback::LoadResourceCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
4677 | |
4678 | void NetworkBackendDispatcherHandler::LoadResourceCallback::sendSuccess(const String& content, const String& mimeType, int status) |
4679 | { |
4680 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
4681 | jsonMessage->setString("content"_s , content); |
4682 | jsonMessage->setString("mimeType"_s , mimeType); |
4683 | jsonMessage->setInteger("status"_s , status); |
4684 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
4685 | } |
4686 | |
4687 | void NetworkBackendDispatcher::loadResource(long requestId, RefPtr<JSON::Object>&& parameters) |
4688 | { |
4689 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
4690 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
4691 | if (m_backendDispatcher->hasProtocolErrors()) { |
4692 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.loadResource' can't be processed"_s ); |
4693 | return; |
4694 | } |
4695 | |
4696 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4697 | if (m_alternateDispatcher) { |
4698 | m_alternateDispatcher->loadResource(requestId, in_frameId, in_url); |
4699 | return; |
4700 | } |
4701 | #endif |
4702 | |
4703 | Ref<NetworkBackendDispatcherHandler::LoadResourceCallback> callback = adoptRef(*new NetworkBackendDispatcherHandler::LoadResourceCallback(m_backendDispatcher.copyRef(), requestId)); |
4704 | m_agent->loadResource(in_frameId, in_url, callback.copyRef()); |
4705 | |
4706 | } |
4707 | |
4708 | void NetworkBackendDispatcher::getSerializedCertificate(long requestId, RefPtr<JSON::Object>&& parameters) |
4709 | { |
4710 | String in_requestId = m_backendDispatcher->getString(parameters.get(), "requestId"_s , nullptr); |
4711 | if (m_backendDispatcher->hasProtocolErrors()) { |
4712 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.getSerializedCertificate' can't be processed"_s ); |
4713 | return; |
4714 | } |
4715 | |
4716 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4717 | if (m_alternateDispatcher) { |
4718 | m_alternateDispatcher->getSerializedCertificate(requestId, in_requestId); |
4719 | return; |
4720 | } |
4721 | #endif |
4722 | |
4723 | ErrorString error; |
4724 | Ref<JSON::Object> result = JSON::Object::create(); |
4725 | String out_serializedCertificate; |
4726 | m_agent->getSerializedCertificate(error, in_requestId, &out_serializedCertificate); |
4727 | |
4728 | if (!error.length()) |
4729 | result->setString("serializedCertificate"_s , out_serializedCertificate); |
4730 | |
4731 | if (!error.length()) |
4732 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4733 | else |
4734 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4735 | } |
4736 | |
4737 | void NetworkBackendDispatcher::resolveWebSocket(long requestId, RefPtr<JSON::Object>&& parameters) |
4738 | { |
4739 | String in_requestId = m_backendDispatcher->getString(parameters.get(), "requestId"_s , nullptr); |
4740 | bool opt_in_objectGroup_valueFound = false; |
4741 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
4742 | if (m_backendDispatcher->hasProtocolErrors()) { |
4743 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.resolveWebSocket' can't be processed"_s ); |
4744 | return; |
4745 | } |
4746 | |
4747 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4748 | if (m_alternateDispatcher) { |
4749 | m_alternateDispatcher->resolveWebSocket(requestId, in_requestId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr); |
4750 | return; |
4751 | } |
4752 | #endif |
4753 | |
4754 | ErrorString error; |
4755 | Ref<JSON::Object> result = JSON::Object::create(); |
4756 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_object; |
4757 | m_agent->resolveWebSocket(error, in_requestId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, out_object); |
4758 | |
4759 | if (!error.length()) |
4760 | result->setObject("object"_s , out_object); |
4761 | |
4762 | if (!error.length()) |
4763 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4764 | else |
4765 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4766 | } |
4767 | |
4768 | Ref<PageBackendDispatcher> PageBackendDispatcher::create(BackendDispatcher& backendDispatcher, PageBackendDispatcherHandler* agent) |
4769 | { |
4770 | return adoptRef(*new PageBackendDispatcher(backendDispatcher, agent)); |
4771 | } |
4772 | |
4773 | PageBackendDispatcher::PageBackendDispatcher(BackendDispatcher& backendDispatcher, PageBackendDispatcherHandler* agent) |
4774 | : SupplementalBackendDispatcher(backendDispatcher) |
4775 | , m_agent(agent) |
4776 | { |
4777 | m_backendDispatcher->registerDispatcherForDomain("Page"_s , this); |
4778 | } |
4779 | |
4780 | void PageBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
4781 | { |
4782 | Ref<PageBackendDispatcher> protect(*this); |
4783 | |
4784 | RefPtr<JSON::Object> parameters; |
4785 | message->getObject("params"_s , parameters); |
4786 | |
4787 | typedef void (PageBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
4788 | typedef HashMap<String, CallHandler> DispatchMap; |
4789 | static NeverDestroyed<DispatchMap> dispatchMap; |
4790 | if (dispatchMap.get().isEmpty()) { |
4791 | static const struct MethodTable { |
4792 | const char* name; |
4793 | CallHandler handler; |
4794 | } commands[] = { |
4795 | { "enable" , &PageBackendDispatcher::enable }, |
4796 | { "disable" , &PageBackendDispatcher::disable }, |
4797 | { "reload" , &PageBackendDispatcher::reload }, |
4798 | { "navigate" , &PageBackendDispatcher::navigate }, |
4799 | { "overrideUserAgent" , &PageBackendDispatcher::overrideUserAgent }, |
4800 | { "overrideSetting" , &PageBackendDispatcher::overrideSetting }, |
4801 | { "getCookies" , &PageBackendDispatcher::getCookies }, |
4802 | { "deleteCookie" , &PageBackendDispatcher::deleteCookie }, |
4803 | { "getResourceTree" , &PageBackendDispatcher::getResourceTree }, |
4804 | { "getResourceContent" , &PageBackendDispatcher::getResourceContent }, |
4805 | { "searchInResource" , &PageBackendDispatcher::searchInResource }, |
4806 | { "searchInResources" , &PageBackendDispatcher::searchInResources }, |
4807 | { "setShowRulers" , &PageBackendDispatcher::setShowRulers }, |
4808 | { "setShowPaintRects" , &PageBackendDispatcher::setShowPaintRects }, |
4809 | { "setEmulatedMedia" , &PageBackendDispatcher::setEmulatedMedia }, |
4810 | { "setForcedAppearance" , &PageBackendDispatcher::setForcedAppearance }, |
4811 | { "getCompositingBordersVisible" , &PageBackendDispatcher::getCompositingBordersVisible }, |
4812 | { "setCompositingBordersVisible" , &PageBackendDispatcher::setCompositingBordersVisible }, |
4813 | { "snapshotNode" , &PageBackendDispatcher::snapshotNode }, |
4814 | { "snapshotRect" , &PageBackendDispatcher::snapshotRect }, |
4815 | { "archive" , &PageBackendDispatcher::archive }, |
4816 | }; |
4817 | size_t length = WTF_ARRAY_LENGTH(commands); |
4818 | for (size_t i = 0; i < length; ++i) |
4819 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
4820 | } |
4821 | |
4822 | auto findResult = dispatchMap.get().find(method); |
4823 | if (findResult == dispatchMap.get().end()) { |
4824 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Page." + method + "' was not found" ); |
4825 | return; |
4826 | } |
4827 | |
4828 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
4829 | } |
4830 | |
4831 | void PageBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
4832 | { |
4833 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4834 | if (m_alternateDispatcher) { |
4835 | m_alternateDispatcher->enable(requestId); |
4836 | return; |
4837 | } |
4838 | #endif |
4839 | |
4840 | ErrorString error; |
4841 | Ref<JSON::Object> result = JSON::Object::create(); |
4842 | m_agent->enable(error); |
4843 | |
4844 | if (!error.length()) |
4845 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4846 | else |
4847 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4848 | } |
4849 | |
4850 | void PageBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
4851 | { |
4852 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4853 | if (m_alternateDispatcher) { |
4854 | m_alternateDispatcher->disable(requestId); |
4855 | return; |
4856 | } |
4857 | #endif |
4858 | |
4859 | ErrorString error; |
4860 | Ref<JSON::Object> result = JSON::Object::create(); |
4861 | m_agent->disable(error); |
4862 | |
4863 | if (!error.length()) |
4864 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4865 | else |
4866 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4867 | } |
4868 | |
4869 | void PageBackendDispatcher::reload(long requestId, RefPtr<JSON::Object>&& parameters) |
4870 | { |
4871 | bool opt_in_ignoreCache_valueFound = false; |
4872 | bool opt_in_ignoreCache = m_backendDispatcher->getBoolean(parameters.get(), "ignoreCache"_s , &opt_in_ignoreCache_valueFound); |
4873 | bool opt_in_revalidateAllResources_valueFound = false; |
4874 | bool opt_in_revalidateAllResources = m_backendDispatcher->getBoolean(parameters.get(), "revalidateAllResources"_s , &opt_in_revalidateAllResources_valueFound); |
4875 | if (m_backendDispatcher->hasProtocolErrors()) { |
4876 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.reload' can't be processed"_s ); |
4877 | return; |
4878 | } |
4879 | |
4880 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4881 | if (m_alternateDispatcher) { |
4882 | m_alternateDispatcher->reload(requestId, opt_in_ignoreCache_valueFound ? &opt_in_ignoreCache : nullptr, opt_in_revalidateAllResources_valueFound ? &opt_in_revalidateAllResources : nullptr); |
4883 | return; |
4884 | } |
4885 | #endif |
4886 | |
4887 | ErrorString error; |
4888 | Ref<JSON::Object> result = JSON::Object::create(); |
4889 | m_agent->reload(error, opt_in_ignoreCache_valueFound ? &opt_in_ignoreCache : nullptr, opt_in_revalidateAllResources_valueFound ? &opt_in_revalidateAllResources : nullptr); |
4890 | |
4891 | if (!error.length()) |
4892 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4893 | else |
4894 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4895 | } |
4896 | |
4897 | void PageBackendDispatcher::navigate(long requestId, RefPtr<JSON::Object>&& parameters) |
4898 | { |
4899 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
4900 | if (m_backendDispatcher->hasProtocolErrors()) { |
4901 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.navigate' can't be processed"_s ); |
4902 | return; |
4903 | } |
4904 | |
4905 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4906 | if (m_alternateDispatcher) { |
4907 | m_alternateDispatcher->navigate(requestId, in_url); |
4908 | return; |
4909 | } |
4910 | #endif |
4911 | |
4912 | ErrorString error; |
4913 | Ref<JSON::Object> result = JSON::Object::create(); |
4914 | m_agent->navigate(error, in_url); |
4915 | |
4916 | if (!error.length()) |
4917 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4918 | else |
4919 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4920 | } |
4921 | |
4922 | void PageBackendDispatcher::overrideUserAgent(long requestId, RefPtr<JSON::Object>&& parameters) |
4923 | { |
4924 | bool opt_in_value_valueFound = false; |
4925 | String opt_in_value = m_backendDispatcher->getString(parameters.get(), "value"_s , &opt_in_value_valueFound); |
4926 | if (m_backendDispatcher->hasProtocolErrors()) { |
4927 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.overrideUserAgent' can't be processed"_s ); |
4928 | return; |
4929 | } |
4930 | |
4931 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4932 | if (m_alternateDispatcher) { |
4933 | m_alternateDispatcher->overrideUserAgent(requestId, opt_in_value_valueFound ? &opt_in_value : nullptr); |
4934 | return; |
4935 | } |
4936 | #endif |
4937 | |
4938 | ErrorString error; |
4939 | Ref<JSON::Object> result = JSON::Object::create(); |
4940 | m_agent->overrideUserAgent(error, opt_in_value_valueFound ? &opt_in_value : nullptr); |
4941 | |
4942 | if (!error.length()) |
4943 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4944 | else |
4945 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4946 | } |
4947 | |
4948 | void PageBackendDispatcher::overrideSetting(long requestId, RefPtr<JSON::Object>&& parameters) |
4949 | { |
4950 | String in_setting = m_backendDispatcher->getString(parameters.get(), "setting"_s , nullptr); |
4951 | bool opt_in_value_valueFound = false; |
4952 | bool opt_in_value = m_backendDispatcher->getBoolean(parameters.get(), "value"_s , &opt_in_value_valueFound); |
4953 | if (m_backendDispatcher->hasProtocolErrors()) { |
4954 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.overrideSetting' can't be processed"_s ); |
4955 | return; |
4956 | } |
4957 | |
4958 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4959 | if (m_alternateDispatcher) { |
4960 | m_alternateDispatcher->overrideSetting(requestId, in_setting, opt_in_value_valueFound ? &opt_in_value : nullptr); |
4961 | return; |
4962 | } |
4963 | #endif |
4964 | |
4965 | ErrorString error; |
4966 | Ref<JSON::Object> result = JSON::Object::create(); |
4967 | m_agent->overrideSetting(error, in_setting, opt_in_value_valueFound ? &opt_in_value : nullptr); |
4968 | |
4969 | if (!error.length()) |
4970 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4971 | else |
4972 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4973 | } |
4974 | |
4975 | void PageBackendDispatcher::getCookies(long requestId, RefPtr<JSON::Object>&&) |
4976 | { |
4977 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
4978 | if (m_alternateDispatcher) { |
4979 | m_alternateDispatcher->getCookies(requestId); |
4980 | return; |
4981 | } |
4982 | #endif |
4983 | |
4984 | ErrorString error; |
4985 | Ref<JSON::Object> result = JSON::Object::create(); |
4986 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Page::Cookie>> out_cookies; |
4987 | m_agent->getCookies(error, out_cookies); |
4988 | |
4989 | if (!error.length()) |
4990 | result->setArray("cookies"_s , out_cookies); |
4991 | |
4992 | if (!error.length()) |
4993 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
4994 | else |
4995 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
4996 | } |
4997 | |
4998 | void PageBackendDispatcher::deleteCookie(long requestId, RefPtr<JSON::Object>&& parameters) |
4999 | { |
5000 | String in_cookieName = m_backendDispatcher->getString(parameters.get(), "cookieName"_s , nullptr); |
5001 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
5002 | if (m_backendDispatcher->hasProtocolErrors()) { |
5003 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.deleteCookie' can't be processed"_s ); |
5004 | return; |
5005 | } |
5006 | |
5007 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5008 | if (m_alternateDispatcher) { |
5009 | m_alternateDispatcher->deleteCookie(requestId, in_cookieName, in_url); |
5010 | return; |
5011 | } |
5012 | #endif |
5013 | |
5014 | ErrorString error; |
5015 | Ref<JSON::Object> result = JSON::Object::create(); |
5016 | m_agent->deleteCookie(error, in_cookieName, in_url); |
5017 | |
5018 | if (!error.length()) |
5019 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5020 | else |
5021 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5022 | } |
5023 | |
5024 | void PageBackendDispatcher::getResourceTree(long requestId, RefPtr<JSON::Object>&&) |
5025 | { |
5026 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5027 | if (m_alternateDispatcher) { |
5028 | m_alternateDispatcher->getResourceTree(requestId); |
5029 | return; |
5030 | } |
5031 | #endif |
5032 | |
5033 | ErrorString error; |
5034 | Ref<JSON::Object> result = JSON::Object::create(); |
5035 | RefPtr<Inspector::Protocol::Page::FrameResourceTree> out_frameTree; |
5036 | m_agent->getResourceTree(error, out_frameTree); |
5037 | |
5038 | if (!error.length()) |
5039 | result->setObject("frameTree"_s , out_frameTree); |
5040 | |
5041 | if (!error.length()) |
5042 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5043 | else |
5044 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5045 | } |
5046 | |
5047 | void PageBackendDispatcher::getResourceContent(long requestId, RefPtr<JSON::Object>&& parameters) |
5048 | { |
5049 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
5050 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
5051 | if (m_backendDispatcher->hasProtocolErrors()) { |
5052 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.getResourceContent' can't be processed"_s ); |
5053 | return; |
5054 | } |
5055 | |
5056 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5057 | if (m_alternateDispatcher) { |
5058 | m_alternateDispatcher->getResourceContent(requestId, in_frameId, in_url); |
5059 | return; |
5060 | } |
5061 | #endif |
5062 | |
5063 | ErrorString error; |
5064 | Ref<JSON::Object> result = JSON::Object::create(); |
5065 | String out_content; |
5066 | bool out_base64Encoded; |
5067 | m_agent->getResourceContent(error, in_frameId, in_url, &out_content, &out_base64Encoded); |
5068 | |
5069 | if (!error.length()) { |
5070 | result->setString("content"_s , out_content); |
5071 | result->setBoolean("base64Encoded"_s , out_base64Encoded); |
5072 | } |
5073 | if (!error.length()) |
5074 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5075 | else |
5076 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5077 | } |
5078 | |
5079 | void PageBackendDispatcher::searchInResource(long requestId, RefPtr<JSON::Object>&& parameters) |
5080 | { |
5081 | String in_frameId = m_backendDispatcher->getString(parameters.get(), "frameId"_s , nullptr); |
5082 | String in_url = m_backendDispatcher->getString(parameters.get(), "url"_s , nullptr); |
5083 | String in_query = m_backendDispatcher->getString(parameters.get(), "query"_s , nullptr); |
5084 | bool opt_in_caseSensitive_valueFound = false; |
5085 | bool opt_in_caseSensitive = m_backendDispatcher->getBoolean(parameters.get(), "caseSensitive"_s , &opt_in_caseSensitive_valueFound); |
5086 | bool opt_in_isRegex_valueFound = false; |
5087 | bool opt_in_isRegex = m_backendDispatcher->getBoolean(parameters.get(), "isRegex"_s , &opt_in_isRegex_valueFound); |
5088 | bool opt_in_requestId_valueFound = false; |
5089 | String opt_in_requestId = m_backendDispatcher->getString(parameters.get(), "requestId"_s , &opt_in_requestId_valueFound); |
5090 | if (m_backendDispatcher->hasProtocolErrors()) { |
5091 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.searchInResource' can't be processed"_s ); |
5092 | return; |
5093 | } |
5094 | |
5095 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5096 | if (m_alternateDispatcher) { |
5097 | m_alternateDispatcher->searchInResource(requestId, in_frameId, in_url, in_query, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr, opt_in_requestId_valueFound ? &opt_in_requestId : nullptr); |
5098 | return; |
5099 | } |
5100 | #endif |
5101 | |
5102 | ErrorString error; |
5103 | Ref<JSON::Object> result = JSON::Object::create(); |
5104 | RefPtr<JSON::ArrayOf<Inspector::Protocol::GenericTypes::SearchMatch>> out_result; |
5105 | m_agent->searchInResource(error, in_frameId, in_url, in_query, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr, opt_in_requestId_valueFound ? &opt_in_requestId : nullptr, out_result); |
5106 | |
5107 | if (!error.length()) |
5108 | result->setArray("result"_s , out_result); |
5109 | |
5110 | if (!error.length()) |
5111 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5112 | else |
5113 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5114 | } |
5115 | |
5116 | void PageBackendDispatcher::searchInResources(long requestId, RefPtr<JSON::Object>&& parameters) |
5117 | { |
5118 | String in_text = m_backendDispatcher->getString(parameters.get(), "text"_s , nullptr); |
5119 | bool opt_in_caseSensitive_valueFound = false; |
5120 | bool opt_in_caseSensitive = m_backendDispatcher->getBoolean(parameters.get(), "caseSensitive"_s , &opt_in_caseSensitive_valueFound); |
5121 | bool opt_in_isRegex_valueFound = false; |
5122 | bool opt_in_isRegex = m_backendDispatcher->getBoolean(parameters.get(), "isRegex"_s , &opt_in_isRegex_valueFound); |
5123 | if (m_backendDispatcher->hasProtocolErrors()) { |
5124 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.searchInResources' can't be processed"_s ); |
5125 | return; |
5126 | } |
5127 | |
5128 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5129 | if (m_alternateDispatcher) { |
5130 | m_alternateDispatcher->searchInResources(requestId, in_text, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr); |
5131 | return; |
5132 | } |
5133 | #endif |
5134 | |
5135 | ErrorString error; |
5136 | Ref<JSON::Object> result = JSON::Object::create(); |
5137 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Page::SearchResult>> out_result; |
5138 | m_agent->searchInResources(error, in_text, opt_in_caseSensitive_valueFound ? &opt_in_caseSensitive : nullptr, opt_in_isRegex_valueFound ? &opt_in_isRegex : nullptr, out_result); |
5139 | |
5140 | if (!error.length()) |
5141 | result->setArray("result"_s , out_result); |
5142 | |
5143 | if (!error.length()) |
5144 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5145 | else |
5146 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5147 | } |
5148 | |
5149 | void PageBackendDispatcher::setShowRulers(long requestId, RefPtr<JSON::Object>&& parameters) |
5150 | { |
5151 | bool in_result = m_backendDispatcher->getBoolean(parameters.get(), "result"_s , nullptr); |
5152 | if (m_backendDispatcher->hasProtocolErrors()) { |
5153 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setShowRulers' can't be processed"_s ); |
5154 | return; |
5155 | } |
5156 | |
5157 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5158 | if (m_alternateDispatcher) { |
5159 | m_alternateDispatcher->setShowRulers(requestId, in_result); |
5160 | return; |
5161 | } |
5162 | #endif |
5163 | |
5164 | ErrorString error; |
5165 | Ref<JSON::Object> result = JSON::Object::create(); |
5166 | m_agent->setShowRulers(error, in_result); |
5167 | |
5168 | if (!error.length()) |
5169 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5170 | else |
5171 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5172 | } |
5173 | |
5174 | void PageBackendDispatcher::setShowPaintRects(long requestId, RefPtr<JSON::Object>&& parameters) |
5175 | { |
5176 | bool in_result = m_backendDispatcher->getBoolean(parameters.get(), "result"_s , nullptr); |
5177 | if (m_backendDispatcher->hasProtocolErrors()) { |
5178 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setShowPaintRects' can't be processed"_s ); |
5179 | return; |
5180 | } |
5181 | |
5182 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5183 | if (m_alternateDispatcher) { |
5184 | m_alternateDispatcher->setShowPaintRects(requestId, in_result); |
5185 | return; |
5186 | } |
5187 | #endif |
5188 | |
5189 | ErrorString error; |
5190 | Ref<JSON::Object> result = JSON::Object::create(); |
5191 | m_agent->setShowPaintRects(error, in_result); |
5192 | |
5193 | if (!error.length()) |
5194 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5195 | else |
5196 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5197 | } |
5198 | |
5199 | void PageBackendDispatcher::setEmulatedMedia(long requestId, RefPtr<JSON::Object>&& parameters) |
5200 | { |
5201 | String in_media = m_backendDispatcher->getString(parameters.get(), "media"_s , nullptr); |
5202 | if (m_backendDispatcher->hasProtocolErrors()) { |
5203 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setEmulatedMedia' can't be processed"_s ); |
5204 | return; |
5205 | } |
5206 | |
5207 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5208 | if (m_alternateDispatcher) { |
5209 | m_alternateDispatcher->setEmulatedMedia(requestId, in_media); |
5210 | return; |
5211 | } |
5212 | #endif |
5213 | |
5214 | ErrorString error; |
5215 | Ref<JSON::Object> result = JSON::Object::create(); |
5216 | m_agent->setEmulatedMedia(error, in_media); |
5217 | |
5218 | if (!error.length()) |
5219 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5220 | else |
5221 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5222 | } |
5223 | |
5224 | void PageBackendDispatcher::setForcedAppearance(long requestId, RefPtr<JSON::Object>&& parameters) |
5225 | { |
5226 | String in_appearance = m_backendDispatcher->getString(parameters.get(), "appearance"_s , nullptr); |
5227 | if (m_backendDispatcher->hasProtocolErrors()) { |
5228 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setForcedAppearance' can't be processed"_s ); |
5229 | return; |
5230 | } |
5231 | |
5232 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5233 | if (m_alternateDispatcher) { |
5234 | m_alternateDispatcher->setForcedAppearance(requestId, in_appearance); |
5235 | return; |
5236 | } |
5237 | #endif |
5238 | |
5239 | ErrorString error; |
5240 | Ref<JSON::Object> result = JSON::Object::create(); |
5241 | m_agent->setForcedAppearance(error, in_appearance); |
5242 | |
5243 | if (!error.length()) |
5244 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5245 | else |
5246 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5247 | } |
5248 | |
5249 | void PageBackendDispatcher::getCompositingBordersVisible(long requestId, RefPtr<JSON::Object>&&) |
5250 | { |
5251 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5252 | if (m_alternateDispatcher) { |
5253 | m_alternateDispatcher->getCompositingBordersVisible(requestId); |
5254 | return; |
5255 | } |
5256 | #endif |
5257 | |
5258 | ErrorString error; |
5259 | Ref<JSON::Object> result = JSON::Object::create(); |
5260 | bool out_result; |
5261 | m_agent->getCompositingBordersVisible(error, &out_result); |
5262 | |
5263 | if (!error.length()) |
5264 | result->setBoolean("result"_s , out_result); |
5265 | |
5266 | if (!error.length()) |
5267 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5268 | else |
5269 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5270 | } |
5271 | |
5272 | void PageBackendDispatcher::setCompositingBordersVisible(long requestId, RefPtr<JSON::Object>&& parameters) |
5273 | { |
5274 | bool in_visible = m_backendDispatcher->getBoolean(parameters.get(), "visible"_s , nullptr); |
5275 | if (m_backendDispatcher->hasProtocolErrors()) { |
5276 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setCompositingBordersVisible' can't be processed"_s ); |
5277 | return; |
5278 | } |
5279 | |
5280 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5281 | if (m_alternateDispatcher) { |
5282 | m_alternateDispatcher->setCompositingBordersVisible(requestId, in_visible); |
5283 | return; |
5284 | } |
5285 | #endif |
5286 | |
5287 | ErrorString error; |
5288 | Ref<JSON::Object> result = JSON::Object::create(); |
5289 | m_agent->setCompositingBordersVisible(error, in_visible); |
5290 | |
5291 | if (!error.length()) |
5292 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5293 | else |
5294 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5295 | } |
5296 | |
5297 | void PageBackendDispatcher::snapshotNode(long requestId, RefPtr<JSON::Object>&& parameters) |
5298 | { |
5299 | int in_nodeId = m_backendDispatcher->getInteger(parameters.get(), "nodeId"_s , nullptr); |
5300 | if (m_backendDispatcher->hasProtocolErrors()) { |
5301 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.snapshotNode' can't be processed"_s ); |
5302 | return; |
5303 | } |
5304 | |
5305 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5306 | if (m_alternateDispatcher) { |
5307 | m_alternateDispatcher->snapshotNode(requestId, in_nodeId); |
5308 | return; |
5309 | } |
5310 | #endif |
5311 | |
5312 | ErrorString error; |
5313 | Ref<JSON::Object> result = JSON::Object::create(); |
5314 | String out_dataURL; |
5315 | m_agent->snapshotNode(error, in_nodeId, &out_dataURL); |
5316 | |
5317 | if (!error.length()) |
5318 | result->setString("dataURL"_s , out_dataURL); |
5319 | |
5320 | if (!error.length()) |
5321 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5322 | else |
5323 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5324 | } |
5325 | |
5326 | void PageBackendDispatcher::snapshotRect(long requestId, RefPtr<JSON::Object>&& parameters) |
5327 | { |
5328 | int in_x = m_backendDispatcher->getInteger(parameters.get(), "x"_s , nullptr); |
5329 | int in_y = m_backendDispatcher->getInteger(parameters.get(), "y"_s , nullptr); |
5330 | int in_width = m_backendDispatcher->getInteger(parameters.get(), "width"_s , nullptr); |
5331 | int in_height = m_backendDispatcher->getInteger(parameters.get(), "height"_s , nullptr); |
5332 | String in_coordinateSystem = m_backendDispatcher->getString(parameters.get(), "coordinateSystem"_s , nullptr); |
5333 | if (m_backendDispatcher->hasProtocolErrors()) { |
5334 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.snapshotRect' can't be processed"_s ); |
5335 | return; |
5336 | } |
5337 | |
5338 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5339 | if (m_alternateDispatcher) { |
5340 | m_alternateDispatcher->snapshotRect(requestId, in_x, in_y, in_width, in_height, in_coordinateSystem); |
5341 | return; |
5342 | } |
5343 | #endif |
5344 | |
5345 | ErrorString error; |
5346 | Ref<JSON::Object> result = JSON::Object::create(); |
5347 | String out_dataURL; |
5348 | m_agent->snapshotRect(error, in_x, in_y, in_width, in_height, in_coordinateSystem, &out_dataURL); |
5349 | |
5350 | if (!error.length()) |
5351 | result->setString("dataURL"_s , out_dataURL); |
5352 | |
5353 | if (!error.length()) |
5354 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5355 | else |
5356 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5357 | } |
5358 | |
5359 | void PageBackendDispatcher::archive(long requestId, RefPtr<JSON::Object>&&) |
5360 | { |
5361 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5362 | if (m_alternateDispatcher) { |
5363 | m_alternateDispatcher->archive(requestId); |
5364 | return; |
5365 | } |
5366 | #endif |
5367 | |
5368 | ErrorString error; |
5369 | Ref<JSON::Object> result = JSON::Object::create(); |
5370 | String out_data; |
5371 | m_agent->archive(error, &out_data); |
5372 | |
5373 | if (!error.length()) |
5374 | result->setString("data"_s , out_data); |
5375 | |
5376 | if (!error.length()) |
5377 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5378 | else |
5379 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5380 | } |
5381 | |
5382 | Ref<RuntimeBackendDispatcher> RuntimeBackendDispatcher::create(BackendDispatcher& backendDispatcher, RuntimeBackendDispatcherHandler* agent) |
5383 | { |
5384 | return adoptRef(*new RuntimeBackendDispatcher(backendDispatcher, agent)); |
5385 | } |
5386 | |
5387 | RuntimeBackendDispatcher::RuntimeBackendDispatcher(BackendDispatcher& backendDispatcher, RuntimeBackendDispatcherHandler* agent) |
5388 | : SupplementalBackendDispatcher(backendDispatcher) |
5389 | , m_agent(agent) |
5390 | { |
5391 | m_backendDispatcher->registerDispatcherForDomain("Runtime"_s , this); |
5392 | } |
5393 | |
5394 | void RuntimeBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
5395 | { |
5396 | Ref<RuntimeBackendDispatcher> protect(*this); |
5397 | |
5398 | RefPtr<JSON::Object> parameters; |
5399 | message->getObject("params"_s , parameters); |
5400 | |
5401 | typedef void (RuntimeBackendDispatcher::*CallHandler)(long requestId, RefPtr<JSON::Object>&& message); |
5402 | typedef HashMap<String, CallHandler> DispatchMap; |
5403 | static NeverDestroyed<DispatchMap> dispatchMap; |
5404 | if (dispatchMap.get().isEmpty()) { |
5405 | static const struct MethodTable { |
5406 | const char* name; |
5407 | CallHandler handler; |
5408 | } commands[] = { |
5409 | { "parse" , &RuntimeBackendDispatcher::parse }, |
5410 | { "evaluate" , &RuntimeBackendDispatcher::evaluate }, |
5411 | { "awaitPromise" , &RuntimeBackendDispatcher::awaitPromise }, |
5412 | { "callFunctionOn" , &RuntimeBackendDispatcher::callFunctionOn }, |
5413 | { "getPreview" , &RuntimeBackendDispatcher::getPreview }, |
5414 | { "getProperties" , &RuntimeBackendDispatcher::getProperties }, |
5415 | { "getDisplayableProperties" , &RuntimeBackendDispatcher::getDisplayableProperties }, |
5416 | { "getCollectionEntries" , &RuntimeBackendDispatcher::getCollectionEntries }, |
5417 | { "saveResult" , &RuntimeBackendDispatcher::saveResult }, |
5418 | { "releaseObject" , &RuntimeBackendDispatcher::releaseObject }, |
5419 | { "releaseObjectGroup" , &RuntimeBackendDispatcher::releaseObjectGroup }, |
5420 | { "enable" , &RuntimeBackendDispatcher::enable }, |
5421 | { "disable" , &RuntimeBackendDispatcher::disable }, |
5422 | { "getRuntimeTypesForVariablesAtOffsets" , &RuntimeBackendDispatcher::getRuntimeTypesForVariablesAtOffsets }, |
5423 | { "enableTypeProfiler" , &RuntimeBackendDispatcher::enableTypeProfiler }, |
5424 | { "disableTypeProfiler" , &RuntimeBackendDispatcher::disableTypeProfiler }, |
5425 | { "enableControlFlowProfiler" , &RuntimeBackendDispatcher::enableControlFlowProfiler }, |
5426 | { "disableControlFlowProfiler" , &RuntimeBackendDispatcher::disableControlFlowProfiler }, |
5427 | { "getBasicBlocks" , &RuntimeBackendDispatcher::getBasicBlocks }, |
5428 | }; |
5429 | size_t length = WTF_ARRAY_LENGTH(commands); |
5430 | for (size_t i = 0; i < length; ++i) |
5431 | dispatchMap.get().add(commands[i].name, commands[i].handler); |
5432 | } |
5433 | |
5434 | auto findResult = dispatchMap.get().find(method); |
5435 | if (findResult == dispatchMap.get().end()) { |
5436 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Runtime." + method + "' was not found" ); |
5437 | return; |
5438 | } |
5439 | |
5440 | ((*this).*findResult->value)(requestId, WTFMove(parameters)); |
5441 | } |
5442 | |
5443 | void RuntimeBackendDispatcher::parse(long requestId, RefPtr<JSON::Object>&& parameters) |
5444 | { |
5445 | String in_source = m_backendDispatcher->getString(parameters.get(), "source"_s , nullptr); |
5446 | if (m_backendDispatcher->hasProtocolErrors()) { |
5447 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.parse' can't be processed"_s ); |
5448 | return; |
5449 | } |
5450 | |
5451 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5452 | if (m_alternateDispatcher) { |
5453 | m_alternateDispatcher->parse(requestId, in_source); |
5454 | return; |
5455 | } |
5456 | #endif |
5457 | |
5458 | ErrorString error; |
5459 | Ref<JSON::Object> result = JSON::Object::create(); |
5460 | Inspector::Protocol::Runtime::SyntaxErrorType out_result; |
5461 | Optional<String> out_message; |
5462 | RefPtr<Inspector::Protocol::Runtime::ErrorRange> out_range; |
5463 | m_agent->parse(error, in_source, &out_result, out_message, out_range); |
5464 | |
5465 | if (!error.length()) { |
5466 | result->setString("result"_s , Inspector::Protocol::InspectorHelpers::getEnumConstantValue(out_result)); |
5467 | if (out_message.hasValue()) |
5468 | result->setString("message"_s , *out_message); |
5469 | if (out_range) |
5470 | result->setObject("range"_s , out_range); |
5471 | } |
5472 | if (!error.length()) |
5473 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5474 | else |
5475 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5476 | } |
5477 | |
5478 | void RuntimeBackendDispatcher::evaluate(long requestId, RefPtr<JSON::Object>&& parameters) |
5479 | { |
5480 | String in_expression = m_backendDispatcher->getString(parameters.get(), "expression"_s , nullptr); |
5481 | bool opt_in_objectGroup_valueFound = false; |
5482 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
5483 | bool opt_in_includeCommandLineAPI_valueFound = false; |
5484 | bool opt_in_includeCommandLineAPI = m_backendDispatcher->getBoolean(parameters.get(), "includeCommandLineAPI"_s , &opt_in_includeCommandLineAPI_valueFound); |
5485 | bool opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound = false; |
5486 | bool opt_in_doNotPauseOnExceptionsAndMuteConsole = m_backendDispatcher->getBoolean(parameters.get(), "doNotPauseOnExceptionsAndMuteConsole"_s , &opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound); |
5487 | bool opt_in_contextId_valueFound = false; |
5488 | int opt_in_contextId = m_backendDispatcher->getInteger(parameters.get(), "contextId"_s , &opt_in_contextId_valueFound); |
5489 | bool opt_in_returnByValue_valueFound = false; |
5490 | bool opt_in_returnByValue = m_backendDispatcher->getBoolean(parameters.get(), "returnByValue"_s , &opt_in_returnByValue_valueFound); |
5491 | bool opt_in_generatePreview_valueFound = false; |
5492 | bool opt_in_generatePreview = m_backendDispatcher->getBoolean(parameters.get(), "generatePreview"_s , &opt_in_generatePreview_valueFound); |
5493 | bool opt_in_saveResult_valueFound = false; |
5494 | bool opt_in_saveResult = m_backendDispatcher->getBoolean(parameters.get(), "saveResult"_s , &opt_in_saveResult_valueFound); |
5495 | bool opt_in_emulateUserGesture_valueFound = false; |
5496 | bool opt_in_emulateUserGesture = m_backendDispatcher->getBoolean(parameters.get(), "emulateUserGesture"_s , &opt_in_emulateUserGesture_valueFound); |
5497 | if (m_backendDispatcher->hasProtocolErrors()) { |
5498 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.evaluate' can't be processed"_s ); |
5499 | return; |
5500 | } |
5501 | |
5502 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5503 | if (m_alternateDispatcher) { |
5504 | m_alternateDispatcher->evaluate(requestId, in_expression, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, opt_in_includeCommandLineAPI_valueFound ? &opt_in_includeCommandLineAPI : nullptr, opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound ? &opt_in_doNotPauseOnExceptionsAndMuteConsole : nullptr, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, opt_in_saveResult_valueFound ? &opt_in_saveResult : nullptr, opt_in_emulateUserGesture_valueFound ? &opt_in_emulateUserGesture : nullptr); |
5505 | return; |
5506 | } |
5507 | #endif |
5508 | |
5509 | ErrorString error; |
5510 | Ref<JSON::Object> result = JSON::Object::create(); |
5511 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_result; |
5512 | Optional<bool> out_wasThrown; |
5513 | Optional<int> out_savedResultIndex; |
5514 | m_agent->evaluate(error, in_expression, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, opt_in_includeCommandLineAPI_valueFound ? &opt_in_includeCommandLineAPI : nullptr, opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound ? &opt_in_doNotPauseOnExceptionsAndMuteConsole : nullptr, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, opt_in_saveResult_valueFound ? &opt_in_saveResult : nullptr, opt_in_emulateUserGesture_valueFound ? &opt_in_emulateUserGesture : nullptr, out_result, out_wasThrown, out_savedResultIndex); |
5515 | |
5516 | if (!error.length()) { |
5517 | result->setObject("result"_s , out_result); |
5518 | if (out_wasThrown.hasValue()) |
5519 | result->setBoolean("wasThrown"_s , *out_wasThrown); |
5520 | if (out_savedResultIndex.hasValue()) |
5521 | result->setInteger("savedResultIndex"_s , *out_savedResultIndex); |
5522 | } |
5523 | if (!error.length()) |
5524 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5525 | else |
5526 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5527 | } |
5528 | |
5529 | RuntimeBackendDispatcherHandler::AwaitPromiseCallback::AwaitPromiseCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { } |
5530 | |
5531 | void RuntimeBackendDispatcherHandler::AwaitPromiseCallback::sendSuccess(RefPtr<Inspector::Protocol::Runtime::RemoteObject>&& result, Optional<bool>& wasThrown, Optional<int>& savedResultIndex) |
5532 | { |
5533 | Ref<JSON::Object> jsonMessage = JSON::Object::create(); |
5534 | jsonMessage->setObject("result"_s , result); |
5535 | if (wasThrown.hasValue()) |
5536 | jsonMessage->setBoolean("wasThrown"_s , *wasThrown); |
5537 | if (savedResultIndex.hasValue()) |
5538 | jsonMessage->setInteger("savedResultIndex"_s , *savedResultIndex); |
5539 | CallbackBase::sendSuccess(WTFMove(jsonMessage)); |
5540 | } |
5541 | |
5542 | void RuntimeBackendDispatcher::awaitPromise(long requestId, RefPtr<JSON::Object>&& parameters) |
5543 | { |
5544 | String in_promiseObjectId = m_backendDispatcher->getString(parameters.get(), "promiseObjectId"_s , nullptr); |
5545 | bool opt_in_returnByValue_valueFound = false; |
5546 | bool opt_in_returnByValue = m_backendDispatcher->getBoolean(parameters.get(), "returnByValue"_s , &opt_in_returnByValue_valueFound); |
5547 | bool opt_in_generatePreview_valueFound = false; |
5548 | bool opt_in_generatePreview = m_backendDispatcher->getBoolean(parameters.get(), "generatePreview"_s , &opt_in_generatePreview_valueFound); |
5549 | bool opt_in_saveResult_valueFound = false; |
5550 | bool opt_in_saveResult = m_backendDispatcher->getBoolean(parameters.get(), "saveResult"_s , &opt_in_saveResult_valueFound); |
5551 | if (m_backendDispatcher->hasProtocolErrors()) { |
5552 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.awaitPromise' can't be processed"_s ); |
5553 | return; |
5554 | } |
5555 | |
5556 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5557 | if (m_alternateDispatcher) { |
5558 | m_alternateDispatcher->awaitPromise(requestId, in_promiseObjectId, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, opt_in_saveResult_valueFound ? &opt_in_saveResult : nullptr); |
5559 | return; |
5560 | } |
5561 | #endif |
5562 | |
5563 | Ref<RuntimeBackendDispatcherHandler::AwaitPromiseCallback> callback = adoptRef(*new RuntimeBackendDispatcherHandler::AwaitPromiseCallback(m_backendDispatcher.copyRef(), requestId)); |
5564 | m_agent->awaitPromise(in_promiseObjectId, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, opt_in_saveResult_valueFound ? &opt_in_saveResult : nullptr, callback.copyRef()); |
5565 | |
5566 | } |
5567 | |
5568 | void RuntimeBackendDispatcher::callFunctionOn(long requestId, RefPtr<JSON::Object>&& parameters) |
5569 | { |
5570 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
5571 | String in_functionDeclaration = m_backendDispatcher->getString(parameters.get(), "functionDeclaration"_s , nullptr); |
5572 | bool opt_in_arguments_valueFound = false; |
5573 | RefPtr<JSON::Array> opt_in_arguments = m_backendDispatcher->getArray(parameters.get(), "arguments"_s , &opt_in_arguments_valueFound); |
5574 | bool opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound = false; |
5575 | bool opt_in_doNotPauseOnExceptionsAndMuteConsole = m_backendDispatcher->getBoolean(parameters.get(), "doNotPauseOnExceptionsAndMuteConsole"_s , &opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound); |
5576 | bool opt_in_returnByValue_valueFound = false; |
5577 | bool opt_in_returnByValue = m_backendDispatcher->getBoolean(parameters.get(), "returnByValue"_s , &opt_in_returnByValue_valueFound); |
5578 | bool opt_in_generatePreview_valueFound = false; |
5579 | bool opt_in_generatePreview = m_backendDispatcher->getBoolean(parameters.get(), "generatePreview"_s , &opt_in_generatePreview_valueFound); |
5580 | if (m_backendDispatcher->hasProtocolErrors()) { |
5581 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.callFunctionOn' can't be processed"_s ); |
5582 | return; |
5583 | } |
5584 | |
5585 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5586 | if (m_alternateDispatcher) { |
5587 | m_alternateDispatcher->callFunctionOn(requestId, in_objectId, in_functionDeclaration, opt_in_arguments_valueFound ? opt_in_arguments.get() : nullptr, opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound ? &opt_in_doNotPauseOnExceptionsAndMuteConsole : nullptr, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr); |
5588 | return; |
5589 | } |
5590 | #endif |
5591 | |
5592 | ErrorString error; |
5593 | Ref<JSON::Object> result = JSON::Object::create(); |
5594 | RefPtr<Inspector::Protocol::Runtime::RemoteObject> out_result; |
5595 | Optional<bool> out_wasThrown; |
5596 | m_agent->callFunctionOn(error, in_objectId, in_functionDeclaration, opt_in_arguments_valueFound ? opt_in_arguments.get() : nullptr, opt_in_doNotPauseOnExceptionsAndMuteConsole_valueFound ? &opt_in_doNotPauseOnExceptionsAndMuteConsole : nullptr, opt_in_returnByValue_valueFound ? &opt_in_returnByValue : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, out_result, out_wasThrown); |
5597 | |
5598 | if (!error.length()) { |
5599 | result->setObject("result"_s , out_result); |
5600 | if (out_wasThrown.hasValue()) |
5601 | result->setBoolean("wasThrown"_s , *out_wasThrown); |
5602 | } |
5603 | if (!error.length()) |
5604 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5605 | else |
5606 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5607 | } |
5608 | |
5609 | void RuntimeBackendDispatcher::getPreview(long requestId, RefPtr<JSON::Object>&& parameters) |
5610 | { |
5611 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
5612 | if (m_backendDispatcher->hasProtocolErrors()) { |
5613 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getPreview' can't be processed"_s ); |
5614 | return; |
5615 | } |
5616 | |
5617 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5618 | if (m_alternateDispatcher) { |
5619 | m_alternateDispatcher->getPreview(requestId, in_objectId); |
5620 | return; |
5621 | } |
5622 | #endif |
5623 | |
5624 | ErrorString error; |
5625 | Ref<JSON::Object> result = JSON::Object::create(); |
5626 | RefPtr<Inspector::Protocol::Runtime::ObjectPreview> out_preview; |
5627 | m_agent->getPreview(error, in_objectId, out_preview); |
5628 | |
5629 | if (!error.length()) |
5630 | result->setObject("preview"_s , out_preview); |
5631 | |
5632 | if (!error.length()) |
5633 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5634 | else |
5635 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5636 | } |
5637 | |
5638 | void RuntimeBackendDispatcher::getProperties(long requestId, RefPtr<JSON::Object>&& parameters) |
5639 | { |
5640 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
5641 | bool opt_in_ownProperties_valueFound = false; |
5642 | bool opt_in_ownProperties = m_backendDispatcher->getBoolean(parameters.get(), "ownProperties"_s , &opt_in_ownProperties_valueFound); |
5643 | bool opt_in_generatePreview_valueFound = false; |
5644 | bool opt_in_generatePreview = m_backendDispatcher->getBoolean(parameters.get(), "generatePreview"_s , &opt_in_generatePreview_valueFound); |
5645 | if (m_backendDispatcher->hasProtocolErrors()) { |
5646 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getProperties' can't be processed"_s ); |
5647 | return; |
5648 | } |
5649 | |
5650 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5651 | if (m_alternateDispatcher) { |
5652 | m_alternateDispatcher->getProperties(requestId, in_objectId, opt_in_ownProperties_valueFound ? &opt_in_ownProperties : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr); |
5653 | return; |
5654 | } |
5655 | #endif |
5656 | |
5657 | ErrorString error; |
5658 | Ref<JSON::Object> result = JSON::Object::create(); |
5659 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::PropertyDescriptor>> out_result; |
5660 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::InternalPropertyDescriptor>> out_internalProperties; |
5661 | m_agent->getProperties(error, in_objectId, opt_in_ownProperties_valueFound ? &opt_in_ownProperties : nullptr, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, out_result, out_internalProperties); |
5662 | |
5663 | if (!error.length()) { |
5664 | result->setArray("result"_s , out_result); |
5665 | if (out_internalProperties) |
5666 | result->setArray("internalProperties"_s , out_internalProperties); |
5667 | } |
5668 | if (!error.length()) |
5669 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5670 | else |
5671 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5672 | } |
5673 | |
5674 | void RuntimeBackendDispatcher::getDisplayableProperties(long requestId, RefPtr<JSON::Object>&& parameters) |
5675 | { |
5676 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
5677 | bool opt_in_generatePreview_valueFound = false; |
5678 | bool opt_in_generatePreview = m_backendDispatcher->getBoolean(parameters.get(), "generatePreview"_s , &opt_in_generatePreview_valueFound); |
5679 | if (m_backendDispatcher->hasProtocolErrors()) { |
5680 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getDisplayableProperties' can't be processed"_s ); |
5681 | return; |
5682 | } |
5683 | |
5684 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5685 | if (m_alternateDispatcher) { |
5686 | m_alternateDispatcher->getDisplayableProperties(requestId, in_objectId, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr); |
5687 | return; |
5688 | } |
5689 | #endif |
5690 | |
5691 | ErrorString error; |
5692 | Ref<JSON::Object> result = JSON::Object::create(); |
5693 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::PropertyDescriptor>> out_properties; |
5694 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::InternalPropertyDescriptor>> out_internalProperties; |
5695 | m_agent->getDisplayableProperties(error, in_objectId, opt_in_generatePreview_valueFound ? &opt_in_generatePreview : nullptr, out_properties, out_internalProperties); |
5696 | |
5697 | if (!error.length()) { |
5698 | result->setArray("properties"_s , out_properties); |
5699 | if (out_internalProperties) |
5700 | result->setArray("internalProperties"_s , out_internalProperties); |
5701 | } |
5702 | if (!error.length()) |
5703 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5704 | else |
5705 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5706 | } |
5707 | |
5708 | void RuntimeBackendDispatcher::getCollectionEntries(long requestId, RefPtr<JSON::Object>&& parameters) |
5709 | { |
5710 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
5711 | bool opt_in_objectGroup_valueFound = false; |
5712 | String opt_in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , &opt_in_objectGroup_valueFound); |
5713 | bool opt_in_startIndex_valueFound = false; |
5714 | int opt_in_startIndex = m_backendDispatcher->getInteger(parameters.get(), "startIndex"_s , &opt_in_startIndex_valueFound); |
5715 | bool opt_in_numberToFetch_valueFound = false; |
5716 | int opt_in_numberToFetch = m_backendDispatcher->getInteger(parameters.get(), "numberToFetch"_s , &opt_in_numberToFetch_valueFound); |
5717 | if (m_backendDispatcher->hasProtocolErrors()) { |
5718 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getCollectionEntries' can't be processed"_s ); |
5719 | return; |
5720 | } |
5721 | |
5722 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5723 | if (m_alternateDispatcher) { |
5724 | m_alternateDispatcher->getCollectionEntries(requestId, in_objectId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, opt_in_startIndex_valueFound ? &opt_in_startIndex : nullptr, opt_in_numberToFetch_valueFound ? &opt_in_numberToFetch : nullptr); |
5725 | return; |
5726 | } |
5727 | #endif |
5728 | |
5729 | ErrorString error; |
5730 | Ref<JSON::Object> result = JSON::Object::create(); |
5731 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::CollectionEntry>> out_entries; |
5732 | m_agent->getCollectionEntries(error, in_objectId, opt_in_objectGroup_valueFound ? &opt_in_objectGroup : nullptr, opt_in_startIndex_valueFound ? &opt_in_startIndex : nullptr, opt_in_numberToFetch_valueFound ? &opt_in_numberToFetch : nullptr, out_entries); |
5733 | |
5734 | if (!error.length()) |
5735 | result->setArray("entries"_s , out_entries); |
5736 | |
5737 | if (!error.length()) |
5738 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5739 | else |
5740 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5741 | } |
5742 | |
5743 | void RuntimeBackendDispatcher::saveResult(long requestId, RefPtr<JSON::Object>&& parameters) |
5744 | { |
5745 | RefPtr<JSON::Object> in_value = m_backendDispatcher->getObject(parameters.get(), "value"_s , nullptr); |
5746 | bool opt_in_contextId_valueFound = false; |
5747 | int opt_in_contextId = m_backendDispatcher->getInteger(parameters.get(), "contextId"_s , &opt_in_contextId_valueFound); |
5748 | if (m_backendDispatcher->hasProtocolErrors()) { |
5749 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.saveResult' can't be processed"_s ); |
5750 | return; |
5751 | } |
5752 | |
5753 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5754 | if (m_alternateDispatcher) { |
5755 | m_alternateDispatcher->saveResult(requestId, *in_value, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr); |
5756 | return; |
5757 | } |
5758 | #endif |
5759 | |
5760 | ErrorString error; |
5761 | Ref<JSON::Object> result = JSON::Object::create(); |
5762 | Optional<int> out_savedResultIndex; |
5763 | m_agent->saveResult(error, *in_value, opt_in_contextId_valueFound ? &opt_in_contextId : nullptr, out_savedResultIndex); |
5764 | |
5765 | if (!error.length()) |
5766 | if (out_savedResultIndex.hasValue()) |
5767 | result->setInteger("savedResultIndex"_s , *out_savedResultIndex); |
5768 | |
5769 | if (!error.length()) |
5770 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5771 | else |
5772 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5773 | } |
5774 | |
5775 | void RuntimeBackendDispatcher::releaseObject(long requestId, RefPtr<JSON::Object>&& parameters) |
5776 | { |
5777 | String in_objectId = m_backendDispatcher->getString(parameters.get(), "objectId"_s , nullptr); |
5778 | if (m_backendDispatcher->hasProtocolErrors()) { |
5779 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.releaseObject' can't be processed"_s ); |
5780 | return; |
5781 | } |
5782 | |
5783 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5784 | if (m_alternateDispatcher) { |
5785 | m_alternateDispatcher->releaseObject(requestId, in_objectId); |
5786 | return; |
5787 | } |
5788 | #endif |
5789 | |
5790 | ErrorString error; |
5791 | Ref<JSON::Object> result = JSON::Object::create(); |
5792 | m_agent->releaseObject(error, in_objectId); |
5793 | |
5794 | if (!error.length()) |
5795 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5796 | else |
5797 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5798 | } |
5799 | |
5800 | void RuntimeBackendDispatcher::releaseObjectGroup(long requestId, RefPtr<JSON::Object>&& parameters) |
5801 | { |
5802 | String in_objectGroup = m_backendDispatcher->getString(parameters.get(), "objectGroup"_s , nullptr); |
5803 | if (m_backendDispatcher->hasProtocolErrors()) { |
5804 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.releaseObjectGroup' can't be processed"_s ); |
5805 | return; |
5806 | } |
5807 | |
5808 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5809 | if (m_alternateDispatcher) { |
5810 | m_alternateDispatcher->releaseObjectGroup(requestId, in_objectGroup); |
5811 | return; |
5812 | } |
5813 | #endif |
5814 | |
5815 | ErrorString error; |
5816 | Ref<JSON::Object> result = JSON::Object::create(); |
5817 | m_agent->releaseObjectGroup(error, in_objectGroup); |
5818 | |
5819 | if (!error.length()) |
5820 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5821 | else |
5822 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5823 | } |
5824 | |
5825 | void RuntimeBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
5826 | { |
5827 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5828 | if (m_alternateDispatcher) { |
5829 | m_alternateDispatcher->enable(requestId); |
5830 | return; |
5831 | } |
5832 | #endif |
5833 | |
5834 | ErrorString error; |
5835 | Ref<JSON::Object> result = JSON::Object::create(); |
5836 | m_agent->enable(error); |
5837 | |
5838 | if (!error.length()) |
5839 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5840 | else |
5841 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5842 | } |
5843 | |
5844 | void RuntimeBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
5845 | { |
5846 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5847 | if (m_alternateDispatcher) { |
5848 | m_alternateDispatcher->disable(requestId); |
5849 | return; |
5850 | } |
5851 | #endif |
5852 | |
5853 | ErrorString error; |
5854 | Ref<JSON::Object> result = JSON::Object::create(); |
5855 | m_agent->disable(error); |
5856 | |
5857 | if (!error.length()) |
5858 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5859 | else |
5860 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5861 | } |
5862 | |
5863 | void RuntimeBackendDispatcher::getRuntimeTypesForVariablesAtOffsets(long requestId, RefPtr<JSON::Object>&& parameters) |
5864 | { |
5865 | RefPtr<JSON::Array> in_locations = m_backendDispatcher->getArray(parameters.get(), "locations"_s , nullptr); |
5866 | if (m_backendDispatcher->hasProtocolErrors()) { |
5867 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getRuntimeTypesForVariablesAtOffsets' can't be processed"_s ); |
5868 | return; |
5869 | } |
5870 | |
5871 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5872 | if (m_alternateDispatcher) { |
5873 | m_alternateDispatcher->getRuntimeTypesForVariablesAtOffsets(requestId, *in_locations); |
5874 | return; |
5875 | } |
5876 | #endif |
5877 | |
5878 | ErrorString error; |
5879 | Ref<JSON::Object> result = JSON::Object::create(); |
5880 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::TypeDescription>> out_types; |
5881 | m_agent->getRuntimeTypesForVariablesAtOffsets(error, *in_locations, out_types); |
5882 | |
5883 | if (!error.length()) |
5884 | result->setArray("types"_s , out_types); |
5885 | |
5886 | if (!error.length()) |
5887 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5888 | else |
5889 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5890 | } |
5891 | |
5892 | void RuntimeBackendDispatcher::enableTypeProfiler(long requestId, RefPtr<JSON::Object>&&) |
5893 | { |
5894 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5895 | if (m_alternateDispatcher) { |
5896 | m_alternateDispatcher->enableTypeProfiler(requestId); |
5897 | return; |
5898 | } |
5899 | #endif |
5900 | |
5901 | ErrorString error; |
5902 | Ref<JSON::Object> result = JSON::Object::create(); |
5903 | m_agent->enableTypeProfiler(error); |
5904 | |
5905 | if (!error.length()) |
5906 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5907 | else |
5908 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5909 | } |
5910 | |
5911 | void RuntimeBackendDispatcher::disableTypeProfiler(long requestId, RefPtr<JSON::Object>&&) |
5912 | { |
5913 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5914 | if (m_alternateDispatcher) { |
5915 | m_alternateDispatcher->disableTypeProfiler(requestId); |
5916 | return; |
5917 | } |
5918 | #endif |
5919 | |
5920 | ErrorString error; |
5921 | Ref<JSON::Object> result = JSON::Object::create(); |
5922 | m_agent->disableTypeProfiler(error); |
5923 | |
5924 | if (!error.length()) |
5925 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5926 | else |
5927 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5928 | } |
5929 | |
5930 | void RuntimeBackendDispatcher::enableControlFlowProfiler(long requestId, RefPtr<JSON::Object>&&) |
5931 | { |
5932 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5933 | if (m_alternateDispatcher) { |
5934 | m_alternateDispatcher->enableControlFlowProfiler(requestId); |
5935 | return; |
5936 | } |
5937 | #endif |
5938 | |
5939 | ErrorString error; |
5940 | Ref<JSON::Object> result = JSON::Object::create(); |
5941 | m_agent->enableControlFlowProfiler(error); |
5942 | |
5943 | if (!error.length()) |
5944 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5945 | else |
5946 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5947 | } |
5948 | |
5949 | void RuntimeBackendDispatcher::disableControlFlowProfiler(long requestId, RefPtr<JSON::Object>&&) |
5950 | { |
5951 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5952 | if (m_alternateDispatcher) { |
5953 | m_alternateDispatcher->disableControlFlowProfiler(requestId); |
5954 | return; |
5955 | } |
5956 | #endif |
5957 | |
5958 | ErrorString error; |
5959 | Ref<JSON::Object> result = JSON::Object::create(); |
5960 | m_agent->disableControlFlowProfiler(error); |
5961 | |
5962 | if (!error.length()) |
5963 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5964 | else |
5965 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5966 | } |
5967 | |
5968 | void RuntimeBackendDispatcher::getBasicBlocks(long requestId, RefPtr<JSON::Object>&& parameters) |
5969 | { |
5970 | String in_sourceID = m_backendDispatcher->getString(parameters.get(), "sourceID"_s , nullptr); |
5971 | if (m_backendDispatcher->hasProtocolErrors()) { |
5972 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getBasicBlocks' can't be processed"_s ); |
5973 | return; |
5974 | } |
5975 | |
5976 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
5977 | if (m_alternateDispatcher) { |
5978 | m_alternateDispatcher->getBasicBlocks(requestId, in_sourceID); |
5979 | return; |
5980 | } |
5981 | #endif |
5982 | |
5983 | ErrorString error; |
5984 | Ref<JSON::Object> result = JSON::Object::create(); |
5985 | RefPtr<JSON::ArrayOf<Inspector::Protocol::Runtime::BasicBlock>> out_basicBlocks; |
5986 | m_agent->getBasicBlocks(error, in_sourceID, out_basicBlocks); |
5987 | |
5988 | if (!error.length()) |
5989 | result->setArray("basicBlocks"_s , out_basicBlocks); |
5990 | |
5991 | if (!error.length()) |
5992 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
5993 | else |
5994 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
5995 | } |
5996 | |
5997 | Ref<ScriptProfilerBackendDispatcher> ScriptProfilerBackendDispatcher::create(BackendDispatcher& backendDispatcher, ScriptProfilerBackendDispatcherHandler* agent) |
5998 | { |
5999 | return adoptRef(*new ScriptProfilerBackendDispatcher(backendDispatcher, agent)); |
6000 | } |
6001 | |
6002 | ScriptProfilerBackendDispatcher::ScriptProfilerBackendDispatcher(BackendDispatcher& backendDispatcher, ScriptProfilerBackendDispatcherHandler* agent) |
6003 | : SupplementalBackendDispatcher(backendDispatcher) |
6004 | , m_agent(agent) |
6005 | { |
6006 | m_backendDispatcher->registerDispatcherForDomain("ScriptProfiler"_s , this); |
6007 | } |
6008 | |
6009 | void ScriptProfilerBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
6010 | { |
6011 | Ref<ScriptProfilerBackendDispatcher> protect(*this); |
6012 | |
6013 | RefPtr<JSON::Object> parameters; |
6014 | message->getObject("params"_s , parameters); |
6015 | |
6016 | if (method == "startTracking" ) |
6017 | startTracking(requestId, WTFMove(parameters)); |
6018 | else if (method == "stopTracking" ) |
6019 | stopTracking(requestId, WTFMove(parameters)); |
6020 | else |
6021 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'ScriptProfiler." + method + "' was not found" ); |
6022 | } |
6023 | |
6024 | void ScriptProfilerBackendDispatcher::startTracking(long requestId, RefPtr<JSON::Object>&& parameters) |
6025 | { |
6026 | bool opt_in_includeSamples_valueFound = false; |
6027 | bool opt_in_includeSamples = m_backendDispatcher->getBoolean(parameters.get(), "includeSamples"_s , &opt_in_includeSamples_valueFound); |
6028 | if (m_backendDispatcher->hasProtocolErrors()) { |
6029 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'ScriptProfiler.startTracking' can't be processed"_s ); |
6030 | return; |
6031 | } |
6032 | |
6033 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6034 | if (m_alternateDispatcher) { |
6035 | m_alternateDispatcher->startTracking(requestId, opt_in_includeSamples_valueFound ? &opt_in_includeSamples : nullptr); |
6036 | return; |
6037 | } |
6038 | #endif |
6039 | |
6040 | ErrorString error; |
6041 | Ref<JSON::Object> result = JSON::Object::create(); |
6042 | m_agent->startTracking(error, opt_in_includeSamples_valueFound ? &opt_in_includeSamples : nullptr); |
6043 | |
6044 | if (!error.length()) |
6045 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6046 | else |
6047 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6048 | } |
6049 | |
6050 | void ScriptProfilerBackendDispatcher::stopTracking(long requestId, RefPtr<JSON::Object>&&) |
6051 | { |
6052 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6053 | if (m_alternateDispatcher) { |
6054 | m_alternateDispatcher->stopTracking(requestId); |
6055 | return; |
6056 | } |
6057 | #endif |
6058 | |
6059 | ErrorString error; |
6060 | Ref<JSON::Object> result = JSON::Object::create(); |
6061 | m_agent->stopTracking(error); |
6062 | |
6063 | if (!error.length()) |
6064 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6065 | else |
6066 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6067 | } |
6068 | |
6069 | Ref<ServiceWorkerBackendDispatcher> ServiceWorkerBackendDispatcher::create(BackendDispatcher& backendDispatcher, ServiceWorkerBackendDispatcherHandler* agent) |
6070 | { |
6071 | return adoptRef(*new ServiceWorkerBackendDispatcher(backendDispatcher, agent)); |
6072 | } |
6073 | |
6074 | ServiceWorkerBackendDispatcher::ServiceWorkerBackendDispatcher(BackendDispatcher& backendDispatcher, ServiceWorkerBackendDispatcherHandler* agent) |
6075 | : SupplementalBackendDispatcher(backendDispatcher) |
6076 | , m_agent(agent) |
6077 | { |
6078 | m_backendDispatcher->registerDispatcherForDomain("ServiceWorker"_s , this); |
6079 | } |
6080 | |
6081 | void ServiceWorkerBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
6082 | { |
6083 | Ref<ServiceWorkerBackendDispatcher> protect(*this); |
6084 | |
6085 | RefPtr<JSON::Object> parameters; |
6086 | message->getObject("params"_s , parameters); |
6087 | |
6088 | if (method == "getInitializationInfo" ) |
6089 | getInitializationInfo(requestId, WTFMove(parameters)); |
6090 | else |
6091 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'ServiceWorker." + method + "' was not found" ); |
6092 | } |
6093 | |
6094 | void ServiceWorkerBackendDispatcher::getInitializationInfo(long requestId, RefPtr<JSON::Object>&&) |
6095 | { |
6096 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6097 | if (m_alternateDispatcher) { |
6098 | m_alternateDispatcher->getInitializationInfo(requestId); |
6099 | return; |
6100 | } |
6101 | #endif |
6102 | |
6103 | ErrorString error; |
6104 | Ref<JSON::Object> result = JSON::Object::create(); |
6105 | RefPtr<Inspector::Protocol::ServiceWorker::Configuration> out_info; |
6106 | m_agent->getInitializationInfo(error, out_info); |
6107 | |
6108 | if (!error.length()) |
6109 | result->setObject("info"_s , out_info); |
6110 | |
6111 | if (!error.length()) |
6112 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6113 | else |
6114 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6115 | } |
6116 | |
6117 | Ref<TargetBackendDispatcher> TargetBackendDispatcher::create(BackendDispatcher& backendDispatcher, TargetBackendDispatcherHandler* agent) |
6118 | { |
6119 | return adoptRef(*new TargetBackendDispatcher(backendDispatcher, agent)); |
6120 | } |
6121 | |
6122 | TargetBackendDispatcher::TargetBackendDispatcher(BackendDispatcher& backendDispatcher, TargetBackendDispatcherHandler* agent) |
6123 | : SupplementalBackendDispatcher(backendDispatcher) |
6124 | , m_agent(agent) |
6125 | { |
6126 | m_backendDispatcher->registerDispatcherForDomain("Target"_s , this); |
6127 | } |
6128 | |
6129 | void TargetBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
6130 | { |
6131 | Ref<TargetBackendDispatcher> protect(*this); |
6132 | |
6133 | RefPtr<JSON::Object> parameters; |
6134 | message->getObject("params"_s , parameters); |
6135 | |
6136 | if (method == "exists" ) |
6137 | exists(requestId, WTFMove(parameters)); |
6138 | else if (method == "sendMessageToTarget" ) |
6139 | sendMessageToTarget(requestId, WTFMove(parameters)); |
6140 | else |
6141 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Target." + method + "' was not found" ); |
6142 | } |
6143 | |
6144 | void TargetBackendDispatcher::exists(long requestId, RefPtr<JSON::Object>&&) |
6145 | { |
6146 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6147 | if (m_alternateDispatcher) { |
6148 | m_alternateDispatcher->exists(requestId); |
6149 | return; |
6150 | } |
6151 | #endif |
6152 | |
6153 | ErrorString error; |
6154 | Ref<JSON::Object> result = JSON::Object::create(); |
6155 | m_agent->exists(error); |
6156 | |
6157 | if (!error.length()) |
6158 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6159 | else |
6160 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6161 | } |
6162 | |
6163 | void TargetBackendDispatcher::sendMessageToTarget(long requestId, RefPtr<JSON::Object>&& parameters) |
6164 | { |
6165 | String in_targetId = m_backendDispatcher->getString(parameters.get(), "targetId"_s , nullptr); |
6166 | String in_message = m_backendDispatcher->getString(parameters.get(), "message"_s , nullptr); |
6167 | if (m_backendDispatcher->hasProtocolErrors()) { |
6168 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Target.sendMessageToTarget' can't be processed"_s ); |
6169 | return; |
6170 | } |
6171 | |
6172 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6173 | if (m_alternateDispatcher) { |
6174 | m_alternateDispatcher->sendMessageToTarget(requestId, in_targetId, in_message); |
6175 | return; |
6176 | } |
6177 | #endif |
6178 | |
6179 | ErrorString error; |
6180 | Ref<JSON::Object> result = JSON::Object::create(); |
6181 | m_agent->sendMessageToTarget(error, in_targetId, in_message); |
6182 | |
6183 | if (!error.length()) |
6184 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6185 | else |
6186 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6187 | } |
6188 | |
6189 | Ref<TimelineBackendDispatcher> TimelineBackendDispatcher::create(BackendDispatcher& backendDispatcher, TimelineBackendDispatcherHandler* agent) |
6190 | { |
6191 | return adoptRef(*new TimelineBackendDispatcher(backendDispatcher, agent)); |
6192 | } |
6193 | |
6194 | TimelineBackendDispatcher::TimelineBackendDispatcher(BackendDispatcher& backendDispatcher, TimelineBackendDispatcherHandler* agent) |
6195 | : SupplementalBackendDispatcher(backendDispatcher) |
6196 | , m_agent(agent) |
6197 | { |
6198 | m_backendDispatcher->registerDispatcherForDomain("Timeline"_s , this); |
6199 | } |
6200 | |
6201 | void TimelineBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
6202 | { |
6203 | Ref<TimelineBackendDispatcher> protect(*this); |
6204 | |
6205 | RefPtr<JSON::Object> parameters; |
6206 | message->getObject("params"_s , parameters); |
6207 | |
6208 | if (method == "start" ) |
6209 | start(requestId, WTFMove(parameters)); |
6210 | else if (method == "stop" ) |
6211 | stop(requestId, WTFMove(parameters)); |
6212 | else if (method == "setAutoCaptureEnabled" ) |
6213 | setAutoCaptureEnabled(requestId, WTFMove(parameters)); |
6214 | else if (method == "setInstruments" ) |
6215 | setInstruments(requestId, WTFMove(parameters)); |
6216 | else |
6217 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Timeline." + method + "' was not found" ); |
6218 | } |
6219 | |
6220 | void TimelineBackendDispatcher::start(long requestId, RefPtr<JSON::Object>&& parameters) |
6221 | { |
6222 | bool opt_in_maxCallStackDepth_valueFound = false; |
6223 | int opt_in_maxCallStackDepth = m_backendDispatcher->getInteger(parameters.get(), "maxCallStackDepth"_s , &opt_in_maxCallStackDepth_valueFound); |
6224 | if (m_backendDispatcher->hasProtocolErrors()) { |
6225 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Timeline.start' can't be processed"_s ); |
6226 | return; |
6227 | } |
6228 | |
6229 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6230 | if (m_alternateDispatcher) { |
6231 | m_alternateDispatcher->start(requestId, opt_in_maxCallStackDepth_valueFound ? &opt_in_maxCallStackDepth : nullptr); |
6232 | return; |
6233 | } |
6234 | #endif |
6235 | |
6236 | ErrorString error; |
6237 | Ref<JSON::Object> result = JSON::Object::create(); |
6238 | m_agent->start(error, opt_in_maxCallStackDepth_valueFound ? &opt_in_maxCallStackDepth : nullptr); |
6239 | |
6240 | if (!error.length()) |
6241 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6242 | else |
6243 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6244 | } |
6245 | |
6246 | void TimelineBackendDispatcher::stop(long requestId, RefPtr<JSON::Object>&&) |
6247 | { |
6248 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6249 | if (m_alternateDispatcher) { |
6250 | m_alternateDispatcher->stop(requestId); |
6251 | return; |
6252 | } |
6253 | #endif |
6254 | |
6255 | ErrorString error; |
6256 | Ref<JSON::Object> result = JSON::Object::create(); |
6257 | m_agent->stop(error); |
6258 | |
6259 | if (!error.length()) |
6260 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6261 | else |
6262 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6263 | } |
6264 | |
6265 | void TimelineBackendDispatcher::setAutoCaptureEnabled(long requestId, RefPtr<JSON::Object>&& parameters) |
6266 | { |
6267 | bool in_enabled = m_backendDispatcher->getBoolean(parameters.get(), "enabled"_s , nullptr); |
6268 | if (m_backendDispatcher->hasProtocolErrors()) { |
6269 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Timeline.setAutoCaptureEnabled' can't be processed"_s ); |
6270 | return; |
6271 | } |
6272 | |
6273 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6274 | if (m_alternateDispatcher) { |
6275 | m_alternateDispatcher->setAutoCaptureEnabled(requestId, in_enabled); |
6276 | return; |
6277 | } |
6278 | #endif |
6279 | |
6280 | ErrorString error; |
6281 | Ref<JSON::Object> result = JSON::Object::create(); |
6282 | m_agent->setAutoCaptureEnabled(error, in_enabled); |
6283 | |
6284 | if (!error.length()) |
6285 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6286 | else |
6287 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6288 | } |
6289 | |
6290 | void TimelineBackendDispatcher::setInstruments(long requestId, RefPtr<JSON::Object>&& parameters) |
6291 | { |
6292 | RefPtr<JSON::Array> in_instruments = m_backendDispatcher->getArray(parameters.get(), "instruments"_s , nullptr); |
6293 | if (m_backendDispatcher->hasProtocolErrors()) { |
6294 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Timeline.setInstruments' can't be processed"_s ); |
6295 | return; |
6296 | } |
6297 | |
6298 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6299 | if (m_alternateDispatcher) { |
6300 | m_alternateDispatcher->setInstruments(requestId, *in_instruments); |
6301 | return; |
6302 | } |
6303 | #endif |
6304 | |
6305 | ErrorString error; |
6306 | Ref<JSON::Object> result = JSON::Object::create(); |
6307 | m_agent->setInstruments(error, *in_instruments); |
6308 | |
6309 | if (!error.length()) |
6310 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6311 | else |
6312 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6313 | } |
6314 | |
6315 | Ref<WorkerBackendDispatcher> WorkerBackendDispatcher::create(BackendDispatcher& backendDispatcher, WorkerBackendDispatcherHandler* agent) |
6316 | { |
6317 | return adoptRef(*new WorkerBackendDispatcher(backendDispatcher, agent)); |
6318 | } |
6319 | |
6320 | WorkerBackendDispatcher::WorkerBackendDispatcher(BackendDispatcher& backendDispatcher, WorkerBackendDispatcherHandler* agent) |
6321 | : SupplementalBackendDispatcher(backendDispatcher) |
6322 | , m_agent(agent) |
6323 | { |
6324 | m_backendDispatcher->registerDispatcherForDomain("Worker"_s , this); |
6325 | } |
6326 | |
6327 | void WorkerBackendDispatcher::dispatch(long requestId, const String& method, Ref<JSON::Object>&& message) |
6328 | { |
6329 | Ref<WorkerBackendDispatcher> protect(*this); |
6330 | |
6331 | RefPtr<JSON::Object> parameters; |
6332 | message->getObject("params"_s , parameters); |
6333 | |
6334 | if (method == "enable" ) |
6335 | enable(requestId, WTFMove(parameters)); |
6336 | else if (method == "disable" ) |
6337 | disable(requestId, WTFMove(parameters)); |
6338 | else if (method == "initialized" ) |
6339 | initialized(requestId, WTFMove(parameters)); |
6340 | else if (method == "sendMessageToWorker" ) |
6341 | sendMessageToWorker(requestId, WTFMove(parameters)); |
6342 | else |
6343 | m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Worker." + method + "' was not found" ); |
6344 | } |
6345 | |
6346 | void WorkerBackendDispatcher::enable(long requestId, RefPtr<JSON::Object>&&) |
6347 | { |
6348 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6349 | if (m_alternateDispatcher) { |
6350 | m_alternateDispatcher->enable(requestId); |
6351 | return; |
6352 | } |
6353 | #endif |
6354 | |
6355 | ErrorString error; |
6356 | Ref<JSON::Object> result = JSON::Object::create(); |
6357 | m_agent->enable(error); |
6358 | |
6359 | if (!error.length()) |
6360 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6361 | else |
6362 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6363 | } |
6364 | |
6365 | void WorkerBackendDispatcher::disable(long requestId, RefPtr<JSON::Object>&&) |
6366 | { |
6367 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6368 | if (m_alternateDispatcher) { |
6369 | m_alternateDispatcher->disable(requestId); |
6370 | return; |
6371 | } |
6372 | #endif |
6373 | |
6374 | ErrorString error; |
6375 | Ref<JSON::Object> result = JSON::Object::create(); |
6376 | m_agent->disable(error); |
6377 | |
6378 | if (!error.length()) |
6379 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6380 | else |
6381 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6382 | } |
6383 | |
6384 | void WorkerBackendDispatcher::initialized(long requestId, RefPtr<JSON::Object>&& parameters) |
6385 | { |
6386 | String in_workerId = m_backendDispatcher->getString(parameters.get(), "workerId"_s , nullptr); |
6387 | if (m_backendDispatcher->hasProtocolErrors()) { |
6388 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Worker.initialized' can't be processed"_s ); |
6389 | return; |
6390 | } |
6391 | |
6392 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6393 | if (m_alternateDispatcher) { |
6394 | m_alternateDispatcher->initialized(requestId, in_workerId); |
6395 | return; |
6396 | } |
6397 | #endif |
6398 | |
6399 | ErrorString error; |
6400 | Ref<JSON::Object> result = JSON::Object::create(); |
6401 | m_agent->initialized(error, in_workerId); |
6402 | |
6403 | if (!error.length()) |
6404 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6405 | else |
6406 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6407 | } |
6408 | |
6409 | void WorkerBackendDispatcher::sendMessageToWorker(long requestId, RefPtr<JSON::Object>&& parameters) |
6410 | { |
6411 | String in_workerId = m_backendDispatcher->getString(parameters.get(), "workerId"_s , nullptr); |
6412 | String in_message = m_backendDispatcher->getString(parameters.get(), "message"_s , nullptr); |
6413 | if (m_backendDispatcher->hasProtocolErrors()) { |
6414 | m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Worker.sendMessageToWorker' can't be processed"_s ); |
6415 | return; |
6416 | } |
6417 | |
6418 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
6419 | if (m_alternateDispatcher) { |
6420 | m_alternateDispatcher->sendMessageToWorker(requestId, in_workerId, in_message); |
6421 | return; |
6422 | } |
6423 | #endif |
6424 | |
6425 | ErrorString error; |
6426 | Ref<JSON::Object> result = JSON::Object::create(); |
6427 | m_agent->sendMessageToWorker(error, in_workerId, in_message); |
6428 | |
6429 | if (!error.length()) |
6430 | m_backendDispatcher->sendResponse(requestId, WTFMove(result), false); |
6431 | else |
6432 | m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, WTFMove(error)); |
6433 | } |
6434 | |
6435 | } // namespace Inspector |
6436 | |