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