Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_LoadInfo_h
8 : #define mozilla_LoadInfo_h
9 :
10 : #include "nsIContentPolicy.h"
11 : #include "nsILoadInfo.h"
12 : #include "nsIPrincipal.h"
13 : #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
14 : #include "nsIURI.h"
15 : #include "nsTArray.h"
16 :
17 : #include "mozilla/BasePrincipal.h"
18 : #include "mozilla/dom/ClientInfo.h"
19 : #include "mozilla/dom/ServiceWorkerDescriptor.h"
20 :
21 : class nsINode;
22 : class nsPIDOMWindowOuter;
23 :
24 : namespace mozilla {
25 :
26 : namespace dom {
27 : class PerformanceStorage;
28 : class XMLHttpRequestMainThread;
29 : }
30 :
31 : namespace net {
32 : class OptionalLoadInfoArgs;
33 : } // namespace net
34 :
35 : namespace ipc {
36 : // we have to forward declare that function so we can use it as a friend.
37 : nsresult
38 : LoadInfoArgsToLoadInfo(const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
39 : nsILoadInfo** outLoadInfo);
40 : } // namespace ipc
41 :
42 : namespace net {
43 :
44 : typedef nsTArray<nsCOMPtr<nsIRedirectHistoryEntry>> RedirectHistoryArray;
45 :
46 : /**
47 : * Class that provides an nsILoadInfo implementation.
48 : */
49 : class LoadInfo final : public nsILoadInfo
50 : {
51 : public:
52 : NS_DECL_ISUPPORTS
53 : NS_DECL_NSILOADINFO
54 :
55 : // aLoadingPrincipal MUST NOT BE NULL.
56 : LoadInfo(nsIPrincipal* aLoadingPrincipal,
57 : nsIPrincipal* aTriggeringPrincipal,
58 : nsINode* aLoadingContext,
59 : nsSecurityFlags aSecurityFlags,
60 : nsContentPolicyType aContentPolicyType,
61 : const Maybe<mozilla::dom::ClientInfo>& aLoadingClientInfo
62 : = Maybe<mozilla::dom::ClientInfo>(),
63 : const Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController
64 : = Maybe<mozilla::dom::ServiceWorkerDescriptor>());
65 :
66 : // Constructor used for TYPE_DOCUMENT loads which have a different
67 : // loadingContext than other loads. This ContextForTopLevelLoad is
68 : // only used for content policy checks.
69 : LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
70 : nsIPrincipal* aTriggeringPrincipal,
71 : nsISupports* aContextForTopLevelLoad,
72 : nsSecurityFlags aSecurityFlags);
73 :
74 : // create an exact copy of the loadinfo
75 : already_AddRefed<nsILoadInfo> Clone() const;
76 : // hands off!!! don't use CloneWithNewSecFlags unless you know
77 : // exactly what you are doing - it should only be used within
78 : // nsBaseChannel::Redirect()
79 : already_AddRefed<nsILoadInfo>
80 : CloneWithNewSecFlags(nsSecurityFlags aSecurityFlags) const;
81 : // creates a copy of the loadinfo which is appropriate to use for a
82 : // separate request. I.e. not for a redirect or an inner channel, but
83 : // when a separate request is made with the same security properties.
84 : already_AddRefed<nsILoadInfo> CloneForNewRequest() const;
85 :
86 : void SetIsPreflight();
87 : void SetUpgradeInsecureRequests();
88 : void SetBrowserUpgradeInsecureRequests();
89 : void SetBrowserWouldUpgradeInsecureRequests();
90 :
91 : private:
92 : // private constructor that is only allowed to be called from within
93 : // HttpChannelParent and FTPChannelParent declared as friends undeneath.
94 : // In e10s we can not serialize nsINode, hence we store the innerWindowID.
95 : // Please note that aRedirectChain uses swapElements.
96 : LoadInfo(nsIPrincipal* aLoadingPrincipal,
97 : nsIPrincipal* aTriggeringPrincipal,
98 : nsIPrincipal* aPrincipalToInherit,
99 : nsIPrincipal* aSandboxedLoadingPrincipal,
100 : nsIURI* aResultPrincipalURI,
101 : const Maybe<mozilla::dom::ClientInfo>& aClientInfo,
102 : const Maybe<mozilla::dom::ClientInfo>& aReservedClientInfo,
103 : const Maybe<mozilla::dom::ClientInfo>& aInitialClientInfo,
104 : const Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController,
105 : nsSecurityFlags aSecurityFlags,
106 : nsContentPolicyType aContentPolicyType,
107 : LoadTainting aTainting,
108 : bool aUpgradeInsecureRequests,
109 : bool aBrowserUpgradeInsecureRequests,
110 : bool aBrowserWouldUpgradeInsecureRequests,
111 : bool aVerifySignedContent,
112 : bool aEnforceSRI,
113 : bool aForceAllowDataURI,
114 : bool aAllowInsecureRedirectToDataURI,
115 : bool aSkipContentPolicyCheckForWebRequest,
116 : bool aForceInheritPrincipalDropped,
117 : uint64_t aInnerWindowID,
118 : uint64_t aOuterWindowID,
119 : uint64_t aParentOuterWindowID,
120 : uint64_t aTopOuterWindowID,
121 : uint64_t aFrameOuterWindowID,
122 : bool aEnforceSecurity,
123 : bool aInitialSecurityCheckDone,
124 : bool aIsThirdPartyRequest,
125 : bool aIsDocshellReload,
126 : const OriginAttributes& aOriginAttributes,
127 : RedirectHistoryArray& aRedirectChainIncludingInternalRedirects,
128 : RedirectHistoryArray& aRedirectChain,
129 : nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals,
130 : const nsTArray<uint64_t>& aAncestorOuterWindowIDs,
131 : const nsTArray<nsCString>& aUnsafeHeaders,
132 : bool aForcePreflight,
133 : bool aIsPreflight,
134 : bool aLoadTriggeredFromExternal,
135 : bool aServiceWorkerTaintingSynthesized);
136 : LoadInfo(const LoadInfo& rhs);
137 :
138 : NS_IMETHOD GetRedirects(JSContext* aCx, JS::MutableHandle<JS::Value> aRedirects,
139 : const RedirectHistoryArray& aArra);
140 :
141 : friend nsresult
142 : mozilla::ipc::LoadInfoArgsToLoadInfo(
143 : const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
144 : nsILoadInfo** outLoadInfo);
145 :
146 4752 : ~LoadInfo() = default;
147 :
148 : void ComputeIsThirdPartyContext(nsPIDOMWindowOuter* aOuterWindow);
149 :
150 : // This function is the *only* function which can change the securityflags
151 : // of a loadinfo. It only exists because of the XHR code. Don't call it
152 : // from anywhere else!
153 : void SetIncludeCookiesSecFlag();
154 : friend class mozilla::dom::XMLHttpRequestMainThread;
155 :
156 : // if you add a member, please also update the copy constructor and consider if
157 : // it should be merged from parent channel through ParentLoadInfoForwarderArgs.
158 : nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
159 : nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
160 : nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
161 : nsCOMPtr<nsIPrincipal> mSandboxedLoadingPrincipal;
162 : nsCOMPtr<nsIURI> mResultPrincipalURI;
163 :
164 : Maybe<mozilla::dom::ClientInfo> mClientInfo;
165 : UniquePtr<mozilla::dom::ClientSource> mReservedClientSource;
166 : Maybe<mozilla::dom::ClientInfo> mReservedClientInfo;
167 : Maybe<mozilla::dom::ClientInfo> mInitialClientInfo;
168 : Maybe<mozilla::dom::ServiceWorkerDescriptor> mController;
169 : RefPtr<mozilla::dom::PerformanceStorage> mPerformanceStorage;
170 :
171 : nsWeakPtr mLoadingContext;
172 : nsWeakPtr mContextForTopLevelLoad;
173 : nsSecurityFlags mSecurityFlags;
174 : nsContentPolicyType mInternalContentPolicyType;
175 : LoadTainting mTainting;
176 : bool mUpgradeInsecureRequests;
177 : bool mBrowserUpgradeInsecureRequests;
178 : bool mBrowserWouldUpgradeInsecureRequests;
179 : bool mVerifySignedContent;
180 : bool mEnforceSRI;
181 : bool mForceAllowDataURI;
182 : bool mAllowInsecureRedirectToDataURI;
183 : bool mSkipContentPolicyCheckForWebRequest;
184 : bool mOriginalFrameSrcLoad;
185 : bool mForceInheritPrincipalDropped;
186 : uint64_t mInnerWindowID;
187 : uint64_t mOuterWindowID;
188 : uint64_t mParentOuterWindowID;
189 : uint64_t mTopOuterWindowID;
190 : uint64_t mFrameOuterWindowID;
191 : bool mEnforceSecurity;
192 : bool mInitialSecurityCheckDone;
193 : bool mIsThirdPartyContext;
194 : bool mIsDocshellReload;
195 : OriginAttributes mOriginAttributes;
196 : RedirectHistoryArray mRedirectChainIncludingInternalRedirects;
197 : RedirectHistoryArray mRedirectChain;
198 : nsTArray<nsCOMPtr<nsIPrincipal>> mAncestorPrincipals;
199 : nsTArray<uint64_t> mAncestorOuterWindowIDs;
200 : nsTArray<nsCString> mCorsUnsafeHeaders;
201 : bool mForcePreflight;
202 : bool mIsPreflight;
203 : bool mLoadTriggeredFromExternal;
204 : bool mServiceWorkerTaintingSynthesized;
205 : };
206 :
207 : } // namespace net
208 : } // namespace mozilla
209 :
210 : #endif // mozilla_LoadInfo_h
211 :
|