2011-01-12 Ilya Tikhonovsky <loislo@chromium.org>
[WebKit-https.git] / Source / WebCore / inspector / InspectorInstrumentation.cpp
1 /*
2 * Copyright (C) 2010 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 #include "InspectorInstrumentation.h"
33
34 #if ENABLE(INSPECTOR)
35
36 #include "DOMWindow.h"
37 #include "DocumentLoader.h"
38 #include "Event.h"
39 #include "EventContext.h"
40 #include "InspectorApplicationCacheAgent.h"
41 #include "InspectorBrowserDebuggerAgent.h"
42 #include "InspectorController.h"
43 #include "InspectorDOMAgent.h"
44 #include "InspectorDebuggerAgent.h"
45 #include "InspectorResourceAgent.h"
46 #include "InspectorTimelineAgent.h"
47 #include "XMLHttpRequest.h"
48 #include <wtf/text/CString.h>
49
50 namespace WebCore {
51
52 static const char* const listenerEventCategoryType = "listener";
53 static const char* const instrumentationEventCategoryType = "instrumentation";
54
55 static const char* const setTimerEventName = "setTimer";
56 static const char* const clearTimerEventName = "clearTimer";
57 static const char* const timerFiredEventName = "timerFired";
58
59 int InspectorInstrumentation::s_frontendCounter = 0;
60
61 static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors)
62 {
63     if (window && window->hasEventListeners(eventType))
64         return true;
65
66     if (node->hasEventListeners(eventType))
67         return true;
68
69     for (size_t i = 0; i < ancestors.size(); i++) {
70         Node* ancestor = ancestors[i].node();
71         if (ancestor->hasEventListeners(eventType))
72             return true;
73     }
74
75     return false;
76 }
77
78 void InspectorInstrumentation::willInsertDOMNodeImpl(InspectorController* inspectorController, Node* node, Node* parent)
79 {
80 #if ENABLE(JAVASCRIPT_DEBUGGER)
81     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
82         browserDebuggerAgent->willInsertDOMNode(node, parent);
83 #endif
84 }
85
86 void InspectorInstrumentation::didInsertDOMNodeImpl(InspectorController* inspectorController, Node* node)
87 {
88     if (InspectorDOMAgent* domAgent = inspectorController->m_domAgent.get())
89         domAgent->didInsertDOMNode(node);
90 #if ENABLE(JAVASCRIPT_DEBUGGER)
91     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
92         browserDebuggerAgent->didInsertDOMNode(node);
93 #endif
94 }
95
96 void InspectorInstrumentation::willRemoveDOMNodeImpl(InspectorController* inspectorController, Node* node)
97 {
98 #if ENABLE(JAVASCRIPT_DEBUGGER)
99     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
100         browserDebuggerAgent->willRemoveDOMNode(node);
101 #endif
102 }
103
104 void InspectorInstrumentation::didRemoveDOMNodeImpl(InspectorController* inspectorController, Node* node)
105 {
106 #if ENABLE(JAVASCRIPT_DEBUGGER)
107     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
108         browserDebuggerAgent->didRemoveDOMNode(node);
109 #endif
110     if (InspectorDOMAgent* domAgent = inspectorController->m_domAgent.get())
111         domAgent->didRemoveDOMNode(node);
112 }
113
114 void InspectorInstrumentation::willModifyDOMAttrImpl(InspectorController* inspectorController, Element* element)
115 {
116 #if ENABLE(JAVASCRIPT_DEBUGGER)
117     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
118         browserDebuggerAgent->willModifyDOMAttr(element);
119 #endif
120 }
121
122 void InspectorInstrumentation::didModifyDOMAttrImpl(InspectorController* inspectorController, Element* element)
123 {
124     if (InspectorDOMAgent* domAgent = inspectorController->m_domAgent.get())
125         domAgent->didModifyDOMAttr(element);
126 }
127
128 void InspectorInstrumentation::characterDataModifiedImpl(InspectorController* inspectorController, CharacterData* characterData)
129 {
130     if (InspectorDOMAgent* domAgent = inspectorController->m_domAgent.get())
131         domAgent->characterDataModified(characterData);
132 }
133
134 void InspectorInstrumentation::willSendXMLHttpRequestImpl(InspectorController* inspectorController, const String& url)
135 {
136 #if ENABLE(JAVASCRIPT_DEBUGGER)
137     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
138         browserDebuggerAgent->willSendXMLHttpRequest(url);
139 #endif
140 }
141
142 void InspectorInstrumentation::didScheduleResourceRequestImpl(InspectorController* inspectorController, const String& url)
143 {
144     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController))
145         timelineAgent->didScheduleResourceRequest(url);
146 }
147
148 void InspectorInstrumentation::didInstallTimerImpl(InspectorController* inspectorController, int timerId, int timeout, bool singleShot)
149 {
150     pauseOnNativeEventIfNeeded(inspectorController, instrumentationEventCategoryType, setTimerEventName, true);
151     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController))
152         timelineAgent->didInstallTimer(timerId, timeout, singleShot);
153 }
154
155 void InspectorInstrumentation::didRemoveTimerImpl(InspectorController* inspectorController, int timerId)
156 {
157     pauseOnNativeEventIfNeeded(inspectorController, instrumentationEventCategoryType, clearTimerEventName, true);
158     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController))
159         timelineAgent->didRemoveTimer(timerId);
160 }
161
162
163 InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InspectorController* inspectorController, const String& scriptName, int scriptLine)
164 {
165     int timelineAgentId = 0;
166     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
167     if (timelineAgent) {
168         timelineAgent->willCallFunction(scriptName, scriptLine);
169         timelineAgentId = timelineAgent->id();
170     }
171     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
172 }
173
174 void InspectorInstrumentation::didCallFunctionImpl(const InspectorInstrumentationCookie& cookie)
175 {
176     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
177         timelineAgent->didCallFunction();
178 }
179
180 InspectorInstrumentationCookie InspectorInstrumentation::willChangeXHRReadyStateImpl(InspectorController* inspectorController, XMLHttpRequest* request)
181 {
182     int timelineAgentId = 0;
183     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
184     if (timelineAgent && request->hasEventListeners(eventNames().readystatechangeEvent)) {
185         timelineAgent->willChangeXHRReadyState(request->url().string(), request->readyState());
186         timelineAgentId = timelineAgent->id();
187     }
188     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
189 }
190
191 void InspectorInstrumentation::didChangeXHRReadyStateImpl(const InspectorInstrumentationCookie& cookie)
192 {
193     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
194         timelineAgent->didChangeXHRReadyState();
195 }
196
197 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InspectorController* inspectorController, const Event& event, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors)
198 {
199     pauseOnNativeEventIfNeeded(inspectorController, listenerEventCategoryType, event.type(), false);
200
201     int timelineAgentId = 0;
202     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
203     if (timelineAgent && eventHasListeners(event.type(), window, node, ancestors)) {
204         timelineAgent->willDispatchEvent(event);
205         timelineAgentId = timelineAgent->id();
206     }
207     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
208 }
209
210 void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)
211 {
212     cancelPauseOnNativeEvent(cookie.first);
213
214     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
215         timelineAgent->didDispatchEvent();
216 }
217
218 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InspectorController* inspectorController, const Event& event, DOMWindow* window)
219 {
220     pauseOnNativeEventIfNeeded(inspectorController, listenerEventCategoryType, event.type(), false);
221
222     int timelineAgentId = 0;
223     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
224     if (timelineAgent && window->hasEventListeners(event.type())) {
225         timelineAgent->willDispatchEvent(event);
226         timelineAgentId = timelineAgent->id();
227     }
228     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
229 }
230
231 void InspectorInstrumentation::didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie& cookie)
232 {
233     cancelPauseOnNativeEvent(cookie.first);
234
235     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
236         timelineAgent->didDispatchEvent();
237 }
238
239 InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InspectorController* inspectorController, const String& url, int lineNumber)
240 {
241     int timelineAgentId = 0;
242     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
243     if (timelineAgent) {
244         timelineAgent->willEvaluateScript(url, lineNumber);
245         timelineAgentId = timelineAgent->id();
246     }
247     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
248 }
249
250 void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentationCookie& cookie)
251 {
252     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
253         timelineAgent->didEvaluateScript();
254 }
255
256 InspectorInstrumentationCookie InspectorInstrumentation::willFireTimerImpl(InspectorController* inspectorController, int timerId)
257 {
258     pauseOnNativeEventIfNeeded(inspectorController, instrumentationEventCategoryType, timerFiredEventName, false);
259
260     int timelineAgentId = 0;
261     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
262     if (timelineAgent) {
263         timelineAgent->willFireTimer(timerId);
264         timelineAgentId = timelineAgent->id();
265     }
266     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
267 }
268
269 void InspectorInstrumentation::didFireTimerImpl(const InspectorInstrumentationCookie& cookie)
270 {
271     cancelPauseOnNativeEvent(cookie.first);
272
273     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
274         timelineAgent->didFireTimer();
275 }
276
277 InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InspectorController* inspectorController)
278 {
279     int timelineAgentId = 0;
280     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
281     if (timelineAgent) {
282         timelineAgent->willLayout();
283         timelineAgentId = timelineAgent->id();
284     }
285     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
286 }
287
288 void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie)
289 {
290     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
291         timelineAgent->didLayout();
292 }
293
294 InspectorInstrumentationCookie InspectorInstrumentation::willLoadXHRImpl(InspectorController* inspectorController, XMLHttpRequest* request)
295 {
296     int timelineAgentId = 0;
297     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
298     if (timelineAgent && request->hasEventListeners(eventNames().loadEvent)) {
299         timelineAgent->willLoadXHR(request->url());
300         timelineAgentId = timelineAgent->id();
301     }
302     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
303 }
304
305 void InspectorInstrumentation::didLoadXHRImpl(const InspectorInstrumentationCookie& cookie)
306 {
307     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
308         timelineAgent->didLoadXHR();
309 }
310
311 InspectorInstrumentationCookie InspectorInstrumentation::willPaintImpl(InspectorController* inspectorController, const IntRect& rect)
312 {
313     int timelineAgentId = 0;
314     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
315     if (timelineAgent) {
316         timelineAgent->willPaint(rect);
317         timelineAgentId = timelineAgent->id();
318     }
319     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
320 }
321
322 void InspectorInstrumentation::didPaintImpl(const InspectorInstrumentationCookie& cookie)
323 {
324     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
325         timelineAgent->didPaint();
326 }
327
328 InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InspectorController* inspectorController)
329 {
330     int timelineAgentId = 0;
331     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
332     if (timelineAgent) {
333         timelineAgent->willRecalculateStyle();
334         timelineAgentId = timelineAgent->id();
335     }
336     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
337 }
338
339 void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrumentationCookie& cookie)
340 {
341     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
342         timelineAgent->didRecalculateStyle();
343 }
344
345 void InspectorInstrumentation::identifierForInitialRequestImpl(InspectorController* ic, unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
346 {
347     if (!ic->enabled())
348         return;
349     ic->ensureSettingsLoaded();
350
351     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
352         resourceAgent->identifierForInitialRequest(identifier, request.url(), loader, ic->isMainResourceLoader(loader, request.url()));
353 }
354
355 void InspectorInstrumentation::willSendRequestImpl(InspectorController* ic, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
356 {
357     ic->willSendRequest(request);
358     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(ic))
359         timelineAgent->willSendResourceRequest(identifier, request);
360     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
361         resourceAgent->willSendRequest(identifier, request, redirectResponse);
362 }
363
364 void InspectorInstrumentation::markResourceAsCachedImpl(InspectorController* ic, unsigned long identifier)
365 {
366     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
367         resourceAgent->markResourceAsCached(identifier);
368 }
369
370 void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InspectorController* ic, DocumentLoader* loader, const CachedResource* cachedResource)
371 {
372     if (!ic->enabled())
373         return;
374     ic->ensureSettingsLoaded();
375     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
376         resourceAgent->didLoadResourceFromMemoryCache(loader, cachedResource);
377 }
378
379 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceDataImpl(InspectorController* inspectorController, unsigned long identifier)
380 {
381     int timelineAgentId = 0;
382     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
383     if (timelineAgent) {
384         timelineAgent->willReceiveResourceData(identifier);
385         timelineAgentId = timelineAgent->id();
386     }
387     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
388 }
389
390 void InspectorInstrumentation::didReceiveResourceDataImpl(const InspectorInstrumentationCookie& cookie)
391 {
392     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
393         timelineAgent->didReceiveResourceData();
394 }
395
396 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceResponseImpl(InspectorController* inspectorController, unsigned long identifier, const ResourceResponse& response)
397 {
398     int timelineAgentId = 0;
399     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
400     if (timelineAgent) {
401         timelineAgent->willReceiveResourceResponse(identifier, response);
402         timelineAgentId = timelineAgent->id();
403     }
404     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
405 }
406
407 void InspectorInstrumentation::didReceiveResourceResponseImpl(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response)
408 {
409     InspectorController* ic = cookie.first;
410     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
411         resourceAgent->didReceiveResponse(identifier, loader, response);
412     // FIXME(52282): move this to console agent.
413     ic->didReceiveResponse(identifier, response);
414     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
415         timelineAgent->didReceiveResourceResponse();
416 }
417
418 void InspectorInstrumentation::didReceiveContentLengthImpl(InspectorController* ic, unsigned long identifier, int lengthReceived)
419 {
420     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
421         resourceAgent->didReceiveContentLength(identifier, lengthReceived);
422 }
423
424 void InspectorInstrumentation::didFinishLoadingImpl(InspectorController* ic, unsigned long identifier, double finishTime)
425 {
426     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(ic))
427         timelineAgent->didFinishLoadingResource(identifier, false, finishTime);
428     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
429         resourceAgent->didFinishLoading(identifier, finishTime);
430 }
431
432 void InspectorInstrumentation::didFailLoadingImpl(InspectorController* ic, unsigned long identifier, const ResourceError& error)
433 {
434     // FIXME(52282): move this to console agent.
435     ic->didFailLoading(identifier, error);
436     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(ic))
437         timelineAgent->didFinishLoadingResource(identifier, true, 0);
438     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
439         resourceAgent->didFailLoading(identifier, error);
440 }
441
442 void InspectorInstrumentation::resourceRetrievedByXMLHttpRequestImpl(InspectorController* ic, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber)
443 {
444     ic->resourceRetrievedByXMLHttpRequest(url, sendURL, sendLineNumber);
445     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
446         resourceAgent->setInitialContent(identifier, sourceString, "XHR");
447 }
448
449 void InspectorInstrumentation::scriptImportedImpl(InspectorController* ic, unsigned long identifier, const String& sourceString)
450 {
451     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
452         resourceAgent->setInitialContent(identifier, sourceString, "Script");
453 }
454
455 InspectorInstrumentationCookie InspectorInstrumentation::willWriteHTMLImpl(InspectorController* inspectorController, unsigned int length, unsigned int startLine)
456 {
457     int timelineAgentId = 0;
458     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(inspectorController);
459     if (timelineAgent) {
460         timelineAgent->willWriteHTML(length, startLine);
461         timelineAgentId = timelineAgent->id();
462     }
463     return InspectorInstrumentationCookie(inspectorController, timelineAgentId);
464 }
465
466 void InspectorInstrumentation::didWriteHTMLImpl(const InspectorInstrumentationCookie& cookie, unsigned int endLine)
467 {
468     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
469         timelineAgent->didWriteHTML(endLine);
470 }
471
472 #if ENABLE(WEB_SOCKETS)
473 void InspectorInstrumentation::didCreateWebSocketImpl(InspectorController* inspectorController, unsigned long identifier, const KURL& requestURL, const KURL& documentURL)
474 {
475     inspectorController->didCreateWebSocket(identifier, requestURL, documentURL);
476 }
477
478 void InspectorInstrumentation::willSendWebSocketHandshakeRequestImpl(InspectorController* inspectorController, unsigned long identifier, const WebSocketHandshakeRequest& request)
479 {
480     inspectorController->willSendWebSocketHandshakeRequest(identifier, request);
481 }
482
483 void InspectorInstrumentation::didReceiveWebSocketHandshakeResponseImpl(InspectorController* inspectorController, unsigned long identifier, const WebSocketHandshakeResponse& response)
484 {
485     inspectorController->didReceiveWebSocketHandshakeResponse(identifier, response);
486 }
487
488 void InspectorInstrumentation::didCloseWebSocketImpl(InspectorController* inspectorController, unsigned long identifier)
489 {
490     inspectorController->didCloseWebSocket(identifier);
491 }
492 #endif
493
494 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
495 void InspectorInstrumentation::networkStateChangedImpl(InspectorController* ic)
496 {
497     if (InspectorApplicationCacheAgent* applicationCacheAgent = ic->applicationCacheAgent())
498         applicationCacheAgent->networkStateChanged();
499 }
500
501 void InspectorInstrumentation::updateApplicationCacheStatusImpl(InspectorController* ic, Frame* frame)
502 {
503     if (InspectorApplicationCacheAgent* applicationCacheAgent = ic->applicationCacheAgent())
504         applicationCacheAgent->updateApplicationCacheStatus(frame);
505 }
506 #endif
507
508 bool InspectorInstrumentation::hasFrontend(InspectorController* inspectorController)
509 {
510     return inspectorController->hasFrontend();
511 }
512
513 void InspectorInstrumentation::pauseOnNativeEventIfNeeded(InspectorController* inspectorController, const String& categoryType, const String& eventName, bool synchronous)
514 {
515 #if ENABLE(JAVASCRIPT_DEBUGGER)
516     if (InspectorBrowserDebuggerAgent* browserDebuggerAgent = inspectorController->m_browserDebuggerAgent.get())
517         browserDebuggerAgent->pauseOnNativeEventIfNeeded(categoryType, eventName, synchronous);
518 #endif
519 }
520
521 void InspectorInstrumentation::cancelPauseOnNativeEvent(InspectorController* inspectorController)
522 {
523 #if ENABLE(JAVASCRIPT_DEBUGGER)
524     if (InspectorDebuggerAgent* debuggerAgent = inspectorController->m_debuggerAgent.get())
525         debuggerAgent->cancelPauseOnNextStatement();
526 #endif
527 }
528
529 InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(InspectorController* inspectorController)
530 {
531     return inspectorController->m_timelineAgent.get();
532 }
533
534 InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
535 {
536     InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie.first);
537     if (timelineAgent && timelineAgent->id() == cookie.second)
538         return timelineAgent;
539     return 0;
540 }
541
542 InspectorResourceAgent* InspectorInstrumentation::retrieveResourceAgent(InspectorController* ic)
543 {
544     return ic->m_resourceAgent.get();
545 }
546
547 } // namespace WebCore
548
549 #endif // !ENABLE(INSPECTOR)