michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_net_HttpChannelChild_h michael@0: #define mozilla_net_HttpChannelChild_h michael@0: michael@0: #include "mozilla/net/HttpBaseChannel.h" michael@0: #include "mozilla/net/PHttpChannelChild.h" michael@0: #include "mozilla/net/ChannelEventQueue.h" michael@0: michael@0: #include "nsIStreamListener.h" michael@0: #include "nsILoadGroup.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsIInterfaceRequestorUtils.h" michael@0: #include "nsIProgressEventSink.h" michael@0: #include "nsICacheInfoChannel.h" michael@0: #include "nsIApplicationCache.h" michael@0: #include "nsIApplicationCacheChannel.h" michael@0: #include "nsIUploadChannel2.h" michael@0: #include "nsIResumableChannel.h" michael@0: #include "nsIProxiedChannel.h" michael@0: #include "nsIAsyncVerifyRedirectCallback.h" michael@0: #include "nsIAssociatedContentSecurity.h" michael@0: #include "nsIChildChannel.h" michael@0: #include "nsIHttpChannelChild.h" michael@0: #include "nsIDivertableChannel.h" michael@0: #include "mozilla/net/DNS.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: class HttpChannelChild : public PHttpChannelChild michael@0: , public HttpBaseChannel michael@0: , public HttpAsyncAborter michael@0: , public nsICacheInfoChannel michael@0: , public nsIProxiedChannel michael@0: , public nsIApplicationCacheChannel michael@0: , public nsIAsyncVerifyRedirectCallback michael@0: , public nsIAssociatedContentSecurity michael@0: , public nsIChildChannel michael@0: , public nsIHttpChannelChild michael@0: , public nsIDivertableChannel michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSICACHEINFOCHANNEL michael@0: NS_DECL_NSIPROXIEDCHANNEL michael@0: NS_DECL_NSIAPPLICATIONCACHECONTAINER michael@0: NS_DECL_NSIAPPLICATIONCACHECHANNEL michael@0: NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK michael@0: NS_DECL_NSIASSOCIATEDCONTENTSECURITY michael@0: NS_DECL_NSICHILDCHANNEL michael@0: NS_DECL_NSIHTTPCHANNELCHILD michael@0: NS_DECL_NSIDIVERTABLECHANNEL michael@0: michael@0: HttpChannelChild(); michael@0: virtual ~HttpChannelChild(); michael@0: michael@0: // Methods HttpBaseChannel didn't implement for us or that we override. michael@0: // michael@0: // nsIRequest michael@0: NS_IMETHOD Cancel(nsresult status); michael@0: NS_IMETHOD Suspend(); michael@0: NS_IMETHOD Resume(); michael@0: // nsIChannel michael@0: NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo); michael@0: NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext); michael@0: // HttpBaseChannel::nsIHttpChannel michael@0: NS_IMETHOD SetRequestHeader(const nsACString& aHeader, michael@0: const nsACString& aValue, michael@0: bool aMerge); michael@0: NS_IMETHOD RedirectTo(nsIURI *newURI); michael@0: // nsIHttpChannelInternal michael@0: NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey); michael@0: NS_IMETHOD GetLocalAddress(nsACString& addr); michael@0: NS_IMETHOD GetLocalPort(int32_t* port); michael@0: NS_IMETHOD GetRemoteAddress(nsACString& addr); michael@0: NS_IMETHOD GetRemotePort(int32_t* port); michael@0: // nsISupportsPriority michael@0: NS_IMETHOD SetPriority(int32_t value); michael@0: // nsIResumableChannel michael@0: NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID); michael@0: michael@0: // IPDL holds a reference while the PHttpChannel protocol is live (starting at michael@0: // AsyncOpen, and ending at either OnStopRequest or any IPDL error, either of michael@0: // which call NeckoChild::DeallocPHttpChannelChild()). michael@0: void AddIPDLReference(); michael@0: void ReleaseIPDLReference(); michael@0: michael@0: bool IsSuspended(); michael@0: michael@0: void FlushedForDiversion(); michael@0: michael@0: protected: michael@0: bool RecvOnStartRequest(const nsresult& channelStatus, michael@0: const nsHttpResponseHead& responseHead, michael@0: const bool& useResponseHead, michael@0: const nsHttpHeaderArray& requestHeaders, michael@0: const bool& isFromCache, michael@0: const bool& cacheEntryAvailable, michael@0: const uint32_t& cacheExpirationTime, michael@0: const nsCString& cachedCharset, michael@0: const nsCString& securityInfoSerialization, michael@0: const NetAddr& selfAddr, michael@0: const NetAddr& peerAddr, michael@0: const int16_t& redirectCount) MOZ_OVERRIDE; michael@0: bool RecvOnTransportAndData(const nsresult& channelStatus, michael@0: const nsresult& status, michael@0: const uint64_t& progress, michael@0: const uint64_t& progressMax, michael@0: const nsCString& data, michael@0: const uint64_t& offset, michael@0: const uint32_t& count) MOZ_OVERRIDE; michael@0: bool RecvOnStopRequest(const nsresult& statusCode); michael@0: bool RecvOnProgress(const uint64_t& progress, const uint64_t& progressMax) MOZ_OVERRIDE; michael@0: bool RecvOnStatus(const nsresult& status) MOZ_OVERRIDE; michael@0: bool RecvFailedAsyncOpen(const nsresult& status) MOZ_OVERRIDE; michael@0: bool RecvRedirect1Begin(const uint32_t& newChannel, michael@0: const URIParams& newURI, michael@0: const uint32_t& redirectFlags, michael@0: const nsHttpResponseHead& responseHead) MOZ_OVERRIDE; michael@0: bool RecvRedirect3Complete() MOZ_OVERRIDE; michael@0: bool RecvAssociateApplicationCache(const nsCString& groupID, michael@0: const nsCString& clientID) MOZ_OVERRIDE; michael@0: bool RecvFlushedForDiversion() MOZ_OVERRIDE; michael@0: bool RecvDivertMessages() MOZ_OVERRIDE; michael@0: bool RecvDeleteSelf() MOZ_OVERRIDE; michael@0: michael@0: bool GetAssociatedContentSecurity(nsIAssociatedContentSecurity** res = nullptr); michael@0: virtual void DoNotifyListenerCleanup(); michael@0: michael@0: private: michael@0: RequestHeaderTuples mClientSetRequestHeaders; michael@0: nsCOMPtr mRedirectChannelChild; michael@0: nsCOMPtr mSecurityInfo; michael@0: michael@0: bool mIsFromCache; michael@0: bool mCacheEntryAvailable; michael@0: uint32_t mCacheExpirationTime; michael@0: nsCString mCachedCharset; michael@0: michael@0: // If ResumeAt is called before AsyncOpen, we need to send extra data upstream michael@0: bool mSendResumeAt; michael@0: michael@0: bool mIPCOpen; michael@0: bool mKeptAlive; // IPC kept open, but only for security info michael@0: nsRefPtr mEventQ; michael@0: michael@0: // Once set, OnData and possibly OnStop will be diverted to the parent. michael@0: bool mDivertingToParent; michael@0: // Once set, no OnStart/OnData/OnStop callbacks should be received from the michael@0: // parent channel, nor dequeued from the ChannelEventQueue. michael@0: bool mFlushedForDiversion; michael@0: // Set if SendSuspend is called. Determines if SendResume is needed when michael@0: // diverting callbacks to parent. michael@0: bool mSuspendSent; michael@0: michael@0: // true after successful AsyncOpen until OnStopRequest completes. michael@0: bool RemoteChannelExists() { return mIPCOpen && !mKeptAlive; } michael@0: michael@0: void AssociateApplicationCache(const nsCString &groupID, michael@0: const nsCString &clientID); michael@0: void OnStartRequest(const nsresult& channelStatus, michael@0: const nsHttpResponseHead& responseHead, michael@0: const bool& useResponseHead, michael@0: const nsHttpHeaderArray& requestHeaders, michael@0: const bool& isFromCache, michael@0: const bool& cacheEntryAvailable, michael@0: const uint32_t& cacheExpirationTime, michael@0: const nsCString& cachedCharset, michael@0: const nsCString& securityInfoSerialization, michael@0: const NetAddr& selfAddr, michael@0: const NetAddr& peerAddr); michael@0: void OnTransportAndData(const nsresult& channelStatus, michael@0: const nsresult& status, michael@0: const uint64_t progress, michael@0: const uint64_t& progressMax, michael@0: const nsCString& data, michael@0: const uint64_t& offset, michael@0: const uint32_t& count); michael@0: void OnStopRequest(const nsresult& channelStatus); michael@0: void OnProgress(const uint64_t& progress, const uint64_t& progressMax); michael@0: void OnStatus(const nsresult& status); michael@0: void FailedAsyncOpen(const nsresult& status); michael@0: void HandleAsyncAbort(); michael@0: void Redirect1Begin(const uint32_t& newChannelId, michael@0: const URIParams& newUri, michael@0: const uint32_t& redirectFlags, michael@0: const nsHttpResponseHead& responseHead); michael@0: void Redirect3Complete(); michael@0: void DeleteSelf(); michael@0: michael@0: friend class AssociateApplicationCacheEvent; michael@0: friend class StartRequestEvent; michael@0: friend class StopRequestEvent; michael@0: friend class TransportAndDataEvent; michael@0: friend class ProgressEvent; michael@0: friend class StatusEvent; michael@0: friend class FailedAsyncOpenEvent; michael@0: friend class Redirect1Event; michael@0: friend class Redirect3Event; michael@0: friend class DeleteSelfEvent; michael@0: friend class HttpAsyncAborter; michael@0: }; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // inline functions michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: inline bool michael@0: HttpChannelChild::IsSuspended() michael@0: { michael@0: return mSuspendCount != 0; michael@0: } michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_net_HttpChannelChild_h