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/. */
7 #include "nsDocShellLoadInfo.h"
8 #include "nsISHEntry.h"
9 #include "nsIInputStream.h"
11 #include "nsIDocShell.h"
12 #include "mozilla/net/ReferrerPolicy.h"
13 #include "mozilla/Unused.h"
18 GetMaybeResultPrincipalURI(nsIDocShellLoadInfo
* aLoadInfo
, Maybe
<nsCOMPtr
<nsIURI
>>& aRPURI
)
27 rv
= aLoadInfo
->GetResultPrincipalURIIsSome(&isSome
);
28 if (NS_WARN_IF(NS_FAILED(rv
))) {
39 rv
= aLoadInfo
->GetResultPrincipalURI(getter_AddRefs(uri
));
40 if (NS_WARN_IF(NS_FAILED(rv
))) {
44 aRPURI
.emplace(std::move(uri
));
48 SetMaybeResultPrincipalURI(nsIDocShellLoadInfo
* aLoadInfo
, Maybe
<nsCOMPtr
<nsIURI
>> const& aRPURI
)
56 rv
= aLoadInfo
->SetResultPrincipalURI(aRPURI
.refOr(nullptr));
57 Unused
<< NS_WARN_IF(NS_FAILED(rv
));
59 rv
= aLoadInfo
->SetResultPrincipalURIIsSome(aRPURI
.isSome());
60 Unused
<< NS_WARN_IF(NS_FAILED(rv
));
65 nsDocShellLoadInfo::nsDocShellLoadInfo()
66 : mResultPrincipalURIIsSome(false)
68 , mInheritPrincipal(false)
69 , mPrincipalIsExplicit(false)
70 , mForceAllowDataURI(false)
71 , mOriginalFrameSrc(false)
73 , mReferrerPolicy(mozilla::net::RP_Unset
)
74 , mLoadType(nsIDocShellLoadInfo::loadNormal
)
75 , mIsSrcdocLoad(false)
79 nsDocShellLoadInfo::~nsDocShellLoadInfo()
83 NS_IMPL_ADDREF(nsDocShellLoadInfo
)
84 NS_IMPL_RELEASE(nsDocShellLoadInfo
)
86 NS_INTERFACE_MAP_BEGIN(nsDocShellLoadInfo
)
87 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDocShellLoadInfo
)
88 NS_INTERFACE_MAP_ENTRY(nsIDocShellLoadInfo
)
92 nsDocShellLoadInfo::GetReferrer(nsIURI
** aReferrer
)
94 NS_ENSURE_ARG_POINTER(aReferrer
);
96 *aReferrer
= mReferrer
;
97 NS_IF_ADDREF(*aReferrer
);
102 nsDocShellLoadInfo::SetReferrer(nsIURI
* aReferrer
)
104 mReferrer
= aReferrer
;
109 nsDocShellLoadInfo::GetOriginalURI(nsIURI
** aOriginalURI
)
111 NS_ENSURE_ARG_POINTER(aOriginalURI
);
113 *aOriginalURI
= mOriginalURI
;
114 NS_IF_ADDREF(*aOriginalURI
);
119 nsDocShellLoadInfo::SetOriginalURI(nsIURI
* aOriginalURI
)
121 mOriginalURI
= aOriginalURI
;
126 nsDocShellLoadInfo::GetResultPrincipalURI(nsIURI
** aResultPrincipalURI
)
128 NS_ENSURE_ARG_POINTER(aResultPrincipalURI
);
130 *aResultPrincipalURI
= mResultPrincipalURI
;
131 NS_IF_ADDREF(*aResultPrincipalURI
);
136 nsDocShellLoadInfo::SetResultPrincipalURI(nsIURI
* aResultPrincipalURI
)
138 mResultPrincipalURI
= aResultPrincipalURI
;
143 nsDocShellLoadInfo::GetResultPrincipalURIIsSome(bool* aIsSome
)
145 *aIsSome
= mResultPrincipalURIIsSome
;
150 nsDocShellLoadInfo::SetResultPrincipalURIIsSome(bool aIsSome
)
152 mResultPrincipalURIIsSome
= aIsSome
;
157 nsDocShellLoadInfo::GetLoadReplace(bool* aLoadReplace
)
159 *aLoadReplace
= mLoadReplace
;
164 nsDocShellLoadInfo::SetLoadReplace(bool aLoadReplace
)
166 mLoadReplace
= aLoadReplace
;
171 nsDocShellLoadInfo::GetTriggeringPrincipal(nsIPrincipal
** aTriggeringPrincipal
)
173 NS_ENSURE_ARG_POINTER(aTriggeringPrincipal
);
174 NS_IF_ADDREF(*aTriggeringPrincipal
= mTriggeringPrincipal
);
179 nsDocShellLoadInfo::SetTriggeringPrincipal(nsIPrincipal
* aTriggeringPrincipal
)
181 mTriggeringPrincipal
= aTriggeringPrincipal
;
186 nsDocShellLoadInfo::GetInheritPrincipal(bool* aInheritPrincipal
)
188 NS_ENSURE_ARG_POINTER(aInheritPrincipal
);
189 *aInheritPrincipal
= mInheritPrincipal
;
194 nsDocShellLoadInfo::SetInheritPrincipal(bool aInheritPrincipal
)
196 mInheritPrincipal
= aInheritPrincipal
;
201 nsDocShellLoadInfo::GetPrincipalIsExplicit(bool* aPrincipalIsExplicit
)
203 *aPrincipalIsExplicit
= mPrincipalIsExplicit
;
208 nsDocShellLoadInfo::SetPrincipalIsExplicit(bool aPrincipalIsExplicit
)
210 mPrincipalIsExplicit
= aPrincipalIsExplicit
;
215 nsDocShellLoadInfo::GetForceAllowDataURI(bool* aForceAllowDataURI
)
217 *aForceAllowDataURI
= mForceAllowDataURI
;
222 nsDocShellLoadInfo::SetForceAllowDataURI(bool aForceAllowDataURI
)
224 mForceAllowDataURI
= aForceAllowDataURI
;
229 nsDocShellLoadInfo::GetOriginalFrameSrc(bool* aOriginalFrameSrc
)
231 *aOriginalFrameSrc
= mOriginalFrameSrc
;
236 nsDocShellLoadInfo::SetOriginalFrameSrc(bool aOriginalFrameSrc
)
238 mOriginalFrameSrc
= aOriginalFrameSrc
;
243 nsDocShellLoadInfo::GetLoadType(nsDocShellInfoLoadType
* aLoadType
)
245 NS_ENSURE_ARG_POINTER(aLoadType
);
247 *aLoadType
= mLoadType
;
252 nsDocShellLoadInfo::SetLoadType(nsDocShellInfoLoadType aLoadType
)
254 mLoadType
= aLoadType
;
259 nsDocShellLoadInfo::GetSHEntry(nsISHEntry
** aSHEntry
)
261 NS_ENSURE_ARG_POINTER(aSHEntry
);
263 *aSHEntry
= mSHEntry
;
264 NS_IF_ADDREF(*aSHEntry
);
269 nsDocShellLoadInfo::SetSHEntry(nsISHEntry
* aSHEntry
)
276 nsDocShellLoadInfo::GetTarget(char16_t
** aTarget
)
278 NS_ENSURE_ARG_POINTER(aTarget
);
280 *aTarget
= ToNewUnicode(mTarget
);
286 nsDocShellLoadInfo::SetTarget(const char16_t
* aTarget
)
288 mTarget
.Assign(aTarget
);
293 nsDocShellLoadInfo::GetPostDataStream(nsIInputStream
** aResult
)
295 NS_ENSURE_ARG_POINTER(aResult
);
297 *aResult
= mPostDataStream
;
299 NS_IF_ADDREF(*aResult
);
304 nsDocShellLoadInfo::SetPostDataStream(nsIInputStream
* aStream
)
306 mPostDataStream
= aStream
;
311 nsDocShellLoadInfo::GetHeadersStream(nsIInputStream
** aHeadersStream
)
313 NS_ENSURE_ARG_POINTER(aHeadersStream
);
314 *aHeadersStream
= mHeadersStream
;
315 NS_IF_ADDREF(*aHeadersStream
);
319 nsDocShellLoadInfo::SetHeadersStream(nsIInputStream
* aHeadersStream
)
321 mHeadersStream
= aHeadersStream
;
326 nsDocShellLoadInfo::GetSendReferrer(bool* aSendReferrer
)
328 NS_ENSURE_ARG_POINTER(aSendReferrer
);
330 *aSendReferrer
= mSendReferrer
;
335 nsDocShellLoadInfo::SetSendReferrer(bool aSendReferrer
)
337 mSendReferrer
= aSendReferrer
;
342 nsDocShellLoadInfo::GetReferrerPolicy(
343 nsDocShellInfoReferrerPolicy
* aReferrerPolicy
)
345 *aReferrerPolicy
= mReferrerPolicy
;
350 nsDocShellLoadInfo::SetReferrerPolicy(
351 nsDocShellInfoReferrerPolicy aReferrerPolicy
)
353 mReferrerPolicy
= aReferrerPolicy
;
358 nsDocShellLoadInfo::GetIsSrcdocLoad(bool* aIsSrcdocLoad
)
360 *aIsSrcdocLoad
= mIsSrcdocLoad
;
365 nsDocShellLoadInfo::GetSrcdocData(nsAString
& aSrcdocData
)
367 aSrcdocData
= mSrcdocData
;
372 nsDocShellLoadInfo::SetSrcdocData(const nsAString
& aSrcdocData
)
374 mSrcdocData
= aSrcdocData
;
375 mIsSrcdocLoad
= true;
380 nsDocShellLoadInfo::GetSourceDocShell(nsIDocShell
** aSourceDocShell
)
382 MOZ_ASSERT(aSourceDocShell
);
383 nsCOMPtr
<nsIDocShell
> result
= mSourceDocShell
;
384 result
.forget(aSourceDocShell
);
389 nsDocShellLoadInfo::SetSourceDocShell(nsIDocShell
* aSourceDocShell
)
391 mSourceDocShell
= aSourceDocShell
;
396 nsDocShellLoadInfo::GetBaseURI(nsIURI
** aBaseURI
)
398 NS_ENSURE_ARG_POINTER(aBaseURI
);
400 *aBaseURI
= mBaseURI
;
401 NS_IF_ADDREF(*aBaseURI
);
406 nsDocShellLoadInfo::SetBaseURI(nsIURI
* aBaseURI
)