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 : /* ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is mozilla.org code.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * The Mozilla Foundation
21 : * Portions created by the Initial Developer are Copyright (C) 2009
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : * Jason Duell <jduell.mcbugs@gmail.com>
26 : * Daniel Witte <dwitte@mozilla.com>
27 : * Honza Bambas <honzab@firemni.cz>
28 : *
29 : * Alternatively, the contents of this file may be used under the terms of
30 : * either the GNU General Public License Version 2 or later (the "GPL"), or
31 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 : * in which case the provisions of the GPL or the LGPL are applicable instead
33 : * of those above. If you wish to allow use of your version of this file only
34 : * under the terms of either the GPL or the LGPL, and not to allow others to
35 : * use your version of this file under the terms of the MPL, indicate your
36 : * decision by deleting the provisions above and replace them with the notice
37 : * and other provisions required by the GPL or the LGPL. If you do not delete
38 : * the provisions above, a recipient may use your version of this file under
39 : * the terms of any one of the MPL, the GPL or the LGPL.
40 : *
41 : * ***** END LICENSE BLOCK ***** */
42 :
43 : #ifndef mozilla_net_HttpChannelChild_h
44 : #define mozilla_net_HttpChannelChild_h
45 :
46 : #include "mozilla/net/HttpBaseChannel.h"
47 : #include "mozilla/net/PHttpChannelChild.h"
48 : #include "mozilla/net/ChannelEventQueue.h"
49 :
50 : #include "nsIStreamListener.h"
51 : #include "nsILoadGroup.h"
52 : #include "nsIInterfaceRequestor.h"
53 : #include "nsIInterfaceRequestorUtils.h"
54 : #include "nsIProgressEventSink.h"
55 : #include "nsICacheInfoChannel.h"
56 : #include "nsIApplicationCache.h"
57 : #include "nsIApplicationCacheChannel.h"
58 : #include "nsIUploadChannel2.h"
59 : #include "nsIResumableChannel.h"
60 : #include "nsIProxiedChannel.h"
61 : #include "nsIAsyncVerifyRedirectCallback.h"
62 : #include "nsIAssociatedContentSecurity.h"
63 : #include "nsIChildChannel.h"
64 : #include "nsIHttpChannelChild.h"
65 :
66 : namespace mozilla {
67 : namespace net {
68 :
69 : class HttpChannelChild : public PHttpChannelChild
70 : , public HttpBaseChannel
71 : , public HttpAsyncAborter<HttpChannelChild>
72 : , public nsICacheInfoChannel
73 : , public nsIProxiedChannel
74 : , public nsIApplicationCacheChannel
75 : , public nsIAsyncVerifyRedirectCallback
76 : , public nsIAssociatedContentSecurity
77 : , public nsIChildChannel
78 : , public nsIHttpChannelChild
79 : {
80 : public:
81 : NS_DECL_ISUPPORTS_INHERITED
82 : NS_DECL_NSICACHEINFOCHANNEL
83 : NS_DECL_NSIPROXIEDCHANNEL
84 : NS_DECL_NSIAPPLICATIONCACHECONTAINER
85 : NS_DECL_NSIAPPLICATIONCACHECHANNEL
86 : NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
87 : NS_DECL_NSIASSOCIATEDCONTENTSECURITY
88 : NS_DECL_NSICHILDCHANNEL
89 : NS_DECL_NSIHTTPCHANNELCHILD
90 :
91 : HttpChannelChild();
92 : virtual ~HttpChannelChild();
93 :
94 : // Methods HttpBaseChannel didn't implement for us or that we override.
95 : //
96 : // nsIRequest
97 : NS_IMETHOD Cancel(nsresult status);
98 : NS_IMETHOD Suspend();
99 : NS_IMETHOD Resume();
100 : // nsIChannel
101 : NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo);
102 : NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext);
103 : // HttpBaseChannel::nsIHttpChannel
104 : NS_IMETHOD SetRequestHeader(const nsACString& aHeader,
105 : const nsACString& aValue,
106 : bool aMerge);
107 : // nsIHttpChannelInternal
108 : NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey);
109 : NS_IMETHOD GetLocalAddress(nsACString& addr);
110 : NS_IMETHOD GetLocalPort(PRInt32* port);
111 : NS_IMETHOD GetRemoteAddress(nsACString& addr);
112 : NS_IMETHOD GetRemotePort(PRInt32* port);
113 : // nsISupportsPriority
114 : NS_IMETHOD SetPriority(PRInt32 value);
115 : // nsIResumableChannel
116 : NS_IMETHOD ResumeAt(PRUint64 startPos, const nsACString& entityID);
117 :
118 : // IPDL holds a reference while the PHttpChannel protocol is live (starting at
119 : // AsyncOpen, and ending at either OnStopRequest or any IPDL error, either of
120 : // which call NeckoChild::DeallocPHttpChannel()).
121 : void AddIPDLReference();
122 : void ReleaseIPDLReference();
123 :
124 : bool IsSuspended();
125 :
126 : protected:
127 : bool RecvOnStartRequest(const nsHttpResponseHead& responseHead,
128 : const bool& useResponseHead,
129 : const nsHttpHeaderArray& requestHeaders,
130 : const bool& isFromCache,
131 : const bool& cacheEntryAvailable,
132 : const PRUint32& cacheExpirationTime,
133 : const nsCString& cachedCharset,
134 : const nsCString& securityInfoSerialization,
135 : const PRNetAddr& selfAddr,
136 : const PRNetAddr& peerAddr);
137 : bool RecvOnTransportAndData(const nsresult& status,
138 : const PRUint64& progress,
139 : const PRUint64& progressMax,
140 : const nsCString& data,
141 : const PRUint32& offset,
142 : const PRUint32& count);
143 : bool RecvOnStopRequest(const nsresult& statusCode);
144 : bool RecvOnProgress(const PRUint64& progress, const PRUint64& progressMax);
145 : bool RecvOnStatus(const nsresult& status);
146 : bool RecvFailedAsyncOpen(const nsresult& status);
147 : bool RecvRedirect1Begin(const PRUint32& newChannel,
148 : const URI& newURI,
149 : const PRUint32& redirectFlags,
150 : const nsHttpResponseHead& responseHead);
151 : bool RecvRedirect3Complete();
152 : bool RecvAssociateApplicationCache(const nsCString& groupID,
153 : const nsCString& clientID);
154 : bool RecvDeleteSelf();
155 :
156 : bool GetAssociatedContentSecurity(nsIAssociatedContentSecurity** res = nsnull);
157 : virtual void DoNotifyListenerCleanup();
158 :
159 : private:
160 : RequestHeaderTuples mClientSetRequestHeaders;
161 : nsCOMPtr<nsIChildChannel> mRedirectChannelChild;
162 : nsCOMPtr<nsISupports> mSecurityInfo;
163 :
164 : bool mIsFromCache;
165 : bool mCacheEntryAvailable;
166 : PRUint32 mCacheExpirationTime;
167 : nsCString mCachedCharset;
168 :
169 : // If ResumeAt is called before AsyncOpen, we need to send extra data upstream
170 : bool mSendResumeAt;
171 :
172 : bool mIPCOpen;
173 : bool mKeptAlive; // IPC kept open, but only for security info
174 : ChannelEventQueue mEventQ;
175 :
176 : // true after successful AsyncOpen until OnStopRequest completes.
177 0 : bool RemoteChannelExists() { return mIPCOpen && !mKeptAlive; }
178 :
179 : void AssociateApplicationCache(const nsCString &groupID,
180 : const nsCString &clientID);
181 : void OnStartRequest(const nsHttpResponseHead& responseHead,
182 : const bool& useResponseHead,
183 : const nsHttpHeaderArray& requestHeaders,
184 : const bool& isFromCache,
185 : const bool& cacheEntryAvailable,
186 : const PRUint32& cacheExpirationTime,
187 : const nsCString& cachedCharset,
188 : const nsCString& securityInfoSerialization,
189 : const PRNetAddr& selfAddr,
190 : const PRNetAddr& peerAddr);
191 : void OnTransportAndData(const nsresult& status,
192 : const PRUint64 progress,
193 : const PRUint64& progressMax,
194 : const nsCString& data,
195 : const PRUint32& offset,
196 : const PRUint32& count);
197 : void OnStopRequest(const nsresult& statusCode);
198 : void OnProgress(const PRUint64& progress, const PRUint64& progressMax);
199 : void OnStatus(const nsresult& status);
200 : void FailedAsyncOpen(const nsresult& status);
201 : void HandleAsyncAbort();
202 : void Redirect1Begin(const PRUint32& newChannelId,
203 : const URI& newUri,
204 : const PRUint32& redirectFlags,
205 : const nsHttpResponseHead& responseHead);
206 : void Redirect3Complete();
207 : void DeleteSelf();
208 :
209 : // Called asynchronously from Resume: continues any pending calls into client.
210 : void CompleteResume();
211 :
212 : friend class AssociateApplicationCacheEvent;
213 : friend class StartRequestEvent;
214 : friend class StopRequestEvent;
215 : friend class TransportAndDataEvent;
216 : friend class ProgressEvent;
217 : friend class StatusEvent;
218 : friend class FailedAsyncOpenEvent;
219 : friend class Redirect1Event;
220 : friend class Redirect3Event;
221 : friend class DeleteSelfEvent;
222 : friend class HttpAsyncAborter<HttpChannelChild>;
223 : };
224 :
225 : //-----------------------------------------------------------------------------
226 : // inline functions
227 : //-----------------------------------------------------------------------------
228 :
229 : inline bool
230 : HttpChannelChild::IsSuspended()
231 : {
232 : return mSuspendCount != 0;
233 : }
234 :
235 : } // namespace net
236 : } // namespace mozilla
237 :
238 : #endif // mozilla_net_HttpChannelChild_h
|