Web Inspector: remove unused metrics and commands from the Timeline agent
[WebKit-https.git] / Source / WebCore / inspector / InspectorTimelineAgent.h
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2014 University of Washington.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef InspectorTimelineAgent_h
33 #define InspectorTimelineAgent_h
34
35 #if ENABLE(INSPECTOR)
36
37 #include "InspectorWebAgentBase.h"
38 #include "InspectorWebBackendDispatchers.h"
39 #include "InspectorWebFrontendDispatchers.h"
40 #include "LayoutRect.h"
41 #include <inspector/InspectorValues.h>
42 #include <inspector/ScriptDebugListener.h>
43 #include <wtf/Vector.h>
44 #include <wtf/WeakPtr.h>
45
46 namespace WebCore {
47
48 class Event;
49 class FloatQuad;
50 class Frame;
51 class InspectorClient;
52 class InspectorPageAgent;
53 class InstrumentingAgents;
54 class IntRect;
55 class URL;
56 class Page;
57 class RenderObject;
58 class ResourceRequest;
59 class ResourceResponse;
60
61 typedef String ErrorString;
62
63 enum class TimelineRecordType {
64     EventDispatch,
65     ScheduleStyleRecalculation,
66     RecalculateStyles,
67     InvalidateLayout,
68     Layout,
69     Paint,
70     ScrollLayer,
71     ResizeImage,
72
73     ParseHTML,
74
75     TimerInstall,
76     TimerRemove,
77     TimerFire,
78
79     EvaluateScript,
80
81     MarkLoad,
82     MarkDOMContent,
83
84     TimeStamp,
85     Time,
86     TimeEnd,
87
88     ScheduleResourceRequest,
89     ResourceSendRequest,
90     ResourceReceiveResponse,
91     ResourceReceivedData,
92     ResourceFinish,
93
94     XHRReadyStateChange,
95     XHRLoad,
96
97     FunctionCall,
98     ProbeSample,
99
100     RequestAnimationFrame,
101     CancelAnimationFrame,
102     FireAnimationFrame,
103
104     WebSocketCreate,
105     WebSocketSendHandshakeRequest,
106     WebSocketReceiveHandshakeResponse,
107     WebSocketDestroy
108 };
109
110 class TimelineTimeConverter {
111 public:
112     TimelineTimeConverter()
113         : m_startOffset(0)
114     {
115     }
116     double fromMonotonicallyIncreasingTime(double time) const  { return (time - m_startOffset) * 1000.0; }
117     void reset();
118
119 private:
120     double m_startOffset;
121 };
122
123 class InspectorTimelineAgent
124     : public InspectorAgentBase
125     , public Inspector::InspectorTimelineBackendDispatcherHandler
126     , public Inspector::ScriptDebugListener {
127     WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
128 public:
129     enum InspectorType { PageInspector, WorkerInspector };
130
131     InspectorTimelineAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorType, InspectorClient*);
132     ~InspectorTimelineAgent();
133
134     virtual void didCreateFrontendAndBackend(Inspector::InspectorFrontendChannel*, Inspector::InspectorBackendDispatcher*) override;
135     virtual void willDestroyFrontendAndBackend(Inspector::InspectorDisconnectReason) override;
136
137     virtual void start(ErrorString*, const int* maxCallStackDepth) override;
138     virtual void stop(ErrorString*) override;
139
140     int id() const { return m_id; }
141
142     void didCommitLoad();
143
144     // Methods called from WebCore.
145     void willCallFunction(const String& scriptName, int scriptLine, Frame*);
146     void didCallFunction(Frame*);
147
148     void willDispatchEvent(const Event&, Frame*);
149     void didDispatchEvent();
150
151     void didInvalidateLayout(Frame*);
152     void willLayout(Frame*);
153     void didLayout(RenderObject*);
154
155     void didScheduleStyleRecalculation(Frame*);
156     void willRecalculateStyle(Frame*);
157     void didRecalculateStyle();
158
159     void willPaint(Frame*);
160     void didPaint(RenderObject*, const LayoutRect&);
161
162     void willScroll(Frame*);
163     void didScroll();
164
165     void willWriteHTML(unsigned startLine, Frame*);
166     void didWriteHTML(unsigned endLine);
167
168     void didInstallTimer(int timerId, int timeout, bool singleShot, Frame*);
169     void didRemoveTimer(int timerId, Frame*);
170     void willFireTimer(int timerId, Frame*);
171     void didFireTimer();
172
173     void willDispatchXHRReadyStateChangeEvent(const String&, int, Frame*);
174     void didDispatchXHRReadyStateChangeEvent();
175     void willDispatchXHRLoadEvent(const String&, Frame*);
176     void didDispatchXHRLoadEvent();
177
178     void willEvaluateScript(const String&, int, Frame*);
179     void didEvaluateScript(Frame*);
180
181     void didTimeStamp(Frame*, const String&);
182     void didMarkDOMContentEvent(Frame*);
183     void didMarkLoadEvent(Frame*);
184
185     void time(Frame*, const String&);
186     void timeEnd(Frame*, const String&);
187
188     void didScheduleResourceRequest(const String& url, Frame*);
189     void willSendResourceRequest(unsigned long, const ResourceRequest&, Frame*);
190     void willReceiveResourceResponse(unsigned long, const ResourceResponse&, Frame*);
191     void didReceiveResourceResponse();
192     void didFinishLoadingResource(unsigned long, bool didFail, double finishTime, Frame*);
193     void willReceiveResourceData(unsigned long identifier, Frame*, int length);
194     void didReceiveResourceData();
195
196     void didRequestAnimationFrame(int callbackId, Frame*);
197     void didCancelAnimationFrame(int callbackId, Frame*);
198     void willFireAnimationFrame(int callbackId, Frame*);
199     void didFireAnimationFrame();
200
201 #if ENABLE(WEB_SOCKETS)
202     void didCreateWebSocket(unsigned long identifier, const URL&, const String& protocol, Frame*);
203     void willSendWebSocketHandshakeRequest(unsigned long identifier, Frame*);
204     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, Frame*);
205     void didDestroyWebSocket(unsigned long identifier, Frame*);
206 #endif
207
208 protected:
209     // ScriptDebugListener. This is only used to create records for probe samples.
210     virtual void didParseSource(JSC::SourceID, const Script&) override { }
211     virtual void failedToParseSource(const String&, const String&, int, int, const String&) override { }
212     virtual void didPause(JSC::ExecState*, const Deprecated::ScriptValue&, const Deprecated::ScriptValue&) override { }
213     virtual void didContinue() override { }
214
215     virtual void breakpointActionLog(JSC::ExecState*, const String&) override { }
216     virtual void breakpointActionSound(int) override { }
217     virtual void breakpointActionProbe(JSC::ExecState*, const Inspector::ScriptBreakpointAction&, int hitCount, const Deprecated::ScriptValue& result) override;
218
219 private:
220     friend class TimelineRecordStack;
221
222     struct TimelineRecordEntry {
223         TimelineRecordEntry(PassRefPtr<Inspector::InspectorObject> record, PassRefPtr<Inspector::InspectorObject> data, PassRefPtr<Inspector::InspectorArray> children, TimelineRecordType type)
224             : record(record), data(data), children(children), type(type)
225         {
226         }
227         RefPtr<Inspector::InspectorObject> record;
228         RefPtr<Inspector::InspectorObject> data;
229         RefPtr<Inspector::InspectorArray> children;
230         TimelineRecordType type;
231     };
232
233     void sendEvent(PassRefPtr<Inspector::InspectorObject>);
234     void appendRecord(PassRefPtr<Inspector::InspectorObject> data, TimelineRecordType, bool captureCallStack, Frame*);
235     void pushCurrentRecord(PassRefPtr<Inspector::InspectorObject>, TimelineRecordType, bool captureCallStack, Frame*);
236
237     void setFrameIdentifier(Inspector::InspectorObject* record, Frame*);
238
239     void didCompleteCurrentRecord(TimelineRecordType);
240
241     void addRecordToTimeline(PassRefPtr<Inspector::InspectorObject>, TimelineRecordType);
242     void clearRecordStack();
243
244     void localToPageQuad(const RenderObject&, const LayoutRect&, FloatQuad*);
245     const TimelineTimeConverter& timeConverter() const { return m_timeConverter; }
246     double timestamp();
247     Page* page();
248
249     InspectorPageAgent* m_pageAgent;
250     TimelineTimeConverter m_timeConverter;
251
252     std::unique_ptr<Inspector::InspectorTimelineFrontendDispatcher> m_frontendDispatcher;
253     RefPtr<Inspector::InspectorTimelineBackendDispatcher> m_backendDispatcher;
254     double m_timestampOffset;
255
256     Vector<TimelineRecordEntry> m_recordStack;
257
258     int m_id;
259     int m_maxCallStackDepth;
260     InspectorType m_inspectorType;
261     InspectorClient* m_client;
262     WeakPtrFactory<InspectorTimelineAgent> m_weakFactory;
263
264     bool m_enabled;
265     bool m_recordingProfile;
266 };
267
268 } // namespace WebCore
269
270 #endif // !ENABLE(INSPECTOR)
271 #endif // !defined(InspectorTimelineAgent_h)