Web Inspector: provide method for recording CanvasRenderingContext2D from JavaScript
[WebKit-https.git] / Source / WebCore / inspector / InspectorInstrumentation.h
1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
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
14 * distribution.
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.
18 *
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.
30 */
31
32 #pragma once
33
34 #include "CSSSelector.h"
35 #include "CallTracerTypes.h"
36 #include "CanvasRenderingContext.h"
37 #include "DocumentThreadableLoader.h"
38 #include "Element.h"
39 #include "EventTarget.h"
40 #include "FormData.h"
41 #include "Frame.h"
42 #include "HTMLCanvasElement.h"
43 #include "HitTestResult.h"
44 #include "InspectorController.h"
45 #include "InspectorInstrumentationCookie.h"
46 #include "OffscreenCanvas.h"
47 #include "Page.h"
48 #include "StorageArea.h"
49 #include "WorkerGlobalScope.h"
50 #include "WorkerInspectorController.h"
51 #include <runtime/JSCInlines.h>
52 #include <wtf/MemoryPressureHandler.h>
53 #include <wtf/RefPtr.h>
54
55 #if ENABLE(WEBGL)
56 #include "WebGLRenderingContextBase.h"
57 #endif
58
59 namespace Inspector {
60 class ConsoleMessage;
61 class ScriptArguments;
62 class ScriptCallStack;
63 }
64
65 namespace WebCore {
66
67 class CachedResource;
68 class CharacterData;
69 class DOMWindow;
70 class DOMWrapperWorld;
71 class Database;
72 class Document;
73 class DocumentLoader;
74 class EventListener;
75 class HTTPHeaderMap;
76 class InspectorTimelineAgent;
77 class InstrumentingAgents;
78 class NetworkLoadMetrics;
79 class Node;
80 class PseudoElement;
81 class RegisteredEventListener;
82 class RenderLayer;
83 class RenderObject;
84 class ResourceLoader;
85 class ResourceRequest;
86 class ResourceResponse;
87 class ScriptExecutionContext;
88 class SecurityOrigin;
89 class ShadowRoot;
90 class TimerBase;
91 class URL;
92 #if ENABLE(WEBGL)
93 class WebGLProgram;
94 #endif
95 class WebKitNamedFlow;
96 class WorkerInspectorProxy;
97
98 enum class StorageType;
99
100 struct WebSocketFrame;
101
102 #define FAST_RETURN_IF_NO_FRONTENDS(value) if (LIKELY(!hasFrontends())) return value;
103
104 class InspectorInstrumentation {
105 public:
106     static void didClearWindowObjectInWorld(Frame&, DOMWrapperWorld&);
107     static bool isDebuggerPaused(Frame*);
108
109     static void willInsertDOMNode(Document&, Node& parent);
110     static void didInsertDOMNode(Document&, Node&);
111     static void willRemoveDOMNode(Document&, Node&);
112     static void didRemoveDOMNode(Document&, Node&);
113     static void willModifyDOMAttr(Document&, Element&, const AtomicString& oldValue, const AtomicString& newValue);
114     static void didModifyDOMAttr(Document&, Element&, const AtomicString& name, const AtomicString& value);
115     static void didRemoveDOMAttr(Document&, Element&, const AtomicString& name);
116     static void characterDataModified(Document&, CharacterData&);
117     static void didInvalidateStyleAttr(Document&, Node&);
118     static void documentDetached(Document&);
119     static void frameWindowDiscarded(Frame&, DOMWindow*);
120     static void mediaQueryResultChanged(Document&);
121     static void activeStyleSheetsUpdated(Document&);
122     static void didPushShadowRoot(Element& host, ShadowRoot&);
123     static void willPopShadowRoot(Element& host, ShadowRoot&);
124     static void didChangeCustomElementState(Element&);
125     static void pseudoElementCreated(Page*, PseudoElement&);
126     static void pseudoElementDestroyed(Page*, PseudoElement&);
127     static void didCreateNamedFlow(Document*, WebKitNamedFlow&);
128     static void willRemoveNamedFlow(Document*, WebKitNamedFlow&);
129     static void didChangeRegionOverset(Document&, WebKitNamedFlow&);
130     static void didRegisterNamedFlowContentElement(Document&, WebKitNamedFlow&, Node& contentElement, Node* nextContentElement = nullptr);
131     static void didUnregisterNamedFlowContentElement(Document&, WebKitNamedFlow&, Node& contentElement);
132
133     static void mouseDidMoveOverElement(Page&, const HitTestResult&, unsigned modifierFlags);
134     static bool handleMousePress(Frame&);
135     static bool handleTouchEvent(Frame&, Node&);
136     static bool forcePseudoState(const Element&, CSSSelector::PseudoClassType);
137
138     static void willSendXMLHttpRequest(ScriptExecutionContext*, const String& url);
139     static void didInstallTimer(ScriptExecutionContext&, int timerId, Seconds timeout, bool singleShot);
140     static void didRemoveTimer(ScriptExecutionContext&, int timerId);
141
142     static void didPostMessage(Frame&, TimerBase&, JSC::ExecState&);
143     static void didFailPostMessage(Frame&, TimerBase&);
144     static void willDispatchPostMessage(Frame&, TimerBase&);
145     static void didDispatchPostMessage(Frame&, TimerBase&);
146
147     static InspectorInstrumentationCookie willCallFunction(ScriptExecutionContext*, const String& scriptName, int scriptLine);
148     static void didCallFunction(const InspectorInstrumentationCookie&, ScriptExecutionContext*);
149     static void didAddEventListener(EventTarget&, const AtomicString& eventType);
150     static void willRemoveEventListener(EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
151     static bool isEventListenerDisabled(EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
152     static InspectorInstrumentationCookie willDispatchEvent(Document&, const Event&, bool hasEventListeners);
153     static void didDispatchEvent(const InspectorInstrumentationCookie&);
154     static void willHandleEvent(ScriptExecutionContext&, const Event&, const RegisteredEventListener&);
155     static void didHandleEvent(ScriptExecutionContext&);
156     static InspectorInstrumentationCookie willDispatchEventOnWindow(Frame*, const Event&, DOMWindow&);
157     static void didDispatchEventOnWindow(const InspectorInstrumentationCookie&);
158     static InspectorInstrumentationCookie willEvaluateScript(Frame&, const String& url, int lineNumber);
159     static void didEvaluateScript(const InspectorInstrumentationCookie&, Frame&);
160     static InspectorInstrumentationCookie willFireTimer(ScriptExecutionContext&, int timerId);
161     static void didFireTimer(const InspectorInstrumentationCookie&);
162     static void didInvalidateLayout(Frame&);
163     static InspectorInstrumentationCookie willLayout(Frame&);
164     static void didLayout(const InspectorInstrumentationCookie&, RenderObject&);
165     static void didScroll(Page&);
166     static void willComposite(Frame&);
167     static void didComposite(Frame&);
168     static void willPaint(RenderObject&);
169     static void didPaint(RenderObject&, const LayoutRect&);
170     static InspectorInstrumentationCookie willRecalculateStyle(Document&);
171     static void didRecalculateStyle(const InspectorInstrumentationCookie&);
172     static void didScheduleStyleRecalculation(Document&);
173     static void applyEmulatedMedia(Frame&, String&);
174
175     static void willSendRequest(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
176     static void didLoadResourceFromMemoryCache(Page&, DocumentLoader*, CachedResource*);
177     static void didReceiveResourceResponse(Frame&, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
178     static void didReceiveThreadableLoaderResponse(DocumentThreadableLoader&, unsigned long identifier);
179     static void didReceiveData(Frame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
180     static void didFinishLoading(Frame*, DocumentLoader*, unsigned long identifier, const NetworkLoadMetrics&, ResourceLoader*);
181     static void didFailLoading(Frame*, DocumentLoader*, unsigned long identifier, const ResourceError&);
182
183     static void willSendRequest(WorkerGlobalScope&, unsigned long identifier, ResourceRequest&);
184     static void didReceiveResourceResponse(WorkerGlobalScope&, unsigned long identifier, const ResourceResponse&);
185     static void didReceiveData(WorkerGlobalScope&, unsigned long identifier, const char* data, int dataLength);
186     static void didFinishLoading(WorkerGlobalScope&, unsigned long identifier, const NetworkLoadMetrics&);
187     static void didFailLoading(WorkerGlobalScope&, unsigned long identifier, const ResourceError&);
188
189     // Some network requests do not go through the normal network loading path.
190     // These network requests have to issue their own willSendRequest / didReceiveResponse / didFinishLoading / didFailLoading
191     // instrumentation calls. Some of these loads are for resources that lack a CachedResource::Type.
192     enum class LoadType { Ping, Beacon };
193     static void willSendRequestOfType(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, LoadType);
194
195     static void continueAfterXFrameOptionsDenied(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
196     static void continueWithPolicyDownload(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
197     static void continueWithPolicyIgnore(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
198     static void didFinishXHRLoading(ScriptExecutionContext*, unsigned long identifier, std::optional<String> decodedText);
199     static void willLoadXHRSynchronously(ScriptExecutionContext*);
200     static void didLoadXHRSynchronously(ScriptExecutionContext*);
201     static void scriptImported(ScriptExecutionContext&, unsigned long identifier, const String& sourceString);
202     static void scriptExecutionBlockedByCSP(ScriptExecutionContext*, const String& directiveText);
203     static void didReceiveScriptResponse(ScriptExecutionContext*, unsigned long identifier);
204     static void domContentLoadedEventFired(Frame&);
205     static void loadEventFired(Frame*);
206     static void frameDetachedFromParent(Frame&);
207     static void didCommitLoad(Frame&, DocumentLoader*);
208     static void frameDocumentUpdated(Frame&);
209     static void loaderDetachedFromFrame(Frame&, DocumentLoader&);
210     static void frameStartedLoading(Frame&);
211     static void frameStoppedLoading(Frame&);
212     static void frameScheduledNavigation(Frame&, Seconds delay);
213     static void frameClearedScheduledNavigation(Frame&);
214     static void willDestroyCachedResource(CachedResource&);
215
216     static void addMessageToConsole(Page&, std::unique_ptr<Inspector::ConsoleMessage>);
217     static void addMessageToConsole(WorkerGlobalScope&, std::unique_ptr<Inspector::ConsoleMessage>);
218
219     static void consoleCount(Page&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
220     static void consoleCount(WorkerGlobalScope&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
221     static void takeHeapSnapshot(Frame&, const String& title);
222     static void startConsoleTiming(Frame&, const String& title);
223     static void startConsoleTiming(WorkerGlobalScope&, const String& title);
224     static void stopConsoleTiming(Frame&, const String& title, Ref<Inspector::ScriptCallStack>&&);
225     static void stopConsoleTiming(WorkerGlobalScope&, const String& title, Ref<Inspector::ScriptCallStack>&&);
226     static void consoleTimeStamp(Frame&, Ref<Inspector::ScriptArguments>&&);
227     static void startProfiling(Page&, JSC::ExecState*, const String& title);
228     static void stopProfiling(Page&, JSC::ExecState*, const String& title);
229     static void consoleStartRecordingCanvas(HTMLCanvasElement&, JSC::ExecState&, JSC::JSObject* options);
230
231     static void didRequestAnimationFrame(Document&, int callbackId);
232     static void didCancelAnimationFrame(Document&, int callbackId);
233     static InspectorInstrumentationCookie willFireAnimationFrame(Document&, int callbackId);
234     static void didFireAnimationFrame(const InspectorInstrumentationCookie&);
235
236     static void didOpenDatabase(ScriptExecutionContext*, RefPtr<Database>&&, const String& domain, const String& name, const String& version);
237
238     static void didDispatchDOMStorageEvent(Page&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
239
240     static bool shouldWaitForDebuggerOnStart(ScriptExecutionContext&);
241     static void workerStarted(ScriptExecutionContext&, WorkerInspectorProxy*, const URL&);
242     static void workerTerminated(ScriptExecutionContext&, WorkerInspectorProxy*);
243
244     static void didCreateWebSocket(Document*, unsigned long identifier, const URL& requestURL);
245     static void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const ResourceRequest&);
246     static void didReceiveWebSocketHandshakeResponse(Document*, unsigned long identifier, const ResourceResponse&);
247     static void didCloseWebSocket(Document*, unsigned long identifier);
248     static void didReceiveWebSocketFrame(Document*, unsigned long identifier, const WebSocketFrame&);
249     static void didSendWebSocketFrame(Document*, unsigned long identifier, const WebSocketFrame&);
250     static void didReceiveWebSocketFrameError(Document*, unsigned long identifier, const String& errorMessage);
251
252 #if ENABLE(RESOURCE_USAGE)
253     static void didHandleMemoryPressure(Page&, Critical);
254 #endif
255
256     static void didCreateCSSCanvas(HTMLCanvasElement&, const String&);
257     static void didChangeCSSCanvasClientNodes(HTMLCanvasElement&);
258     static void didCreateCanvasRenderingContext(HTMLCanvasElement&);
259     static void didChangeCanvasMemory(HTMLCanvasElement&);
260     static void recordCanvasAction(CanvasRenderingContext&, const String&, Vector<RecordCanvasActionVariant>&& = { });
261     static void didFinishRecordingCanvasFrame(HTMLCanvasElement&, bool forceDispatch = false);
262 #if ENABLE(WEBGL)
263     static void didEnableExtension(WebGLRenderingContextBase&, const String&);
264     static void didCreateProgram(WebGLRenderingContextBase&, WebGLProgram&);
265     static void willDeleteProgram(WebGLRenderingContextBase&, WebGLProgram&);
266     static bool isShaderProgramDisabled(WebGLRenderingContextBase&, WebGLProgram&);
267 #endif
268
269     static void networkStateChanged(Page&);
270     static void updateApplicationCacheStatus(Frame*);
271
272     static void layerTreeDidChange(Page*);
273     static void renderLayerDestroyed(Page*, const RenderLayer&);
274
275     static void frontendCreated();
276     static void frontendDeleted();
277     static bool hasFrontends() { return s_frontendCounter; }
278
279     static void firstFrontendCreated();
280     static void lastFrontendDeleted();
281
282     static bool consoleAgentEnabled(ScriptExecutionContext*);
283     static bool timelineAgentEnabled(ScriptExecutionContext*);
284
285     static InstrumentingAgents* instrumentingAgentsForPage(Page*);
286
287     static void registerInstrumentingAgents(InstrumentingAgents&);
288     static void unregisterInstrumentingAgents(InstrumentingAgents&);
289
290 private:
291     static void didClearWindowObjectInWorldImpl(InstrumentingAgents&, Frame&, DOMWrapperWorld&);
292     static bool isDebuggerPausedImpl(InstrumentingAgents&);
293
294     static void willInsertDOMNodeImpl(InstrumentingAgents&, Node& parent);
295     static void didInsertDOMNodeImpl(InstrumentingAgents&, Node&);
296     static void willRemoveDOMNodeImpl(InstrumentingAgents&, Node&);
297     static void didRemoveDOMNodeImpl(InstrumentingAgents&, Node&);
298     static void willModifyDOMAttrImpl(InstrumentingAgents&, Element&, const AtomicString& oldValue, const AtomicString& newValue);
299     static void didModifyDOMAttrImpl(InstrumentingAgents&, Element&, const AtomicString& name, const AtomicString& value);
300     static void didRemoveDOMAttrImpl(InstrumentingAgents&, Element&, const AtomicString& name);
301     static void characterDataModifiedImpl(InstrumentingAgents&, CharacterData&);
302     static void didInvalidateStyleAttrImpl(InstrumentingAgents&, Node&);
303     static void documentDetachedImpl(InstrumentingAgents&, Document&);
304     static void frameWindowDiscardedImpl(InstrumentingAgents&, DOMWindow*);
305     static void mediaQueryResultChangedImpl(InstrumentingAgents&);
306     static void activeStyleSheetsUpdatedImpl(InstrumentingAgents&, Document&);
307     static void didPushShadowRootImpl(InstrumentingAgents&, Element& host, ShadowRoot&);
308     static void willPopShadowRootImpl(InstrumentingAgents&, Element& host, ShadowRoot&);
309     static void didChangeCustomElementStateImpl(InstrumentingAgents&, Element&);
310     static void pseudoElementCreatedImpl(InstrumentingAgents&, PseudoElement&);
311     static void pseudoElementDestroyedImpl(InstrumentingAgents&, PseudoElement&);
312     static void didCreateNamedFlowImpl(InstrumentingAgents&, Document*, WebKitNamedFlow&);
313     static void willRemoveNamedFlowImpl(InstrumentingAgents&, Document*, WebKitNamedFlow&);
314     static void didChangeRegionOversetImpl(InstrumentingAgents&, Document&, WebKitNamedFlow&);
315     static void didRegisterNamedFlowContentElementImpl(InstrumentingAgents&, Document&, WebKitNamedFlow&, Node& contentElement, Node* nextContentElement = nullptr);
316     static void didUnregisterNamedFlowContentElementImpl(InstrumentingAgents&, Document&, WebKitNamedFlow&, Node& contentElement);
317
318     static void mouseDidMoveOverElementImpl(InstrumentingAgents&, const HitTestResult&, unsigned modifierFlags);
319     static bool handleMousePressImpl(InstrumentingAgents&);
320     static bool handleTouchEventImpl(InstrumentingAgents&, Node&);
321     static bool forcePseudoStateImpl(InstrumentingAgents&, const Element&, CSSSelector::PseudoClassType);
322
323     static void willSendXMLHttpRequestImpl(InstrumentingAgents&, const String& url);
324     static void didInstallTimerImpl(InstrumentingAgents&, int timerId, Seconds timeout, bool singleShot, ScriptExecutionContext&);
325     static void didRemoveTimerImpl(InstrumentingAgents&, int timerId, ScriptExecutionContext&);
326
327     static void didPostMessageImpl(InstrumentingAgents&, const TimerBase&, JSC::ExecState&);
328     static void didFailPostMessageImpl(InstrumentingAgents&, const TimerBase&);
329     static void willDispatchPostMessageImpl(InstrumentingAgents&, const TimerBase&);
330     static void didDispatchPostMessageImpl(InstrumentingAgents&, const TimerBase&);
331
332     static InspectorInstrumentationCookie willCallFunctionImpl(InstrumentingAgents&, const String& scriptName, int scriptLine, ScriptExecutionContext*);
333     static void didCallFunctionImpl(const InspectorInstrumentationCookie&, ScriptExecutionContext*);
334     static void didAddEventListenerImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType);
335     static void willRemoveEventListenerImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
336     static bool isEventListenerDisabledImpl(InstrumentingAgents&, EventTarget&, const AtomicString& eventType, EventListener&, bool capture);
337     static InspectorInstrumentationCookie willDispatchEventImpl(InstrumentingAgents&, Document&, const Event&, bool hasEventListeners);
338     static void willHandleEventImpl(InstrumentingAgents&, const Event&, const RegisteredEventListener&);
339     static void didHandleEventImpl(InstrumentingAgents&);
340     static void didDispatchEventImpl(const InspectorInstrumentationCookie&);
341     static InspectorInstrumentationCookie willDispatchEventOnWindowImpl(InstrumentingAgents&, const Event&, DOMWindow&);
342     static void didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie&);
343     static InspectorInstrumentationCookie willEvaluateScriptImpl(InstrumentingAgents&, Frame&, const String& url, int lineNumber);
344     static void didEvaluateScriptImpl(const InspectorInstrumentationCookie&, Frame&);
345     static InspectorInstrumentationCookie willFireTimerImpl(InstrumentingAgents&, int timerId, ScriptExecutionContext&);
346     static void didFireTimerImpl(const InspectorInstrumentationCookie&);
347     static void didInvalidateLayoutImpl(InstrumentingAgents&, Frame&);
348     static InspectorInstrumentationCookie willLayoutImpl(InstrumentingAgents&, Frame&);
349     static void didLayoutImpl(const InspectorInstrumentationCookie&, RenderObject&);
350     static void didScrollImpl(InstrumentingAgents&);
351     static void willCompositeImpl(InstrumentingAgents&, Frame&);
352     static void didCompositeImpl(InstrumentingAgents&);
353     static void willPaintImpl(InstrumentingAgents&, RenderObject&);
354     static void didPaintImpl(InstrumentingAgents&, RenderObject&, const LayoutRect&);
355     static InspectorInstrumentationCookie willRecalculateStyleImpl(InstrumentingAgents&, Document&);
356     static void didRecalculateStyleImpl(const InspectorInstrumentationCookie&);
357     static void didScheduleStyleRecalculationImpl(InstrumentingAgents&, Document&);
358     static void applyEmulatedMediaImpl(InstrumentingAgents&, String&);
359
360     static void willSendRequestImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
361     static void willSendRequestOfTypeImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, ResourceRequest&, LoadType);
362     static void markResourceAsCachedImpl(InstrumentingAgents&, unsigned long identifier);
363     static void didLoadResourceFromMemoryCacheImpl(InstrumentingAgents&, DocumentLoader*, CachedResource*);
364     static void didReceiveResourceResponseImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
365     static void didReceiveThreadableLoaderResponseImpl(InstrumentingAgents&, DocumentThreadableLoader&, unsigned long identifier);
366     static void didReceiveDataImpl(InstrumentingAgents&, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
367     static void didFinishLoadingImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, const NetworkLoadMetrics&, ResourceLoader*);
368     static void didFailLoadingImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, const ResourceError&);
369     static void didFinishXHRLoadingImpl(InstrumentingAgents&, unsigned long identifier, std::optional<String> decodedText);
370     static void willLoadXHRSynchronouslyImpl(InstrumentingAgents&);
371     static void didLoadXHRSynchronouslyImpl(InstrumentingAgents&);
372     static void scriptImportedImpl(InstrumentingAgents&, unsigned long identifier, const String& sourceString);
373     static void scriptExecutionBlockedByCSPImpl(InstrumentingAgents&, const String& directiveText);
374     static void didReceiveScriptResponseImpl(InstrumentingAgents&, unsigned long identifier);
375     static void domContentLoadedEventFiredImpl(InstrumentingAgents&, Frame&);
376     static void loadEventFiredImpl(InstrumentingAgents&, Frame*);
377     static void frameDetachedFromParentImpl(InstrumentingAgents&, Frame&);
378     static void didCommitLoadImpl(InstrumentingAgents&, Frame&, DocumentLoader*);
379     static void frameDocumentUpdatedImpl(InstrumentingAgents&, Frame&);
380     static void loaderDetachedFromFrameImpl(InstrumentingAgents&, DocumentLoader&);
381     static void frameStartedLoadingImpl(InstrumentingAgents&, Frame&);
382     static void frameStoppedLoadingImpl(InstrumentingAgents&, Frame&);
383     static void frameScheduledNavigationImpl(InstrumentingAgents&, Frame&, Seconds delay);
384     static void frameClearedScheduledNavigationImpl(InstrumentingAgents&, Frame&);
385     static void willDestroyCachedResourceImpl(CachedResource&);
386
387     static void addMessageToConsoleImpl(InstrumentingAgents&, std::unique_ptr<Inspector::ConsoleMessage>);
388
389     static void consoleCountImpl(InstrumentingAgents&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
390     static void takeHeapSnapshotImpl(InstrumentingAgents&, const String& title);
391     static void startConsoleTimingImpl(InstrumentingAgents&, Frame&, const String& title);
392     static void startConsoleTimingImpl(InstrumentingAgents&, const String& title);
393     static void stopConsoleTimingImpl(InstrumentingAgents&, Frame&, const String& title, Ref<Inspector::ScriptCallStack>&&);
394     static void stopConsoleTimingImpl(InstrumentingAgents&, const String& title, Ref<Inspector::ScriptCallStack>&&);
395     static void consoleTimeStampImpl(InstrumentingAgents&, Frame&, Ref<Inspector::ScriptArguments>&&);
396     static void startProfilingImpl(InstrumentingAgents&, JSC::ExecState*, const String& title);
397     static void stopProfilingImpl(InstrumentingAgents&, JSC::ExecState*, const String& title);
398     static void consoleStartRecordingCanvasImpl(InstrumentingAgents&, HTMLCanvasElement&, JSC::ExecState&, JSC::JSObject* options);
399
400     static void didRequestAnimationFrameImpl(InstrumentingAgents&, int callbackId, Document&);
401     static void didCancelAnimationFrameImpl(InstrumentingAgents&, int callbackId, Document&);
402     static InspectorInstrumentationCookie willFireAnimationFrameImpl(InstrumentingAgents&, int callbackId, Document&);
403     static void didFireAnimationFrameImpl(const InspectorInstrumentationCookie&);
404
405     static void didOpenDatabaseImpl(InstrumentingAgents&, RefPtr<Database>&&, const String& domain, const String& name, const String& version);
406
407     static void didDispatchDOMStorageEventImpl(InstrumentingAgents&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
408
409     static bool shouldWaitForDebuggerOnStartImpl(InstrumentingAgents&);
410     static void workerStartedImpl(InstrumentingAgents&, WorkerInspectorProxy*, const URL&);
411     static void workerTerminatedImpl(InstrumentingAgents&, WorkerInspectorProxy*);
412
413     static void didCreateWebSocketImpl(InstrumentingAgents&, unsigned long identifier, const URL& requestURL);
414     static void willSendWebSocketHandshakeRequestImpl(InstrumentingAgents&, unsigned long identifier, const ResourceRequest&);
415     static void didReceiveWebSocketHandshakeResponseImpl(InstrumentingAgents&, unsigned long identifier, const ResourceResponse&);
416     static void didCloseWebSocketImpl(InstrumentingAgents&, unsigned long identifier);
417     static void didReceiveWebSocketFrameImpl(InstrumentingAgents&, unsigned long identifier, const WebSocketFrame&);
418     static void didSendWebSocketFrameImpl(InstrumentingAgents&, unsigned long identifier, const WebSocketFrame&);
419     static void didReceiveWebSocketFrameErrorImpl(InstrumentingAgents&, unsigned long identifier, const String&);
420
421 #if ENABLE(RESOURCE_USAGE)
422     static void didHandleMemoryPressureImpl(InstrumentingAgents&, Critical);
423 #endif
424
425     static void networkStateChangedImpl(InstrumentingAgents&);
426     static void updateApplicationCacheStatusImpl(InstrumentingAgents&, Frame&);
427
428     static void didCreateCSSCanvasImpl(InstrumentingAgents&, HTMLCanvasElement&, const String&);
429     static void didChangeCSSCanvasClientNodesImpl(InstrumentingAgents&, HTMLCanvasElement&);
430     static void didCreateCanvasRenderingContextImpl(InstrumentingAgents&, HTMLCanvasElement&);
431     static void didChangeCanvasMemoryImpl(InstrumentingAgents&, HTMLCanvasElement&);
432     static void recordCanvasActionImpl(InstrumentingAgents&, CanvasRenderingContext&, const String&, Vector<RecordCanvasActionVariant>&& = { });
433     static void didFinishRecordingCanvasFrameImpl(InstrumentingAgents&, HTMLCanvasElement&, bool forceDispatch = false);
434 #if ENABLE(WEBGL)
435     static void didEnableExtensionImpl(InstrumentingAgents&, WebGLRenderingContextBase&, const String&);
436     static void didCreateProgramImpl(InstrumentingAgents&, WebGLRenderingContextBase&, WebGLProgram&);
437     static void willDeleteProgramImpl(InstrumentingAgents&, WebGLProgram&);
438     static bool isShaderProgramDisabledImpl(InstrumentingAgents&, WebGLProgram&);
439 #endif
440
441     static void layerTreeDidChangeImpl(InstrumentingAgents&);
442     static void renderLayerDestroyedImpl(InstrumentingAgents&, const RenderLayer&);
443
444     static InstrumentingAgents& instrumentingAgentsForPage(Page&);
445     static InstrumentingAgents& instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope&);
446
447     static InstrumentingAgents* instrumentingAgentsForFrame(Frame&);
448     static InstrumentingAgents* instrumentingAgentsForFrame(Frame*);
449     static InstrumentingAgents* instrumentingAgentsForContext(ScriptExecutionContext*);
450     static InstrumentingAgents* instrumentingAgentsForContext(ScriptExecutionContext&);
451     static InstrumentingAgents* instrumentingAgentsForDocument(Document&);
452     static InstrumentingAgents* instrumentingAgentsForDocument(Document*);
453     static InstrumentingAgents* instrumentingAgentsForRenderer(RenderObject&);
454     static InstrumentingAgents* instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope*);
455
456     static InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
457
458     static void pauseOnNativeEventIfNeeded(InstrumentingAgents&, bool isDOMEvent, const String& eventName, bool synchronous);
459
460     WEBCORE_EXPORT static int s_frontendCounter;
461 };
462
463 inline void InspectorInstrumentation::didClearWindowObjectInWorld(Frame& frame, DOMWrapperWorld& world)
464 {
465     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
466         didClearWindowObjectInWorldImpl(*instrumentingAgents, frame, world);
467 }
468
469 inline bool InspectorInstrumentation::isDebuggerPaused(Frame* frame)
470 {
471     FAST_RETURN_IF_NO_FRONTENDS(false);
472     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
473         return isDebuggerPausedImpl(*instrumentingAgents);
474     return false;
475 }
476
477 inline void InspectorInstrumentation::willInsertDOMNode(Document& document, Node& parent)
478 {
479     FAST_RETURN_IF_NO_FRONTENDS(void());
480     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
481         willInsertDOMNodeImpl(*instrumentingAgents, parent);
482 }
483
484 inline void InspectorInstrumentation::didInsertDOMNode(Document& document, Node& node)
485 {
486     FAST_RETURN_IF_NO_FRONTENDS(void());
487     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
488         didInsertDOMNodeImpl(*instrumentingAgents, node);
489 }
490
491 inline void InspectorInstrumentation::willRemoveDOMNode(Document& document, Node& node)
492 {
493     FAST_RETURN_IF_NO_FRONTENDS(void());
494     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
495         willRemoveDOMNodeImpl(*instrumentingAgents, node);
496 }
497
498 inline void InspectorInstrumentation::didRemoveDOMNode(Document& document, Node& node)
499 {
500     FAST_RETURN_IF_NO_FRONTENDS(void());
501     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
502         didRemoveDOMNodeImpl(*instrumentingAgents, node);
503 }
504
505 inline void InspectorInstrumentation::willModifyDOMAttr(Document& document, Element& element, const AtomicString& oldValue, const AtomicString& newValue)
506 {
507     FAST_RETURN_IF_NO_FRONTENDS(void());
508     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
509         willModifyDOMAttrImpl(*instrumentingAgents, element, oldValue, newValue);
510 }
511
512 inline void InspectorInstrumentation::didModifyDOMAttr(Document& document, Element& element, const AtomicString& name, const AtomicString& value)
513 {
514     FAST_RETURN_IF_NO_FRONTENDS(void());
515     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
516         didModifyDOMAttrImpl(*instrumentingAgents, element, name, value);
517 }
518
519 inline void InspectorInstrumentation::didRemoveDOMAttr(Document& document, Element& element, const AtomicString& name)
520 {
521     FAST_RETURN_IF_NO_FRONTENDS(void());
522     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
523         didRemoveDOMAttrImpl(*instrumentingAgents, element, name);
524 }
525
526 inline void InspectorInstrumentation::didInvalidateStyleAttr(Document& document, Node& node)
527 {
528     FAST_RETURN_IF_NO_FRONTENDS(void());
529     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
530         didInvalidateStyleAttrImpl(*instrumentingAgents, node);
531 }
532
533 inline void InspectorInstrumentation::documentDetached(Document& document)
534 {
535     FAST_RETURN_IF_NO_FRONTENDS(void());
536     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
537         documentDetachedImpl(*instrumentingAgents, document);
538 }
539
540 inline void InspectorInstrumentation::frameWindowDiscarded(Frame& frame, DOMWindow* domWindow)
541 {
542     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
543         frameWindowDiscardedImpl(*instrumentingAgents, domWindow);
544 }
545
546 inline void InspectorInstrumentation::mediaQueryResultChanged(Document& document)
547 {
548     FAST_RETURN_IF_NO_FRONTENDS(void());
549     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
550         mediaQueryResultChangedImpl(*instrumentingAgents);
551 }
552
553 inline void InspectorInstrumentation::activeStyleSheetsUpdated(Document& document)
554 {
555     FAST_RETURN_IF_NO_FRONTENDS(void());
556     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
557         activeStyleSheetsUpdatedImpl(*instrumentingAgents, document);
558 }
559
560 inline void InspectorInstrumentation::didPushShadowRoot(Element& host, ShadowRoot& root)
561 {
562     FAST_RETURN_IF_NO_FRONTENDS(void());
563     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(host.document()))
564         didPushShadowRootImpl(*instrumentingAgents, host, root);
565 }
566
567 inline void InspectorInstrumentation::willPopShadowRoot(Element& host, ShadowRoot& root)
568 {
569     FAST_RETURN_IF_NO_FRONTENDS(void());
570     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(host.document()))
571         willPopShadowRootImpl(*instrumentingAgents, host, root);
572 }
573
574 inline void InspectorInstrumentation::didChangeCustomElementState(Element& element)
575 {
576     FAST_RETURN_IF_NO_FRONTENDS(void());
577     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(element.document()))
578         didChangeCustomElementStateImpl(*instrumentingAgents, element);
579 }
580
581 inline void InspectorInstrumentation::pseudoElementCreated(Page* page, PseudoElement& pseudoElement)
582 {
583     FAST_RETURN_IF_NO_FRONTENDS(void());
584     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
585         pseudoElementCreatedImpl(*instrumentingAgents, pseudoElement);
586 }
587
588 inline void InspectorInstrumentation::pseudoElementDestroyed(Page* page, PseudoElement& pseudoElement)
589 {
590     FAST_RETURN_IF_NO_FRONTENDS(void());
591     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
592         pseudoElementDestroyedImpl(*instrumentingAgents, pseudoElement);
593 }
594
595 inline void InspectorInstrumentation::didCreateNamedFlow(Document* document, WebKitNamedFlow& namedFlow)
596 {
597     FAST_RETURN_IF_NO_FRONTENDS(void());
598     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
599         didCreateNamedFlowImpl(*instrumentingAgents, document, namedFlow);
600 }
601
602 inline void InspectorInstrumentation::willRemoveNamedFlow(Document* document, WebKitNamedFlow& namedFlow)
603 {
604     FAST_RETURN_IF_NO_FRONTENDS(void());
605     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
606         willRemoveNamedFlowImpl(*instrumentingAgents, document, namedFlow);
607 }
608
609 inline void InspectorInstrumentation::didChangeRegionOverset(Document& document, WebKitNamedFlow& namedFlow)
610 {
611     FAST_RETURN_IF_NO_FRONTENDS(void());
612     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
613         didChangeRegionOversetImpl(*instrumentingAgents, document, namedFlow);
614 }
615
616 inline void InspectorInstrumentation::didRegisterNamedFlowContentElement(Document& document, WebKitNamedFlow& namedFlow, Node& contentElement, Node* nextContentElement)
617 {
618     FAST_RETURN_IF_NO_FRONTENDS(void());
619     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
620         didRegisterNamedFlowContentElementImpl(*instrumentingAgents, document, namedFlow, contentElement, nextContentElement);
621 }
622
623 inline void InspectorInstrumentation::didUnregisterNamedFlowContentElement(Document& document, WebKitNamedFlow& namedFlow, Node& contentElement)
624 {
625     FAST_RETURN_IF_NO_FRONTENDS(void());
626     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
627         didUnregisterNamedFlowContentElementImpl(*instrumentingAgents, document, namedFlow, contentElement);
628 }
629
630 inline void InspectorInstrumentation::mouseDidMoveOverElement(Page& page, const HitTestResult& result, unsigned modifierFlags)
631 {
632     FAST_RETURN_IF_NO_FRONTENDS(void());
633     mouseDidMoveOverElementImpl(instrumentingAgentsForPage(page), result, modifierFlags);
634 }
635
636 inline bool InspectorInstrumentation::handleTouchEvent(Frame& frame, Node& node)
637 {
638     FAST_RETURN_IF_NO_FRONTENDS(false);
639     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
640         return handleTouchEventImpl(*instrumentingAgents, node);
641     return false;
642 }
643
644 inline bool InspectorInstrumentation::handleMousePress(Frame& frame)
645 {
646     FAST_RETURN_IF_NO_FRONTENDS(false);
647     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
648         return handleMousePressImpl(*instrumentingAgents);
649     return false;
650 }
651
652 inline bool InspectorInstrumentation::forcePseudoState(const Element& element, CSSSelector::PseudoClassType pseudoState)
653 {
654     FAST_RETURN_IF_NO_FRONTENDS(false);
655     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(element.document()))
656         return forcePseudoStateImpl(*instrumentingAgents, element, pseudoState);
657     return false;
658 }
659
660 inline void InspectorInstrumentation::characterDataModified(Document& document, CharacterData& characterData)
661 {
662     FAST_RETURN_IF_NO_FRONTENDS(void());
663     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
664         characterDataModifiedImpl(*instrumentingAgents, characterData);
665 }
666
667 inline void InspectorInstrumentation::willSendXMLHttpRequest(ScriptExecutionContext* context, const String& url)
668 {
669     FAST_RETURN_IF_NO_FRONTENDS(void());
670     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
671         willSendXMLHttpRequestImpl(*instrumentingAgents, url);
672 }
673
674 inline void InspectorInstrumentation::didInstallTimer(ScriptExecutionContext& context, int timerId, Seconds timeout, bool singleShot)
675 {
676     FAST_RETURN_IF_NO_FRONTENDS(void());
677     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
678         didInstallTimerImpl(*instrumentingAgents, timerId, timeout, singleShot, context);
679 }
680
681 inline void InspectorInstrumentation::didRemoveTimer(ScriptExecutionContext& context, int timerId)
682 {
683     FAST_RETURN_IF_NO_FRONTENDS(void());
684     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
685         didRemoveTimerImpl(*instrumentingAgents, timerId, context);
686 }
687
688 inline void InspectorInstrumentation::didAddEventListener(EventTarget& target, const AtomicString& eventType)
689 {
690     FAST_RETURN_IF_NO_FRONTENDS(void());
691     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(target.scriptExecutionContext()))
692         didAddEventListenerImpl(*instrumentingAgents, target, eventType);
693 }
694
695 inline void InspectorInstrumentation::willRemoveEventListener(EventTarget& target, const AtomicString& eventType, EventListener& listener, bool capture)
696 {
697     FAST_RETURN_IF_NO_FRONTENDS(void());
698     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(target.scriptExecutionContext()))
699         willRemoveEventListenerImpl(*instrumentingAgents, target, eventType, listener, capture);
700 }
701
702 inline bool InspectorInstrumentation::isEventListenerDisabled(EventTarget& target, const AtomicString& eventType, EventListener& listener, bool capture)
703 {
704     FAST_RETURN_IF_NO_FRONTENDS(false);
705     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(target.scriptExecutionContext()))
706         return isEventListenerDisabledImpl(*instrumentingAgents, target, eventType, listener, capture);
707     return false;
708 }
709
710 inline void InspectorInstrumentation::didPostMessage(Frame& frame, TimerBase& timer, JSC::ExecState& state)
711 {
712     FAST_RETURN_IF_NO_FRONTENDS(void());
713     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
714         didPostMessageImpl(*instrumentingAgents, timer, state);
715 }
716
717 inline void InspectorInstrumentation::didFailPostMessage(Frame& frame, TimerBase& timer)
718 {
719     FAST_RETURN_IF_NO_FRONTENDS(void());
720     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
721         didFailPostMessageImpl(*instrumentingAgents, timer);
722 }
723
724 inline void InspectorInstrumentation::willDispatchPostMessage(Frame& frame, TimerBase& timer)
725 {
726     FAST_RETURN_IF_NO_FRONTENDS(void());
727     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
728         willDispatchPostMessageImpl(*instrumentingAgents, timer);
729 }
730
731 inline void InspectorInstrumentation::didDispatchPostMessage(Frame& frame, TimerBase& timer)
732 {
733     FAST_RETURN_IF_NO_FRONTENDS(void());
734     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
735         didDispatchPostMessageImpl(*instrumentingAgents, timer);
736 }
737
738 inline InspectorInstrumentationCookie InspectorInstrumentation::willCallFunction(ScriptExecutionContext* context, const String& scriptName, int scriptLine)
739 {
740     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
741     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
742         return willCallFunctionImpl(*instrumentingAgents, scriptName, scriptLine, context);
743     return InspectorInstrumentationCookie();
744 }
745
746 inline void InspectorInstrumentation::didCallFunction(const InspectorInstrumentationCookie& cookie, ScriptExecutionContext* context)
747 {
748     FAST_RETURN_IF_NO_FRONTENDS(void());
749     if (cookie.isValid())
750         didCallFunctionImpl(cookie, context);
751 }
752
753 inline InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEvent(Document& document, const Event& event, bool hasEventListeners)
754 {
755     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
756     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
757         return willDispatchEventImpl(*instrumentingAgents, document, event, hasEventListeners);
758     return InspectorInstrumentationCookie();
759 }
760
761 inline void InspectorInstrumentation::didDispatchEvent(const InspectorInstrumentationCookie& cookie)
762 {
763     FAST_RETURN_IF_NO_FRONTENDS(void());
764     if (cookie.isValid())
765         didDispatchEventImpl(cookie);
766 }
767
768 inline void InspectorInstrumentation::willHandleEvent(ScriptExecutionContext& context, const Event& event, const RegisteredEventListener& listener)
769 {
770     FAST_RETURN_IF_NO_FRONTENDS(void());
771     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
772         return willHandleEventImpl(*instrumentingAgents, event, listener);
773 }
774
775 inline void InspectorInstrumentation::didHandleEvent(ScriptExecutionContext& context)
776 {
777     FAST_RETURN_IF_NO_FRONTENDS(void());
778     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
779         return didHandleEventImpl(*instrumentingAgents);
780 }
781
782 inline InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindow(Frame* frame, const Event& event, DOMWindow& window)
783 {
784     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
785     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
786         return willDispatchEventOnWindowImpl(*instrumentingAgents, event, window);
787     return InspectorInstrumentationCookie();
788 }
789
790 inline void InspectorInstrumentation::didDispatchEventOnWindow(const InspectorInstrumentationCookie& cookie)
791 {
792     FAST_RETURN_IF_NO_FRONTENDS(void());
793     if (cookie.isValid())
794         didDispatchEventOnWindowImpl(cookie);
795 }
796
797 inline InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScript(Frame& frame, const String& url, int lineNumber)
798 {
799     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
800     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
801         return willEvaluateScriptImpl(*instrumentingAgents, frame, url, lineNumber);
802     return InspectorInstrumentationCookie();
803 }
804
805 inline void InspectorInstrumentation::didEvaluateScript(const InspectorInstrumentationCookie& cookie, Frame& frame)
806 {
807     FAST_RETURN_IF_NO_FRONTENDS(void());
808     if (cookie.isValid())
809         didEvaluateScriptImpl(cookie, frame);
810 }
811
812 inline InspectorInstrumentationCookie InspectorInstrumentation::willFireTimer(ScriptExecutionContext& context, int timerId)
813 {
814     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
815     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
816         return willFireTimerImpl(*instrumentingAgents, timerId, context);
817     return InspectorInstrumentationCookie();
818 }
819
820 inline void InspectorInstrumentation::didFireTimer(const InspectorInstrumentationCookie& cookie)
821 {
822     FAST_RETURN_IF_NO_FRONTENDS(void());
823     if (cookie.isValid())
824         didFireTimerImpl(cookie);
825 }
826
827 inline void InspectorInstrumentation::didInvalidateLayout(Frame& frame)
828 {
829     FAST_RETURN_IF_NO_FRONTENDS(void());
830     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
831         didInvalidateLayoutImpl(*instrumentingAgents, frame);
832 }
833
834 inline InspectorInstrumentationCookie InspectorInstrumentation::willLayout(Frame& frame)
835 {
836     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
837     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
838         return willLayoutImpl(*instrumentingAgents, frame);
839     return InspectorInstrumentationCookie();
840 }
841
842 inline void InspectorInstrumentation::didLayout(const InspectorInstrumentationCookie& cookie, RenderObject& root)
843 {
844     FAST_RETURN_IF_NO_FRONTENDS(void());
845     if (cookie.isValid())
846         didLayoutImpl(cookie, root);
847 }
848
849 inline void InspectorInstrumentation::didScroll(Page& page)
850 {
851     FAST_RETURN_IF_NO_FRONTENDS(void());
852     didScrollImpl(instrumentingAgentsForPage(page));
853 }
854
855 inline void InspectorInstrumentation::willComposite(Frame& frame)
856 {
857     FAST_RETURN_IF_NO_FRONTENDS(void());
858     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
859         willCompositeImpl(*instrumentingAgents, frame);
860 }
861
862 inline void InspectorInstrumentation::didComposite(Frame& frame)
863 {
864     FAST_RETURN_IF_NO_FRONTENDS(void());
865     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
866         didCompositeImpl(*instrumentingAgents);
867 }
868
869 inline void InspectorInstrumentation::willPaint(RenderObject& renderer)
870 {
871     FAST_RETURN_IF_NO_FRONTENDS(void());
872     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForRenderer(renderer))
873         return willPaintImpl(*instrumentingAgents, renderer);
874 }
875
876 inline void InspectorInstrumentation::didPaint(RenderObject& renderer, const LayoutRect& rect)
877 {
878     FAST_RETURN_IF_NO_FRONTENDS(void());
879     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForRenderer(renderer))
880         didPaintImpl(*instrumentingAgents, renderer, rect);
881 }
882
883 inline InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyle(Document& document)
884 {
885     FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
886     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
887         return willRecalculateStyleImpl(*instrumentingAgents, document);
888     return InspectorInstrumentationCookie();
889 }
890
891 inline void InspectorInstrumentation::didRecalculateStyle(const InspectorInstrumentationCookie& cookie)
892 {
893     FAST_RETURN_IF_NO_FRONTENDS(void());
894     if (cookie.isValid())
895         didRecalculateStyleImpl(cookie);
896 }
897
898 inline void InspectorInstrumentation::didScheduleStyleRecalculation(Document& document)
899 {
900     FAST_RETURN_IF_NO_FRONTENDS(void());
901     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
902         didScheduleStyleRecalculationImpl(*instrumentingAgents, document);
903 }
904
905 inline void InspectorInstrumentation::applyEmulatedMedia(Frame& frame, String& media)
906 {
907     FAST_RETURN_IF_NO_FRONTENDS(void());
908     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
909         applyEmulatedMediaImpl(*instrumentingAgents, media);
910 }
911
912 inline void InspectorInstrumentation::willSendRequest(Frame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
913 {
914     FAST_RETURN_IF_NO_FRONTENDS(void());
915     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
916         willSendRequestImpl(*instrumentingAgents, identifier, loader, request, redirectResponse);
917 }
918
919 inline void InspectorInstrumentation::willSendRequest(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, ResourceRequest& request)
920 {
921     FAST_RETURN_IF_NO_FRONTENDS(void());
922     willSendRequestImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, request, ResourceResponse { });
923 }
924
925 inline void InspectorInstrumentation::willSendRequestOfType(Frame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, LoadType loadType)
926 {
927     FAST_RETURN_IF_NO_FRONTENDS(void());
928     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
929         willSendRequestOfTypeImpl(*instrumentingAgents, identifier, loader, request, loadType);
930 }
931
932 inline void InspectorInstrumentation::didLoadResourceFromMemoryCache(Page& page, DocumentLoader* loader, CachedResource* resource)
933 {
934     FAST_RETURN_IF_NO_FRONTENDS(void());
935     didLoadResourceFromMemoryCacheImpl(instrumentingAgentsForPage(page), loader, resource);
936 }
937
938 inline void InspectorInstrumentation::didReceiveResourceResponse(Frame& frame, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
939 {
940     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
941         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, loader, response, resourceLoader);
942 }
943
944 inline void InspectorInstrumentation::didReceiveResourceResponse(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const ResourceResponse& response)
945 {
946     didReceiveResourceResponseImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, response, nullptr);
947 }
948
949 inline void InspectorInstrumentation::didReceiveThreadableLoaderResponse(DocumentThreadableLoader& documentThreadableLoader, unsigned long identifier)
950 {
951     FAST_RETURN_IF_NO_FRONTENDS(void());
952     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(documentThreadableLoader.document()))
953         didReceiveThreadableLoaderResponseImpl(*instrumentingAgents, documentThreadableLoader, identifier);
954 }
955     
956 inline void InspectorInstrumentation::didReceiveData(Frame* frame, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
957 {
958     FAST_RETURN_IF_NO_FRONTENDS(void());
959     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
960         didReceiveDataImpl(*instrumentingAgents, identifier, data, dataLength, encodedDataLength);
961 }
962
963 inline void InspectorInstrumentation::didReceiveData(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const char* data, int dataLength)
964 {
965     FAST_RETURN_IF_NO_FRONTENDS(void());
966     didReceiveDataImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, data, dataLength, dataLength);
967 }
968
969 inline void InspectorInstrumentation::didFinishLoading(Frame* frame, DocumentLoader* loader, unsigned long identifier, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
970 {
971     FAST_RETURN_IF_NO_FRONTENDS(void());
972     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
973         didFinishLoadingImpl(*instrumentingAgents, identifier, loader, networkLoadMetrics, resourceLoader);
974 }
975
976 inline void InspectorInstrumentation::didFinishLoading(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const NetworkLoadMetrics& networkLoadMetrics)
977 {
978     FAST_RETURN_IF_NO_FRONTENDS(void());
979     didFinishLoadingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, networkLoadMetrics, nullptr);
980 }
981
982 inline void InspectorInstrumentation::didFailLoading(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
983 {
984     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
985         didFailLoadingImpl(*instrumentingAgents, identifier, loader, error);
986 }
987
988 inline void InspectorInstrumentation::didFailLoading(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const ResourceError& error)
989 {
990     didFailLoadingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, error);
991 }
992
993 inline void InspectorInstrumentation::continueAfterXFrameOptionsDenied(Frame& frame, unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response)
994 {
995     // Treat the same as didReceiveResponse.
996     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
997         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, &loader, response, nullptr);
998 }
999
1000 inline void InspectorInstrumentation::continueWithPolicyDownload(Frame& frame, unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response)
1001 {
1002     // Treat the same as didReceiveResponse.
1003     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1004         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, &loader, response, nullptr);
1005 }
1006
1007 inline void InspectorInstrumentation::continueWithPolicyIgnore(Frame& frame, unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response)
1008 {
1009     // Treat the same as didReceiveResponse.
1010     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1011         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, &loader, response, nullptr);
1012 }
1013
1014 inline void InspectorInstrumentation::didFinishXHRLoading(ScriptExecutionContext* context, unsigned long identifier, std::optional<String> decodedText)
1015 {
1016     FAST_RETURN_IF_NO_FRONTENDS(void());
1017     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1018         didFinishXHRLoadingImpl(*instrumentingAgents, identifier, decodedText);
1019 }
1020
1021 inline void InspectorInstrumentation::willLoadXHRSynchronously(ScriptExecutionContext* context)
1022 {
1023     FAST_RETURN_IF_NO_FRONTENDS(void());
1024     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1025         willLoadXHRSynchronouslyImpl(*instrumentingAgents);
1026 }
1027
1028 inline void InspectorInstrumentation::didLoadXHRSynchronously(ScriptExecutionContext* context)
1029 {
1030     FAST_RETURN_IF_NO_FRONTENDS(void());
1031     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1032         didLoadXHRSynchronouslyImpl(*instrumentingAgents);
1033 }
1034
1035 inline void InspectorInstrumentation::scriptImported(ScriptExecutionContext& context, unsigned long identifier, const String& sourceString)
1036 {
1037     FAST_RETURN_IF_NO_FRONTENDS(void());
1038     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1039         scriptImportedImpl(*instrumentingAgents, identifier, sourceString);
1040 }
1041
1042 inline void InspectorInstrumentation::scriptExecutionBlockedByCSP(ScriptExecutionContext* context, const String& directiveText)
1043 {
1044     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1045         scriptExecutionBlockedByCSPImpl(*instrumentingAgents, directiveText);
1046 }
1047
1048 inline void InspectorInstrumentation::didReceiveScriptResponse(ScriptExecutionContext* context, unsigned long identifier)
1049 {
1050     FAST_RETURN_IF_NO_FRONTENDS(void());
1051     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1052         didReceiveScriptResponseImpl(*instrumentingAgents, identifier);
1053 }
1054
1055 inline void InspectorInstrumentation::domContentLoadedEventFired(Frame& frame)
1056 {
1057     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1058         domContentLoadedEventFiredImpl(*instrumentingAgents, frame);
1059 }
1060
1061 inline void InspectorInstrumentation::loadEventFired(Frame* frame)
1062 {
1063     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1064         loadEventFiredImpl(*instrumentingAgents, frame);
1065 }
1066
1067 inline void InspectorInstrumentation::frameDetachedFromParent(Frame& frame)
1068 {
1069     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1070         frameDetachedFromParentImpl(*instrumentingAgents, frame);
1071 }
1072
1073 inline void InspectorInstrumentation::didCommitLoad(Frame& frame, DocumentLoader* loader)
1074 {
1075     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1076         didCommitLoadImpl(*instrumentingAgents, frame, loader);
1077 }
1078
1079 inline void InspectorInstrumentation::frameDocumentUpdated(Frame& frame)
1080 {
1081     FAST_RETURN_IF_NO_FRONTENDS(void());
1082     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1083         frameDocumentUpdatedImpl(*instrumentingAgents, frame);
1084 }
1085
1086 inline void InspectorInstrumentation::loaderDetachedFromFrame(Frame& frame, DocumentLoader& loader)
1087 {
1088     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1089         loaderDetachedFromFrameImpl(*instrumentingAgents, loader);
1090 }
1091
1092 inline void InspectorInstrumentation::frameStartedLoading(Frame& frame)
1093 {
1094     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1095         frameStartedLoadingImpl(*instrumentingAgents, frame);
1096 }
1097
1098 inline void InspectorInstrumentation::frameStoppedLoading(Frame& frame)
1099 {
1100     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1101         frameStoppedLoadingImpl(*instrumentingAgents, frame);
1102 }
1103
1104 inline void InspectorInstrumentation::frameScheduledNavigation(Frame& frame, Seconds delay)
1105 {
1106     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1107         frameScheduledNavigationImpl(*instrumentingAgents, frame, delay);
1108 }
1109
1110 inline void InspectorInstrumentation::frameClearedScheduledNavigation(Frame& frame)
1111 {
1112     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1113         frameClearedScheduledNavigationImpl(*instrumentingAgents, frame);
1114 }
1115
1116 inline void InspectorInstrumentation::willDestroyCachedResource(CachedResource& cachedResource)
1117 {
1118     FAST_RETURN_IF_NO_FRONTENDS(void());
1119     willDestroyCachedResourceImpl(cachedResource);
1120 }
1121
1122 inline void InspectorInstrumentation::didOpenDatabase(ScriptExecutionContext* context, RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
1123 {
1124     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1125         didOpenDatabaseImpl(*instrumentingAgents, WTFMove(database), domain, name, version);
1126 }
1127
1128 inline void InspectorInstrumentation::didDispatchDOMStorageEvent(Page& page, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin)
1129 {
1130     FAST_RETURN_IF_NO_FRONTENDS(void());
1131     didDispatchDOMStorageEventImpl(instrumentingAgentsForPage(page), key, oldValue, newValue, storageType, securityOrigin);
1132 }
1133
1134 inline bool InspectorInstrumentation::shouldWaitForDebuggerOnStart(ScriptExecutionContext& context)
1135 {
1136     FAST_RETURN_IF_NO_FRONTENDS(false);
1137     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1138         return shouldWaitForDebuggerOnStartImpl(*instrumentingAgents);
1139     return false;
1140 }
1141
1142 inline void InspectorInstrumentation::workerStarted(ScriptExecutionContext& context, WorkerInspectorProxy* proxy, const URL& url)
1143 {
1144     FAST_RETURN_IF_NO_FRONTENDS(void());
1145     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1146         workerStartedImpl(*instrumentingAgents, proxy, url);
1147 }
1148
1149 inline void InspectorInstrumentation::workerTerminated(ScriptExecutionContext& context, WorkerInspectorProxy* proxy)
1150 {
1151     FAST_RETURN_IF_NO_FRONTENDS(void());
1152     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
1153         workerTerminatedImpl(*instrumentingAgents, proxy);
1154 }
1155
1156 inline void InspectorInstrumentation::didCreateWebSocket(Document* document, unsigned long identifier, const URL& requestURL)
1157 {
1158     FAST_RETURN_IF_NO_FRONTENDS(void());
1159     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1160         didCreateWebSocketImpl(*instrumentingAgents, identifier, requestURL);
1161 }
1162
1163 inline void InspectorInstrumentation::willSendWebSocketHandshakeRequest(Document* document, unsigned long identifier, const ResourceRequest& request)
1164 {
1165     FAST_RETURN_IF_NO_FRONTENDS(void());
1166     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1167         willSendWebSocketHandshakeRequestImpl(*instrumentingAgents, identifier, request);
1168 }
1169
1170 inline void InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(Document* document, unsigned long identifier, const ResourceResponse& response)
1171 {
1172     FAST_RETURN_IF_NO_FRONTENDS(void());
1173     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1174         didReceiveWebSocketHandshakeResponseImpl(*instrumentingAgents, identifier, response);
1175 }
1176
1177 inline void InspectorInstrumentation::didCloseWebSocket(Document* document, unsigned long identifier)
1178 {
1179     FAST_RETURN_IF_NO_FRONTENDS(void());
1180     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1181         didCloseWebSocketImpl(*instrumentingAgents, identifier);
1182 }
1183
1184 inline void InspectorInstrumentation::didReceiveWebSocketFrame(Document* document, unsigned long identifier, const WebSocketFrame& frame)
1185 {
1186     FAST_RETURN_IF_NO_FRONTENDS(void());
1187     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1188         didReceiveWebSocketFrameImpl(*instrumentingAgents, identifier, frame);
1189 }
1190
1191 inline void InspectorInstrumentation::didReceiveWebSocketFrameError(Document* document, unsigned long identifier, const String& errorMessage)
1192 {
1193     FAST_RETURN_IF_NO_FRONTENDS(void());
1194     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1195         didReceiveWebSocketFrameErrorImpl(*instrumentingAgents, identifier, errorMessage);
1196 }
1197
1198 inline void InspectorInstrumentation::didSendWebSocketFrame(Document* document, unsigned long identifier, const WebSocketFrame& frame)
1199 {
1200     FAST_RETURN_IF_NO_FRONTENDS(void());
1201     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1202         didSendWebSocketFrameImpl(*instrumentingAgents, identifier, frame);
1203 }
1204
1205 #if ENABLE(RESOURCE_USAGE)
1206 inline void InspectorInstrumentation::didHandleMemoryPressure(Page& page, Critical critical)
1207 {
1208     FAST_RETURN_IF_NO_FRONTENDS(void());
1209     didHandleMemoryPressureImpl(instrumentingAgentsForPage(page), critical);
1210 }
1211 #endif
1212
1213 inline void InspectorInstrumentation::didCreateCSSCanvas(HTMLCanvasElement& canvasElement, const String& name)
1214 {
1215     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
1216         didCreateCSSCanvasImpl(*instrumentingAgents, canvasElement, name);
1217 }
1218
1219 inline void InspectorInstrumentation::didChangeCSSCanvasClientNodes(HTMLCanvasElement& canvasElement)
1220 {
1221     FAST_RETURN_IF_NO_FRONTENDS(void());
1222     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
1223         didChangeCSSCanvasClientNodesImpl(*instrumentingAgents, canvasElement);
1224 }
1225
1226 inline void InspectorInstrumentation::didCreateCanvasRenderingContext(HTMLCanvasElement& canvasElement)
1227 {
1228     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
1229         didCreateCanvasRenderingContextImpl(*instrumentingAgents, canvasElement);
1230 }
1231
1232 inline void InspectorInstrumentation::didChangeCanvasMemory(HTMLCanvasElement& canvasElement)
1233 {
1234     FAST_RETURN_IF_NO_FRONTENDS(void());
1235     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
1236         didChangeCanvasMemoryImpl(*instrumentingAgents, canvasElement);
1237 }
1238
1239 inline void InspectorInstrumentation::recordCanvasAction(CanvasRenderingContext& canvasRenderingContext, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
1240 {
1241     FAST_RETURN_IF_NO_FRONTENDS(void());
1242     auto& canvasBase = canvasRenderingContext.canvasBase();
1243     auto* canvasElement = is<HTMLCanvasElement>(canvasBase) ? &downcast<HTMLCanvasElement>(canvasBase) : nullptr;
1244     if (canvasElement) {
1245         if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement->document()))
1246             recordCanvasActionImpl(*instrumentingAgents, canvasRenderingContext, name, WTFMove(parameters));
1247     }
1248 }
1249
1250 inline void InspectorInstrumentation::didFinishRecordingCanvasFrame(HTMLCanvasElement& canvasElement, bool forceDispatch)
1251 {
1252     FAST_RETURN_IF_NO_FRONTENDS(void());
1253     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
1254         didFinishRecordingCanvasFrameImpl(*instrumentingAgents, canvasElement, forceDispatch);
1255 }
1256
1257 #if ENABLE(WEBGL)
1258 inline void InspectorInstrumentation::didEnableExtension(WebGLRenderingContextBase& context, const String& extension)
1259 {
1260     FAST_RETURN_IF_NO_FRONTENDS(void());
1261     auto canvas = context.canvas();
1262     WTF::switchOn(canvas,
1263         [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
1264             if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
1265                 didEnableExtensionImpl(*instrumentingAgents, context, extension);
1266         },
1267         [&] (const RefPtr<OffscreenCanvas>&) {
1268         }
1269     );
1270 }
1271
1272 inline void InspectorInstrumentation::didCreateProgram(WebGLRenderingContextBase& context, WebGLProgram& program)
1273 {
1274     auto canvas = context.canvas();
1275     WTF::switchOn(canvas,
1276         [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
1277             if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
1278                 didCreateProgramImpl(*instrumentingAgents, context, program);
1279         },
1280         [&] (const RefPtr<OffscreenCanvas>&) {
1281         }
1282     );
1283 }
1284
1285 inline void InspectorInstrumentation::willDeleteProgram(WebGLRenderingContextBase& context, WebGLProgram& program)
1286 {
1287     auto canvas = context.canvas();
1288     WTF::switchOn(canvas,
1289         [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
1290             if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
1291                 willDeleteProgramImpl(*instrumentingAgents, program);
1292         },
1293         [&] (const RefPtr<OffscreenCanvas>&) {
1294         }
1295     );
1296 }
1297
1298 inline bool InspectorInstrumentation::isShaderProgramDisabled(WebGLRenderingContextBase& context, WebGLProgram& program)
1299 {
1300     FAST_RETURN_IF_NO_FRONTENDS(false);
1301     auto canvas = context.canvas();
1302     return WTF::switchOn(canvas,
1303         [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
1304             if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
1305                 return isShaderProgramDisabledImpl(*instrumentingAgents, program);
1306             return false;
1307         },
1308         [&] (const RefPtr<OffscreenCanvas>&) {
1309             return false;
1310         }
1311     );
1312 }
1313 #endif
1314
1315 inline void InspectorInstrumentation::networkStateChanged(Page& page)
1316 {
1317     FAST_RETURN_IF_NO_FRONTENDS(void());
1318     networkStateChangedImpl(instrumentingAgentsForPage(page));
1319 }
1320
1321 inline void InspectorInstrumentation::updateApplicationCacheStatus(Frame* frame)
1322 {
1323     FAST_RETURN_IF_NO_FRONTENDS(void());
1324     if (auto* instrumentingAgents = instrumentingAgentsForFrame(frame))
1325         updateApplicationCacheStatusImpl(*instrumentingAgents, *frame);
1326 }
1327
1328 inline void InspectorInstrumentation::addMessageToConsole(Page& page, std::unique_ptr<Inspector::ConsoleMessage> message)
1329 {
1330     addMessageToConsoleImpl(instrumentingAgentsForPage(page), WTFMove(message));
1331 }
1332
1333 inline void InspectorInstrumentation::addMessageToConsole(WorkerGlobalScope& workerGlobalScope, std::unique_ptr<Inspector::ConsoleMessage> message)
1334 {
1335     addMessageToConsoleImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), WTFMove(message));
1336 }
1337
1338 inline void InspectorInstrumentation::consoleCount(Page& page, JSC::ExecState* state, Ref<Inspector::ScriptArguments>&& arguments)
1339 {
1340     consoleCountImpl(instrumentingAgentsForPage(page), state, WTFMove(arguments));
1341 }
1342
1343 inline void InspectorInstrumentation::consoleCount(WorkerGlobalScope& workerGlobalScope, JSC::ExecState* state, Ref<Inspector::ScriptArguments>&& arguments)
1344 {
1345     consoleCountImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), state, WTFMove(arguments));
1346 }
1347
1348 inline void InspectorInstrumentation::takeHeapSnapshot(Frame& frame, const String& title)
1349 {
1350     FAST_RETURN_IF_NO_FRONTENDS(void());
1351     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1352         takeHeapSnapshotImpl(*instrumentingAgents, title);
1353 }
1354
1355 inline void InspectorInstrumentation::startConsoleTiming(Frame& frame, const String& title)
1356 {
1357     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1358         startConsoleTimingImpl(*instrumentingAgents, frame, title);
1359 }
1360
1361 inline void InspectorInstrumentation::startConsoleTiming(WorkerGlobalScope& workerGlobalScope, const String& title)
1362 {
1363     startConsoleTimingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), title);
1364 }
1365
1366 inline void InspectorInstrumentation::stopConsoleTiming(Frame& frame, const String& title, Ref<Inspector::ScriptCallStack>&& stack)
1367 {
1368     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1369         stopConsoleTimingImpl(*instrumentingAgents, frame, title, WTFMove(stack));
1370 }
1371
1372 inline void InspectorInstrumentation::stopConsoleTiming(WorkerGlobalScope& workerGlobalScope, const String& title, Ref<Inspector::ScriptCallStack>&& stack)
1373 {
1374     stopConsoleTimingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), title, WTFMove(stack));
1375 }
1376
1377 inline void InspectorInstrumentation::consoleTimeStamp(Frame& frame, Ref<Inspector::ScriptArguments>&& arguments)
1378 {
1379     FAST_RETURN_IF_NO_FRONTENDS(void());
1380     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
1381         consoleTimeStampImpl(*instrumentingAgents, frame, WTFMove(arguments));
1382 }
1383
1384 inline void InspectorInstrumentation::startProfiling(Page& page, JSC::ExecState* exec, const String &title)
1385 {
1386     startProfilingImpl(instrumentingAgentsForPage(page), exec, title);
1387 }
1388
1389 inline void InspectorInstrumentation::stopProfiling(Page& page, JSC::ExecState* exec, const String &title)
1390 {
1391     stopProfilingImpl(instrumentingAgentsForPage(page), exec, title);
1392 }
1393
1394 inline void InspectorInstrumentation::consoleStartRecordingCanvas(HTMLCanvasElement& canvasElement, JSC::ExecState& exec, JSC::JSObject* options)
1395 {
1396     FAST_RETURN_IF_NO_FRONTENDS(void());
1397     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
1398         consoleStartRecordingCanvasImpl(*instrumentingAgents, canvasElement, exec, options);
1399 }
1400
1401 inline void InspectorInstrumentation::didRequestAnimationFrame(Document& document, int callbackId)
1402 {
1403     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1404         didRequestAnimationFrameImpl(*instrumentingAgents, callbackId, document);
1405 }
1406
1407 inline void InspectorInstrumentation::didCancelAnimationFrame(Document& document, int callbackId)
1408 {
1409     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1410         didCancelAnimationFrameImpl(*instrumentingAgents, callbackId, document);
1411 }
1412
1413 inline InspectorInstrumentationCookie InspectorInstrumentation::willFireAnimationFrame(Document& document, int callbackId)
1414 {
1415     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1416         return willFireAnimationFrameImpl(*instrumentingAgents, callbackId, document);
1417     return InspectorInstrumentationCookie();
1418 }
1419
1420 inline void InspectorInstrumentation::didFireAnimationFrame(const InspectorInstrumentationCookie& cookie)
1421 {
1422     FAST_RETURN_IF_NO_FRONTENDS(void());
1423     if (cookie.isValid())
1424         didFireAnimationFrameImpl(cookie);
1425 }
1426
1427 inline void InspectorInstrumentation::layerTreeDidChange(Page* page)
1428 {
1429     FAST_RETURN_IF_NO_FRONTENDS(void());
1430     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
1431         layerTreeDidChangeImpl(*instrumentingAgents);
1432 }
1433
1434 inline void InspectorInstrumentation::renderLayerDestroyed(Page* page, const RenderLayer& renderLayer)
1435 {
1436     FAST_RETURN_IF_NO_FRONTENDS(void());
1437     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
1438         renderLayerDestroyedImpl(*instrumentingAgents, renderLayer);
1439 }
1440
1441 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForContext(ScriptExecutionContext* context)
1442 {
1443     return context ? instrumentingAgentsForContext(*context) : nullptr;
1444 }
1445
1446 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForContext(ScriptExecutionContext& context)
1447 {
1448     if (is<Document>(context))
1449         return instrumentingAgentsForPage(downcast<Document>(context).page());
1450     if (is<WorkerGlobalScope>(context))
1451         return &instrumentingAgentsForWorkerGlobalScope(downcast<WorkerGlobalScope>(context));
1452     return nullptr;
1453 }
1454
1455 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForFrame(Frame* frame)
1456 {
1457     return frame ? instrumentingAgentsForFrame(*frame) : nullptr;
1458 }
1459
1460 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForFrame(Frame& frame)
1461 {
1462     return instrumentingAgentsForPage(frame.page());
1463 }
1464
1465 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForDocument(Document* document)
1466 {
1467     return document ? instrumentingAgentsForDocument(*document) : nullptr;
1468 }
1469
1470 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForDocument(Document& document)
1471 {
1472     Page* page = document.page();
1473     if (!page && document.templateDocumentHost())
1474         page = document.templateDocumentHost()->page();
1475     return instrumentingAgentsForPage(page);
1476 }
1477
1478 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForPage(Page* page)
1479 {
1480     return page ? &instrumentingAgentsForPage(*page) : nullptr;
1481 }
1482
1483 inline InstrumentingAgents& InspectorInstrumentation::instrumentingAgentsForPage(Page& page)
1484 {
1485     ASSERT(isMainThread());
1486     return page.inspectorController().m_instrumentingAgents.get();
1487 }
1488
1489 inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope* workerGlobalScope)
1490 {
1491     return workerGlobalScope ? &instrumentingAgentsForWorkerGlobalScope(*workerGlobalScope) : nullptr;
1492 }
1493
1494 inline InstrumentingAgents& InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope& workerGlobalScope)
1495 {
1496     return workerGlobalScope.inspectorController().m_instrumentingAgents;
1497 }
1498
1499 inline void InspectorInstrumentation::frontendCreated()
1500 {
1501     s_frontendCounter++;
1502
1503     if (s_frontendCounter == 1)
1504         InspectorInstrumentation::firstFrontendCreated();
1505 }
1506
1507 inline void InspectorInstrumentation::frontendDeleted()
1508 {
1509     s_frontendCounter--;
1510
1511     if (!s_frontendCounter)
1512         InspectorInstrumentation::lastFrontendDeleted();
1513 }
1514
1515 } // namespace WebCore