/src/mozilla-central/netwerk/base/LoadInfo.h
Line | Count | Source |
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 | | nsIPrincipal* aTopLevelPrincipal, |
101 | | nsIPrincipal* aTopLevelStorageAreaPrincipal, |
102 | | nsIURI* aResultPrincipalURI, |
103 | | const Maybe<mozilla::dom::ClientInfo>& aClientInfo, |
104 | | const Maybe<mozilla::dom::ClientInfo>& aReservedClientInfo, |
105 | | const Maybe<mozilla::dom::ClientInfo>& aInitialClientInfo, |
106 | | const Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController, |
107 | | nsSecurityFlags aSecurityFlags, |
108 | | nsContentPolicyType aContentPolicyType, |
109 | | LoadTainting aTainting, |
110 | | bool aUpgradeInsecureRequests, |
111 | | bool aBrowserUpgradeInsecureRequests, |
112 | | bool aBrowserWouldUpgradeInsecureRequests, |
113 | | bool aVerifySignedContent, |
114 | | bool aEnforceSRI, |
115 | | bool aForceAllowDataURI, |
116 | | bool aAllowInsecureRedirectToDataURI, |
117 | | bool aSkipContentPolicyCheckForWebRequest, |
118 | | bool aForceInheritPrincipalDropped, |
119 | | uint64_t aInnerWindowID, |
120 | | uint64_t aOuterWindowID, |
121 | | uint64_t aParentOuterWindowID, |
122 | | uint64_t aTopOuterWindowID, |
123 | | uint64_t aFrameOuterWindowID, |
124 | | bool aEnforceSecurity, |
125 | | bool aInitialSecurityCheckDone, |
126 | | bool aIsThirdPartyRequest, |
127 | | bool aIsDocshellReload, |
128 | | bool aSendCSPViolationEvents, |
129 | | const OriginAttributes& aOriginAttributes, |
130 | | RedirectHistoryArray& aRedirectChainIncludingInternalRedirects, |
131 | | RedirectHistoryArray& aRedirectChain, |
132 | | nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals, |
133 | | const nsTArray<uint64_t>& aAncestorOuterWindowIDs, |
134 | | const nsTArray<nsCString>& aUnsafeHeaders, |
135 | | bool aForcePreflight, |
136 | | bool aIsPreflight, |
137 | | bool aLoadTriggeredFromExternal, |
138 | | bool aServiceWorkerTaintingSynthesized, |
139 | | bool aDocumentHasUserInteracted); |
140 | | LoadInfo(const LoadInfo& rhs); |
141 | | |
142 | | NS_IMETHOD GetRedirects(JSContext* aCx, JS::MutableHandle<JS::Value> aRedirects, |
143 | | const RedirectHistoryArray& aArra); |
144 | | |
145 | | friend nsresult |
146 | | mozilla::ipc::LoadInfoArgsToLoadInfo( |
147 | | const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs, |
148 | | nsILoadInfo** outLoadInfo); |
149 | | |
150 | 5 | ~LoadInfo() = default; |
151 | | |
152 | | void ComputeIsThirdPartyContext(nsPIDOMWindowOuter* aOuterWindow); |
153 | | |
154 | | // This function is the *only* function which can change the securityflags |
155 | | // of a loadinfo. It only exists because of the XHR code. Don't call it |
156 | | // from anywhere else! |
157 | | void SetIncludeCookiesSecFlag(); |
158 | | friend class mozilla::dom::XMLHttpRequestMainThread; |
159 | | |
160 | | // if you add a member, please also update the copy constructor and consider if |
161 | | // it should be merged from parent channel through ParentLoadInfoForwarderArgs. |
162 | | nsCOMPtr<nsIPrincipal> mLoadingPrincipal; |
163 | | nsCOMPtr<nsIPrincipal> mTriggeringPrincipal; |
164 | | nsCOMPtr<nsIPrincipal> mPrincipalToInherit; |
165 | | nsCOMPtr<nsIPrincipal> mSandboxedLoadingPrincipal; |
166 | | nsCOMPtr<nsIPrincipal> mTopLevelPrincipal; |
167 | | nsCOMPtr<nsIPrincipal> mTopLevelStorageAreaPrincipal; |
168 | | nsCOMPtr<nsIURI> mResultPrincipalURI; |
169 | | |
170 | | Maybe<mozilla::dom::ClientInfo> mClientInfo; |
171 | | UniquePtr<mozilla::dom::ClientSource> mReservedClientSource; |
172 | | Maybe<mozilla::dom::ClientInfo> mReservedClientInfo; |
173 | | Maybe<mozilla::dom::ClientInfo> mInitialClientInfo; |
174 | | Maybe<mozilla::dom::ServiceWorkerDescriptor> mController; |
175 | | RefPtr<mozilla::dom::PerformanceStorage> mPerformanceStorage; |
176 | | |
177 | | nsWeakPtr mLoadingContext; |
178 | | nsWeakPtr mContextForTopLevelLoad; |
179 | | nsSecurityFlags mSecurityFlags; |
180 | | nsContentPolicyType mInternalContentPolicyType; |
181 | | LoadTainting mTainting; |
182 | | bool mUpgradeInsecureRequests; |
183 | | bool mBrowserUpgradeInsecureRequests; |
184 | | bool mBrowserWouldUpgradeInsecureRequests; |
185 | | bool mVerifySignedContent; |
186 | | bool mEnforceSRI; |
187 | | bool mForceAllowDataURI; |
188 | | bool mAllowInsecureRedirectToDataURI; |
189 | | bool mSkipContentPolicyCheckForWebRequest; |
190 | | bool mOriginalFrameSrcLoad; |
191 | | bool mForceInheritPrincipalDropped; |
192 | | uint64_t mInnerWindowID; |
193 | | uint64_t mOuterWindowID; |
194 | | uint64_t mParentOuterWindowID; |
195 | | uint64_t mTopOuterWindowID; |
196 | | uint64_t mFrameOuterWindowID; |
197 | | bool mEnforceSecurity; |
198 | | bool mInitialSecurityCheckDone; |
199 | | bool mIsThirdPartyContext; |
200 | | bool mIsDocshellReload; |
201 | | bool mSendCSPViolationEvents; |
202 | | OriginAttributes mOriginAttributes; |
203 | | RedirectHistoryArray mRedirectChainIncludingInternalRedirects; |
204 | | RedirectHistoryArray mRedirectChain; |
205 | | nsTArray<nsCOMPtr<nsIPrincipal>> mAncestorPrincipals; |
206 | | nsTArray<uint64_t> mAncestorOuterWindowIDs; |
207 | | nsTArray<nsCString> mCorsUnsafeHeaders; |
208 | | |
209 | | mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED mTrackerBlockedReason; |
210 | | |
211 | | bool mForcePreflight; |
212 | | bool mIsPreflight; |
213 | | bool mLoadTriggeredFromExternal; |
214 | | bool mServiceWorkerTaintingSynthesized; |
215 | | |
216 | | bool mIsTracker; |
217 | | bool mIsTrackerBlocked; |
218 | | bool mDocumentHasUserInteracted; |
219 | | }; |
220 | | |
221 | | } // namespace net |
222 | | } // namespace mozilla |
223 | | |
224 | | #endif // mozilla_LoadInfo_h |
225 | | |