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.
32 #include "core/inspector/InspectorInstrumentation.h"
34 #include "core/events/EventTarget.h"
35 #include "core/fetch/FetchInitiatorInfo.h"
36 #include "core/inspector/InspectorCSSAgent.h"
37 #include "core/inspector/InspectorConsoleAgent.h"
38 #include "core/inspector/InspectorController.h"
39 #include "core/inspector/InspectorDebuggerAgent.h"
40 #include "core/inspector/InspectorInspectorAgent.h"
41 #include "core/inspector/InspectorProfilerAgent.h"
42 #include "core/inspector/InspectorResourceAgent.h"
43 #include "core/inspector/InspectorTimelineAgent.h"
44 #include "core/inspector/InstrumentingAgents.h"
45 #include "core/inspector/WorkerInspectorController.h"
46 #include "core/workers/WorkerGlobalScope.h"
51 static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0;
54 namespace InspectorInstrumentation {
55 int FrontendCounter::s_frontendCounter = 0;
58 InspectorInstrumentationCookie::InspectorInstrumentationCookie()
59 : m_instrumentingAgents(0)
60 , m_timelineAgentId(0)
64 InspectorInstrumentationCookie::InspectorInstrumentationCookie(InstrumentingAgents* agents, int timelineAgentId)
65 : m_instrumentingAgents(agents)
66 , m_timelineAgentId(timelineAgentId)
70 InspectorInstrumentationCookie::InspectorInstrumentationCookie(const InspectorInstrumentationCookie& other)
71 : m_instrumentingAgents(other.m_instrumentingAgents)
72 , m_timelineAgentId(other.m_timelineAgentId)
76 InspectorInstrumentationCookie& InspectorInstrumentationCookie::operator=(const InspectorInstrumentationCookie& other)
79 m_instrumentingAgents = other.m_instrumentingAgents;
80 m_timelineAgentId = other.m_timelineAgentId;
85 InspectorInstrumentationCookie::~InspectorInstrumentationCookie()
89 namespace InspectorInstrumentation {
91 bool isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents)
93 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
94 return debuggerAgent->isPaused();
98 void didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
100 didReceiveResourceResponse(frame, identifier, loader, r, 0);
103 void continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
105 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
108 void continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
110 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
113 void continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
115 didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
118 void willDestroyResourceImpl(Resource* cachedResource)
120 if (!instrumentingAgentsSet)
122 HashSet<InstrumentingAgents*>::iterator end = instrumentingAgentsSet->end();
123 for (HashSet<InstrumentingAgents*>::iterator it = instrumentingAgentsSet->begin(); it != end; ++it) {
124 InstrumentingAgents* instrumentingAgents = *it;
125 if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgents->inspectorResourceAgent())
126 inspectorResourceAgent->willDestroyResource(cachedResource);
130 bool collectingHTMLParseErrorsImpl(InstrumentingAgents* instrumentingAgents)
132 if (InspectorInspectorAgent* inspectorAgent = instrumentingAgents->inspectorInspectorAgent())
133 return inspectorAgent->hasFrontend();
137 PassOwnPtr<ScriptSourceCode> preprocessImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, const ScriptSourceCode& sourceCode)
139 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
140 return debuggerAgent->preprocess(frame, sourceCode);
141 return PassOwnPtr<ScriptSourceCode>();
144 String preprocessEventListenerImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, const String& source, const String& url, const String& functionName)
146 if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
147 return debuggerAgent->preprocessEventListener(frame, source, url, functionName);
151 bool canvasAgentEnabled(ExecutionContext* executionContext)
153 InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
154 return instrumentingAgents && instrumentingAgents->inspectorCanvasAgent();
157 bool consoleAgentEnabled(ExecutionContext* executionContext)
159 InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
160 InspectorConsoleAgent* consoleAgent = instrumentingAgents ? instrumentingAgents->inspectorConsoleAgent() : 0;
161 return consoleAgent && consoleAgent->enabled();
164 bool timelineAgentEnabled(ExecutionContext* executionContext)
166 InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
167 return instrumentingAgents && instrumentingAgents->inspectorTimelineAgent();
170 void registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
172 if (!instrumentingAgentsSet)
173 instrumentingAgentsSet = new HashSet<InstrumentingAgents*>();
174 instrumentingAgentsSet->add(instrumentingAgents);
177 void unregisterInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
179 if (!instrumentingAgentsSet)
181 instrumentingAgentsSet->remove(instrumentingAgents);
182 if (instrumentingAgentsSet->isEmpty()) {
183 delete instrumentingAgentsSet;
184 instrumentingAgentsSet = 0;
188 InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
190 if (!cookie.instrumentingAgents())
192 InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent();
193 if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id()))
194 return timelineAgent;
198 InstrumentingAgents* instrumentingAgentsFor(Page* page)
202 return instrumentationForPage(page);
205 InstrumentingAgents* instrumentingAgentsFor(EventTarget* eventTarget)
209 return instrumentingAgentsFor(eventTarget->executionContext());
212 InstrumentingAgents* instrumentingAgentsFor(RenderObject* renderer)
214 return instrumentingAgentsFor(renderer->frame());
217 InstrumentingAgents* instrumentingAgentsFor(WorkerGlobalScope* workerGlobalScope)
219 if (!workerGlobalScope)
221 return instrumentationForWorkerGlobalScope(workerGlobalScope);
224 InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ExecutionContext* context)
226 if (context->isWorkerGlobalScope())
227 return instrumentationForWorkerGlobalScope(toWorkerGlobalScope(context));
231 } // namespace InspectorInstrumentation
233 namespace InstrumentationEvents {
234 const char PaintSetup[] = "PaintSetup";
235 const char RasterTask[] = "RasterTask";
236 const char Paint[] = "Paint";
237 const char Layer[] = "Layer";
238 const char RequestMainThreadFrame[] = "RequestMainThreadFrame";
239 const char BeginFrame[] = "BeginFrame";
240 const char ActivateLayerTree[] = "ActivateLayerTree";
241 const char DrawFrame[] = "DrawFrame";
244 namespace InstrumentationEventArguments {
245 const char FrameId[] = "frameId";
246 const char LayerId[] = "layerId";
247 const char LayerTreeId[] = "layerTreeId";
248 const char PageId[] = "pageId";
251 InstrumentingAgents* instrumentationForPage(Page* page)
253 ASSERT(isMainThread());
254 return page->inspectorController().m_instrumentingAgents.get();
257 InstrumentingAgents* instrumentationForWorkerGlobalScope(WorkerGlobalScope* workerGlobalScope)
259 if (WorkerInspectorController* controller = workerGlobalScope->workerInspectorController())
260 return controller->m_instrumentingAgents.get();
264 } // namespace WebCore