/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// These need to be kept in sync with // "browser.opaqueResponseBlocking.filterFetchResponse" enumclass OpaqueResponseFilterFetch { Never, AllowedByORB, BlockedByORB, All };
/* * This class is a partial implementation of nsIHttpChannel. It contains code * shared by nsHttpChannel and HttpChannelChild. * - Note that this class has nothing to do with nsBaseChannel, which is an * earlier effort at a base class for channels that somehow never made it all * the way to the HTTP channel.
*/ class HttpBaseChannel : public nsHashPropertyBag, public nsIEncodedChannel, public nsIHttpChannel, public nsIHttpChannelInternal, public nsIFormPOSTActionChannel, public nsIUploadChannel2, public nsISupportsPriority, public nsIClassOfService, public nsIResumableChannel, public nsITraceableChannel, public PrivateBrowsingChannel<HttpBaseChannel>, public nsITimedChannel, public nsIForcePendingChannel, public nsIConsoleReportCollector, public nsIThrottledInputChannel, public nsIClassifiedChannel { protected: virtual ~HttpBaseChannel();
// We do not own the buffer. The channel owns it. constchar* mEncodingHeader; constchar* mCurStart; // points to start of current header constchar* mCurEnd; // points to end of current header
// Hold a ref to our channel so that it can't go away and take the // header with it.
nsCOMPtr<nsIHttpChannel> mChannel;
// Return the cloned HTTP Headers if available. // The returned headers can be passed to SetDummyChannelForCachedResource // to create a dummy channel with the same HTTP headers.
UniquePtr<nsHttpResponseHead> MaybeCloneResponseHeadForCachedResource();
// Set this channel as a dummy channel for cached resources. // // If aMaybeResponseHead is provided, this uses the given HTTP headers. // Otherwise this uses an empty HTTP headers. void SetDummyChannelForCachedResource( const nsHttpResponseHead* aMaybeResponseHead = nullptr);
// Return whether upon a redirect code of httpStatus for method, the // request method should be rewritten to GET. staticbool ShouldRewriteRedirectToGET(
uint32_t httpStatus, nsHttpRequestHead::ParsedMethodType method);
// Like nsIEncodedChannel::DoApplyConversions except context is set to // mListenerContext.
[[nodiscard]] nsresult DoApplyContentConversions(
nsIStreamListener* aNextListener, nsIStreamListener** aNewNextListener);
// Set referrerInfo and compute the referrer header if neccessary. // Pass true for aSetOriginal if this is a new referrer and should // overwrite the 'original' value, false if this is a mutation (like // stripping the path).
nsresult SetReferrerInfoInternal(nsIReferrerInfo* aReferrerInfo, bool aClone, bool aCompute, bool aRespectBeforeConnect);
// Create a ReplacementChannelConfig object that can be used to duplicate the // current channel.
ReplacementChannelConfig CloneReplacementChannelConfig( bool aPreserveMethod, uint32_t aRedirectFlags, ReplacementReason aReason);
// Called before we create the redirect target channel.
already_AddRefed<nsILoadInfo> CloneLoadInfoForRedirect(
nsIURI* aNewURI, uint32_t aRedirectFlags);
// True if we've already applied content conversion to the data // passed to mListener. bool HasAppliedConversion() { return LoadHasAppliedConversion(); }
// bundle calling OMR observers and marking flag into one function inlinevoid CallOnModifyRequestObservers() {
gHttpHandler->OnModifyRequest(this);
MOZ_ASSERT(!LoadRequestObserversCalled());
StoreRequestObserversCalled(true);
}
// Helper function to simplify getting notification callbacks. template <class T> void GetCallback(nsCOMPtr<T>& aResult) {
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
NS_GET_TEMPLATE_IID(T),
getter_AddRefs(aResult));
}
// Redirect tracking // Checks whether or not aURI and mOriginalURI share the same domain. virtualbool SameOriginWithOriginalUri(nsIURI* aURI);
[[nodiscard]] bool BypassServiceWorker() const;
// Returns true if this channel should intercept the network request and // prepare for a possible synthesized response instead. bool ShouldIntercept(nsIURI* aURI = nullptr);
#ifdef DEBUG // Check if mPrivateBrowsingId matches between LoadInfo and LoadContext. void AssertPrivateBrowsingId(); #endif
protected: // this section is for main-thread-only object // all the references need to be proxy released on main thread.
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIURI> mDocumentURI;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsILoadInfo> mLoadInfo;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsIProgressEventSink> mProgressSink;
nsCOMPtr<nsIReferrerInfo> mReferrerInfo; // The first parameter is the URI we would like to redirect to // The second parameter should be true if trasparent redirect otherwise false // mAPIRedirectTo is Nothing if and only if the URI is null.
mozilla::Maybe<mozilla::CompactPair<nsCOMPtr<nsIURI>, bool>> mAPIRedirectTo;
nsCOMPtr<nsIURI> mProxyURI;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsIURI> mTopWindowURI;
nsCOMPtr<nsIStreamListener> mListener; // An instance of nsHTTPCompressConv
nsCOMPtr<nsIStreamListener> mCompressListener;
nsCOMPtr<nsIEventTarget> mCurrentThread;
RefPtr<OpaqueResponseBlocker> mORB;
private: // Proxy release all members above on main thread. void ReleaseMainThreadOnlyReferences();
protected:
nsCString mSpec; // ASCII encoded URL spec
nsCString mContentTypeHint;
nsCString mContentCharsetHint;
nsCString mUserSetCookieHeader; // HTTP Upgrade Data
nsCString mUpgradeProtocol; // Resumable channel specific data
nsCString mEntityID; // The initiator type (for this resource) - how was the resource referenced in // the HTML file.
nsString mInitiatorType; // Holds the name of the preferred alt-data type for each contentType.
nsTArray<PreferredAlternativeDataTypeParams> mPreferredCachedAltDataTypes; // Holds the name of the alternative data type the channel returned.
nsCString mAvailableCachedAltDataType;
nsString mIntegrityMetadata;
// A time value equal to the starting time of the fetch that initiates the // redirect.
mozilla::TimeStamp mRedirectStartTimeStamp; // A time value equal to the time immediately after receiving the last byte of // the response of the last redirect.
mozilla::TimeStamp mRedirectEndTimeStamp;
PRTime mChannelCreationTime;
TimeStamp mChannelCreationTimestamp;
TimeStamp mAsyncOpenTime;
TimeStamp mCacheReadStart;
TimeStamp mCacheReadEnd;
TimeStamp mLaunchServiceWorkerStart;
TimeStamp mLaunchServiceWorkerEnd;
TimeStamp mDispatchFetchEventStart;
TimeStamp mDispatchFetchEventEnd;
TimeStamp mHandleFetchEventStart;
TimeStamp mHandleFetchEventEnd;
TimeStamp mOnStartRequestStartTime;
TimeStamp mOnDataAvailableStartTime;
TimeStamp mOnStopRequestStartTime; // copied from the transaction before we null out mTransaction // so that the timing can still be queried from OnStopRequest
TimingStruct mTransactionTimings;
// Gets computed during ComputeCrossOriginOpenerPolicyMismatch so we have // the channel's policy even if we don't know policy initiator.
nsILoadInfo::CrossOriginOpenerPolicy mComputedCrossOriginOpenerPolicy;
uint64_t mStartPos;
uint64_t mTransferSize;
uint64_t mRequestSize;
uint64_t mDecodedBodySize; // True only when the channel supports any of the versions of HTTP3 bool mSupportsHTTP3;
uint64_t mEncodedBodySize;
uint64_t mRequestContextID; // ID of the top-level document's inner window this channel is being // originated from.
uint64_t mContentWindowId;
uint64_t mBrowserId;
int64_t mAltDataLength;
uint64_t mChannelId;
uint64_t mReqContentLength;
Atomic<nsresult, ReleaseAcquire> mStatus;
// Use Release-Acquire ordering to ensure the OMT ODA is ignored while channel // is canceled on main thread.
Atomic<bool, ReleaseAcquire> mCanceled;
Atomic<uint32_t, ReleaseAcquire> mFirstPartyClassificationFlags;
Atomic<uint32_t, ReleaseAcquire> mThirdPartyClassificationFlags;
// mutex to guard members accessed during OnDataFinished in // HttpChannelChild.cpp
Mutex mOnDataFinishedMutex{"HttpChannelChild::OnDataFinishedMutex"};
UniquePtr<ProfileChunkedBuffer> mSource;
uint32_t mLoadFlags;
uint32_t mCaps;
ClassOfService mClassOfService; // This should be set the the actual TRR mode used to resolve the request. // Is initially set to TRR_DEFAULT_MODE, but should be updated to the actual // mode used by the request
nsIRequest::TRRMode mEffectiveTRRMode = nsIRequest::TRR_DEFAULT_MODE;
TRRSkippedReason mTRRSkipReason = TRRSkippedReason::TRR_UNSET;
protected: // Storing Http 103 Early Hint preloads. The parent process is responsible to // start the early hint preloads, but the http child needs to be able to look // them up. They are sent via IPC and stored in this variable. This is set on // main document channel
nsTArray<EarlyHintConnectArgs> mEarlyHints; // EarlyHintRegistrar id to connect back to the preload. Set on preload // channels started from the above list
uint64_t mEarlyHintPreloaderId = 0;
uint32_t mEarlyHintLinkType = 0;
// clang-format off
MOZ_ATOMIC_BITFIELDS(mAtomicBitfields1, 32, (
(uint32_t, UpgradeToSecure, 1),
(uint32_t, ApplyConversion, 1), // Set to true if DoApplyContentConversions has been applied to // our default mListener.
(uint32_t, HasAppliedConversion, 1),
(uint32_t, IsPending, 1),
(uint32_t, WasOpened, 1), // if 1 all "http-on-{opening|modify|etc}-request" observers have been // called.
(uint32_t, RequestObserversCalled, 1),
(uint32_t, ResponseHeadersModified, 1),
(uint32_t, AllowSTS, 1),
(uint32_t, ThirdPartyFlags, 3),
(uint32_t, UploadStreamHasHeaders, 1),
(uint32_t, ChannelIsForDownload, 1),
(uint32_t, TracingEnabled, 1),
(uint32_t, ReportTiming, 1),
(uint32_t, AllowSpdy, 1),
(uint32_t, AllowHttp3, 1),
(uint32_t, AllowAltSvc, 1), // !!! This is also used by the URL classifier to exempt channels from // classification. If this is changed or removed, make sure we also update // NS_ShouldClassifyChannel accordingly !!!
(uint32_t, BeConservative, 1), // If the current channel is used to as a TRR connection.
(uint32_t, IsTRRServiceChannel, 1), // If the request was performed to a TRR resolved IP address. // Will be false if loading the resource does not create a connection // (for example when it's loaded from the cache).
(uint32_t, ResolvedByTRR, 1),
(uint32_t, ResponseTimeoutEnabled, 1), // A flag that should be false only if a cross-domain redirect occurred
(uint32_t, AllRedirectsSameOrigin, 1),
// Is 1 if no redirects have occured or if all redirects // pass the Resource Timing timing-allow-check
(uint32_t, AllRedirectsPassTimingAllowCheck, 1),
// True if this channel was intercepted and could receive a synthesized // response.
(uint32_t, ResponseCouldBeSynthesized, 1),
(uint32_t, BlockAuthPrompt, 1),
// If true, we behave as if the LOAD_FROM_CACHE flag has been set. // Used to enforce that flag's behavior but not expose it externally.
(uint32_t, AllowStaleCacheContent, 1),
// If true, we behave as if the VALIDATE_ALWAYS flag has been set. // Used to force validate the cached content.
(uint32_t, ForceValidateCacheContent, 1),
// If true, we prefer the LOAD_FROM_CACHE flag over LOAD_BYPASS_CACHE or // LOAD_BYPASS_LOCAL_CACHE.
(uint32_t, PreferCacheLoadOverBypass, 1),
(uint32_t, IsProxyUsed, 1)
))
// Broken up into two bitfields to avoid alignment requirements of uint64_t. // (Too many bits used for one uint32_t.)
MOZ_ATOMIC_BITFIELDS(mAtomicBitfields2, 32, ( // True iff this request has been calculated in its request context as // a non tail request. We must remove it again when this channel is done.
(uint32_t, AddedAsNonTailRequest, 1),
// True if AsyncOpen() is called when the upload stream normalization or // length is still unknown. AsyncOpen() will be retriggered when // normalization is complete and length has been determined.
(uint32_t, AsyncOpenWaitingForStreamNormalization, 1),
// Defaults to true. This is set to false when it is no longer possible // to upgrade the request to a secure channel.
(uint32_t, UpgradableToSecure, 1),
// Tainted origin flag of a request, specified by // WHATWG Fetch Standard 2.2.5.
(uint32_t, TaintedOriginFlag, 1),
// If the channel is being used to check OCSP
(uint32_t, IsOCSP, 1),
// Used by system requests such as remote settings and updates to // retry requests without proxies.
(uint32_t, BypassProxy, 1),
// Indicate whether the response of this channel is coming from // socket process.
(uint32_t, LoadedBySocketProcess, 1),
// Indicates whether the user-agent header has been modifed since the channel // was created.
(uint32_t, IsUserAgentHeaderModified, 1)
)) // clang-format on
// An opaque flags for non-standard behavior of the TLS system. // It is unlikely this will need to be set outside of telemetry studies // relating to the TLS implementation.
uint32_t mTlsFlags;
// Current suspension depth for this channel object
uint32_t mSuspendCount;
// Per channel transport window override (0 means no override)
uint32_t mInitialRwin;
// If this channel was created as the result of a redirect, then this value // will reflect the redirect flags passed to the SetupReplacementChannel() // method.
uint32_t mLastRedirectFlags;
int16_t mPriority;
uint8_t mRedirectionLimit;
// Performance tracking // Number of redirects that has occurred.
int8_t mRedirectCount; // Number of internal redirects that has occurred.
int8_t mInternalRedirectCount;
// Used to ensure the same pref value is being used across the // lifetime of this http channel. constbool mCachedOpaqueResponseBlockingPref; bool mChannelBlockedByOpaqueResponse;
bool mDummyChannelForCachedResource;
bool mHasContentDecompressed;
// A flag that should be false if render-blocking is not stated bool mRenderBlocking;
// true if the channel is deliving alt-data.
(bool, DeliveringAltData, 1),
(bool, CorsIncludeCredentials, 1),
// These parameters are used to ensure that we do not call OnStartRequest // and OnStopRequest more than once.
(bool, OnStartRequestCalled, 1),
(bool, OnStopRequestCalled, 1),
// Defaults to false. Is set to true at the begining of OnStartRequest. // Used to ensure methods can't be called before OnStartRequest.
(bool, AfterOnStartRequestBegun, 1),
(bool, RequireCORSPreflight, 1)
))
// Broken up into two bitfields to avoid alignment requirements of uint16_t. // (Too many bits used for one uint8_t.)
MOZ_ATOMIC_BITFIELDS(mAtomicBitfields4, 8, ( // This flag will be true if the consumer is requesting alt-data AND the // consumer is in the child process.
(bool, AltDataForChild, 1), // This flag will be true if the consumer cannot process alt-data. This // is used in the webextension StreamFilter handler. If true, we bypass // using alt-data for the request.
(bool, DisableAltDataCache, 1),
(bool, ForceMainDocumentChannel, 1), // This is set true if the channel is waiting for upload stream // normalization or the InputStreamLengthHelper::GetAsyncLength callback.
(bool, PendingUploadStreamNormalization, 1),
// Set to true if our listener has indicated that it requires // content conversion to be done by us.
(bool, ListenerRequiresContentConversion, 1),
// True if this is a navigation to a page with a different cross origin // opener policy ( see ComputeCrossOriginOpenerPolicyMismatch )
(uint32_t, HasCrossOriginOpenerPolicyMismatch, 1),
// True if HTTPS RR is used during the connection establishment of this // channel.
(uint32_t, HasHTTPSRR, 1),
// Ensures that ProcessCrossOriginSecurityHeadersCalled has been called // before calling CallOnStartRequest.
(uint32_t, ProcessCrossOriginSecurityHeadersCalled, 1)
)) // clang-format on
// Adds/removes this channel as a non-tailed request in its request context // these helpers ensure we add it only once and remove it only when added // via AddedAsNonTailRequest member tracking. void AddAsNonTailRequest(); void RemoveAsNonTailRequest();
// Share some code while working around C++'s absurd inability to handle casting // of member functions between base/derived types. // - We want to store member function pointer to call at resume time, but one // such function--HandleAsyncAbort--we want to share between the // nsHttpChannel/HttpChannelChild. Can't define it in base class, because // then we'd have to cast member function ptr between base/derived class // types. Sigh... template <class T> class HttpAsyncAborter { public: explicit HttpAsyncAborter(T* derived)
: mThis(derived), mCallOnResume(nullptr) {}
// Aborts channel: calls OnStart/Stop with provided status, removes channel // from loadGroup.
[[nodiscard]] nsresult AsyncAbort(nsresult status);
// Does most the actual work. void HandleAsyncAbort();
// AsyncCall calls a member function asynchronously (via an event). // retval isn't refcounted and is set only when event was successfully // posted, the event is returned for the purpose of cancelling when needed
[[nodiscard]] virtual nsresult AsyncCall( void (T::*funcPtr)(), nsRunnableMethod<T>** retval = nullptr);
private:
T* mThis;
protected: // Function to be called at resume time
std::function<nsresult(T*)> mCallOnResume;
};
// if this fails? Callers ignore our return value anyway.... return AsyncCall(&T::HandleAsyncAbort);
}
// Each subclass needs to define its own version of this (which just calls this // base version), else we wind up casting base/derived member function ptrs template <class T> inlinevoid HttpAsyncAborter<T>::HandleAsyncAbort() {
MOZ_ASSERT(!mCallOnResume, "How did that happen?");
if (mThis->mSuspendCount) {
MOZ_LOG(
gHttpLog, LogLevel::Debug,
("Waiting until resume to do async notification [this=%p]\n", mThis));
mCallOnResume = [](T* self) {
self->HandleAsyncAbort(); return NS_OK;
}; return;
}
mThis->DoNotifyListener();
// finally remove ourselves from the load group. if (mThis->mLoadGroup) {
mThis->mLoadGroup->RemoveRequest(mThis, nullptr, mThis->mStatus);
}
}
class ProxyReleaseRunnable final : public mozilla::Runnable { public: explicit ProxyReleaseRunnable(nsTArray<nsCOMPtr<nsISupports>>&& aDoomed)
: Runnable("ProxyReleaseRunnable"), mDoomed(std::move(aDoomed)) {}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.