2 * Copyright (C) 2010 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.
31 #ifndef InspectorInstrumentation_h
32 #define InspectorInstrumentation_h
34 #include "bindings/core/v8/ScriptString.h"
35 #include "core/css/CSSSelector.h"
36 #include "core/css/CSSStyleDeclaration.h"
37 #include "core/css/CSSStyleSheet.h"
38 #include "core/dom/CharacterData.h"
39 #include "core/dom/Element.h"
40 #include "core/dom/ExecutionContext.h"
41 #include "core/events/NodeEventContext.h"
42 #include "core/frame/LocalFrame.h"
43 #include "core/inspector/ConsoleAPITypes.h"
44 #include "core/rendering/HitTestResult.h"
45 #include "core/rendering/RenderImage.h"
46 #include "core/storage/StorageArea.h"
47 #include "platform/network/FormData.h"
48 #include "platform/network/WebSocketHandshakeRequest.h"
49 #include "platform/network/WebSocketHandshakeResponse.h"
50 #include "wtf/RefPtr.h"
56 class ExecutionContext;
58 class InspectorTimelineAgent;
59 class InstrumentingAgents;
60 class ThreadableLoaderClient;
61 class WorkerGlobalScope;
62 class WorkerInspectorProxy;
64 #define FAST_RETURN_IF_NO_FRONTENDS(value) if (!hasFrontends()) return value;
66 class InspectorInstrumentationCookie {
69 InspectorInstrumentationCookie();
70 InspectorInstrumentationCookie(InstrumentingAgents*, int);
71 InspectorInstrumentationCookie(const InspectorInstrumentationCookie&);
72 InspectorInstrumentationCookie& operator=(const InspectorInstrumentationCookie&);
73 ~InspectorInstrumentationCookie();
75 InstrumentingAgents* instrumentingAgents() const { return m_instrumentingAgents.get(); }
76 bool isValid() const { return !!m_instrumentingAgents; }
77 bool hasMatchingTimelineAgentId(int id) const { return m_timelineAgentId == id; }
80 RefPtrWillBeMember<InstrumentingAgents> m_instrumentingAgents;
81 int m_timelineAgentId;
84 namespace InspectorInstrumentation {
86 class FrontendCounter {
88 friend void frontendCreated();
89 friend void frontendDeleted();
90 friend bool hasFrontends();
91 static int s_frontendCounter;
94 inline void frontendCreated() { atomicIncrement(&FrontendCounter::s_frontendCounter); }
95 inline void frontendDeleted() { atomicDecrement(&FrontendCounter::s_frontendCounter); }
96 inline bool hasFrontends() { return FrontendCounter::s_frontendCounter; }
98 void registerInstrumentingAgents(InstrumentingAgents*);
99 void unregisterInstrumentingAgents(InstrumentingAgents*);
101 InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
103 // Called from generated instrumentation code.
104 InstrumentingAgents* instrumentingAgentsFor(Page*);
105 InstrumentingAgents* instrumentingAgentsFor(LocalFrame*);
106 InstrumentingAgents* instrumentingAgentsFor(EventTarget*);
107 InstrumentingAgents* instrumentingAgentsFor(ExecutionContext*);
108 InstrumentingAgents* instrumentingAgentsFor(Document&);
109 InstrumentingAgents* instrumentingAgentsFor(Document*);
110 InstrumentingAgents* instrumentingAgentsFor(RenderObject*);
111 InstrumentingAgents* instrumentingAgentsFor(Node*);
112 InstrumentingAgents* instrumentingAgentsFor(WorkerGlobalScope*);
113 InstrumentingAgents* instrumentingAgentsFor(FrameHost*);
115 // Helper for the one above.
116 InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ExecutionContext*);
118 } // namespace InspectorInstrumentation
120 namespace InstrumentationEvents {
121 extern const char PaintSetup[];
122 extern const char RasterTask[];
123 extern const char Paint[];
124 extern const char Layer[];
125 extern const char RequestMainThreadFrame[];
126 extern const char BeginFrame[];
127 extern const char DrawFrame[];
128 extern const char ActivateLayerTree[];
129 extern const char EmbedderCallback[];
132 namespace InstrumentationEventArguments {
133 extern const char FrameId[];
134 extern const char LayerId[];
135 extern const char LayerTreeId[];
136 extern const char PageId[];
137 extern const char CallbackName[];
140 namespace InspectorInstrumentation {
142 inline InstrumentingAgents* instrumentingAgentsFor(ExecutionContext* context)
146 return context->isDocument() ? instrumentingAgentsFor(*toDocument(context)) : instrumentingAgentsForNonDocumentContext(context);
149 inline InstrumentingAgents* instrumentingAgentsFor(LocalFrame* frame)
151 return frame ? instrumentingAgentsFor(frame->page()) : 0;
154 inline InstrumentingAgents* instrumentingAgentsFor(Document& document)
156 Page* page = document.page();
157 if (!page && document.templateDocumentHost())
158 page = document.templateDocumentHost()->page();
159 return instrumentingAgentsFor(page);
162 inline InstrumentingAgents* instrumentingAgentsFor(Document* document)
164 return document ? instrumentingAgentsFor(*document) : 0;
167 inline InstrumentingAgents* instrumentingAgentsFor(CSSStyleSheet* styleSheet)
169 return styleSheet ? instrumentingAgentsFor(styleSheet->ownerDocument()) : 0;
172 inline InstrumentingAgents* instrumentingAgentsFor(Node* node)
174 return node ? instrumentingAgentsFor(node->document()) : 0;
177 inline InstrumentingAgents* instrumentingAgentsFor(CSSStyleDeclaration* declaration)
179 return declaration ? instrumentingAgentsFor(declaration->parentStyleSheet()) : 0;
182 } // namespace InspectorInstrumentation
184 InstrumentingAgents* instrumentationForPage(Page*);
186 InstrumentingAgents* instrumentationForWorkerGlobalScope(WorkerGlobalScope*);
190 #include "core/InspectorInstrumentationInl.h"
192 #include "core/inspector/InspectorInstrumentationCustomInl.h"
194 #include "core/InspectorOverridesInl.h"
196 #endif // !defined(InspectorInstrumentation_h)