LCOV - code coverage report
Current view: top level - netwerk/protocol/http - HttpBaseChannel.h (source / functions) Hit Total Coverage
Test: output.info Lines: 24 49 49.0 %
Date: 2017-07-14 16:53:18 Functions: 16 30 53.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "mozilla/Atomics.h"
      12             : #include "nsHttp.h"
      13             : #include "nsAutoPtr.h"
      14             : #include "nsHashPropertyBag.h"
      15             : #include "nsProxyInfo.h"
      16             : #include "nsHttpRequestHead.h"
      17             : #include "nsHttpResponseHead.h"
      18             : #include "nsHttpConnectionInfo.h"
      19             : #include "nsIConsoleReportCollector.h"
      20             : #include "nsIEncodedChannel.h"
      21             : #include "nsIHttpChannel.h"
      22             : #include "nsHttpHandler.h"
      23             : #include "nsIHttpChannelInternal.h"
      24             : #include "nsIForcePendingChannel.h"
      25             : #include "nsIFormPOSTActionChannel.h"
      26             : #include "nsIUploadChannel2.h"
      27             : #include "nsIProgressEventSink.h"
      28             : #include "nsIURI.h"
      29             : #include "nsIEffectiveTLDService.h"
      30             : #include "nsIStringEnumerator.h"
      31             : #include "nsISupportsPriority.h"
      32             : #include "nsIClassOfService.h"
      33             : #include "nsIClassifiedChannel.h"
      34             : #include "nsIApplicationCache.h"
      35             : #include "nsIResumableChannel.h"
      36             : #include "nsITraceableChannel.h"
      37             : #include "nsILoadContext.h"
      38             : #include "nsILoadInfo.h"
      39             : #include "mozilla/net/NeckoCommon.h"
      40             : #include "nsThreadUtils.h"
      41             : #include "PrivateBrowsingChannel.h"
      42             : #include "mozilla/net/DNS.h"
      43             : #include "nsITimedChannel.h"
      44             : #include "nsIHttpChannel.h"
      45             : #include "nsISecurityConsoleMessage.h"
      46             : #include "nsCOMArray.h"
      47             : #include "mozilla/net/ChannelEventQueue.h"
      48             : #include "mozilla/Move.h"
      49             : #include "nsIThrottledInputChannel.h"
      50             : #include "nsTArray.h"
      51             : #include "nsCOMPtr.h"
      52             : #include "mozilla/IntegerPrintfMacros.h"
      53             : 
      54             : #define HTTP_BASE_CHANNEL_IID \
      55             : { 0x9d5cde03, 0xe6e9, 0x4612, \
      56             :     { 0xbf, 0xef, 0xbb, 0x66, 0xf3, 0xbb, 0x74, 0x46 } }
      57             : 
      58             : 
      59             : class nsISecurityConsoleMessage;
      60             : class nsIPrincipal;
      61             : 
      62             : namespace mozilla {
      63             : 
      64             : namespace dom {
      65             : class Performance;
      66             : }
      67             : 
      68             : class LogCollector;
      69             : 
      70             : namespace net {
      71             : extern mozilla::LazyLogModule gHttpLog;
      72             : 
      73             : /*
      74             :  * This class is a partial implementation of nsIHttpChannel.  It contains code
      75             :  * shared by nsHttpChannel and HttpChannelChild.
      76             :  * - Note that this class has nothing to do with nsBaseChannel, which is an
      77             :  *   earlier effort at a base class for channels that somehow never made it all
      78             :  *   the way to the HTTP channel.
      79             :  */
      80             : class HttpBaseChannel : public nsHashPropertyBag
      81             :                       , public nsIEncodedChannel
      82             :                       , public nsIHttpChannel
      83             :                       , public nsIHttpChannelInternal
      84             :                       , public nsIFormPOSTActionChannel
      85             :                       , public nsIUploadChannel2
      86             :                       , public nsISupportsPriority
      87             :                       , public nsIClassOfService
      88             :                       , public nsIResumableChannel
      89             :                       , public nsITraceableChannel
      90             :                       , public PrivateBrowsingChannel<HttpBaseChannel>
      91             :                       , public nsITimedChannel
      92             :                       , public nsIForcePendingChannel
      93             :                       , public nsIConsoleReportCollector
      94             :                       , public nsIThrottledInputChannel
      95             :                       , public nsIClassifiedChannel
      96             : {
      97             : protected:
      98             :   virtual ~HttpBaseChannel();
      99             : 
     100             : public:
     101             :   NS_DECL_ISUPPORTS_INHERITED
     102             :   NS_DECL_NSIUPLOADCHANNEL
     103             :   NS_DECL_NSIFORMPOSTACTIONCHANNEL
     104             :   NS_DECL_NSIUPLOADCHANNEL2
     105             :   NS_DECL_NSITRACEABLECHANNEL
     106             :   NS_DECL_NSITIMEDCHANNEL
     107             :   NS_DECL_NSITHROTTLEDINPUTCHANNEL
     108             :   NS_DECL_NSICLASSIFIEDCHANNEL
     109             : 
     110             :   NS_DECLARE_STATIC_IID_ACCESSOR(HTTP_BASE_CHANNEL_IID)
     111             : 
     112             :   HttpBaseChannel();
     113             : 
     114             :   virtual MOZ_MUST_USE nsresult Init(nsIURI *aURI, uint32_t aCaps,
     115             :                                      nsProxyInfo *aProxyInfo,
     116             :                                      uint32_t aProxyResolveFlags,
     117             :                                      nsIURI *aProxyURI,
     118             :                                      uint64_t aChannelId);
     119             : 
     120             :   // nsIRequest
     121             :   NS_IMETHOD GetName(nsACString& aName) override;
     122             :   NS_IMETHOD IsPending(bool *aIsPending) override;
     123             :   NS_IMETHOD GetStatus(nsresult *aStatus) override;
     124             :   NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup) override;
     125             :   NS_IMETHOD SetLoadGroup(nsILoadGroup *aLoadGroup) override;
     126             :   NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) override;
     127             :   NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) override;
     128             :   NS_IMETHOD SetDocshellUserAgentOverride();
     129             : 
     130             :   // nsIChannel
     131             :   NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI) override;
     132             :   NS_IMETHOD SetOriginalURI(nsIURI *aOriginalURI) override;
     133             :   NS_IMETHOD GetURI(nsIURI **aURI) override;
     134             :   NS_IMETHOD GetOwner(nsISupports **aOwner) override;
     135             :   NS_IMETHOD SetOwner(nsISupports *aOwner) override;
     136             :   NS_IMETHOD GetLoadInfo(nsILoadInfo **aLoadInfo) override;
     137             :   NS_IMETHOD SetLoadInfo(nsILoadInfo *aLoadInfo) override;
     138             :   NS_IMETHOD GetIsDocument(bool *aIsDocument) override;
     139             :   NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks) override;
     140             :   NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks) override;
     141             :   NS_IMETHOD GetContentType(nsACString& aContentType) override;
     142             :   NS_IMETHOD SetContentType(const nsACString& aContentType) override;
     143             :   NS_IMETHOD GetContentCharset(nsACString& aContentCharset) override;
     144             :   NS_IMETHOD SetContentCharset(const nsACString& aContentCharset) override;
     145             :   NS_IMETHOD GetContentDisposition(uint32_t *aContentDisposition) override;
     146             :   NS_IMETHOD SetContentDisposition(uint32_t aContentDisposition) override;
     147             :   NS_IMETHOD GetContentDispositionFilename(nsAString& aContentDispositionFilename) override;
     148             :   NS_IMETHOD SetContentDispositionFilename(const nsAString& aContentDispositionFilename) override;
     149             :   NS_IMETHOD GetContentDispositionHeader(nsACString& aContentDispositionHeader) override;
     150             :   NS_IMETHOD GetContentLength(int64_t *aContentLength) override;
     151             :   NS_IMETHOD SetContentLength(int64_t aContentLength) override;
     152             :   NS_IMETHOD Open(nsIInputStream **aResult) override;
     153             :   NS_IMETHOD Open2(nsIInputStream **aResult) override;
     154             :   NS_IMETHOD GetBlockAuthPrompt(bool* aValue) override;
     155             :   NS_IMETHOD SetBlockAuthPrompt(bool aValue) override;
     156             : 
     157             :   // nsIEncodedChannel
     158             :   NS_IMETHOD GetApplyConversion(bool *value) override;
     159             :   NS_IMETHOD SetApplyConversion(bool value) override;
     160             :   NS_IMETHOD GetContentEncodings(nsIUTF8StringEnumerator** aEncodings) override;
     161             :   NS_IMETHOD DoApplyContentConversions(nsIStreamListener *aNextListener,
     162             :                                        nsIStreamListener **aNewNextListener,
     163             :                                        nsISupports *aCtxt) override;
     164             : 
     165             :   // HttpBaseChannel::nsIHttpChannel
     166             :   NS_IMETHOD GetRequestMethod(nsACString& aMethod) override;
     167             :   NS_IMETHOD SetRequestMethod(const nsACString& aMethod) override;
     168             :   NS_IMETHOD GetReferrer(nsIURI **referrer) override;
     169             :   NS_IMETHOD SetReferrer(nsIURI *referrer) override;
     170             :   NS_IMETHOD GetReferrerPolicy(uint32_t *referrerPolicy) override;
     171             :   NS_IMETHOD SetReferrerWithPolicy(nsIURI *referrer, uint32_t referrerPolicy) override;
     172             :   NS_IMETHOD GetRequestHeader(const nsACString& aHeader, nsACString& aValue) override;
     173             :   NS_IMETHOD SetRequestHeader(const nsACString& aHeader,
     174             :                               const nsACString& aValue, bool aMerge) override;
     175             :   NS_IMETHOD SetEmptyRequestHeader(const nsACString& aHeader) override;
     176             :   NS_IMETHOD VisitRequestHeaders(nsIHttpHeaderVisitor *visitor) override;
     177             :   NS_IMETHOD VisitNonDefaultRequestHeaders(nsIHttpHeaderVisitor *visitor) override;
     178             :   NS_IMETHOD GetResponseHeader(const nsACString &header, nsACString &value) override;
     179             :   NS_IMETHOD SetResponseHeader(const nsACString& header,
     180             :                                const nsACString& value, bool merge) override;
     181             :   NS_IMETHOD VisitResponseHeaders(nsIHttpHeaderVisitor *visitor) override;
     182             :   NS_IMETHOD GetOriginalResponseHeader(const nsACString &aHeader,
     183             :                                        nsIHttpHeaderVisitor *aVisitor) override;
     184             :   NS_IMETHOD VisitOriginalResponseHeaders(nsIHttpHeaderVisitor *aVisitor) override;
     185             :   NS_IMETHOD GetAllowPipelining(bool *value) override; // deprecated
     186             :   NS_IMETHOD SetAllowPipelining(bool value) override;  // deprecated
     187             :   NS_IMETHOD GetAllowSTS(bool *value) override;
     188             :   NS_IMETHOD SetAllowSTS(bool value) override;
     189             :   NS_IMETHOD GetRedirectionLimit(uint32_t *value) override;
     190             :   NS_IMETHOD SetRedirectionLimit(uint32_t value) override;
     191             :   NS_IMETHOD IsNoStoreResponse(bool *value) override;
     192             :   NS_IMETHOD IsNoCacheResponse(bool *value) override;
     193             :   NS_IMETHOD IsPrivateResponse(bool *value) override;
     194             :   NS_IMETHOD GetResponseStatus(uint32_t *aValue) override;
     195             :   NS_IMETHOD GetResponseStatusText(nsACString& aValue) override;
     196             :   NS_IMETHOD GetRequestSucceeded(bool *aValue) override;
     197             :   NS_IMETHOD RedirectTo(nsIURI *newURI) override;
     198             :   NS_IMETHOD GetRequestContextID(uint64_t *aRCID) override;
     199             :   NS_IMETHOD GetTransferSize(uint64_t *aTransferSize) override;
     200             :   NS_IMETHOD GetDecodedBodySize(uint64_t *aDecodedBodySize) override;
     201             :   NS_IMETHOD GetEncodedBodySize(uint64_t *aEncodedBodySize) override;
     202             :   NS_IMETHOD SetRequestContextID(uint64_t aRCID) override;
     203             :   NS_IMETHOD GetIsMainDocumentChannel(bool* aValue) override;
     204             :   NS_IMETHOD SetIsMainDocumentChannel(bool aValue) override;
     205             :   NS_IMETHOD GetProtocolVersion(nsACString & aProtocolVersion) override;
     206             :   NS_IMETHOD GetChannelId(uint64_t *aChannelId) override;
     207             :   NS_IMETHOD SetChannelId(uint64_t aChannelId) override;
     208             :   NS_IMETHOD GetTopLevelContentWindowId(uint64_t *aContentWindowId) override;
     209             :   NS_IMETHOD SetTopLevelContentWindowId(uint64_t aContentWindowId) override;
     210             :   NS_IMETHOD GetTopLevelOuterContentWindowId(uint64_t *aWindowId) override;
     211             :   NS_IMETHOD SetTopLevelOuterContentWindowId(uint64_t aWindowId) override;
     212             :   NS_IMETHOD GetIsTrackingResource(bool* aIsTrackingResource) override;
     213             : 
     214             :   // nsIHttpChannelInternal
     215             :   NS_IMETHOD GetDocumentURI(nsIURI **aDocumentURI) override;
     216             :   NS_IMETHOD SetDocumentURI(nsIURI *aDocumentURI) override;
     217             :   NS_IMETHOD GetRequestVersion(uint32_t *major, uint32_t *minor) override;
     218             :   NS_IMETHOD GetResponseVersion(uint32_t *major, uint32_t *minor) override;
     219             :   NS_IMETHOD SetCookie(const char *aCookieHeader) override;
     220             :   NS_IMETHOD GetThirdPartyFlags(uint32_t *aForce) override;
     221             :   NS_IMETHOD SetThirdPartyFlags(uint32_t aForce) override;
     222             :   NS_IMETHOD GetForceAllowThirdPartyCookie(bool *aForce) override;
     223             :   NS_IMETHOD SetForceAllowThirdPartyCookie(bool aForce) override;
     224             :   NS_IMETHOD GetCanceled(bool *aCanceled) override;
     225             :   NS_IMETHOD GetChannelIsForDownload(bool *aChannelIsForDownload) override;
     226             :   NS_IMETHOD SetChannelIsForDownload(bool aChannelIsForDownload) override;
     227             :   NS_IMETHOD SetCacheKeysRedirectChain(nsTArray<nsCString> *cacheKeys) override;
     228             :   NS_IMETHOD GetLocalAddress(nsACString& addr) override;
     229             :   NS_IMETHOD GetLocalPort(int32_t* port) override;
     230             :   NS_IMETHOD GetRemoteAddress(nsACString& addr) override;
     231             :   NS_IMETHOD GetRemotePort(int32_t* port) override;
     232             :   NS_IMETHOD GetAllowSpdy(bool *aAllowSpdy) override;
     233             :   NS_IMETHOD SetAllowSpdy(bool aAllowSpdy) override;
     234             :   NS_IMETHOD GetAllowAltSvc(bool *aAllowAltSvc) override;
     235             :   NS_IMETHOD SetAllowAltSvc(bool aAllowAltSvc) override;
     236             :   NS_IMETHOD GetBeConservative(bool *aBeConservative) override;
     237             :   NS_IMETHOD SetBeConservative(bool aBeConservative) override;
     238             :   NS_IMETHOD GetApiRedirectToURI(nsIURI * *aApiRedirectToURI) override;
     239             :   virtual MOZ_MUST_USE nsresult AddSecurityMessage(const nsAString &aMessageTag, const nsAString &aMessageCategory);
     240             :   NS_IMETHOD TakeAllSecurityMessages(nsCOMArray<nsISecurityConsoleMessage> &aMessages) override;
     241             :   NS_IMETHOD GetResponseTimeoutEnabled(bool *aEnable) override;
     242             :   NS_IMETHOD SetResponseTimeoutEnabled(bool aEnable) override;
     243             :   NS_IMETHOD GetInitialRwin(uint32_t* aRwin) override;
     244             :   NS_IMETHOD SetInitialRwin(uint32_t aRwin) override;
     245             :   NS_IMETHOD GetNetworkInterfaceId(nsACString& aNetworkInterfaceId) override;
     246             :   NS_IMETHOD SetNetworkInterfaceId(const nsACString& aNetworkInterfaceId) override;
     247             :   NS_IMETHOD ForcePending(bool aForcePending) override;
     248             :   NS_IMETHOD GetLastModifiedTime(PRTime* lastModifiedTime) override;
     249             :   NS_IMETHOD GetCorsIncludeCredentials(bool* aInclude) override;
     250             :   NS_IMETHOD SetCorsIncludeCredentials(bool aInclude) override;
     251             :   NS_IMETHOD GetCorsMode(uint32_t* aCorsMode) override;
     252             :   NS_IMETHOD SetCorsMode(uint32_t aCorsMode) override;
     253             :   NS_IMETHOD GetRedirectMode(uint32_t* aRedirectMode) override;
     254             :   NS_IMETHOD SetRedirectMode(uint32_t aRedirectMode) override;
     255             :   NS_IMETHOD GetFetchCacheMode(uint32_t* aFetchCacheMode) override;
     256             :   NS_IMETHOD SetFetchCacheMode(uint32_t aFetchCacheMode) override;
     257             :   NS_IMETHOD GetTopWindowURI(nsIURI **aTopWindowURI) override;
     258             :   NS_IMETHOD SetTopWindowURIIfUnknown(nsIURI *aTopWindowURI) override;
     259             :   NS_IMETHOD GetProxyURI(nsIURI **proxyURI) override;
     260             :   virtual void SetCorsPreflightParameters(const nsTArray<nsCString>& unsafeHeaders) override;
     261             :   NS_IMETHOD GetConnectionInfoHashKey(nsACString& aConnectionInfoHashKey) override;
     262             :   NS_IMETHOD GetIntegrityMetadata(nsAString& aIntegrityMetadata) override;
     263             :   NS_IMETHOD SetIntegrityMetadata(const nsAString& aIntegrityMetadata) override;
     264             :   NS_IMETHOD GetLastRedirectFlags(uint32_t *aValue) override;
     265             :   NS_IMETHOD SetLastRedirectFlags(uint32_t aValue) override;
     266             : 
     267          13 :   inline void CleanRedirectCacheChainIfNecessary()
     268             :   {
     269          13 :       mRedirectedCachekeys = nullptr;
     270          13 :   }
     271             :   NS_IMETHOD HTTPUpgrade(const nsACString & aProtocolName,
     272             :                          nsIHttpUpgradeListener *aListener) override;
     273             : 
     274             :   // nsISupportsPriority
     275             :   NS_IMETHOD GetPriority(int32_t *value) override;
     276             :   NS_IMETHOD AdjustPriority(int32_t delta) override;
     277             : 
     278             :   // nsIClassOfService
     279           0 :   NS_IMETHOD GetClassFlags(uint32_t *outFlags) override { *outFlags = mClassOfService; return NS_OK; }
     280             : 
     281             :   // nsIResumableChannel
     282             :   NS_IMETHOD GetEntityID(nsACString& aEntityID) override;
     283             : 
     284             : 
     285             :   // nsIConsoleReportCollector
     286             :   void
     287             :   AddConsoleReport(uint32_t aErrorFlags, const nsACString& aCategory,
     288             :                    nsContentUtils::PropertiesFile aPropertiesFile,
     289             :                    const nsACString& aSourceFileURI,
     290             :                    uint32_t aLineNumber, uint32_t aColumnNumber,
     291             :                    const nsACString& aMessageName,
     292             :                    const nsTArray<nsString>& aStringParams) override;
     293             : 
     294             :   void
     295             :   FlushReportsToConsole(uint64_t aInnerWindowID,
     296             :                         ReportAction aAction = ReportAction::Forget) override;
     297             : 
     298             :   void
     299             :   FlushConsoleReports(nsIDocument* aDocument,
     300             :                       ReportAction aAction = ReportAction::Forget) override;
     301             : 
     302             :   void
     303             :   FlushConsoleReports(nsILoadGroup* aLoadGroup,
     304             :                       ReportAction aAction = ReportAction::Forget) override;
     305             : 
     306             :   void
     307             :   FlushConsoleReports(nsIConsoleReportCollector* aCollector) override;
     308             : 
     309             :   void
     310             :   ClearConsoleReports() override;
     311             : 
     312             :   class nsContentEncodings : public nsIUTF8StringEnumerator
     313             :     {
     314             :     public:
     315             :         NS_DECL_ISUPPORTS
     316             :         NS_DECL_NSIUTF8STRINGENUMERATOR
     317             : 
     318             :         nsContentEncodings(nsIHttpChannel* aChannel, const char* aEncodingHeader);
     319             : 
     320             :     private:
     321             :         virtual ~nsContentEncodings();
     322             : 
     323             :         MOZ_MUST_USE nsresult PrepareForNext(void);
     324             : 
     325             :         // We do not own the buffer.  The channel owns it.
     326             :         const char* mEncodingHeader;
     327             :         const char* mCurStart;  // points to start of current header
     328             :         const char* mCurEnd;  // points to end of current header
     329             : 
     330             :         // Hold a ref to our channel so that it can't go away and take the
     331             :         // header with it.
     332             :         nsCOMPtr<nsIHttpChannel> mChannel;
     333             : 
     334             :         bool mReady;
     335             :     };
     336             : 
     337           3 :     nsHttpResponseHead * GetResponseHead() const { return mResponseHead; }
     338           3 :     nsHttpRequestHead * GetRequestHead() { return &mRequestHead; }
     339             : 
     340           3 :     const NetAddr& GetSelfAddr() { return mSelfAddr; }
     341           3 :     const NetAddr& GetPeerAddr() { return mPeerAddr; }
     342             : 
     343             :     MOZ_MUST_USE nsresult OverrideSecurityInfo(nsISupports* aSecurityInfo);
     344             : 
     345             : public: /* Necko internal use only... */
     346           3 :     int64_t GetAltDataLength() { return mAltDataLength; }
     347             :     bool IsNavigation();
     348             : 
     349             :     // Return whether upon a redirect code of httpStatus for method, the
     350             :     // request method should be rewritten to GET.
     351             :     static bool ShouldRewriteRedirectToGET(uint32_t httpStatus,
     352             :                                            nsHttpRequestHead::ParsedMethodType method);
     353             : 
     354             :     // Like nsIEncodedChannel::DoApplyConversions except context is set to
     355             :     // mListenerContext.
     356             :     MOZ_MUST_USE nsresult
     357             :     DoApplyContentConversions(nsIStreamListener *aNextListener,
     358             :                               nsIStreamListener **aNewNextListener);
     359             : 
     360             :     // Callback on STS thread called by CopyComplete when NS_AsyncCopy()
     361             :     // is finished. This function works as a proxy function to dispatch
     362             :     // |EnsureUploadStreamIsCloneableComplete| to main thread.
     363             :     virtual void OnCopyComplete(nsresult aStatus);
     364             : 
     365           0 :     void SetIsTrackingResource()
     366             :     {
     367           0 :       mIsTrackingResource = true;
     368           0 :     }
     369             : 
     370           6 :     const uint64_t& ChannelId() const
     371             :     {
     372           6 :       return mChannelId;
     373             :     }
     374             : 
     375             : protected:
     376             :   // Handle notifying listener, removing from loadgroup if request failed.
     377             :   void     DoNotifyListener();
     378             :   virtual void DoNotifyListenerCleanup() = 0;
     379             : 
     380             :   // drop reference to listener, its callbacks, and the progress sink
     381             :   virtual void ReleaseListeners();
     382             : 
     383             :   // This is fired only when a cookie is created due to the presence of
     384             :   // Set-Cookie header in the response header of any network request.
     385             :   // This notification will come only after the "http-on-examine-response"
     386             :   // was fired.
     387             :   void NotifySetCookie(char const *aCookie);
     388             : 
     389             :   mozilla::dom::Performance* GetPerformance();
     390             :   nsIURI* GetReferringPage();
     391             :   nsPIDOMWindowInner* GetInnerDOMWindow();
     392             : 
     393             :   void AddCookiesToRequest();
     394             :   virtual MOZ_MUST_USE nsresult
     395             :   SetupReplacementChannel(nsIURI *, nsIChannel *, bool preserveMethod,
     396             :                           uint32_t redirectFlags);
     397             : 
     398             :   // bundle calling OMR observers and marking flag into one function
     399           6 :   inline void CallOnModifyRequestObservers() {
     400           6 :     gHttpHandler->OnModifyRequest(this);
     401           6 :     mRequestObserversCalled = true;
     402           6 :   }
     403             : 
     404             :   // Helper function to simplify getting notification callbacks.
     405             :   template <class T>
     406          38 :   void GetCallback(nsCOMPtr<T> &aResult)
     407             :   {
     408          38 :     NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
     409             :                                   NS_GET_TEMPLATE_IID(T),
     410             :                                   getter_AddRefs(aResult));
     411          38 :   }
     412             : 
     413             :   // Redirect tracking
     414             :   // Checks whether or not aURI and mOriginalURI share the same domain.
     415             :   bool SameOriginWithOriginalUri(nsIURI *aURI);
     416             : 
     417             :   // GetPrincipal Returns the channel's URI principal.
     418             :   nsIPrincipal *GetURIPrincipal();
     419             : 
     420             :   MOZ_MUST_USE bool BypassServiceWorker() const;
     421             : 
     422             :   // Returns true if this channel should intercept the network request and prepare
     423             :   // for a possible synthesized response instead.
     424             :   bool ShouldIntercept(nsIURI* aURI = nullptr);
     425             : 
     426             :   // Callback on main thread when NS_AsyncCopy() is finished populating
     427             :   // the new mUploadStream.
     428             :   void EnsureUploadStreamIsCloneableComplete(nsresult aStatus);
     429             : 
     430             : #ifdef DEBUG
     431             :   // Check if mPrivateBrowsingId matches between LoadInfo and LoadContext.
     432             :   void AssertPrivateBrowsingId();
     433             : #endif
     434             : 
     435             :   // Called before we create the redirect target channel.
     436             :   already_AddRefed<nsILoadInfo> CloneLoadInfoForRedirect(nsIURI *newURI, uint32_t redirectFlags);
     437             : 
     438             :   friend class PrivateBrowsingChannel<HttpBaseChannel>;
     439             :   friend class InterceptFailedOnStop;
     440             : 
     441             : protected:
     442             :   // this section is for main-thread-only object
     443             :   // all the references need to be proxy released on main thread.
     444             :   nsCOMPtr<nsIURI> mURI;
     445             :   nsCOMPtr<nsIURI> mOriginalURI;
     446             :   nsCOMPtr<nsIURI> mDocumentURI;
     447             :   nsCOMPtr<nsILoadGroup> mLoadGroup;
     448             :   nsCOMPtr<nsILoadInfo> mLoadInfo;
     449             :   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
     450             :   nsCOMPtr<nsIProgressEventSink> mProgressSink;
     451             :   nsCOMPtr<nsIURI> mReferrer;
     452             :   nsCOMPtr<nsIApplicationCache> mApplicationCache;
     453             :   nsCOMPtr<nsIURI> mAPIRedirectToURI;
     454             :   nsCOMPtr<nsIURI> mProxyURI;
     455             :   nsCOMPtr<nsIPrincipal> mPrincipal;
     456             :   nsCOMPtr<nsIURI> mTopWindowURI;
     457             : 
     458             : private:
     459             :   // Proxy release all members above on main thread.
     460             :   void ReleaseMainThreadOnlyReferences();
     461             : 
     462             : protected:
     463             :   // Use Release-Acquire ordering to ensure the OMT ODA is ignored while channel
     464             :   // is canceled on main thread.
     465             :   Atomic<bool, ReleaseAcquire> mCanceled;
     466             : 
     467             :   nsTArray<Pair<nsString, nsString>> mSecurityConsoleMessages;
     468             : 
     469             :   nsCOMPtr<nsIStreamListener>       mListener;
     470             :   nsCOMPtr<nsISupports>             mListenerContext;
     471             :   nsCOMPtr<nsISupports>             mOwner;
     472             : 
     473             :   // An instance of nsHTTPCompressConv
     474             :   nsCOMPtr<nsIStreamListener>       mCompressListener;
     475             : 
     476             :   nsHttpRequestHead                 mRequestHead;
     477             :   // Upload throttling.
     478             :   nsCOMPtr<nsIInputChannelThrottleQueue> mThrottleQueue;
     479             :   nsCOMPtr<nsIInputStream>          mUploadStream;
     480             :   nsCOMPtr<nsIRunnable>             mUploadCloneableCallback;
     481             :   nsAutoPtr<nsHttpResponseHead>     mResponseHead;
     482             :   RefPtr<nsHttpConnectionInfo>      mConnectionInfo;
     483             :   nsCOMPtr<nsIProxyInfo>            mProxyInfo;
     484             :   nsCOMPtr<nsISupports>             mSecurityInfo;
     485             : 
     486             :   nsCString                         mSpec; // ASCII encoded URL spec
     487             :   nsCString                         mContentTypeHint;
     488             :   nsCString                         mContentCharsetHint;
     489             :   nsCString                         mUserSetCookieHeader;
     490             : 
     491             :   NetAddr                           mSelfAddr;
     492             :   NetAddr                           mPeerAddr;
     493             : 
     494             :   // HTTP Upgrade Data
     495             :   nsCString                        mUpgradeProtocol;
     496             :   nsCOMPtr<nsIHttpUpgradeListener> mUpgradeProtocolCallback;
     497             : 
     498             :   // Resumable channel specific data
     499             :   nsCString                         mEntityID;
     500             :   uint64_t                          mStartPos;
     501             : 
     502             :   Atomic<nsresult, ReleaseAcquire>  mStatus;
     503             :   uint32_t                          mLoadFlags;
     504             :   uint32_t                          mCaps;
     505             :   uint32_t                          mClassOfService;
     506             :   int16_t                           mPriority;
     507             :   uint8_t                           mRedirectionLimit;
     508             : 
     509             :   uint32_t                          mApplyConversion            : 1;
     510             :   uint32_t                          mIsPending                  : 1;
     511             :   uint32_t                          mWasOpened                  : 1;
     512             :   // if 1 all "http-on-{opening|modify|etc}-request" observers have been called
     513             :   uint32_t                          mRequestObserversCalled     : 1;
     514             :   uint32_t                          mResponseHeadersModified    : 1;
     515             :   uint32_t                          mAllowSTS                   : 1;
     516             :   uint32_t                          mThirdPartyFlags            : 3;
     517             :   uint32_t                          mUploadStreamHasHeaders     : 1;
     518             :   uint32_t                          mInheritApplicationCache    : 1;
     519             :   uint32_t                          mChooseApplicationCache     : 1;
     520             :   uint32_t                          mLoadedFromApplicationCache : 1;
     521             :   uint32_t                          mChannelIsForDownload       : 1;
     522             :   uint32_t                          mTracingEnabled             : 1;
     523             :   // True if timing collection is enabled
     524             :   uint32_t                          mTimingEnabled              : 1;
     525             :   uint32_t                          mAllowSpdy                  : 1;
     526             :   uint32_t                          mAllowAltSvc                : 1;
     527             :   uint32_t                          mBeConservative             : 1;
     528             :   uint32_t                          mResponseTimeoutEnabled     : 1;
     529             :   // A flag that should be false only if a cross-domain redirect occurred
     530             :   uint32_t                          mAllRedirectsSameOrigin     : 1;
     531             : 
     532             :   // Is 1 if no redirects have occured or if all redirects
     533             :   // pass the Resource Timing timing-allow-check
     534             :   uint32_t                          mAllRedirectsPassTimingAllowCheck : 1;
     535             : 
     536             :   // True if this channel was intercepted and could receive a synthesized response.
     537             :   uint32_t                          mResponseCouldBeSynthesized : 1;
     538             : 
     539             :   uint32_t                          mBlockAuthPrompt : 1;
     540             : 
     541             :   // If true, we behave as if the LOAD_FROM_CACHE flag has been set.
     542             :   // Used to enforce that flag's behavior but not expose it externally.
     543             :   uint32_t                          mAllowStaleCacheContent : 1;
     544             : 
     545             :   // Current suspension depth for this channel object
     546             :   uint32_t                          mSuspendCount;
     547             : 
     548             :   // Per channel transport window override (0 means no override)
     549             :   uint32_t                          mInitialRwin;
     550             : 
     551             :   nsAutoPtr<nsTArray<nsCString> >   mRedirectedCachekeys;
     552             : 
     553             :   uint32_t                          mProxyResolveFlags;
     554             : 
     555             :   uint32_t                          mContentDispositionHint;
     556             :   nsAutoPtr<nsString>               mContentDispositionFilename;
     557             : 
     558             :   RefPtr<nsHttpHandler>           mHttpHandler;  // keep gHttpHandler alive
     559             : 
     560             :   uint32_t                          mReferrerPolicy;
     561             : 
     562             :   // Performance tracking
     563             :   // The initiator type (for this resource) - how was the resource referenced in
     564             :   // the HTML file.
     565             :   nsString                          mInitiatorType;
     566             :   // Number of redirects that has occurred.
     567             :   int16_t                           mRedirectCount;
     568             :   // A time value equal to the starting time of the fetch that initiates the
     569             :   // redirect.
     570             :   mozilla::TimeStamp                mRedirectStartTimeStamp;
     571             :   // A time value equal to the time immediately after receiving the last byte of
     572             :   // the response of the last redirect.
     573             :   mozilla::TimeStamp                mRedirectEndTimeStamp;
     574             : 
     575             :   PRTime                            mChannelCreationTime;
     576             :   TimeStamp                         mChannelCreationTimestamp;
     577             :   TimeStamp                         mAsyncOpenTime;
     578             :   TimeStamp                         mCacheReadStart;
     579             :   TimeStamp                         mCacheReadEnd;
     580             :   TimeStamp                         mLaunchServiceWorkerStart;
     581             :   TimeStamp                         mLaunchServiceWorkerEnd;
     582             :   TimeStamp                         mDispatchFetchEventStart;
     583             :   TimeStamp                         mDispatchFetchEventEnd;
     584             :   TimeStamp                         mHandleFetchEventStart;
     585             :   TimeStamp                         mHandleFetchEventEnd;
     586             :   // copied from the transaction before we null out mTransaction
     587             :   // so that the timing can still be queried from OnStopRequest
     588             :   TimingStruct                      mTransactionTimings;
     589             : 
     590             :   bool                              mForcePending;
     591             : 
     592             :   bool mCorsIncludeCredentials;
     593             :   uint32_t mCorsMode;
     594             :   uint32_t mRedirectMode;
     595             :   uint32_t mFetchCacheMode;
     596             : 
     597             :   // These parameters are used to ensure that we do not call OnStartRequest and
     598             :   // OnStopRequest more than once.
     599             :   bool mOnStartRequestCalled;
     600             :   bool mOnStopRequestCalled;
     601             : 
     602             :   // Defaults to false. Is set to true at the begining of OnStartRequest.
     603             :   // Used to ensure methods can't be called before OnStartRequest.
     604             :   bool mAfterOnStartRequestBegun;
     605             : 
     606             :   uint64_t mTransferSize;
     607             :   uint64_t mDecodedBodySize;
     608             :   uint64_t mEncodedBodySize;
     609             : 
     610             :   // The network interface id that's associated with this channel.
     611             :   nsCString mNetworkInterfaceId;
     612             : 
     613             :   uint64_t mRequestContextID;
     614             :   bool EnsureRequestContextID();
     615             : 
     616             :   // ID of the top-level document's inner window this channel is being
     617             :   // originated from.
     618             :   uint64_t mContentWindowId;
     619             : 
     620             :   uint64_t mTopLevelOuterContentWindowId;
     621             :   void EnsureTopLevelOuterContentWindowId();
     622             : 
     623             :   bool                              mRequireCORSPreflight;
     624             :   nsTArray<nsCString>               mUnsafeHeaders;
     625             : 
     626             :   nsCOMPtr<nsIConsoleReportCollector> mReportCollector;
     627             : 
     628             :   // Holds the name of the preferred alt-data type.
     629             :   nsCString mPreferredCachedAltDataType;
     630             :   // Holds the name of the alternative data type the channel returned.
     631             :   nsCString mAvailableCachedAltDataType;
     632             :   int64_t   mAltDataLength;
     633             : 
     634             :   bool mForceMainDocumentChannel;
     635             :   bool mIsTrackingResource;
     636             : 
     637             :   uint64_t mChannelId;
     638             : 
     639             :   // If this channel was created as the result of a redirect, then this value
     640             :   // will reflect the redirect flags passed to the SetupReplacementChannel()
     641             :   // method.
     642             :   uint32_t mLastRedirectFlags;
     643             : 
     644             :   nsString mIntegrityMetadata;
     645             : 
     646             :   // Classified channel's matched information
     647             :   nsCString mMatchedList;
     648             :   nsCString mMatchedProvider;
     649             :   nsCString mMatchedPrefix;
     650             : };
     651             : 
     652             : NS_DEFINE_STATIC_IID_ACCESSOR(HttpBaseChannel, HTTP_BASE_CHANNEL_IID)
     653             : 
     654             : // Share some code while working around C++'s absurd inability to handle casting
     655             : // of member functions between base/derived types.
     656             : // - We want to store member function pointer to call at resume time, but one
     657             : //   such function--HandleAsyncAbort--we want to share between the
     658             : //   nsHttpChannel/HttpChannelChild.  Can't define it in base class, because
     659             : //   then we'd have to cast member function ptr between base/derived class
     660             : //   types.  Sigh...
     661             : template <class T>
     662             : class HttpAsyncAborter
     663             : {
     664             : public:
     665          10 :   explicit HttpAsyncAborter(T *derived) : mThis(derived), mCallOnResume(0) {}
     666             : 
     667             :   // Aborts channel: calls OnStart/Stop with provided status, removes channel
     668             :   // from loadGroup.
     669             :   MOZ_MUST_USE nsresult AsyncAbort(nsresult status);
     670             : 
     671             :   // Does most the actual work.
     672             :   void HandleAsyncAbort();
     673             : 
     674             :   // AsyncCall calls a member function asynchronously (via an event).
     675             :   // retval isn't refcounted and is set only when event was successfully
     676             :   // posted, the event is returned for the purpose of cancelling when needed
     677             :   MOZ_MUST_USE virtual nsresult AsyncCall(void (T::*funcPtr)(),
     678             :                                           nsRunnableMethod<T> **retval = nullptr);
     679             : private:
     680             :   T *mThis;
     681             : 
     682             : protected:
     683             :   // Function to be called at resume time
     684             :   void (T::* mCallOnResume)(void);
     685             : };
     686             : 
     687             : template <class T>
     688           0 : MOZ_MUST_USE nsresult HttpAsyncAborter<T>::AsyncAbort(nsresult status)
     689             : {
     690           0 :   MOZ_LOG(gHttpLog, LogLevel::Debug,
     691             :          ("HttpAsyncAborter::AsyncAbort [this=%p status=%" PRIx32 "]\n",
     692             :           mThis, static_cast<uint32_t>(status)));
     693             : 
     694           0 :   mThis->mStatus = status;
     695             : 
     696             :   // if this fails?  Callers ignore our return value anyway....
     697           0 :   return AsyncCall(&T::HandleAsyncAbort);
     698             : }
     699             : 
     700             : // Each subclass needs to define its own version of this (which just calls this
     701             : // base version), else we wind up casting base/derived member function ptrs
     702             : template <class T>
     703           0 : inline void HttpAsyncAborter<T>::HandleAsyncAbort()
     704             : {
     705           0 :   NS_PRECONDITION(!mCallOnResume, "How did that happen?");
     706             : 
     707           0 :   if (mThis->mSuspendCount) {
     708           0 :     MOZ_LOG(gHttpLog, LogLevel::Debug,
     709             :            ("Waiting until resume to do async notification [this=%p]\n", mThis));
     710           0 :     mCallOnResume = &T::HandleAsyncAbort;
     711           0 :     return;
     712             :   }
     713             : 
     714           0 :   mThis->DoNotifyListener();
     715             : 
     716             :   // finally remove ourselves from the load group.
     717           0 :   if (mThis->mLoadGroup)
     718           0 :     mThis->mLoadGroup->RemoveRequest(mThis, nullptr, mThis->mStatus);
     719             : }
     720             : 
     721             : template <class T>
     722           3 : nsresult HttpAsyncAborter<T>::AsyncCall(void (T::*funcPtr)(),
     723             :                                         nsRunnableMethod<T> **retval)
     724             : {
     725             :   nsresult rv;
     726             : 
     727             :   RefPtr<nsRunnableMethod<T>> event =
     728           6 :     NewRunnableMethod("net::HttpAsyncAborter::AsyncCall", mThis, funcPtr);
     729           3 :   rv = NS_DispatchToCurrentThread(event);
     730           3 :   if (NS_SUCCEEDED(rv) && retval) {
     731           3 :     *retval = event;
     732             :   }
     733             : 
     734           6 :   return rv;
     735             : }
     736             : 
     737             : class ProxyReleaseRunnable final : public mozilla::Runnable
     738             : {
     739             : public:
     740           0 :   explicit ProxyReleaseRunnable(nsTArray<nsCOMPtr<nsISupports>>&& aDoomed)
     741           0 :     : Runnable("ProxyReleaseRunnable")
     742           0 :     , mDoomed(Move(aDoomed))
     743           0 :   {}
     744             : 
     745             :   NS_IMETHOD
     746           0 :   Run() override
     747             :   {
     748           0 :     mDoomed.Clear();
     749           0 :     return NS_OK;
     750             :   }
     751             : 
     752             : private:
     753           0 :   virtual ~ProxyReleaseRunnable() {}
     754             : 
     755             :   nsTArray<nsCOMPtr<nsISupports>> mDoomed;
     756             : };
     757             : 
     758             : } // namespace net
     759             : } // namespace mozilla
     760             : 
     761             : #endif // mozilla_net_HttpBaseChannel_h

Generated by: LCOV version 1.13