[Soup] utilize multipart/x-mixed-replace support recently added to libsoup
[WebKit-https.git] / 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 #define LIBSOUP_USE_UNSTABLE_REQUEST_API
50 #include <libsoup/soup-multipart-input-stream.h>
51 #include <libsoup/soup-request.h>
52 #include <libsoup/soup.h>
53 #include <wtf/gobject/GRefPtr.h>
54 class Frame;
55 #endif
56
57 #if PLATFORM(QT)
58 QT_BEGIN_NAMESPACE
59 class QWebNetworkJob;
60 QT_END_NAMESPACE
61 namespace WebCore {
62 class QNetworkReplyHandler;
63 }
64 #endif
65
66 #if PLATFORM(MAC)
67 OBJC_CLASS NSURLAuthenticationChallenge;
68 OBJC_CLASS NSURLConnection;
69 #endif
70
71 #if PLATFORM(MAC) || USE(CFNETWORK)
72 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
73 #endif
74
75 // The allocations and releases in ResourceHandleInternal are
76 // Cocoa-exception-free (either simple Foundation classes or
77 // WebCoreResourceLoaderImp which avoids doing work in dealloc).
78
79 namespace WebCore {
80     class ResourceHandleClient;
81
82     class ResourceHandleInternal {
83         WTF_MAKE_NONCOPYABLE(ResourceHandleInternal); WTF_MAKE_FAST_ALLOCATED;
84     public:
85         ResourceHandleInternal(ResourceHandle* loader, const ResourceRequest& request, ResourceHandleClient* c, bool defersLoading, bool shouldContentSniff)
86             : m_client(c)
87             , m_firstRequest(request)
88             , m_lastHTTPMethod(request.httpMethod())
89             , status(0)
90             , m_defersLoading(defersLoading)
91             , m_shouldContentSniff(shouldContentSniff)
92 #if USE(CFNETWORK)
93             , m_connection(0)
94 #endif
95 #if USE(WININET)
96             , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer)
97             , m_internetHandle(0)
98             , m_connectHandle(0)
99             , m_requestHandle(0)
100             , m_sentEndRequest(false)
101             , m_bytesRemainingToWrite(0)
102             , m_loadSynchronously(false)
103             , m_hasReceivedResponse(false)
104 #endif
105 #if USE(CURL)
106             , m_handle(0)
107             , m_url(0)
108             , m_customHeaders(0)
109             , m_cancelled(false)
110             , m_formDataStream(loader)
111 #endif
112 #if USE(SOUP)
113             , m_cancelled(false)
114             , m_buffer(0)
115             , m_bodySize(0)
116             , m_bodyDataSent(0)
117 #endif
118 #if PLATFORM(QT)
119             , m_job(0)
120 #endif
121 #if PLATFORM(MAC)
122             , m_startWhenScheduled(false)
123             , m_needsSiteSpecificQuirks(false)
124             , m_currentMacChallenge(nil)
125 #endif
126             , m_scheduledFailureType(ResourceHandle::NoFailure)
127             , m_failureTimer(loader, &ResourceHandle::fireFailure)
128         {
129             const KURL& url = m_firstRequest.url();
130             m_user = url.user();
131             m_pass = url.pass();
132             m_firstRequest.removeCredentials();
133         }
134         
135         ~ResourceHandleInternal();
136
137         ResourceHandleClient* client() { return m_client; }
138         ResourceHandleClient* m_client;
139         
140         ResourceRequest m_firstRequest;
141         String m_lastHTTPMethod;
142
143         // Suggested credentials for the current redirection step.
144         String m_user;
145         String m_pass;
146         
147         Credential m_initialCredential;
148         
149         int status;
150
151         bool m_defersLoading;
152         bool m_shouldContentSniff;
153 #if USE(CFNETWORK)
154         RetainPtr<CFURLConnectionRef> m_connection;
155 #endif
156 #if PLATFORM(MAC) && !USE(CFNETWORK)
157         RetainPtr<NSURLConnection> m_connection;
158         RetainPtr<WebCoreResourceHandleAsDelegate> m_delegate;
159         RetainPtr<id> m_proxy;
160 #endif
161 #if PLATFORM(MAC)
162         bool m_startWhenScheduled;
163         bool m_needsSiteSpecificQuirks;
164 #endif
165 #if PLATFORM(MAC) || USE(CFNETWORK)
166         RetainPtr<CFURLStorageSessionRef> m_storageSession;
167 #endif
168 #if USE(WININET)
169         Timer<ResourceHandle> m_fileLoadTimer;
170         HINTERNET m_internetHandle;
171         HINTERNET m_connectHandle;
172         HINTERNET m_requestHandle;
173         bool m_sentEndRequest;
174         Vector<char> m_formData;
175         size_t m_bytesRemainingToWrite;
176         bool m_loadSynchronously;
177         bool m_hasReceivedResponse;
178         String m_redirectUrl;
179 #endif
180 #if USE(CURL)
181         CURL* m_handle;
182         char* m_url;
183         struct curl_slist* m_customHeaders;
184         ResourceResponse m_response;
185         bool m_cancelled;
186
187         FormDataStream m_formDataStream;
188         Vector<char> m_postBytes;
189 #endif
190 #if USE(SOUP)
191         GRefPtr<SoupMessage> m_soupMessage;
192         ResourceResponse m_response;
193         bool m_cancelled;
194         GRefPtr<SoupRequest> m_soupRequest;
195         GRefPtr<GInputStream> m_inputStream;
196         GRefPtr<SoupMultipartInputStream> m_multipartInputStream;
197         GRefPtr<GCancellable> m_cancellable;
198         GRefPtr<GAsyncResult> m_deferredResult;
199         GRefPtr<GSource> m_timeoutSource;
200         char* m_buffer;
201         unsigned long m_bodySize;
202         unsigned long m_bodyDataSent;
203         RefPtr<NetworkingContext> m_context;
204         SoupSession* soupSession();
205 #endif
206 #if PLATFORM(GTK)
207         struct {
208             Credential credential;
209             AuthenticationChallenge challenge;
210         } m_credentialDataToSaveInPersistentStore;
211 #endif
212 #if PLATFORM(QT)
213         QNetworkReplyHandler* m_job;
214         RefPtr<NetworkingContext> m_context;
215 #endif
216
217 #if PLATFORM(MAC)
218         // We need to keep a reference to the original challenge to be able to cancel it.
219         // It is almost identical to m_currentWebChallenge.nsURLAuthenticationChallenge(), but has a different sender.
220         NSURLAuthenticationChallenge *m_currentMacChallenge;
221 #endif
222         AuthenticationChallenge m_currentWebChallenge;
223
224         ResourceHandle::FailureType m_scheduledFailureType;
225         Timer<ResourceHandle> m_failureTimer;
226     };
227
228 } // namespace WebCore
229
230 #endif // ResourceHandleInternal_h