Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / inspector / TimelineRecordFactory.cpp
blob4fdd502aa3c142f44ed5b5f624a0792584359f74
1 /*
2 * Copyright (C) 2009 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
6 * met:
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.
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 #include "config.h"
32 #include "TimelineRecordFactory.h"
34 #if ENABLE(INSPECTOR)
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 "ScriptObject.h"
44 namespace WebCore {
46 ScriptObject TimelineRecordFactory::createGenericRecord(InspectorFrontend* frontend, double startTime)
48 ScriptObject record = frontend->newScriptObject();
49 record.set("startTime", startTime);
50 return record;
53 ScriptObject TimelineRecordFactory::createEventDispatchRecord(InspectorFrontend* frontend, double startTime, const Event& event)
55 ScriptObject record = createGenericRecord(frontend, startTime);
56 ScriptObject data = frontend->newScriptObject();
57 data.set("type", event.type().string());
58 record.set("data", data);
59 return record;
62 ScriptObject TimelineRecordFactory::createGenericTimerRecord(InspectorFrontend* frontend, double startTime, int timerId)
64 ScriptObject record = createGenericRecord(frontend, startTime);
65 ScriptObject data = frontend->newScriptObject();
66 data.set("timerId", timerId);
67 record.set("data", data);
68 return record;
71 ScriptObject TimelineRecordFactory::createTimerInstallRecord(InspectorFrontend* frontend, double startTime, int timerId, int timeout, bool singleShot)
73 ScriptObject record = createGenericRecord(frontend, startTime);
74 ScriptObject data = frontend->newScriptObject();
75 data.set("timerId", timerId);
76 data.set("timeout", timeout);
77 data.set("singleShot", singleShot);
78 record.set("data", data);
79 return record;
82 ScriptObject TimelineRecordFactory::createXHRReadyStateChangeRecord(InspectorFrontend* frontend, double startTime, const String& url, int readyState)
84 ScriptObject record = createGenericRecord(frontend, startTime);
85 ScriptObject data = frontend->newScriptObject();
86 data.set("url", url);
87 data.set("readyState", readyState);
88 record.set("data", data);
89 return record;
92 ScriptObject TimelineRecordFactory::createXHRLoadRecord(InspectorFrontend* frontend, double startTime, const String& url)
94 ScriptObject record = createGenericRecord(frontend, startTime);
95 ScriptObject data = frontend->newScriptObject();
96 data.set("url", url);
97 record.set("data", data);
98 return record;
101 ScriptObject TimelineRecordFactory::createEvaluateScriptRecord(InspectorFrontend* frontend, double startTime, const String& url, double lineNumber)
103 ScriptObject record = createGenericRecord(frontend, startTime);
104 ScriptObject data = frontend->newScriptObject();
105 data.set("url", url);
106 data.set("lineNumber", lineNumber);
107 record.set("data", data);
108 return record;
111 ScriptObject TimelineRecordFactory::createMarkTimelineRecord(InspectorFrontend* frontend, double startTime, const String& message)
113 ScriptObject record = createGenericRecord(frontend, startTime);
114 ScriptObject data = frontend->newScriptObject();
115 data.set("message", message);
116 record.set("data", data);
117 return record;
121 ScriptObject TimelineRecordFactory::createResourceSendRequestRecord(InspectorFrontend* frontend, double startTime,
122 unsigned long identifier, bool isMainResource, const ResourceRequest& request)
124 ScriptObject record = createGenericRecord(frontend, startTime);
125 ScriptObject data = frontend->newScriptObject();
126 data.set("identifier", identifier);
127 data.set("url", request.url().string());
128 data.set("requestMethod", request.httpMethod());
129 data.set("isMainResource", isMainResource);
130 record.set("data", data);
131 return record;
134 ScriptObject TimelineRecordFactory::createResourceReceiveResponseRecord(InspectorFrontend* frontend, double startTime,
135 unsigned long identifier, const ResourceResponse& response)
137 ScriptObject record = createGenericRecord(frontend, startTime);
138 ScriptObject data = frontend->newScriptObject();
139 data.set("identifier", identifier);
140 data.set("statusCode", response.httpStatusCode());
141 data.set("mimeType", response.mimeType());
142 data.set("expectedContentLength", response.expectedContentLength());
143 record.set("data", data);
144 return record;
147 ScriptObject TimelineRecordFactory::createResourceFinishRecord(InspectorFrontend* frontend, double startTime,
148 unsigned long identifier, bool didFail)
150 ScriptObject record = createGenericRecord(frontend, startTime);
151 ScriptObject data = frontend->newScriptObject();
152 data.set("identifier", identifier);
153 data.set("didFail", didFail);
154 record.set("data", data);
155 return record;
158 ScriptObject TimelineRecordFactory::createPaintRecord(InspectorFrontend* frontend, double startTime, const IntRect& rect)
160 ScriptObject record = createGenericRecord(frontend, startTime);
161 ScriptObject data = frontend->newScriptObject();
162 data.set("x", rect.x());
163 data.set("y", rect.y());
164 data.set("width", rect.width());
165 data.set("height", rect.height());
166 record.set("data", data);
167 return record;
170 } // namespace WebCore
172 #endif // ENABLE(INSPECTOR)