1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/HttpChannelChild.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,223 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set sw=2 ts=8 et tw=80 : */ 1.6 + 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef mozilla_net_HttpChannelChild_h 1.12 +#define mozilla_net_HttpChannelChild_h 1.13 + 1.14 +#include "mozilla/net/HttpBaseChannel.h" 1.15 +#include "mozilla/net/PHttpChannelChild.h" 1.16 +#include "mozilla/net/ChannelEventQueue.h" 1.17 + 1.18 +#include "nsIStreamListener.h" 1.19 +#include "nsILoadGroup.h" 1.20 +#include "nsIInterfaceRequestor.h" 1.21 +#include "nsIInterfaceRequestorUtils.h" 1.22 +#include "nsIProgressEventSink.h" 1.23 +#include "nsICacheInfoChannel.h" 1.24 +#include "nsIApplicationCache.h" 1.25 +#include "nsIApplicationCacheChannel.h" 1.26 +#include "nsIUploadChannel2.h" 1.27 +#include "nsIResumableChannel.h" 1.28 +#include "nsIProxiedChannel.h" 1.29 +#include "nsIAsyncVerifyRedirectCallback.h" 1.30 +#include "nsIAssociatedContentSecurity.h" 1.31 +#include "nsIChildChannel.h" 1.32 +#include "nsIHttpChannelChild.h" 1.33 +#include "nsIDivertableChannel.h" 1.34 +#include "mozilla/net/DNS.h" 1.35 + 1.36 +namespace mozilla { 1.37 +namespace net { 1.38 + 1.39 +class HttpChannelChild : public PHttpChannelChild 1.40 + , public HttpBaseChannel 1.41 + , public HttpAsyncAborter<HttpChannelChild> 1.42 + , public nsICacheInfoChannel 1.43 + , public nsIProxiedChannel 1.44 + , public nsIApplicationCacheChannel 1.45 + , public nsIAsyncVerifyRedirectCallback 1.46 + , public nsIAssociatedContentSecurity 1.47 + , public nsIChildChannel 1.48 + , public nsIHttpChannelChild 1.49 + , public nsIDivertableChannel 1.50 +{ 1.51 +public: 1.52 + NS_DECL_ISUPPORTS_INHERITED 1.53 + NS_DECL_NSICACHEINFOCHANNEL 1.54 + NS_DECL_NSIPROXIEDCHANNEL 1.55 + NS_DECL_NSIAPPLICATIONCACHECONTAINER 1.56 + NS_DECL_NSIAPPLICATIONCACHECHANNEL 1.57 + NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK 1.58 + NS_DECL_NSIASSOCIATEDCONTENTSECURITY 1.59 + NS_DECL_NSICHILDCHANNEL 1.60 + NS_DECL_NSIHTTPCHANNELCHILD 1.61 + NS_DECL_NSIDIVERTABLECHANNEL 1.62 + 1.63 + HttpChannelChild(); 1.64 + virtual ~HttpChannelChild(); 1.65 + 1.66 + // Methods HttpBaseChannel didn't implement for us or that we override. 1.67 + // 1.68 + // nsIRequest 1.69 + NS_IMETHOD Cancel(nsresult status); 1.70 + NS_IMETHOD Suspend(); 1.71 + NS_IMETHOD Resume(); 1.72 + // nsIChannel 1.73 + NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo); 1.74 + NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext); 1.75 + // HttpBaseChannel::nsIHttpChannel 1.76 + NS_IMETHOD SetRequestHeader(const nsACString& aHeader, 1.77 + const nsACString& aValue, 1.78 + bool aMerge); 1.79 + NS_IMETHOD RedirectTo(nsIURI *newURI); 1.80 + // nsIHttpChannelInternal 1.81 + NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey); 1.82 + NS_IMETHOD GetLocalAddress(nsACString& addr); 1.83 + NS_IMETHOD GetLocalPort(int32_t* port); 1.84 + NS_IMETHOD GetRemoteAddress(nsACString& addr); 1.85 + NS_IMETHOD GetRemotePort(int32_t* port); 1.86 + // nsISupportsPriority 1.87 + NS_IMETHOD SetPriority(int32_t value); 1.88 + // nsIResumableChannel 1.89 + NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID); 1.90 + 1.91 + // IPDL holds a reference while the PHttpChannel protocol is live (starting at 1.92 + // AsyncOpen, and ending at either OnStopRequest or any IPDL error, either of 1.93 + // which call NeckoChild::DeallocPHttpChannelChild()). 1.94 + void AddIPDLReference(); 1.95 + void ReleaseIPDLReference(); 1.96 + 1.97 + bool IsSuspended(); 1.98 + 1.99 + void FlushedForDiversion(); 1.100 + 1.101 +protected: 1.102 + bool RecvOnStartRequest(const nsresult& channelStatus, 1.103 + const nsHttpResponseHead& responseHead, 1.104 + const bool& useResponseHead, 1.105 + const nsHttpHeaderArray& requestHeaders, 1.106 + const bool& isFromCache, 1.107 + const bool& cacheEntryAvailable, 1.108 + const uint32_t& cacheExpirationTime, 1.109 + const nsCString& cachedCharset, 1.110 + const nsCString& securityInfoSerialization, 1.111 + const NetAddr& selfAddr, 1.112 + const NetAddr& peerAddr, 1.113 + const int16_t& redirectCount) MOZ_OVERRIDE; 1.114 + bool RecvOnTransportAndData(const nsresult& channelStatus, 1.115 + const nsresult& status, 1.116 + const uint64_t& progress, 1.117 + const uint64_t& progressMax, 1.118 + const nsCString& data, 1.119 + const uint64_t& offset, 1.120 + const uint32_t& count) MOZ_OVERRIDE; 1.121 + bool RecvOnStopRequest(const nsresult& statusCode); 1.122 + bool RecvOnProgress(const uint64_t& progress, const uint64_t& progressMax) MOZ_OVERRIDE; 1.123 + bool RecvOnStatus(const nsresult& status) MOZ_OVERRIDE; 1.124 + bool RecvFailedAsyncOpen(const nsresult& status) MOZ_OVERRIDE; 1.125 + bool RecvRedirect1Begin(const uint32_t& newChannel, 1.126 + const URIParams& newURI, 1.127 + const uint32_t& redirectFlags, 1.128 + const nsHttpResponseHead& responseHead) MOZ_OVERRIDE; 1.129 + bool RecvRedirect3Complete() MOZ_OVERRIDE; 1.130 + bool RecvAssociateApplicationCache(const nsCString& groupID, 1.131 + const nsCString& clientID) MOZ_OVERRIDE; 1.132 + bool RecvFlushedForDiversion() MOZ_OVERRIDE; 1.133 + bool RecvDivertMessages() MOZ_OVERRIDE; 1.134 + bool RecvDeleteSelf() MOZ_OVERRIDE; 1.135 + 1.136 + bool GetAssociatedContentSecurity(nsIAssociatedContentSecurity** res = nullptr); 1.137 + virtual void DoNotifyListenerCleanup(); 1.138 + 1.139 +private: 1.140 + RequestHeaderTuples mClientSetRequestHeaders; 1.141 + nsCOMPtr<nsIChildChannel> mRedirectChannelChild; 1.142 + nsCOMPtr<nsISupports> mSecurityInfo; 1.143 + 1.144 + bool mIsFromCache; 1.145 + bool mCacheEntryAvailable; 1.146 + uint32_t mCacheExpirationTime; 1.147 + nsCString mCachedCharset; 1.148 + 1.149 + // If ResumeAt is called before AsyncOpen, we need to send extra data upstream 1.150 + bool mSendResumeAt; 1.151 + 1.152 + bool mIPCOpen; 1.153 + bool mKeptAlive; // IPC kept open, but only for security info 1.154 + nsRefPtr<ChannelEventQueue> mEventQ; 1.155 + 1.156 + // Once set, OnData and possibly OnStop will be diverted to the parent. 1.157 + bool mDivertingToParent; 1.158 + // Once set, no OnStart/OnData/OnStop callbacks should be received from the 1.159 + // parent channel, nor dequeued from the ChannelEventQueue. 1.160 + bool mFlushedForDiversion; 1.161 + // Set if SendSuspend is called. Determines if SendResume is needed when 1.162 + // diverting callbacks to parent. 1.163 + bool mSuspendSent; 1.164 + 1.165 + // true after successful AsyncOpen until OnStopRequest completes. 1.166 + bool RemoteChannelExists() { return mIPCOpen && !mKeptAlive; } 1.167 + 1.168 + void AssociateApplicationCache(const nsCString &groupID, 1.169 + const nsCString &clientID); 1.170 + void OnStartRequest(const nsresult& channelStatus, 1.171 + const nsHttpResponseHead& responseHead, 1.172 + const bool& useResponseHead, 1.173 + const nsHttpHeaderArray& requestHeaders, 1.174 + const bool& isFromCache, 1.175 + const bool& cacheEntryAvailable, 1.176 + const uint32_t& cacheExpirationTime, 1.177 + const nsCString& cachedCharset, 1.178 + const nsCString& securityInfoSerialization, 1.179 + const NetAddr& selfAddr, 1.180 + const NetAddr& peerAddr); 1.181 + void OnTransportAndData(const nsresult& channelStatus, 1.182 + const nsresult& status, 1.183 + const uint64_t progress, 1.184 + const uint64_t& progressMax, 1.185 + const nsCString& data, 1.186 + const uint64_t& offset, 1.187 + const uint32_t& count); 1.188 + void OnStopRequest(const nsresult& channelStatus); 1.189 + void OnProgress(const uint64_t& progress, const uint64_t& progressMax); 1.190 + void OnStatus(const nsresult& status); 1.191 + void FailedAsyncOpen(const nsresult& status); 1.192 + void HandleAsyncAbort(); 1.193 + void Redirect1Begin(const uint32_t& newChannelId, 1.194 + const URIParams& newUri, 1.195 + const uint32_t& redirectFlags, 1.196 + const nsHttpResponseHead& responseHead); 1.197 + void Redirect3Complete(); 1.198 + void DeleteSelf(); 1.199 + 1.200 + friend class AssociateApplicationCacheEvent; 1.201 + friend class StartRequestEvent; 1.202 + friend class StopRequestEvent; 1.203 + friend class TransportAndDataEvent; 1.204 + friend class ProgressEvent; 1.205 + friend class StatusEvent; 1.206 + friend class FailedAsyncOpenEvent; 1.207 + friend class Redirect1Event; 1.208 + friend class Redirect3Event; 1.209 + friend class DeleteSelfEvent; 1.210 + friend class HttpAsyncAborter<HttpChannelChild>; 1.211 +}; 1.212 + 1.213 +//----------------------------------------------------------------------------- 1.214 +// inline functions 1.215 +//----------------------------------------------------------------------------- 1.216 + 1.217 +inline bool 1.218 +HttpChannelChild::IsSuspended() 1.219 +{ 1.220 + return mSuspendCount != 0; 1.221 +} 1.222 + 1.223 +} // namespace net 1.224 +} // namespace mozilla 1.225 + 1.226 +#endif // mozilla_net_HttpChannelChild_h