Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp
Warning:line 253, column 9
Value stored to 'subdocRootFrame' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_layout_generic4.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -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 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/generic -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/generic -resource-dir /usr/lib/llvm-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/layout/base -I /var/lib/jenkins/workspace/firefox-scan-build/layout/forms -I /var/lib/jenkins/workspace/firefox-scan-build/layout/painting -I /var/lib/jenkins/workspace/firefox-scan-build/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/layout/tables -I /var/lib/jenkins/workspace/firefox-scan-build/layout/xul -I /var/lib/jenkins/workspace/firefox-scan-build/docshell/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/html -I /var/lib/jenkins/workspace/firefox-scan-build/dom/xul -I /var/lib/jenkins/workspace/firefox-scan-build/gfx/cairo/cairo/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/cloudproviders -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0/unix-print -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-07-30-004816-4182763-1 -x c++ Unified_cpp_layout_generic4.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7/*
8 * rendering object for replaced elements that contain a document, such
9 * as <frame>, <iframe>, and some <object>s
10 */
11
12#include "nsSubDocumentFrame.h"
13
14#include "mozilla/ComputedStyleInlines.h"
15#include "mozilla/Preferences.h"
16#include "mozilla/PresShell.h"
17#include "mozilla/ScrollContainerFrame.h"
18#include "mozilla/StaticPrefs_layout.h"
19#include "mozilla/Unused.h"
20#include "mozilla/dom/Document.h"
21#include "mozilla/dom/HTMLFrameElement.h"
22#include "mozilla/dom/ImageDocument.h"
23#include "mozilla/dom/BrowserParent.h"
24
25#include "nsCOMPtr.h"
26#include "nsGenericHTMLElement.h"
27#include "nsGenericHTMLFrameElement.h"
28#include "nsAttrValueInlines.h"
29#include "nsIDocShell.h"
30#include "nsIDocumentViewer.h"
31#include "nsIContentInlines.h"
32#include "nsPresContext.h"
33#include "nsView.h"
34#include "nsViewManager.h"
35#include "nsGkAtoms.h"
36#include "nsStyleConsts.h"
37#include "nsStyleStruct.h"
38#include "nsStyleStructInlines.h"
39#include "nsFrameSetFrame.h"
40#include "nsNameSpaceManager.h"
41#include "nsDisplayList.h"
42#include "nsIObjectLoadingContent.h"
43#include "nsLayoutUtils.h"
44#include "nsContentUtils.h"
45#include "nsServiceManagerUtils.h"
46#include "nsQueryObject.h"
47#include "RetainedDisplayListBuilder.h"
48#include "nsObjectLoadingContent.h"
49
50#include "mozilla/layers/WebRenderUserData.h"
51#include "mozilla/layers/WebRenderScrollData.h"
52#include "mozilla/layers/RenderRootStateManager.h"
53#include "mozilla/layers/StackingContextHelper.h" // for StackingContextHelper
54#include "mozilla/ProfilerLabels.h"
55
56using namespace mozilla;
57using namespace mozilla::dom;
58using namespace mozilla::gfx;
59using namespace mozilla::layers;
60
61static Document* GetDocumentFromView(nsView* aView) {
62 MOZ_ASSERT(aView, "null view")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aView)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(aView))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("aView" " (" "null view" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 62); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aView" ") (" "null view"
")"); do { *((volatile int*)__null) = 62; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
63
64 nsViewManager* vm = aView->GetViewManager();
65 PresShell* presShell = vm ? vm->GetPresShell() : nullptr;
66 return presShell ? presShell->GetDocument() : nullptr;
67}
68
69static void PropagateIsUnderHiddenEmbedderElement(nsFrameLoader* aFrameLoader,
70 bool aValue) {
71 if (!aFrameLoader) {
72 return;
73 }
74
75 if (BrowsingContext* bc = aFrameLoader->GetExtantBrowsingContext()) {
76 if (bc->IsUnderHiddenEmbedderElement() != aValue) {
77 Unused << bc->SetIsUnderHiddenEmbedderElement(aValue);
78 }
79 }
80}
81
82nsSubDocumentFrame::nsSubDocumentFrame(ComputedStyle* aStyle,
83 nsPresContext* aPresContext)
84 : nsAtomicContainerFrame(aStyle, aPresContext, kClassID),
85 mOuterView(nullptr),
86 mInnerView(nullptr),
87 mIsInline(false),
88 mPostedReflowCallback(false),
89 mDidCreateDoc(false),
90 mCallingShow(false),
91 mIsInObjectOrEmbed(false) {}
92
93#ifdef ACCESSIBILITY1
94a11y::AccType nsSubDocumentFrame::AccessibleType() {
95 return a11y::eOuterDocType;
96}
97#endif
98
99NS_QUERYFRAME_HEAD(nsSubDocumentFrame)void* nsSubDocumentFrame ::QueryFrame(FrameIID id) const { switch
(id) {
100 NS_QUERYFRAME_ENTRY(nsSubDocumentFrame)case nsSubDocumentFrame ::kFrameIID: { static_assert( std::is_same_v
<nsSubDocumentFrame, nsSubDocumentFrame ::Has_NS_DECL_QUERYFRAME_TARGET
>, "nsSubDocumentFrame" " must declare itself as a queryframe target"
); return const_cast<nsSubDocumentFrame*>(static_cast<
const nsSubDocumentFrame*>(this)); }
101NS_QUERYFRAME_TAIL_INHERITING(nsAtomicContainerFrame)default: break; } return nsAtomicContainerFrame ::QueryFrame(
id); }
102
103class AsyncFrameInit : public Runnable {
104 public:
105 explicit AsyncFrameInit(nsIFrame* aFrame)
106 : mozilla::Runnable("AsyncFrameInit"), mFrame(aFrame) {}
107 NS_IMETHODvirtual nsresult Run() override {
108 AUTO_PROFILER_LABEL("AsyncFrameInit::Run", OTHER)mozilla::AutoProfilerLabel raiiObject108( "AsyncFrameInit::Run"
, nullptr, JS::ProfilingCategoryPair::OTHER)
;
109 if (mFrame.IsAlive()) {
110 static_cast<nsSubDocumentFrame*>(mFrame.GetFrame())->ShowViewer();
111 }
112 return NS_OK;
113 }
114
115 private:
116 WeakFrame mFrame;
117};
118
119void nsSubDocumentFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
120 nsIFrame* aPrevInFlow) {
121 MOZ_ASSERT(aContent)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aContent)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aContent))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aContent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 121); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aContent" ")"
); do { *((volatile int*)__null) = 121; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
122 // determine if we are a <frame> or <iframe>
123 mIsInline = !aContent->IsHTMLElement(nsGkAtoms::frame);
124
125 nsAtomicContainerFrame::Init(aContent, aParent, aPrevInFlow);
126
127 // CreateView() creates this frame's view, stored in mOuterView. It needs to
128 // be created first since it's the parent of the inner view, stored in
129 // mInnerView.
130 CreateView();
131 EnsureInnerView();
132
133 // Set the primary frame now so that nsDocumentViewer::FindContainerView
134 // called from within EndSwapDocShellsForViews below can find it if needed.
135 aContent->SetPrimaryFrame(this);
136
137 // If we have a detached subdoc's root view on our frame loader, re-insert it
138 // into the view tree. This happens when we've been reframed, and ensures the
139 // presentation persists across reframes.
140 if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) {
141 bool hadFrame = false;
142 nsIFrame* detachedFrame = frameloader->GetDetachedSubdocFrame(&hadFrame);
143 frameloader->SetDetachedSubdocFrame(nullptr);
144 nsView* detachedView = detachedFrame ? detachedFrame->GetView() : nullptr;
145 if (detachedView) {
146 // Restore stashed presentation.
147 InsertViewsInReverseOrder(detachedView, mInnerView);
148 EndSwapDocShellsForViews(mInnerView->GetFirstChild());
149 } else if (hadFrame) {
150 // Presentation is for a different document, don't restore it.
151 frameloader->Hide();
152 }
153 }
154
155 // NOTE: The frame loader might not yet be initialized yet. If it's not, the
156 // call in ShowViewer() should pick things up.
157 UpdateEmbeddedBrowsingContextDependentData();
158 nsContentUtils::AddScriptRunner(new AsyncFrameInit(this));
159}
160
161void nsSubDocumentFrame::UpdateEmbeddedBrowsingContextDependentData() {
162 if (!mFrameLoader) {
163 return;
164 }
165 BrowsingContext* bc = mFrameLoader->GetExtantBrowsingContext();
166 if (!bc) {
167 return;
168 }
169 mIsInObjectOrEmbed = bc->IsEmbedderTypeObjectOrEmbed();
170 MaybeUpdateRemoteStyle();
171 MaybeUpdateEmbedderColorScheme();
172 PropagateIsUnderHiddenEmbedderElement(
173 PresShell()->IsUnderHiddenEmbedderElement() ||
174 !StyleVisibility()->IsVisible());
175}
176
177void nsSubDocumentFrame::PropagateIsUnderHiddenEmbedderElement(bool aValue) {
178 ::PropagateIsUnderHiddenEmbedderElement(mFrameLoader, aValue);
179}
180
181void nsSubDocumentFrame::ShowViewer() {
182 if (mCallingShow) {
183 return;
184 }
185
186 RefPtr<nsFrameLoader> frameloader = FrameLoader();
187 if (!frameloader || frameloader->IsDead()) {
188 return;
189 }
190
191 if (!frameloader->IsRemoteFrame() && !PresContext()->IsDynamic()) {
192 // We let the printing code take care of loading the document and
193 // initializing the shell; just create the inner view for it to use.
194 (void)EnsureInnerView();
195 } else {
196 AutoWeakFrame weakThis(this);
197 mCallingShow = true;
198 bool didCreateDoc = frameloader->Show(this);
199 if (!weakThis.IsAlive()) {
200 return;
201 }
202 mCallingShow = false;
203 mDidCreateDoc = didCreateDoc;
204 if (!HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
205 frameloader->UpdatePositionAndSize(this);
206 }
207 if (!weakThis.IsAlive()) {
208 return;
209 }
210 UpdateEmbeddedBrowsingContextDependentData();
211 InvalidateFrame();
212 }
213}
214
215nsIFrame* nsSubDocumentFrame::GetSubdocumentRootFrame() {
216 if (!mInnerView) return nullptr;
217 nsView* subdocView = mInnerView->GetFirstChild();
218 return subdocView ? subdocView->GetFrame() : nullptr;
219}
220
221mozilla::PresShell* nsSubDocumentFrame::GetSubdocumentPresShellForPainting(
222 uint32_t aFlags) {
223 if (!mInnerView) return nullptr;
224
225 nsView* subdocView = mInnerView->GetFirstChild();
226 if (!subdocView) return nullptr;
227
228 mozilla::PresShell* presShell = nullptr;
229
230 nsIFrame* subdocRootFrame = subdocView->GetFrame();
231 if (subdocRootFrame) {
232 presShell = subdocRootFrame->PresShell();
233 }
234
235 // If painting is suppressed in the presshell, we try to look for a better
236 // presshell to use.
237 if (!presShell || (presShell->IsPaintingSuppressed() &&
238 !(aFlags & IGNORE_PAINT_SUPPRESSION))) {
239 // During page transition mInnerView will sometimes have two children, the
240 // first being the new page that may not have any frame, and the second
241 // being the old page that will probably have a frame.
242 nsView* nextView = subdocView->GetNextSibling();
243 nsIFrame* frame = nullptr;
244 if (nextView) {
245 frame = nextView->GetFrame();
246 }
247 if (frame) {
248 mozilla::PresShell* presShellForNextView = frame->PresShell();
249 if (!presShell || (presShellForNextView &&
250 !presShellForNextView->IsPaintingSuppressed() &&
251 StaticPrefs::layout_show_previous_page())) {
252 subdocView = nextView;
253 subdocRootFrame = frame;
Value stored to 'subdocRootFrame' is never read
254 presShell = presShellForNextView;
255 }
256 }
257 if (!presShell) {
258 // If we don't have a frame we use this roundabout way to get the pres
259 // shell.
260 if (!mFrameLoader) return nullptr;
261 nsIDocShell* docShell = mFrameLoader->GetDocShell(IgnoreErrors());
262 if (!docShell) return nullptr;
263 presShell = docShell->GetPresShell();
264 }
265 }
266
267 return presShell;
268}
269
270nsRect nsSubDocumentFrame::GetDestRect() {
271 nsRect rect = GetContent()->IsHTMLElement(nsGkAtoms::frame)
272 ? GetRectRelativeToSelf()
273 : GetContentRectRelativeToSelf();
274 return GetDestRect(rect);
275}
276
277nsRect nsSubDocumentFrame::GetDestRect(const nsRect& aConstraintRect) {
278 // Adjust subdocument size, according to 'object-fit' and the subdocument's
279 // intrinsic size and ratio.
280 return nsLayoutUtils::ComputeObjectDestRect(
281 aConstraintRect, ComputeIntrinsicSize(/* aIgnoreContainment = */ true),
282 GetIntrinsicRatio(), StylePosition());
283}
284
285ScreenIntSize nsSubDocumentFrame::GetSubdocumentSize() {
286 if (HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
287 if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) {
288 nsIFrame* detachedFrame = frameloader->GetDetachedSubdocFrame();
289 if (nsView* view = detachedFrame ? detachedFrame->GetView() : nullptr) {
290 nsSize size = view->GetBounds().Size();
291 nsPresContext* presContext = detachedFrame->PresContext();
292 return ScreenIntSize(presContext->AppUnitsToDevPixels(size.width),
293 presContext->AppUnitsToDevPixels(size.height));
294 }
295 }
296 // Pick some default size for now. Using 10x10 because that's what the
297 // code used to do.
298 return ScreenIntSize(10, 10);
299 }
300
301 nsSize docSizeAppUnits = GetDestRect().Size();
302 nsPresContext* pc = PresContext();
303 return ScreenIntSize(pc->AppUnitsToDevPixels(docSizeAppUnits.width),
304 pc->AppUnitsToDevPixels(docSizeAppUnits.height));
305}
306
307static void WrapBackgroundColorInOwnLayer(nsDisplayListBuilder* aBuilder,
308 nsIFrame* aFrame,
309 nsDisplayList* aList) {
310 for (nsDisplayItem* item : aList->TakeItems()) {
311 if (item->GetType() == DisplayItemType::TYPE_BACKGROUND_COLOR) {
312 nsDisplayList tmpList(aBuilder);
313 tmpList.AppendToTop(item);
314 item = MakeDisplayItemWithIndex<nsDisplayOwnLayer>(
315 aBuilder, aFrame, /* aIndex = */ nsDisplayOwnLayer::OwnLayerForSubdoc,
316 &tmpList, aBuilder->CurrentActiveScrolledRoot(),
317 nsDisplayOwnLayerFlags::None, ScrollbarData{}, true, false);
318 }
319 aList->AppendToTop(item);
320 }
321}
322
323void nsSubDocumentFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
324 const nsDisplayListSet& aLists) {
325 if (!IsVisibleForPainting()) {
326 return;
327 }
328
329 const bool pointerEventsNone =
330 Style()->PointerEvents() == StylePointerEvents::None;
331 if (aBuilder->IsForEventDelivery() && pointerEventsNone) {
332 // If we are pointer-events:none then we don't need to HitTest background or
333 // anything else.
334 return;
335 }
336
337 nsFrameLoader* frameLoader = FrameLoader();
338 const bool isRemoteFrame = frameLoader && frameLoader->IsRemoteFrame();
339
340 nsDisplayListCollection decorations(aBuilder);
341 DisplayBorderBackgroundOutline(aBuilder, decorations);
342 if (isRemoteFrame) {
343 // Wrap background colors of <iframe>s with remote subdocuments in their
344 // own layer so we generate a ColorLayer. This is helpful for optimizing
345 // compositing; we can skip compositing the ColorLayer when the
346 // remote content is opaque.
347 WrapBackgroundColorInOwnLayer(aBuilder, this,
348 decorations.BorderBackground());
349 }
350 decorations.MoveTo(aLists);
351
352 if (HidesContent()) {
353 return;
354 }
355
356 // If we're passing pointer events to children then we have to descend into
357 // subdocuments no matter what, to determine which parts are transparent for
358 // hit-testing or event regions.
359 bool needToDescend = aBuilder->GetDescendIntoSubdocuments();
360 if (!mInnerView || !needToDescend) {
361 return;
362 }
363
364 if (isRemoteFrame) {
365 // We're the subdoc for <browser remote="true"> and it has
366 // painted content. Display its shadow layer tree.
367 DisplayListClipState::AutoSaveRestore clipState(aBuilder);
368 clipState.ClipContainingBlockDescendantsToContentBox(aBuilder, this);
369
370 aLists.Content()->AppendNewToTop<nsDisplayRemote>(aBuilder, this);
371 return;
372 }
373
374 RefPtr<mozilla::PresShell> presShell = GetSubdocumentPresShellForPainting(
375 aBuilder->IsIgnoringPaintSuppression() ? IGNORE_PAINT_SUPPRESSION : 0);
376
377 if (!presShell) {
378 return;
379 }
380
381 if (aBuilder->IsInFilter()) {
382 Document* outerDoc = PresShell()->GetDocument();
383 Document* innerDoc = presShell->GetDocument();
384 if (outerDoc && innerDoc) {
385 if (!outerDoc->NodePrincipal()->Equals(innerDoc->NodePrincipal())) {
386 outerDoc->SetUseCounter(eUseCounter_custom_FilteredCrossOriginIFrame);
387 }
388 }
389 }
390
391 nsIFrame* subdocRootFrame = presShell->GetRootFrame();
392
393 nsPresContext* presContext = presShell->GetPresContext();
394
395 int32_t parentAPD = PresContext()->AppUnitsPerDevPixel();
396 int32_t subdocAPD = presContext->AppUnitsPerDevPixel();
397
398 nsRect visible;
399 nsRect dirty;
400 bool ignoreViewportScrolling = false;
401 if (subdocRootFrame) {
402 // get the dirty rect relative to the root frame of the subdoc
403 visible = aBuilder->GetVisibleRect() + GetOffsetToCrossDoc(subdocRootFrame);
404 dirty = aBuilder->GetDirtyRect() + GetOffsetToCrossDoc(subdocRootFrame);
405 // and convert into the appunits of the subdoc
406 visible = visible.ScaleToOtherAppUnitsRoundOut(parentAPD, subdocAPD);
407 dirty = dirty.ScaleToOtherAppUnitsRoundOut(parentAPD, subdocAPD);
408
409 if (ScrollContainerFrame* sf = presShell->GetRootScrollContainerFrame()) {
410 // Use a copy, so the rects don't get modified.
411 nsRect copyOfDirty = dirty;
412 nsRect copyOfVisible = visible;
413 // TODO(botond): Can we just axe this DecideScrollableLayer call?
414 sf->DecideScrollableLayer(aBuilder, &copyOfVisible, &copyOfDirty,
415 /* aSetBase = */ true);
416
417 ignoreViewportScrolling = presShell->IgnoringViewportScrolling();
418 }
419
420 aBuilder->EnterPresShell(subdocRootFrame, pointerEventsNone);
421 aBuilder->IncrementPresShellPaintCount(presShell);
422 } else {
423 visible = aBuilder->GetVisibleRect();
424 dirty = aBuilder->GetDirtyRect();
425 }
426
427 DisplayListClipState::AutoSaveRestore clipState(aBuilder);
428 clipState.ClipContainingBlockDescendantsToContentBox(aBuilder, this);
429
430 ScrollContainerFrame* sf = presShell->GetRootScrollContainerFrame();
431 bool constructZoomItem = subdocRootFrame && parentAPD != subdocAPD;
432 bool needsOwnLayer = constructZoomItem ||
433 presContext->IsRootContentDocumentCrossProcess() ||
434 (sf && sf->IsScrollingActive());
435
436 nsDisplayList childItems(aBuilder);
437
438 {
439 DisplayListClipState::AutoSaveRestore nestedClipState(aBuilder);
440 if (needsOwnLayer) {
441 // Clear current clip. There's no point in propagating it down, since
442 // the layer we will construct will be clipped by the current clip.
443 // In fact for nsDisplayZoom propagating it down would be incorrect since
444 // nsDisplayZoom changes the meaning of appunits.
445 nestedClipState.Clear();
446 }
447
448 // Invoke AutoBuildingDisplayList to ensure that the correct dirty rect
449 // is used to compute the visible rect if AddCanvasBackgroundColorItem
450 // creates a display item.
451 nsIFrame* frame = subdocRootFrame ? subdocRootFrame : this;
452 nsDisplayListBuilder::AutoBuildingDisplayList building(aBuilder, frame,
453 visible, dirty);
454
455 if (subdocRootFrame) {
456 bool hasDocumentLevelListenersForApzAwareEvents =
457 gfxPlatform::AsyncPanZoomEnabled() &&
458 nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(presShell);
459
460 aBuilder->SetAncestorHasApzAwareEventHandler(
461 hasDocumentLevelListenersForApzAwareEvents);
462 subdocRootFrame->BuildDisplayListForStackingContext(aBuilder,
463 &childItems);
464 if (!aBuilder->IsForEventDelivery()) {
465 // If we are going to use a displayzoom below then any items we put
466 // under it need to have underlying frames from the subdocument. So we
467 // need to calculate the bounds based on which frame will be the
468 // underlying frame for the canvas background color item.
469 nsRect bounds =
470 GetContentRectRelativeToSelf() + aBuilder->ToReferenceFrame(this);
471 bounds = bounds.ScaleToOtherAppUnitsRoundOut(parentAPD, subdocAPD);
472
473 // Add the canvas background color to the bottom of the list. This
474 // happens after we've built the list so that
475 // AddCanvasBackgroundColorItem can monkey with the contents if
476 // necessary.
477 presShell->AddCanvasBackgroundColorItem(aBuilder, &childItems, frame,
478 bounds, NS_RGBA(0, 0, 0, 0)((nscolor)(((0) << 24) | ((0) << 16) | ((0) <<
8) | (0)))
);
479 }
480 }
481 }
482
483 if (subdocRootFrame) {
484 aBuilder->LeavePresShell(subdocRootFrame, &childItems);
485 }
486
487 // Generate a resolution and/or zoom item if needed. If one or both of those
488 // is created, we don't need to create a separate nsDisplaySubDocument.
489
490 nsDisplayOwnLayerFlags flags =
491 nsDisplayOwnLayerFlags::GenerateSubdocInvalidations;
492 // If ignoreViewportScrolling is true then the top most layer we create here
493 // is going to become the scrollable layer for the root scroll frame, so we
494 // want to add nsDisplayOwnLayer::GENERATE_SCROLLABLE_LAYER to whatever layer
495 // becomes the topmost. We do this below.
496 if (constructZoomItem) {
497 nsDisplayOwnLayerFlags zoomFlags = flags;
498 if (ignoreViewportScrolling) {
499 zoomFlags |= nsDisplayOwnLayerFlags::GenerateScrollableLayer;
500 }
501 childItems.AppendNewToTop<nsDisplayZoom>(aBuilder, subdocRootFrame, this,
502 &childItems, subdocAPD, parentAPD,
503 zoomFlags);
504
505 needsOwnLayer = false;
506 }
507 // Wrap the zoom item in the resolution item if we have both because we want
508 // the resolution scale applied on top of the app units per dev pixel
509 // conversion.
510 if (ignoreViewportScrolling) {
511 flags |= nsDisplayOwnLayerFlags::GenerateScrollableLayer;
512 }
513
514 // We always want top level content documents to be in their own layer.
515 nsDisplaySubDocument* layerItem = MakeDisplayItem<nsDisplaySubDocument>(
516 aBuilder, subdocRootFrame ? subdocRootFrame : this, this, &childItems,
517 flags);
518 if (layerItem) {
519 childItems.AppendToTop(layerItem);
520 layerItem->SetShouldFlattenAway(!needsOwnLayer);
521 }
522
523 if (aBuilder->IsForFrameVisibility()) {
524 // We don't add the childItems to the return list as we're dealing with them
525 // here.
526 presShell->RebuildApproximateFrameVisibilityDisplayList(childItems);
527 childItems.DeleteAll(aBuilder);
528 } else {
529 aLists.Content()->AppendToTop(&childItems);
530 }
531}
532
533#ifdef DEBUG_FRAME_DUMP1
534void nsSubDocumentFrame::List(FILE* out, const char* aPrefix,
535 ListFlags aFlags) const {
536 nsCString str;
537 ListGeneric(str, aPrefix, aFlags);
538 fprintf_stderr(out, "%s\n", str.get());
539
540 if (aFlags.contains(ListFlag::TraverseSubdocumentFrames)) {
541 nsSubDocumentFrame* f = const_cast<nsSubDocumentFrame*>(this);
542 nsIFrame* subdocRootFrame = f->GetSubdocumentRootFrame();
543 if (subdocRootFrame) {
544 nsCString pfx(aPrefix);
545 pfx += " ";
546 subdocRootFrame->List(out, pfx.get(), aFlags);
547 }
548 }
549}
550
551nsresult nsSubDocumentFrame::GetFrameName(nsAString& aResult) const {
552 return MakeFrameName(u"FrameOuter"_ns, aResult);
553}
554#endif
555
556nscoord nsSubDocumentFrame::IntrinsicISize(gfxContext* aContext,
557 IntrinsicISizeType aType) {
558 // Note: when computing max-content inline size (i.e. when aType is
559 // IntrinsicISizeType::PrefISize), if the subdocument is an SVG document, then
560 // in theory we want to return the same value that SVGOuterSVGFrame does. That
561 // method has some special handling of percentage values to avoid unhelpful
562 // zero sizing in the presence of orthogonal writing modes. We don't bother
563 // with that for SVG documents in <embed> and <object>, since that special
564 // handling doesn't look up across document boundaries anyway.
565 return GetIntrinsicISize();
566}
567
568/* virtual */
569IntrinsicSize nsSubDocumentFrame::GetIntrinsicSize() {
570 return ComputeIntrinsicSize();
571}
572
573IntrinsicSize nsSubDocumentFrame::ComputeIntrinsicSize(
574 bool aIgnoreContainment) const {
575 const auto containAxes =
576 aIgnoreContainment ? ContainSizeAxes(false, false) : GetContainSizeAxes();
577 if (containAxes.IsBoth()) {
578 // Intrinsic size of 'contain:size' replaced elements is determined by
579 // contain-intrinsic-size.
580 return FinishIntrinsicSize(containAxes, IntrinsicSize(0, 0));
581 }
582
583 if (nsCOMPtr<nsIObjectLoadingContent> iolc = do_QueryInterface(mContent)) {
584 const auto* olc = static_cast<nsObjectLoadingContent*>(iolc.get());
585 if (auto size = olc->GetSubdocumentIntrinsicSize()) {
586 // Use the intrinsic size from the child SVG document, if available.
587 return FinishIntrinsicSize(containAxes, *size);
588 }
589 }
590
591 if (!IsInline()) {
592 return {}; // <frame> elements have no useful intrinsic size.
593 }
594
595 if (mContent->IsXULElement()) {
596 return {}; // XUL <iframe> and <browser> have no useful intrinsic size
597 }
598
599 // We must be an HTML <iframe>. Return fallback size.
600 return FinishIntrinsicSize(containAxes,
601 IntrinsicSize(kFallbackIntrinsicSize));
602}
603
604/* virtual */
605AspectRatio nsSubDocumentFrame::GetIntrinsicRatio() const {
606 // FIXME(emilio): This should probably respect contain: size and return no
607 // ratio in the case subDocRoot is non-null. Otherwise we do it by virtue of
608 // using a zero-size below and reusing GetIntrinsicSize().
609 if (nsCOMPtr<nsIObjectLoadingContent> iolc = do_QueryInterface(mContent)) {
610 auto olc = static_cast<nsObjectLoadingContent*>(iolc.get());
611
612 auto ratio = olc->GetSubdocumentIntrinsicRatio();
613 if (ratio && *ratio) {
614 // Use the intrinsic aspect ratio from the child SVG document, if
615 // available.
616 return *ratio;
617 }
618 }
619
620 // NOTE(emilio): Even though we have an intrinsic size, we may not have an
621 // intrinsic ratio. For example `<iframe style="width: 100px">` should not
622 // shrink in the vertical axis to preserve the 300x150 ratio.
623 return nsAtomicContainerFrame::GetIntrinsicRatio();
624}
625
626/* virtual */
627LogicalSize nsSubDocumentFrame::ComputeAutoSize(
628 gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
629 nscoord aAvailableISize, const LogicalSize& aMargin,
630 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
631 ComputeSizeFlags aFlags) {
632 if (!IsInline()) {
633 return nsIFrame::ComputeAutoSize(aRenderingContext, aWM, aCBSize,
634 aAvailableISize, aMargin, aBorderPadding,
635 aSizeOverrides, aFlags);
636 }
637
638 const WritingMode wm = GetWritingMode();
639 LogicalSize result(wm, GetIntrinsicISize(), GetIntrinsicBSize());
640 return result.ConvertTo(aWM, wm);
641}
642
643/* virtual */
644nsIFrame::SizeComputationResult nsSubDocumentFrame::ComputeSize(
645 gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
646 nscoord aAvailableISize, const LogicalSize& aMargin,
647 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
648 ComputeSizeFlags aFlags) {
649 return {ComputeSizeWithIntrinsicDimensions(
650 aRenderingContext, aWM, GetIntrinsicSize(), GetAspectRatio(),
651 aCBSize, aMargin, aBorderPadding, aSizeOverrides, aFlags),
652 AspectRatioUsage::None};
653}
654
655void nsSubDocumentFrame::Reflow(nsPresContext* aPresContext,
656 ReflowOutput& aDesiredSize,
657 const ReflowInput& aReflowInput,
658 nsReflowStatus& aStatus) {
659 MarkInReflow();
660 DO_GLOBAL_REFLOW_COUNT("nsSubDocumentFrame")aPresContext->CountReflows(("nsSubDocumentFrame"), (nsIFrame
*)this);
;
661 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aStatus.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aStatus.IsEmpty()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aStatus.IsEmpty()"
" (" "Caller should pass a fresh reflow status!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 661); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatus.IsEmpty()"
") (" "Caller should pass a fresh reflow status!" ")"); do {
*((volatile int*)__null) = 661; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
662 NS_FRAME_TRACE(do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d"
, aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight
()); } } while (0)
663 NS_FRAME_TRACE_CALLS,do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d"
, aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight
()); } } while (0)
664 ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d",do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d"
, aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight
()); } } while (0)
665 aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d"
, aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight
()); } } while (0)
;
666
667 NS_ASSERTION(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE,do { if (!(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained inline-size here "
"thanks to the rules of reflow", "aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 669); MOZ_PretendNoReturn(); } } while (0)
668 "Shouldn't have unconstrained inline-size here "do { if (!(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained inline-size here "
"thanks to the rules of reflow", "aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 669); MOZ_PretendNoReturn(); } } while (0)
669 "thanks to the rules of reflow")do { if (!(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained inline-size here "
"thanks to the rules of reflow", "aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 669); MOZ_PretendNoReturn(); } } while (0)
;
670 NS_ASSERTION(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE,do { if (!(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained block-size here "
"thanks to ComputeAutoSize", "aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 672); MOZ_PretendNoReturn(); } } while (0)
671 "Shouldn't have unconstrained block-size here "do { if (!(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained block-size here "
"thanks to ComputeAutoSize", "aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 672); MOZ_PretendNoReturn(); } } while (0)
672 "thanks to ComputeAutoSize")do { if (!(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained block-size here "
"thanks to ComputeAutoSize", "aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 672); MOZ_PretendNoReturn(); } } while (0)
;
673
674 NS_ASSERTION(mContent->GetPrimaryFrame() == this, "Shouldn't happen")do { if (!(mContent->GetPrimaryFrame() == this)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Shouldn't happen", "mContent->GetPrimaryFrame() == this"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 674); MOZ_PretendNoReturn(); } } while (0)
;
675
676 // XUL <iframe> or <browser>, or HTML <iframe>, <object> or <embed>
677 const auto wm = aReflowInput.GetWritingMode();
678 aDesiredSize.SetSize(wm, aReflowInput.ComputedSizeWithBorderPadding(wm));
679
680 // "offset" is the offset of our content area from our frame's
681 // top-left corner.
682 nsPoint offset = nsPoint(aReflowInput.ComputedPhysicalBorderPadding().left,
683 aReflowInput.ComputedPhysicalBorderPadding().top);
684
685 if (mInnerView) {
686 const nsMargin& bp = aReflowInput.ComputedPhysicalBorderPadding();
687 nsSize innerSize(aDesiredSize.Width() - bp.LeftRight(),
688 aDesiredSize.Height() - bp.TopBottom());
689
690 // Size & position the view according to 'object-fit' & 'object-position'.
691 nsRect destRect = GetDestRect(nsRect(offset, innerSize));
692 nsViewManager* vm = mInnerView->GetViewManager();
693 vm->MoveViewTo(mInnerView, destRect.x, destRect.y);
694 vm->ResizeView(mInnerView, nsRect(nsPoint(0, 0), destRect.Size()));
695 }
696
697 aDesiredSize.SetOverflowAreasToDesiredBounds();
698
699 FinishAndStoreOverflow(&aDesiredSize);
700
701 if (!aPresContext->IsRootPaginatedDocument() && !mPostedReflowCallback) {
702 PresShell()->PostReflowCallback(this);
703 mPostedReflowCallback = true;
704 }
705
706 NS_FRAME_TRACE(do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s"
, aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus
).c_str()); } } while (0)
707 NS_FRAME_TRACE_CALLS,do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s"
, aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus
).c_str()); } } while (0)
708 ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s",do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s"
, aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus
).c_str()); } } while (0)
709 aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus).c_str()))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s"
, aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus
).c_str()); } } while (0)
;
710}
711
712bool nsSubDocumentFrame::ReflowFinished() {
713 RefPtr<nsFrameLoader> frameloader = FrameLoader();
714 if (frameloader) {
715 AutoWeakFrame weakFrame(this);
716
717 frameloader->UpdatePositionAndSize(this);
718
719 if (weakFrame.IsAlive()) {
720 // Make sure that we can post a reflow callback in the future.
721 mPostedReflowCallback = false;
722 }
723 } else {
724 mPostedReflowCallback = false;
725 }
726 return false;
727}
728
729void nsSubDocumentFrame::ReflowCallbackCanceled() {
730 mPostedReflowCallback = false;
731}
732
733nsresult nsSubDocumentFrame::AttributeChanged(int32_t aNameSpaceID,
734 nsAtom* aAttribute,
735 int32_t aModType) {
736 if (aNameSpaceID != kNameSpaceID_None) {
737 return NS_OK;
738 }
739
740 // If the noResize attribute changes, dis/allow frame to be resized
741 if (aAttribute == nsGkAtoms::noresize) {
742 // Note that we're not doing content type checks, but that's ok -- if
743 // they'd fail we will just end up with a null framesetFrame.
744 if (mContent->GetParent()->IsHTMLElement(nsGkAtoms::frameset)) {
745 nsIFrame* parentFrame = GetParent();
746
747 if (parentFrame) {
748 // There is no interface for nsHTMLFramesetFrame so QI'ing to
749 // concrete class, yay!
750 nsHTMLFramesetFrame* framesetFrame = do_QueryFrame(parentFrame);
751 if (framesetFrame) {
752 framesetFrame->RecalculateBorderResize();
753 }
754 }
755 }
756 } else if (aAttribute == nsGkAtoms::marginwidth ||
757 aAttribute == nsGkAtoms::marginheight) {
758 // Notify the frameloader
759 if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) {
760 frameloader->MarginsChanged();
761 }
762 }
763
764 return NS_OK;
765}
766
767void nsSubDocumentFrame::MaybeUpdateEmbedderColorScheme() {
768 nsFrameLoader* fl = mFrameLoader.get();
769 if (!fl) {
770 return;
771 }
772
773 BrowsingContext* bc = fl->GetExtantBrowsingContext();
774 if (!bc) {
775 return;
776 }
777
778 auto ToOverride = [](ColorScheme aScheme) -> PrefersColorSchemeOverride {
779 return aScheme == ColorScheme::Dark ? PrefersColorSchemeOverride::Dark
780 : PrefersColorSchemeOverride::Light;
781 };
782
783 EmbedderColorSchemes schemes{
784 ToOverride(LookAndFeel::ColorSchemeForFrame(this, ColorSchemeMode::Used)),
785 ToOverride(
786 LookAndFeel::ColorSchemeForFrame(this, ColorSchemeMode::Preferred))};
787 if (bc->GetEmbedderColorSchemes() == schemes) {
788 return;
789 }
790
791 Unused << bc->SetEmbedderColorSchemes(schemes);
792}
793
794void nsSubDocumentFrame::MaybeUpdateRemoteStyle(
795 ComputedStyle* aOldComputedStyle) {
796 if (!mIsInObjectOrEmbed) {
797 return;
798 }
799
800 if (aOldComputedStyle &&
801 aOldComputedStyle->StyleVisibility()->mImageRendering ==
802 Style()->StyleVisibility()->mImageRendering) {
803 return;
804 }
805
806 if (!mFrameLoader) {
807 return;
808 }
809
810 if (mFrameLoader->IsRemoteFrame()) {
811 mFrameLoader->UpdateRemoteStyle(
812 Style()->StyleVisibility()->mImageRendering);
813 return;
814 }
815
816 BrowsingContext* context = mFrameLoader->GetExtantBrowsingContext();
817 if (!context) {
818 return;
819 }
820
821 Document* document = context->GetDocument();
822 if (!document) {
823 return;
824 }
825
826 if (document->IsImageDocument()) {
827 document->AsImageDocument()->UpdateRemoteStyle(
828 Style()->StyleVisibility()->mImageRendering);
829 }
830}
831
832void nsSubDocumentFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
833 nsAtomicContainerFrame::DidSetComputedStyle(aOldComputedStyle);
834
835 MaybeUpdateEmbedderColorScheme();
836
837 MaybeUpdateRemoteStyle(aOldComputedStyle);
838
839 // If this presshell has invisible ancestors, we don't need to propagate the
840 // visibility style change to the subdocument since the subdocument should
841 // have already set the IsUnderHiddenEmbedderElement flag in
842 // nsSubDocumentFrame::Init.
843 if (PresShell()->IsUnderHiddenEmbedderElement()) {
844 return;
845 }
846
847 const bool isVisible = StyleVisibility()->IsVisible();
848 if (!aOldComputedStyle ||
849 isVisible != aOldComputedStyle->StyleVisibility()->IsVisible()) {
850 PropagateIsUnderHiddenEmbedderElement(!isVisible);
851 }
852}
853
854nsIFrame* NS_NewSubDocumentFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
855 return new (aPresShell)
856 nsSubDocumentFrame(aStyle, aPresShell->GetPresContext());
857}
858
859NS_IMPL_FRAMEARENA_HELPERS(nsSubDocumentFrame)void* nsSubDocumentFrame ::operator new(size_t sz, mozilla::PresShell
* aShell) { return aShell->AllocateFrame(nsQueryFrame::nsSubDocumentFrame_id
, sz); }
860
861class nsHideViewer final : public Runnable {
862 public:
863 nsHideViewer(nsIContent* aFrameElement, nsFrameLoader* aFrameLoader,
864 PresShell* aPresShell, bool aHideViewerIfFrameless)
865 : mozilla::Runnable("nsHideViewer"),
866 mFrameElement(aFrameElement),
867 mFrameLoader(aFrameLoader),
868 mPresShell(aPresShell),
869 mHideViewerIfFrameless(aHideViewerIfFrameless) {
870 NS_ASSERTION(mFrameElement, "Must have a frame element")do { if (!(mFrameElement)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "Must have a frame element", "mFrameElement", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 870); MOZ_PretendNoReturn(); } } while (0)
;
871 NS_ASSERTION(mFrameLoader, "Must have a frame loader")do { if (!(mFrameLoader)) { NS_DebugBreak(NS_DEBUG_ASSERTION,
"Must have a frame loader", "mFrameLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 871); MOZ_PretendNoReturn(); } } while (0)
;
872 NS_ASSERTION(mPresShell, "Must have a presshell")do { if (!(mPresShell)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have a presshell"
, "mPresShell", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 872); MOZ_PretendNoReturn(); } } while (0)
;
873 }
874
875 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODvirtual nsresult Run() override {
876 // Flush frames, to ensure any pending display:none changes are made.
877 // Note it can be unsafe to flush if we've destroyed the presentation
878 // for some other reason, like if we're shutting down.
879 //
880 // But avoid the flush if we know for sure we're away, like when we're out
881 // of the document already.
882 //
883 // FIXME(emilio): This could still be a perf footgun when removing lots of
884 // siblings where each of them cause the reframe of an ancestor which happen
885 // to contain a subdocument.
886 //
887 // We should find some way to avoid that!
888 if (!mPresShell->IsDestroying() && mFrameElement->IsInComposedDoc()) {
889 mPresShell->FlushPendingNotifications(FlushType::Frames);
890 }
891
892 // Either the frame has been constructed by now, or it never will be,
893 // either way we want to clear the stashed views.
894 mFrameLoader->SetDetachedSubdocFrame(nullptr);
895
896 nsSubDocumentFrame* frame = do_QueryFrame(mFrameElement->GetPrimaryFrame());
897 if (!frame || frame->FrameLoader() != mFrameLoader) {
898 PropagateIsUnderHiddenEmbedderElement(mFrameLoader, true);
899 if (mHideViewerIfFrameless) {
900 // The frame element has no nsIFrame for the same frame loader.
901 // Hide the nsFrameLoader, which destroys the presentation.
902 mFrameLoader->Hide();
903 }
904 }
905 return NS_OK;
906 }
907
908 private:
909 const nsCOMPtr<nsIContent> mFrameElement;
910 const RefPtr<nsFrameLoader> mFrameLoader;
911 const RefPtr<PresShell> mPresShell;
912 const bool mHideViewerIfFrameless;
913};
914
915static nsView* BeginSwapDocShellsForViews(nsView* aSibling);
916
917void nsSubDocumentFrame::Destroy(DestroyContext& aContext) {
918 if (mPostedReflowCallback) {
919 PresShell()->CancelReflowCallback(this);
920 mPostedReflowCallback = false;
921 }
922
923 // Detach the subdocument's views and stash them in the frame loader.
924 // We can then reattach them if we're being reframed (for example if
925 // the frame has been made position:fixed).
926 if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) {
927 ClearDisplayItems();
928
929 nsView* detachedViews =
930 ::BeginSwapDocShellsForViews(mInnerView->GetFirstChild());
931
932 frameloader->SetDetachedSubdocFrame(
933 detachedViews ? detachedViews->GetFrame() : nullptr);
934
935 // We call nsFrameLoader::HideViewer() in a script runner so that we can
936 // safely determine whether the frame is being reframed or destroyed.
937 nsContentUtils::AddScriptRunner(new nsHideViewer(
938 mContent, frameloader, PresShell(), (mDidCreateDoc || mCallingShow)));
939 }
940
941 nsAtomicContainerFrame::Destroy(aContext);
942}
943
944nsFrameLoader* nsSubDocumentFrame::FrameLoader() const {
945 if (mFrameLoader) {
946 return mFrameLoader;
947 }
948
949 if (RefPtr<nsFrameLoaderOwner> loaderOwner = do_QueryObject(GetContent())) {
950 mFrameLoader = loaderOwner->GetFrameLoader();
951 }
952
953 return mFrameLoader;
954}
955
956auto nsSubDocumentFrame::GetRemotePaintData() const -> RemoteFramePaintData {
957 if (mRetainedRemoteFrame) {
958 return *mRetainedRemoteFrame;
959 }
960
961 RemoteFramePaintData data;
962 nsFrameLoader* fl = FrameLoader();
963 if (!fl) {
964 return data;
965 }
966
967 auto* rb = fl->GetRemoteBrowser();
968 if (!rb) {
969 return data;
970 }
971 data.mLayersId = rb->GetLayersId();
972 data.mTabId = rb->GetTabId();
973 return data;
974}
975
976void nsSubDocumentFrame::ResetFrameLoader(RetainPaintData aRetain) {
977 if (aRetain == RetainPaintData::Yes && mFrameLoader) {
978 mRetainedRemoteFrame = Some(GetRemotePaintData());
979 } else {
980 mRetainedRemoteFrame.reset();
981 }
982 mFrameLoader = nullptr;
983 ClearDisplayItems();
984 nsContentUtils::AddScriptRunner(new AsyncFrameInit(this));
985}
986
987void nsSubDocumentFrame::ClearRetainedPaintData() {
988 mRetainedRemoteFrame.reset();
989 ClearDisplayItems();
990 InvalidateFrameSubtree();
991}
992
993// XXX this should be called ObtainDocShell or something like that,
994// to indicate that it could have side effects
995nsIDocShell* nsSubDocumentFrame::GetDocShell() const {
996 // How can FrameLoader() return null???
997 if (NS_WARN_IF(!FrameLoader())NS_warn_if_impl(!FrameLoader(), "!FrameLoader()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 997)
) {
998 return nullptr;
999 }
1000 return mFrameLoader->GetDocShell(IgnoreErrors());
1001}
1002
1003static void DestroyDisplayItemDataForFrames(nsIFrame* aFrame) {
1004 // Destroying a WebRenderUserDataTable can cause destruction of other objects
1005 // which can remove frame properties in their destructor. If we delete a frame
1006 // property it runs the destructor of the stored object in the middle of
1007 // updating the frame property table, so if the destruction of that object
1008 // causes another update to the frame property table it would leave the frame
1009 // property table in an inconsistent state. So we remove it from the table and
1010 // then destroy it. (bug 1530657)
1011 WebRenderUserDataTable* userDataTable =
1012 aFrame->TakeProperty(WebRenderUserDataProperty::Key());
1013 if (userDataTable) {
1014 for (const auto& data : userDataTable->Values()) {
1015 data->RemoveFromTable();
1016 }
1017 delete userDataTable;
1018 }
1019
1020 for (const auto& childList : aFrame->ChildLists()) {
1021 for (nsIFrame* child : childList.mList) {
1022 DestroyDisplayItemDataForFrames(child);
1023 }
1024 }
1025}
1026
1027static CallState BeginSwapDocShellsForDocument(Document& aDocument) {
1028 if (PresShell* presShell = aDocument.GetPresShell()) {
1029 // Disable painting while the views are detached, see bug 946929.
1030 presShell->SetNeverPainting(true);
1031
1032 if (nsIFrame* rootFrame = presShell->GetRootFrame()) {
1033 ::DestroyDisplayItemDataForFrames(rootFrame);
1034 }
1035 }
1036 aDocument.EnumerateSubDocuments(BeginSwapDocShellsForDocument);
1037 return CallState::Continue;
1038}
1039
1040static nsView* BeginSwapDocShellsForViews(nsView* aSibling) {
1041 // Collect the removed sibling views in reverse order in 'removedViews'.
1042 nsView* removedViews = nullptr;
1043 while (aSibling) {
1044 if (Document* doc = ::GetDocumentFromView(aSibling)) {
1045 ::BeginSwapDocShellsForDocument(*doc);
1046 }
1047 nsView* next = aSibling->GetNextSibling();
1048 aSibling->GetViewManager()->RemoveChild(aSibling);
1049 aSibling->SetNextSibling(removedViews);
1050 removedViews = aSibling;
1051 aSibling = next;
1052 }
1053 return removedViews;
1054}
1055
1056/* static */
1057void nsSubDocumentFrame::InsertViewsInReverseOrder(nsView* aSibling,
1058 nsView* aParent) {
1059 MOZ_ASSERT(aParent, "null view")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aParent)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aParent" " (" "null view"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 1059); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent" ") ("
"null view" ")"); do { *((volatile int*)__null) = 1059; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
1060 MOZ_ASSERT(!aParent->GetFirstChild(), "inserting into non-empty list")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aParent->GetFirstChild())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aParent->GetFirstChild()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"!aParent->GetFirstChild()" " (" "inserting into non-empty list"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 1060); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aParent->GetFirstChild()"
") (" "inserting into non-empty list" ")"); do { *((volatile
int*)__null) = 1060; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1061
1062 nsViewManager* vm = aParent->GetViewManager();
1063 while (aSibling) {
1064 nsView* next = aSibling->GetNextSibling();
1065 aSibling->SetNextSibling(nullptr);
1066 // true means 'after' in document order which is 'before' in view order,
1067 // so this call prepends the child, thus reversing the siblings as we go.
1068 vm->InsertChild(aParent, aSibling, nullptr, true);
1069 aSibling = next;
1070 }
1071}
1072
1073nsresult nsSubDocumentFrame::BeginSwapDocShells(nsIFrame* aOther) {
1074 if (!aOther || !aOther->IsSubDocumentFrame()) {
1075 return NS_ERROR_NOT_IMPLEMENTED;
1076 }
1077
1078 nsSubDocumentFrame* other = static_cast<nsSubDocumentFrame*>(aOther);
1079 if (!mFrameLoader || !mDidCreateDoc || mCallingShow || !other->mFrameLoader ||
1080 !other->mDidCreateDoc) {
1081 return NS_ERROR_NOT_IMPLEMENTED;
1082 }
1083
1084 ClearDisplayItems();
1085 other->ClearDisplayItems();
1086
1087 if (mInnerView && other->mInnerView) {
1088 nsView* ourSubdocViews = mInnerView->GetFirstChild();
1089 nsView* ourRemovedViews = ::BeginSwapDocShellsForViews(ourSubdocViews);
1090 nsView* otherSubdocViews = other->mInnerView->GetFirstChild();
1091 nsView* otherRemovedViews = ::BeginSwapDocShellsForViews(otherSubdocViews);
1092
1093 InsertViewsInReverseOrder(ourRemovedViews, other->mInnerView);
1094 InsertViewsInReverseOrder(otherRemovedViews, mInnerView);
1095 }
1096 mFrameLoader.swap(other->mFrameLoader);
1097 return NS_OK;
1098}
1099
1100static CallState EndSwapDocShellsForDocument(Document& aDocument) {
1101 // Our docshell and view trees have been updated for the new hierarchy.
1102 // Now also update all nsDeviceContext::mWidget to that of the
1103 // container view in the new hierarchy.
1104 if (nsCOMPtr<nsIDocShell> ds = aDocument.GetDocShell()) {
1105 nsCOMPtr<nsIDocumentViewer> viewer;
1106 ds->GetDocViewer(getter_AddRefs(viewer));
1107 while (viewer) {
1108 RefPtr<nsPresContext> pc = viewer->GetPresContext();
1109 if (pc && pc->GetPresShell()) {
1110 pc->GetPresShell()->SetNeverPainting(ds->IsInvisible());
1111 }
1112 nsDeviceContext* dc = pc ? pc->DeviceContext() : nullptr;
1113 if (dc) {
1114 nsView* v = viewer->FindContainerView();
1115 dc->Init(v ? v->GetNearestWidget(nullptr) : nullptr);
1116 }
1117 viewer = viewer->GetPreviousViewer();
1118 }
1119 }
1120
1121 aDocument.EnumerateSubDocuments(EndSwapDocShellsForDocument);
1122 return CallState::Continue;
1123}
1124
1125/* static */
1126void nsSubDocumentFrame::EndSwapDocShellsForViews(nsView* aSibling) {
1127 for (; aSibling; aSibling = aSibling->GetNextSibling()) {
1128 if (Document* doc = ::GetDocumentFromView(aSibling)) {
1129 ::EndSwapDocShellsForDocument(*doc);
1130 }
1131 nsIFrame* frame = aSibling->GetFrame();
1132 if (frame) {
1133 nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(frame);
1134 if (parent->HasAnyStateBits(NS_FRAME_IN_POPUP)) {
1135 nsIFrame::AddInPopupStateBitToDescendants(frame);
1136 } else {
1137 nsIFrame::RemoveInPopupStateBitFromDescendants(frame);
1138 }
1139 if (frame->HasInvalidFrameInSubtree()) {
1140 while (parent &&
1141 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT |
1142 NS_FRAME_IS_NONDISPLAY)) {
1143 parent->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
1144 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent);
1145 }
1146 }
1147 }
1148 }
1149}
1150
1151void nsSubDocumentFrame::EndSwapDocShells(nsIFrame* aOther) {
1152 nsSubDocumentFrame* other = static_cast<nsSubDocumentFrame*>(aOther);
1153 AutoWeakFrame weakThis(this);
1154 AutoWeakFrame weakOther(aOther);
1155
1156 if (mInnerView) {
1157 EndSwapDocShellsForViews(mInnerView->GetFirstChild());
1158 }
1159 if (other->mInnerView) {
1160 EndSwapDocShellsForViews(other->mInnerView->GetFirstChild());
1161 }
1162
1163 // Now make sure we reflow both frames, in case their contents
1164 // determine their size.
1165 // And repaint them, for good measure, in case there's nothing
1166 // interesting that happens during reflow.
1167 if (weakThis.IsAlive()) {
1168 PresShell()->FrameNeedsReflow(this, IntrinsicDirty::FrameAndAncestors,
1169 NS_FRAME_IS_DIRTY);
1170 InvalidateFrameSubtree();
1171 PropagateIsUnderHiddenEmbedderElement(
1172 PresShell()->IsUnderHiddenEmbedderElement() ||
1173 !StyleVisibility()->IsVisible());
1174 }
1175 if (weakOther.IsAlive()) {
1176 other->PresShell()->FrameNeedsReflow(
1177 other, IntrinsicDirty::FrameAndAncestors, NS_FRAME_IS_DIRTY);
1178 other->InvalidateFrameSubtree();
1179 other->PropagateIsUnderHiddenEmbedderElement(
1180 other->PresShell()->IsUnderHiddenEmbedderElement() ||
1181 !other->StyleVisibility()->IsVisible());
1182 }
1183}
1184
1185void nsSubDocumentFrame::ClearDisplayItems() {
1186 if (auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this)) {
1187 DL_LOGD("nsSubDocumentFrame::ClearDisplayItems() %p", this)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Debug, "nsSubDocumentFrame::ClearDisplayItems() %p"
, this); } } while (0)
;
1188 builder->ClearRetainedData();
1189 }
1190}
1191
1192nsView* nsSubDocumentFrame::EnsureInnerView() {
1193 if (mInnerView) {
1194 return mInnerView;
1195 }
1196
1197 // create, init, set the parent of the view
1198 nsView* outerView = GetView();
1199 NS_ASSERTION(outerView, "Must have an outer view already")do { if (!(outerView)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have an outer view already"
, "outerView", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 1199); MOZ_PretendNoReturn(); } } while (0)
;
1200 nsRect viewBounds(0, 0, 0, 0); // size will be fixed during reflow
1201
1202 nsViewManager* viewMan = outerView->GetViewManager();
1203 nsView* innerView = viewMan->CreateView(viewBounds, outerView);
1204 if (!innerView) {
1205 NS_ERROR("Could not create inner view")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Could not create inner view"
, "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 1205); MOZ_PretendNoReturn(); } while (0)
;
1206 return nullptr;
1207 }
1208 mInnerView = innerView;
1209 viewMan->InsertChild(outerView, innerView, nullptr, true);
1210
1211 return mInnerView;
1212}
1213
1214nsPoint nsSubDocumentFrame::GetExtraOffset() const {
1215 MOZ_ASSERT(mInnerView)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mInnerView)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mInnerView))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("mInnerView", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 1215); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mInnerView"
")"); do { *((volatile int*)__null) = 1215; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1216 return mInnerView->GetPosition();
1217}
1218
1219void nsSubDocumentFrame::SubdocumentIntrinsicSizeOrRatioChanged() {
1220 const nsStylePosition* pos = StylePosition();
1221 bool dependsOnIntrinsics =
1222 !pos->mWidth.ConvertsToLength() || !pos->mHeight.ConvertsToLength();
1223
1224 if (dependsOnIntrinsics || pos->mObjectFit != StyleObjectFit::Fill) {
1225 auto dirtyHint = dependsOnIntrinsics
1226 ? IntrinsicDirty::FrameAncestorsAndDescendants
1227 : IntrinsicDirty::None;
1228 PresShell()->FrameNeedsReflow(this, dirtyHint, NS_FRAME_IS_DIRTY);
1229 InvalidateFrame();
1230 }
1231}
1232
1233// Return true iff |aManager| is a "temporary layer manager". They're
1234// used for small software rendering tasks, like drawWindow. That's
1235// currently implemented by a BasicLayerManager without a backing
1236// widget, and hence in non-retained mode.
1237nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder,
1238 nsSubDocumentFrame* aFrame)
1239 : nsPaintedDisplayItem(aBuilder, aFrame),
1240 mEventRegionsOverride(EventRegionsOverride::NoOverride) {
1241 const bool frameIsPointerEventsNone =
1242 aFrame->Style()->PointerEvents() == StylePointerEvents::None;
1243 if (aBuilder->IsInsidePointerEventsNoneDoc() || frameIsPointerEventsNone) {
1244 mEventRegionsOverride |= EventRegionsOverride::ForceEmptyHitRegion;
1245 }
1246 if (nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(
1247 aFrame->PresShell())) {
1248 mEventRegionsOverride |= EventRegionsOverride::ForceDispatchToContent;
1249 }
1250
1251 mPaintData = aFrame->GetRemotePaintData();
1252}
1253
1254namespace mozilla {
1255
1256void nsDisplayRemote::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) {
1257 nsPresContext* pc = mFrame->PresContext();
1258 nsFrameLoader* fl = GetFrameLoader();
1259 if (pc->GetPrintSettings() && fl->IsRemoteFrame()) {
1260 // See the comment below in CreateWebRenderCommands() as for why doing this.
1261 fl->UpdatePositionAndSize(static_cast<nsSubDocumentFrame*>(mFrame));
1262 }
1263
1264 DrawTarget* target = aCtx->GetDrawTarget();
1265 if (!target->IsRecording() || mPaintData.mTabId == 0) {
1266 NS_WARNING("Remote iframe not rendered")NS_DebugBreak(NS_DEBUG_WARNING, "Remote iframe not rendered",
nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp"
, 1266)
;
1267 return;
1268 }
1269
1270 // Rendering the inner document will apply a scale to account for its app
1271 // units per dev pixel ratio. We want to apply the inverse scaling using our
1272 // app units per dev pixel ratio, so that no actual scaling will be applied if
1273 // they match. For in-process rendering, nsSubDocumentFrame creates an
1274 // nsDisplayZoom item if the app units per dev pixel ratio changes.
1275 //
1276 // Similarly, rendering the inner document will scale up by the cross process
1277 // paint scale again, so we also need to account for that.
1278 const int32_t appUnitsPerDevPixel = pc->AppUnitsPerDevPixel();
1279
1280 gfxContextMatrixAutoSaveRestore saveMatrix(aCtx);
1281 gfxFloat targetAuPerDev =
1282 gfxFloat(AppUnitsPerCSSPixel()) / aCtx->GetCrossProcessPaintScale();
1283
1284 gfxFloat scale = targetAuPerDev / appUnitsPerDevPixel;
1285 aCtx->Multiply(gfxMatrix::Scaling(scale, scale));
1286
1287 Rect destRect =
1288 NSRectToSnappedRect(GetContentRect(), targetAuPerDev, *target);
1289 target->DrawDependentSurface(mPaintData.mTabId, destRect);
1290}
1291
1292bool nsDisplayRemote::CreateWebRenderCommands(
1293 mozilla::wr::DisplayListBuilder& aBuilder,
1294 mozilla::wr::IpcResourceUpdateQueue& aResources,
1295 const StackingContextHelper& aSc,
1296 mozilla::layers::RenderRootStateManager* aManager,
1297 nsDisplayListBuilder* aDisplayListBuilder) {
1298 if (!mPaintData.mLayersId.IsValid()) {
1299 return true;
1300 }
1301
1302 nsPresContext* pc = mFrame->PresContext();
1303 nsFrameLoader* fl = GetFrameLoader();
1304
1305 auto* subDocFrame = static_cast<nsSubDocumentFrame*>(mFrame);
1306 nsRect destRect = subDocFrame->GetDestRect();
1307 if (RefPtr<RemoteBrowser> remoteBrowser = fl->GetRemoteBrowser()) {
1308 if (pc->GetPrintSettings()) {
1309 // HACK(emilio): Usually we update sizing/positioning from
1310 // ReflowFinished(). Print documents have no incremental reflow at all
1311 // though, so we can't rely on it firing after a frame becomes remote.
1312 // Thus, if we're painting a remote frame, update its sizing and position
1313 // now.
1314 //
1315 // UpdatePositionAndSize() can cause havoc for non-remote frames but
1316 // luckily we don't care about those, so this is fine.
1317 fl->UpdatePositionAndSize(subDocFrame);
1318 }
1319
1320 // Adjust mItemVisibleRect, which is relative to the reference frame, to be
1321 // relative to this frame.
1322 const nsRect buildingRect = GetBuildingRect() - ToReferenceFrame();
1323 Maybe<nsRect> visibleRect =
1324 buildingRect.EdgeInclusiveIntersection(destRect);
1325 if (visibleRect) {
1326 *visibleRect -= destRect.TopLeft();
1327 }
1328
1329 // Generate an effects update notifying the browser it is visible
1330 MatrixScales scale = aSc.GetInheritedScale();
1331
1332 ParentLayerToScreenScale2D transformToAncestorScale =
1333 ParentLayerToParentLayerScale(
1334 pc->GetPresShell() ? pc->GetPresShell()->GetCumulativeResolution()
1335 : 1.f) *
1336 nsLayoutUtils::GetTransformToAncestorScaleCrossProcessForFrameMetrics(
1337 mFrame);
1338
1339 aDisplayListBuilder->AddEffectUpdate(
1340 remoteBrowser, EffectsInfo::VisibleWithinRect(
1341 visibleRect, scale, transformToAncestorScale));
1342
1343 // Create a WebRenderRemoteData to notify the RemoteBrowser when it is no
1344 // longer visible
1345 RefPtr<WebRenderRemoteData> userData =
1346 aManager->CommandBuilder()
1347 .CreateOrRecycleWebRenderUserData<WebRenderRemoteData>(this,
1348 nullptr);
1349 userData->SetRemoteBrowser(remoteBrowser);
1350 }
1351
1352 nscoord auPerDevPixel = pc->AppUnitsPerDevPixel();
1353 nsPoint layerOffset =
1354 aDisplayListBuilder->ToReferenceFrame(mFrame) + destRect.TopLeft();
1355 mOffset = LayoutDevicePoint::FromAppUnits(layerOffset, auPerDevPixel);
1356
1357 destRect.MoveTo(0, 0);
1358 auto rect = LayoutDeviceRect::FromAppUnits(destRect, auPerDevPixel);
1359 rect += mOffset;
1360
1361 aBuilder.PushIFrame(rect, !BackfaceIsHidden(),
1362 mozilla::wr::AsPipelineId(mPaintData.mLayersId),
1363 /*ignoreMissingPipelines*/ true);
1364
1365 return true;
1366}
1367
1368bool nsDisplayRemote::UpdateScrollData(
1369 mozilla::layers::WebRenderScrollData* aData,
1370 mozilla::layers::WebRenderLayerScrollData* aLayerData) {
1371 if (!mPaintData.mLayersId.IsValid()) {
1372 return true;
1373 }
1374
1375 if (aLayerData) {
1376 aLayerData->SetReferentId(mPaintData.mLayersId);
1377
1378 auto size = static_cast<nsSubDocumentFrame*>(mFrame)->GetSubdocumentSize();
1379 Matrix4x4 m = Matrix4x4::Translation(mOffset.x, mOffset.y, 0.0);
1380 aLayerData->SetTransform(m);
1381 aLayerData->SetEventRegionsOverride(mEventRegionsOverride);
1382 aLayerData->SetRemoteDocumentSize(LayerIntSize(size.width, size.height));
1383 }
1384 return true;
1385}
1386
1387nsFrameLoader* nsDisplayRemote::GetFrameLoader() const {
1388 return static_cast<nsSubDocumentFrame*>(mFrame)->FrameLoader();
1389}
1390
1391} // namespace mozilla