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