Remove TimelineTraceEventProcessor since no current ports use it
[WebKit-https.git] / Source / WebCore / inspector / InspectorInstrumentation.cpp
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #if ENABLE(INSPECTOR)
34
35 #include "InspectorInstrumentation.h"
36
37 #include "CSSRule.h"
38 #include "CSSStyleRule.h"
39 #include "ConsoleAPITypes.h"
40 #include "ConsoleTypes.h"
41 #include "DOMWindow.h"
42 #include "DOMWrapperWorld.h"
43 #include "Database.h"
44 #include "DeviceOrientationData.h"
45 #include "DocumentLoader.h"
46 #include "Event.h"
47 #include "EventContext.h"
48 #include "InspectorAgent.h"
49 #include "InspectorApplicationCacheAgent.h"
50 #include "InspectorCSSAgent.h"
51 #include "InspectorCanvasAgent.h"
52 #include "InspectorConsoleAgent.h"
53 #include "InspectorController.h"
54 #include "InspectorDOMAgent.h"
55 #include "InspectorDOMDebuggerAgent.h"
56 #include "InspectorDOMStorageAgent.h"
57 #include "InspectorDatabaseAgent.h"
58 #include "InspectorDebuggerAgent.h"
59 #include "InspectorHeapProfilerAgent.h"
60 #include "InspectorLayerTreeAgent.h"
61 #include "InspectorPageAgent.h"
62 #include "InspectorProfilerAgent.h"
63 #include "InspectorResourceAgent.h"
64 #include "InspectorTimelineAgent.h"
65 #include "InspectorWorkerAgent.h"
66 #include "InstrumentingAgents.h"
67 #include "PageDebuggerAgent.h"
68 #include "PageRuntimeAgent.h"
69 #include "RenderObject.h"
70 #include "RenderView.h"
71 #include "ScriptArguments.h"
72 #include "ScriptCallStack.h"
73 #include "ScriptController.h"
74 #include "ScriptProfile.h"
75 #include "StyleResolver.h"
76 #include "StyleRule.h"
77 #include "WorkerGlobalScope.h"
78 #include "WorkerInspectorController.h"
79 #include "WorkerRuntimeAgent.h"
80 #include "WorkerThread.h"
81 #include "XMLHttpRequest.h"
82 #include <wtf/StdLibExtras.h>
83 #include <wtf/text/CString.h>
84
85 namespace WebCore {
86
87 static const char* const requestAnimationFrameEventName = "requestAnimationFrame";
88 static const char* const cancelAnimationFrameEventName = "cancelAnimationFrame";
89 static const char* const animationFrameFiredEventName = "animationFrameFired";
90 static const char* const setTimerEventName = "setTimer";
91 static const char* const clearTimerEventName = "clearTimer";
92 static const char* const timerFiredEventName = "timerFired";
93
94 namespace {
95 static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0;
96 }
97
98 int InspectorInstrumentation::s_frontendCounter = 0;
99
100 static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const EventPath& eventPath)
101 {
102     if (window && window->hasEventListeners(eventType))
103         return true;
104
105     if (node->hasEventListeners(eventType))
106         return true;
107
108     for (size_t i = 0; i < eventPath.size(); i++) {
109         if (eventPath[i]->node()->hasEventListeners(eventType))
110             return true;
111     }
112
113     return false;
114 }
115
116 static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
117 {
118     Frame* frame = 0;
119     if (context->isDocument())
120         frame = toDocument(context)->frame();
121     return frame;
122 }
123
124 InspectorInstrumentationCookie::InspectorInstrumentationCookie()
125     : m_instrumentingAgents(0)
126     , m_timelineAgentId(0)
127 {
128 }
129
130 InspectorInstrumentationCookie::InspectorInstrumentationCookie(InstrumentingAgents* agents, int timelineAgentId)
131     : m_instrumentingAgents(agents)
132     , m_timelineAgentId(timelineAgentId)
133 {
134 }
135
136 InspectorInstrumentationCookie::InspectorInstrumentationCookie(const InspectorInstrumentationCookie& other)
137     : m_instrumentingAgents(other.m_instrumentingAgents)
138     , m_timelineAgentId(other.m_timelineAgentId)
139 {
140 }
141
142 InspectorInstrumentationCookie& InspectorInstrumentationCookie::operator=(const InspectorInstrumentationCookie& other)
143 {
144     if (this != &other) {
145         m_instrumentingAgents = other.m_instrumentingAgents;
146         m_timelineAgentId = other.m_timelineAgentId;
147     }
148     return *this;
149 }
150
151 InspectorInstrumentationCookie::~InspectorInstrumentationCookie()
152 {
153 }
154
155 void InspectorInstrumentation::didClearWindowObjectInWorldImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, DOMWrapperWorld* world)
156 {
157     InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent();
158     if (pageAgent)
159         pageAgent->didClearWindowObjectInWorld(frame, world);
160     if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
161         inspectorAgent->didClearWindowObjectInWorld(frame, world);
162 #if ENABLE(JAVASCRIPT_DEBUGGER)
163     if (PageDebuggerAgent* debuggerAgent = instrumentingAgents->pageDebuggerAgent()) {
164         if (pageAgent && world == mainThreadNormalWorld() && frame == pageAgent->mainFrame())
165             debuggerAgent->didClearMainFrameWindowObject();
166     }
167 #endif
168     if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents->pageRuntimeAgent()) {
169         if (world == mainThreadNormalWorld())
170             pageRuntimeAgent->didCreateMainWorldContext(frame);
171     }
172 }
173
174 bool InspectorInstrumentation::isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents)
175 {
176 #if ENABLE(JAVASCRIPT_DEBUGGER)
177     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
178         return debuggerAgent->isPaused();
179 #endif
180     return false;
181 }
182
183 void InspectorInstrumentation::willInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* parent)
184 {
185 #if ENABLE(JAVASCRIPT_DEBUGGER)
186     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
187         domDebuggerAgent->willInsertDOMNode(parent);
188 #endif
189 }
190
191 void InspectorInstrumentation::didInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
192 {
193     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
194         domAgent->didInsertDOMNode(node);
195 #if ENABLE(JAVASCRIPT_DEBUGGER)
196     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
197         domDebuggerAgent->didInsertDOMNode(node);
198 #endif
199 }
200
201 void InspectorInstrumentation::willRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
202 {
203 #if ENABLE(JAVASCRIPT_DEBUGGER)
204     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
205         domDebuggerAgent->willRemoveDOMNode(node);
206 #endif
207 }
208
209 void InspectorInstrumentation::didRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
210 {
211 #if ENABLE(JAVASCRIPT_DEBUGGER)
212     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
213         domDebuggerAgent->didRemoveDOMNode(node);
214 #endif
215     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
216         domAgent->didRemoveDOMNode(node);
217 }
218
219 void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& oldValue, const AtomicString& newValue)
220 {
221 #if ENABLE(JAVASCRIPT_DEBUGGER)
222     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
223         domDebuggerAgent->willModifyDOMAttr(element);
224     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
225         domAgent->willModifyDOMAttr(element, oldValue, newValue);
226 #endif
227 }
228
229 void InspectorInstrumentation::didModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name, const AtomicString& value)
230 {
231     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
232         domAgent->didModifyDOMAttr(element, name, value);
233 }
234
235 void InspectorInstrumentation::didRemoveDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name)
236 {
237     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
238         domAgent->didRemoveDOMAttr(element, name);
239 }
240
241 void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents* instrumentingAgents, Node* node)
242 {
243     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
244         domAgent->didInvalidateStyleAttr(node);
245 #if ENABLE(JAVASCRIPT_DEBUGGER)
246     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
247         domDebuggerAgent->didInvalidateStyleAttr(node);
248 #endif
249 }
250
251 void InspectorInstrumentation::frameWindowDiscardedImpl(InstrumentingAgents* instrumentingAgents, DOMWindow* window)
252 {
253     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
254         consoleAgent->frameWindowDiscarded(window);
255 }
256
257 void InspectorInstrumentation::mediaQueryResultChangedImpl(InstrumentingAgents* instrumentingAgents)
258 {
259     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
260         cssAgent->mediaQueryResultChanged();
261 }
262
263 void InspectorInstrumentation::didPushShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
264 {
265     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
266         domAgent->didPushShadowRoot(host, root);
267 }
268
269 void InspectorInstrumentation::willPopShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
270 {
271     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
272         domAgent->willPopShadowRoot(host, root);
273 }
274
275 void InspectorInstrumentation::didCreateNamedFlowImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
276 {
277     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
278         cssAgent->didCreateNamedFlow(document, namedFlow);
279 }
280
281 void InspectorInstrumentation::willRemoveNamedFlowImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
282 {
283     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
284         cssAgent->willRemoveNamedFlow(document, namedFlow);
285 }
286
287 void InspectorInstrumentation::didUpdateRegionLayoutImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
288 {
289     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
290         cssAgent->didUpdateRegionLayout(document, namedFlow);
291 }
292
293 void InspectorInstrumentation::didChangeRegionOversetImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
294 {
295     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
296         cssAgent->didChangeRegionOverset(document, namedFlow);
297 }
298
299 void InspectorInstrumentation::mouseDidMoveOverElementImpl(InstrumentingAgents* instrumentingAgents, const HitTestResult& result, unsigned modifierFlags)
300 {
301     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
302         domAgent->mouseDidMoveOverElement(result, modifierFlags);
303 }
304
305 void InspectorInstrumentation::didScrollImpl(InstrumentingAgents* instrumentingAgents)
306 {
307     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
308         pageAgent->didScroll();
309 }
310
311 bool InspectorInstrumentation::handleTouchEventImpl(InstrumentingAgents* instrumentingAgents, Node* node)
312 {
313     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
314         return domAgent->handleTouchEvent(node);
315     return false;
316 }
317
318 bool InspectorInstrumentation::handleMousePressImpl(InstrumentingAgents* instrumentingAgents)
319 {
320     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
321         return domAgent->handleMousePress();
322     return false;
323 }
324
325 bool InspectorInstrumentation::forcePseudoStateImpl(InstrumentingAgents* instrumentingAgents, Element* element, CSSSelector::PseudoType pseudoState)
326 {
327     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
328         return cssAgent->forcePseudoState(element, pseudoState);
329     return false;
330 }
331
332 void InspectorInstrumentation::characterDataModifiedImpl(InstrumentingAgents* instrumentingAgents, CharacterData* characterData)
333 {
334     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
335         domAgent->characterDataModified(characterData);
336 }
337
338 void InspectorInstrumentation::willSendXMLHttpRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url)
339 {
340 #if ENABLE(JAVASCRIPT_DEBUGGER)
341     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
342         domDebuggerAgent->willSendXMLHttpRequest(url);
343 #endif
344 }
345
346 void InspectorInstrumentation::didScheduleResourceRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url, Frame* frame)
347 {
348     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
349         timelineAgent->didScheduleResourceRequest(url, frame);
350 }
351
352 void InspectorInstrumentation::didInstallTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, int timeout, bool singleShot, ScriptExecutionContext* context)
353 {
354     pauseOnNativeEventIfNeeded(instrumentingAgents, false, setTimerEventName, true);
355     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
356         timelineAgent->didInstallTimer(timerId, timeout, singleShot, frameForScriptExecutionContext(context));
357 }
358
359 void InspectorInstrumentation::didRemoveTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
360 {
361     pauseOnNativeEventIfNeeded(instrumentingAgents, false, clearTimerEventName, true);
362     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
363         timelineAgent->didRemoveTimer(timerId, frameForScriptExecutionContext(context));
364 }
365
366 InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents* instrumentingAgents, const String& scriptName, int scriptLine, ScriptExecutionContext* context)
367 {
368     int timelineAgentId = 0;
369     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
370         timelineAgent->willCallFunction(scriptName, scriptLine, frameForScriptExecutionContext(context));
371         timelineAgentId = timelineAgent->id();
372     }
373     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
374 }
375
376 void InspectorInstrumentation::didCallFunctionImpl(const InspectorInstrumentationCookie& cookie)
377 {
378     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
379         timelineAgent->didCallFunction();
380 }
381
382 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRReadyStateChangeEventImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
383 {
384     int timelineAgentId = 0;
385     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
386     if (timelineAgent && request->hasEventListeners(eventNames().readystatechangeEvent)) {
387         timelineAgent->willDispatchXHRReadyStateChangeEvent(request->url().string(), request->readyState(), frameForScriptExecutionContext(context));
388         timelineAgentId = timelineAgent->id();
389     }
390     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
391 }
392
393 void InspectorInstrumentation::didDispatchXHRReadyStateChangeEventImpl(const InspectorInstrumentationCookie& cookie)
394 {
395     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
396         timelineAgent->didDispatchXHRReadyStateChangeEvent();
397 }
398
399 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window, Node* node, const EventPath& eventPath, Document* document)
400 {
401     int timelineAgentId = 0;
402     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
403     if (timelineAgent && eventHasListeners(event.type(), window, node, eventPath)) {
404         timelineAgent->willDispatchEvent(event, document->frame());
405         timelineAgentId = timelineAgent->id();
406     }
407     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
408 }
409
410 InspectorInstrumentationCookie InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents* instrumentingAgents, Event* event)
411 {
412     pauseOnNativeEventIfNeeded(instrumentingAgents, true, event->type(), false);
413     return InspectorInstrumentationCookie(instrumentingAgents, 0);
414 }
415
416 void InspectorInstrumentation::didHandleEventImpl(const InspectorInstrumentationCookie& cookie)
417 {
418     cancelPauseOnNativeEvent(cookie.instrumentingAgents());
419 }
420
421 void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)
422 {
423     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
424         timelineAgent->didDispatchEvent();
425 }
426
427 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window)
428 {
429     int timelineAgentId = 0;
430     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
431     if (timelineAgent && window->hasEventListeners(event.type())) {
432         timelineAgent->willDispatchEvent(event, window ? window->frame() : 0);
433         timelineAgentId = timelineAgent->id();
434     }
435     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
436 }
437
438 void InspectorInstrumentation::didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie& cookie)
439 {
440     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
441         timelineAgent->didDispatchEvent();
442 }
443
444 InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InstrumentingAgents* instrumentingAgents, const String& url, int lineNumber, Frame* frame)
445 {
446     int timelineAgentId = 0;
447     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
448         timelineAgent->willEvaluateScript(url, lineNumber, frame);
449         timelineAgentId = timelineAgent->id();
450     }
451     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
452 }
453
454 void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentationCookie& cookie)
455 {
456     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
457         timelineAgent->didEvaluateScript();
458 }
459
460 void InspectorInstrumentation::scriptsEnabledImpl(InstrumentingAgents* instrumentingAgents, bool isEnabled)
461 {
462     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
463         pageAgent->scriptsEnabled(isEnabled);
464 }
465
466 void InspectorInstrumentation::didCreateIsolatedContextImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, ScriptState* scriptState, SecurityOrigin* origin)
467 {
468     if (PageRuntimeAgent* runtimeAgent = instrumentingAgents->pageRuntimeAgent())
469         runtimeAgent->didCreateIsolatedContext(frame, scriptState, origin);
470 }
471
472 InspectorInstrumentationCookie InspectorInstrumentation::willFireTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
473 {
474     pauseOnNativeEventIfNeeded(instrumentingAgents, false, timerFiredEventName, false);
475
476     int timelineAgentId = 0;
477     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
478         timelineAgent->willFireTimer(timerId, frameForScriptExecutionContext(context));
479         timelineAgentId = timelineAgent->id();
480     }
481     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
482 }
483
484 void InspectorInstrumentation::didFireTimerImpl(const InspectorInstrumentationCookie& cookie)
485 {
486     cancelPauseOnNativeEvent(cookie.instrumentingAgents());
487
488     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
489         timelineAgent->didFireTimer();
490 }
491
492 void InspectorInstrumentation::didInvalidateLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
493 {
494     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
495         timelineAgent->didInvalidateLayout(frame);
496 }
497
498 InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
499 {
500     int timelineAgentId = 0;
501     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
502         timelineAgent->willLayout(frame);
503         timelineAgentId = timelineAgent->id();
504     }
505     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
506 }
507
508 void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie, RenderObject* root)
509 {
510     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
511         timelineAgent->didLayout(root);
512
513     if (InspectorPageAgent* pageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
514         pageAgent->didLayout();
515 }
516
517 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRLoadEventImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
518 {
519     int timelineAgentId = 0;
520     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
521     if (timelineAgent && request->hasEventListeners(eventNames().loadEvent)) {
522         timelineAgent->willDispatchXHRLoadEvent(request->url(), frameForScriptExecutionContext(context));
523         timelineAgentId = timelineAgent->id();
524     }
525     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
526 }
527
528 void InspectorInstrumentation::didDispatchXHRLoadEventImpl(const InspectorInstrumentationCookie& cookie)
529 {
530     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
531         timelineAgent->didDispatchXHRLoadEvent();
532 }
533
534 void InspectorInstrumentation::willPaintImpl(InstrumentingAgents* instrumentingAgents, RenderObject* renderer)
535 {
536     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
537         timelineAgent->willPaint(&renderer->frame());
538 }
539
540 void InspectorInstrumentation::didPaintImpl(InstrumentingAgents*  instrumentingAgents, RenderObject* renderer, GraphicsContext* context, const LayoutRect& rect)
541 {
542     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
543         timelineAgent->didPaint(renderer, rect);
544     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
545         pageAgent->didPaint(context, rect);
546 }
547
548 void InspectorInstrumentation::willScrollLayerImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
549 {
550     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
551         timelineAgent->willScroll(frame);
552 }
553
554 void InspectorInstrumentation::didScrollLayerImpl(InstrumentingAgents* instrumentingAgents)
555 {
556     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
557         timelineAgent->didScroll();
558 }
559
560 InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
561 {
562     int timelineAgentId = 0;
563     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
564         timelineAgent->willRecalculateStyle(frame);
565         timelineAgentId = timelineAgent->id();
566     }
567     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
568         resourceAgent->willRecalculateStyle();
569     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
570 }
571
572 void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrumentationCookie& cookie)
573 {
574     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
575         timelineAgent->didRecalculateStyle();
576     InstrumentingAgents* instrumentingAgents = cookie.instrumentingAgents();
577     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
578         resourceAgent->didRecalculateStyle();
579     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
580         pageAgent->didRecalculateStyle();
581 }
582
583 void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents* instrumentingAgents, Document* document)
584 {
585     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
586         timelineAgent->didScheduleStyleRecalculation(document->frame());
587     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
588         resourceAgent->didScheduleStyleRecalculation(document);
589 }
590
591 InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* sheetCollection)
592 {
593     InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
594     if (cssAgent) {
595         cssAgent->willMatchRule(rule, inspectorCSSOMWrappers, sheetCollection);
596         return InspectorInstrumentationCookie(instrumentingAgents, 1);
597     }
598
599     return InspectorInstrumentationCookie();
600 }
601
602 void InspectorInstrumentation::didMatchRuleImpl(const InspectorInstrumentationCookie& cookie, bool matched)
603 {
604     InspectorCSSAgent* cssAgent = cookie.instrumentingAgents()->inspectorCSSAgent();
605     if (cssAgent)
606         cssAgent->didMatchRule(matched);
607 }
608
609 InspectorInstrumentationCookie InspectorInstrumentation::willProcessRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, StyleResolver& styleResolver)
610 {
611     InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
612     if (cssAgent) {
613         cssAgent->willProcessRule(rule, styleResolver);
614         return InspectorInstrumentationCookie(instrumentingAgents, 1);
615     }
616
617     return InspectorInstrumentationCookie();
618 }
619
620 void InspectorInstrumentation::didProcessRuleImpl(const InspectorInstrumentationCookie& cookie)
621 {
622     InspectorCSSAgent* cssAgent = cookie.instrumentingAgents()->inspectorCSSAgent();
623     if (cssAgent)
624         cssAgent->didProcessRule();
625 }
626
627 void InspectorInstrumentation::applyUserAgentOverrideImpl(InstrumentingAgents* instrumentingAgents, String* userAgent)
628 {
629     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
630         resourceAgent->applyUserAgentOverride(userAgent);
631 }
632
633 void InspectorInstrumentation::applyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents, long* width)
634 {
635     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
636         pageAgent->applyScreenWidthOverride(width);
637 }
638
639 void InspectorInstrumentation::applyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents, long* height)
640 {
641     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
642         pageAgent->applyScreenHeightOverride(height);
643 }
644
645 bool InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents)
646 {
647     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
648         long width = 0;
649         pageAgent->applyScreenWidthOverride(&width);
650         return !!width;
651     }
652     return false;
653 }
654
655 bool InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents)
656 {
657     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
658         long height = 0;
659         pageAgent->applyScreenHeightOverride(&height);
660         return !!height;
661     }
662     return false;
663 }
664
665 void InspectorInstrumentation::applyEmulatedMediaImpl(InstrumentingAgents* instrumentingAgents, String* media)
666 {
667     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
668         pageAgent->applyEmulatedMedia(media);
669 }
670
671 void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
672 {
673     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
674         timelineAgent->willSendResourceRequest(identifier, request, loader->frame());
675     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
676         resourceAgent->willSendRequest(identifier, loader, request, redirectResponse);
677 }
678
679 void InspectorInstrumentation::continueAfterPingLoaderImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& response)
680 {
681     willSendRequestImpl(instrumentingAgents, identifier, loader, request, response);
682 }
683
684 void InspectorInstrumentation::markResourceAsCachedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
685 {
686     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
687         resourceAgent->markResourceAsCached(identifier);
688 }
689
690 void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
691 {
692     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
693     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
694         return;
695     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
696         resourceAgent->didLoadResourceFromMemoryCache(loader, cachedResource);
697 }
698
699 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, Frame* frame, int length)
700 {
701     int timelineAgentId = 0;
702     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
703         timelineAgent->willReceiveResourceData(identifier, frame, length);
704         timelineAgentId = timelineAgent->id();
705     }
706     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
707 }
708
709 void InspectorInstrumentation::didReceiveResourceDataImpl(const InspectorInstrumentationCookie& cookie)
710 {
711     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
712         timelineAgent->didReceiveResourceData();
713 }
714
715 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Frame* frame)
716 {
717     int timelineAgentId = 0;
718     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
719     if (timelineAgent) {
720         timelineAgent->willReceiveResourceResponse(identifier, response, frame);
721         timelineAgentId = timelineAgent->id();
722     }
723     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
724 }
725
726 void InspectorInstrumentation::didReceiveResourceResponseImpl(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
727 {
728     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
729         timelineAgent->didReceiveResourceResponse();
730     if (!loader)
731         return;
732     InstrumentingAgents* instrumentingAgents = cookie.instrumentingAgents();
733     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
734         resourceAgent->didReceiveResponse(identifier, loader, response, resourceLoader);
735     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
736         consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
737 }
738
739 void InspectorInstrumentation::didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
740 {
741     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(frame, identifier, r);
742     InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r, 0);
743 }
744
745 void InspectorInstrumentation::continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
746 {
747     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
748 }
749
750 void InspectorInstrumentation::continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
751 {
752     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
753 }
754
755 void InspectorInstrumentation::continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
756 {
757     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
758 }
759
760 void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
761 {
762     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
763         resourceAgent->didReceiveData(identifier, data, dataLength, encodedDataLength);
764 }
765
766 void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, double monotonicFinishTime)
767 {
768     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
769     InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent();
770     if (!timelineAgent && !resourceAgent)
771         return;
772
773     double finishTime = 0.0;
774     // FIXME: Expose all of the timing details to inspector and have it calculate finishTime.
775     if (monotonicFinishTime)
776         finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFinishTime);
777
778     if (timelineAgent)
779         timelineAgent->didFinishLoadingResource(identifier, false, finishTime, loader->frame());
780     if (resourceAgent)
781         resourceAgent->didFinishLoading(identifier, loader, finishTime);
782 }
783
784 void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
785 {
786     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
787         timelineAgent->didFinishLoadingResource(identifier, true, 0, loader->frame());
788     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
789         resourceAgent->didFailLoading(identifier, loader, error);
790     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
791         consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
792 }
793
794 void InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClientImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, ThreadableLoaderClient* client)
795 {
796     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
797         resourceAgent->documentThreadableLoaderStartedLoadingForClient(identifier, client);
798 }
799
800 void InspectorInstrumentation::willLoadXHRImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client, const String& method, const KURL& url, bool async, PassRefPtr<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials)
801 {
802     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
803         resourceAgent->willLoadXHR(client, method, url, async, formData, headers, includeCredentials);
804 }
805
806 void InspectorInstrumentation::didFailXHRLoadingImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client)
807 {
808     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
809         resourceAgent->didFailXHRLoading(client);
810 }
811
812 void InspectorInstrumentation::didFinishXHRLoadingImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber)
813 {
814     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
815         consoleAgent->didFinishXHRLoading(identifier, url, sendURL, sendLineNumber);
816     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
817         resourceAgent->didFinishXHRLoading(client, identifier, sourceString);
818 }
819
820 void InspectorInstrumentation::didReceiveXHRResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
821 {
822     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
823         resourceAgent->didReceiveXHRResponse(identifier);
824 }
825
826 void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
827 {
828     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
829         resourceAgent->willLoadXHRSynchronously();
830 }
831
832 void InspectorInstrumentation::didLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
833 {
834     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
835         resourceAgent->didLoadXHRSynchronously();
836 }
837
838 void InspectorInstrumentation::scriptImportedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& sourceString)
839 {
840     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
841         resourceAgent->setInitialScriptContent(identifier, sourceString);
842 }
843
844 void InspectorInstrumentation::scriptExecutionBlockedByCSPImpl(InstrumentingAgents* instrumentingAgents, const String& directiveText)
845 {
846 #if ENABLE(JAVASCRIPT_DEBUGGER)
847     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
848         debuggerAgent->scriptExecutionBlockedByCSP(directiveText);
849 #endif
850 }
851
852 void InspectorInstrumentation::didReceiveScriptResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
853 {
854     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
855         resourceAgent->didReceiveScriptResponse(identifier);
856 }
857
858 void InspectorInstrumentation::domContentLoadedEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
859 {
860     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
861         timelineAgent->didMarkDOMContentEvent(frame);
862
863     if (&frame->page()->mainFrame() != frame)
864         return;
865
866     if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
867         inspectorAgent->domContentLoadedEventFired();
868
869     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
870         domAgent->mainFrameDOMContentLoaded();
871
872     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
873         pageAgent->domContentEventFired();
874 }
875
876 void InspectorInstrumentation::loadEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
877 {
878     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
879         domAgent->loadEventFired(frame->document());
880
881     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
882         timelineAgent->didMarkLoadEvent(frame);
883
884     if (&frame->page()->mainFrame() != frame)
885         return;
886
887     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
888         pageAgent->loadEventFired();
889 }
890
891 void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
892 {
893     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
894         canvasAgent->frameDetached(frame);
895     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
896         pageAgent->frameDetached(frame);
897 }
898
899 void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents* instrumentingAgents, Page* page, DocumentLoader* loader)
900 {
901     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
902     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
903         return;
904
905     if (page->frameIsMainFrame(loader->frame())) {
906         if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
907             consoleAgent->reset();
908
909         if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
910             resourceAgent->mainFrameNavigated(loader);
911 #if ENABLE(JAVASCRIPT_DEBUGGER)
912         if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
913             profilerAgent->resetState();
914         if (InspectorHeapProfilerAgent* heapProfilerAgent = instrumentingAgents->inspectorHeapProfilerAgent())
915             heapProfilerAgent->resetState();
916 #endif
917         if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
918             cssAgent->reset();
919 #if ENABLE(SQL_DATABASE)
920         if (InspectorDatabaseAgent* databaseAgent = instrumentingAgents->inspectorDatabaseAgent())
921             databaseAgent->clearResources();
922 #endif
923         if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
924             domAgent->setDocument(page->mainFrame().document());
925 #if USE(ACCELERATED_COMPOSITING)
926         if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
927             layerTreeAgent->reset();
928 #endif
929         inspectorAgent->didCommitLoad();
930     }
931     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
932         canvasAgent->frameNavigated(loader->frame());
933     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
934         pageAgent->frameNavigated(loader);
935 }
936
937 void InspectorInstrumentation::frameDocumentUpdatedImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
938 {
939     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
940     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
941         return;
942
943     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
944         domAgent->frameDocumentUpdated(frame);
945 }
946
947 void InspectorInstrumentation::loaderDetachedFromFrameImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader)
948 {
949     if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
950         inspectorPageAgent->loaderDetachedFromFrame(loader);
951 }
952
953 void InspectorInstrumentation::frameStartedLoadingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
954 {
955     if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
956         inspectorPageAgent->frameStartedLoading(frame);
957 }
958
959 void InspectorInstrumentation::frameStoppedLoadingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
960 {
961     if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
962         inspectorPageAgent->frameStoppedLoading(frame);
963 }
964
965 void InspectorInstrumentation::frameScheduledNavigationImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, double delay)
966 {
967     if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
968         inspectorPageAgent->frameScheduledNavigation(frame, delay);
969 }
970
971 void InspectorInstrumentation::frameClearedScheduledNavigationImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
972 {
973     if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
974         inspectorPageAgent->frameClearedScheduledNavigation(frame);
975 }
976
977 InspectorInstrumentationCookie InspectorInstrumentation::willRunJavaScriptDialogImpl(InstrumentingAgents* instrumentingAgents, const String& message)
978 {
979     if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
980         inspectorPageAgent->willRunJavaScriptDialog(message);
981     return InspectorInstrumentationCookie(instrumentingAgents, 0);
982 }
983
984 void InspectorInstrumentation::didRunJavaScriptDialogImpl(const InspectorInstrumentationCookie& cookie)
985 {
986     if (InspectorPageAgent* inspectorPageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
987         inspectorPageAgent->didRunJavaScriptDialog();
988 }
989
990 void InspectorInstrumentation::willDestroyCachedResourceImpl(CachedResource* cachedResource)
991 {
992     if (!instrumentingAgentsSet)
993         return;
994     HashSet<InstrumentingAgents*>::iterator end = instrumentingAgentsSet->end();
995     for (HashSet<InstrumentingAgents*>::iterator it = instrumentingAgentsSet->begin(); it != end; ++it) {
996         InstrumentingAgents* instrumentingAgents = *it;
997         if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgents->inspectorResourceAgent())
998             inspectorResourceAgent->willDestroyCachedResource(cachedResource);
999     }
1000 }
1001
1002 InspectorInstrumentationCookie InspectorInstrumentation::willWriteHTMLImpl(InstrumentingAgents* instrumentingAgents, unsigned startLine, Frame* frame)
1003 {
1004     int timelineAgentId = 0;
1005     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
1006         timelineAgent->willWriteHTML(startLine, frame);
1007         timelineAgentId = timelineAgent->id();
1008     }
1009     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
1010 }
1011
1012 void InspectorInstrumentation::didWriteHTMLImpl(const InspectorInstrumentationCookie& cookie, unsigned endLine)
1013 {
1014     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
1015         timelineAgent->didWriteHTML(endLine);
1016 }
1017
1018 // FIXME: Drop this once we no longer generate stacks outside of Inspector.
1019 void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptCallStack> callStack, unsigned long requestIdentifier)
1020 {
1021     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
1022         consoleAgent->addMessageToConsole(source, type, level, message, callStack, requestIdentifier);
1023 #if ENABLE(JAVASCRIPT_DEBUGGER)
1024     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
1025         debuggerAgent->addMessageToConsole(source, type);
1026 #endif
1027 }
1028
1029 void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, ScriptState* state, PassRefPtr<ScriptArguments> arguments, unsigned long requestIdentifier)
1030 {
1031     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
1032         consoleAgent->addMessageToConsole(source, type, level, message, state, arguments, requestIdentifier);
1033 #if ENABLE(JAVASCRIPT_DEBUGGER)
1034     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
1035         debuggerAgent->addMessageToConsole(source, type);
1036 #endif
1037 }
1038
1039 void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, const String& scriptId, unsigned lineNumber, unsigned columnNumber, ScriptState* state, unsigned long requestIdentifier)
1040 {
1041     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
1042         consoleAgent->addMessageToConsole(source, type, level, message, scriptId, lineNumber, columnNumber, state, requestIdentifier);
1043 }
1044
1045 void InspectorInstrumentation::consoleCountImpl(InstrumentingAgents* instrumentingAgents, ScriptState* state, PassRefPtr<ScriptArguments> arguments)
1046 {
1047     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
1048         consoleAgent->count(state, arguments);
1049 }
1050
1051 void InspectorInstrumentation::startConsoleTimingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, const String& title)
1052 {
1053     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1054         timelineAgent->time(frame, title);
1055     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
1056         consoleAgent->startTiming(title);
1057 }
1058
1059 void InspectorInstrumentation::stopConsoleTimingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, const String& title, PassRefPtr<ScriptCallStack> stack)
1060 {
1061     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
1062         consoleAgent->stopTiming(title, stack);
1063     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1064         timelineAgent->timeEnd(frame, title);
1065 }
1066
1067 void InspectorInstrumentation::consoleTimeStampImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, PassRefPtr<ScriptArguments> arguments)
1068 {
1069     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
1070         String message;
1071         arguments->getFirstArgumentAsString(message);
1072         timelineAgent->didTimeStamp(frame, message);
1073      }
1074 }
1075
1076 #if ENABLE(JAVASCRIPT_DEBUGGER)
1077 void InspectorInstrumentation::addStartProfilingMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, const String& title, unsigned lineNumber, unsigned columnNumber, const String& sourceURL)
1078 {
1079     if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
1080         profilerAgent->addStartProfilingMessageToConsole(title, lineNumber, columnNumber, sourceURL);
1081 }
1082
1083 void InspectorInstrumentation::addProfileImpl(InstrumentingAgents* instrumentingAgents, RefPtr<ScriptProfile> profile, PassRefPtr<ScriptCallStack> callStack)
1084 {
1085     if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent()) {
1086         const ScriptCallFrame& lastCaller = callStack->at(0);
1087         profilerAgent->addProfile(profile, lastCaller.lineNumber(), lastCaller.columnNumber(), lastCaller.sourceURL());
1088     }
1089 }
1090
1091 String InspectorInstrumentation::getCurrentUserInitiatedProfileNameImpl(InstrumentingAgents* instrumentingAgents, bool incrementProfileNumber)
1092 {
1093     if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
1094         return profilerAgent->getCurrentUserInitiatedProfileName(incrementProfileNumber);
1095     return "";
1096 }
1097
1098 bool InspectorInstrumentation::profilerEnabledImpl(InstrumentingAgents* instrumentingAgents)
1099 {
1100     if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
1101         return profilerAgent->enabled();
1102     return false;
1103 }
1104 #endif
1105
1106 #if ENABLE(SQL_DATABASE)
1107 void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents* instrumentingAgents, PassRefPtr<Database> database, const String& domain, const String& name, const String& version)
1108 {
1109     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
1110     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
1111         return;
1112     if (InspectorDatabaseAgent* dbAgent = instrumentingAgents->inspectorDatabaseAgent())
1113         dbAgent->didOpenDatabase(database, domain, name, version);
1114 }
1115 #endif
1116
1117 void InspectorInstrumentation::didDispatchDOMStorageEventImpl(InstrumentingAgents* instrumentingAgents, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Page* page)
1118 {
1119     if (InspectorDOMStorageAgent* domStorageAgent = instrumentingAgents->inspectorDOMStorageAgent())
1120         domStorageAgent->didDispatchDOMStorageEvent(key, oldValue, newValue, storageType, securityOrigin, page);
1121 }
1122
1123 #if ENABLE(WORKERS)
1124 bool InspectorInstrumentation::shouldPauseDedicatedWorkerOnStartImpl(InstrumentingAgents* instrumentingAgents)
1125 {
1126     if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
1127         return workerAgent->shouldPauseDedicatedWorkerOnStart();
1128     return false;
1129 }
1130
1131 void InspectorInstrumentation::didStartWorkerGlobalScopeImpl(InstrumentingAgents* instrumentingAgents, WorkerGlobalScopeProxy* workerGlobalScopeProxy, const KURL& url)
1132 {
1133     if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
1134         workerAgent->didStartWorkerGlobalScope(workerGlobalScopeProxy, url);
1135 }
1136
1137 void InspectorInstrumentation::willEvaluateWorkerScript(WorkerGlobalScope* workerGlobalScope, int workerThreadStartMode)
1138 {
1139     if (workerThreadStartMode != PauseWorkerGlobalScopeOnStart)
1140         return;
1141     InstrumentingAgents* instrumentingAgents = instrumentationForWorkerGlobalScope(workerGlobalScope);
1142     if (!instrumentingAgents)
1143         return;
1144 #if ENABLE(JAVASCRIPT_DEBUGGER)
1145     if (WorkerRuntimeAgent* runtimeAgent = instrumentingAgents->workerRuntimeAgent())
1146         runtimeAgent->pauseWorkerGlobalScope(workerGlobalScope);
1147 #endif
1148 }
1149
1150 void InspectorInstrumentation::workerGlobalScopeTerminatedImpl(InstrumentingAgents* instrumentingAgents, WorkerGlobalScopeProxy* proxy)
1151 {
1152     if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
1153         workerAgent->workerGlobalScopeTerminated(proxy);
1154 }
1155 #endif
1156
1157 #if ENABLE(WEB_SOCKETS)
1158 void InspectorInstrumentation::didCreateWebSocketImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const KURL& requestURL, const KURL&, const String& protocol, Document* document)
1159 {
1160     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
1161     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
1162         return;
1163     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1164         resourceAgent->didCreateWebSocket(identifier, requestURL);
1165     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1166         timelineAgent->didCreateWebSocket(identifier, requestURL, protocol, document->frame());
1167 }
1168
1169 void InspectorInstrumentation::willSendWebSocketHandshakeRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceRequest& request, Document* document)
1170 {
1171     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1172         resourceAgent->willSendWebSocketHandshakeRequest(identifier, request);
1173     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1174         timelineAgent->willSendWebSocketHandshakeRequest(identifier, document->frame());
1175 }
1176
1177 void InspectorInstrumentation::didReceiveWebSocketHandshakeResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Document* document)
1178 {
1179     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1180         resourceAgent->didReceiveWebSocketHandshakeResponse(identifier, response);
1181     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1182         timelineAgent->didReceiveWebSocketHandshakeResponse(identifier, document->frame());
1183 }
1184
1185 void InspectorInstrumentation::didCloseWebSocketImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, Document* document)
1186 {
1187     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1188         resourceAgent->didCloseWebSocket(identifier);
1189     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1190         timelineAgent->didDestroyWebSocket(identifier, document->frame());
1191 }
1192
1193 void InspectorInstrumentation::didReceiveWebSocketFrameImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
1194 {
1195     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1196         resourceAgent->didReceiveWebSocketFrame(identifier, frame);
1197 }
1198 void InspectorInstrumentation::didReceiveWebSocketFrameErrorImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& errorMessage)
1199 {
1200     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1201         resourceAgent->didReceiveWebSocketFrameError(identifier, errorMessage);
1202 }
1203 void InspectorInstrumentation::didSendWebSocketFrameImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
1204 {
1205     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1206         resourceAgent->didSendWebSocketFrame(identifier, frame);
1207 }
1208 #endif
1209
1210 void InspectorInstrumentation::networkStateChangedImpl(InstrumentingAgents* instrumentingAgents)
1211 {
1212     if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents->inspectorApplicationCacheAgent())
1213         applicationCacheAgent->networkStateChanged();
1214 }
1215
1216 void InspectorInstrumentation::updateApplicationCacheStatusImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
1217 {
1218     if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents->inspectorApplicationCacheAgent())
1219         applicationCacheAgent->updateApplicationCacheStatus(frame);
1220 }
1221
1222 bool InspectorInstrumentation::collectingHTMLParseErrors(InstrumentingAgents* instrumentingAgents)
1223 {
1224     if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
1225         return inspectorAgent->hasFrontend();
1226     return false;
1227 }
1228
1229 bool InspectorInstrumentation::canvasAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
1230 {
1231     InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
1232     return instrumentingAgents && instrumentingAgents->inspectorCanvasAgent();
1233 }
1234
1235 bool InspectorInstrumentation::consoleAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
1236 {
1237     InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
1238     InspectorConsoleAgent* consoleAgent = instrumentingAgents ? instrumentingAgents->inspectorConsoleAgent() : 0;
1239     return consoleAgent && consoleAgent->enabled();
1240 }
1241
1242 bool InspectorInstrumentation::timelineAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
1243 {
1244     InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
1245     return instrumentingAgents && instrumentingAgents->inspectorTimelineAgent();
1246 }
1247
1248 void InspectorInstrumentation::pauseOnNativeEventIfNeeded(InstrumentingAgents* instrumentingAgents, bool isDOMEvent, const String& eventName, bool synchronous)
1249 {
1250 #if ENABLE(JAVASCRIPT_DEBUGGER)
1251     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
1252         domDebuggerAgent->pauseOnNativeEventIfNeeded(isDOMEvent, eventName, synchronous);
1253 #endif
1254 }
1255
1256 void InspectorInstrumentation::cancelPauseOnNativeEvent(InstrumentingAgents* instrumentingAgents)
1257 {
1258 #if ENABLE(JAVASCRIPT_DEBUGGER)
1259     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
1260         debuggerAgent->cancelPauseOnNextStatement();
1261 #endif
1262 }
1263
1264 void InspectorInstrumentation::didRequestAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
1265 {
1266     pauseOnNativeEventIfNeeded(instrumentingAgents, false, requestAnimationFrameEventName, true);
1267
1268     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1269         timelineAgent->didRequestAnimationFrame(callbackId, frame);
1270 }
1271
1272 void InspectorInstrumentation::didCancelAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
1273 {
1274     pauseOnNativeEventIfNeeded(instrumentingAgents, false, cancelAnimationFrameEventName, true);
1275
1276     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1277         timelineAgent->didCancelAnimationFrame(callbackId, frame);
1278 }
1279
1280 InspectorInstrumentationCookie InspectorInstrumentation::willFireAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
1281 {
1282     pauseOnNativeEventIfNeeded(instrumentingAgents, false, animationFrameFiredEventName, false);
1283
1284     int timelineAgentId = 0;
1285     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
1286         timelineAgent->willFireAnimationFrame(callbackId, frame);
1287         timelineAgentId = timelineAgent->id();
1288     }
1289     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
1290 }
1291
1292 void InspectorInstrumentation::didFireAnimationFrameImpl(const InspectorInstrumentationCookie& cookie)
1293 {
1294     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
1295         timelineAgent->didFireAnimationFrame();
1296 }
1297
1298 void InspectorInstrumentation::registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
1299 {
1300     if (!instrumentingAgentsSet)
1301         instrumentingAgentsSet = new HashSet<InstrumentingAgents*>();
1302     instrumentingAgentsSet->add(instrumentingAgents);
1303 }
1304
1305 void InspectorInstrumentation::unregisterInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
1306 {
1307     if (!instrumentingAgentsSet)
1308         return;
1309     instrumentingAgentsSet->remove(instrumentingAgents);
1310     if (instrumentingAgentsSet->isEmpty()) {
1311         delete instrumentingAgentsSet;
1312         instrumentingAgentsSet = 0;
1313     }
1314 }
1315
1316 InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
1317 {
1318     if (!cookie.instrumentingAgents())
1319         return 0;
1320     InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent();
1321     if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id()))
1322         return timelineAgent;
1323     return 0;
1324 }
1325
1326 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForPage(Page* page)
1327 {
1328     if (!page)
1329         return 0;
1330     return instrumentationForPage(page);
1331 }
1332
1333 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForRenderer(RenderObject* renderer)
1334 {
1335     return instrumentingAgentsForFrame(&renderer->frame());
1336 }
1337
1338 #if ENABLE(WORKERS)
1339 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope* workerGlobalScope)
1340 {
1341     if (!workerGlobalScope)
1342         return 0;
1343     return instrumentationForWorkerGlobalScope(workerGlobalScope);
1344 }
1345
1346 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context)
1347 {
1348     if (context->isWorkerGlobalScope())
1349         return instrumentationForWorkerGlobalScope(static_cast<WorkerGlobalScope*>(context));
1350     return 0;
1351 }
1352 #endif
1353
1354 #if ENABLE(GEOLOCATION)
1355 GeolocationPosition* InspectorInstrumentation::overrideGeolocationPositionImpl(InstrumentingAgents* instrumentingAgents, GeolocationPosition* position)
1356 {
1357     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
1358         position = pageAgent->overrideGeolocationPosition(position);
1359     return position;
1360 }
1361 #endif
1362
1363 DeviceOrientationData* InspectorInstrumentation::overrideDeviceOrientationImpl(InstrumentingAgents* instrumentingAgents, DeviceOrientationData* deviceOrientation)
1364 {
1365     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
1366         deviceOrientation = pageAgent->overrideDeviceOrientation(deviceOrientation);
1367     return deviceOrientation;
1368 }
1369
1370 #if USE(ACCELERATED_COMPOSITING)
1371 void InspectorInstrumentation::layerTreeDidChangeImpl(InstrumentingAgents* instrumentingAgents)
1372 {
1373     if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
1374         layerTreeAgent->layerTreeDidChange();
1375 }
1376
1377 void InspectorInstrumentation::renderLayerDestroyedImpl(InstrumentingAgents* instrumentingAgents, const RenderLayer* renderLayer)
1378 {
1379     if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
1380         layerTreeAgent->renderLayerDestroyed(renderLayer);
1381 }
1382
1383 void InspectorInstrumentation::pseudoElementDestroyedImpl(InstrumentingAgents* instrumentingAgents, PseudoElement* pseudoElement)
1384 {
1385     if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
1386         layerTreeAgent->pseudoElementDestroyed(pseudoElement);
1387 }
1388 #endif
1389
1390 } // namespace WebCore
1391
1392 #endif // !ENABLE(INSPECTOR)