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