2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
35 #include "InspectorInstrumentation.h"
38 #include "CSSStyleRule.h"
39 #include "DOMWindow.h"
41 #include "DocumentLoader.h"
43 #include "EventContext.h"
44 #include "InspectorAgent.h"
45 #include "InspectorApplicationCacheAgent.h"
46 #include "InspectorDOMDebuggerAgent.h"
47 #include "InspectorCSSAgent.h"
48 #include "InspectorConsoleAgent.h"
49 #include "InspectorController.h"
50 #include "WorkerInspectorController.h"
51 #include "InspectorDatabaseAgent.h"
52 #include "InspectorDOMAgent.h"
53 #include "InspectorDOMStorageAgent.h"
54 #include "InspectorDebuggerAgent.h"
55 #include "InspectorPageAgent.h"
56 #include "InspectorProfilerAgent.h"
57 #include "InspectorResourceAgent.h"
58 #include "InspectorRuntimeAgent.h"
59 #include "InspectorTimelineAgent.h"
60 #include "InspectorWorkerAgent.h"
61 #include "InstrumentingAgents.h"
62 #include "PageRuntimeAgent.h"
63 #include "ScriptArguments.h"
64 #include "ScriptCallStack.h"
65 #include "ScriptProfile.h"
66 #include "StyleRule.h"
67 #include "WorkerContext.h"
68 #include "WorkerThread.h"
69 #include "XMLHttpRequest.h"
70 #include <wtf/StdLibExtras.h>
71 #include <wtf/ThreadSpecific.h>
72 #include <wtf/text/CString.h>
76 static const char* const requestAnimationFrameEventName = "requestAnimationFrame";
77 static const char* const cancelAnimationFrameEventName = "cancelAnimationFrame";
78 static const char* const animationFrameFiredEventName = "animationFrameFired";
79 static const char* const setTimerEventName = "setTimer";
80 static const char* const clearTimerEventName = "clearTimer";
81 static const char* const timerFiredEventName = "timerFired";
84 static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0;
87 int InspectorInstrumentation::s_frontendCounter = 0;
89 static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors)
91 if (window && window->hasEventListeners(eventType))
94 if (node->hasEventListeners(eventType))
97 for (size_t i = 0; i < ancestors.size(); i++) {
98 Node* ancestor = ancestors[i].node();
99 if (ancestor->hasEventListeners(eventType))
106 static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
109 if (context->isDocument())
110 frame = static_cast<Document*>(context)->frame();
114 void InspectorInstrumentation::didClearWindowObjectInWorldImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, DOMWrapperWorld* world)
116 InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent();
118 pageAgent->didClearWindowObjectInWorld(frame, world);
119 if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
120 inspectorAgent->didClearWindowObjectInWorld(frame, world);
121 #if ENABLE(JAVASCRIPT_DEBUGGER)
122 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent()) {
123 if (pageAgent && world == mainThreadNormalWorld() && frame == pageAgent->mainFrame())
124 debuggerAgent->didClearMainFrameWindowObject();
127 if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents->pageRuntimeAgent()) {
128 if (world == mainThreadNormalWorld())
129 pageRuntimeAgent->didClearWindowObject(frame);
133 bool InspectorInstrumentation::isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents)
135 #if ENABLE(JAVASCRIPT_DEBUGGER)
136 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
137 return debuggerAgent->isPaused();
142 void InspectorInstrumentation::willInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* parent)
144 #if ENABLE(JAVASCRIPT_DEBUGGER)
145 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
146 domDebuggerAgent->willInsertDOMNode(parent);
150 void InspectorInstrumentation::didInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
152 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
153 domAgent->didInsertDOMNode(node);
154 #if ENABLE(JAVASCRIPT_DEBUGGER)
155 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
156 domDebuggerAgent->didInsertDOMNode(node);
160 void InspectorInstrumentation::willRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
162 #if ENABLE(JAVASCRIPT_DEBUGGER)
163 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
164 domDebuggerAgent->willRemoveDOMNode(node);
168 void InspectorInstrumentation::didRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
170 #if ENABLE(JAVASCRIPT_DEBUGGER)
171 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
172 domDebuggerAgent->didRemoveDOMNode(node);
174 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
175 domAgent->didRemoveDOMNode(node);
178 void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& oldValue, const AtomicString& newValue)
180 #if ENABLE(JAVASCRIPT_DEBUGGER)
181 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
182 domDebuggerAgent->willModifyDOMAttr(element);
183 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
184 domAgent->willModifyDOMAttr(element, oldValue, newValue);
188 void InspectorInstrumentation::didModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name, const AtomicString& value)
190 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
191 domAgent->didModifyDOMAttr(element, name, value);
194 void InspectorInstrumentation::didRemoveDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name)
196 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
197 domAgent->didRemoveDOMAttr(element, name);
200 void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents* instrumentingAgents, Node* node)
202 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
203 domAgent->didInvalidateStyleAttr(node);
204 #if ENABLE(JAVASCRIPT_DEBUGGER)
205 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
206 domDebuggerAgent->didInvalidateStyleAttr(node);
210 void InspectorInstrumentation::frameWindowDiscardedImpl(InstrumentingAgents* instrumentingAgents, DOMWindow* window)
212 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
213 consoleAgent->frameWindowDiscarded(window);
216 void InspectorInstrumentation::mediaQueryResultChangedImpl(InstrumentingAgents* instrumentingAgents)
218 if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
219 cssAgent->mediaQueryResultChanged();
222 void InspectorInstrumentation::didPushShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
224 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
225 domAgent->didPushShadowRoot(host, root);
228 void InspectorInstrumentation::willPopShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
230 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
231 domAgent->willPopShadowRoot(host, root);
234 void InspectorInstrumentation::mouseDidMoveOverElementImpl(InstrumentingAgents* instrumentingAgents, const HitTestResult& result, unsigned modifierFlags)
236 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
237 domAgent->mouseDidMoveOverElement(result, modifierFlags);
240 bool InspectorInstrumentation::handleMousePressImpl(InstrumentingAgents* instrumentingAgents)
242 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
243 return domAgent->handleMousePress();
247 bool InspectorInstrumentation::forcePseudoStateImpl(InstrumentingAgents* instrumentingAgents, Element* element, CSSSelector::PseudoType pseudoState)
249 if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
250 return cssAgent->forcePseudoState(element, pseudoState);
254 void InspectorInstrumentation::characterDataModifiedImpl(InstrumentingAgents* instrumentingAgents, CharacterData* characterData)
256 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
257 domAgent->characterDataModified(characterData);
260 void InspectorInstrumentation::willSendXMLHttpRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url)
262 #if ENABLE(JAVASCRIPT_DEBUGGER)
263 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
264 domDebuggerAgent->willSendXMLHttpRequest(url);
268 void InspectorInstrumentation::didScheduleResourceRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url, Frame* frame)
270 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
271 timelineAgent->didScheduleResourceRequest(url, frame);
274 void InspectorInstrumentation::didInstallTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, int timeout, bool singleShot, ScriptExecutionContext* context)
276 pauseOnNativeEventIfNeeded(instrumentingAgents, false, setTimerEventName, true);
277 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
278 timelineAgent->didInstallTimer(timerId, timeout, singleShot, frameForScriptExecutionContext(context));
281 void InspectorInstrumentation::didRemoveTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
283 pauseOnNativeEventIfNeeded(instrumentingAgents, false, clearTimerEventName, true);
284 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
285 timelineAgent->didRemoveTimer(timerId, frameForScriptExecutionContext(context));
288 InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents* instrumentingAgents, const String& scriptName, int scriptLine, ScriptExecutionContext* context)
290 int timelineAgentId = 0;
291 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
292 timelineAgent->willCallFunction(scriptName, scriptLine, frameForScriptExecutionContext(context));
293 timelineAgentId = timelineAgent->id();
295 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
298 void InspectorInstrumentation::didCallFunctionImpl(const InspectorInstrumentationCookie& cookie)
300 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
301 timelineAgent->didCallFunction();
304 InspectorInstrumentationCookie InspectorInstrumentation::willChangeXHRReadyStateImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
306 int timelineAgentId = 0;
307 InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
308 if (timelineAgent && request->hasEventListeners(eventNames().readystatechangeEvent)) {
309 timelineAgent->willChangeXHRReadyState(request->url().string(), request->readyState(), frameForScriptExecutionContext(context));
310 timelineAgentId = timelineAgent->id();
312 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
315 void InspectorInstrumentation::didChangeXHRReadyStateImpl(const InspectorInstrumentationCookie& cookie)
317 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
318 timelineAgent->didChangeXHRReadyState();
321 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors, Document* document)
323 int timelineAgentId = 0;
324 InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
325 if (timelineAgent && eventHasListeners(event.type(), window, node, ancestors)) {
326 timelineAgent->willDispatchEvent(event, document->frame());
327 timelineAgentId = timelineAgent->id();
329 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
332 InspectorInstrumentationCookie InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents* instrumentingAgents, Event* event)
334 pauseOnNativeEventIfNeeded(instrumentingAgents, true, event->type(), false);
335 return InspectorInstrumentationCookie(instrumentingAgents, 0);
338 void InspectorInstrumentation::didHandleEventImpl(const InspectorInstrumentationCookie& cookie)
340 cancelPauseOnNativeEvent(cookie.first);
343 void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)
345 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
346 timelineAgent->didDispatchEvent();
349 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window)
351 int timelineAgentId = 0;
352 InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
353 if (timelineAgent && window->hasEventListeners(event.type())) {
354 timelineAgent->willDispatchEvent(event, window ? window->frame() : 0);
355 timelineAgentId = timelineAgent->id();
357 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
360 void InspectorInstrumentation::didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie& cookie)
362 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
363 timelineAgent->didDispatchEvent();
366 InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InstrumentingAgents* instrumentingAgents, const String& url, int lineNumber, Frame* frame)
368 int timelineAgentId = 0;
369 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
370 timelineAgent->willEvaluateScript(url, lineNumber, frame);
371 timelineAgentId = timelineAgent->id();
373 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
376 void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentationCookie& cookie)
378 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
379 timelineAgent->didEvaluateScript();
382 void InspectorInstrumentation::didCreateIsolatedContextImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, ScriptState* scriptState, SecurityOrigin* origin)
384 if (PageRuntimeAgent* runtimeAgent = instrumentingAgents->pageRuntimeAgent())
385 runtimeAgent->didCreateIsolatedContext(frame, scriptState, origin);
388 InspectorInstrumentationCookie InspectorInstrumentation::willFireTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
390 pauseOnNativeEventIfNeeded(instrumentingAgents, false, timerFiredEventName, false);
392 int timelineAgentId = 0;
393 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
394 timelineAgent->willFireTimer(timerId, frameForScriptExecutionContext(context));
395 timelineAgentId = timelineAgent->id();
397 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
400 void InspectorInstrumentation::didFireTimerImpl(const InspectorInstrumentationCookie& cookie)
402 cancelPauseOnNativeEvent(cookie.first);
404 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
405 timelineAgent->didFireTimer();
408 void InspectorInstrumentation::didBeginFrameImpl(InstrumentingAgents* instrumentingAgents)
410 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
411 timelineAgent->didBeginFrame();
414 void InspectorInstrumentation::didCancelFrameImpl(InstrumentingAgents* instrumentingAgents)
416 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
417 timelineAgent->didCancelFrame();
420 InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
422 int timelineAgentId = 0;
423 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
424 timelineAgent->willLayout(frame);
425 timelineAgentId = timelineAgent->id();
427 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
430 void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie)
435 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
436 timelineAgent->didLayout();
438 if (InspectorPageAgent* pageAgent = cookie.first->inspectorPageAgent())
439 pageAgent->didLayout();
442 InspectorInstrumentationCookie InspectorInstrumentation::willLoadXHRImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
444 int timelineAgentId = 0;
445 InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
446 if (timelineAgent && request->hasEventListeners(eventNames().loadEvent)) {
447 timelineAgent->willLoadXHR(request->url(), frameForScriptExecutionContext(context));
448 timelineAgentId = timelineAgent->id();
450 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
453 void InspectorInstrumentation::didLoadXHRImpl(const InspectorInstrumentationCookie& cookie)
455 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
456 timelineAgent->didLoadXHR();
459 InspectorInstrumentationCookie InspectorInstrumentation::willPaintImpl(InstrumentingAgents* instrumentingAgents, GraphicsContext* context, const LayoutRect& rect, Frame* frame)
461 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
462 pageAgent->willPaint(context, rect);
464 int timelineAgentId = 0;
465 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
466 timelineAgent->willPaint(rect, frame);
467 timelineAgentId = timelineAgent->id();
469 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
472 void InspectorInstrumentation::didPaintImpl(const InspectorInstrumentationCookie& cookie)
474 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
475 timelineAgent->didPaint();
476 if (InspectorPageAgent* pageAgent = cookie.first ? cookie.first->inspectorPageAgent() : 0)
477 pageAgent->didPaint();
480 void InspectorInstrumentation::willCompositeImpl(InstrumentingAgents* instrumentingAgents)
482 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
483 timelineAgent->willComposite();
486 void InspectorInstrumentation::didCompositeImpl(InstrumentingAgents* instrumentingAgents)
488 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
489 timelineAgent->didComposite();
492 InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
494 int timelineAgentId = 0;
495 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
496 timelineAgent->willRecalculateStyle(frame);
497 timelineAgentId = timelineAgent->id();
499 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
500 resourceAgent->willRecalculateStyle();
501 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
504 void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrumentationCookie& cookie)
506 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
507 timelineAgent->didRecalculateStyle();
508 InstrumentingAgents* instrumentingAgents = cookie.first;
509 if (!instrumentingAgents)
511 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
512 resourceAgent->didRecalculateStyle();
515 void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents* instrumentingAgents, Document* document)
517 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
518 resourceAgent->didScheduleStyleRecalculation(document);
521 InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(InstrumentingAgents* instrumentingAgents, const StyleRule* rule)
523 InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
525 RefPtr<CSSRule> cssRule = rule->createCSSOMWrapper();
526 cssAgent->willMatchRule(static_cast<CSSStyleRule*>(cssRule.get()));
527 return InspectorInstrumentationCookie(instrumentingAgents, 1);
530 return InspectorInstrumentationCookie();
533 void InspectorInstrumentation::didMatchRuleImpl(const InspectorInstrumentationCookie& cookie, bool matched)
535 InspectorCSSAgent* cssAgent = cookie.first->inspectorCSSAgent();
537 cssAgent->didMatchRule(matched);
540 InspectorInstrumentationCookie InspectorInstrumentation::willProcessRuleImpl(InstrumentingAgents* instrumentingAgents, const StyleRule* rule)
542 InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
544 RefPtr<CSSRule> cssRule = rule->createCSSOMWrapper();
545 cssAgent->willProcessRule(static_cast<CSSStyleRule*>(cssRule.get()));
546 return InspectorInstrumentationCookie(instrumentingAgents, 1);
549 return InspectorInstrumentationCookie();
552 void InspectorInstrumentation::didProcessRuleImpl(const InspectorInstrumentationCookie& cookie)
554 InspectorCSSAgent* cssAgent = cookie.first->inspectorCSSAgent();
556 cssAgent->didProcessRule();
559 void InspectorInstrumentation::willProcessTaskImpl(InstrumentingAgents* instrumentingAgents)
561 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
562 timelineAgent->willProcessTask();
565 void InspectorInstrumentation::didProcessTaskImpl(InstrumentingAgents* instrumentingAgents)
567 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
568 timelineAgent->didProcessTask();
571 void InspectorInstrumentation::applyUserAgentOverrideImpl(InstrumentingAgents* instrumentingAgents, String* userAgent)
573 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
574 resourceAgent->applyUserAgentOverride(userAgent);
577 void InspectorInstrumentation::applyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents, long* width)
579 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
580 pageAgent->applyScreenWidthOverride(width);
583 void InspectorInstrumentation::applyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents, long* height)
585 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
586 pageAgent->applyScreenHeightOverride(height);
589 bool InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents)
591 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
593 pageAgent->applyScreenWidthOverride(&width);
599 bool InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents)
601 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
603 pageAgent->applyScreenHeightOverride(&height);
609 void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
611 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
612 timelineAgent->willSendResourceRequest(identifier, request, loader->frame());
613 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
614 resourceAgent->willSendRequest(identifier, loader, request, redirectResponse);
617 void InspectorInstrumentation::continueAfterPingLoaderImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& response)
619 willSendRequestImpl(instrumentingAgents, identifier, loader, request, response);
622 void InspectorInstrumentation::markResourceAsCachedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
624 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
625 resourceAgent->markResourceAsCached(identifier);
628 void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
630 InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
631 if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
633 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
634 resourceAgent->didLoadResourceFromMemoryCache(loader, cachedResource);
637 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, Frame* frame, int length)
639 int timelineAgentId = 0;
640 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
641 timelineAgent->willReceiveResourceData(identifier, frame, length);
642 timelineAgentId = timelineAgent->id();
644 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
647 void InspectorInstrumentation::didReceiveResourceDataImpl(const InspectorInstrumentationCookie& cookie)
649 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
650 timelineAgent->didReceiveResourceData();
653 InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Frame* frame)
655 int timelineAgentId = 0;
656 InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
658 timelineAgent->willReceiveResourceResponse(identifier, response, frame);
659 timelineAgentId = timelineAgent->id();
661 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
664 void InspectorInstrumentation::didReceiveResourceResponseImpl(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response)
666 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
667 timelineAgent->didReceiveResourceResponse();
670 InstrumentingAgents* instrumentingAgents = cookie.first;
671 if (!instrumentingAgents)
673 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
674 resourceAgent->didReceiveResponse(identifier, loader, response);
675 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
676 consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
679 void InspectorInstrumentation::didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
681 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(frame, identifier, r);
682 InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r);
685 void InspectorInstrumentation::continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
687 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
690 void InspectorInstrumentation::continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
692 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
695 void InspectorInstrumentation::continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
697 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
700 void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
702 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
703 resourceAgent->didReceiveData(identifier, data, dataLength, encodedDataLength);
706 void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, double monotonicFinishTime)
708 InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
709 InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent();
710 if (!timelineAgent && !resourceAgent)
713 double finishTime = 0.0;
714 // FIXME: Expose all of the timing details to inspector and have it calculate finishTime.
715 if (monotonicFinishTime)
716 finishTime = loader->timing()->convertMonotonicTimeToDocumentTime(monotonicFinishTime);
719 timelineAgent->didFinishLoadingResource(identifier, false, finishTime, loader->frame());
721 resourceAgent->didFinishLoading(identifier, loader, finishTime);
724 void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
726 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
727 timelineAgent->didFinishLoadingResource(identifier, true, 0, loader->frame());
728 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
729 resourceAgent->didFailLoading(identifier, loader, error);
730 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
731 consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
734 void InspectorInstrumentation::resourceRetrievedByXMLHttpRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber)
736 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
737 consoleAgent->resourceRetrievedByXMLHttpRequest(identifier, url, sendURL, sendLineNumber);
738 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
739 resourceAgent->setInitialXHRContent(identifier, sourceString);
742 void InspectorInstrumentation::didReceiveXHRResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
744 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
745 resourceAgent->didReceiveXHRResponse(identifier);
748 void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
750 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
751 resourceAgent->willLoadXHRSynchronously();
754 void InspectorInstrumentation::didLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
756 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
757 resourceAgent->didLoadXHRSynchronously();
760 void InspectorInstrumentation::scriptImportedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& sourceString)
762 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
763 resourceAgent->setInitialScriptContent(identifier, sourceString);
766 void InspectorInstrumentation::didReceiveScriptResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
768 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
769 resourceAgent->didReceiveScriptResponse(identifier);
772 void InspectorInstrumentation::domContentLoadedEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
774 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
775 timelineAgent->didMarkDOMContentEvent(frame);
777 if (frame->page()->mainFrame() != frame)
780 if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
781 inspectorAgent->domContentLoadedEventFired();
783 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
784 domAgent->mainFrameDOMContentLoaded();
786 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
787 pageAgent->domContentEventFired();
790 void InspectorInstrumentation::loadEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
792 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
793 domAgent->loadEventFired(frame->document());
795 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
796 timelineAgent->didMarkLoadEvent(frame);
798 if (frame->page()->mainFrame() != frame)
801 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
802 pageAgent->loadEventFired();
805 void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
807 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
808 pageAgent->frameDetached(frame);
811 void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents* instrumentingAgents, Page* page, DocumentLoader* loader)
813 InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
814 if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
817 Frame* mainFrame = page->mainFrame();
818 if (loader->frame() == mainFrame) {
819 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
820 consoleAgent->reset();
822 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
823 resourceAgent->mainFrameNavigated(loader);
824 #if ENABLE(JAVASCRIPT_DEBUGGER) && USE(JSC)
825 if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
826 profilerAgent->resetState();
828 if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
830 #if ENABLE(SQL_DATABASE)
831 if (InspectorDatabaseAgent* databaseAgent = instrumentingAgents->inspectorDatabaseAgent())
832 databaseAgent->clearResources();
834 if (InspectorDOMStorageAgent* domStorageAgent = instrumentingAgents->inspectorDOMStorageAgent())
835 domStorageAgent->clearResources();
836 if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
837 domAgent->setDocument(mainFrame->document());
839 inspectorAgent->didCommitLoad();
841 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
842 pageAgent->frameNavigated(loader);
845 void InspectorInstrumentation::loaderDetachedFromFrameImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader)
847 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
848 inspectorPageAgent->loaderDetachedFromFrame(loader);
851 void InspectorInstrumentation::willDestroyCachedResourceImpl(CachedResource* cachedResource)
853 if (!instrumentingAgentsSet)
855 HashSet<InstrumentingAgents*>::iterator end = instrumentingAgentsSet->end();
856 for (HashSet<InstrumentingAgents*>::iterator it = instrumentingAgentsSet->begin(); it != end; ++it) {
857 InstrumentingAgents* instrumentingAgents = *it;
858 if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgents->inspectorResourceAgent())
859 inspectorResourceAgent->willDestroyCachedResource(cachedResource);
863 InspectorInstrumentationCookie InspectorInstrumentation::willWriteHTMLImpl(InstrumentingAgents* instrumentingAgents, unsigned int length, unsigned int startLine, Frame* frame)
865 int timelineAgentId = 0;
866 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
867 timelineAgent->willWriteHTML(length, startLine, frame);
868 timelineAgentId = timelineAgent->id();
870 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
873 void InspectorInstrumentation::didWriteHTMLImpl(const InspectorInstrumentationCookie& cookie, unsigned int endLine)
875 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
876 timelineAgent->didWriteHTML(endLine);
879 void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptArguments> arguments, PassRefPtr<ScriptCallStack> callStack)
881 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
882 consoleAgent->addMessageToConsole(source, type, level, message, arguments, callStack);
885 void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, const String& scriptId, unsigned lineNumber)
887 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
888 consoleAgent->addMessageToConsole(source, type, level, message, scriptId, lineNumber);
891 void InspectorInstrumentation::consoleCountImpl(InstrumentingAgents* instrumentingAgents, PassRefPtr<ScriptArguments> arguments, PassRefPtr<ScriptCallStack> stack)
893 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
894 consoleAgent->count(arguments, stack);
897 void InspectorInstrumentation::startConsoleTimingImpl(InstrumentingAgents* instrumentingAgents, const String& title)
899 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
900 timelineAgent->time(title);
901 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
902 consoleAgent->startTiming(title);
905 void InspectorInstrumentation::stopConsoleTimingImpl(InstrumentingAgents* instrumentingAgents, const String& title, PassRefPtr<ScriptCallStack> stack)
907 if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
908 consoleAgent->stopTiming(title, stack);
909 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
910 timelineAgent->timeEnd(title);
913 void InspectorInstrumentation::consoleTimeStampImpl(InstrumentingAgents* instrumentingAgents, PassRefPtr<ScriptArguments> arguments)
915 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
917 arguments->getFirstArgumentAsString(message);
918 timelineAgent->didTimeStamp(message);
922 #if ENABLE(JAVASCRIPT_DEBUGGER)
923 void InspectorInstrumentation::addStartProfilingMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, const String& title, unsigned lineNumber, const String& sourceURL)
925 if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
926 profilerAgent->addStartProfilingMessageToConsole(title, lineNumber, sourceURL);
929 void InspectorInstrumentation::addProfileImpl(InstrumentingAgents* instrumentingAgents, RefPtr<ScriptProfile> profile, PassRefPtr<ScriptCallStack> callStack)
931 if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent()) {
932 const ScriptCallFrame& lastCaller = callStack->at(0);
933 profilerAgent->addProfile(profile, lastCaller.lineNumber(), lastCaller.sourceURL());
937 String InspectorInstrumentation::getCurrentUserInitiatedProfileNameImpl(InstrumentingAgents* instrumentingAgents, bool incrementProfileNumber)
939 if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
940 return profilerAgent->getCurrentUserInitiatedProfileName(incrementProfileNumber);
944 bool InspectorInstrumentation::profilerEnabledImpl(InstrumentingAgents* instrumentingAgents)
946 if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
947 return profilerAgent->enabled();
952 #if ENABLE(SQL_DATABASE)
953 void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents* instrumentingAgents, PassRefPtr<Database> database, const String& domain, const String& name, const String& version)
955 InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
956 if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
958 if (InspectorDatabaseAgent* dbAgent = instrumentingAgents->inspectorDatabaseAgent())
959 dbAgent->didOpenDatabase(database, domain, name, version);
963 void InspectorInstrumentation::didUseDOMStorageImpl(InstrumentingAgents* instrumentingAgents, StorageArea* storageArea, bool isLocalStorage, Frame* frame)
965 InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
966 if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
968 if (InspectorDOMStorageAgent* domStorageAgent = instrumentingAgents->inspectorDOMStorageAgent())
969 domStorageAgent->didUseDOMStorage(storageArea, isLocalStorage, frame);
972 void InspectorInstrumentation::didDispatchDOMStorageEventImpl(InstrumentingAgents* instrumentingAgents, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Page* page)
974 if (InspectorDOMStorageAgent* domStorageAgent = instrumentingAgents->inspectorDOMStorageAgent())
975 domStorageAgent->didDispatchDOMStorageEvent(key, oldValue, newValue, storageType, securityOrigin, page);
979 bool InspectorInstrumentation::shouldPauseDedicatedWorkerOnStartImpl(InstrumentingAgents* instrumentingAgents)
981 if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
982 return workerAgent->shouldPauseDedicatedWorkerOnStart();
986 void InspectorInstrumentation::didStartWorkerContextImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* workerContextProxy, const KURL& url)
988 if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
989 workerAgent->didStartWorkerContext(workerContextProxy, url);
992 void InspectorInstrumentation::willEvaluateWorkerScript(WorkerContext* workerContext, int workerThreadStartMode)
994 if (workerThreadStartMode != PauseWorkerContextOnStart)
996 InstrumentingAgents* instrumentingAgents = instrumentationForWorkerContext(workerContext);
997 if (!instrumentingAgents)
999 #if ENABLE(JAVASCRIPT_DEBUGGER)
1000 if (InspectorRuntimeAgent* runtimeAgent = instrumentingAgents->inspectorRuntimeAgent())
1001 runtimeAgent->pauseWorkerContext(workerContext);
1005 void InspectorInstrumentation::workerContextTerminatedImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* proxy)
1007 if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
1008 workerAgent->workerContextTerminated(proxy);
1012 #if ENABLE(WEB_SOCKETS)
1013 void InspectorInstrumentation::didCreateWebSocketImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const KURL& requestURL, const KURL&)
1015 InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
1016 if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
1018 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1019 resourceAgent->didCreateWebSocket(identifier, requestURL);
1022 void InspectorInstrumentation::willSendWebSocketHandshakeRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketHandshakeRequest& request)
1024 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1025 resourceAgent->willSendWebSocketHandshakeRequest(identifier, request);
1028 void InspectorInstrumentation::didReceiveWebSocketHandshakeResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketHandshakeResponse& response)
1030 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1031 resourceAgent->didReceiveWebSocketHandshakeResponse(identifier, response);
1034 void InspectorInstrumentation::didCloseWebSocketImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
1036 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1037 resourceAgent->didCloseWebSocket(identifier);
1039 void InspectorInstrumentation::didReceiveWebSocketFrameImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
1041 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1042 resourceAgent->didReceiveWebSocketFrame(identifier, frame);
1044 void InspectorInstrumentation::didReceiveWebSocketFrameErrorImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& errorMessage)
1046 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1047 resourceAgent->didReceiveWebSocketFrameError(identifier, errorMessage);
1049 void InspectorInstrumentation::didSendWebSocketFrameImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
1051 if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
1052 resourceAgent->didSendWebSocketFrame(identifier, frame);
1056 void InspectorInstrumentation::networkStateChangedImpl(InstrumentingAgents* instrumentingAgents)
1058 if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents->inspectorApplicationCacheAgent())
1059 applicationCacheAgent->networkStateChanged();
1062 void InspectorInstrumentation::updateApplicationCacheStatusImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
1064 if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents->inspectorApplicationCacheAgent())
1065 applicationCacheAgent->updateApplicationCacheStatus(frame);
1068 bool InspectorInstrumentation::collectingHTMLParseErrors(InstrumentingAgents* instrumentingAgents)
1070 if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
1071 return inspectorAgent->hasFrontend();
1075 bool InspectorInstrumentation::hasFrontendForScriptContext(ScriptExecutionContext* scriptExecutionContext)
1077 if (!scriptExecutionContext)
1081 if (scriptExecutionContext->isWorkerContext()) {
1082 WorkerContext* workerContext = static_cast<WorkerContext*>(scriptExecutionContext);
1083 WorkerInspectorController* workerInspectorController = workerContext->workerInspectorController();
1084 return workerInspectorController && workerInspectorController->hasFrontend();
1088 ASSERT(scriptExecutionContext->isDocument());
1089 Document* document = static_cast<Document*>(scriptExecutionContext);
1090 Page* page = document->page();
1091 return page && page->inspectorController()->hasFrontend();
1094 void InspectorInstrumentation::pauseOnNativeEventIfNeeded(InstrumentingAgents* instrumentingAgents, bool isDOMEvent, const String& eventName, bool synchronous)
1096 #if ENABLE(JAVASCRIPT_DEBUGGER)
1097 if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
1098 domDebuggerAgent->pauseOnNativeEventIfNeeded(isDOMEvent, eventName, synchronous);
1102 void InspectorInstrumentation::cancelPauseOnNativeEvent(InstrumentingAgents* instrumentingAgents)
1104 #if ENABLE(JAVASCRIPT_DEBUGGER)
1105 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
1106 debuggerAgent->cancelPauseOnNextStatement();
1110 void InspectorInstrumentation::didRequestAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
1112 pauseOnNativeEventIfNeeded(instrumentingAgents, false, requestAnimationFrameEventName, true);
1114 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1115 timelineAgent->didRequestAnimationFrame(callbackId, frame);
1118 void InspectorInstrumentation::didCancelAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
1120 pauseOnNativeEventIfNeeded(instrumentingAgents, false, cancelAnimationFrameEventName, true);
1122 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
1123 timelineAgent->didCancelAnimationFrame(callbackId, frame);
1126 InspectorInstrumentationCookie InspectorInstrumentation::willFireAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
1128 pauseOnNativeEventIfNeeded(instrumentingAgents, false, animationFrameFiredEventName, false);
1130 int timelineAgentId = 0;
1131 if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
1132 timelineAgent->willFireAnimationFrame(callbackId, frame);
1133 timelineAgentId = timelineAgent->id();
1135 return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
1138 void InspectorInstrumentation::didFireAnimationFrameImpl(const InspectorInstrumentationCookie& cookie)
1140 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
1141 timelineAgent->didFireAnimationFrame();
1144 InspectorTimelineAgent* InspectorInstrumentation::timelineAgentForOrphanEvents()
1146 return *threadSpecificTimelineAgentForOrphanEvents();
1149 void InspectorInstrumentation::setTimelineAgentForOrphanEvents(InspectorTimelineAgent* inspectorTimelineAgent)
1151 *threadSpecificTimelineAgentForOrphanEvents() = inspectorTimelineAgent;
1154 WTF::ThreadSpecific<InspectorTimelineAgent*>& InspectorInstrumentation::threadSpecificTimelineAgentForOrphanEvents()
1156 AtomicallyInitializedStatic(WTF::ThreadSpecific<InspectorTimelineAgent*>*, instance = new WTF::ThreadSpecific<InspectorTimelineAgent*>());
1160 void InspectorInstrumentation::registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
1162 if (!instrumentingAgentsSet)
1163 instrumentingAgentsSet = new HashSet<InstrumentingAgents*>();
1164 instrumentingAgentsSet->add(instrumentingAgents);
1167 void InspectorInstrumentation::unregisterInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
1169 if (!instrumentingAgentsSet)
1171 instrumentingAgentsSet->remove(instrumentingAgents);
1172 if (!instrumentingAgentsSet->size())
1173 delete instrumentingAgentsSet;
1176 InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
1180 InspectorTimelineAgent* timelineAgent = cookie.first->inspectorTimelineAgent();
1181 if (timelineAgent && timelineAgent->id() == cookie.second)
1182 return timelineAgent;
1186 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForPage(Page* page)
1190 return instrumentationForPage(page);
1194 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForWorkerContext(WorkerContext* workerContext)
1198 return instrumentationForWorkerContext(workerContext);
1201 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context)
1203 if (context->isWorkerContext())
1204 return instrumentationForWorkerContext(static_cast<WorkerContext*>(context));
1209 #if ENABLE(GEOLOCATION)
1210 GeolocationPosition* InspectorInstrumentation::overrideGeolocationPositionImpl(InstrumentingAgents* instrumentingAgents, GeolocationPosition* position)
1212 if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
1213 position = pageAgent->overrideGeolocationPosition(position);
1218 } // namespace WebCore
1220 #endif // !ENABLE(INSPECTOR)