• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 #include "config.h"
32 #include "TimelineRecordFactory.h"
33 
34 #if ENABLE(INSPECTOR)
35 
36 #include "Event.h"
37 #include "InspectorValues.h"
38 #include "IntRect.h"
39 #include "ResourceRequest.h"
40 #include "ResourceResponse.h"
41 #include "ScriptCallStack.h"
42 #include "ScriptCallStackFactory.h"
43 
44 namespace WebCore {
45 
createGenericRecord(double startTime)46 PassRefPtr<InspectorObject> TimelineRecordFactory::createGenericRecord(double startTime)
47 {
48     RefPtr<InspectorObject> record = InspectorObject::create();
49     record->setNumber("startTime", startTime);
50 
51     RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(5, true);
52     if (stackTrace && stackTrace->size())
53         record->setArray("stackTrace", stackTrace->buildInspectorArray());
54     return record.release();
55 }
56 
createGCEventData(const size_t usedHeapSizeDelta)57 PassRefPtr<InspectorObject> TimelineRecordFactory::createGCEventData(const size_t usedHeapSizeDelta)
58 {
59     RefPtr<InspectorObject> data = InspectorObject::create();
60     data->setNumber("usedHeapSizeDelta", usedHeapSizeDelta);
61     return data.release();
62 }
63 
createFunctionCallData(const String & scriptName,int scriptLine)64 PassRefPtr<InspectorObject> TimelineRecordFactory::createFunctionCallData(const String& scriptName, int scriptLine)
65 {
66     RefPtr<InspectorObject> data = InspectorObject::create();
67     data->setString("scriptName", scriptName);
68     data->setNumber("scriptLine", scriptLine);
69     return data.release();
70 }
71 
createEventDispatchData(const Event & event)72 PassRefPtr<InspectorObject> TimelineRecordFactory::createEventDispatchData(const Event& event)
73 {
74     RefPtr<InspectorObject> data = InspectorObject::create();
75     data->setString("type", event.type().string());
76     return data.release();
77 }
78 
createGenericTimerData(int timerId)79 PassRefPtr<InspectorObject> TimelineRecordFactory::createGenericTimerData(int timerId)
80 {
81     RefPtr<InspectorObject> data = InspectorObject::create();
82     data->setNumber("timerId", timerId);
83     return data.release();
84 }
85 
createTimerInstallData(int timerId,int timeout,bool singleShot)86 PassRefPtr<InspectorObject> TimelineRecordFactory::createTimerInstallData(int timerId, int timeout, bool singleShot)
87 {
88     RefPtr<InspectorObject> data = InspectorObject::create();
89     data->setNumber("timerId", timerId);
90     data->setNumber("timeout", timeout);
91     data->setBoolean("singleShot", singleShot);
92     return data.release();
93 }
94 
createXHRReadyStateChangeData(const String & url,int readyState)95 PassRefPtr<InspectorObject> TimelineRecordFactory::createXHRReadyStateChangeData(const String& url, int readyState)
96 {
97     RefPtr<InspectorObject> data = InspectorObject::create();
98     data->setString("url", url);
99     data->setNumber("readyState", readyState);
100     return data.release();
101 }
102 
createXHRLoadData(const String & url)103 PassRefPtr<InspectorObject> TimelineRecordFactory::createXHRLoadData(const String& url)
104 {
105     RefPtr<InspectorObject> data = InspectorObject::create();
106     data->setString("url", url);
107     return data.release();
108 }
109 
createEvaluateScriptData(const String & url,double lineNumber)110 PassRefPtr<InspectorObject> TimelineRecordFactory::createEvaluateScriptData(const String& url, double lineNumber)
111 {
112     RefPtr<InspectorObject> data = InspectorObject::create();
113     data->setString("url", url);
114     data->setNumber("lineNumber", lineNumber);
115     return data.release();
116 }
117 
createMarkTimelineData(const String & message)118 PassRefPtr<InspectorObject> TimelineRecordFactory::createMarkTimelineData(const String& message)
119 {
120     RefPtr<InspectorObject> data = InspectorObject::create();
121     data->setString("message", message);
122     return data.release();
123 }
124 
createScheduleResourceRequestData(const String & url)125 PassRefPtr<InspectorObject> TimelineRecordFactory::createScheduleResourceRequestData(const String& url)
126 {
127     RefPtr<InspectorObject> data = InspectorObject::create();
128     data->setString("url", url);
129     return data.release();
130 }
131 
createResourceSendRequestData(unsigned long identifier,const ResourceRequest & request)132 PassRefPtr<InspectorObject> TimelineRecordFactory::createResourceSendRequestData(unsigned long identifier, const ResourceRequest& request)
133 {
134     RefPtr<InspectorObject> data = InspectorObject::create();
135     data->setNumber("identifier", identifier);
136     data->setString("url", request.url().string());
137     data->setString("requestMethod", request.httpMethod());
138     return data.release();
139 }
140 
createResourceReceiveResponseData(unsigned long identifier,const ResourceResponse & response)141 PassRefPtr<InspectorObject> TimelineRecordFactory::createResourceReceiveResponseData(unsigned long identifier, const ResourceResponse& response)
142 {
143     RefPtr<InspectorObject> data = InspectorObject::create();
144     data->setNumber("identifier", identifier);
145     data->setNumber("statusCode", response.httpStatusCode());
146     data->setString("mimeType", response.mimeType());
147     return data.release();
148 }
149 
createResourceFinishData(unsigned long identifier,bool didFail,double finishTime)150 PassRefPtr<InspectorObject> TimelineRecordFactory::createResourceFinishData(unsigned long identifier, bool didFail, double finishTime)
151 {
152     RefPtr<InspectorObject> data = InspectorObject::create();
153     data->setNumber("identifier", identifier);
154     data->setBoolean("didFail", didFail);
155     if (finishTime)
156         data->setNumber("networkTime", finishTime);
157     return data.release();
158 }
159 
createReceiveResourceData(unsigned long identifier)160 PassRefPtr<InspectorObject> TimelineRecordFactory::createReceiveResourceData(unsigned long identifier)
161 {
162     RefPtr<InspectorObject> data = InspectorObject::create();
163     data->setNumber("identifier", identifier);
164     return data.release();
165 }
166 
createPaintData(const IntRect & rect)167 PassRefPtr<InspectorObject> TimelineRecordFactory::createPaintData(const IntRect& rect)
168 {
169     RefPtr<InspectorObject> data = InspectorObject::create();
170     data->setNumber("x", rect.x());
171     data->setNumber("y", rect.y());
172     data->setNumber("width", rect.width());
173     data->setNumber("height", rect.height());
174     return data.release();
175 }
176 
createParseHTMLData(unsigned int length,unsigned int startLine)177 PassRefPtr<InspectorObject> TimelineRecordFactory::createParseHTMLData(unsigned int length, unsigned int startLine)
178 {
179     RefPtr<InspectorObject> data = InspectorObject::create();
180     data->setNumber("length", length);
181     data->setNumber("startLine", startLine);
182     return data.release();
183 }
184 
185 } // namespace WebCore
186 
187 #endif // ENABLE(INSPECTOR)
188