2010-04-07 Sheriff Bot <webkit.review.bot@gmail.com>
[WebKit-https.git] / WebCore / inspector / TimelineRecordFactory.cpp
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 "InspectorFrontend.h"
38 #include "IntRect.h"
39 #include "ResourceRequest.h"
40 #include "ResourceResponse.h"
41 #include "ScriptArray.h"
42 #include "ScriptCallStack.h"
43 #include "ScriptObject.h"
44
45 namespace WebCore {
46
47 ScriptObject TimelineRecordFactory::createGenericRecord(InspectorFrontend* frontend, double startTime)
48 {
49     ScriptObject record = frontend->newScriptObject();
50     record.set("startTime", startTime);
51
52     String sourceName;
53     int sourceLineNumber;
54     if (ScriptCallStack::callLocation(&sourceName, &sourceLineNumber) && sourceName != "undefined") {
55         record.set("callerScriptName", sourceName);
56         record.set("callerScriptLine", sourceLineNumber);
57     }
58     return record;
59 }
60
61 ScriptObject TimelineRecordFactory::createGCEventData(InspectorFrontend* frontend, const size_t usedHeapSizeDelta)
62 {
63     ScriptObject data = frontend->newScriptObject();
64     data.set("usedHeapSizeDelta", usedHeapSizeDelta);
65     return data;
66 }
67
68 ScriptObject TimelineRecordFactory::createFunctionCallData(InspectorFrontend* frontend, const String& scriptName, int scriptLine)
69 {
70     ScriptObject data = frontend->newScriptObject();
71     data.set("scriptName", scriptName);
72     data.set("scriptLine", scriptLine);
73     return data;
74 }
75
76 ScriptObject TimelineRecordFactory::createEventDispatchData(InspectorFrontend* frontend, const Event& event)
77 {
78     ScriptObject data = frontend->newScriptObject();
79     data.set("type", event.type().string());
80     return data;
81 }
82
83 ScriptObject TimelineRecordFactory::createGenericTimerData(InspectorFrontend* frontend, int timerId)
84 {
85     ScriptObject data = frontend->newScriptObject();
86     data.set("timerId", timerId);
87     return data;
88 }
89
90 ScriptObject TimelineRecordFactory::createTimerInstallData(InspectorFrontend* frontend, int timerId, int timeout, bool singleShot)
91 {
92     ScriptObject data = frontend->newScriptObject();
93     data.set("timerId", timerId);
94     data.set("timeout", timeout);
95     data.set("singleShot", singleShot);
96     return data;
97 }
98
99 ScriptObject TimelineRecordFactory::createXHRReadyStateChangeData(InspectorFrontend* frontend, const String& url, int readyState)
100 {
101     ScriptObject data = frontend->newScriptObject();
102     data.set("url", url);
103     data.set("readyState", readyState);
104     return data;
105 }
106
107 ScriptObject TimelineRecordFactory::createXHRLoadData(InspectorFrontend* frontend, const String& url)
108 {
109     ScriptObject data = frontend->newScriptObject();
110     data.set("url", url);
111     return data;
112 }
113
114 ScriptObject TimelineRecordFactory::createEvaluateScriptData(InspectorFrontend* frontend, const String& url, double lineNumber) 
115 {
116     ScriptObject data = frontend->newScriptObject();
117     data.set("url", url);
118     data.set("lineNumber", lineNumber);
119     return data;
120 }
121
122 ScriptObject TimelineRecordFactory::createMarkTimelineData(InspectorFrontend* frontend, const String& message) 
123 {
124     ScriptObject data = frontend->newScriptObject();
125     data.set("message", message);
126     return data;
127 }
128
129
130 ScriptObject TimelineRecordFactory::createResourceSendRequestData(InspectorFrontend* frontend, unsigned long identifier, bool isMainResource, const ResourceRequest& request)
131 {
132     ScriptObject data = frontend->newScriptObject();
133     data.set("identifier", identifier);
134     data.set("url", request.url().string());
135     data.set("requestMethod", request.httpMethod());
136     data.set("isMainResource", isMainResource);
137     return data;
138 }
139
140 ScriptObject TimelineRecordFactory::createResourceReceiveResponseData(InspectorFrontend* frontend, unsigned long identifier, const ResourceResponse& response)
141 {
142     ScriptObject data = frontend->newScriptObject();
143     data.set("identifier", identifier);
144     data.set("statusCode", response.httpStatusCode());
145     data.set("mimeType", response.mimeType());
146     data.set("expectedContentLength", response.expectedContentLength());
147     return data;
148 }
149
150 ScriptObject TimelineRecordFactory::createResourceFinishData(InspectorFrontend* frontend, unsigned long identifier, bool didFail)
151 {
152     ScriptObject data = frontend->newScriptObject();
153     data.set("identifier", identifier);
154     data.set("didFail", didFail);
155     return data;
156 }
157
158 ScriptObject TimelineRecordFactory::createReceiveResourceData(InspectorFrontend* frontend, unsigned long identifier)
159 {
160     ScriptObject data = frontend->newScriptObject();
161     data.set("identifier", identifier);
162     return data;
163 }
164     
165 ScriptObject TimelineRecordFactory::createPaintData(InspectorFrontend* frontend, const IntRect& rect)
166 {
167     ScriptObject data = frontend->newScriptObject();
168     data.set("x", rect.x());
169     data.set("y", rect.y());
170     data.set("width", rect.width());
171     data.set("height", rect.height());
172     return data;
173 }
174
175 ScriptObject TimelineRecordFactory::createParseHTMLData(InspectorFrontend* frontend, unsigned int length, unsigned int startLine)
176 {
177     ScriptObject data = frontend->newScriptObject();
178     data.set("length", length);
179     data.set("startLine", startLine);
180     return data;
181 }
182
183 } // namespace WebCore
184
185 #endif // ENABLE(INSPECTOR)