Use std::make_unique<> when creating an unique_ptr object.
[WebKit-https.git] / Source / WebCore / inspector / InspectorTimelineAgent.cpp
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2014 University of Washington.
4 * Copyright (C) 2015 Apple Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *     * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *     * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 *     * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "config.h"
34 #include "InspectorTimelineAgent.h"
35
36 #include "Event.h"
37 #include "Frame.h"
38 #include "InspectorPageAgent.h"
39 #include "InstrumentingAgents.h"
40 #include "JSDOMWindow.h"
41 #include "PageScriptDebugServer.h"
42 #include "RenderView.h"
43 #include "ScriptState.h"
44 #include "TimelineRecordFactory.h"
45 #include <inspector/ScriptBreakpoint.h>
46 #include <profiler/LegacyProfiler.h>
47 #include <wtf/Stopwatch.h>
48
49 #if PLATFORM(IOS)
50 #include "RuntimeApplicationChecksIOS.h"
51 #include <WebCore/WebCoreThread.h>
52 #endif
53
54 #if PLATFORM(COCOA)
55 #include <WebCore/RunLoopObserver.h>
56 #endif
57
58 using namespace Inspector;
59
60 namespace WebCore {
61
62 #if PLATFORM(COCOA)
63 static const CFIndex frameStopRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit + 1;
64
65 static CFRunLoopRef currentRunLoop()
66 {
67 #if PLATFORM(IOS)
68     // A race condition during WebView deallocation can lead to a crash if the layer sync run loop
69     // observer is added to the main run loop <rdar://problem/9798550>. However, for responsiveness,
70     // we still allow this, see <rdar://problem/7403328>. Since the race condition and subsequent
71     // crash are especially troublesome for iBooks, we never allow the observer to be added to the
72     // main run loop in iBooks.
73     if (applicationIsIBooksOnIOS())
74         return WebThreadRunLoop();
75 #endif
76     return CFRunLoopGetCurrent();
77 }
78 #endif
79
80 InspectorTimelineAgent::~InspectorTimelineAgent()
81 {
82 }
83
84 void InspectorTimelineAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
85 {
86     m_instrumentingAgents.setPersistentInspectorTimelineAgent(this);
87
88     // Recompile to include profiling information.
89     // FIXME: This doesn't seem like the most appropriate place.
90     m_environment.scriptDebugServer().recompileAllJSFunctions();
91 }
92
93 void InspectorTimelineAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason reason)
94 {
95     m_instrumentingAgents.setPersistentInspectorTimelineAgent(nullptr);
96
97     if (reason != Inspector::DisconnectReason::InspectedTargetDestroyed)
98         m_environment.scriptDebugServer().recompileAllJSFunctions();
99
100     ErrorString unused;
101     stop(unused);
102 }
103
104 void InspectorTimelineAgent::start(ErrorString&, const int* maxCallStackDepth)
105 {
106     m_enabledFromFrontend = true;
107
108     internalStart(maxCallStackDepth);
109 }
110
111 void InspectorTimelineAgent::stop(ErrorString&)
112 {
113     internalStop();
114
115     m_enabledFromFrontend = false;
116 }
117
118 void InspectorTimelineAgent::internalStart(const int* maxCallStackDepth)
119 {
120     if (m_enabled)
121         return;
122
123     if (maxCallStackDepth && *maxCallStackDepth > 0)
124         m_maxCallStackDepth = *maxCallStackDepth;
125     else
126         m_maxCallStackDepth = 5;
127
128     m_instrumentingAgents.setInspectorTimelineAgent(this);
129
130     m_environment.scriptDebugServer().addListener(this);
131
132     m_enabled = true;
133
134     // FIXME: Abstract away platform-specific code once https://bugs.webkit.org/show_bug.cgi?id=142748 is fixed.
135
136 #if PLATFORM(COCOA)
137     m_frameStartObserver = std::make_unique<RunLoopObserver>(0, [this]() {
138         if (!m_enabled || m_environment.scriptDebugServer().isPaused())
139             return;
140
141         if (!m_runLoopNestingLevel)
142             pushCurrentRecord(InspectorObject::create(), TimelineRecordType::RenderingFrame, false, nullptr);
143         m_runLoopNestingLevel++;
144     });
145
146     m_frameStopObserver = std::make_unique<RunLoopObserver>(frameStopRunLoopOrder, [this]() {
147         if (!m_enabled || m_environment.scriptDebugServer().isPaused())
148             return;
149
150         ASSERT(m_runLoopNestingLevel > 0);
151         m_runLoopNestingLevel--;
152         if (m_runLoopNestingLevel)
153             return;
154
155         if (m_startedComposite)
156             didComposite();
157
158         didCompleteCurrentRecord(TimelineRecordType::RenderingFrame);
159     });
160
161     m_frameStartObserver->schedule(currentRunLoop(), kCFRunLoopEntry | kCFRunLoopAfterWaiting);
162     m_frameStopObserver->schedule(currentRunLoop(), kCFRunLoopExit | kCFRunLoopBeforeWaiting);
163
164     // Create a runloop record and increment the runloop nesting level, to capture the current turn of the main runloop
165     // (which is the outer runloop if recording started while paused in the debugger).
166     pushCurrentRecord(InspectorObject::create(), TimelineRecordType::RenderingFrame, false, nullptr);
167
168     m_runLoopNestingLevel = 1;
169 #endif
170
171     m_frontendDispatcher->recordingStarted(timestamp());
172 }
173
174 void InspectorTimelineAgent::internalStop()
175 {
176     if (!m_enabled)
177         return;
178
179     m_instrumentingAgents.setInspectorTimelineAgent(nullptr);
180
181     m_environment.scriptDebugServer().removeListener(this, true);
182
183 #if PLATFORM(COCOA)
184     m_frameStartObserver = nullptr;
185     m_frameStopObserver = nullptr;
186     m_runLoopNestingLevel = 0;
187
188     // Complete all pending records to prevent discarding events that are currently in progress.
189     while (!m_recordStack.isEmpty())
190         didCompleteCurrentRecord(m_recordStack.last().type);
191 #endif
192
193     clearRecordStack();
194
195     m_enabled = false;
196     m_startedComposite = false;
197
198     m_frontendDispatcher->recordingStopped(timestamp());
199 }
200
201 double InspectorTimelineAgent::timestamp()
202 {
203     return m_environment.executionStopwatch()->elapsedTime();
204 }
205
206 static inline void startProfiling(JSC::ExecState* exec, const String& title, RefPtr<Stopwatch>&& stopwatch)
207 {
208     JSC::LegacyProfiler::profiler()->startProfiling(exec, title, WTFMove(stopwatch));
209 }
210
211 static inline RefPtr<JSC::Profile> stopProfiling(JSC::ExecState* exec, const String& title)
212 {
213     return JSC::LegacyProfiler::profiler()->stopProfiling(exec, title);
214 }
215
216 void InspectorTimelineAgent::startFromConsole(JSC::ExecState* exec, const String &title)
217 {
218     // Only allow recording of a profile if it is anonymous (empty title) or does not match
219     // the title of an already recording profile.
220     if (!title.isEmpty()) {
221         for (const TimelineRecordEntry& record : m_pendingConsoleProfileRecords) {
222             String recordTitle;
223             record.data->getString(ASCIILiteral("title"), recordTitle);
224             if (recordTitle == title)
225                 return;
226         }
227     }
228
229     if (!m_enabled && m_pendingConsoleProfileRecords.isEmpty())
230         internalStart();
231
232     startProfiling(exec, title, m_environment.executionStopwatch());
233
234     m_pendingConsoleProfileRecords.append(createRecordEntry(TimelineRecordFactory::createConsoleProfileData(title), TimelineRecordType::ConsoleProfile, true, frameFromExecState(exec)));
235 }
236
237 RefPtr<JSC::Profile> InspectorTimelineAgent::stopFromConsole(JSC::ExecState* exec, const String& title)
238 {
239     // Stop profiles in reverse order. If the title is empty, then stop the last profile.
240     // Otherwise, match the title of the profile to stop.
241     for (ptrdiff_t i = m_pendingConsoleProfileRecords.size() - 1; i >= 0; --i) {
242         const TimelineRecordEntry& record = m_pendingConsoleProfileRecords[i];
243
244         String recordTitle;
245         record.data->getString(ASCIILiteral("title"), recordTitle);
246
247         if (title.isEmpty() || recordTitle == title) {
248             RefPtr<JSC::Profile> profile = stopProfiling(exec, title);
249             if (profile)
250                 TimelineRecordFactory::appendProfile(record.data.get(), profile.copyRef());
251
252             didCompleteRecordEntry(record);
253
254             m_pendingConsoleProfileRecords.remove(i);
255
256             if (!m_enabledFromFrontend && m_pendingConsoleProfileRecords.isEmpty())
257                 internalStop();
258
259             return profile;
260         }
261     }
262
263     return nullptr;
264 }
265
266 void InspectorTimelineAgent::willCallFunction(const String& scriptName, int scriptLine, Frame* frame)
267 {
268     pushCurrentRecord(TimelineRecordFactory::createFunctionCallData(scriptName, scriptLine), TimelineRecordType::FunctionCall, true, frame);
269 }
270
271 void InspectorTimelineAgent::didCallFunction(Frame*)
272 {
273     didCompleteCurrentRecord(TimelineRecordType::FunctionCall);
274 }
275
276 void InspectorTimelineAgent::willDispatchEvent(const Event& event, Frame* frame)
277 {
278     pushCurrentRecord(TimelineRecordFactory::createEventDispatchData(event), TimelineRecordType::EventDispatch, false, frame);
279 }
280
281 void InspectorTimelineAgent::didDispatchEvent()
282 {
283     didCompleteCurrentRecord(TimelineRecordType::EventDispatch);
284 }
285
286 void InspectorTimelineAgent::didInvalidateLayout(Frame& frame)
287 {
288     appendRecord(InspectorObject::create(), TimelineRecordType::InvalidateLayout, true, &frame);
289 }
290
291 void InspectorTimelineAgent::willLayout(Frame& frame)
292 {
293     pushCurrentRecord(InspectorObject::create(), TimelineRecordType::Layout, true, &frame);
294 }
295
296 void InspectorTimelineAgent::didLayout(RenderObject* root)
297 {
298     if (m_recordStack.isEmpty())
299         return;
300     TimelineRecordEntry& entry = m_recordStack.last();
301     ASSERT(entry.type == TimelineRecordType::Layout);
302     Vector<FloatQuad> quads;
303     root->absoluteQuads(quads);
304     if (quads.size() >= 1)
305         TimelineRecordFactory::appendLayoutRoot(entry.data.get(), quads[0]);
306     else
307         ASSERT_NOT_REACHED();
308     didCompleteCurrentRecord(TimelineRecordType::Layout);
309 }
310
311 void InspectorTimelineAgent::didScheduleStyleRecalculation(Frame* frame)
312 {
313     appendRecord(InspectorObject::create(), TimelineRecordType::ScheduleStyleRecalculation, true, frame);
314 }
315
316 void InspectorTimelineAgent::willRecalculateStyle(Frame* frame)
317 {
318     pushCurrentRecord(InspectorObject::create(), TimelineRecordType::RecalculateStyles, true, frame);
319 }
320
321 void InspectorTimelineAgent::didRecalculateStyle()
322 {
323     didCompleteCurrentRecord(TimelineRecordType::RecalculateStyles);
324 }
325
326 void InspectorTimelineAgent::willComposite(Frame& frame)
327 {
328     ASSERT(!m_startedComposite);
329     pushCurrentRecord(InspectorObject::create(), TimelineRecordType::Composite, true, &frame);
330     m_startedComposite = true;
331 }
332
333 void InspectorTimelineAgent::didComposite()
334 {
335     ASSERT(m_startedComposite);
336     didCompleteCurrentRecord(TimelineRecordType::Composite);
337     m_startedComposite = false;
338 }
339
340 void InspectorTimelineAgent::willPaint(Frame& frame)
341 {
342     pushCurrentRecord(InspectorObject::create(), TimelineRecordType::Paint, true, &frame);
343 }
344
345 void InspectorTimelineAgent::didPaint(RenderObject* renderer, const LayoutRect& clipRect)
346 {
347     TimelineRecordEntry& entry = m_recordStack.last();
348     ASSERT(entry.type == TimelineRecordType::Paint);
349     FloatQuad quad;
350     localToPageQuad(*renderer, clipRect, &quad);
351     entry.data = TimelineRecordFactory::createPaintData(quad);
352     didCompleteCurrentRecord(TimelineRecordType::Paint);
353 }
354
355 void InspectorTimelineAgent::didInstallTimer(int timerId, int timeout, bool singleShot, Frame* frame)
356 {
357     appendRecord(TimelineRecordFactory::createTimerInstallData(timerId, timeout, singleShot), TimelineRecordType::TimerInstall, true, frame);
358 }
359
360 void InspectorTimelineAgent::didRemoveTimer(int timerId, Frame* frame)
361 {
362     appendRecord(TimelineRecordFactory::createGenericTimerData(timerId), TimelineRecordType::TimerRemove, true, frame);
363 }
364
365 void InspectorTimelineAgent::willFireTimer(int timerId, Frame* frame)
366 {
367     pushCurrentRecord(TimelineRecordFactory::createGenericTimerData(timerId), TimelineRecordType::TimerFire, false, frame);
368 }
369
370 void InspectorTimelineAgent::didFireTimer()
371 {
372     didCompleteCurrentRecord(TimelineRecordType::TimerFire);
373 }
374
375 void InspectorTimelineAgent::willEvaluateScript(const String& url, int lineNumber, Frame& frame)
376 {
377     pushCurrentRecord(TimelineRecordFactory::createEvaluateScriptData(url, lineNumber), TimelineRecordType::EvaluateScript, true, &frame);
378 }
379
380 void InspectorTimelineAgent::didEvaluateScript(Frame&)
381 {
382     didCompleteCurrentRecord(TimelineRecordType::EvaluateScript);
383 }
384
385 void InspectorTimelineAgent::didTimeStamp(Frame& frame, const String& message)
386 {
387     appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::TimeStamp, true, &frame);
388 }
389
390 void InspectorTimelineAgent::time(Frame& frame, const String& message)
391 {
392     appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::Time, true, &frame);
393 }
394
395 void InspectorTimelineAgent::timeEnd(Frame& frame, const String& message)
396 {
397     appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::TimeEnd, true, &frame);
398 }
399
400 void InspectorTimelineAgent::didCommitLoad()
401 {
402     clearRecordStack();
403 }
404
405 void InspectorTimelineAgent::didRequestAnimationFrame(int callbackId, Frame* frame)
406 {
407     appendRecord(TimelineRecordFactory::createAnimationFrameData(callbackId), TimelineRecordType::RequestAnimationFrame, true, frame);
408 }
409
410 void InspectorTimelineAgent::didCancelAnimationFrame(int callbackId, Frame* frame)
411 {
412     appendRecord(TimelineRecordFactory::createAnimationFrameData(callbackId), TimelineRecordType::CancelAnimationFrame, true, frame);
413 }
414
415 void InspectorTimelineAgent::willFireAnimationFrame(int callbackId, Frame* frame)
416 {
417     pushCurrentRecord(TimelineRecordFactory::createAnimationFrameData(callbackId), TimelineRecordType::FireAnimationFrame, false, frame);
418 }
419
420 void InspectorTimelineAgent::didFireAnimationFrame()
421 {
422     didCompleteCurrentRecord(TimelineRecordType::FireAnimationFrame);
423 }
424
425 // ScriptDebugListener
426
427 void InspectorTimelineAgent::breakpointActionProbe(JSC::ExecState* exec, const Inspector::ScriptBreakpointAction& action, unsigned batchId, unsigned sampleId, const Deprecated::ScriptValue&)
428 {
429     UNUSED_PARAM(batchId);
430     ASSERT(exec);
431
432     appendRecord(TimelineRecordFactory::createProbeSampleData(action, sampleId), TimelineRecordType::ProbeSample, false, frameFromExecState(exec));
433 }
434
435 static Inspector::Protocol::Timeline::EventType toProtocol(TimelineRecordType type)
436 {
437     switch (type) {
438     case TimelineRecordType::EventDispatch:
439         return Inspector::Protocol::Timeline::EventType::EventDispatch;
440     case TimelineRecordType::ScheduleStyleRecalculation:
441         return Inspector::Protocol::Timeline::EventType::ScheduleStyleRecalculation;
442     case TimelineRecordType::RecalculateStyles:
443         return Inspector::Protocol::Timeline::EventType::RecalculateStyles;
444     case TimelineRecordType::InvalidateLayout:
445         return Inspector::Protocol::Timeline::EventType::InvalidateLayout;
446     case TimelineRecordType::Layout:
447         return Inspector::Protocol::Timeline::EventType::Layout;
448     case TimelineRecordType::Paint:
449         return Inspector::Protocol::Timeline::EventType::Paint;
450     case TimelineRecordType::Composite:
451         return Inspector::Protocol::Timeline::EventType::Composite;
452     case TimelineRecordType::RenderingFrame:
453         return Inspector::Protocol::Timeline::EventType::RenderingFrame;
454
455     case TimelineRecordType::TimerInstall:
456         return Inspector::Protocol::Timeline::EventType::TimerInstall;
457     case TimelineRecordType::TimerRemove:
458         return Inspector::Protocol::Timeline::EventType::TimerRemove;
459     case TimelineRecordType::TimerFire:
460         return Inspector::Protocol::Timeline::EventType::TimerFire;
461
462     case TimelineRecordType::EvaluateScript:
463         return Inspector::Protocol::Timeline::EventType::EvaluateScript;
464
465     case TimelineRecordType::TimeStamp:
466         return Inspector::Protocol::Timeline::EventType::TimeStamp;
467     case TimelineRecordType::Time:
468         return Inspector::Protocol::Timeline::EventType::Time;
469     case TimelineRecordType::TimeEnd:
470         return Inspector::Protocol::Timeline::EventType::TimeEnd;
471
472     case TimelineRecordType::FunctionCall:
473         return Inspector::Protocol::Timeline::EventType::FunctionCall;
474     case TimelineRecordType::ProbeSample:
475         return Inspector::Protocol::Timeline::EventType::ProbeSample;
476     case TimelineRecordType::ConsoleProfile:
477         return Inspector::Protocol::Timeline::EventType::ConsoleProfile;
478
479     case TimelineRecordType::RequestAnimationFrame:
480         return Inspector::Protocol::Timeline::EventType::RequestAnimationFrame;
481     case TimelineRecordType::CancelAnimationFrame:
482         return Inspector::Protocol::Timeline::EventType::CancelAnimationFrame;
483     case TimelineRecordType::FireAnimationFrame:
484         return Inspector::Protocol::Timeline::EventType::FireAnimationFrame;
485     }
486
487     return Inspector::Protocol::Timeline::EventType::TimeStamp;
488 }
489
490 void InspectorTimelineAgent::addRecordToTimeline(RefPtr<InspectorObject>&& record, TimelineRecordType type)
491 {
492     ASSERT_ARG(record, record);
493     record->setString("type", Inspector::Protocol::getEnumConstantValue(toProtocol(type)));
494
495     if (m_recordStack.isEmpty()) {
496         auto recordObject = BindingTraits<Inspector::Protocol::Timeline::TimelineEvent>::runtimeCast(WTFMove(record));
497         sendEvent(WTFMove(recordObject));
498     } else {
499         const TimelineRecordEntry& parent = m_recordStack.last();
500         // Nested paint records are an implementation detail and add no information not already contained in the parent.
501         if (type == TimelineRecordType::Paint && parent.type == type)
502             return;
503
504         parent.children->pushObject(WTFMove(record));
505     }
506 }
507
508 void InspectorTimelineAgent::setFrameIdentifier(InspectorObject* record, Frame* frame)
509 {
510     if (!frame || !m_pageAgent)
511         return;
512     String frameId;
513     if (frame && m_pageAgent)
514         frameId = m_pageAgent->frameId(frame);
515     record->setString("frameId", frameId);
516 }
517
518 void InspectorTimelineAgent::didCompleteRecordEntry(const TimelineRecordEntry& entry)
519 {
520     entry.record->setObject(ASCIILiteral("data"), entry.data);
521     entry.record->setArray(ASCIILiteral("children"), entry.children);
522     entry.record->setDouble(ASCIILiteral("endTime"), timestamp());
523     addRecordToTimeline(entry.record.copyRef(), entry.type);
524 }
525
526 void InspectorTimelineAgent::didCompleteCurrentRecord(TimelineRecordType type)
527 {
528     // An empty stack could merely mean that the timeline agent was turned on in the middle of
529     // an event.  Don't treat as an error.
530     if (!m_recordStack.isEmpty()) {
531         TimelineRecordEntry entry = m_recordStack.last();
532         m_recordStack.removeLast();
533         ASSERT_UNUSED(type, entry.type == type);
534
535         // Don't send RenderingFrame records that have no children to reduce noise.
536         if (entry.type == TimelineRecordType::RenderingFrame && !entry.children->length())
537             return;
538
539         didCompleteRecordEntry(entry);
540     }
541 }
542
543 InspectorTimelineAgent::InspectorTimelineAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
544     : InspectorAgentBase(ASCIILiteral("Timeline"), context)
545     , m_frontendDispatcher(std::make_unique<Inspector::TimelineFrontendDispatcher>(context.frontendRouter))
546     , m_backendDispatcher(Inspector::TimelineBackendDispatcher::create(context.backendDispatcher, this))
547     , m_pageAgent(pageAgent)
548 {
549 }
550
551 void InspectorTimelineAgent::appendRecord(RefPtr<InspectorObject>&& data, TimelineRecordType type, bool captureCallStack, Frame* frame)
552 {
553     Ref<InspectorObject> record = TimelineRecordFactory::createGenericRecord(timestamp(), captureCallStack ? m_maxCallStackDepth : 0);
554     record->setObject("data", WTFMove(data));
555     setFrameIdentifier(&record.get(), frame);
556     addRecordToTimeline(WTFMove(record), type);
557 }
558
559 void InspectorTimelineAgent::sendEvent(RefPtr<InspectorObject>&& event)
560 {
561     // FIXME: runtimeCast is a hack. We do it because we can't build TimelineEvent directly now.
562     auto recordChecked = BindingTraits<Inspector::Protocol::Timeline::TimelineEvent>::runtimeCast(WTFMove(event));
563     m_frontendDispatcher->eventRecorded(WTFMove(recordChecked));
564 }
565
566 InspectorTimelineAgent::TimelineRecordEntry InspectorTimelineAgent::createRecordEntry(RefPtr<InspectorObject>&& data, TimelineRecordType type, bool captureCallStack, Frame* frame)
567 {
568     Ref<InspectorObject> record = TimelineRecordFactory::createGenericRecord(timestamp(), captureCallStack ? m_maxCallStackDepth : 0);
569     setFrameIdentifier(&record.get(), frame);
570     return TimelineRecordEntry(WTFMove(record), WTFMove(data), InspectorArray::create(), type);
571 }
572
573 void InspectorTimelineAgent::pushCurrentRecord(RefPtr<InspectorObject>&& data, TimelineRecordType type, bool captureCallStack, Frame* frame)
574 {
575     pushCurrentRecord(createRecordEntry(WTFMove(data), type, captureCallStack, frame));
576 }
577
578 void InspectorTimelineAgent::clearRecordStack()
579 {
580     m_recordStack.clear();
581     m_id++;
582 }
583
584 void InspectorTimelineAgent::localToPageQuad(const RenderObject& renderer, const LayoutRect& rect, FloatQuad* quad)
585 {
586     const FrameView& frameView = renderer.view().frameView();
587     FloatQuad absolute = renderer.localToAbsoluteQuad(FloatQuad(rect));
588     quad->setP1(frameView.contentsToRootView(roundedIntPoint(absolute.p1())));
589     quad->setP2(frameView.contentsToRootView(roundedIntPoint(absolute.p2())));
590     quad->setP3(frameView.contentsToRootView(roundedIntPoint(absolute.p3())));
591     quad->setP4(frameView.contentsToRootView(roundedIntPoint(absolute.p4())));
592 }
593
594 } // namespace WebCore