2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "InspectorInstrumentation.h"
36 #include "CSSStyleRule.h"
37 #include "DOMWindow.h"
38 #include "DOMWrapperWorld.h"
40 #include "DocumentLoader.h"
42 #include "EventDispatcher.h"
43 #include "InspectorApplicationCacheAgent.h"
44 #include "InspectorController.h"
45 #include "InspectorCSSAgent.h"
46 #include "InspectorCanvasAgent.h"
47 #include "InspectorDOMAgent.h"
48 #include "InspectorDOMDebuggerAgent.h"
49 #include "InspectorDOMStorageAgent.h"
50 #include "InspectorDatabaseAgent.h"
51 #include "InspectorLayerTreeAgent.h"
52 #include "InspectorPageAgent.h"
53 #include "InspectorResourceAgent.h"
54 #include "InspectorTimelineAgent.h"
55 #include "InspectorWorkerAgent.h"
56 #include "InstrumentingAgents.h"
57 #include "MainFrame.h"
58 #include "PageDebuggerAgent.h"
59 #include "PageRuntimeAgent.h"
60 #include "RenderObject.h"
61 #include "RenderView.h"
62 #include "ScriptController.h"
63 #include "StyleResolver.h"
64 #include "StyleRule.h"
65 #include "WebConsoleAgent.h"
66 #include "WebGLRenderingContextBase.h"
67 #include "WorkerGlobalScope.h"
68 #include "WorkerInspectorController.h"
69 #include "WorkerRuntimeAgent.h"
70 #include "WorkerThread.h"
71 #include "XMLHttpRequest.h"
72 #include <inspector/ConsoleMessage.h>
73 #include <inspector/ScriptArguments.h>
74 #include <inspector/ScriptCallStack.h>
75 #include <inspector/agents/InspectorDebuggerAgent.h>
76 #include <profiler/Profile.h>
77 #include <runtime/ConsoleTypes.h>
78 #include <wtf/StdLibExtras.h>
79 #include <wtf/text/CString.h>
81 #if ENABLE(WEB_REPLAY)
82 #include "InspectorReplayAgent.h"
83 #include "ReplayController.h" // for ReplayPosition.
86 using namespace Inspector;
90 static const char* const requestAnimationFrameEventName = "requestAnimationFrame";
91 static const char* const cancelAnimationFrameEventName = "cancelAnimationFrame";
92 static const char* const animationFrameFiredEventName = "animationFrameFired";
93 static const char* const setTimerEventName = "setTimer";
94 static const char* const clearTimerEventName = "clearTimer";
95 static const char* const timerFiredEventName = "timerFired";
98 static HashSet<InstrumentingAgents*>* s_instrumentingAgentsSet = nullptr;
101 int InspectorInstrumentation::s_frontendCounter = 0;
103 static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
105 Frame* frame = nullptr;
106 if (is<Document>(*context))
107 frame = downcast<Document>(*context).frame();
111 void InspectorInstrumentation::didClearWindowObjectInWorldImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, DOMWrapperWorld& world)
113 InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent();
115 pageAgent->didClearWindowObjectInWorld(&frame, world);
116 if (PageDebuggerAgent* debuggerAgent = instrumentingAgents.pageDebuggerAgent()) {
117 if (pageAgent && &world == &mainThreadNormalWorld() && &frame == pageAgent->mainFrame())
118 debuggerAgent->didClearMainFrameWindowObject();
120 if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents.pageRuntimeAgent()) {
121 if (&world == &mainThreadNormalWorld())
122 pageRuntimeAgent->didCreateMainWorldContext(frame);
126 bool InspectorInstrumentation::isDebuggerPausedImpl(InstrumentingAgents& instrumentingAgents)
128 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
129 return debuggerAgent->isPaused();
133 void InspectorInstrumentation::willInsertDOMNodeImpl(InstrumentingAgents& instrumentingAgents, Node& parent)
135 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
136 domDebuggerAgent->willInsertDOMNode(parent);
139 void InspectorInstrumentation::didInsertDOMNodeImpl(InstrumentingAgents& instrumentingAgents, Node& node)
141 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
142 domAgent->didInsertDOMNode(node);
143 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
144 domDebuggerAgent->didInsertDOMNode(node);
147 void InspectorInstrumentation::willRemoveDOMNodeImpl(InstrumentingAgents& instrumentingAgents, Node& node)
149 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
150 domDebuggerAgent->willRemoveDOMNode(node);
153 void InspectorInstrumentation::didRemoveDOMNodeImpl(InstrumentingAgents& instrumentingAgents, Node& node)
155 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
156 domDebuggerAgent->didRemoveDOMNode(node);
157 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
158 domAgent->didRemoveDOMNode(node);
161 void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents& instrumentingAgents, Element& element, const AtomicString& oldValue, const AtomicString& newValue)
163 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
164 domDebuggerAgent->willModifyDOMAttr(element);
165 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
166 domAgent->willModifyDOMAttr(element, oldValue, newValue);
169 void InspectorInstrumentation::didModifyDOMAttrImpl(InstrumentingAgents& instrumentingAgents, Element& element, const AtomicString& name, const AtomicString& value)
171 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
172 domAgent->didModifyDOMAttr(element, name, value);
175 void InspectorInstrumentation::didRemoveDOMAttrImpl(InstrumentingAgents& instrumentingAgents, Element& element, const AtomicString& name)
177 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
178 domAgent->didRemoveDOMAttr(element, name);
181 void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents& instrumentingAgents, Node& node)
183 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
184 domAgent->didInvalidateStyleAttr(node);
185 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
186 domDebuggerAgent->didInvalidateStyleAttr(node);
189 void InspectorInstrumentation::frameWindowDiscardedImpl(InstrumentingAgents& instrumentingAgents, DOMWindow* window)
191 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
192 consoleAgent->frameWindowDiscarded(window);
195 void InspectorInstrumentation::mediaQueryResultChangedImpl(InstrumentingAgents& instrumentingAgents)
197 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
198 cssAgent->mediaQueryResultChanged();
201 void InspectorInstrumentation::didPushShadowRootImpl(InstrumentingAgents& instrumentingAgents, Element& host, ShadowRoot& root)
203 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
204 domAgent->didPushShadowRoot(host, root);
207 void InspectorInstrumentation::willPopShadowRootImpl(InstrumentingAgents& instrumentingAgents, Element& host, ShadowRoot& root)
209 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
210 domAgent->willPopShadowRoot(host, root);
213 void InspectorInstrumentation::didCreateNamedFlowImpl(InstrumentingAgents& instrumentingAgents, Document* document, WebKitNamedFlow& namedFlow)
218 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
219 cssAgent->didCreateNamedFlow(*document, namedFlow);
222 void InspectorInstrumentation::willRemoveNamedFlowImpl(InstrumentingAgents& instrumentingAgents, Document* document, WebKitNamedFlow& namedFlow)
227 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
228 cssAgent->willRemoveNamedFlow(*document, namedFlow);
231 void InspectorInstrumentation::didChangeRegionOversetImpl(InstrumentingAgents& instrumentingAgents, Document& document, WebKitNamedFlow& namedFlow)
233 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
234 cssAgent->didChangeRegionOverset(document, namedFlow);
237 void InspectorInstrumentation::didRegisterNamedFlowContentElementImpl(InstrumentingAgents& instrumentingAgents, Document& document, WebKitNamedFlow& namedFlow, Node& contentElement, Node* nextContentElement)
239 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
240 cssAgent->didRegisterNamedFlowContentElement(document, namedFlow, contentElement, nextContentElement);
243 void InspectorInstrumentation::didUnregisterNamedFlowContentElementImpl(InstrumentingAgents& instrumentingAgents, Document& document, WebKitNamedFlow& namedFlow, Node& contentElement)
245 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
246 cssAgent->didUnregisterNamedFlowContentElement(document, namedFlow, contentElement);
249 void InspectorInstrumentation::mouseDidMoveOverElementImpl(InstrumentingAgents& instrumentingAgents, const HitTestResult& result, unsigned modifierFlags)
251 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
252 domAgent->mouseDidMoveOverElement(result, modifierFlags);
255 void InspectorInstrumentation::didScrollImpl(InstrumentingAgents& instrumentingAgents)
257 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
258 pageAgent->didScroll();
261 bool InspectorInstrumentation::handleTouchEventImpl(InstrumentingAgents& instrumentingAgents, Node& node)
263 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
264 return domAgent->handleTouchEvent(node);
268 bool InspectorInstrumentation::handleMousePressImpl(InstrumentingAgents& instrumentingAgents)
270 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
271 return domAgent->handleMousePress();
275 bool InspectorInstrumentation::forcePseudoStateImpl(InstrumentingAgents& instrumentingAgents, Element& element, CSSSelector::PseudoClassType pseudoState)
277 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
278 return cssAgent->forcePseudoState(element, pseudoState);
282 void InspectorInstrumentation::characterDataModifiedImpl(InstrumentingAgents& instrumentingAgents, CharacterData& characterData)
284 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
285 domAgent->characterDataModified(characterData);
288 void InspectorInstrumentation::willSendXMLHttpRequestImpl(InstrumentingAgents& instrumentingAgents, const String& url)
290 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
291 domDebuggerAgent->willSendXMLHttpRequest(url);
294 void InspectorInstrumentation::didInstallTimerImpl(InstrumentingAgents& instrumentingAgents, int timerId, int timeout, bool singleShot, ScriptExecutionContext* context)
296 pauseOnNativeEventIfNeeded(instrumentingAgents, false, setTimerEventName, true);
297 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
298 timelineAgent->didInstallTimer(timerId, timeout, singleShot, frameForScriptExecutionContext(context));
301 void InspectorInstrumentation::didRemoveTimerImpl(InstrumentingAgents& instrumentingAgents, int timerId, ScriptExecutionContext* context)
303 pauseOnNativeEventIfNeeded(instrumentingAgents, false, clearTimerEventName, true);
304 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
305 timelineAgent->didRemoveTimer(timerId, frameForScriptExecutionContext(context));
308 InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents& instrumentingAgents, const String& scriptName, int scriptLine, ScriptExecutionContext* context)
310 int timelineAgentId = 0;
311 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
312 timelineAgent->willCallFunction(scriptName, scriptLine, frameForScriptExecutionContext(context));
313 timelineAgentId = timelineAgent->id();
315 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
318 void InspectorInstrumentation::didCallFunctionImpl(const InspectorInstrumentationCookie& cookie, ScriptExecutionContext* context)
320 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
321 timelineAgent->didCallFunction(frameForScriptExecutionContext(context));
324 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRReadyStateChangeEventImpl(InstrumentingAgents& instrumentingAgents, XMLHttpRequest& request, ScriptExecutionContext* context)
326 int timelineAgentId = 0;
327 InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent();
328 if (timelineAgent && request.hasEventListeners(eventNames().readystatechangeEvent)) {
329 timelineAgent->willDispatchXHRReadyStateChangeEvent(request.url().string(), request.readyState(), frameForScriptExecutionContext(context));
330 timelineAgentId = timelineAgent->id();
332 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
335 void InspectorInstrumentation::didDispatchXHRReadyStateChangeEventImpl(const InspectorInstrumentationCookie& cookie)
337 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
338 timelineAgent->didDispatchXHRReadyStateChangeEvent();
341 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InstrumentingAgents& instrumentingAgents, Document& document, const Event& event, bool hasEventListeners)
343 int timelineAgentId = 0;
344 InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent();
345 if (timelineAgent && hasEventListeners) {
346 timelineAgent->willDispatchEvent(event, document.frame());
347 timelineAgentId = timelineAgent->id();
349 #if ENABLE(WEB_REPLAY)
350 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
351 replayAgent->willDispatchEvent(event, document.frame());
353 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
356 InspectorInstrumentationCookie InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents& instrumentingAgents, const Event& event)
358 pauseOnNativeEventIfNeeded(instrumentingAgents, true, event.type(), false);
359 return InspectorInstrumentationCookie(instrumentingAgents, 0);
362 void InspectorInstrumentation::didHandleEventImpl(const InspectorInstrumentationCookie& cookie)
364 if (cookie.isValid())
365 cancelPauseOnNativeEvent(*cookie.instrumentingAgents());
368 void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)
370 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
371 timelineAgent->didDispatchEvent();
374 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InstrumentingAgents& instrumentingAgents, const Event& event, DOMWindow& window)
376 int timelineAgentId = 0;
377 InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent();
378 if (timelineAgent && window.hasEventListeners(event.type())) {
379 timelineAgent->willDispatchEvent(event, window.frame());
380 timelineAgentId = timelineAgent->id();
382 #if ENABLE(WEB_REPLAY)
383 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
384 replayAgent->willDispatchEvent(event, window.frame());
386 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
389 void InspectorInstrumentation::didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie& cookie)
391 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
392 timelineAgent->didDispatchEvent();
395 InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, const String& url, int lineNumber)
397 int timelineAgentId = 0;
398 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
399 timelineAgent->willEvaluateScript(url, lineNumber, frame);
400 timelineAgentId = timelineAgent->id();
402 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
405 void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentationCookie& cookie, Frame& frame)
407 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
408 timelineAgent->didEvaluateScript(frame);
411 void InspectorInstrumentation::scriptsEnabledImpl(InstrumentingAgents& instrumentingAgents, bool isEnabled)
413 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
414 pageAgent->scriptsEnabled(isEnabled);
417 InspectorInstrumentationCookie InspectorInstrumentation::willFireTimerImpl(InstrumentingAgents& instrumentingAgents, int timerId, ScriptExecutionContext* context)
419 pauseOnNativeEventIfNeeded(instrumentingAgents, false, timerFiredEventName, false);
421 int timelineAgentId = 0;
422 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
423 timelineAgent->willFireTimer(timerId, frameForScriptExecutionContext(context));
424 timelineAgentId = timelineAgent->id();
426 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
429 void InspectorInstrumentation::didFireTimerImpl(const InspectorInstrumentationCookie& cookie)
431 if (cookie.isValid())
432 cancelPauseOnNativeEvent(*cookie.instrumentingAgents());
434 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
435 timelineAgent->didFireTimer();
438 void InspectorInstrumentation::didInvalidateLayoutImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
440 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
441 timelineAgent->didInvalidateLayout(frame);
444 InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
446 int timelineAgentId = 0;
447 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
448 timelineAgent->willLayout(frame);
449 timelineAgentId = timelineAgent->id();
451 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
454 void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie, RenderObject* root)
456 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
457 timelineAgent->didLayout(root);
459 if (InspectorPageAgent* pageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
460 pageAgent->didLayout();
463 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRLoadEventImpl(InstrumentingAgents& instrumentingAgents, XMLHttpRequest& request, ScriptExecutionContext* context)
465 int timelineAgentId = 0;
466 InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent();
467 if (timelineAgent && request.hasEventListeners(eventNames().loadEvent)) {
468 timelineAgent->willDispatchXHRLoadEvent(request.url(), frameForScriptExecutionContext(context));
469 timelineAgentId = timelineAgent->id();
471 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
474 void InspectorInstrumentation::didDispatchXHRLoadEventImpl(const InspectorInstrumentationCookie& cookie)
476 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
477 timelineAgent->didDispatchXHRLoadEvent();
480 void InspectorInstrumentation::willPaintImpl(InstrumentingAgents& instrumentingAgents, RenderObject* renderer)
482 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
483 timelineAgent->willPaint(renderer->frame());
486 void InspectorInstrumentation::didPaintImpl(InstrumentingAgents& instrumentingAgents, RenderObject* renderer, const LayoutRect& rect)
488 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
489 timelineAgent->didPaint(renderer, rect);
491 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
492 pageAgent->didPaint(renderer, rect);
495 void InspectorInstrumentation::willScrollLayerImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
497 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
498 timelineAgent->willScroll(frame);
501 void InspectorInstrumentation::didScrollLayerImpl(InstrumentingAgents& instrumentingAgents)
503 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
504 timelineAgent->didScroll();
507 InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InstrumentingAgents& instrumentingAgents, Document& document)
509 int timelineAgentId = 0;
510 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
511 timelineAgent->willRecalculateStyle(document.frame());
512 timelineAgentId = timelineAgent->id();
514 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
515 resourceAgent->willRecalculateStyle();
516 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
519 void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrumentationCookie& cookie)
521 if (!cookie.isValid())
524 InstrumentingAgents& instrumentingAgents = *cookie.instrumentingAgents();
526 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
527 timelineAgent->didRecalculateStyle();
528 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
529 resourceAgent->didRecalculateStyle();
530 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
531 pageAgent->didRecalculateStyle();
534 void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents& instrumentingAgents, Document& document)
536 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
537 timelineAgent->didScheduleStyleRecalculation(document.frame());
538 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
539 resourceAgent->didScheduleStyleRecalculation(document);
542 void InspectorInstrumentation::applyEmulatedMediaImpl(InstrumentingAgents& instrumentingAgents, String& media)
544 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
545 pageAgent->applyEmulatedMedia(media);
548 void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
553 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
554 resourceAgent->willSendRequest(identifier, *loader, request, redirectResponse);
557 void InspectorInstrumentation::continueAfterPingLoaderImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& response)
559 willSendRequestImpl(instrumentingAgents, identifier, loader, request, response);
562 void InspectorInstrumentation::markResourceAsCachedImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier)
564 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
565 resourceAgent->markResourceAsCached(identifier);
568 void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents& instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
570 if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
573 if (!loader || !cachedResource)
576 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
577 resourceAgent->didLoadResourceFromMemoryCache(*loader, *cachedResource);
580 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceResponseImpl(InstrumentingAgents& instrumentingAgents)
582 return InspectorInstrumentationCookie(instrumentingAgents, 0);
585 void InspectorInstrumentation::didReceiveResourceResponseImpl(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
587 if (!cookie.isValid())
593 InstrumentingAgents& instrumentingAgents = *cookie.instrumentingAgents();
595 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
596 resourceAgent->didReceiveResponse(identifier, *loader, response, resourceLoader);
597 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
598 consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
601 void InspectorInstrumentation::didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader& loader, unsigned long identifier, const ResourceResponse& r)
606 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(frame);
607 InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, &loader, r, nullptr);
610 void InspectorInstrumentation::continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader& loader, unsigned long identifier, const ResourceResponse& r)
612 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
615 void InspectorInstrumentation::continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader& loader, unsigned long identifier, const ResourceResponse& r)
617 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
620 void InspectorInstrumentation::continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader& loader, unsigned long identifier, const ResourceResponse& r)
622 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
625 void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
627 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
628 resourceAgent->didReceiveData(identifier, data, dataLength, encodedDataLength);
631 void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, double finishTime)
636 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
637 resourceAgent->didFinishLoading(identifier, *loader, finishTime);
640 void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
645 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
646 resourceAgent->didFailLoading(identifier, *loader, error);
647 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
648 consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
651 void InspectorInstrumentation::didFinishXHRLoadingImpl(InstrumentingAgents& instrumentingAgents, ThreadableLoaderClient* client, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber, unsigned sendColumnNumber)
653 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
654 consoleAgent->didFinishXHRLoading(identifier, url, sendURL, sendLineNumber, sendColumnNumber);
655 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
656 resourceAgent->didFinishXHRLoading(client, identifier, sourceString);
659 void InspectorInstrumentation::didReceiveXHRResponseImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier)
661 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
662 resourceAgent->didReceiveXHRResponse(identifier);
665 void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents& instrumentingAgents)
667 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
668 resourceAgent->willLoadXHRSynchronously();
671 void InspectorInstrumentation::didLoadXHRSynchronouslyImpl(InstrumentingAgents& instrumentingAgents)
673 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
674 resourceAgent->didLoadXHRSynchronously();
677 void InspectorInstrumentation::scriptImportedImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const String& sourceString)
679 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
680 resourceAgent->setInitialScriptContent(identifier, sourceString);
683 void InspectorInstrumentation::scriptExecutionBlockedByCSPImpl(InstrumentingAgents& instrumentingAgents, const String& directiveText)
685 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
686 debuggerAgent->scriptExecutionBlockedByCSP(directiveText);
689 void InspectorInstrumentation::didReceiveScriptResponseImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier)
691 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
692 resourceAgent->didReceiveScriptResponse(identifier);
695 void InspectorInstrumentation::domContentLoadedEventFiredImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
697 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
698 timelineAgent->didMarkDOMContentEvent(frame);
700 if (!frame.isMainFrame())
703 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
704 domAgent->mainFrameDOMContentLoaded();
706 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
707 pageAgent->domContentEventFired();
710 void InspectorInstrumentation::loadEventFiredImpl(InstrumentingAgents& instrumentingAgents, Frame* frame)
715 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
716 timelineAgent->didMarkLoadEvent(*frame);
718 if (!frame->isMainFrame())
721 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
722 pageAgent->loadEventFired();
725 void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
727 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
728 pageAgent->frameDetached(frame);
730 #if ENABLE(WEB_REPLAY)
731 if (!frame.isMainFrame())
734 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
735 replayAgent->frameDetached(frame);
739 void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents& instrumentingAgents, Page* page, DocumentLoader* loader)
741 if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
744 if (!page || !loader || !loader->frame())
747 if (loader->frame()->isMainFrame()) {
748 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
749 consoleAgent->reset();
751 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
752 resourceAgent->mainFrameNavigated(*loader);
754 if (InspectorCSSAgent* cssAgent = instrumentingAgents.inspectorCSSAgent())
757 if (InspectorDatabaseAgent* databaseAgent = instrumentingAgents.inspectorDatabaseAgent())
758 databaseAgent->clearResources();
760 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
761 domAgent->setDocument(page->mainFrame().document());
763 if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents.inspectorLayerTreeAgent())
764 layerTreeAgent->reset();
767 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
768 canvasAgent->frameNavigated(loader);
770 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
771 domAgent->didCommitLoad(loader->frame()->document());
773 if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
774 pageAgent->frameNavigated(loader);
776 #if ENABLE(WEB_REPLAY)
777 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
778 replayAgent->frameNavigated(loader);
782 void InspectorInstrumentation::frameDocumentUpdatedImpl(InstrumentingAgents& instrumentingAgents, Frame* frame)
784 if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
786 if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
787 domAgent->frameDocumentUpdated(frame);
790 void InspectorInstrumentation::loaderDetachedFromFrameImpl(InstrumentingAgents& instrumentingAgents, DocumentLoader& loader)
792 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())
793 inspectorPageAgent->loaderDetachedFromFrame(loader);
796 void InspectorInstrumentation::frameStartedLoadingImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
798 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())
799 inspectorPageAgent->frameStartedLoading(frame);
802 void InspectorInstrumentation::frameStoppedLoadingImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
804 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())
805 inspectorPageAgent->frameStoppedLoading(frame);
808 void InspectorInstrumentation::frameScheduledNavigationImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, double delay)
810 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())
811 inspectorPageAgent->frameScheduledNavigation(frame, delay);
814 void InspectorInstrumentation::frameClearedScheduledNavigationImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
816 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())
817 inspectorPageAgent->frameClearedScheduledNavigation(frame);
820 InspectorInstrumentationCookie InspectorInstrumentation::willRunJavaScriptDialogImpl(InstrumentingAgents& instrumentingAgents, const String& message)
822 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())
823 inspectorPageAgent->willRunJavaScriptDialog(message);
824 return InspectorInstrumentationCookie(instrumentingAgents, 0);
827 void InspectorInstrumentation::didRunJavaScriptDialogImpl(const InspectorInstrumentationCookie& cookie)
829 if (InspectorPageAgent* inspectorPageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
830 inspectorPageAgent->didRunJavaScriptDialog();
833 void InspectorInstrumentation::willDestroyCachedResourceImpl(CachedResource& cachedResource)
835 if (!s_instrumentingAgentsSet)
838 for (auto* instrumentingAgent : *s_instrumentingAgentsSet) {
839 if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgent->inspectorResourceAgent())
840 inspectorResourceAgent->willDestroyCachedResource(cachedResource);
844 InspectorInstrumentationCookie InspectorInstrumentation::willWriteHTMLImpl(InstrumentingAgents& instrumentingAgents, unsigned startLine, Frame* frame)
846 int timelineAgentId = 0;
847 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
848 timelineAgent->willWriteHTML(startLine, frame);
849 timelineAgentId = timelineAgent->id();
851 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
854 void InspectorInstrumentation::didWriteHTMLImpl(const InspectorInstrumentationCookie& cookie, unsigned endLine)
856 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
857 timelineAgent->didWriteHTML(endLine);
860 // JavaScriptCore InspectorDebuggerAgent should know Console MessageTypes.
861 static bool isConsoleAssertMessage(MessageSource source, MessageType type)
863 return source == MessageSource::ConsoleAPI && type == MessageType::Assert;
866 void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents& instrumentingAgents, std::unique_ptr<ConsoleMessage> message)
868 MessageSource source = message->source();
869 MessageType type = message->type();
870 String messageText = message->message();
872 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
873 consoleAgent->addMessageToConsole(WTF::move(message));
874 // FIXME: This should just pass the message on to the debugger agent. JavaScriptCore InspectorDebuggerAgent should know Console MessageTypes.
875 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent()) {
876 if (isConsoleAssertMessage(source, type))
877 debuggerAgent->handleConsoleAssert(messageText);
881 void InspectorInstrumentation::consoleCountImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* state, RefPtr<ScriptArguments>&& arguments)
883 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
884 consoleAgent->count(state, arguments);
887 void InspectorInstrumentation::startConsoleTimingImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, const String& title)
889 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
890 timelineAgent->time(frame, title);
891 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
892 consoleAgent->startTiming(title);
895 void InspectorInstrumentation::stopConsoleTimingImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, const String& title, RefPtr<ScriptCallStack>&& stack)
897 if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
898 consoleAgent->stopTiming(title, stack);
899 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
900 timelineAgent->timeEnd(frame, title);
903 void InspectorInstrumentation::consoleTimeStampImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, RefPtr<ScriptArguments>&& arguments)
905 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
907 arguments->getFirstArgumentAsString(message);
908 timelineAgent->didTimeStamp(frame, message);
912 void InspectorInstrumentation::startProfilingImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* exec, const String& title)
914 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.persistentInspectorTimelineAgent())
915 timelineAgent->startFromConsole(exec, title);
918 RefPtr<JSC::Profile> InspectorInstrumentation::stopProfilingImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* exec, const String& title)
920 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.persistentInspectorTimelineAgent())
921 return timelineAgent->stopFromConsole(exec, title);
925 void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents& instrumentingAgents, RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
927 if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
929 if (InspectorDatabaseAgent* dbAgent = instrumentingAgents.inspectorDatabaseAgent())
930 dbAgent->didOpenDatabase(database, domain, name, version);
933 void InspectorInstrumentation::didDispatchDOMStorageEventImpl(InstrumentingAgents& instrumentingAgents, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Page* page)
935 if (InspectorDOMStorageAgent* domStorageAgent = instrumentingAgents.inspectorDOMStorageAgent())
936 domStorageAgent->didDispatchDOMStorageEvent(key, oldValue, newValue, storageType, securityOrigin, page);
939 bool InspectorInstrumentation::shouldPauseDedicatedWorkerOnStartImpl(InstrumentingAgents& instrumentingAgents)
941 if (InspectorWorkerAgent* workerAgent = instrumentingAgents.inspectorWorkerAgent())
942 return workerAgent->shouldPauseDedicatedWorkerOnStart();
946 void InspectorInstrumentation::didStartWorkerGlobalScopeImpl(InstrumentingAgents& instrumentingAgents, WorkerGlobalScopeProxy* workerGlobalScopeProxy, const URL& url)
948 if (InspectorWorkerAgent* workerAgent = instrumentingAgents.inspectorWorkerAgent())
949 workerAgent->didStartWorkerGlobalScope(workerGlobalScopeProxy, url);
952 void InspectorInstrumentation::willEvaluateWorkerScript(WorkerGlobalScope* workerGlobalScope, int workerThreadStartMode)
954 if (workerThreadStartMode != PauseWorkerGlobalScopeOnStart)
957 InstrumentingAgents* instrumentingAgents = instrumentingAgentsForWorkerGlobalScope(workerGlobalScope);
958 if (!instrumentingAgents)
961 if (WorkerRuntimeAgent* runtimeAgent = instrumentingAgents->workerRuntimeAgent())
962 runtimeAgent->pauseWorkerGlobalScope(workerGlobalScope);
965 void InspectorInstrumentation::workerGlobalScopeTerminatedImpl(InstrumentingAgents& instrumentingAgents, WorkerGlobalScopeProxy* proxy)
967 if (InspectorWorkerAgent* workerAgent = instrumentingAgents.inspectorWorkerAgent())
968 workerAgent->workerGlobalScopeTerminated(proxy);
971 #if ENABLE(WEB_SOCKETS)
972 void InspectorInstrumentation::didCreateWebSocketImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const URL& requestURL, const URL&, const String& protocol, Document* document)
974 if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
980 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
981 resourceAgent->didCreateWebSocket(identifier, requestURL);
982 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
983 timelineAgent->didCreateWebSocket(identifier, requestURL, protocol, document->frame());
986 void InspectorInstrumentation::willSendWebSocketHandshakeRequestImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const ResourceRequest& request, Document* document)
991 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
992 resourceAgent->willSendWebSocketHandshakeRequest(identifier, request);
993 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
994 timelineAgent->willSendWebSocketHandshakeRequest(identifier, document->frame());
997 void InspectorInstrumentation::didReceiveWebSocketHandshakeResponseImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Document* document)
1002 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
1003 resourceAgent->didReceiveWebSocketHandshakeResponse(identifier, response);
1004 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
1005 timelineAgent->didReceiveWebSocketHandshakeResponse(identifier, document->frame());
1008 void InspectorInstrumentation::didCloseWebSocketImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, Document* document)
1013 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
1014 resourceAgent->didCloseWebSocket(identifier);
1015 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
1016 timelineAgent->didDestroyWebSocket(identifier, document->frame());
1019 void InspectorInstrumentation::didReceiveWebSocketFrameImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
1021 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
1022 resourceAgent->didReceiveWebSocketFrame(identifier, frame);
1024 void InspectorInstrumentation::didReceiveWebSocketFrameErrorImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const String& errorMessage)
1026 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
1027 resourceAgent->didReceiveWebSocketFrameError(identifier, errorMessage);
1029 void InspectorInstrumentation::didSendWebSocketFrameImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
1031 if (InspectorResourceAgent* resourceAgent = instrumentingAgents.inspectorResourceAgent())
1032 resourceAgent->didSendWebSocketFrame(identifier, frame);
1036 void InspectorInstrumentation::didCreateCSSCanvasImpl(InstrumentingAgents* instrumentingAgents, HTMLCanvasElement& canvasElement, const String& name)
1038 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
1039 canvasAgent->didCreateCSSCanvas(canvasElement, name);
1042 void InspectorInstrumentation::didCreateCanvasRenderingContextImpl(InstrumentingAgents* instrumentingAgents, HTMLCanvasElement& canvasElement)
1044 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
1045 canvasAgent->didCreateCanvasRenderingContext(canvasElement);
1049 void InspectorInstrumentation::didAttachShaderImpl(InstrumentingAgents* instrumentingAgents, WebGLRenderingContextBase& context, WebGLProgram& program, WebGLShader& shader)
1051 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
1052 canvasAgent->didAttachShader(context, program, shader);
1055 void InspectorInstrumentation::didDetachShaderImpl(InstrumentingAgents* instrumentingAgents, WebGLRenderingContextBase& context, WebGLProgram& program, WebGLShader& shader)
1057 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
1058 canvasAgent->didDetachShader(context, program, shader);
1061 void InspectorInstrumentation::didCreateProgramImpl(InstrumentingAgents* instrumentingAgents, WebGLRenderingContextBase& context, WebGLProgram& program)
1063 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
1064 canvasAgent->didCreateProgram(context, program);
1067 void InspectorInstrumentation::didDeleteProgramImpl(InstrumentingAgents* instrumentingAgents, WebGLRenderingContextBase& context, WebGLProgram& program)
1069 if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
1070 canvasAgent->didDeleteProgram(context, program);
1074 #if ENABLE(WEB_REPLAY)
1075 void InspectorInstrumentation::sessionCreatedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySession>&& session)
1077 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1078 replayAgent->sessionCreated(WTF::move(session));
1081 void InspectorInstrumentation::sessionLoadedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySession>&& session)
1083 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1084 replayAgent->sessionLoaded(WTF::move(session));
1087 void InspectorInstrumentation::sessionModifiedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySession>&& session)
1089 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1090 replayAgent->sessionModified(WTF::move(session));
1093 void InspectorInstrumentation::segmentCreatedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySessionSegment>&& segment)
1095 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1096 replayAgent->segmentCreated(WTF::move(segment));
1099 void InspectorInstrumentation::segmentCompletedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySessionSegment>&& segment)
1101 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1102 replayAgent->segmentCompleted(WTF::move(segment));
1105 void InspectorInstrumentation::segmentLoadedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySessionSegment>&& segment)
1107 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1108 replayAgent->segmentLoaded(WTF::move(segment));
1111 void InspectorInstrumentation::segmentUnloadedImpl(InstrumentingAgents& instrumentingAgents)
1113 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1114 replayAgent->segmentUnloaded();
1117 void InspectorInstrumentation::captureStartedImpl(InstrumentingAgents& instrumentingAgents)
1119 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1120 replayAgent->captureStarted();
1123 void InspectorInstrumentation::captureStoppedImpl(InstrumentingAgents& instrumentingAgents)
1125 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1126 replayAgent->captureStopped();
1129 void InspectorInstrumentation::playbackStartedImpl(InstrumentingAgents& instrumentingAgents)
1131 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1132 replayAgent->playbackStarted();
1135 void InspectorInstrumentation::playbackPausedImpl(InstrumentingAgents& instrumentingAgents, const ReplayPosition& position)
1137 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1138 replayAgent->playbackPaused(position);
1141 void InspectorInstrumentation::playbackHitPositionImpl(InstrumentingAgents& instrumentingAgents, const ReplayPosition& position)
1143 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1144 replayAgent->playbackHitPosition(position);
1147 void InspectorInstrumentation::playbackFinishedImpl(InstrumentingAgents& instrumentingAgents)
1149 if (InspectorReplayAgent* replayAgent = instrumentingAgents.inspectorReplayAgent())
1150 replayAgent->playbackFinished();
1154 void InspectorInstrumentation::networkStateChangedImpl(InstrumentingAgents& instrumentingAgents)
1156 if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents.inspectorApplicationCacheAgent())
1157 applicationCacheAgent->networkStateChanged();
1160 void InspectorInstrumentation::updateApplicationCacheStatusImpl(InstrumentingAgents& instrumentingAgents, Frame* frame)
1162 if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents.inspectorApplicationCacheAgent())
1163 applicationCacheAgent->updateApplicationCacheStatus(frame);
1166 bool InspectorInstrumentation::consoleAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
1168 InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
1169 InspectorConsoleAgent* consoleAgent = instrumentingAgents ? instrumentingAgents->webConsoleAgent() : nullptr;
1170 return consoleAgent && consoleAgent->enabled();
1173 bool InspectorInstrumentation::timelineAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
1175 InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
1176 return instrumentingAgents && instrumentingAgents->inspectorTimelineAgent();
1179 bool InspectorInstrumentation::replayAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
1181 #if ENABLE(WEB_REPLAY)
1182 InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
1183 return instrumentingAgents && instrumentingAgents->inspectorReplayAgent();
1185 UNUSED_PARAM(scriptExecutionContext);
1190 void InspectorInstrumentation::pauseOnNativeEventIfNeeded(InstrumentingAgents& instrumentingAgents, bool isDOMEvent, const String& eventName, bool synchronous)
1192 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
1193 domDebuggerAgent->pauseOnNativeEventIfNeeded(isDOMEvent, eventName, synchronous);
1196 void InspectorInstrumentation::cancelPauseOnNativeEvent(InstrumentingAgents& instrumentingAgents)
1198 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
1199 debuggerAgent->cancelPauseOnNextStatement();
1202 void InspectorInstrumentation::didRequestAnimationFrameImpl(InstrumentingAgents& instrumentingAgents, int callbackId, Frame* frame)
1204 pauseOnNativeEventIfNeeded(instrumentingAgents, false, requestAnimationFrameEventName, true);
1206 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
1207 timelineAgent->didRequestAnimationFrame(callbackId, frame);
1210 void InspectorInstrumentation::didCancelAnimationFrameImpl(InstrumentingAgents& instrumentingAgents, int callbackId, Frame* frame)
1212 pauseOnNativeEventIfNeeded(instrumentingAgents, false, cancelAnimationFrameEventName, true);
1214 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
1215 timelineAgent->didCancelAnimationFrame(callbackId, frame);
1218 InspectorInstrumentationCookie InspectorInstrumentation::willFireAnimationFrameImpl(InstrumentingAgents& instrumentingAgents, int callbackId, Frame* frame)
1220 pauseOnNativeEventIfNeeded(instrumentingAgents, false, animationFrameFiredEventName, false);
1222 int timelineAgentId = 0;
1223 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
1224 timelineAgent->willFireAnimationFrame(callbackId, frame);
1225 timelineAgentId = timelineAgent->id();
1227 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
1230 void InspectorInstrumentation::didFireAnimationFrameImpl(const InspectorInstrumentationCookie& cookie)
1232 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
1233 timelineAgent->didFireAnimationFrame();
1236 void InspectorInstrumentation::registerInstrumentingAgents(InstrumentingAgents& instrumentingAgents)
1238 if (!s_instrumentingAgentsSet)
1239 s_instrumentingAgentsSet = new HashSet<InstrumentingAgents*>();
1241 s_instrumentingAgentsSet->add(&instrumentingAgents);
1244 void InspectorInstrumentation::unregisterInstrumentingAgents(InstrumentingAgents& instrumentingAgents)
1246 if (!s_instrumentingAgentsSet)
1249 s_instrumentingAgentsSet->remove(&instrumentingAgents);
1250 if (s_instrumentingAgentsSet->isEmpty()) {
1251 delete s_instrumentingAgentsSet;
1252 s_instrumentingAgentsSet = nullptr;
1256 InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
1258 if (!cookie.isValid())
1261 InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent();
1262 if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id()))
1263 return timelineAgent;
1267 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForRenderingContext(WebGLRenderingContextBase* context)
1271 HTMLCanvasElement* canvasElement = context->canvas();
1273 return instrumentingAgentsForDocument(&canvasElement->document());
1277 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForPage(Page* page)
1279 return page ? instrumentingAgentsForPage(*page) : nullptr;
1282 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForPage(Page& page)
1284 ASSERT(isMainThread());
1285 return page.inspectorController().m_instrumentingAgents.get();
1288 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForRenderer(RenderObject* renderer)
1290 return instrumentingAgentsForFrame(renderer->frame());
1293 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope* workerGlobalScope)
1295 return workerGlobalScope ? workerGlobalScope->workerInspectorController().m_instrumentingAgents.get() : nullptr;
1298 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context)
1301 if (is<WorkerGlobalScope>(*context))
1302 return instrumentingAgentsForWorkerGlobalScope(downcast<WorkerGlobalScope>(context));
1306 void InspectorInstrumentation::layerTreeDidChangeImpl(InstrumentingAgents& instrumentingAgents)
1308 if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents.inspectorLayerTreeAgent())
1309 layerTreeAgent->layerTreeDidChange();
1312 void InspectorInstrumentation::renderLayerDestroyedImpl(InstrumentingAgents& instrumentingAgents, const RenderLayer& renderLayer)
1314 if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents.inspectorLayerTreeAgent())
1315 layerTreeAgent->renderLayerDestroyed(renderLayer);
1318 void InspectorInstrumentation::pseudoElementDestroyedImpl(InstrumentingAgents& instrumentingAgents, PseudoElement& pseudoElement)
1320 if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents.inspectorLayerTreeAgent())
1321 layerTreeAgent->pseudoElementDestroyed(pseudoElement);
1324 } // namespace WebCore