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