1 | /* |
2 | * Copyright (C) 2009 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 | #include "config.h" |
33 | #include "TimelineRecordFactory.h" |
34 | |
35 | #include "Event.h" |
36 | #include "FloatQuad.h" |
37 | #include "JSExecState.h" |
38 | #include <JavaScriptCore/InspectorProtocolObjects.h> |
39 | #include <JavaScriptCore/ScriptBreakpoint.h> |
40 | #include <JavaScriptCore/ScriptCallStack.h> |
41 | #include <JavaScriptCore/ScriptCallStackFactory.h> |
42 | |
43 | namespace WebCore { |
44 | |
45 | using namespace Inspector; |
46 | |
47 | Ref<JSON::Object> TimelineRecordFactory::createGenericRecord(double startTime, int maxCallStackDepth) |
48 | { |
49 | Ref<JSON::Object> record = JSON::Object::create(); |
50 | record->setDouble("startTime"_s , startTime); |
51 | |
52 | if (maxCallStackDepth) { |
53 | Ref<ScriptCallStack> stackTrace = createScriptCallStack(JSExecState::currentState(), maxCallStackDepth); |
54 | if (stackTrace->size()) |
55 | record->setValue("stackTrace"_s , stackTrace->buildInspectorArray()); |
56 | } |
57 | return record; |
58 | } |
59 | |
60 | Ref<JSON::Object> TimelineRecordFactory::createFunctionCallData(const String& scriptName, int scriptLine, int scriptColumn) |
61 | { |
62 | Ref<JSON::Object> data = JSON::Object::create(); |
63 | data->setString("scriptName"_s , scriptName); |
64 | data->setInteger("scriptLine"_s , scriptLine); |
65 | data->setInteger("scriptColumn"_s , scriptColumn); |
66 | return data; |
67 | } |
68 | |
69 | Ref<JSON::Object> TimelineRecordFactory::createConsoleProfileData(const String& title) |
70 | { |
71 | Ref<JSON::Object> data = JSON::Object::create(); |
72 | data->setString("title"_s , title); |
73 | return data; |
74 | } |
75 | |
76 | Ref<JSON::Object> TimelineRecordFactory::createProbeSampleData(const ScriptBreakpointAction& action, unsigned sampleId) |
77 | { |
78 | Ref<JSON::Object> data = JSON::Object::create(); |
79 | data->setInteger("probeId"_s , action.identifier); |
80 | data->setInteger("sampleId"_s , sampleId); |
81 | return data; |
82 | } |
83 | |
84 | Ref<JSON::Object> TimelineRecordFactory::createEventDispatchData(const Event& event) |
85 | { |
86 | Ref<JSON::Object> data = JSON::Object::create(); |
87 | data->setString("type"_s , event.type().string()); |
88 | return data; |
89 | } |
90 | |
91 | Ref<JSON::Object> TimelineRecordFactory::createGenericTimerData(int timerId) |
92 | { |
93 | Ref<JSON::Object> data = JSON::Object::create(); |
94 | data->setInteger("timerId"_s , timerId); |
95 | return data; |
96 | } |
97 | |
98 | Ref<JSON::Object> TimelineRecordFactory::createTimerInstallData(int timerId, Seconds timeout, bool singleShot) |
99 | { |
100 | Ref<JSON::Object> data = JSON::Object::create(); |
101 | data->setInteger("timerId"_s , timerId); |
102 | data->setInteger("timeout"_s , (int)timeout.milliseconds()); |
103 | data->setBoolean("singleShot"_s , singleShot); |
104 | return data; |
105 | } |
106 | |
107 | Ref<JSON::Object> TimelineRecordFactory::createEvaluateScriptData(const String& url, int lineNumber, int columnNumber) |
108 | { |
109 | Ref<JSON::Object> data = JSON::Object::create(); |
110 | data->setString("url"_s , url); |
111 | data->setInteger("lineNumber"_s , lineNumber); |
112 | data->setInteger("columnNumber"_s , columnNumber); |
113 | return data; |
114 | } |
115 | |
116 | Ref<JSON::Object> TimelineRecordFactory::createTimeStampData(const String& message) |
117 | { |
118 | Ref<JSON::Object> data = JSON::Object::create(); |
119 | data->setString("message"_s , message); |
120 | return data; |
121 | } |
122 | |
123 | Ref<JSON::Object> TimelineRecordFactory::createAnimationFrameData(int callbackId) |
124 | { |
125 | Ref<JSON::Object> data = JSON::Object::create(); |
126 | data->setInteger("id"_s , callbackId); |
127 | return data; |
128 | } |
129 | |
130 | Ref<JSON::Object> TimelineRecordFactory::createObserverCallbackData(const String& callbackType) |
131 | { |
132 | Ref<JSON::Object> data = JSON::Object::create(); |
133 | data->setString("type"_s , callbackType); |
134 | return data; |
135 | } |
136 | |
137 | static Ref<JSON::Array> createQuad(const FloatQuad& quad) |
138 | { |
139 | Ref<JSON::Array> array = JSON::Array::create(); |
140 | array->pushDouble(quad.p1().x()); |
141 | array->pushDouble(quad.p1().y()); |
142 | array->pushDouble(quad.p2().x()); |
143 | array->pushDouble(quad.p2().y()); |
144 | array->pushDouble(quad.p3().x()); |
145 | array->pushDouble(quad.p3().y()); |
146 | array->pushDouble(quad.p4().x()); |
147 | array->pushDouble(quad.p4().y()); |
148 | return array; |
149 | } |
150 | |
151 | Ref<JSON::Object> TimelineRecordFactory::createPaintData(const FloatQuad& quad) |
152 | { |
153 | Ref<JSON::Object> data = JSON::Object::create(); |
154 | data->setArray("clip"_s , createQuad(quad)); |
155 | return data; |
156 | } |
157 | |
158 | void TimelineRecordFactory::appendLayoutRoot(JSON::Object* data, const FloatQuad& quad) |
159 | { |
160 | data->setArray("root"_s , createQuad(quad)); |
161 | } |
162 | |
163 | } // namespace WebCore |
164 | |