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