Bug 1473362 [wpt PR 11778] - Update wpt metadata, a=testonly
[gecko.git] / docshell / base / nsDocShellLoadInfo.cpp
blobcc6dc760e825eb62c96682cbbb89a148c80e5db7
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"
10 #include "nsIURI.h"
11 #include "nsIDocShell.h"
12 #include "mozilla/net/ReferrerPolicy.h"
13 #include "mozilla/Unused.h"
15 namespace mozilla {
17 void
18 GetMaybeResultPrincipalURI(nsIDocShellLoadInfo* aLoadInfo, Maybe<nsCOMPtr<nsIURI>>& aRPURI)
20 if (!aLoadInfo) {
21 return;
24 nsresult rv;
26 bool isSome;
27 rv = aLoadInfo->GetResultPrincipalURIIsSome(&isSome);
28 if (NS_WARN_IF(NS_FAILED(rv))) {
29 return;
32 aRPURI.reset();
34 if (!isSome) {
35 return;
38 nsCOMPtr<nsIURI> uri;
39 rv = aLoadInfo->GetResultPrincipalURI(getter_AddRefs(uri));
40 if (NS_WARN_IF(NS_FAILED(rv))) {
41 return;
44 aRPURI.emplace(std::move(uri));
47 void
48 SetMaybeResultPrincipalURI(nsIDocShellLoadInfo* aLoadInfo, Maybe<nsCOMPtr<nsIURI>> const& aRPURI)
50 if (!aLoadInfo) {
51 return;
54 nsresult rv;
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));
63 } // mozilla
65 nsDocShellLoadInfo::nsDocShellLoadInfo()
66 : mResultPrincipalURIIsSome(false)
67 , mLoadReplace(false)
68 , mInheritPrincipal(false)
69 , mPrincipalIsExplicit(false)
70 , mForceAllowDataURI(false)
71 , mOriginalFrameSrc(false)
72 , mSendReferrer(true)
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)
89 NS_INTERFACE_MAP_END
91 NS_IMETHODIMP
92 nsDocShellLoadInfo::GetReferrer(nsIURI** aReferrer)
94 NS_ENSURE_ARG_POINTER(aReferrer);
96 *aReferrer = mReferrer;
97 NS_IF_ADDREF(*aReferrer);
98 return NS_OK;
101 NS_IMETHODIMP
102 nsDocShellLoadInfo::SetReferrer(nsIURI* aReferrer)
104 mReferrer = aReferrer;
105 return NS_OK;
108 NS_IMETHODIMP
109 nsDocShellLoadInfo::GetOriginalURI(nsIURI** aOriginalURI)
111 NS_ENSURE_ARG_POINTER(aOriginalURI);
113 *aOriginalURI = mOriginalURI;
114 NS_IF_ADDREF(*aOriginalURI);
115 return NS_OK;
118 NS_IMETHODIMP
119 nsDocShellLoadInfo::SetOriginalURI(nsIURI* aOriginalURI)
121 mOriginalURI = aOriginalURI;
122 return NS_OK;
125 NS_IMETHODIMP
126 nsDocShellLoadInfo::GetResultPrincipalURI(nsIURI** aResultPrincipalURI)
128 NS_ENSURE_ARG_POINTER(aResultPrincipalURI);
130 *aResultPrincipalURI = mResultPrincipalURI;
131 NS_IF_ADDREF(*aResultPrincipalURI);
132 return NS_OK;
135 NS_IMETHODIMP
136 nsDocShellLoadInfo::SetResultPrincipalURI(nsIURI* aResultPrincipalURI)
138 mResultPrincipalURI = aResultPrincipalURI;
139 return NS_OK;
142 NS_IMETHODIMP
143 nsDocShellLoadInfo::GetResultPrincipalURIIsSome(bool* aIsSome)
145 *aIsSome = mResultPrincipalURIIsSome;
146 return NS_OK;
149 NS_IMETHODIMP
150 nsDocShellLoadInfo::SetResultPrincipalURIIsSome(bool aIsSome)
152 mResultPrincipalURIIsSome = aIsSome;
153 return NS_OK;
156 NS_IMETHODIMP
157 nsDocShellLoadInfo::GetLoadReplace(bool* aLoadReplace)
159 *aLoadReplace = mLoadReplace;
160 return NS_OK;
163 NS_IMETHODIMP
164 nsDocShellLoadInfo::SetLoadReplace(bool aLoadReplace)
166 mLoadReplace = aLoadReplace;
167 return NS_OK;
170 NS_IMETHODIMP
171 nsDocShellLoadInfo::GetTriggeringPrincipal(nsIPrincipal** aTriggeringPrincipal)
173 NS_ENSURE_ARG_POINTER(aTriggeringPrincipal);
174 NS_IF_ADDREF(*aTriggeringPrincipal = mTriggeringPrincipal);
175 return NS_OK;
178 NS_IMETHODIMP
179 nsDocShellLoadInfo::SetTriggeringPrincipal(nsIPrincipal* aTriggeringPrincipal)
181 mTriggeringPrincipal = aTriggeringPrincipal;
182 return NS_OK;
185 NS_IMETHODIMP
186 nsDocShellLoadInfo::GetInheritPrincipal(bool* aInheritPrincipal)
188 NS_ENSURE_ARG_POINTER(aInheritPrincipal);
189 *aInheritPrincipal = mInheritPrincipal;
190 return NS_OK;
193 NS_IMETHODIMP
194 nsDocShellLoadInfo::SetInheritPrincipal(bool aInheritPrincipal)
196 mInheritPrincipal = aInheritPrincipal;
197 return NS_OK;
200 NS_IMETHODIMP
201 nsDocShellLoadInfo::GetPrincipalIsExplicit(bool* aPrincipalIsExplicit)
203 *aPrincipalIsExplicit = mPrincipalIsExplicit;
204 return NS_OK;
207 NS_IMETHODIMP
208 nsDocShellLoadInfo::SetPrincipalIsExplicit(bool aPrincipalIsExplicit)
210 mPrincipalIsExplicit = aPrincipalIsExplicit;
211 return NS_OK;
214 NS_IMETHODIMP
215 nsDocShellLoadInfo::GetForceAllowDataURI(bool* aForceAllowDataURI)
217 *aForceAllowDataURI = mForceAllowDataURI;
218 return NS_OK;
221 NS_IMETHODIMP
222 nsDocShellLoadInfo::SetForceAllowDataURI(bool aForceAllowDataURI)
224 mForceAllowDataURI = aForceAllowDataURI;
225 return NS_OK;
228 NS_IMETHODIMP
229 nsDocShellLoadInfo::GetOriginalFrameSrc(bool* aOriginalFrameSrc)
231 *aOriginalFrameSrc = mOriginalFrameSrc;
232 return NS_OK;
235 NS_IMETHODIMP
236 nsDocShellLoadInfo::SetOriginalFrameSrc(bool aOriginalFrameSrc)
238 mOriginalFrameSrc = aOriginalFrameSrc;
239 return NS_OK;
242 NS_IMETHODIMP
243 nsDocShellLoadInfo::GetLoadType(nsDocShellInfoLoadType* aLoadType)
245 NS_ENSURE_ARG_POINTER(aLoadType);
247 *aLoadType = mLoadType;
248 return NS_OK;
251 NS_IMETHODIMP
252 nsDocShellLoadInfo::SetLoadType(nsDocShellInfoLoadType aLoadType)
254 mLoadType = aLoadType;
255 return NS_OK;
258 NS_IMETHODIMP
259 nsDocShellLoadInfo::GetSHEntry(nsISHEntry** aSHEntry)
261 NS_ENSURE_ARG_POINTER(aSHEntry);
263 *aSHEntry = mSHEntry;
264 NS_IF_ADDREF(*aSHEntry);
265 return NS_OK;
268 NS_IMETHODIMP
269 nsDocShellLoadInfo::SetSHEntry(nsISHEntry* aSHEntry)
271 mSHEntry = aSHEntry;
272 return NS_OK;
275 NS_IMETHODIMP
276 nsDocShellLoadInfo::GetTarget(char16_t** aTarget)
278 NS_ENSURE_ARG_POINTER(aTarget);
280 *aTarget = ToNewUnicode(mTarget);
282 return NS_OK;
285 NS_IMETHODIMP
286 nsDocShellLoadInfo::SetTarget(const char16_t* aTarget)
288 mTarget.Assign(aTarget);
289 return NS_OK;
292 NS_IMETHODIMP
293 nsDocShellLoadInfo::GetPostDataStream(nsIInputStream** aResult)
295 NS_ENSURE_ARG_POINTER(aResult);
297 *aResult = mPostDataStream;
299 NS_IF_ADDREF(*aResult);
300 return NS_OK;
303 NS_IMETHODIMP
304 nsDocShellLoadInfo::SetPostDataStream(nsIInputStream* aStream)
306 mPostDataStream = aStream;
307 return NS_OK;
310 NS_IMETHODIMP
311 nsDocShellLoadInfo::GetHeadersStream(nsIInputStream** aHeadersStream)
313 NS_ENSURE_ARG_POINTER(aHeadersStream);
314 *aHeadersStream = mHeadersStream;
315 NS_IF_ADDREF(*aHeadersStream);
316 return NS_OK;
318 NS_IMETHODIMP
319 nsDocShellLoadInfo::SetHeadersStream(nsIInputStream* aHeadersStream)
321 mHeadersStream = aHeadersStream;
322 return NS_OK;
325 NS_IMETHODIMP
326 nsDocShellLoadInfo::GetSendReferrer(bool* aSendReferrer)
328 NS_ENSURE_ARG_POINTER(aSendReferrer);
330 *aSendReferrer = mSendReferrer;
331 return NS_OK;
334 NS_IMETHODIMP
335 nsDocShellLoadInfo::SetSendReferrer(bool aSendReferrer)
337 mSendReferrer = aSendReferrer;
338 return NS_OK;
341 NS_IMETHODIMP
342 nsDocShellLoadInfo::GetReferrerPolicy(
343 nsDocShellInfoReferrerPolicy* aReferrerPolicy)
345 *aReferrerPolicy = mReferrerPolicy;
346 return NS_OK;
349 NS_IMETHODIMP
350 nsDocShellLoadInfo::SetReferrerPolicy(
351 nsDocShellInfoReferrerPolicy aReferrerPolicy)
353 mReferrerPolicy = aReferrerPolicy;
354 return NS_OK;
357 NS_IMETHODIMP
358 nsDocShellLoadInfo::GetIsSrcdocLoad(bool* aIsSrcdocLoad)
360 *aIsSrcdocLoad = mIsSrcdocLoad;
361 return NS_OK;
364 NS_IMETHODIMP
365 nsDocShellLoadInfo::GetSrcdocData(nsAString& aSrcdocData)
367 aSrcdocData = mSrcdocData;
368 return NS_OK;
371 NS_IMETHODIMP
372 nsDocShellLoadInfo::SetSrcdocData(const nsAString& aSrcdocData)
374 mSrcdocData = aSrcdocData;
375 mIsSrcdocLoad = true;
376 return NS_OK;
379 NS_IMETHODIMP
380 nsDocShellLoadInfo::GetSourceDocShell(nsIDocShell** aSourceDocShell)
382 MOZ_ASSERT(aSourceDocShell);
383 nsCOMPtr<nsIDocShell> result = mSourceDocShell;
384 result.forget(aSourceDocShell);
385 return NS_OK;
388 NS_IMETHODIMP
389 nsDocShellLoadInfo::SetSourceDocShell(nsIDocShell* aSourceDocShell)
391 mSourceDocShell = aSourceDocShell;
392 return NS_OK;
395 NS_IMETHODIMP
396 nsDocShellLoadInfo::GetBaseURI(nsIURI** aBaseURI)
398 NS_ENSURE_ARG_POINTER(aBaseURI);
400 *aBaseURI = mBaseURI;
401 NS_IF_ADDREF(*aBaseURI);
402 return NS_OK;
405 NS_IMETHODIMP
406 nsDocShellLoadInfo::SetBaseURI(nsIURI* aBaseURI)
408 mBaseURI = aBaseURI;
409 return NS_OK;