Bug Summary

File:Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore/inspector/agents/page/PageTimelineAgent.cpp
Warning:line 265, column 31
Call argument for 'this' parameter is unchecked and unsafe

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple arm64-apple-macosx15.5.0 -O2 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name UnifiedSource265.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=osx -analyzer-checker=security.insecureAPI.decodeValueOfObjCType -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -target-sdk-version=15.5 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fno-modulemap-allow-subdirectory-search -fdefine-target-os-macros -enable-tlsdesc -target-cpu apple-m1 -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -dwarf-ext-refs -fmodule-format=obj -debug-info-kind=standalone -dwarf-version=5 -debugger-tuning=lldb -fdebug-compilation-dir=/Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore -target-linker-version 1167.5 -fcoverage-compilation-dir=/Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore -resource-dir /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/llvm-project/build/lib/clang/21 -dependency-file /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/scan-build-output/StaticAnalyzer/WebCore/WebCore/normal/arm64/UnifiedSource265.d -skip-unused-modulemap-deps -MT dependencies -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -iquote /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/WebCore-generated-files.hmap -iquote /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/WebCore-project-headers.hmap -isystem /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore/PAL/ThirdParty/dav1d/include -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/System/Library/PrivateFrameworks -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/System/Library/Frameworks -include-pch /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/PrecompiledHeaders/SharedPrecompiledHeaders/12902642326230122134/WebCorePrefix.h.gch -D _LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D CLANG_WEBKIT_BRANCH=1 -D NDEBUG -D BUILDING_WEBKIT -D GL_SILENCE_DEPRECATION=1 -D GLES_SILENCE_DEPRECATION=1 -D __clang_analyzer__ -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/WebCore-own-target-headers.hmap -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/WebCore-all-target-headers.hmap -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/include -I PAL -I ForwardingHeaders -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include/libxslt -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include/libxml2 -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/DerivedSources/WebCore -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/usr/local/include -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/usr/local/include/WebKitAdditions -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/local/include/WebKitAdditions -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/usr/local/include -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitLibraries/SDKs/macosx15.0-additions.sdk/usr/local/include -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/local/include -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/usr/local/include/webrtc -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/local/include/webrtc -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/usr/local/include/webm -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/local/include/webm -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/PAL.build/PAL.build/DerivedSources -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/PAL.build/Release/PAL.build/DerivedSources -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/DerivedSources-normal/arm64 -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/DerivedSources/arm64 -I /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release/WebCore.build/DerivedSources -F/Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/local/include -internal-isystem /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/llvm-project/build/lib/clang/21/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/System/Library/Frameworks -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/System/Library/SubFrameworks -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/Library/Frameworks -Wno-trigraphs -Werror -Wno-missing-field-initializers -Wmissing-prototypes -Wunreachable-code -Wnon-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wsign-compare -Wno-shorten-64-to-32 -Wnewline-eof -Wno-c++11-extensions -Wno-implicit-fallthrough -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wno-semicolon-before-method-body -Wall -Wc99-designator -Wconditional-uninitialized -Wextra -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion -Wenum-float-conversion -Wfinal-dtor-non-final-class -Wformat=2 -Wmisleading-indentation -Wpointer-to-int-cast -Wreorder-init-list -Wundef -Wunused-but-set-variable -Wvla -Werror=unguarded-availability -Wno-elaborated-enum-base -Wcast-qual -Wchar-subscripts -Wextra-tokens -Winit-self -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion -Wthread-safety -Wno-profile-instr-out-of-date -Wno-profile-instr-unprofiled -Wno-backend-plugin -Wunsafe-buffer-usage -std=c++2b -fdeprecated-macro -ferror-limit 19 -fmacro-backtrace-limit=0 -fvisibility=hidden -fvisibility-inlines-hidden -stack-protector 1 -fblocks -fencode-extended-block-signature -fno-rtti -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -fno-implicit-modules -fskip-odr-check-in-gmf -fpascal-strings -fmax-type-align=16 -fdiagnostics-show-note-include-stack -vectorize-loops -vectorize-slp -fsafe-buffer-usage-suggestions -analyzer-output=html -analyzer-config report-in-main-source-file=true -analyzer-config nullability:NoDiagnoseCallsToSystemHeaders=true -analyzer-checker optin.osx.cocoa.localizability.NonLocalizedStringChecker -analyzer-checker security.insecureAPI.UncheckedReturn -analyzer-checker security.insecureAPI.getpw -analyzer-checker security.insecureAPI.gets -analyzer-checker security.insecureAPI.mkstemp -analyzer-checker security.insecureAPI.mktemp -analyzer-disable-checker security.insecureAPI.rand -analyzer-disable-checker security.insecureAPI.strcpy -analyzer-checker security.insecureAPI.vfork -analyzer-disable-checker alpha,apiModeling,core,cplusplus,deadcode,debug,fuchsia,nullability,optin,osx,security,unix,webkit -analyzer-checker alpha.webkit.ForwardDeclChecker,alpha.webkit.MemoryUnsafeCastChecker,alpha.webkit.NoDeleteChecker,alpha.webkit.NoUncheckedPtrMemberChecker,alpha.webkit.NoUnretainedMemberChecker,alpha.webkit.RetainPtrCtorAdoptChecker,alpha.webkit.UncheckedCallArgsChecker,alpha.webkit.UncheckedLocalVarsChecker,alpha.webkit.UncountedCallArgsChecker,alpha.webkit.UncountedLocalVarsChecker,alpha.webkit.UnretainedCallArgsChecker,alpha.webkit.UnretainedLambdaCapturesChecker,alpha.webkit.UnretainedLocalVarsChecker,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,webkit.UncountedLambdaCapturesChecker -analyzer-config max-nodes=10000000 -analyzer-config verbose-report-filename=true -fdwarf2-cfi-asm -o /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/scan-build-output/StaticAnalyzer/WebCore/WebCore/normal/arm64/UnifiedSource265.plist -x c++ /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/DerivedSources/WebCore/unified-sources/UnifiedSource265.cpp
1/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2014 University of Washington.
4 * Copyright (C) 2015-2016 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
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 * THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "config.h"
29#include "PageTimelineAgent.h"
30
31#include "DocumentView.h"
32#include "FrameSnapshotting.h"
33#include "ImageBuffer.h"
34#include "ImageUtilities.h"
35#include "InspectorBackendClient.h"
36#include "InstrumentingAgents.h"
37#include "Page.h"
38#include "PageInspectorController.h"
39#include "RenderObjectInlines.h"
40#include "RenderView.h"
41#include "TimelineRecordFactory.h"
42#include "WebDebuggerAgent.h"
43
44#if PLATFORM(IOS_FAMILY)(defined WTF_PLATFORM_IOS_FAMILY && WTF_PLATFORM_IOS_FAMILY
)
45#include "WebCoreThreadInternal.h"
46#include <wtf/RuntimeApplicationChecks.h>
47#endif
48
49#if PLATFORM(COCOA)(defined 1 && 1)
50#include "RunLoopObserver.h"
51#endif
52
53namespace WebCore {
54
55using namespace Inspector;
56
57WTF_MAKE_TZONE_ALLOCATED_IMPL(PageTimelineAgent)::bmalloc::api::HeapRef PageTimelineAgent::s_heapRef; const TZoneSpecification
PageTimelineAgent::s_heapSpec = { &PageTimelineAgent::s_heapRef
, TZoneSpecification::encodeSize<PageTimelineAgent>(), TZoneSpecification
::encodeAlignment<PageTimelineAgent>(), TZoneSpecification
::encodeCategory<PageTimelineAgent>(), ::bmalloc::api::
compactAllocationMode<PageTimelineAgent>(), TZoneSpecification
::encodeDescriptor<PageTimelineAgent>(), }; void* PageTimelineAgent
::operatorNewSlow(size_t size) { if constexpr (::bmalloc::api
::compactAllocationMode<PageTimelineAgent>() == CompactAllocationMode
::Compact) return ::bmalloc::api::tzoneAllocateCompactSlow(size
, s_heapSpec); return ::bmalloc::api::tzoneAllocateNonCompactSlow
(size, s_heapSpec); } using __makeBtzoneMallocedInlineMacroSemicolonifier
__attribute__((unused)) = int
;
58
59#if PLATFORM(COCOA)(defined 1 && 1)
60static CFRunLoopRef currentRunLoop()
61{
62#if PLATFORM(IOS_FAMILY)(defined WTF_PLATFORM_IOS_FAMILY && WTF_PLATFORM_IOS_FAMILY
)
63 // A race condition during WebView deallocation can lead to a crash if the layer sync run loop
64 // observer is added to the main run loop <rdar://problem/9798550>. However, for responsiveness,
65 // we still allow this, see <rdar://problem/7403328>. Since the race condition and subsequent
66 // crash are especially troublesome for Apple Books, we never allow the observer to be added to the
67 // main run loop in Apple Books.
68 if (WTF::CocoaApplication::isAppleBooks())
69 return WebThreadRunLoop();
70#endif
71 return CFRunLoopGetCurrent();
72}
73#endif
74
75PageTimelineAgent::PageTimelineAgent(PageAgentContext& context)
76 : InspectorTimelineAgent(context)
77 , m_inspectedPage(context.inspectedPage)
78{
79}
80
81PageTimelineAgent::~PageTimelineAgent() = default;
82
83bool PageTimelineAgent::enabled() const
84{
85 return Ref { m_instrumentingAgents.get() }->enabledPageTimelineAgent() == this && InspectorTimelineAgent::enabled();
86}
87
88void PageTimelineAgent::internalEnable()
89{
90 Ref { m_instrumentingAgents.get() }->setEnabledPageTimelineAgent(this);
91
92 InspectorTimelineAgent::internalEnable();
93}
94
95void PageTimelineAgent::internalDisable()
96{
97 Ref { m_instrumentingAgents.get() }->setEnabledPageTimelineAgent(nullptr);
98
99 m_autoCaptureEnabled = false;
100
101 InspectorTimelineAgent::internalDisable();
102}
103
104bool PageTimelineAgent::tracking() const
105{
106 return Ref { m_instrumentingAgents.get() }->trackingPageTimelineAgent() == this && InspectorTimelineAgent::tracking();
107}
108
109void PageTimelineAgent::internalStart(std::optional<int>&& maxCallStackDepth)
110{
111 Ref { m_instrumentingAgents.get() }->setTrackingPageTimelineAgent(this);
112
113 // FIXME: Abstract away platform-specific code once https://bugs.webkit.org/show_bug.cgi?id=142748 is fixed.
114
115#if PLATFORM(COCOA)(defined 1 && 1)
116 m_frameStartObserver = makeUnique<RunLoopObserver>(RunLoopObserver::WellKnownOrder::InspectorFrameBegin, [weakThis = WeakPtr { *this }] {
117 CheckedPtr checkedThis = weakThis.get();
118 if (!checkedThis)
119 return;
120 if (!checkedThis->tracking() || protect(checkedThis->environment())->debugger()->isPaused())
121 return;
122 if (!checkedThis->m_runLoopNestingLevel) {
123 checkedThis->pushCurrentRecord(JSON::Object::create(), TimelineRecordType::RenderingFrame, false);
124 checkedThis->m_runLoopNestingLevel++;
125 }
126 });
127
128 m_frameStartObserver->schedule(currentRunLoop(), { RunLoopObserver::Activity::Entry, RunLoopObserver::Activity::AfterWaiting });
129
130 // Create a runloop record and increment the runloop nesting level, to capture the current turn of the main runloop
131 // (which is the outer runloop if recording started while paused in the debugger).
132 pushCurrentRecord(JSON::Object::create(), TimelineRecordType::RenderingFrame, false);
133
134 m_runLoopNestingLevel = 1;
135#elif USE(GLIB_EVENT_LOOP)(defined USE_GLIB_EVENT_LOOP && USE_GLIB_EVENT_LOOP)
136 m_runLoopObserver = RunLoop::EventObserver::create([weakThis = WeakPtr { *this }](RunLoop::Event event, const String& name) {
137 CheckedPtr checkedThis = weakThis.get();
138 if (!checkedThis)
139 return;
140 if (!checkedThis->tracking() || protect(checkedThis->environment())->debugger()->isPaused())
141 return;
142
143 switch (event) {
144 case RunLoop::Event::WillDispatch:
145 checkedThis->pushCurrentRecord(TimelineRecordFactory::createRenderingFrameData(name), TimelineRecordType::RenderingFrame, false);
146 break;
147 case RunLoop::Event::DidDispatch:
148 if (checkedThis->m_startedComposite)
149 checkedThis->didComposite();
150 checkedThis->didCompleteCurrentRecord(TimelineRecordType::RenderingFrame);
151 break;
152 }
153 });
154 RunLoop::currentSingleton().observeEvent(*m_runLoopObserver);
155#endif
156
157 InspectorTimelineAgent::internalStart(WTF::move(maxCallStackDepth));
158
159 if (auto* client = m_inspectedPage->inspectorController().inspectorBackendClient())
160 client->timelineRecordingChanged(true);
161}
162
163void PageTimelineAgent::internalStop()
164{
165 Ref { m_instrumentingAgents.get() }->setTrackingPageTimelineAgent(nullptr);
166
167 m_autoCapturePhase = AutoCapturePhase::None;
168
169#if PLATFORM(COCOA)(defined 1 && 1)
170 m_frameStartObserver = nullptr;
171 m_runLoopNestingLevel = 0;
172#elif USE(GLIB_EVENT_LOOP)(defined USE_GLIB_EVENT_LOOP && USE_GLIB_EVENT_LOOP)
173 m_runLoopObserver = nullptr;
174#endif
175 m_startedComposite = false;
176
177 InspectorTimelineAgent::internalStop();
178
179 if (auto* client = m_inspectedPage->inspectorController().inspectorBackendClient())
180 client->timelineRecordingChanged(false);
181}
182
183Inspector::Protocol::ErrorStringOr<void> PageTimelineAgent::setAutoCaptureEnabled(bool enabled)
184{
185 m_autoCaptureEnabled = enabled;
186
187 return { };
188}
189
190void PageTimelineAgent::didInvalidateLayout()
191{
192 appendRecord(JSON::Object::create(), TimelineRecordType::InvalidateLayout, true);
193}
194
195void PageTimelineAgent::willLayout()
196{
197 pushCurrentRecord(JSON::Object::create(), TimelineRecordType::Layout, true);
198}
199
200void PageTimelineAgent::didLayout(const Vector<FloatQuad>& layoutAreas)
201{
202 auto* entry = lastRecordEntry();
203 if (!entry)
204 return;
205
206 ASSERT(entry->type == TimelineRecordType::Layout)((void)0);
207 ASSERT(!layoutAreas.isEmpty())((void)0);
208 if (!layoutAreas.isEmpty())
209 TimelineRecordFactory::appendLayoutRoot(entry->data.get(), layoutAreas[0]);
210
211 didCompleteCurrentRecord(TimelineRecordType::Layout);
212}
213
214void PageTimelineAgent::didScheduleStyleRecalculation()
215{
216 appendRecord(JSON::Object::create(), TimelineRecordType::ScheduleStyleRecalculation, true);
217}
218
219void PageTimelineAgent::willRecalculateStyle()
220{
221 pushCurrentRecord(JSON::Object::create(), TimelineRecordType::RecalculateStyles, true);
222}
223
224void PageTimelineAgent::didRecalculateStyle()
225{
226 didCompleteCurrentRecord(TimelineRecordType::RecalculateStyles);
227}
228
229void PageTimelineAgent::willComposite()
230{
231 ASSERT(!m_startedComposite)((void)0);
232 pushCurrentRecord(JSON::Object::create(), TimelineRecordType::Composite, true);
233 m_startedComposite = true;
234}
235
236void PageTimelineAgent::didComposite()
237{
238 if (m_startedComposite)
239 didCompleteCurrentRecord(TimelineRecordType::Composite);
240 m_startedComposite = false;
241
242 if (instruments().contains(Inspector::Protocol::Timeline::Instrument::Screenshot))
243 captureScreenshot();
244}
245
246void PageTimelineAgent::willPaint()
247{
248 if (m_isCapturingScreenshot)
249 return;
250
251 pushCurrentRecord(JSON::Object::create(), TimelineRecordType::Paint, true);
252}
253
254void PageTimelineAgent::didPaint(RenderObject& renderer, const LayoutRect& clipRect)
255{
256 if (m_isCapturingScreenshot)
257 return;
258
259 auto* entry = lastRecordEntry();
260 if (!entry)
261 return;
262
263 ASSERT(entry->type == TimelineRecordType::Paint)((void)0);
264
265 auto clipQuadInRootView = renderer.view().frameView().contentsToRootView(renderer.localToAbsoluteQuad({ clipRect }));
Call argument for 'this' parameter is unchecked and unsafe
266 entry->data = TimelineRecordFactory::createPaintData(clipQuadInRootView);
267
268 didCompleteCurrentRecord(TimelineRecordType::Paint);
269}
270
271void PageTimelineAgent::mainFrameStartedLoading()
272{
273 if (!m_autoCaptureEnabled)
274 return;
275
276 if (instruments().isEmpty())
277 return;
278
279 m_autoCapturePhase = AutoCapturePhase::BeforeLoad;
280
281 // Pre-emptively disable breakpoints. The frontend must re-enable them.
282 if (auto* webDebuggerAgent = Ref { m_instrumentingAgents.get() }->enabledWebDebuggerAgent())
283 std::ignore = webDebuggerAgent->setBreakpointsActive(false);
284
285 // Inform the frontend we started an auto capture. The frontend must stop capture.
286 autoCaptureStarted();
287
288 toggleInstruments(InstrumentState::Start);
289}
290
291void PageTimelineAgent::mainFrameNavigated()
292{
293 if (m_autoCapturePhase == AutoCapturePhase::BeforeLoad) {
294 m_autoCapturePhase = AutoCapturePhase::FirstNavigation;
295 toggleInstruments(InstrumentState::Start);
296 m_autoCapturePhase = AutoCapturePhase::AfterFirstNavigation;
297 }
298}
299
300void PageTimelineAgent::didCompleteRenderingFrame()
301{
302#if PLATFORM(COCOA)(defined 1 && 1)
303 if (!tracking() || protect(environment())->debugger()->isPaused())
304 return;
305
306 ASSERT(m_runLoopNestingLevel > 0)((void)0);
307 m_runLoopNestingLevel--;
308 if (m_runLoopNestingLevel)
309 return;
310
311 if (m_startedComposite)
312 didComposite();
313
314 didCompleteCurrentRecord(TimelineRecordType::RenderingFrame);
315#endif
316}
317
318bool PageTimelineAgent::shouldStartHeapInstrument() const
319{
320 if (m_autoCapturePhase == AutoCapturePhase::BeforeLoad || m_autoCapturePhase == AutoCapturePhase::AfterFirstNavigation)
321 return false;
322 return InspectorTimelineAgent::shouldStartHeapInstrument();
323}
324
325void PageTimelineAgent::captureScreenshot()
326{
327 SetForScope isTakingScreenshot(m_isCapturingScreenshot, true);
328
329 auto snapshotStartTime = timestamp();
330
331 Ref inspectedPage = m_inspectedPage.get();
332 RefPtr localMainFrame = inspectedPage->localMainFrame();
333 if (!localMainFrame)
334 return;
335
336 RefPtr localMainFrameView = localMainFrame->view();
337 if (!localMainFrameView)
338 return;
339
340 if (RefPtr snapshot = snapshotFrameRect(*localMainFrame, localMainFrameView->unobscuredContentRect(), { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() })) {
341 Ref snapshotRecord = TimelineRecordFactory::createScreenshotData(encodeDataURL(WTF::move(snapshot), "image/png"_s));
342 pushCurrentRecord(WTF::move(snapshotRecord), TimelineRecordType::Screenshot, false, snapshotStartTime);
343 didCompleteCurrentRecord(TimelineRecordType::Screenshot);
344 }
345}
346
347} // namespace WebCore