Bug Summary

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