HttpBaseChannel.h (48245B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et tw=80 : */ 3 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef mozilla_net_HttpBaseChannel_h 9 #define mozilla_net_HttpBaseChannel_h 10 11 #include <utility> 12 13 #include "OpaqueResponseUtils.h" 14 #include "mozilla/AtomicBitfields.h" 15 #include "mozilla/Atomics.h" 16 #include "mozilla/CompactPair.h" 17 #include "mozilla/dom/DOMTypes.h" 18 #include "mozilla/DataMutex.h" 19 #include <mozilla/Maybe.h> 20 #include "mozilla/net/DNS.h" 21 #include "mozilla/net/NeckoChannelParams.h" 22 #include "mozilla/net/NeckoCommon.h" 23 #include "mozilla/net/PrivateBrowsingChannel.h" 24 #include "nsCOMPtr.h" 25 #include "nsHashPropertyBag.h" 26 #include "nsHttp.h" 27 #include "nsHttpHandler.h" 28 #include "nsHttpRequestHead.h" 29 #include "nsIClassOfService.h" 30 #include "nsIClassifiedChannel.h" 31 #include "nsIConsoleReportCollector.h" 32 #include "nsIEncodedChannel.h" 33 #include "nsIForcePendingChannel.h" 34 #include "nsIFormPOSTActionChannel.h" 35 #include "nsIHttpChannel.h" 36 #include "nsIHttpChannelInternal.h" 37 #include "nsILoadInfo.h" 38 #include "nsIResumableChannel.h" 39 #include "nsIStringEnumerator.h" 40 #include "nsISupportsPriority.h" 41 #include "nsIThrottledInputChannel.h" 42 #include "nsITimedChannel.h" 43 #include "nsITraceableChannel.h" 44 #include "nsITransportSecurityInfo.h" 45 #include "nsIURI.h" 46 #include "nsIUploadChannel2.h" 47 #include "nsStringEnumerator.h" 48 #include "nsStringFwd.h" 49 #include "nsTArray.h" 50 #include "nsThreadUtils.h" 51 52 #define HTTP_BASE_CHANNEL_IID \ 53 {0x9d5cde03, 0xe6e9, 0x4612, {0xbf, 0xef, 0xbb, 0x66, 0xf3, 0xbb, 0x74, 0x46}} 54 55 class nsIProgressEventSink; 56 class nsISecurityConsoleMessage; 57 class nsIPrincipal; 58 59 namespace mozilla { 60 61 namespace dom { 62 class PerformanceStorage; 63 class ContentParent; 64 } // namespace dom 65 66 class LogCollector; 67 68 namespace net { 69 extern mozilla::LazyLogModule gHttpLog; 70 71 class OpaqueResponseBlocker; 72 class PreferredAlternativeDataTypeParams; 73 74 // These need to be kept in sync with 75 // "browser.opaqueResponseBlocking.filterFetchResponse" 76 enum class OpaqueResponseFilterFetch { Never, AllowedByORB, BlockedByORB, All }; 77 78 /* 79 * This class is a partial implementation of nsIHttpChannel. It contains code 80 * shared by nsHttpChannel and HttpChannelChild. 81 * - Note that this class has nothing to do with nsBaseChannel, which is an 82 * earlier effort at a base class for channels that somehow never made it all 83 * the way to the HTTP channel. 84 */ 85 class HttpBaseChannel : public nsHashPropertyBag, 86 public nsIEncodedChannel, 87 public nsIHttpChannel, 88 public nsIHttpChannelInternal, 89 public nsIFormPOSTActionChannel, 90 public nsIUploadChannel2, 91 public nsISupportsPriority, 92 public nsIClassOfService, 93 public nsIResumableChannel, 94 public nsITraceableChannel, 95 public PrivateBrowsingChannel<HttpBaseChannel>, 96 public nsITimedChannel, 97 public nsIForcePendingChannel, 98 public nsIConsoleReportCollector, 99 public nsIThrottledInputChannel, 100 public nsIClassifiedChannel { 101 protected: 102 virtual ~HttpBaseChannel(); 103 104 public: 105 NS_DECL_ISUPPORTS_INHERITED 106 NS_DECL_NSIUPLOADCHANNEL 107 NS_DECL_NSIFORMPOSTACTIONCHANNEL 108 NS_DECL_NSIUPLOADCHANNEL2 109 NS_DECL_NSITRACEABLECHANNEL 110 NS_DECL_NSITIMEDCHANNEL 111 NS_DECL_NSITHROTTLEDINPUTCHANNEL 112 NS_DECL_NSICLASSIFIEDCHANNEL 113 114 NS_INLINE_DECL_STATIC_IID(HTTP_BASE_CHANNEL_IID) 115 116 HttpBaseChannel(); 117 118 [[nodiscard]] virtual nsresult Init(nsIURI* aURI, uint32_t aCaps, 119 nsProxyInfo* aProxyInfo, 120 uint32_t aProxyResolveFlags, 121 nsIURI* aProxyURI, uint64_t aChannelId, 122 nsILoadInfo* aLoadInfo); 123 124 // nsIRequest 125 NS_IMETHOD GetName(nsACString& aName) override; 126 NS_IMETHOD IsPending(bool* aIsPending) override; 127 NS_IMETHOD GetStatus(nsresult* aStatus) override; 128 NS_IMETHOD GetLoadGroup(nsILoadGroup** aLoadGroup) override; 129 NS_IMETHOD SetLoadGroup(nsILoadGroup* aLoadGroup) override; 130 NS_IMETHOD GetLoadFlags(nsLoadFlags* aLoadFlags) override; 131 NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) override; 132 NS_IMETHOD GetTRRMode(nsIRequest::TRRMode* aTRRMode) override; 133 NS_IMETHOD SetTRRMode(nsIRequest::TRRMode aTRRMode) override; 134 NS_IMETHOD SetDocshellUserAgentOverride(); 135 136 // nsIChannel 137 NS_IMETHOD GetOriginalURI(nsIURI** aOriginalURI) override; 138 NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) override; 139 NS_IMETHOD GetURI(nsIURI** aURI) override; 140 NS_IMETHOD GetOwner(nsISupports** aOwner) override; 141 NS_IMETHOD SetOwner(nsISupports* aOwner) override; 142 NS_IMETHOD GetLoadInfo(nsILoadInfo** aLoadInfo) override; 143 NS_IMETHOD SetLoadInfo(nsILoadInfo* aLoadInfo) override; 144 NS_IMETHOD GetIsDocument(bool* aIsDocument) override; 145 NS_IMETHOD GetNotificationCallbacks( 146 nsIInterfaceRequestor** aCallbacks) override; 147 NS_IMETHOD SetNotificationCallbacks( 148 nsIInterfaceRequestor* aCallbacks) override; 149 NS_IMETHOD GetContentType(nsACString& aContentType) override; 150 NS_IMETHOD SetContentType(const nsACString& aContentType) override; 151 NS_IMETHOD GetContentCharset(nsACString& aContentCharset) override; 152 NS_IMETHOD SetContentCharset(const nsACString& aContentCharset) override; 153 NS_IMETHOD GetContentDisposition(uint32_t* aContentDisposition) override; 154 NS_IMETHOD SetContentDisposition(uint32_t aContentDisposition) override; 155 NS_IMETHOD GetContentDispositionFilename( 156 nsAString& aContentDispositionFilename) override; 157 NS_IMETHOD SetContentDispositionFilename( 158 const nsAString& aContentDispositionFilename) override; 159 NS_IMETHOD GetContentDispositionHeader( 160 nsACString& aContentDispositionHeader) override; 161 NS_IMETHOD GetContentLength(int64_t* aContentLength) override; 162 NS_IMETHOD SetContentLength(int64_t aContentLength) override; 163 NS_IMETHOD Open(nsIInputStream** aResult) override; 164 NS_IMETHOD GetBlockAuthPrompt(bool* aValue) override; 165 NS_IMETHOD SetBlockAuthPrompt(bool aValue) override; 166 NS_IMETHOD GetCanceled(bool* aCanceled) override; 167 168 // nsIEncodedChannel 169 NS_IMETHOD GetApplyConversion(bool* value) override; 170 NS_IMETHOD SetApplyConversion(bool value) override; 171 NS_IMETHOD GetContentEncodings(nsIUTF8StringEnumerator** aEncodings) override; 172 // Note: Doesn't modify the Content-Encoding 173 NS_IMETHOD DoApplyContentConversions(nsIStreamListener* aNextListener, 174 nsIStreamListener** aNewNextListener, 175 nsISupports* aCtxt) override; 176 NS_IMETHOD SetHasContentDecompressed(bool value) override; 177 NS_IMETHOD GetHasContentDecompressed(bool* value) override; 178 179 // HttpBaseChannel::nsIHttpChannel 180 NS_IMETHOD GetRequestMethod(nsACString& aMethod) override; 181 NS_IMETHOD SetRequestMethod(const nsACString& aMethod) override; 182 NS_IMETHOD GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) override; 183 NS_IMETHOD SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) override; 184 NS_IMETHOD SetReferrerInfoWithoutClone( 185 nsIReferrerInfo* aReferrerInfo) override; 186 NS_IMETHOD GetRequestHeader(const nsACString& aHeader, 187 nsACString& aValue) override; 188 NS_IMETHOD SetRequestHeader(const nsACString& aHeader, 189 const nsACString& aValue, bool aMerge) override; 190 NS_IMETHOD SetNewReferrerInfo(const nsACString& aUrl, 191 nsIReferrerInfo::ReferrerPolicyIDL aPolicy, 192 bool aSendReferrer) override; 193 NS_IMETHOD SetEmptyRequestHeader(const nsACString& aHeader) override; 194 NS_IMETHOD VisitRequestHeaders(nsIHttpHeaderVisitor* visitor) override; 195 NS_IMETHOD VisitNonDefaultRequestHeaders( 196 nsIHttpHeaderVisitor* visitor) override; 197 NS_IMETHOD ShouldStripRequestBodyHeader(const nsACString& aMethod, 198 bool* aResult) override; 199 NS_IMETHOD GetResponseHeader(const nsACString& header, 200 nsACString& value) override; 201 NS_IMETHOD SetResponseHeader(const nsACString& header, 202 const nsACString& value, bool merge) override; 203 NS_IMETHOD VisitResponseHeaders(nsIHttpHeaderVisitor* visitor) override; 204 NS_IMETHOD GetOriginalResponseHeader(const nsACString& aHeader, 205 nsIHttpHeaderVisitor* aVisitor) override; 206 NS_IMETHOD VisitOriginalResponseHeaders( 207 nsIHttpHeaderVisitor* aVisitor) override; 208 NS_IMETHOD GetAllowSTS(bool* value) override; 209 NS_IMETHOD SetAllowSTS(bool value) override; 210 NS_IMETHOD GetRedirectionLimit(uint32_t* value) override; 211 NS_IMETHOD SetRedirectionLimit(uint32_t value) override; 212 NS_IMETHOD IsNoStoreResponse(bool* value) override; 213 NS_IMETHOD IsNoCacheResponse(bool* value) override; 214 NS_IMETHOD GetResponseStatus(uint32_t* aValue) override; 215 NS_IMETHOD GetResponseStatusText(nsACString& aValue) override; 216 NS_IMETHOD GetRequestSucceeded(bool* aValue) override; 217 NS_IMETHOD RedirectTo(nsIURI* newURI) override; 218 NS_IMETHOD TransparentRedirectTo(nsIURI* newURI) override; 219 NS_IMETHOD UpgradeToSecure() override; 220 NS_IMETHOD GetRequestObserversCalled(bool* aCalled) override; 221 NS_IMETHOD SetRequestObserversCalled(bool aCalled) override; 222 NS_IMETHOD GetRequestContextID(uint64_t* aRCID) override; 223 NS_IMETHOD GetTransferSize(uint64_t* aTransferSize) override; 224 NS_IMETHOD GetRequestSize(uint64_t* aRequestSize) override; 225 NS_IMETHOD GetDecodedBodySize(uint64_t* aDecodedBodySize) override; 226 NS_IMETHOD GetEncodedBodySize(uint64_t* aEncodedBodySize) override; 227 NS_IMETHOD GetSupportsHTTP3(bool* aSupportsHTTP3) override; 228 NS_IMETHOD GetHasHTTPSRR(bool* aHasHTTPSRR) override; 229 NS_IMETHOD SetRequestContextID(uint64_t aRCID) override; 230 NS_IMETHOD GetIsMainDocumentChannel(bool* aValue) override; 231 NS_IMETHOD SetIsMainDocumentChannel(bool aValue) override; 232 NS_IMETHOD GetIsUserAgentHeaderOutdated(bool* aValue) override; 233 NS_IMETHOD SetIsUserAgentHeaderOutdated(bool aValue) override; 234 NS_IMETHOD GetProtocolVersion(nsACString& aProtocolVersion) override; 235 NS_IMETHOD GetChannelId(uint64_t* aChannelId) override; 236 NS_IMETHOD SetChannelId(uint64_t aChannelId) override; 237 NS_IMETHOD GetTopLevelContentWindowId(uint64_t* aContentWindowId) override; 238 NS_IMETHOD SetTopLevelContentWindowId(uint64_t aContentWindowId) override; 239 NS_IMETHOD GetBrowserId(uint64_t* aId) override; 240 NS_IMETHOD SetBrowserId(uint64_t aId) override; 241 NS_IMETHOD GetIsProxyUsed(bool* aIsProxyUsed) override; 242 243 using nsIClassifiedChannel::IsThirdPartyTrackingResource; 244 245 virtual void SetSource(UniquePtr<ProfileChunkedBuffer> aSource) override { 246 mSource = std::move(aSource); 247 } 248 249 // nsIHttpChannelInternal 250 NS_IMETHOD GetDocumentURI(nsIURI** aDocumentURI) override; 251 NS_IMETHOD SetDocumentURI(nsIURI* aDocumentURI) override; 252 NS_IMETHOD GetRequestVersion(uint32_t* major, uint32_t* minor) override; 253 NS_IMETHOD GetResponseVersion(uint32_t* major, uint32_t* minor) override; 254 NS_IMETHOD SetCookieHeaders( 255 const nsTArray<nsCString>& aCookieHeaders) override; 256 NS_IMETHOD GetThirdPartyFlags(uint32_t* aForce) override; 257 NS_IMETHOD SetThirdPartyFlags(uint32_t aForce) override; 258 NS_IMETHOD GetForceAllowThirdPartyCookie(bool* aForce) override; 259 NS_IMETHOD SetForceAllowThirdPartyCookie(bool aForce) override; 260 NS_IMETHOD GetChannelIsForDownload(bool* aChannelIsForDownload) override; 261 NS_IMETHOD SetChannelIsForDownload(bool aChannelIsForDownload) override; 262 NS_IMETHOD SetCacheKeysRedirectChain(nsTArray<nsCString>* cacheKeys) override; 263 NS_IMETHOD GetLocalAddress(nsACString& addr) override; 264 NS_IMETHOD GetLocalPort(int32_t* port) override; 265 NS_IMETHOD GetRemoteAddress(nsACString& addr) override; 266 NS_IMETHOD GetRemotePort(int32_t* port) override; 267 NS_IMETHOD GetOnlyConnect(bool* aOnlyConnect) override; 268 NS_IMETHOD SetConnectOnly(bool aTlsTunnel) override; 269 NS_IMETHOD GetAllowSpdy(bool* aAllowSpdy) override; 270 NS_IMETHOD SetAllowSpdy(bool aAllowSpdy) override; 271 NS_IMETHOD GetAllowHttp3(bool* aAllowHttp3) override; 272 NS_IMETHOD SetAllowHttp3(bool aAllowHttp3) override; 273 NS_IMETHOD GetAllowAltSvc(bool* aAllowAltSvc) override; 274 NS_IMETHOD SetAllowAltSvc(bool aAllowAltSvc) override; 275 NS_IMETHOD GetBeConservative(bool* aBeConservative) override; 276 NS_IMETHOD SetBeConservative(bool aBeConservative) override; 277 NS_IMETHOD GetBypassProxy(bool* aBypassProxy) override; 278 NS_IMETHOD SetBypassProxy(bool aBypassProxy) override; 279 bool BypassProxy(); 280 281 NS_IMETHOD GetIsTRRServiceChannel(bool* aTRR) override; 282 NS_IMETHOD SetIsTRRServiceChannel(bool aTRR) override; 283 NS_IMETHOD GetIsResolvedByTRR(bool* aResolvedByTRR) override; 284 NS_IMETHOD GetEffectiveTRRMode( 285 nsIRequest::TRRMode* aEffectiveTRRMode) override; 286 NS_IMETHOD GetTrrSkipReason(nsITRRSkipReason::value* aTrrSkipReason) override; 287 NS_IMETHOD GetIsLoadedBySocketProcess(bool* aResult) override; 288 NS_IMETHOD GetIsOCSP(bool* value) override; 289 NS_IMETHOD SetIsOCSP(bool value) override; 290 NS_IMETHOD GetTlsFlags(uint32_t* aTlsFlags) override; 291 NS_IMETHOD SetTlsFlags(uint32_t aTlsFlags) override; 292 NS_IMETHOD GetApiRedirectToURI(nsIURI** aApiRedirectToURI) override; 293 [[nodiscard]] virtual nsresult AddSecurityMessage( 294 const nsAString& aMessageTag, const nsAString& aMessageCategory); 295 NS_IMETHOD TakeAllSecurityMessages( 296 nsCOMArray<nsISecurityConsoleMessage>& aMessages) override; 297 NS_IMETHOD GetResponseTimeoutEnabled(bool* aEnable) override; 298 NS_IMETHOD SetResponseTimeoutEnabled(bool aEnable) override; 299 NS_IMETHOD GetInitialRwin(uint32_t* aRwin) override; 300 NS_IMETHOD SetInitialRwin(uint32_t aRwin) override; 301 NS_IMETHOD ForcePending(bool aForcePending) override; 302 NS_IMETHOD GetLastModifiedTime(PRTime* lastModifiedTime) override; 303 NS_IMETHOD GetCorsIncludeCredentials(bool* aInclude) override; 304 NS_IMETHOD SetCorsIncludeCredentials(bool aInclude) override; 305 NS_IMETHOD GetRequestMode(dom::RequestMode* aRequestMode) override; 306 NS_IMETHOD SetRequestMode(dom::RequestMode aRequestMode) override; 307 NS_IMETHOD GetRedirectMode(uint32_t* aRedirectMode) override; 308 NS_IMETHOD SetRedirectMode(uint32_t aRedirectMode) override; 309 NS_IMETHOD GetFetchCacheMode(uint32_t* aFetchCacheMode) override; 310 NS_IMETHOD SetFetchCacheMode(uint32_t aFetchCacheMode) override; 311 NS_IMETHOD GetTopWindowURI(nsIURI** aTopWindowURI) override; 312 NS_IMETHOD SetTopWindowURIIfUnknown(nsIURI* aTopWindowURI) override; 313 NS_IMETHOD GetProxyURI(nsIURI** proxyURI) override; 314 virtual void SetCorsPreflightParameters( 315 const nsTArray<nsCString>& unsafeHeaders, 316 bool aShouldStripRequestBodyHeader, bool aShouldStripAuthHeader) override; 317 virtual void SetAltDataForChild(bool aIsForChild) override; 318 virtual void DisableAltDataCache() override { 319 StoreDisableAltDataCache(true); 320 }; 321 322 NS_IMETHOD GetConnectionInfoHashKey( 323 nsACString& aConnectionInfoHashKey) override; 324 NS_IMETHOD GetLastRedirectFlags(uint32_t* aValue) override; 325 NS_IMETHOD SetLastRedirectFlags(uint32_t aValue) override; 326 NS_IMETHOD GetNavigationStartTimeStamp(TimeStamp* aTimeStamp) override; 327 NS_IMETHOD SetNavigationStartTimeStamp(TimeStamp aTimeStamp) override; 328 NS_IMETHOD CancelByURLClassifier(nsresult aErrorCode) override; 329 NS_IMETHOD SetIPv4Disabled(void) override; 330 NS_IMETHOD SetIPv6Disabled(void) override; 331 NS_IMETHOD GetCrossOriginOpenerPolicy( 332 nsILoadInfo::CrossOriginOpenerPolicy* aCrossOriginOpenerPolicy) override; 333 NS_IMETHOD ComputeCrossOriginOpenerPolicy( 334 nsILoadInfo::CrossOriginOpenerPolicy aInitiatorPolicy, 335 nsILoadInfo::CrossOriginOpenerPolicy* aOutPolicy) override; 336 NS_IMETHOD HasCrossOriginOpenerPolicyMismatch(bool* aIsMismatch) override; 337 NS_IMETHOD GetResponseEmbedderPolicy( 338 bool aIsOriginTrialCoepCredentiallessEnabled, 339 nsILoadInfo::CrossOriginEmbedderPolicy* aOutPolicy) override; 340 NS_IMETHOD GetOriginAgentClusterHeader(bool* aValue) override; 341 342 inline void CleanRedirectCacheChainIfNecessary() { 343 auto redirectedCachekeys = mRedirectedCachekeys.Lock(); 344 redirectedCachekeys.ref() = nullptr; 345 } 346 NS_IMETHOD HTTPUpgrade(const nsACString& aProtocolName, 347 nsIHttpUpgradeListener* aListener) override; 348 void DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() override; 349 350 NS_IMETHOD SetEarlyHintPreloaderId(uint64_t aEarlyHintPreloaderId) override; 351 NS_IMETHOD GetEarlyHintPreloaderId(uint64_t* aEarlyHintPreloaderId) override; 352 353 NS_IMETHOD SetEarlyHintLinkType(uint32_t aEarlyHintLinkType) override; 354 NS_IMETHOD GetEarlyHintLinkType(uint32_t* aEarlyHintLinkType) override; 355 356 NS_IMETHOD SetIsUserAgentHeaderModified(bool value) override; 357 NS_IMETHOD GetIsUserAgentHeaderModified(bool* value) override; 358 359 NS_IMETHOD GetLastTransportStatus(nsresult* aLastTransportStatus) override; 360 361 NS_IMETHOD GetCaps(uint32_t* aCaps) override { 362 if (!aCaps) { 363 return NS_ERROR_INVALID_ARG; 364 } 365 366 *aCaps = mCaps; 367 return NS_OK; 368 } 369 370 NS_IMETHOD SetClassicScriptHintCharset( 371 const nsAString& aClassicScriptHintCharset) override; 372 NS_IMETHOD GetClassicScriptHintCharset( 373 nsAString& aClassicScriptHintCharset) override; 374 375 NS_IMETHOD SetDocumentCharacterSet( 376 const nsAString& aDocumentCharacterSet) override; 377 NS_IMETHOD GetDocumentCharacterSet(nsAString& aDocumentCharacterSet) override; 378 379 virtual void SetConnectionInfo( 380 mozilla::net::nsHttpConnectionInfo* aCI) override; 381 382 // nsISupportsPriority 383 NS_IMETHOD GetPriority(int32_t* value) override; 384 NS_IMETHOD AdjustPriority(int32_t delta) override; 385 386 // nsIClassOfService 387 NS_IMETHOD GetClassFlags(uint32_t* outFlags) override { 388 *outFlags = mClassOfService.Flags(); 389 return NS_OK; 390 } 391 392 NS_IMETHOD GetIncremental(bool* outIncremental) override { 393 *outIncremental = mClassOfService.Incremental(); 394 return NS_OK; 395 } 396 397 NS_IMETHOD GetFetchPriority( 398 nsIClassOfService::FetchPriority* aFetchPriority) override { 399 *aFetchPriority = mClassOfService.FetchPriority(); 400 return NS_OK; 401 } 402 403 NS_IMETHOD SetFetchPriority( 404 nsIClassOfService::FetchPriority aFetchPriority) override { 405 mClassOfService.SetFetchPriority(aFetchPriority); 406 return NS_OK; 407 } 408 409 void SetFetchPriorityDOM(mozilla::dom::FetchPriority aPriority) override; 410 411 // nsIResumableChannel 412 NS_IMETHOD GetEntityID(nsACString& aEntityID) override; 413 414 // nsIConsoleReportCollector 415 void AddConsoleReport(uint32_t aErrorFlags, const nsACString& aCategory, 416 nsContentUtils::PropertiesFile aPropertiesFile, 417 const nsACString& aSourceFileURI, uint32_t aLineNumber, 418 uint32_t aColumnNumber, const nsACString& aMessageName, 419 const nsTArray<nsString>& aStringParams) override; 420 421 void FlushReportsToConsole( 422 uint64_t aInnerWindowID, 423 ReportAction aAction = ReportAction::Forget) override; 424 425 void FlushReportsToConsoleForServiceWorkerScope( 426 const nsACString& aScope, 427 ReportAction aAction = ReportAction::Forget) override; 428 429 void FlushConsoleReports( 430 dom::Document* aDocument, 431 ReportAction aAction = ReportAction::Forget) override; 432 433 void FlushConsoleReports( 434 nsILoadGroup* aLoadGroup, 435 ReportAction aAction = ReportAction::Forget) override; 436 437 void FlushConsoleReports(nsIConsoleReportCollector* aCollector) override; 438 439 void StealConsoleReports( 440 nsTArray<net::ConsoleReportCollected>& aReports) override; 441 442 void ClearConsoleReports() override; 443 444 class nsContentEncodings : public nsStringEnumeratorBase { 445 public: 446 NS_DECL_ISUPPORTS 447 NS_DECL_NSIUTF8STRINGENUMERATOR 448 449 using nsStringEnumeratorBase::GetNext; 450 451 nsContentEncodings(nsIHttpChannel* aChannel, const char* aEncodingHeader); 452 453 private: 454 virtual ~nsContentEncodings() = default; 455 456 [[nodiscard]] nsresult PrepareForNext(void); 457 458 // We do not own the buffer. The channel owns it. 459 const char* mEncodingHeader; 460 const char* mCurStart; // points to start of current header 461 const char* mCurEnd; // points to end of current header 462 463 // Hold a ref to our channel so that it can't go away and take the 464 // header with it. 465 nsCOMPtr<nsIHttpChannel> mChannel; 466 467 bool mReady; 468 }; 469 470 nsHttpResponseHead* GetResponseHead() const { return mResponseHead.get(); } 471 nsHttpRequestHead* GetRequestHead() { return &mRequestHead; } 472 nsHttpHeaderArray* GetResponseTrailers() const { 473 return mResponseTrailers.get(); 474 } 475 476 // Return the cloned HTTP Headers if available. 477 // The returned headers can be passed to SetDummyChannelForCachedResource 478 // to create a dummy channel with the same HTTP headers. 479 UniquePtr<nsHttpResponseHead> MaybeCloneResponseHeadForCachedResource(); 480 481 // Set this channel as a dummy channel for cached resources. 482 // 483 // If aMaybeResponseHead is provided, this uses the given HTTP headers. 484 // Otherwise this uses an empty HTTP headers. 485 void SetDummyChannelForCachedResource( 486 const nsHttpResponseHead* aMaybeResponseHead = nullptr); 487 488 const NetAddr& GetSelfAddr() { return mSelfAddr; } 489 const NetAddr& GetPeerAddr() { return mPeerAddr; } 490 491 [[nodiscard]] nsresult OverrideSecurityInfo( 492 nsITransportSecurityInfo* aSecurityInfo); 493 494 void LogORBError(const nsAString& aReason, 495 const OpaqueResponseBlockedTelemetryReason aTelemetryReason); 496 497 public: /* Necko internal use only... */ 498 int64_t GetAltDataLength() { return mAltDataLength; } 499 bool IsNavigation(); 500 501 bool IsDeliveringAltData() const { return LoadDeliveringAltData(); } 502 503 static void PropagateReferenceIfNeeded(nsIURI* aURI, 504 nsCOMPtr<nsIURI>& aRedirectURI); 505 506 // Return whether upon a redirect code of httpStatus for method, the 507 // request method should be rewritten to GET. 508 static bool ShouldRewriteRedirectToGET( 509 uint32_t httpStatus, nsHttpRequestHead::ParsedMethodType method); 510 511 [[nodiscard]] nsresult DoApplyContentConversionsInternal( 512 nsIStreamListener* aNextListener, nsIStreamListener** aNewNextListener, 513 bool aRemoveEncodings, nsISupports* aCtxt); 514 515 // Like nsIEncodedChannel::DoApplyConversions except context is set to 516 // mListenerContext. 517 [[nodiscard]] nsresult DoApplyContentConversions( 518 nsIStreamListener* aNextListener, nsIStreamListener** aNewNextListener); 519 520 void AddClassificationFlags(uint32_t aClassificationFlags, 521 bool aIsThirdParty); 522 523 const uint64_t& ChannelId() const { return mChannelId; } 524 525 nsresult InternalSetUploadStream(nsIInputStream* uploadStream, 526 int64_t aContentLength = -1, 527 bool aSetContentLengthHeader = false); 528 529 void SetUploadStreamHasHeaders(bool hasHeaders) { 530 StoreUploadStreamHasHeaders(hasHeaders); 531 } 532 533 virtual nsresult SetReferrerHeader(const nsACString& aReferrer, 534 bool aRespectBeforeConnect = true) { 535 if (aRespectBeforeConnect) { 536 ENSURE_CALLED_BEFORE_CONNECT(); 537 } 538 return mRequestHead.SetHeader(nsHttp::Referer, aReferrer); 539 } 540 541 nsresult ClearReferrerHeader() { 542 ENSURE_CALLED_BEFORE_CONNECT(); 543 return mRequestHead.ClearHeader(nsHttp::Referer); 544 } 545 546 void SetTopWindowURI(nsIURI* aTopWindowURI) { mTopWindowURI = aTopWindowURI; } 547 548 // Set referrerInfo and compute the referrer header if neccessary. 549 // Pass true for aSetOriginal if this is a new referrer and should 550 // overwrite the 'original' value, false if this is a mutation (like 551 // stripping the path). 552 nsresult SetReferrerInfoInternal(nsIReferrerInfo* aReferrerInfo, bool aClone, 553 bool aCompute, bool aRespectBeforeConnect); 554 555 struct ReplacementChannelConfig { 556 ReplacementChannelConfig() = default; 557 explicit ReplacementChannelConfig( 558 const dom::ReplacementChannelConfigInit& aInit); 559 560 uint32_t redirectFlags = 0; 561 ClassOfService classOfService = {0, false}; 562 Maybe<bool> privateBrowsing = Nothing(); 563 Maybe<nsCString> method; 564 nsCOMPtr<nsIReferrerInfo> referrerInfo; 565 Maybe<dom::TimedChannelInfo> timedChannelInfo; 566 nsCOMPtr<nsIInputStream> uploadStream; 567 uint64_t uploadStreamLength = 0; 568 bool uploadStreamHasHeaders = false; 569 Maybe<nsCString> contentType; 570 Maybe<nsCString> contentLength; 571 572 dom::ReplacementChannelConfigInit Serialize(); 573 }; 574 575 enum class ReplacementReason { 576 Redirect, 577 InternalRedirect, 578 DocumentChannel, 579 }; 580 581 // Create a ReplacementChannelConfig object that can be used to duplicate the 582 // current channel. 583 ReplacementChannelConfig CloneReplacementChannelConfig( 584 bool aPreserveMethod, uint32_t aRedirectFlags, ReplacementReason aReason); 585 586 static void ConfigureReplacementChannel(nsIChannel*, 587 const ReplacementChannelConfig&, 588 ReplacementReason); 589 590 // Called before we create the redirect target channel. 591 already_AddRefed<nsILoadInfo> CloneLoadInfoForRedirect( 592 nsIURI* aNewURI, uint32_t aRedirectFlags); 593 594 // True if we've already applied content conversion to the data 595 // passed to mListener. 596 bool HasAppliedConversion() { return LoadHasAppliedConversion(); } 597 598 // https://fetch.spec.whatwg.org/#concept-request-tainted-origin 599 bool HasRedirectTaintedOrigin() { return LoadTaintedOriginFlag(); } 600 601 bool ChannelBlockedByOpaqueResponse() const { 602 return mChannelBlockedByOpaqueResponse; 603 } 604 bool CachedOpaqueResponseBlockingPref() const { 605 return mCachedOpaqueResponseBlockingPref; 606 } 607 608 TimeStamp GetOnStartRequestStartTime() const { 609 return mOnStartRequestStartTime; 610 } 611 TimeStamp GetDataAvailableStartTime() const { 612 return mOnDataAvailableStartTime; 613 } 614 TimeStamp GetOnStopRequestStartTime() const { 615 return mOnStopRequestStartTime; 616 } 617 618 protected: 619 nsresult GetTopWindowURI(nsIURI* aURIBeingLoaded, nsIURI** aTopWindowURI); 620 621 // Handle notifying listener, removing from loadgroup if request failed. 622 void DoNotifyListener(); 623 virtual void DoNotifyListenerCleanup() = 0; 624 625 // drop reference to listener, its callbacks, and the progress sink 626 virtual void ReleaseListeners(); 627 628 // Call AsyncAbort(). 629 virtual void DoAsyncAbort(nsresult aStatus) = 0; 630 631 void MaybeReportTimingData(); 632 nsIURI* GetReferringPage(); 633 nsPIDOMWindowInner* GetInnerDOMWindow(); 634 635 void AddCookiesToRequest(); 636 [[nodiscard]] virtual nsresult SetupReplacementChannel( 637 nsIURI*, nsIChannel*, bool preserveMethod, uint32_t redirectFlags); 638 639 bool IsNewChannelSameOrigin(nsIChannel* aNewChannel); 640 641 // WHATWG Fetch Standard 4.4. HTTP-redirect fetch, step 10 642 virtual bool ShouldTaintReplacementChannelOrigin(nsIChannel* aNewChannel, 643 uint32_t aRedirectFlags); 644 645 // bundle calling OMR observers and marking flag into one function 646 inline void CallOnModifyRequestObservers() { 647 gHttpHandler->OnModifyRequest(this); 648 MOZ_ASSERT(!LoadRequestObserversCalled()); 649 StoreRequestObserversCalled(true); 650 } 651 652 // Helper function to simplify getting notification callbacks. 653 template <class T> 654 void GetCallback(nsCOMPtr<T>& aResult) { 655 NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, NS_GET_IID(T), 656 getter_AddRefs(aResult)); 657 } 658 659 // Redirect tracking 660 // Checks whether or not aURI and mOriginalURI share the same domain. 661 virtual bool SameOriginWithOriginalUri(nsIURI* aURI); 662 663 [[nodiscard]] bool BypassServiceWorker() const; 664 665 // Returns true if this channel should intercept the network request and 666 // prepare for a possible synthesized response instead. 667 bool ShouldIntercept(nsIURI* aURI = nullptr); 668 669 #ifdef DEBUG 670 // Check if mPrivateBrowsingId matches between LoadInfo and LoadContext. 671 void AssertPrivateBrowsingId(); 672 #endif 673 674 static void CallTypeSniffers(void* aClosure, const uint8_t* aData, 675 uint32_t aCount); 676 677 nsresult CheckRedirectLimit(nsIURI* aNewURI, uint32_t aRedirectFlags) const; 678 679 bool MaybeWaitForUploadStreamNormalization(nsIStreamListener* aListener, 680 nsISupports* aContext); 681 682 void MaybeFlushConsoleReports(); 683 684 bool IsBrowsingContextDiscarded() const; 685 686 nsresult ProcessCrossOriginEmbedderPolicyHeader(); 687 688 nsresult ProcessCrossOriginResourcePolicyHeader(); 689 690 nsresult ComputeCrossOriginOpenerPolicyMismatch(); 691 692 nsresult ProcessCrossOriginSecurityHeaders(); 693 694 nsresult ValidateMIMEType(); 695 696 bool ShouldFilterOpaqueResponse(OpaqueResponseFilterFetch aFilterType) const; 697 bool ShouldBlockOpaqueResponse() const; 698 OpaqueResponse BlockOrFilterOpaqueResponse( 699 OpaqueResponseBlocker* aORB, const nsAString& aReason, 700 const OpaqueResponseBlockedTelemetryReason aTelemetryReason, 701 const char* aFormat, ...); 702 703 OpaqueResponse PerformOpaqueResponseSafelistCheckBeforeSniff(); 704 705 OpaqueResponse PerformOpaqueResponseSafelistCheckAfterSniff( 706 const nsACString& aContentType, bool aNoSniff); 707 708 bool NeedOpaqueResponseAllowedCheckAfterSniff() const; 709 void BlockOpaqueResponseAfterSniff( 710 const nsAString& aReason, 711 const OpaqueResponseBlockedTelemetryReason aTelemetryReason); 712 void AllowOpaqueResponseAfterSniff(); 713 void SetChannelBlockedByOpaqueResponse(); 714 bool Http3Allowed() const; 715 716 virtual void ExplicitSetUploadStreamLength(uint64_t aContentLength, 717 bool aSetContentLengthHeader); 718 719 friend class OpaqueResponseBlocker; 720 friend class PrivateBrowsingChannel<HttpBaseChannel>; 721 friend class InterceptFailedOnStop; 722 friend class HttpChannelParent; 723 724 protected: 725 // this section is for main-thread-only object 726 // all the references need to be proxy released on main thread. 727 nsCOMPtr<nsIURI> mURI; 728 nsCOMPtr<nsIURI> mOriginalURI; 729 nsCOMPtr<nsIURI> mDocumentURI; 730 nsCOMPtr<nsILoadGroup> mLoadGroup; 731 nsCOMPtr<nsILoadInfo> mLoadInfo; 732 nsCOMPtr<nsIInterfaceRequestor> mCallbacks; 733 nsCOMPtr<nsIProgressEventSink> mProgressSink; 734 nsCOMPtr<nsIReferrerInfo> mReferrerInfo; 735 // The first parameter is the URI we would like to redirect to 736 // The second parameter should be true if trasparent redirect otherwise false 737 // mAPIRedirectTo is Nothing if and only if the URI is null. 738 mozilla::Maybe<mozilla::CompactPair<nsCOMPtr<nsIURI>, bool>> mAPIRedirectTo; 739 nsCOMPtr<nsIURI> mProxyURI; 740 nsCOMPtr<nsIPrincipal> mPrincipal; 741 nsCOMPtr<nsIURI> mTopWindowURI; 742 nsCOMPtr<nsIStreamListener> mListener; 743 // An instance of nsHTTPCompressConv 744 nsCOMPtr<nsIStreamListener> mCompressListener; 745 nsCOMPtr<nsIEventTarget> mCurrentThread; 746 747 RefPtr<OpaqueResponseBlocker> mORB; 748 749 private: 750 // Proxy release all members above on main thread. 751 void ReleaseMainThreadOnlyReferences(); 752 753 void MaybeResumeAsyncOpen(); 754 755 nsresult SetRequestHeaderInternal(const nsACString& aHeader, 756 const nsACString& aValue, bool aMerge, 757 nsHttpHeaderArray::HeaderVariety aVariety); 758 759 protected: 760 nsCString mSpec; // ASCII encoded URL spec 761 nsCString mContentTypeHint; 762 nsCString mContentCharsetHint; 763 nsCString mUserSetCookieHeader; 764 // HTTP Upgrade Data 765 nsCString mUpgradeProtocol; 766 // Resumable channel specific data 767 nsCString mEntityID; 768 // The initiator type (for this resource) - how was the resource referenced in 769 // the HTML file. 770 nsString mInitiatorType; 771 // Holds the name of the preferred alt-data type for each contentType. 772 nsTArray<PreferredAlternativeDataTypeParams> mPreferredCachedAltDataTypes; 773 // Holds the name of the alternative data type the channel returned. 774 nsCString mAvailableCachedAltDataType; 775 776 // Classified channel's matched information 777 nsCString mMatchedList; 778 nsCString mMatchedProvider; 779 nsCString mMatchedFullHash; 780 781 nsTArray<nsCString> mMatchedTrackingLists; 782 nsTArray<nsCString> mMatchedTrackingFullHashes; 783 784 nsCOMPtr<nsISupports> mOwner; 785 786 nsHttpRequestHead mRequestHead; 787 // Upload throttling. 788 nsCOMPtr<nsIInputChannelThrottleQueue> mThrottleQueue; 789 nsCOMPtr<nsIInputStream> mUploadStream; 790 UniquePtr<nsHttpResponseHead> mResponseHead; 791 UniquePtr<nsHttpHeaderArray> mResponseTrailers; 792 RefPtr<nsHttpConnectionInfo> mConnectionInfo; 793 nsCOMPtr<nsIProxyInfo> mProxyInfo; 794 nsCOMPtr<nsITransportSecurityInfo> mSecurityInfo; 795 nsCOMPtr<nsIHttpUpgradeListener> mUpgradeProtocolCallback; 796 UniquePtr<nsString> mContentDispositionFilename; 797 nsCOMPtr<nsIConsoleReportCollector> mReportCollector; 798 799 RefPtr<nsHttpHandler> mHttpHandler; // keep gHttpHandler alive 800 // Accessed on MainThread and Cache2 IO thread 801 DataMutex<UniquePtr<nsTArray<nsCString>>> mRedirectedCachekeys{ 802 "mRedirectedCacheKeys"}; 803 nsCOMPtr<nsIRequestContext> mRequestContext; 804 805 NetAddr mSelfAddr; 806 NetAddr mPeerAddr; 807 808 nsTArray<std::pair<nsString, nsString>> mSecurityConsoleMessages; 809 nsTArray<nsCString> mUnsafeHeaders; 810 811 // A time value equal to the starting time of the fetch that initiates the 812 // redirect. 813 mozilla::TimeStamp mRedirectStartTimeStamp; 814 // A time value equal to the time immediately after receiving the last byte of 815 // the response of the last redirect. 816 mozilla::TimeStamp mRedirectEndTimeStamp; 817 818 PRTime mChannelCreationTime{0}; 819 TimeStamp mChannelCreationTimestamp; 820 TimeStamp mAsyncOpenTime; 821 TimeStamp mCacheReadStart; 822 TimeStamp mCacheReadEnd; 823 TimeStamp mLaunchServiceWorkerStart; 824 TimeStamp mLaunchServiceWorkerEnd; 825 TimeStamp mDispatchFetchEventStart; 826 TimeStamp mDispatchFetchEventEnd; 827 TimeStamp mHandleFetchEventStart; 828 TimeStamp mHandleFetchEventEnd; 829 TimeStamp mOnStartRequestStartTime; 830 TimeStamp mOnDataAvailableStartTime; 831 TimeStamp mOnStopRequestStartTime; 832 // copied from the transaction before we null out mTransaction 833 // so that the timing can still be queried from OnStopRequest 834 TimingStruct mTransactionTimings{}; 835 836 // Gets computed during ComputeCrossOriginOpenerPolicyMismatch so we have 837 // the channel's policy even if we don't know policy initiator. 838 nsILoadInfo::CrossOriginOpenerPolicy mComputedCrossOriginOpenerPolicy{ 839 nsILoadInfo::OPENER_POLICY_UNSAFE_NONE}; 840 841 uint64_t mStartPos{UINT64_MAX}; 842 uint64_t mTransferSize{0}; 843 uint64_t mRequestSize{0}; 844 uint64_t mDecodedBodySize{0}; 845 // True only when the channel supports any of the versions of HTTP3 846 bool mSupportsHTTP3{false}; 847 uint64_t mEncodedBodySize{0}; 848 uint64_t mRequestContextID{0}; 849 // ID of the top-level document's inner window this channel is being 850 // originated from. 851 uint64_t mContentWindowId{0}; 852 uint64_t mBrowserId{0}; 853 int64_t mAltDataLength{-1}; 854 uint64_t mChannelId{0}; 855 uint64_t mReqContentLength{0}; 856 857 Atomic<nsresult, ReleaseAcquire> mStatus{NS_OK}; 858 859 // Use Release-Acquire ordering to ensure the OMT ODA is ignored while channel 860 // is canceled on main thread. 861 Atomic<bool, ReleaseAcquire> mCanceled{false}; 862 Atomic<uint32_t, ReleaseAcquire> mFirstPartyClassificationFlags{0}; 863 Atomic<uint32_t, ReleaseAcquire> mThirdPartyClassificationFlags{0}; 864 865 // mutex to guard members accessed during OnDataFinished in 866 // HttpChannelChild.cpp 867 Mutex mOnDataFinishedMutex{"HttpChannelChild::OnDataFinishedMutex"}; 868 869 UniquePtr<ProfileChunkedBuffer> mSource; 870 871 uint32_t mLoadFlags{LOAD_NORMAL}; 872 uint32_t mCaps{0}; 873 874 ClassOfService mClassOfService; 875 // This should be set the the actual TRR mode used to resolve the request. 876 // Is initially set to TRR_DEFAULT_MODE, but should be updated to the actual 877 // mode used by the request 878 nsIRequest::TRRMode mEffectiveTRRMode = nsIRequest::TRR_DEFAULT_MODE; 879 TRRSkippedReason mTRRSkipReason = TRRSkippedReason::TRR_UNSET; 880 881 public: 882 void SetEarlyHints( 883 nsTArray<mozilla::net::EarlyHintConnectArgs>&& aEarlyHints); 884 nsTArray<mozilla::net::EarlyHintConnectArgs>&& TakeEarlyHints(); 885 886 protected: 887 // Storing Http 103 Early Hint preloads. The parent process is responsible to 888 // start the early hint preloads, but the http child needs to be able to look 889 // them up. They are sent via IPC and stored in this variable. This is set on 890 // main document channel 891 nsTArray<EarlyHintConnectArgs> mEarlyHints; 892 // EarlyHintRegistrar id to connect back to the preload. Set on preload 893 // channels started from the above list 894 uint64_t mEarlyHintPreloaderId = 0; 895 uint32_t mEarlyHintLinkType = 0; 896 897 nsString mClassicScriptHintCharset; 898 nsString mDocumentCharacterSet; 899 900 // clang-format off 901 MOZ_ATOMIC_BITFIELDS(mAtomicBitfields1, 32, ( 902 (uint32_t, UpgradeToSecure, 1), 903 (uint32_t, ApplyConversion, 1), 904 // Set to true if DoApplyContentConversions has been applied to 905 // our default mListener. 906 (uint32_t, HasAppliedConversion, 1), 907 (uint32_t, IsPending, 1), 908 (uint32_t, WasOpened, 1), 909 // if 1 all "http-on-{opening|modify|etc}-request" observers have been 910 // called. 911 (uint32_t, RequestObserversCalled, 1), 912 (uint32_t, ResponseHeadersModified, 1), 913 (uint32_t, AllowSTS, 1), 914 (uint32_t, ThirdPartyFlags, 3), 915 (uint32_t, UploadStreamHasHeaders, 1), 916 (uint32_t, ChannelIsForDownload, 1), 917 (uint32_t, TracingEnabled, 1), 918 (uint32_t, ReportTiming, 1), 919 (uint32_t, AllowSpdy, 1), 920 (uint32_t, AllowHttp3, 1), 921 (uint32_t, AllowAltSvc, 1), 922 // !!! This is also used by the URL classifier to exempt channels from 923 // classification. If this is changed or removed, make sure we also update 924 // NS_ShouldClassifyChannel accordingly !!! 925 (uint32_t, BeConservative, 1), 926 // If the current channel is used to as a TRR connection. 927 (uint32_t, IsTRRServiceChannel, 1), 928 // If the request was performed to a TRR resolved IP address. 929 // Will be false if loading the resource does not create a connection 930 // (for example when it's loaded from the cache). 931 (uint32_t, ResolvedByTRR, 1), 932 (uint32_t, ResponseTimeoutEnabled, 1), 933 // A flag that should be false only if a cross-domain redirect occurred 934 (uint32_t, AllRedirectsSameOrigin, 1), 935 936 // Is 1 if no redirects have occured or if all redirects 937 // pass the Resource Timing timing-allow-check 938 (uint32_t, AllRedirectsPassTimingAllowCheck, 1), 939 940 // True if this channel was intercepted and could receive a synthesized 941 // response. 942 (uint32_t, ResponseCouldBeSynthesized, 1), 943 944 (uint32_t, BlockAuthPrompt, 1), 945 946 // If true, we behave as if the LOAD_FROM_CACHE flag has been set. 947 // Used to enforce that flag's behavior but not expose it externally. 948 (uint32_t, AllowStaleCacheContent, 1), 949 950 // If true, we behave as if the VALIDATE_ALWAYS flag has been set. 951 // Used to force validate the cached content. 952 (uint32_t, ForceValidateCacheContent, 1), 953 954 // If true, we prefer the LOAD_FROM_CACHE flag over LOAD_BYPASS_CACHE or 955 // LOAD_BYPASS_LOCAL_CACHE. 956 (uint32_t, PreferCacheLoadOverBypass, 1), 957 958 (uint32_t, IsProxyUsed, 1) 959 )) 960 961 // Broken up into two bitfields to avoid alignment requirements of uint64_t. 962 // (Too many bits used for one uint32_t.) 963 MOZ_ATOMIC_BITFIELDS(mAtomicBitfields2, 32, ( 964 // True iff this request has been calculated in its request context as 965 // a non tail request. We must remove it again when this channel is done. 966 (uint32_t, AddedAsNonTailRequest, 1), 967 968 // True if AsyncOpen() is called when the upload stream normalization or 969 // length is still unknown. AsyncOpen() will be retriggered when 970 // normalization is complete and length has been determined. 971 (uint32_t, AsyncOpenWaitingForStreamNormalization, 1), 972 973 // Defaults to true. This is set to false when it is no longer possible 974 // to upgrade the request to a secure channel. 975 (uint32_t, UpgradableToSecure, 1), 976 977 // Tainted origin flag of a request, specified by 978 // WHATWG Fetch Standard 2.2.5. 979 (uint32_t, TaintedOriginFlag, 1), 980 981 // If the channel is being used to check OCSP 982 (uint32_t, IsOCSP, 1), 983 984 // Used by system requests such as remote settings and updates to 985 // retry requests without proxies. 986 (uint32_t, BypassProxy, 1), 987 988 // Indicate whether the response of this channel is coming from 989 // socket process. 990 (uint32_t, LoadedBySocketProcess, 1), 991 992 // Indicates whether the user-agent header has been modifed since the channel 993 // was created. 994 (uint32_t, IsUserAgentHeaderModified, 1), 995 996 // Indicates whether the user-agent header is outdated and can not be used as 997 // a user agent value. 998 (uint32_t, IsUserAgentHeaderOutdated, 1) 999 )) 1000 // clang-format on 1001 1002 // An opaque flags for non-standard behavior of the TLS system. 1003 // It is unlikely this will need to be set outside of telemetry studies 1004 // relating to the TLS implementation. 1005 uint32_t mTlsFlags{0}; 1006 1007 // Current suspension depth for this channel object 1008 uint32_t mSuspendCount{0}; 1009 1010 // Per channel transport window override (0 means no override) 1011 uint32_t mInitialRwin{0}; 1012 1013 uint32_t mProxyResolveFlags{0}; 1014 1015 uint32_t mContentDispositionHint{UINT32_MAX}; 1016 1017 dom::RequestMode mRequestMode; 1018 uint32_t mRedirectMode{nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW}; 1019 1020 // If this channel was created as the result of a redirect, then this value 1021 // will reflect the redirect flags passed to the SetupReplacementChannel() 1022 // method. 1023 uint32_t mLastRedirectFlags{0}; 1024 1025 int16_t mPriority{PRIORITY_NORMAL}; 1026 uint8_t mRedirectionLimit; 1027 1028 // Performance tracking 1029 // Number of redirects that has occurred. 1030 int8_t mRedirectCount{0}; 1031 // Number of internal redirects that has occurred. 1032 int8_t mInternalRedirectCount{0}; 1033 1034 enum class SnifferCategoryType { 1035 NetContent = 0, 1036 OpaqueResponseBlocking, 1037 All 1038 }; 1039 SnifferCategoryType mSnifferCategoryType = SnifferCategoryType::NetContent; 1040 1041 // Used to ensure the same pref value is being used across the 1042 // lifetime of this http channel. 1043 const bool mCachedOpaqueResponseBlockingPref; 1044 bool mChannelBlockedByOpaqueResponse{false}; 1045 1046 bool mDummyChannelForCachedResource{false}; 1047 1048 bool mHasContentDecompressed{false}; 1049 1050 // A flag that should be false if render-blocking is not stated 1051 bool mRenderBlocking{false}; 1052 1053 // clang-format off 1054 MOZ_ATOMIC_BITFIELDS(mAtomicBitfields3, 8, ( 1055 (bool, AsyncOpenTimeOverriden, 1), 1056 (bool, ForcePending, 1), 1057 1058 // true if the channel is deliving alt-data. 1059 (bool, DeliveringAltData, 1), 1060 1061 (bool, CorsIncludeCredentials, 1), 1062 1063 // These parameters are used to ensure that we do not call OnStartRequest 1064 // and OnStopRequest more than once. 1065 (bool, OnStartRequestCalled, 1), 1066 (bool, OnStopRequestCalled, 1), 1067 1068 // Defaults to false. Is set to true at the begining of OnStartRequest. 1069 // Used to ensure methods can't be called before OnStartRequest. 1070 (bool, AfterOnStartRequestBegun, 1), 1071 1072 (bool, RequireCORSPreflight, 1) 1073 )) 1074 1075 // Broken up into two bitfields to avoid alignment requirements of uint16_t. 1076 // (Too many bits used for one uint8_t.) 1077 MOZ_ATOMIC_BITFIELDS(mAtomicBitfields4, 8, ( 1078 // This flag will be true if the consumer is requesting alt-data AND the 1079 // consumer is in the child process. 1080 (bool, AltDataForChild, 1), 1081 // This flag will be true if the consumer cannot process alt-data. This 1082 // is used in the webextension StreamFilter handler. If true, we bypass 1083 // using alt-data for the request. 1084 (bool, DisableAltDataCache, 1), 1085 1086 (bool, ForceMainDocumentChannel, 1), 1087 // This is set true if the channel is waiting for upload stream 1088 // normalization or the InputStreamLengthHelper::GetAsyncLength callback. 1089 (bool, PendingUploadStreamNormalization, 1), 1090 1091 // Set to true if our listener has indicated that it requires 1092 // content conversion to be done by us. 1093 (bool, ListenerRequiresContentConversion, 1), 1094 1095 // True if this is a navigation to a page with a different cross origin 1096 // opener policy ( see ComputeCrossOriginOpenerPolicyMismatch ) 1097 (uint32_t, HasCrossOriginOpenerPolicyMismatch, 1), 1098 1099 // True if HTTPS RR is used during the connection establishment of this 1100 // channel. 1101 (uint32_t, HasHTTPSRR, 1), 1102 1103 // Ensures that ProcessCrossOriginSecurityHeadersCalled has been called 1104 // before calling CallOnStartRequest. 1105 (uint32_t, ProcessCrossOriginSecurityHeadersCalled, 1) 1106 )) 1107 // clang-format on 1108 1109 bool EnsureRequestContextID(); 1110 bool EnsureRequestContext(); 1111 1112 // Adds/removes this channel as a non-tailed request in its request context 1113 // these helpers ensure we add it only once and remove it only when added 1114 // via AddedAsNonTailRequest member tracking. 1115 void AddAsNonTailRequest(); 1116 void RemoveAsNonTailRequest(); 1117 1118 void EnsureBrowserId(); 1119 1120 bool PerformCORSCheck(); 1121 }; 1122 1123 // Share some code while working around C++'s absurd inability to handle casting 1124 // of member functions between base/derived types. 1125 // - We want to store member function pointer to call at resume time, but one 1126 // such function--HandleAsyncAbort--we want to share between the 1127 // nsHttpChannel/HttpChannelChild. Can't define it in base class, because 1128 // then we'd have to cast member function ptr between base/derived class 1129 // types. Sigh... 1130 template <class T> 1131 class HttpAsyncAborter { 1132 public: 1133 explicit HttpAsyncAborter(T* derived) 1134 : mThis(derived), mCallOnResume(nullptr) {} 1135 1136 // Aborts channel: calls OnStart/Stop with provided status, removes channel 1137 // from loadGroup. 1138 [[nodiscard]] nsresult AsyncAbort(nsresult status); 1139 1140 // Does most the actual work. 1141 void HandleAsyncAbort(); 1142 1143 // AsyncCall calls a member function asynchronously (via an event). 1144 // retval isn't refcounted and is set only when event was successfully 1145 // posted, the event is returned for the purpose of cancelling when needed 1146 [[nodiscard]] virtual nsresult AsyncCall( 1147 void (T::*funcPtr)(), nsRunnableMethod<T>** retval = nullptr); 1148 1149 private: 1150 T* mThis; 1151 1152 protected: 1153 // Function to be called at resume time 1154 std::function<nsresult(T*)> mCallOnResume; 1155 }; 1156 1157 template <class T> 1158 [[nodiscard]] nsresult HttpAsyncAborter<T>::AsyncAbort(nsresult status) { 1159 MOZ_LOG(gHttpLog, LogLevel::Debug, 1160 ("HttpAsyncAborter::AsyncAbort [this=%p status=%" PRIx32 "]\n", mThis, 1161 static_cast<uint32_t>(status))); 1162 1163 mThis->mStatus = status; 1164 1165 // if this fails? Callers ignore our return value anyway.... 1166 return AsyncCall(&T::HandleAsyncAbort); 1167 } 1168 1169 // Each subclass needs to define its own version of this (which just calls this 1170 // base version), else we wind up casting base/derived member function ptrs 1171 template <class T> 1172 inline void HttpAsyncAborter<T>::HandleAsyncAbort() { 1173 MOZ_ASSERT(!mCallOnResume, "How did that happen?"); 1174 1175 if (mThis->mSuspendCount) { 1176 MOZ_LOG( 1177 gHttpLog, LogLevel::Debug, 1178 ("Waiting until resume to do async notification [this=%p]\n", mThis)); 1179 mCallOnResume = [](T* self) { 1180 self->HandleAsyncAbort(); 1181 return NS_OK; 1182 }; 1183 return; 1184 } 1185 1186 mThis->DoNotifyListener(); 1187 1188 // finally remove ourselves from the load group. 1189 if (mThis->mLoadGroup) { 1190 mThis->mLoadGroup->RemoveRequest(mThis, nullptr, mThis->mStatus); 1191 } 1192 } 1193 1194 template <class T> 1195 nsresult HttpAsyncAborter<T>::AsyncCall(void (T::*funcPtr)(), 1196 nsRunnableMethod<T>** retval) { 1197 nsresult rv; 1198 1199 RefPtr<nsRunnableMethod<T>> event = 1200 NewRunnableMethod("net::HttpAsyncAborter::AsyncCall", mThis, funcPtr); 1201 rv = NS_DispatchToCurrentThread(event); 1202 if (NS_SUCCEEDED(rv) && retval) { 1203 *retval = event; 1204 } 1205 1206 return rv; 1207 } 1208 1209 class ProxyReleaseRunnable final : public mozilla::Runnable { 1210 public: 1211 explicit ProxyReleaseRunnable(nsTArray<nsCOMPtr<nsISupports>>&& aDoomed) 1212 : Runnable("ProxyReleaseRunnable"), mDoomed(std::move(aDoomed)) {} 1213 1214 NS_IMETHOD 1215 Run() override { 1216 mDoomed.Clear(); 1217 return NS_OK; 1218 } 1219 1220 private: 1221 virtual ~ProxyReleaseRunnable() = default; 1222 1223 nsTArray<nsCOMPtr<nsISupports>> mDoomed; 1224 }; 1225 1226 } // namespace net 1227 } // namespace mozilla 1228 1229 #endif // mozilla_net_HttpBaseChannel_h