Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nsDocShellLoadState.h
Warning:line 56, column 7
Excessive padding in 'class nsDocShellLoadState' (43 padding bytes, where 3 is optimal). Optimal fields order: mRefCnt, _mOwningThread, mReferrerInfo, mURI, mOriginalURI, mResultPrincipalURI, mTriggeringPrincipal, mTriggeringWindowId, mPolicyContainer, mPrincipalToInherit, mPartitionedPrincipalToInherit, mHttpsFirstDowngradeData, mSHEntry, mLoadingSessionHistoryInfo, mPostDataStream, mHeadersStream, mBaseURI, mPendingRedirectedChannel, mChannelRegistrarId, mLoadIdentifier, mSpeculativeListener, mUnstrippedURI, mSourceElement, mNavigationAPIState, mNavigationAPIMethodTracker, mFormDataEntryList, mTarget, mTargetBrowsingContext, mSrcdocData, mSourceBrowsingContext, mTypeHint, mFileName, mOriginalURIString, mTriggeringRemoteType, mRemoteTypeOverride, mTriggeringSandboxFlags, mLoadType, mLoadFlags, mInternalLoadFlags, mHttpsUpgradeTelemetry, mAppLinkLaunchType, mTriggeringClassificationFlags, mCancelContentJSEpoch, mResultPrincipalURIIsSome, mKeepResultPrincipalURIIfSet, mLoadReplace, mInheritPrincipal, mPrincipalIsExplicit, mNotifiedBeforeUnloadListeners, mForceAllowDataURI, mIsExemptFromHTTPSFirstMode, mOriginalFrameSrc, mShouldCheckForRecursion, mIsFormSubmission, mNeedsCompletelyLoadedDocument, mUserNavigationInvolvement, mFirstParty, mHasValidUserGestureActivation, mTextDirectiveUserActivation, mAllowFocusMove, mIsFromProcessingFrameAttributes, mHasComputedNamedTargetBrowsingContext, mHasSpeculativeListener, mIsMetaRefresh, mWasCreatedRemotely, mSchemelessInput, mForceMediaDocument, mIsCaptivePortalTab, mIsInitialAboutBlankHandlingProhibited, mIsResumingInterceptedNavigation, mHistoryBehavior, consider reordering the fields or adding explicit padding members

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name AccessibleWrap.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=/root/firefox-clang/obj-x86_64-pc-linux-gnu/accessible/atk -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/accessible/atk -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/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 /root/firefox-clang/accessible/atk -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/accessible/atk -I /root/firefox-clang/accessible/base -I /root/firefox-clang/accessible/generic -I /root/firefox-clang/accessible/html -I /root/firefox-clang/accessible/ipc -I /root/firefox-clang/accessible/xpcom -I /root/firefox-clang/accessible/xul -I /root/firefox-clang/layout/generic -I /root/firefox-clang/other-licenses/atk-1.0 -I /root/firefox-clang/widget -I /root/firefox-clang/widget/gtk -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -I /usr/include/gtk-3.0/unix-print -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/cloudproviders -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/fribidi -I /usr/include/harfbuzz -I /usr/include/atk-1.0 -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/glycin-2 -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -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-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 -Wno-character-conversion -Wno-error=unused-function -Wno-unused-local-typedefs -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-10-17-231001-351276-1 -x c++ /root/firefox-clang/accessible/atk/AccessibleWrap.cpp
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#ifndef nsDocShellLoadState_h_
6#define nsDocShellLoadState_h_
7
8#include "mozilla/dom/BrowsingContext.h"
9#include "mozilla/dom/NavigationBinding.h"
10#include "mozilla/dom/RemoteType.h"
11#include "mozilla/dom/SessionHistoryEntry.h"
12#include "mozilla/dom/UserNavigationInvolvement.h"
13#include "mozilla/dom/LoadURIOptionsBinding.h"
14
15#include "nsIClassifiedChannel.h"
16#include "nsILoadInfo.h"
17
18// Helper Classes
19#include "mozilla/Maybe.h"
20#include "nsCOMPtr.h"
21#include "nsString.h"
22#include "nsDocShellLoadTypes.h"
23#include "nsTArrayForwardDeclare.h"
24
25class nsIInputStream;
26class nsIURI;
27class nsIDocShell;
28class nsIChannel;
29class nsIReferrerInfo;
30struct HTTPSFirstDowngradeData;
31namespace mozilla {
32class OriginAttributes;
33namespace net {
34class DocumentLoadListener;
35}
36namespace dom {
37class FormData;
38class DocShellLoadStateInit;
39struct NavigationAPIMethodTracker;
40class SessionHistoryEntry;
41struct RemoteType;
42} // namespace dom
43} // namespace mozilla
44
45namespace mozilla::dom {
46
47bool ContentTriggeredURILoadIsAllowed(
48 nsIURI* aURI, const mozilla::dom::RemoteType& aEffectiveRemoteType);
49
50}
51
52/**
53 * nsDocShellLoadState contains setup information used in a nsIDocShell::loadURI
54 * call.
55 */
56class nsDocShellLoadState final {
Excessive padding in 'class nsDocShellLoadState' (43 padding bytes, where 3 is optimal). Optimal fields order: mRefCnt, _mOwningThread, mReferrerInfo, mURI, mOriginalURI, mResultPrincipalURI, mTriggeringPrincipal, mTriggeringWindowId, mPolicyContainer, mPrincipalToInherit, mPartitionedPrincipalToInherit, mHttpsFirstDowngradeData, mSHEntry, mLoadingSessionHistoryInfo, mPostDataStream, mHeadersStream, mBaseURI, mPendingRedirectedChannel, mChannelRegistrarId, mLoadIdentifier, mSpeculativeListener, mUnstrippedURI, mSourceElement, mNavigationAPIState, mNavigationAPIMethodTracker, mFormDataEntryList, mTarget, mTargetBrowsingContext, mSrcdocData, mSourceBrowsingContext, mTypeHint, mFileName, mOriginalURIString, mTriggeringRemoteType, mRemoteTypeOverride, mTriggeringSandboxFlags, mLoadType, mLoadFlags, mInternalLoadFlags, mHttpsUpgradeTelemetry, mAppLinkLaunchType, mTriggeringClassificationFlags, mCancelContentJSEpoch, mResultPrincipalURIIsSome, mKeepResultPrincipalURIIfSet, mLoadReplace, mInheritPrincipal, mPrincipalIsExplicit, mNotifiedBeforeUnloadListeners, mForceAllowDataURI, mIsExemptFromHTTPSFirstMode, mOriginalFrameSrc, mShouldCheckForRecursion, mIsFormSubmission, mNeedsCompletelyLoadedDocument, mUserNavigationInvolvement, mFirstParty, mHasValidUserGestureActivation, mTextDirectiveUserActivation, mAllowFocusMove, mIsFromProcessingFrameAttributes, mHasComputedNamedTargetBrowsingContext, mHasSpeculativeListener, mIsMetaRefresh, mWasCreatedRemotely, mSchemelessInput, mForceMediaDocument, mIsCaptivePortalTab, mIsInitialAboutBlankHandlingProhibited, mIsResumingInterceptedNavigation, mHistoryBehavior, consider reordering the fields or adding explicit padding members
57 using BrowsingContext = mozilla::dom::BrowsingContext;
58 template <typename T>
59 using MaybeDiscarded = mozilla::dom::MaybeDiscarded<T>;
60 using SessionHistoryEntry = mozilla::dom::SessionHistoryEntry;
61
62 public:
63 NS_INLINE_DECL_REFCOUNTING(nsDocShellLoadState)public: MozExternalRefCountType AddRef(void) { static_assert(
!std::is_destructible_v<nsDocShellLoadState>, "Reference-counted class "
"nsDocShellLoadState" " should not have a public destructor. "
"Make this class's destructor non-public"); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(int32_t
(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nsDocShellLoadState.h"
, 63); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 63
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); _mOwningThread.AssertOwnership("nsDocShellLoadState"
" not thread-safe"); ++mRefCnt; NS_LogAddRef((this), (mRefCnt
), ("nsDocShellLoadState"), (uint32_t)(sizeof(*this))); return
mRefCnt; } MozExternalRefCountType Release(void) { do { static_assert
( mozilla::detail::AssertionConditionType<decltype(int32_t
(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0"
" (" "dup release" ")", "/root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nsDocShellLoadState.h"
, 63); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 63)
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); _mOwningThread.AssertOwnership("nsDocShellLoadState"
" not thread-safe"); --mRefCnt; NS_LogRelease((this), (mRefCnt
), ("nsDocShellLoadState")); if (mRefCnt == 0) { mRefCnt = 1;
delete (this); return 0; } return mRefCnt; } using HasThreadSafeRefCnt
= std::false_type; protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread
_mOwningThread; public:
;
64
65 explicit nsDocShellLoadState(nsIURI* aURI);
66 explicit nsDocShellLoadState(
67 const mozilla::dom::DocShellLoadStateInit& aLoadState,
68 mozilla::ipc::IProtocol* aActor, bool* aReadSuccess);
69 explicit nsDocShellLoadState(const nsDocShellLoadState& aOther);
70 nsDocShellLoadState(nsIURI* aURI, uint64_t aLoadIdentifier);
71
72 static nsresult CreateFromPendingChannel(nsIChannel* aPendingChannel,
73 uint64_t aLoadIdentifier,
74 uint64_t aRegistarId,
75 nsDocShellLoadState** aResult);
76
77 static nsresult CreateFromLoadURIOptions(
78 BrowsingContext* aBrowsingContext, const nsAString& aURI,
79 const mozilla::dom::LoadURIOptions& aLoadURIOptions,
80 nsDocShellLoadState** aResult);
81 static nsresult CreateFromLoadURIOptions(
82 BrowsingContext* aBrowsingContext, nsIURI* aURI,
83 const mozilla::dom::LoadURIOptions& aLoadURIOptions,
84 nsDocShellLoadState** aResult);
85
86 // Getters and Setters
87
88 nsIReferrerInfo* GetReferrerInfo() const;
89
90 void SetReferrerInfo(nsIReferrerInfo* aReferrerInfo);
91
92 nsIURI* URI() const;
93
94 void SetURI(nsIURI* aURI);
95
96 nsIURI* OriginalURI() const;
97
98 void SetOriginalURI(nsIURI* aOriginalURI);
99
100 nsIURI* ResultPrincipalURI() const;
101
102 void SetResultPrincipalURI(nsIURI* aResultPrincipalURI);
103
104 bool ResultPrincipalURIIsSome() const;
105
106 void SetResultPrincipalURIIsSome(bool aIsSome);
107
108 bool KeepResultPrincipalURIIfSet() const;
109
110 void SetKeepResultPrincipalURIIfSet(bool aKeep);
111
112 nsIPrincipal* PrincipalToInherit() const;
113
114 void SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit);
115
116 nsIPrincipal* PartitionedPrincipalToInherit() const;
117
118 void SetPartitionedPrincipalToInherit(
119 nsIPrincipal* aPartitionedPrincipalToInherit);
120
121 bool LoadReplace() const;
122
123 void SetLoadReplace(bool aLoadReplace);
124
125 nsIPrincipal* TriggeringPrincipal() const;
126
127 void SetTriggeringPrincipal(nsIPrincipal* aTriggeringPrincipal);
128
129 uint32_t TriggeringSandboxFlags() const;
130
131 void SetTriggeringSandboxFlags(uint32_t aTriggeringSandboxFlags);
132
133 uint64_t TriggeringWindowId() const;
134
135 void SetTriggeringWindowId(uint64_t aTriggeringWindowId);
136
137 mozilla::net::ClassificationFlags TriggeringClassificationFlags() const;
138 void SetTriggeringClassificationFlags(
139 mozilla::net::ClassificationFlags aFlags);
140
141 nsIPolicyContainer* PolicyContainer() const;
142
143 void SetPolicyContainer(nsIPolicyContainer* aPolicyContainer);
144
145 bool InheritPrincipal() const;
146
147 void SetInheritPrincipal(bool aInheritPrincipal);
148
149 bool PrincipalIsExplicit() const;
150
151 void SetPrincipalIsExplicit(bool aPrincipalIsExplicit);
152
153 // If true, "beforeunload" event listeners were notified by the creater of the
154 // LoadState and given the chance to abort the navigation, and should not be
155 // notified again.
156 bool NotifiedBeforeUnloadListeners() const;
157
158 void SetNotifiedBeforeUnloadListeners(bool aNotifiedBeforeUnloadListeners);
159
160 bool ForceAllowDataURI() const;
161
162 void SetForceAllowDataURI(bool aForceAllowDataURI);
163
164 bool IsExemptFromHTTPSFirstMode() const;
165
166 void SetIsExemptFromHTTPSFirstMode(bool aIsExemptFromHTTPSFirstMode);
167
168 RefPtr<HTTPSFirstDowngradeData> GetHttpsFirstDowngradeData() const;
169
170 void SetHttpsFirstDowngradeData(
171 RefPtr<HTTPSFirstDowngradeData> const& aHttpsFirstTelemetryData);
172
173 bool OriginalFrameSrc() const;
174
175 void SetOriginalFrameSrc(bool aOriginalFrameSrc);
176
177 bool ShouldCheckForRecursion() const;
178
179 void SetShouldCheckForRecursion(bool aShouldCheckForRecursion);
180
181 bool IsFormSubmission() const;
182
183 void SetIsFormSubmission(bool aIsFormSubmission);
184
185 bool NeedsCompletelyLoadedDocument() const;
186
187 void SetNeedsCompletelyLoadedDocument(bool aNeedsCompletelyLoadedDocument);
188
189 mozilla::Maybe<mozilla::dom::NavigationHistoryBehavior> HistoryBehavior()
190 const;
191
192 void SetHistoryBehavior(
193 mozilla::dom::NavigationHistoryBehavior aHistoryBehavior);
194
195 void ResetHistoryBehavior();
196
197 uint32_t LoadType() const;
198
199 void SetLoadType(uint32_t aLoadType);
200
201 mozilla::dom::UserNavigationInvolvement UserNavigationInvolvement() const;
202
203 void SetUserNavigationInvolvement(
204 mozilla::dom::UserNavigationInvolvement aUserNavigationInvolvement);
205
206 SessionHistoryEntry* SHEntry() const;
207
208 void SetSHEntry(SessionHistoryEntry* aSHEntry);
209
210 void SetPreviousEntryForActivation(nsISHEntry* aSHEntry);
211 void SetPreviousEntryForActivation(
212 const mozilla::Maybe<mozilla::dom::PreviousSessionHistoryInfo>& aInfo);
213
214 const mozilla::dom::LoadingSessionHistoryInfo* GetLoadingSessionHistoryInfo()
215 const;
216
217 // Copies aLoadingInfo and stores the copy in this nsDocShellLoadState.
218 void SetLoadingSessionHistoryInfo(
219 const mozilla::dom::LoadingSessionHistoryInfo& aLoadingInfo);
220
221 // Stores aLoadingInfo in this nsDocShellLoadState.
222 void SetLoadingSessionHistoryInfo(
223 mozilla::UniquePtr<mozilla::dom::LoadingSessionHistoryInfo> aLoadingInfo);
224
225 bool LoadIsFromSessionHistory() const;
226
227 const nsString& Target() const;
228
229 void SetTarget(const nsAString& aTarget);
230
231 nsIInputStream* PostDataStream() const;
232
233 void SetPostDataStream(nsIInputStream* aStream);
234
235 nsIInputStream* HeadersStream() const;
236
237 void SetHeadersStream(nsIInputStream* aHeadersStream);
238
239 bool IsSrcdocLoad() const;
240
241 const nsString& SrcdocData() const;
242
243 void SetSrcdocData(const nsAString& aSrcdocData);
244
245 const MaybeDiscarded<BrowsingContext>& SourceBrowsingContext() const {
246 return mSourceBrowsingContext;
247 }
248
249 void SetSourceBrowsingContext(BrowsingContext*);
250
251 void SetAllowFocusMove(bool aAllow) { mAllowFocusMove = aAllow; }
252
253 bool AllowFocusMove() const { return mAllowFocusMove; }
254
255 const MaybeDiscarded<BrowsingContext>& TargetBrowsingContext() const {
256 return mTargetBrowsingContext;
257 }
258
259 void SetTargetBrowsingContext(BrowsingContext* aTargetBrowsingContext);
260
261 nsIURI* BaseURI() const;
262
263 void SetBaseURI(nsIURI* aBaseURI);
264
265 // Helper function allowing convenient work with mozilla::Maybe in C++, hiding
266 // resultPrincipalURI and resultPrincipalURIIsSome attributes from the
267 // consumer.
268 void GetMaybeResultPrincipalURI(
269 mozilla::Maybe<nsCOMPtr<nsIURI>>& aRPURI) const;
270
271 void SetMaybeResultPrincipalURI(
272 mozilla::Maybe<nsCOMPtr<nsIURI>> const& aRPURI);
273
274 uint32_t LoadFlags() const;
275
276 void SetLoadFlags(uint32_t aFlags);
277
278 void SetLoadFlag(uint32_t aFlag);
279
280 void UnsetLoadFlag(uint32_t aFlag);
281
282 bool HasLoadFlags(uint32_t aFlag);
283
284 uint32_t InternalLoadFlags() const;
285
286 void SetInternalLoadFlags(uint32_t aFlags);
287
288 void SetInternalLoadFlag(uint32_t aFlag);
289
290 void UnsetInternalLoadFlag(uint32_t aFlag);
291
292 bool HasInternalLoadFlags(uint32_t aFlag);
293
294 bool FirstParty() const;
295
296 void SetFirstParty(bool aFirstParty);
297
298 bool HasValidUserGestureActivation() const;
299
300 void SetHasValidUserGestureActivation(bool HasValidUserGestureActivation);
301
302 void SetTextDirectiveUserActivation(bool aTextDirectiveUserActivation);
303
304 bool GetTextDirectiveUserActivation();
305
306 const nsCString& TypeHint() const;
307
308 void SetTypeHint(const nsCString& aTypeHint);
309
310 const nsString& FileName() const;
311
312 void SetFileName(const nsAString& aFileName);
313
314 nsIURI* GetUnstrippedURI() const;
315
316 void SetUnstrippedURI(nsIURI* aUnstrippedURI);
317
318 // Give the type of DocShell we're loading into (chrome/content/etc) and
319 // origin attributes for the URI we're loading, figure out if we should
320 // inherit our principal from the document the load was requested from, or
321 // else if the principal should be set up later in the process (after loads).
322 // See comments in function for more info on principal selection algorithm
323 nsresult SetupInheritingPrincipal(
324 mozilla::dom::BrowsingContext::Type aType,
325 const mozilla::OriginAttributes& aOriginAttributes);
326
327 // If no triggering principal exists at the moment, create one using referrer
328 // information and origin attributes.
329 nsresult SetupTriggeringPrincipal(
330 const mozilla::OriginAttributes& aOriginAttributes);
331
332 void SetIsFromProcessingFrameAttributes() {
333 mIsFromProcessingFrameAttributes = true;
334 }
335 bool GetIsFromProcessingFrameAttributes() const {
336 return mIsFromProcessingFrameAttributes;
337 }
338
339 nsIChannel* GetPendingRedirectedChannel() {
340 return mPendingRedirectedChannel;
341 }
342
343 uint64_t GetPendingRedirectChannelRegistrarId() const {
344 return mChannelRegistrarId;
345 }
346
347 void SetOriginalURIString(const nsCString& aOriginalURI) {
348 mOriginalURIString.emplace(aOriginalURI);
349 }
350 const mozilla::Maybe<nsCString>& GetOriginalURIString() const {
351 return mOriginalURIString;
352 }
353
354 void SetCancelContentJSEpoch(int32_t aCancelEpoch) {
355 mCancelContentJSEpoch.emplace(aCancelEpoch);
356 }
357 const mozilla::Maybe<int32_t>& GetCancelContentJSEpoch() const {
358 return mCancelContentJSEpoch;
359 }
360
361 uint64_t GetLoadIdentifier() const { return mLoadIdentifier; }
362
363 void SetSpeculativeListener(mozilla::net::DocumentLoadListener* aListener);
364 already_AddRefed<mozilla::net::DocumentLoadListener>
365 TakeSpeculativeListener();
366
367 void SetIsMetaRefresh(bool aMetaRefresh) { mIsMetaRefresh = aMetaRefresh; }
368
369 bool IsMetaRefresh() const { return mIsMetaRefresh; }
370
371 const mozilla::Maybe<mozilla::dom::RemoteType>& GetRemoteTypeOverride()
372 const {
373 return mRemoteTypeOverride;
374 }
375
376 void SetRemoteTypeOverride(
377 const mozilla::dom::RemoteType& aRemoteTypeOverride);
378
379 void SetSchemelessInput(nsILoadInfo::SchemelessInputType aSchemelessInput) {
380 mSchemelessInput = aSchemelessInput;
381 }
382
383 nsILoadInfo::SchemelessInputType GetSchemelessInput() {
384 return mSchemelessInput;
385 }
386
387 void SetForceMediaDocument(
388 mozilla::dom::ForceMediaDocument aForceMediaDocument) {
389 mForceMediaDocument = aForceMediaDocument;
390 }
391
392 mozilla::dom::ForceMediaDocument GetForceMediaDocument() const {
393 return mForceMediaDocument;
394 }
395
396 void SetHttpsUpgradeTelemetry(
397 nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsUpgradeTelemetry) {
398 mHttpsUpgradeTelemetry = aHttpsUpgradeTelemetry;
399 }
400
401 nsILoadInfo::HTTPSUpgradeTelemetryType GetHttpsUpgradeTelemetry() {
402 return mHttpsUpgradeTelemetry;
403 }
404
405 // Determine the remote type of the process which should be considered
406 // responsible for this load for the purposes of security checks.
407 //
408 // This will generally be the process which created the nsDocShellLoadState
409 // originally, however non-errorpage history loads are always considered to be
410 // triggered by the parent process, as we can validate them against the
411 // history entry.
412 const mozilla::dom::RemoteType& GetEffectiveTriggeringRemoteType() const;
413
414 void SetTriggeringRemoteType(
415 const mozilla::dom::RemoteType& aTriggeringRemoteType);
416
417 // Diagnostic assert if this is a system-principal triggered load, and it is
418 // trivial to determine that the effective triggering remote type would not be
419 // allowed to perform this load.
420 //
421 // This is called early during the load to crash as close to the cause as
422 // possible. See bug 1838686 for details.
423#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED1
424 void AssertProcessCouldTriggerLoadIfSystem();
425#else
426 void AssertProcessCouldTriggerLoadIfSystem() {}
427#endif
428
429 // When loading a document through nsDocShell::LoadURI(), a special set of
430 // flags needs to be set based on other values in nsDocShellLoadState. This
431 // function calculates those flags, before the LoadState is passed to
432 // nsDocShell::InternalLoad.
433 void CalculateLoadURIFlags();
434
435 // Compute the load flags to be used by creating channel. aUriModified and
436 // aIsEmbeddingBlockedError are expected to be Nothing when called from parent
437 // process.
438 nsLoadFlags CalculateChannelLoadFlags(
439 mozilla::dom::BrowsingContext* aBrowsingContext, bool aUriModified,
440 mozilla::Maybe<bool> aIsEmbeddingBlockedError);
441
442 mozilla::dom::DocShellLoadStateInit Serialize(
443 mozilla::ipc::IProtocol* aActor);
444
445 void SetLoadIsFromSessionHistory(int32_t aOffset, bool aLoadingCurrentEntry);
446 void ClearLoadIsFromSessionHistory();
447
448 void MaybeStripTrackerQueryStrings(mozilla::dom::BrowsingContext* aContext);
449
450 // This is used as the parameter for https://html.spec.whatwg.org/#navigate
451 void SetSourceElement(mozilla::dom::Element* aElement);
452 already_AddRefed<mozilla::dom::Element> GetSourceElement() const;
453 bool HasSourceElement() const {
454 return mSourceElement && mSourceElement->IsAlive();
455 }
456
457 // This is used as the parameter for https://html.spec.whatwg.org/#navigate
458 nsIStructuredCloneContainer* GetNavigationAPIState() const;
459 void SetNavigationAPIState(nsIStructuredCloneContainer* aNavigationAPIState);
460
461 // This is used to pass the navigation API method tracker through the
462 // navigation pipeline for navigate().
463 // See https://html.spec.whatwg.org/#navigation-api-method-tracker
464 mozilla::dom::NavigationAPIMethodTracker* GetNavigationAPIMethodTracker()
465 const;
466 void SetNavigationAPIMethodTracker(
467 mozilla::dom::NavigationAPIMethodTracker* aTracker);
468
469 // This is used as the parameter for https://html.spec.whatwg.org/#navigate
470 mozilla::dom::NavigationType GetNavigationType() const;
471
472 // This is used as the parameter for https://html.spec.whatwg.org/#navigate
473 // It should only ever be set if the method is POST.
474 mozilla::dom::FormData* GetFormDataEntryList();
475 void SetFormDataEntryList(mozilla::dom::FormData* aFormDataEntryList);
476
477 // This is used as the getter/setter for the app link intent launch type
478 // for the load.
479 uint32_t GetAppLinkLaunchType() const;
480 void SetAppLinkLaunchType(uint32_t aAppLinkLaunchType);
481
482 // This is used as the getter/setter for the captive portal tab flag.
483 bool GetIsCaptivePortalTab() const;
484 void SetIsCaptivePortalTab(bool aIsCaptivePortalTab);
485
486 void ProhibitInitialAboutBlankHandling() {
487 mIsInitialAboutBlankHandlingProhibited = true;
488 }
489 bool IsInitialAboutBlankHandlingProhibited() {
490 return mIsInitialAboutBlankHandlingProhibited;
491 }
492
493 void SetIsResumingInterceptedNavigation(
494 bool aIsResumingInterceptedNavigation) {
495 mIsResumingInterceptedNavigation = aIsResumingInterceptedNavigation;
496 }
497
498 bool IsResumingInterceptedNavigation() const {
499 return mIsResumingInterceptedNavigation;
500 }
501
502 bool HasComputedNamedTargetBrowsingContext() const {
503 return mHasComputedNamedTargetBrowsingContext;
504 }
505 void SetHasComputedNamedTargetBrowsingContext(bool aValue) {
506 mHasComputedNamedTargetBrowsingContext = aValue;
507 }
508
509 protected:
510 // Destructor can't be defaulted or inlined, as header doesn't have all type
511 // includes it needs to do so.
512 ~nsDocShellLoadState();
513
514 // Given the original `nsDocShellLoadState` which was sent to a content
515 // process, validate that they corespond to the same load.
516 // Returns a static (telemetry-safe) string naming what did not match, or
517 // nullptr if it succeeds.
518 const char* ValidateWithOriginalState(nsDocShellLoadState* aOriginalState);
519
520 static nsresult CreateFromLoadURIOptions(
521 BrowsingContext* aBrowsingContext, nsIURI* aURI,
522 const mozilla::dom::LoadURIOptions& aLoadURIOptions,
523 uint32_t aLoadFlagsOverride, nsIInputStream* aPostDataOverride,
524 nsDocShellLoadState** aResult);
525
526 // This is the referrer for the load.
527 nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
528
529 // The URI we are navigating to. Will not be null once set.
530 nsCOMPtr<nsIURI> mURI;
531
532 // The URI to set as the originalURI on the channel that does the load. If
533 // null, aURI will be set as the originalURI.
534 nsCOMPtr<nsIURI> mOriginalURI;
535
536 // The URI to be set to loadInfo.resultPrincipalURI
537 // - When Nothing, there will be no change
538 // - When Some, the principal URI will overwrite even
539 // with a null value.
540 //
541 // Valid only if mResultPrincipalURIIsSome is true (has the same meaning as
542 // isSome() on mozilla::Maybe.)
543 nsCOMPtr<nsIURI> mResultPrincipalURI;
544 bool mResultPrincipalURIIsSome;
545
546 // The principal of the load, that is, the entity responsible for causing the
547 // load to occur. In most cases the referrer and the triggeringPrincipal's URI
548 // will be identical.
549 //
550 // Please note that this is the principal that is used for security checks. If
551 // the argument aURI is provided by the web, then please do not pass a
552 // SystemPrincipal as the triggeringPrincipal.
553 nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
554
555 // The SandboxFlags of the load, that are, the SandboxFlags of the entity
556 // responsible for causing the load to occur. Most likely this are the
557 // SandboxFlags of the document that started the load.
558 uint32_t mTriggeringSandboxFlags;
559
560 // The window ID of the entity triggering the load.
561 uint64_t mTriggeringWindowId;
562
563 // The classification flags of the context responsible for causing
564 // the load to start.
565 mozilla::net::ClassificationFlags mTriggeringClassificationFlags;
566
567 // The policyContainer of the load, that is, the policyContainer of the entity
568 // responsible for causing the load to occur. Most likely this is the
569 // policyContainer of the document that started the load. In case the entity
570 // starting the load did not use a policyContainer, then mpPolicyContainer can
571 // be null. Please note that this is also the policyContainer that will be
572 // applied to the load in case the load encounters a server side redirect.
573 nsCOMPtr<nsIPolicyContainer> mPolicyContainer;
574
575 // If a refresh is caused by http-equiv="refresh" we want to set
576 // aResultPrincipalURI, but we do not want to overwrite the channel's
577 // ResultPrincipalURI, if it has already been set on the channel by a protocol
578 // handler.
579 bool mKeepResultPrincipalURIIfSet;
580
581 // If set LOAD_REPLACE flag will be set on the channel. If aOriginalURI is
582 // null, this argument is ignored.
583 bool mLoadReplace;
584
585 // If this attribute is true and no triggeringPrincipal is specified,
586 // copy the principal from the referring document.
587 bool mInheritPrincipal;
588
589 // If this attribute is true only ever use the principal specified
590 // by the triggeringPrincipal and inheritPrincipal attributes.
591 // If there are security reasons for why this is unsafe, such
592 // as trying to use a systemprincipal as the triggeringPrincipal
593 // for a content docshell the load fails.
594 bool mPrincipalIsExplicit;
595
596 // If this attribute is true, any potential unload listeners have been
597 // notified if applicable.
598 bool mNotifiedBeforeUnloadListeners;
599
600 // Principal we're inheriting. If null, this means the principal should be
601 // inherited from the current document. If set to NullPrincipal, the channel
602 // will fill in principal information later in the load. See internal comments
603 // of SetupInheritingPrincipal for more info.
604 //
605 // When passed to InternalLoad, If this argument is null then
606 // principalToInherit is computed differently. See nsDocShell::InternalLoad
607 // for more comments.
608
609 nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
610
611 nsCOMPtr<nsIPrincipal> mPartitionedPrincipalToInherit;
612
613 // If this attribute is true, then a top-level navigation
614 // to a data URI will be allowed.
615 bool mForceAllowDataURI;
616
617 // If this attribute is true, then the top-level navigaion
618 // will be exempt from HTTPS-Only-Mode upgrades.
619 bool mIsExemptFromHTTPSFirstMode;
620
621 // If set, this load is a HTTPS-First downgrade, and the downgrade data will
622 // be submitted to telemetry later if the load succeeds.
623 RefPtr<HTTPSFirstDowngradeData> mHttpsFirstDowngradeData;
624
625 // If this attribute is true, this load corresponds to a frame
626 // element loading its original src (or srcdoc) attribute.
627 bool mOriginalFrameSrc;
628
629 // If this attribute is true, this load corresponds to a frame, object, or
630 // embed element that needs a recursion check when loading it's src (or data).
631 // Unlike mOriginalFrameSrc, this attribute will always be set regardless
632 // whether we've loaded the src already.
633 bool mShouldCheckForRecursion;
634
635 // If this attribute is true, then the load was initiated by a
636 // form submission.
637 bool mIsFormSubmission;
638
639 // If this attribute is true, we need to check if the current document is
640 // completely loaded to determine if we should perform a push or replace load.
641 bool mNeedsCompletelyLoadedDocument;
642
643 // If this attribute is `Auto`, we should determine if this should be a push
644 // or replace load when actually loading.
645 mozilla::Maybe<mozilla::dom::NavigationHistoryBehavior> mHistoryBehavior;
646
647 // Contains a load type as specified by the nsDocShellLoadTypes::load*
648 // constants
649 uint32_t mLoadType;
650
651 // https://html.spec.whatwg.org/#user-navigation-involvement
652 mozilla::dom::UserNavigationInvolvement mUserNavigationInvolvement =
653 mozilla::dom::UserNavigationInvolvement::None;
654
655 // Active Session History entry (if loading from SH)
656 RefPtr<SessionHistoryEntry> mSHEntry;
657
658 // Loading session history info for the load
659 mozilla::UniquePtr<mozilla::dom::LoadingSessionHistoryInfo>
660 mLoadingSessionHistoryInfo;
661
662 // Target for load, like _content, _blank etc.
663 nsString mTarget;
664
665 // When set, this is the Target Browsing Context for the navigation
666 // after retargeting.
667 MaybeDiscarded<BrowsingContext> mTargetBrowsingContext;
668
669 // Post data stream (if POSTing)
670 nsCOMPtr<nsIInputStream> mPostDataStream;
671
672 // Additional Headers
673 nsCOMPtr<nsIInputStream> mHeadersStream;
674
675 // When set, the load will be interpreted as a srcdoc load, where contents of
676 // this string will be loaded instead of the URI. Setting srcdocData sets
677 // isSrcdocLoad to true
678 nsString mSrcdocData;
679
680 // When set, this is the Source Browsing Context for the navigation.
681 MaybeDiscarded<BrowsingContext> mSourceBrowsingContext;
682
683 // BaseURI for the load, used when this information isn't clear from the URI.
684 nsCOMPtr<nsIURI> mBaseURI;
685
686 // Set of Load Flags, taken from nsDocShellLoadTypes.h and nsIWebNavigation
687 uint32_t mLoadFlags;
688
689 // Set of internal load flags
690 uint32_t mInternalLoadFlags;
691
692 // Is this a First Party Load?
693 bool mFirstParty;
694
695 // Is this load triggered by a user gesture?
696 bool mHasValidUserGestureActivation;
697
698 // True if a text directive can be scrolled to. This is true either if the
699 // load is triggered by a user, or the document has an unconsumed activation
700 // (eg. client redirect).
701 bool mTextDirectiveUserActivation = false;
702
703 // Whether this load can steal the focus from the source browsing context.
704 bool mAllowFocusMove;
705
706 // A hint as to the content-type of the resulting data. If no hint, IsVoid()
707 // should return true.
708 nsCString mTypeHint;
709
710 // Non-void when the link should be downloaded as the given filename.
711 // mFileName being non-void but empty means that no filename hint was
712 // specified, but link should still trigger a download. If not a download,
713 // mFileName.IsVoid() should return true.
714 nsString mFileName;
715
716 // This will be true if this load is triggered by attribute changes.
717 // See nsILoadInfo.isFromProcessingFrameAttributes
718 bool mIsFromProcessingFrameAttributes;
719
720 // Whether the target name has been looked up yet
721 bool mHasComputedNamedTargetBrowsingContext = false;
722
723 // If set, a pending cross-process redirected channel should be used to
724 // perform the load. The channel will be stored in this value.
725 nsCOMPtr<nsIChannel> mPendingRedirectedChannel;
726
727 // An optional string representation of mURI, before any
728 // fixups were applied, so that we can send it to a search
729 // engine service if needed.
730 mozilla::Maybe<nsCString> mOriginalURIString;
731
732 // An optional value to pass to nsIDocShell::setCancelJSEpoch
733 // when initiating the load.
734 mozilla::Maybe<int32_t> mCancelContentJSEpoch;
735
736 // If mPendingRedirectChannel is set, then this is the identifier
737 // that the parent-process equivalent channel has been registered
738 // with using RedirectChannelRegistrar.
739 uint64_t mChannelRegistrarId;
740
741 // An identifier to make it possible to examine if two loads are
742 // equal, and which browsing context they belong to (see
743 // BrowsingContext::{Get, Set}CurrentLoadIdentifier)
744 const uint64_t mLoadIdentifier;
745
746 // Optional DocumentLoadListener reference. This is only set in the parent
747 // process, and indicates that the channel has been pre-initialized in the
748 // parent process.
749 RefPtr<mozilla::net::DocumentLoadListener> mSpeculativeListener;
750
751 // Optional value available in content to indicate the channel has been
752 // pre-initialized in the parent process.
753 bool mHasSpeculativeListener = false;
754
755 // True if the load was triggered by a meta refresh.
756 bool mIsMetaRefresh;
757
758 // True if the nsDocShellLoadState was received over IPC.
759 bool mWasCreatedRemotely = false;
760
761 // The original URI before query stripping happened. If it's present, it shows
762 // the query stripping happened. Otherwise, it will be a nullptr.
763 nsCOMPtr<nsIURI> mUnstrippedURI;
764
765 // If set, the remote type which the load should be completed within.
766 mozilla::Maybe<mozilla::dom::RemoteType> mRemoteTypeOverride;
767
768 // Remote type of the process which originally requested the load.
769 mozilla::dom::RemoteType mTriggeringRemoteType;
770
771 // if the address had an intentional protocol
772 nsILoadInfo::SchemelessInputType mSchemelessInput =
773 nsILoadInfo::SchemelessInputTypeUnset;
774
775 // If not None, force the load to result in a specific media document kind.
776 mozilla::dom::ForceMediaDocument mForceMediaDocument =
777 mozilla::dom::ForceMediaDocument::None;
778
779 // Solely for the use of collecting Telemetry for HTTPS upgrades.
780 nsILoadInfo::HTTPSUpgradeTelemetryType mHttpsUpgradeTelemetry =
781 nsILoadInfo::NOT_INITIALIZED;
782
783 nsWeakPtr mSourceElement;
784
785 RefPtr<nsStructuredCloneContainer> mNavigationAPIState;
786
787 RefPtr<mozilla::dom::NavigationAPIMethodTracker> mNavigationAPIMethodTracker;
788
789 RefPtr<mozilla::dom::FormData> mFormDataEntryList;
790
791 // App link intent launch type: 0 = unknown, 1 = cold, 2 = warm, 3 = hot.
792 uint32_t mAppLinkLaunchType = 0;
793
794 // Whether this is a captive portal tab.
795 bool mIsCaptivePortalTab = false;
796
797 // When this is the initial load and it is loading about:blank, force it
798 // to take the regular load path. It will replace the previous document
799 // and not load synchronous.
800 bool mIsInitialAboutBlankHandlingProhibited;
801
802 // True when this LoadURI call is synchronously resuming a traversal
803 // navigation that was paused while the Navigation API's NavigateEvent was
804 // dispatched and intercepted. Set by Navigation::CommitNavigateEvent after
805 // the event commits, and consumed on the docshell side to keep the existing
806 // ongoing navigation in place (rather than resetting it) and to forward the
807 // flag through LoadHistoryEntry.
808 bool mIsResumingInterceptedNavigation = false;
809};
810
811#endif /* nsDocShellLoadState_h_ */