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