Make some things that return never-null pointers return references instead.
[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 "ScriptArguments.h"
71 #include "ScriptCallStack.h"
72 #include "ScriptController.h"
73 #include "ScriptProfile.h"
74 #include "StyleResolver.h"
75 #include "StyleRule.h"
76 #include "WorkerGlobalScope.h"
77 #include "WorkerInspectorController.h"
78 #include "WorkerRuntimeAgent.h"
79 #include "WorkerThread.h"
80 #include "XMLHttpRequest.h"
81 #include <wtf/StdLibExtras.h>
82 #include <wtf/text/CString.h>
83
84 namespace WebCore {
85
86 static const char* const requestAnimationFrameEventName = "requestAnimationFrame";
87 static const char* const cancelAnimationFrameEventName = "cancelAnimationFrame";
88 static const char* const animationFrameFiredEventName = "animationFrameFired";
89 static const char* const setTimerEventName = "setTimer";
90 static const char* const clearTimerEventName = "clearTimer";
91 static const char* const timerFiredEventName = "timerFired";
92
93 namespace {
94 static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0;
95 }
96
97 int InspectorInstrumentation::s_frontendCounter = 0;
98
99 static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const EventPath& eventPath)
100 {
101     if (window && window->hasEventListeners(eventType))
102         return true;
103
104     if (node->hasEventListeners(eventType))
105         return true;
106
107     for (size_t i = 0; i < eventPath.size(); i++) {
108         if (eventPath[i]->node()->hasEventListeners(eventType))
109             return true;
110     }
111
112     return false;
113 }
114
115 static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
116 {
117     Frame* frame = 0;
118     if (context->isDocument())
119         frame = toDocument(context)->frame();
120     return frame;
121 }
122
123 InspectorInstrumentationCookie::InspectorInstrumentationCookie()
124     : m_instrumentingAgents(0)
125     , m_timelineAgentId(0)
126 {
127 }
128
129 InspectorInstrumentationCookie::InspectorInstrumentationCookie(InstrumentingAgents* agents, int timelineAgentId)
130     : m_instrumentingAgents(agents)
131     , m_timelineAgentId(timelineAgentId)
132 {
133 }
134
135 InspectorInstrumentationCookie::InspectorInstrumentationCookie(const InspectorInstrumentationCookie& other)
136     : m_instrumentingAgents(other.m_instrumentingAgents)
137     , m_timelineAgentId(other.m_timelineAgentId)
138 {
139 }
140
141 InspectorInstrumentationCookie& InspectorInstrumentationCookie::operator=(const InspectorInstrumentationCookie& other)
142 {
143     if (this != &other) {
144         m_instrumentingAgents = other.m_instrumentingAgents;
145         m_timelineAgentId = other.m_timelineAgentId;
146     }
147     return *this;
148 }
149
150 InspectorInstrumentationCookie::~InspectorInstrumentationCookie()
151 {
152 }
153
154 void InspectorInstrumentation::didClearWindowObjectInWorldImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, DOMWrapperWorld* world)
155 {
156     InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent();
157     if (pageAgent)
158         pageAgent->didClearWindowObjectInWorld(frame, world);
159     if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
160         inspectorAgent->didClearWindowObjectInWorld(frame, world);
161 #if ENABLE(JAVASCRIPT_DEBUGGER)
162     if (PageDebuggerAgent* debuggerAgent = instrumentingAgents->pageDebuggerAgent()) {
163         if (pageAgent && world == mainThreadNormalWorld() && frame == pageAgent->mainFrame())
164             debuggerAgent->didClearMainFrameWindowObject();
165     }
166 #endif
167     if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents->pageRuntimeAgent()) {
168         if (world == mainThreadNormalWorld())
169             pageRuntimeAgent->didCreateMainWorldContext(frame);
170     }
171 }
172
173 bool InspectorInstrumentation::isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents)
174 {
175 #if ENABLE(JAVASCRIPT_DEBUGGER)
176     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
177         return debuggerAgent->isPaused();
178 #endif
179     return false;
180 }
181
182 void InspectorInstrumentation::willInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* parent)
183 {
184 #if ENABLE(JAVASCRIPT_DEBUGGER)
185     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
186         domDebuggerAgent->willInsertDOMNode(parent);
187 #endif
188 }
189
190 void InspectorInstrumentation::didInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
191 {
192     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
193         domAgent->didInsertDOMNode(node);
194 #if ENABLE(JAVASCRIPT_DEBUGGER)
195     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
196         domDebuggerAgent->didInsertDOMNode(node);
197 #endif
198 }
199
200 void InspectorInstrumentation::willRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
201 {
202 #if ENABLE(JAVASCRIPT_DEBUGGER)
203     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
204         domDebuggerAgent->willRemoveDOMNode(node);
205 #endif
206 }
207
208 void InspectorInstrumentation::didRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
209 {
210 #if ENABLE(JAVASCRIPT_DEBUGGER)
211     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
212         domDebuggerAgent->didRemoveDOMNode(node);
213 #endif
214     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
215         domAgent->didRemoveDOMNode(node);
216 }
217
218 void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& oldValue, const AtomicString& newValue)
219 {
220 #if ENABLE(JAVASCRIPT_DEBUGGER)
221     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
222         domDebuggerAgent->willModifyDOMAttr(element);
223     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
224         domAgent->willModifyDOMAttr(element, oldValue, newValue);
225 #endif
226 }
227
228 void InspectorInstrumentation::didModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name, const AtomicString& value)
229 {
230     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
231         domAgent->didModifyDOMAttr(element, name, value);
232 }
233
234 void InspectorInstrumentation::didRemoveDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name)
235 {
236     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
237         domAgent->didRemoveDOMAttr(element, name);
238 }
239
240 void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents* instrumentingAgents, Node* node)
241 {
242     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
243         domAgent->didInvalidateStyleAttr(node);
244 #if ENABLE(JAVASCRIPT_DEBUGGER)
245     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
246         domDebuggerAgent->didInvalidateStyleAttr(node);
247 #endif
248 }
249
250 void InspectorInstrumentation::frameWindowDiscardedImpl(InstrumentingAgents* instrumentingAgents, DOMWindow* window)
251 {
252     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
253         consoleAgent->frameWindowDiscarded(window);
254 }
255
256 void InspectorInstrumentation::mediaQueryResultChangedImpl(InstrumentingAgents* instrumentingAgents)
257 {
258     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
259         cssAgent->mediaQueryResultChanged();
260 }
261
262 void InspectorInstrumentation::didPushShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
263 {
264     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
265         domAgent->didPushShadowRoot(host, root);
266 }
267
268 void InspectorInstrumentation::willPopShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
269 {
270     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
271         domAgent->willPopShadowRoot(host, root);
272 }
273
274 void InspectorInstrumentation::didCreateNamedFlowImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
275 {
276     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
277         cssAgent->didCreateNamedFlow(document, namedFlow);
278 }
279
280 void InspectorInstrumentation::willRemoveNamedFlowImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
281 {
282     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
283         cssAgent->willRemoveNamedFlow(document, namedFlow);
284 }
285
286 void InspectorInstrumentation::didUpdateRegionLayoutImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
287 {
288     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
289         cssAgent->didUpdateRegionLayout(document, namedFlow);
290 }
291
292 void InspectorInstrumentation::didChangeRegionOversetImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
293 {
294     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
295         cssAgent->didChangeRegionOverset(document, namedFlow);
296 }
297
298 void InspectorInstrumentation::mouseDidMoveOverElementImpl(InstrumentingAgents* instrumentingAgents, const HitTestResult& result, unsigned modifierFlags)
299 {
300     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
301         domAgent->mouseDidMoveOverElement(result, modifierFlags);
302 }
303
304 void InspectorInstrumentation::didScrollImpl(InstrumentingAgents* instrumentingAgents)
305 {
306     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
307         pageAgent->didScroll();
308 }
309
310 bool InspectorInstrumentation::handleTouchEventImpl(InstrumentingAgents* instrumentingAgents, Node* node)
311 {
312     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
313         return domAgent->handleTouchEvent(node);
314     return false;
315 }
316
317 bool InspectorInstrumentation::handleMousePressImpl(InstrumentingAgents* instrumentingAgents)
318 {
319     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
320         return domAgent->handleMousePress();
321     return false;
322 }
323
324 bool InspectorInstrumentation::forcePseudoStateImpl(InstrumentingAgents* instrumentingAgents, Element* element, CSSSelector::PseudoType pseudoState)
325 {
326     if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
327         return cssAgent->forcePseudoState(element, pseudoState);
328     return false;
329 }
330
331 void InspectorInstrumentation::characterDataModifiedImpl(InstrumentingAgents* instrumentingAgents, CharacterData* characterData)
332 {
333     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
334         domAgent->characterDataModified(characterData);
335 }
336
337 void InspectorInstrumentation::willSendXMLHttpRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url)
338 {
339 #if ENABLE(JAVASCRIPT_DEBUGGER)
340     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
341         domDebuggerAgent->willSendXMLHttpRequest(url);
342 #endif
343 }
344
345 void InspectorInstrumentation::didScheduleResourceRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url, Frame* frame)
346 {
347     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
348         timelineAgent->didScheduleResourceRequest(url, frame);
349 }
350
351 void InspectorInstrumentation::didInstallTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, int timeout, bool singleShot, ScriptExecutionContext* context)
352 {
353     pauseOnNativeEventIfNeeded(instrumentingAgents, false, setTimerEventName, true);
354     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
355         timelineAgent->didInstallTimer(timerId, timeout, singleShot, frameForScriptExecutionContext(context));
356 }
357
358 void InspectorInstrumentation::didRemoveTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
359 {
360     pauseOnNativeEventIfNeeded(instrumentingAgents, false, clearTimerEventName, true);
361     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
362         timelineAgent->didRemoveTimer(timerId, frameForScriptExecutionContext(context));
363 }
364
365 InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents* instrumentingAgents, const String& scriptName, int scriptLine, ScriptExecutionContext* context)
366 {
367     int timelineAgentId = 0;
368     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
369         timelineAgent->willCallFunction(scriptName, scriptLine, frameForScriptExecutionContext(context));
370         timelineAgentId = timelineAgent->id();
371     }
372     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
373 }
374
375 void InspectorInstrumentation::didCallFunctionImpl(const InspectorInstrumentationCookie& cookie)
376 {
377     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
378         timelineAgent->didCallFunction();
379 }
380
381 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRReadyStateChangeEventImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
382 {
383     int timelineAgentId = 0;
384     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
385     if (timelineAgent && request->hasEventListeners(eventNames().readystatechangeEvent)) {
386         timelineAgent->willDispatchXHRReadyStateChangeEvent(request->url().string(), request->readyState(), frameForScriptExecutionContext(context));
387         timelineAgentId = timelineAgent->id();
388     }
389     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
390 }
391
392 void InspectorInstrumentation::didDispatchXHRReadyStateChangeEventImpl(const InspectorInstrumentationCookie& cookie)
393 {
394     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
395         timelineAgent->didDispatchXHRReadyStateChangeEvent();
396 }
397
398 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window, Node* node, const EventPath& eventPath, Document* document)
399 {
400     int timelineAgentId = 0;
401     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
402     if (timelineAgent && eventHasListeners(event.type(), window, node, eventPath)) {
403         timelineAgent->willDispatchEvent(event, document->frame());
404         timelineAgentId = timelineAgent->id();
405     }
406     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
407 }
408
409 InspectorInstrumentationCookie InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents* instrumentingAgents, Event* event)
410 {
411     pauseOnNativeEventIfNeeded(instrumentingAgents, true, event->type(), false);
412     return InspectorInstrumentationCookie(instrumentingAgents, 0);
413 }
414
415 void InspectorInstrumentation::didHandleEventImpl(const InspectorInstrumentationCookie& cookie)
416 {
417     cancelPauseOnNativeEvent(cookie.instrumentingAgents());
418 }
419
420 void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)
421 {
422     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
423         timelineAgent->didDispatchEvent();
424 }
425
426 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window)
427 {
428     int timelineAgentId = 0;
429     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
430     if (timelineAgent && window->hasEventListeners(event.type())) {
431         timelineAgent->willDispatchEvent(event, window ? window->frame() : 0);
432         timelineAgentId = timelineAgent->id();
433     }
434     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
435 }
436
437 void InspectorInstrumentation::didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie& cookie)
438 {
439     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
440         timelineAgent->didDispatchEvent();
441 }
442
443 InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InstrumentingAgents* instrumentingAgents, const String& url, int lineNumber, Frame* frame)
444 {
445     int timelineAgentId = 0;
446     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
447         timelineAgent->willEvaluateScript(url, lineNumber, frame);
448         timelineAgentId = timelineAgent->id();
449     }
450     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
451 }
452
453 void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentationCookie& cookie)
454 {
455     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
456         timelineAgent->didEvaluateScript();
457 }
458
459 void InspectorInstrumentation::scriptsEnabledImpl(InstrumentingAgents* instrumentingAgents, bool isEnabled)
460 {
461     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
462         pageAgent->scriptsEnabled(isEnabled);
463 }
464
465 void InspectorInstrumentation::didCreateIsolatedContextImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, ScriptState* scriptState, SecurityOrigin* origin)
466 {
467     if (PageRuntimeAgent* runtimeAgent = instrumentingAgents->pageRuntimeAgent())
468         runtimeAgent->didCreateIsolatedContext(frame, scriptState, origin);
469 }
470
471 InspectorInstrumentationCookie InspectorInstrumentation::willFireTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
472 {
473     pauseOnNativeEventIfNeeded(instrumentingAgents, false, timerFiredEventName, false);
474
475     int timelineAgentId = 0;
476     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
477         timelineAgent->willFireTimer(timerId, frameForScriptExecutionContext(context));
478         timelineAgentId = timelineAgent->id();
479     }
480     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
481 }
482
483 void InspectorInstrumentation::didFireTimerImpl(const InspectorInstrumentationCookie& cookie)
484 {
485     cancelPauseOnNativeEvent(cookie.instrumentingAgents());
486
487     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
488         timelineAgent->didFireTimer();
489 }
490
491 void InspectorInstrumentation::didInvalidateLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
492 {
493     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
494         timelineAgent->didInvalidateLayout(frame);
495 }
496
497 InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
498 {
499     int timelineAgentId = 0;
500     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
501         timelineAgent->willLayout(frame);
502         timelineAgentId = timelineAgent->id();
503     }
504     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
505 }
506
507 void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie, RenderObject* root)
508 {
509     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
510         timelineAgent->didLayout(root);
511
512     if (InspectorPageAgent* pageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
513         pageAgent->didLayout();
514 }
515
516 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRLoadEventImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
517 {
518     int timelineAgentId = 0;
519     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
520     if (timelineAgent && request->hasEventListeners(eventNames().loadEvent)) {
521         timelineAgent->willDispatchXHRLoadEvent(request->url(), frameForScriptExecutionContext(context));
522         timelineAgentId = timelineAgent->id();
523     }
524     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
525 }
526
527 void InspectorInstrumentation::didDispatchXHRLoadEventImpl(const InspectorInstrumentationCookie& cookie)
528 {
529     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
530         timelineAgent->didDispatchXHRLoadEvent();
531 }
532
533 void InspectorInstrumentation::willPaintImpl(InstrumentingAgents* instrumentingAgents, RenderObject* renderer)
534 {
535     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
536         timelineAgent->willPaint(renderer->frame());
537 }
538
539 void InspectorInstrumentation::didPaintImpl(InstrumentingAgents*  instrumentingAgents, RenderObject* renderer, GraphicsContext* context, const LayoutRect& rect)
540 {
541     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
542         timelineAgent->didPaint(renderer, rect);
543     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
544         pageAgent->didPaint(context, rect);
545 }
546
547 void InspectorInstrumentation::willScrollLayerImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
548 {
549     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
550         timelineAgent->willScroll(frame);
551 }
552
553 void InspectorInstrumentation::didScrollLayerImpl(InstrumentingAgents* instrumentingAgents)
554 {
555     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
556         timelineAgent->didScroll();
557 }
558
559 InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
560 {
561     int timelineAgentId = 0;
562     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
563         timelineAgent->willRecalculateStyle(frame);
564         timelineAgentId = timelineAgent->id();
565     }
566     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
567         resourceAgent->willRecalculateStyle();
568     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
569 }
570
571 void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrumentationCookie& cookie)
572 {
573     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
574         timelineAgent->didRecalculateStyle();
575     InstrumentingAgents* instrumentingAgents = cookie.instrumentingAgents();
576     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
577         resourceAgent->didRecalculateStyle();
578     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
579         pageAgent->didRecalculateStyle();
580 }
581
582 void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents* instrumentingAgents, Document* document)
583 {
584     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
585         timelineAgent->didScheduleStyleRecalculation(document->frame());
586     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
587         resourceAgent->didScheduleStyleRecalculation(document);
588 }
589
590 InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* sheetCollection)
591 {
592     InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
593     if (cssAgent) {
594         cssAgent->willMatchRule(rule, inspectorCSSOMWrappers, sheetCollection);
595         return InspectorInstrumentationCookie(instrumentingAgents, 1);
596     }
597
598     return InspectorInstrumentationCookie();
599 }
600
601 void InspectorInstrumentation::didMatchRuleImpl(const InspectorInstrumentationCookie& cookie, bool matched)
602 {
603     InspectorCSSAgent* cssAgent = cookie.instrumentingAgents()->inspectorCSSAgent();
604     if (cssAgent)
605         cssAgent->didMatchRule(matched);
606 }
607
608 InspectorInstrumentationCookie InspectorInstrumentation::willProcessRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, StyleResolver& styleResolver)
609 {
610     InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
611     if (cssAgent) {
612         cssAgent->willProcessRule(rule, styleResolver);
613         return InspectorInstrumentationCookie(instrumentingAgents, 1);
614     }
615
616     return InspectorInstrumentationCookie();
617 }
618
619 void InspectorInstrumentation::didProcessRuleImpl(const InspectorInstrumentationCookie& cookie)
620 {
621     InspectorCSSAgent* cssAgent = cookie.instrumentingAgents()->inspectorCSSAgent();
622     if (cssAgent)
623         cssAgent->didProcessRule();
624 }
625
626 void InspectorInstrumentation::applyUserAgentOverrideImpl(InstrumentingAgents* instrumentingAgents, String* userAgent)
627 {
628     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
629         resourceAgent->applyUserAgentOverride(userAgent);
630 }
631
632 void InspectorInstrumentation::applyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents, long* width)
633 {
634     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
635         pageAgent->applyScreenWidthOverride(width);
636 }
637
638 void InspectorInstrumentation::applyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents, long* height)
639 {
640     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
641         pageAgent->applyScreenHeightOverride(height);
642 }
643
644 bool InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents)
645 {
646     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
647         long width = 0;
648         pageAgent->applyScreenWidthOverride(&width);
649         return !!width;
650     }
651     return false;
652 }
653
654 bool InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents)
655 {
656     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
657         long height = 0;
658         pageAgent->applyScreenHeightOverride(&height);
659         return !!height;
660     }
661     return false;
662 }
663
664 void InspectorInstrumentation::applyEmulatedMediaImpl(InstrumentingAgents* instrumentingAgents, String* media)
665 {
666     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
667         pageAgent->applyEmulatedMedia(media);
668 }
669
670 void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
671 {
672     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
673         timelineAgent->willSendResourceRequest(identifier, request, loader->frame());
674     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
675         resourceAgent->willSendRequest(identifier, loader, request, redirectResponse);
676 }
677
678 void InspectorInstrumentation::continueAfterPingLoaderImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& response)
679 {
680     willSendRequestImpl(instrumentingAgents, identifier, loader, request, response);
681 }
682
683 void InspectorInstrumentation::markResourceAsCachedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
684 {
685     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
686         resourceAgent->markResourceAsCached(identifier);
687 }
688
689 void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
690 {
691     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
692     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
693         return;
694     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
695         resourceAgent->didLoadResourceFromMemoryCache(loader, cachedResource);
696 }
697
698 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, Frame* frame, int length)
699 {
700     int timelineAgentId = 0;
701     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
702         timelineAgent->willReceiveResourceData(identifier, frame, length);
703         timelineAgentId = timelineAgent->id();
704     }
705     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
706 }
707
708 void InspectorInstrumentation::didReceiveResourceDataImpl(const InspectorInstrumentationCookie& cookie)
709 {
710     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
711         timelineAgent->didReceiveResourceData();
712 }
713
714 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Frame* frame)
715 {
716     int timelineAgentId = 0;
717     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
718     if (timelineAgent) {
719         timelineAgent->willReceiveResourceResponse(identifier, response, frame);
720         timelineAgentId = timelineAgent->id();
721     }
722     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
723 }
724
725 void InspectorInstrumentation::didReceiveResourceResponseImpl(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
726 {
727     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
728         timelineAgent->didReceiveResourceResponse();
729     if (!loader)
730         return;
731     InstrumentingAgents* instrumentingAgents = cookie.instrumentingAgents();
732     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
733         resourceAgent->didReceiveResponse(identifier, loader, response, resourceLoader);
734     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
735         consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
736 }
737
738 void InspectorInstrumentation::didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
739 {
740     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(frame, identifier, r);
741     InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r, 0);
742 }
743
744 void InspectorInstrumentation::continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
745 {
746     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
747 }
748
749 void InspectorInstrumentation::continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
750 {
751     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
752 }
753
754 void InspectorInstrumentation::continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
755 {
756     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
757 }
758
759 void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
760 {
761     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
762         resourceAgent->didReceiveData(identifier, data, dataLength, encodedDataLength);
763 }
764
765 void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, double monotonicFinishTime)
766 {
767     InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
768     InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent();
769     if (!timelineAgent && !resourceAgent)
770         return;
771
772     double finishTime = 0.0;
773     // FIXME: Expose all of the timing details to inspector and have it calculate finishTime.
774     if (monotonicFinishTime)
775         finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFinishTime);
776
777     if (timelineAgent)
778         timelineAgent->didFinishLoadingResource(identifier, false, finishTime, loader->frame());
779     if (resourceAgent)
780         resourceAgent->didFinishLoading(identifier, loader, finishTime);
781 }
782
783 void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
784 {
785     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
786         timelineAgent->didFinishLoadingResource(identifier, true, 0, loader->frame());
787     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
788         resourceAgent->didFailLoading(identifier, loader, error);
789     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
790         consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
791 }
792
793 void InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClientImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, ThreadableLoaderClient* client)
794 {
795     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
796         resourceAgent->documentThreadableLoaderStartedLoadingForClient(identifier, client);
797 }
798
799 void InspectorInstrumentation::willLoadXHRImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client, const String& method, const KURL& url, bool async, PassRefPtr<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials)
800 {
801     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
802         resourceAgent->willLoadXHR(client, method, url, async, formData, headers, includeCredentials);
803 }
804
805 void InspectorInstrumentation::didFailXHRLoadingImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client)
806 {
807     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
808         resourceAgent->didFailXHRLoading(client);
809 }
810
811 void InspectorInstrumentation::didFinishXHRLoadingImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber)
812 {
813     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
814         consoleAgent->didFinishXHRLoading(identifier, url, sendURL, sendLineNumber);
815     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
816         resourceAgent->didFinishXHRLoading(client, identifier, sourceString);
817 }
818
819 void InspectorInstrumentation::didReceiveXHRResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
820 {
821     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
822         resourceAgent->didReceiveXHRResponse(identifier);
823 }
824
825 void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
826 {
827     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
828         resourceAgent->willLoadXHRSynchronously();
829 }
830
831 void InspectorInstrumentation::didLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
832 {
833     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
834         resourceAgent->didLoadXHRSynchronously();
835 }
836
837 void InspectorInstrumentation::scriptImportedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& sourceString)
838 {
839     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
840         resourceAgent->setInitialScriptContent(identifier, sourceString);
841 }
842
843 void InspectorInstrumentation::scriptExecutionBlockedByCSPImpl(InstrumentingAgents* instrumentingAgents, const String& directiveText)
844 {
845 #if ENABLE(JAVASCRIPT_DEBUGGER)
846     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
847         debuggerAgent->scriptExecutionBlockedByCSP(directiveText);
848 #endif
849 }
850
851 void InspectorInstrumentation::didReceiveScriptResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
852 {
853     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
854         resourceAgent->didReceiveScriptResponse(identifier);
855 }
856
857 void InspectorInstrumentation::domContentLoadedEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
858 {
859     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
860         timelineAgent->didMarkDOMContentEvent(frame);
861
862     if (frame->page()->mainFrame() != frame)
863         return;
864
865     if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
866         inspectorAgent->domContentLoadedEventFired();
867
868     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
869         domAgent->mainFrameDOMContentLoaded();
870
871     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
872         pageAgent->domContentEventFired();
873 }
874
875 void InspectorInstrumentation::loadEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
876 {
877     if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
878         domAgent->loadEventFired(frame->document());
879
880     if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
881         timelineAgent->didMarkLoadEvent(frame);
882
883     if (frame->page()->mainFrame() != frame)
884         return;
885
886     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
887         pageAgent->loadEventFired();
888 }
889
890 void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
891 {
892     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
893         canvasAgent->frameDetached(frame);
894     if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
895         pageAgent->frameDetached(frame);
896 }
897
898 void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents* instrumentingAgents, Page* page, DocumentLoader* loader)
899 {
900     InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
901     if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
902         return;
903
904     Frame* mainFrame = page->mainFrame();
905     if (loader->frame() == mainFrame) {
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(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 InstrumentationEvents {
1391 const char PaintLayer[] = "PaintLayer";
1392 const char RasterTask[] = "RasterTask";
1393 const char Paint[] = "Paint";
1394 const char Layer[] = "Layer";
1395 const char BeginFrame[] = "BeginFrame";
1396 };
1397
1398 namespace InstrumentationEventArguments {
1399 const char LayerId[] = "layerId";
1400 const char PageId[] = "pageId";
1401 };
1402
1403 } // namespace WebCore
1404
1405 #endif // !ENABLE(INSPECTOR)