Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set sw=2 ts=8 et tw=80 : */ |
michael@0 | 3 | |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef mozilla_net_HttpChannelChild_h |
michael@0 | 9 | #define mozilla_net_HttpChannelChild_h |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/net/HttpBaseChannel.h" |
michael@0 | 12 | #include "mozilla/net/PHttpChannelChild.h" |
michael@0 | 13 | #include "mozilla/net/ChannelEventQueue.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "nsIStreamListener.h" |
michael@0 | 16 | #include "nsILoadGroup.h" |
michael@0 | 17 | #include "nsIInterfaceRequestor.h" |
michael@0 | 18 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 19 | #include "nsIProgressEventSink.h" |
michael@0 | 20 | #include "nsICacheInfoChannel.h" |
michael@0 | 21 | #include "nsIApplicationCache.h" |
michael@0 | 22 | #include "nsIApplicationCacheChannel.h" |
michael@0 | 23 | #include "nsIUploadChannel2.h" |
michael@0 | 24 | #include "nsIResumableChannel.h" |
michael@0 | 25 | #include "nsIProxiedChannel.h" |
michael@0 | 26 | #include "nsIAsyncVerifyRedirectCallback.h" |
michael@0 | 27 | #include "nsIAssociatedContentSecurity.h" |
michael@0 | 28 | #include "nsIChildChannel.h" |
michael@0 | 29 | #include "nsIHttpChannelChild.h" |
michael@0 | 30 | #include "nsIDivertableChannel.h" |
michael@0 | 31 | #include "mozilla/net/DNS.h" |
michael@0 | 32 | |
michael@0 | 33 | namespace mozilla { |
michael@0 | 34 | namespace net { |
michael@0 | 35 | |
michael@0 | 36 | class HttpChannelChild : public PHttpChannelChild |
michael@0 | 37 | , public HttpBaseChannel |
michael@0 | 38 | , public HttpAsyncAborter<HttpChannelChild> |
michael@0 | 39 | , public nsICacheInfoChannel |
michael@0 | 40 | , public nsIProxiedChannel |
michael@0 | 41 | , public nsIApplicationCacheChannel |
michael@0 | 42 | , public nsIAsyncVerifyRedirectCallback |
michael@0 | 43 | , public nsIAssociatedContentSecurity |
michael@0 | 44 | , public nsIChildChannel |
michael@0 | 45 | , public nsIHttpChannelChild |
michael@0 | 46 | , public nsIDivertableChannel |
michael@0 | 47 | { |
michael@0 | 48 | public: |
michael@0 | 49 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 50 | NS_DECL_NSICACHEINFOCHANNEL |
michael@0 | 51 | NS_DECL_NSIPROXIEDCHANNEL |
michael@0 | 52 | NS_DECL_NSIAPPLICATIONCACHECONTAINER |
michael@0 | 53 | NS_DECL_NSIAPPLICATIONCACHECHANNEL |
michael@0 | 54 | NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK |
michael@0 | 55 | NS_DECL_NSIASSOCIATEDCONTENTSECURITY |
michael@0 | 56 | NS_DECL_NSICHILDCHANNEL |
michael@0 | 57 | NS_DECL_NSIHTTPCHANNELCHILD |
michael@0 | 58 | NS_DECL_NSIDIVERTABLECHANNEL |
michael@0 | 59 | |
michael@0 | 60 | HttpChannelChild(); |
michael@0 | 61 | virtual ~HttpChannelChild(); |
michael@0 | 62 | |
michael@0 | 63 | // Methods HttpBaseChannel didn't implement for us or that we override. |
michael@0 | 64 | // |
michael@0 | 65 | // nsIRequest |
michael@0 | 66 | NS_IMETHOD Cancel(nsresult status); |
michael@0 | 67 | NS_IMETHOD Suspend(); |
michael@0 | 68 | NS_IMETHOD Resume(); |
michael@0 | 69 | // nsIChannel |
michael@0 | 70 | NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo); |
michael@0 | 71 | NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext); |
michael@0 | 72 | // HttpBaseChannel::nsIHttpChannel |
michael@0 | 73 | NS_IMETHOD SetRequestHeader(const nsACString& aHeader, |
michael@0 | 74 | const nsACString& aValue, |
michael@0 | 75 | bool aMerge); |
michael@0 | 76 | NS_IMETHOD RedirectTo(nsIURI *newURI); |
michael@0 | 77 | // nsIHttpChannelInternal |
michael@0 | 78 | NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey); |
michael@0 | 79 | NS_IMETHOD GetLocalAddress(nsACString& addr); |
michael@0 | 80 | NS_IMETHOD GetLocalPort(int32_t* port); |
michael@0 | 81 | NS_IMETHOD GetRemoteAddress(nsACString& addr); |
michael@0 | 82 | NS_IMETHOD GetRemotePort(int32_t* port); |
michael@0 | 83 | // nsISupportsPriority |
michael@0 | 84 | NS_IMETHOD SetPriority(int32_t value); |
michael@0 | 85 | // nsIResumableChannel |
michael@0 | 86 | NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID); |
michael@0 | 87 | |
michael@0 | 88 | // IPDL holds a reference while the PHttpChannel protocol is live (starting at |
michael@0 | 89 | // AsyncOpen, and ending at either OnStopRequest or any IPDL error, either of |
michael@0 | 90 | // which call NeckoChild::DeallocPHttpChannelChild()). |
michael@0 | 91 | void AddIPDLReference(); |
michael@0 | 92 | void ReleaseIPDLReference(); |
michael@0 | 93 | |
michael@0 | 94 | bool IsSuspended(); |
michael@0 | 95 | |
michael@0 | 96 | void FlushedForDiversion(); |
michael@0 | 97 | |
michael@0 | 98 | protected: |
michael@0 | 99 | bool RecvOnStartRequest(const nsresult& channelStatus, |
michael@0 | 100 | const nsHttpResponseHead& responseHead, |
michael@0 | 101 | const bool& useResponseHead, |
michael@0 | 102 | const nsHttpHeaderArray& requestHeaders, |
michael@0 | 103 | const bool& isFromCache, |
michael@0 | 104 | const bool& cacheEntryAvailable, |
michael@0 | 105 | const uint32_t& cacheExpirationTime, |
michael@0 | 106 | const nsCString& cachedCharset, |
michael@0 | 107 | const nsCString& securityInfoSerialization, |
michael@0 | 108 | const NetAddr& selfAddr, |
michael@0 | 109 | const NetAddr& peerAddr, |
michael@0 | 110 | const int16_t& redirectCount) MOZ_OVERRIDE; |
michael@0 | 111 | bool RecvOnTransportAndData(const nsresult& channelStatus, |
michael@0 | 112 | const nsresult& status, |
michael@0 | 113 | const uint64_t& progress, |
michael@0 | 114 | const uint64_t& progressMax, |
michael@0 | 115 | const nsCString& data, |
michael@0 | 116 | const uint64_t& offset, |
michael@0 | 117 | const uint32_t& count) MOZ_OVERRIDE; |
michael@0 | 118 | bool RecvOnStopRequest(const nsresult& statusCode); |
michael@0 | 119 | bool RecvOnProgress(const uint64_t& progress, const uint64_t& progressMax) MOZ_OVERRIDE; |
michael@0 | 120 | bool RecvOnStatus(const nsresult& status) MOZ_OVERRIDE; |
michael@0 | 121 | bool RecvFailedAsyncOpen(const nsresult& status) MOZ_OVERRIDE; |
michael@0 | 122 | bool RecvRedirect1Begin(const uint32_t& newChannel, |
michael@0 | 123 | const URIParams& newURI, |
michael@0 | 124 | const uint32_t& redirectFlags, |
michael@0 | 125 | const nsHttpResponseHead& responseHead) MOZ_OVERRIDE; |
michael@0 | 126 | bool RecvRedirect3Complete() MOZ_OVERRIDE; |
michael@0 | 127 | bool RecvAssociateApplicationCache(const nsCString& groupID, |
michael@0 | 128 | const nsCString& clientID) MOZ_OVERRIDE; |
michael@0 | 129 | bool RecvFlushedForDiversion() MOZ_OVERRIDE; |
michael@0 | 130 | bool RecvDivertMessages() MOZ_OVERRIDE; |
michael@0 | 131 | bool RecvDeleteSelf() MOZ_OVERRIDE; |
michael@0 | 132 | |
michael@0 | 133 | bool GetAssociatedContentSecurity(nsIAssociatedContentSecurity** res = nullptr); |
michael@0 | 134 | virtual void DoNotifyListenerCleanup(); |
michael@0 | 135 | |
michael@0 | 136 | private: |
michael@0 | 137 | RequestHeaderTuples mClientSetRequestHeaders; |
michael@0 | 138 | nsCOMPtr<nsIChildChannel> mRedirectChannelChild; |
michael@0 | 139 | nsCOMPtr<nsISupports> mSecurityInfo; |
michael@0 | 140 | |
michael@0 | 141 | bool mIsFromCache; |
michael@0 | 142 | bool mCacheEntryAvailable; |
michael@0 | 143 | uint32_t mCacheExpirationTime; |
michael@0 | 144 | nsCString mCachedCharset; |
michael@0 | 145 | |
michael@0 | 146 | // If ResumeAt is called before AsyncOpen, we need to send extra data upstream |
michael@0 | 147 | bool mSendResumeAt; |
michael@0 | 148 | |
michael@0 | 149 | bool mIPCOpen; |
michael@0 | 150 | bool mKeptAlive; // IPC kept open, but only for security info |
michael@0 | 151 | nsRefPtr<ChannelEventQueue> mEventQ; |
michael@0 | 152 | |
michael@0 | 153 | // Once set, OnData and possibly OnStop will be diverted to the parent. |
michael@0 | 154 | bool mDivertingToParent; |
michael@0 | 155 | // Once set, no OnStart/OnData/OnStop callbacks should be received from the |
michael@0 | 156 | // parent channel, nor dequeued from the ChannelEventQueue. |
michael@0 | 157 | bool mFlushedForDiversion; |
michael@0 | 158 | // Set if SendSuspend is called. Determines if SendResume is needed when |
michael@0 | 159 | // diverting callbacks to parent. |
michael@0 | 160 | bool mSuspendSent; |
michael@0 | 161 | |
michael@0 | 162 | // true after successful AsyncOpen until OnStopRequest completes. |
michael@0 | 163 | bool RemoteChannelExists() { return mIPCOpen && !mKeptAlive; } |
michael@0 | 164 | |
michael@0 | 165 | void AssociateApplicationCache(const nsCString &groupID, |
michael@0 | 166 | const nsCString &clientID); |
michael@0 | 167 | void OnStartRequest(const nsresult& channelStatus, |
michael@0 | 168 | const nsHttpResponseHead& responseHead, |
michael@0 | 169 | const bool& useResponseHead, |
michael@0 | 170 | const nsHttpHeaderArray& requestHeaders, |
michael@0 | 171 | const bool& isFromCache, |
michael@0 | 172 | const bool& cacheEntryAvailable, |
michael@0 | 173 | const uint32_t& cacheExpirationTime, |
michael@0 | 174 | const nsCString& cachedCharset, |
michael@0 | 175 | const nsCString& securityInfoSerialization, |
michael@0 | 176 | const NetAddr& selfAddr, |
michael@0 | 177 | const NetAddr& peerAddr); |
michael@0 | 178 | void OnTransportAndData(const nsresult& channelStatus, |
michael@0 | 179 | const nsresult& status, |
michael@0 | 180 | const uint64_t progress, |
michael@0 | 181 | const uint64_t& progressMax, |
michael@0 | 182 | const nsCString& data, |
michael@0 | 183 | const uint64_t& offset, |
michael@0 | 184 | const uint32_t& count); |
michael@0 | 185 | void OnStopRequest(const nsresult& channelStatus); |
michael@0 | 186 | void OnProgress(const uint64_t& progress, const uint64_t& progressMax); |
michael@0 | 187 | void OnStatus(const nsresult& status); |
michael@0 | 188 | void FailedAsyncOpen(const nsresult& status); |
michael@0 | 189 | void HandleAsyncAbort(); |
michael@0 | 190 | void Redirect1Begin(const uint32_t& newChannelId, |
michael@0 | 191 | const URIParams& newUri, |
michael@0 | 192 | const uint32_t& redirectFlags, |
michael@0 | 193 | const nsHttpResponseHead& responseHead); |
michael@0 | 194 | void Redirect3Complete(); |
michael@0 | 195 | void DeleteSelf(); |
michael@0 | 196 | |
michael@0 | 197 | friend class AssociateApplicationCacheEvent; |
michael@0 | 198 | friend class StartRequestEvent; |
michael@0 | 199 | friend class StopRequestEvent; |
michael@0 | 200 | friend class TransportAndDataEvent; |
michael@0 | 201 | friend class ProgressEvent; |
michael@0 | 202 | friend class StatusEvent; |
michael@0 | 203 | friend class FailedAsyncOpenEvent; |
michael@0 | 204 | friend class Redirect1Event; |
michael@0 | 205 | friend class Redirect3Event; |
michael@0 | 206 | friend class DeleteSelfEvent; |
michael@0 | 207 | friend class HttpAsyncAborter<HttpChannelChild>; |
michael@0 | 208 | }; |
michael@0 | 209 | |
michael@0 | 210 | //----------------------------------------------------------------------------- |
michael@0 | 211 | // inline functions |
michael@0 | 212 | //----------------------------------------------------------------------------- |
michael@0 | 213 | |
michael@0 | 214 | inline bool |
michael@0 | 215 | HttpChannelChild::IsSuspended() |
michael@0 | 216 | { |
michael@0 | 217 | return mSuspendCount != 0; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | } // namespace net |
michael@0 | 221 | } // namespace mozilla |
michael@0 | 222 | |
michael@0 | 223 | #endif // mozilla_net_HttpChannelChild_h |