initial import
[vuplus_webkit] / Source / WebCore / platform / network / ResourceHandleInternal.h
1 /*
2  * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef ResourceHandleInternal_h
27 #define ResourceHandleInternal_h
28
29 #include "ResourceHandle.h"
30 #include "ResourceRequest.h"
31 #include "AuthenticationChallenge.h"
32 #include "Timer.h"
33
34 #if USE(CFNETWORK)
35 #include <CFNetwork/CFURLConnectionPriv.h>
36 #endif
37
38 #if USE(WININET) || (USE(CURL) && PLATFORM(WIN))
39 #include <winsock2.h>
40 #include <windows.h>
41 #endif
42
43 #if USE(CURL)
44 #include <curl/curl.h>
45 #include "FormDataStreamCurl.h"
46 #endif
47
48 #if USE(SOUP)
49 #include <GRefPtr.h>
50 #define LIBSOUP_USE_UNSTABLE_REQUEST_API
51 #include <libsoup/soup-request.h>
52 #include <libsoup/soup.h>
53 class Frame;
54 #endif
55
56 #if PLATFORM(QT)
57 class QWebNetworkJob;
58 namespace WebCore {
59 class QNetworkReplyHandler;
60 }
61 #endif
62
63 #if PLATFORM(MAC)
64 #ifdef __OBJC__
65 @class NSURLAuthenticationChallenge;
66 @class NSURLConnection;
67 #else
68 class NSURLAuthenticationChallenge;
69 class NSURLConnection;
70 #endif
71 #endif
72
73 // The allocations and releases in ResourceHandleInternal are
74 // Cocoa-exception-free (either simple Foundation classes or
75 // WebCoreResourceLoaderImp which avoids doing work in dealloc).
76
77 namespace WebCore {
78     class ResourceHandleClient;
79
80     class ResourceHandleInternal {
81         WTF_MAKE_NONCOPYABLE(ResourceHandleInternal); WTF_MAKE_FAST_ALLOCATED;
82     public:
83         ResourceHandleInternal(ResourceHandle* loader, const ResourceRequest& request, ResourceHandleClient* c, bool defersLoading, bool shouldContentSniff)
84             : m_client(c)
85             , m_firstRequest(request)
86             , m_lastHTTPMethod(request.httpMethod())
87             , status(0)
88             , m_defersLoading(defersLoading)
89             , m_shouldContentSniff(shouldContentSniff)
90 #if USE(CFNETWORK)
91             , m_connection(0)
92 #endif
93 #if USE(WININET)
94             , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer)
95             , m_internetHandle(0)
96             , m_connectHandle(0)
97             , m_requestHandle(0)
98             , m_sentEndRequest(false)
99             , m_bytesRemainingToWrite(0)
100             , m_loadSynchronously(false)
101             , m_hasReceivedResponse(false)
102 #endif
103 #if USE(CURL)
104             , m_handle(0)
105             , m_url(0)
106             , m_customHeaders(0)
107             , m_cancelled(false)
108             , m_formDataStream(loader)
109 #endif
110 #if USE(SOUP)
111             , m_cancelled(false)
112             , m_finished(false)
113             , m_finishedHandler(0)
114             , m_buffer(0)
115             , m_bodySize(0)
116             , m_bodyDataSent(0)
117             , m_gotChunkHandler(0)
118 #endif
119 #if PLATFORM(QT)
120             , m_job(0)
121 #endif
122 #if PLATFORM(MAC)
123             , m_startWhenScheduled(false)
124             , m_needsSiteSpecificQuirks(false)
125             , m_currentMacChallenge(nil)
126 #endif
127             , m_scheduledFailureType(ResourceHandle::NoFailure)
128             , m_failureTimer(loader, &ResourceHandle::fireFailure)
129         {
130             const KURL& url = m_firstRequest.url();
131             m_user = url.user();
132             m_pass = url.pass();
133             m_firstRequest.removeCredentials();
134         }
135         
136         ~ResourceHandleInternal();
137
138         ResourceHandleClient* client() { return m_client; }
139         ResourceHandleClient* m_client;
140         
141         ResourceRequest m_firstRequest;
142         String m_lastHTTPMethod;
143
144         // Suggested credentials for the current redirection step.
145         String m_user;
146         String m_pass;
147         
148         Credential m_initialCredential;
149         
150         int status;
151
152         bool m_defersLoading;
153         bool m_shouldContentSniff;
154 #if USE(CFNETWORK)
155         RetainPtr<CFURLConnectionRef> m_connection;
156 #endif
157 #if PLATFORM(MAC) && !USE(CFNETWORK)
158         RetainPtr<NSURLConnection> m_connection;
159         RetainPtr<WebCoreResourceHandleAsDelegate> m_delegate;
160         RetainPtr<id> m_proxy;
161 #endif
162 #if PLATFORM(MAC)
163         bool m_startWhenScheduled;
164         bool m_needsSiteSpecificQuirks;
165 #endif
166 #if USE(WININET)
167         Timer<ResourceHandle> m_fileLoadTimer;
168         HINTERNET m_internetHandle;
169         HINTERNET m_connectHandle;
170         HINTERNET m_requestHandle;
171         bool m_sentEndRequest;
172         Vector<char> m_formData;
173         size_t m_bytesRemainingToWrite;
174         bool m_loadSynchronously;
175         bool m_hasReceivedResponse;
176         String m_redirectUrl;
177 #endif
178 #if USE(CURL)
179         CURL* m_handle;
180         char* m_url;
181         struct curl_slist* m_customHeaders;
182         ResourceResponse m_response;
183         bool m_cancelled;
184
185         FormDataStream m_formDataStream;
186         Vector<char> m_postBytes;
187 #endif
188 #if USE(SOUP)
189         GRefPtr<SoupMessage> m_soupMessage;
190         ResourceResponse m_response;
191         bool m_cancelled;
192         bool m_finished;
193         gulong m_finishedHandler;
194         GRefPtr<SoupRequest> m_soupRequest;
195         GRefPtr<GInputStream> m_inputStream;
196         GRefPtr<GCancellable> m_cancellable;
197         char* m_buffer;
198         unsigned long m_bodySize;
199         unsigned long m_bodyDataSent;
200         RefPtr<NetworkingContext> m_context;
201         gulong m_gotChunkHandler;
202 #endif
203 #if PLATFORM(QT)
204         QNetworkReplyHandler* m_job;
205         RefPtr<NetworkingContext> m_context;
206 #endif
207
208 #if PLATFORM(MAC)
209         // We need to keep a reference to the original challenge to be able to cancel it.
210         // It is almost identical to m_currentWebChallenge.nsURLAuthenticationChallenge(), but has a different sender.
211         NSURLAuthenticationChallenge *m_currentMacChallenge;
212 #endif
213         AuthenticationChallenge m_currentWebChallenge;
214
215         ResourceHandle::FailureType m_scheduledFailureType;
216         Timer<ResourceHandle> m_failureTimer;
217     };
218
219 } // namespace WebCore
220
221 #endif // ResourceHandleInternal_h