Bug Summary

File:Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore/page/Frame.cpp
Warning:line 219, column 18
Local variable 'child' is uncounted 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 UnifiedSource297.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/UnifiedSource297.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/988383290502741483/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 -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-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.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/UnifiedSource297.plist -x c++ /Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/WebKitBuild/Release/DerivedSources/WebCore/unified-sources/UnifiedSource297.cpp
1/*
2 * Copyright (C) 2018-2025 Apple 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "Frame.h"
28
29#include "ContainerNodeInlines.h"
30#include "FrameLoader.h"
31#include "FrameLoaderClient.h"
32#include "HTMLFrameOwnerElement.h"
33#include "HTMLIFrameElement.h"
34#include "LocalDOMWindow.h"
35#include "NavigationScheduler.h"
36#include "NodeDocument.h"
37#include "OwnerPermissionsPolicyData.h"
38#include "Page.h"
39#include "RemoteFrame.h"
40#include "RenderElement.h"
41#include "RenderWidget.h"
42#include "ScrollingCoordinator.h"
43#include "Settings.h"
44#include "WindowProxy.h"
45#include <wtf/Assertions.h>
46#include <wtf/NeverDestroyed.h>
47
48namespace WebCore {
49
50#if ASSERT_ENABLED0
51class FrameLifetimeVerifier {
52public:
53 static FrameLifetimeVerifier& singleton()
54 {
55 static NeverDestroyed<FrameLifetimeVerifier> instance;
56 return instance.get();
57 }
58
59 void frameCreated(Frame& frame)
60 {
61 auto& pair = m_map.ensure(frame.frameID(), [] {
62 return std::pair<WeakPtr<LocalFrame>, WeakPtr<RemoteFrame>> { };
63 }).iterator->value;
64
65 switch (frame.frameType()) {
66 case Frame::FrameType::Local:
67 ASSERT_WITH_MESSAGE(!pair.first, "There should never be two LocalFrames with the same ID in the same process")((void)0);
68 pair.first = downcast<LocalFrame>(frame);
69 break;
70 case Frame::FrameType::Remote:
71 ASSERT_WITH_MESSAGE(!pair.second, "There should never be two RemoteFrames with the same ID in the same process")((void)0);
72 pair.second = downcast<RemoteFrame>(frame);
73 break;
74 }
75 }
76
77 void frameDestroyed(Frame& frame)
78 {
79 auto it = m_map.find(frame.frameID());
80 ASSERT(it != m_map.end())((void)0);
81 auto& pair = it->value;
82 switch (frame.frameType()) {
83 case Frame::FrameType::Local:
84 ASSERT(pair.first == &frame)((void)0);
85 if (pair.second)
86 pair.first = nullptr;
87 else
88 m_map.remove(it);
89 break;
90 case Frame::FrameType::Remote:
91 ASSERT(pair.second == &frame)((void)0);
92 if (pair.first)
93 pair.second = nullptr;
94 else
95 m_map.remove(it);
96 }
97 }
98
99 bool isRootFrameIdentifier(FrameIdentifier identifier)
100 {
101 auto it = m_map.find(identifier);
102 if (it == m_map.end())
103 return false;
104 return it->value.first && it->value.first->isRootFrame();
105 }
106private:
107 HashMap<FrameIdentifier, std::pair<WeakPtr<LocalFrame>, WeakPtr<RemoteFrame>>> m_map;
108};
109#endif
110
111Frame::Frame(Page& page, FrameIdentifier frameID, FrameType frameType, HTMLFrameOwnerElement* ownerElement, Frame* parent, Frame* opener, Ref<FrameTreeSyncData>&& frameTreeSyncData, AddToFrameTree addToFrameTree)
112 : m_page(page)
113 , m_frameID(frameID)
114 , m_treeNode(*this, addToFrameTree == AddToFrameTree::Yes ? parent : nullptr)
115 , m_windowProxy(WindowProxy::create(*this))
116 , m_ownerElement(ownerElement)
117 , m_mainFrame(parent ? page.mainFrame() : *this)
118 , m_settings(page.settings())
119 , m_frameType(frameType)
120 , m_navigationScheduler(makeUniqueRefWithoutRefCountedCheck<NavigationScheduler>(*this))
121 , m_opener(opener)
122 , m_frameTreeSyncData(WTF::move(frameTreeSyncData))
123{
124 relaxAdoptionRequirement();
125 if (parent && addToFrameTree == AddToFrameTree::Yes)
126 parent->tree().appendChild(*this);
127
128 if (ownerElement)
129 ownerElement->setContentFrame(*this);
130
131 if (opener)
132 opener->m_openedFrames.add(*this);
133
134#if ASSERT_ENABLED0
135 FrameLifetimeVerifier::singleton().frameCreated(*this);
136#endif
137}
138
139Frame::~Frame()
140{
141 protectedWindowProxy()->detachFromFrame();
142 protectedNavigationScheduler()->cancel();
143
144#if ASSERT_ENABLED0
145 FrameLifetimeVerifier::singleton().frameDestroyed(*this);
146#endif
147}
148
149void Frame::resetWindowProxy()
150{
151 m_windowProxy = WindowProxy::create(*this);
152}
153
154void Frame::detachFromPage()
155{
156 if (isRootFrame()) {
157 if (RefPtr page = m_page.get()) {
158 page->removeRootFrame(downcast<LocalFrame>(*this));
159 if (RefPtr scrollingCoordinator = page->scrollingCoordinator())
160 scrollingCoordinator->rootFrameWasRemoved(frameID());
161 }
162 }
163 m_page = nullptr;
164}
165
166void Frame::disconnectOwnerElement()
167{
168 if (RefPtr ownerElement = m_ownerElement.get()) {
169 ownerElement->clearContentFrame();
170 m_ownerElement = nullptr;
171 }
172
173 frameWasDisconnectedFromOwner();
174}
175
176void Frame::takeWindowProxyAndOpenerFrom(Frame& frame)
177{
178 ASSERT(is<LocalDOMWindow>(window()) != is<LocalDOMWindow>(frame.window()) || page() != frame.page())((void)0);
179 ASSERT(m_windowProxy->frame() == this)((void)0);
180 protectedWindowProxy()->detachFromFrame();
181 m_windowProxy = frame.windowProxy();
182 frame.resetWindowProxy();
183 protectedWindowProxy()->replaceFrame(*this);
184
185 ASSERT(!m_opener)((void)0);
186 m_opener = frame.m_opener;
187 if (m_opener)
188 m_opener->m_openedFrames.add(*this);
189
190 for (Ref opened : frame.m_openedFrames) {
191 ASSERT(opened->m_opener.get() == &frame)((void)0);
192 opened->m_opener = *this;
193 m_openedFrames.add(opened);
194 }
195 frame.m_openedFrames.clear();
196}
197
198Ref<WindowProxy> Frame::protectedWindowProxy() const
199{
200 return m_windowProxy;
201}
202
203RefPtr<DOMWindow> Frame::protectedWindow() const
204{
205 return window();
206}
207
208Ref<NavigationScheduler> Frame::protectedNavigationScheduler() const
209{
210 return m_navigationScheduler.get();
211}
212
213std::optional<uint64_t> Frame::indexInFrameTreeSiblings() const
214{
215 if (!tree().parent())
216 return std::nullopt;
217
218 for (uint64_t i = 0; i < tree().parent()->tree().childCount(); i++) {
219 if (auto child = tree().parent()->tree().child(i); child->frameID() == this->frameID())
Local variable 'child' is uncounted and unsafe
220 return i;
221 }
222
223 ASSERT_NOT_REACHED("This frame should be in its own tree")((void)0);
224 return std::nullopt;
225}
226
227Vector<uint64_t> Frame::pathToFrame() const
228{
229 Vector<uint64_t> path;
230 RefPtr current = this;
231
232 while (current) {
233 if (auto index = current->indexInFrameTreeSiblings())
234 path.append(*index);
235 current = current->tree().parent();
236 }
237
238 path.reverse();
239 return path;
240}
241
242RenderWidget* Frame::ownerRenderer() const
243{
244 RefPtr ownerElement = this->ownerElement();
245 if (!ownerElement)
246 return nullptr;
247 // FIXME: If <object> is ever fixed to disassociate itself from frames
248 // that it has started but canceled, then this can turn into an ASSERT
249 // since ownerElement would be nullptr when the load is canceled.
250 // https://bugs.webkit.org/show_bug.cgi?id=18585
251 return dynamicDowncast<RenderWidget>(ownerElement->renderer());
252}
253
254RefPtr<FrameView> Frame::protectedVirtualView() const
255{
256 return virtualView();
257}
258
259#if ASSERT_ENABLED0
260bool Frame::isRootFrameIdentifier(FrameIdentifier identifier)
261{
262 return FrameLifetimeVerifier::singleton().isRootFrameIdentifier(identifier);
263}
264#endif
265
266void Frame::updateOpener(Frame& newOpener, NotifyUIProcess notifyUIProcess)
267{
268 if (notifyUIProcess == NotifyUIProcess::Yes)
269 loaderClient().updateOpener(newOpener.frameID());
270 if (m_opener)
271 m_opener->m_openedFrames.remove(*this);
272 newOpener.m_openedFrames.add(*this);
273 if (RefPtr page = this->page())
274 page->setOpenedByDOMWithOpener(true);
275 m_opener = newOpener;
276
277 reinitializeDocumentSecurityContext();
278}
279
280void Frame::disownOpener(NotifyUIProcess notifyUIProcess)
281{
282 if (m_opener) {
283 if (notifyUIProcess == NotifyUIProcess::Yes)
284 loaderClient().updateOpener(std::nullopt);
285 m_opener->m_openedFrames.remove(*this);
286 }
287
288 m_opener = nullptr;
289
290 reinitializeDocumentSecurityContext();
291}
292
293void Frame::setOpenerForWebKitLegacy(Frame* frame)
294{
295 ASSERT(!m_opener)((void)0);
296 ASSERT(frame)((void)0);
297 m_opener = frame;
298 m_page->setOpenedByDOMWithOpener(true);
299 reinitializeDocumentSecurityContext();
300}
301
302void Frame::detachFromAllOpenedFrames()
303{
304 for (Ref frame : std::exchange(m_openedFrames, { }))
305 frame->m_opener = nullptr;
306}
307
308bool Frame::hasOpenedFrames() const
309{
310 return !m_openedFrames.isEmptyIgnoringNullReferences();
311}
312
313void Frame::setOwnerElement(HTMLFrameOwnerElement* element)
314{
315 m_ownerElement = element;
316 if (element) {
317 element->clearContentFrame();
318 element->setContentFrame(*this);
319 }
320 updateScrollingMode();
321}
322
323void Frame::setOwnerPermissionsPolicy(OwnerPermissionsPolicyData&& ownerPermissionsPolicy)
324{
325 m_ownerPermisssionsPolicyOverride = makeUnique<OwnerPermissionsPolicyData>(WTF::move(ownerPermissionsPolicy));
326}
327
328std::optional<OwnerPermissionsPolicyData> Frame::ownerPermissionsPolicy() const
329{
330 if (m_ownerPermisssionsPolicyOverride)
331 return *m_ownerPermisssionsPolicyOverride;
332
333 RefPtr owner = ownerElement();
334 if (!owner)
335 return std::nullopt;
336
337 auto documentOrigin = owner->protectedDocument()->securityOrigin().data();
338 auto documentPolicy = owner->protectedDocument()->permissionsPolicy();
339
340 RefPtr iframe = dynamicDowncast<HTMLIFrameElement>(owner);
341 auto containerPolicy = iframe ? PermissionsPolicy::processPermissionsPolicyAttribute(*iframe) : PermissionsPolicy::PolicyDirective { };
342 return OwnerPermissionsPolicyData { WTF::move(documentOrigin), WTF::move(documentPolicy), WTF::move(containerPolicy) };
343}
344
345void Frame::updateSandboxFlags(SandboxFlags flags, NotifyUIProcess notifyUIProcess)
346{
347 if (notifyUIProcess == NotifyUIProcess::Yes)
348 loaderClient().updateSandboxFlags(flags);
349}
350
351void Frame::stopForBackForwardCache()
352{
353 if (RefPtr localFrame = dynamicDowncast<LocalFrame>(*this))
354 localFrame->loader().stopForBackForwardCache();
355 else {
356 for (RefPtr child = tree().firstChild(); child; child = child->tree().nextSibling())
357 child->stopForBackForwardCache();
358 }
359}
360
361void Frame::updateFrameTreeSyncData(Ref<FrameTreeSyncData>&& data)
362{
363 m_frameTreeSyncData = WTF::move(data);
364}
365
366void Frame::updateFrameTreeSyncData(const FrameTreeSyncSerializationData& data)
367{
368 protectedFrameTreeSyncData()->update(data);
369}
370
371bool Frame::frameCanCreatePaymentSession() const
372{
373 // Prefer the LocalFrame code path when site isolation is disabled.
374 ASSERT(m_settings->siteIsolationEnabled())((void)0);
375 return m_frameTreeSyncData->frameCanCreatePaymentSession;
376}
377
378bool Frame::isPrinting() const
379{
380 return m_isPrinting;
381}
382
383void Frame::setPrinting(bool printing, FloatSize pageSize, FloatSize originalPageSize, float maximumShrinkRatio, AdjustViewSize shouldAdjustViewSize, NotifyUIProcess notifyUIProcess)
384{
385 m_isPrinting = printing;
386 if (notifyUIProcess == NotifyUIProcess::Yes && m_settings->siteIsolationEnabled())
387 loaderClient().setPrinting(printing, pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
388}
389
390} // namespace WebCore