Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / inspector / InspectorInstrumentation.h
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 #ifndef InspectorInstrumentation_h
32 #define InspectorInstrumentation_h
33
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"
51
52 namespace blink {
53
54 class Document;
55 class EventTarget;
56 class ExecutionContext;
57 class FrameHost;
58 class InspectorTimelineAgent;
59 class InstrumentingAgents;
60 class ThreadableLoaderClient;
61 class WorkerGlobalScope;
62 class WorkerInspectorProxy;
63
64 #define FAST_RETURN_IF_NO_FRONTENDS(value) if (!hasFrontends()) return value;
65
66 class InspectorInstrumentationCookie {
67     STACK_ALLOCATED();
68 public:
69     InspectorInstrumentationCookie();
70     InspectorInstrumentationCookie(InstrumentingAgents*, int);
71     InspectorInstrumentationCookie(const InspectorInstrumentationCookie&);
72     InspectorInstrumentationCookie& operator=(const InspectorInstrumentationCookie&);
73     ~InspectorInstrumentationCookie();
74
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; }
78
79 private:
80     RefPtrWillBeMember<InstrumentingAgents> m_instrumentingAgents;
81     int m_timelineAgentId;
82 };
83
84 namespace InspectorInstrumentation {
85
86 class FrontendCounter {
87 private:
88     friend void frontendCreated();
89     friend void frontendDeleted();
90     friend bool hasFrontends();
91     static int s_frontendCounter;
92 };
93
94 inline void frontendCreated() { atomicIncrement(&FrontendCounter::s_frontendCounter); }
95 inline void frontendDeleted() { atomicDecrement(&FrontendCounter::s_frontendCounter); }
96 inline bool hasFrontends() { return FrontendCounter::s_frontendCounter; }
97
98 void registerInstrumentingAgents(InstrumentingAgents*);
99 void unregisterInstrumentingAgents(InstrumentingAgents*);
100
101 InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
102
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*);
114
115 // Helper for the one above.
116 InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ExecutionContext*);
117
118 }  // namespace InspectorInstrumentation
119
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[];
130 };
131
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[];
138 };
139
140 namespace InspectorInstrumentation {
141
142 inline InstrumentingAgents* instrumentingAgentsFor(ExecutionContext* context)
143 {
144     if (!context)
145         return 0;
146     return context->isDocument() ? instrumentingAgentsFor(*toDocument(context)) : instrumentingAgentsForNonDocumentContext(context);
147 }
148
149 inline InstrumentingAgents* instrumentingAgentsFor(LocalFrame* frame)
150 {
151     return frame ? instrumentingAgentsFor(frame->page()) : 0;
152 }
153
154 inline InstrumentingAgents* instrumentingAgentsFor(Document& document)
155 {
156     Page* page = document.page();
157     if (!page && document.templateDocumentHost())
158         page = document.templateDocumentHost()->page();
159     return instrumentingAgentsFor(page);
160 }
161
162 inline InstrumentingAgents* instrumentingAgentsFor(Document* document)
163 {
164     return document ? instrumentingAgentsFor(*document) : 0;
165 }
166
167 inline InstrumentingAgents* instrumentingAgentsFor(CSSStyleSheet* styleSheet)
168 {
169     return styleSheet ? instrumentingAgentsFor(styleSheet->ownerDocument()) : 0;
170 }
171
172 inline InstrumentingAgents* instrumentingAgentsFor(Node* node)
173 {
174     return node ? instrumentingAgentsFor(node->document()) : 0;
175 }
176
177 inline InstrumentingAgents* instrumentingAgentsFor(CSSStyleDeclaration* declaration)
178 {
179     return declaration ? instrumentingAgentsFor(declaration->parentStyleSheet()) : 0;
180 }
181
182 } // namespace InspectorInstrumentation
183
184 InstrumentingAgents* instrumentationForPage(Page*);
185
186 InstrumentingAgents* instrumentationForWorkerGlobalScope(WorkerGlobalScope*);
187
188 } // namespace blink
189
190 #include "core/InspectorInstrumentationInl.h"
191
192 #include "core/inspector/InspectorInstrumentationCustomInl.h"
193
194 #include "core/InspectorOverridesInl.h"
195
196 #endif // !defined(InspectorInstrumentation_h)