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