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 #if PLATFORM(ANDROID) 74 #include "ResourceLoaderAndroid.h" 75 #endif 76 77 // The allocations and releases in ResourceHandleInternal are 78 // Cocoa-exception-free (either simple Foundation classes or 79 // WebCoreResourceLoaderImp which avoids doing work in dealloc). 80 81 namespace WebCore { 82 class ResourceHandleClient; 83 84 class ResourceHandleInternal { 85 WTF_MAKE_NONCOPYABLE(ResourceHandleInternal); WTF_MAKE_FAST_ALLOCATED; 86 public: 87 ResourceHandleInternal(ResourceHandle* loader, const ResourceRequest& request, ResourceHandleClient* c, bool defersLoading, bool shouldContentSniff) 88 : m_client(c) 89 , m_firstRequest(request) 90 , m_lastHTTPMethod(request.httpMethod()) 91 , status(0) 92 , m_defersLoading(defersLoading) 93 , m_shouldContentSniff(shouldContentSniff) 94 #if USE(CFNETWORK) 95 , m_connection(0) 96 #endif 97 #if USE(WININET) 98 , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer) 99 , m_internetHandle(0) 100 , m_connectHandle(0) 101 , m_requestHandle(0) 102 , m_sentEndRequest(false) 103 , m_bytesRemainingToWrite(0) 104 , m_loadSynchronously(false) 105 , m_hasReceivedResponse(false) 106 #endif 107 #if USE(CURL) 108 , m_handle(0) 109 , m_url(0) 110 , m_customHeaders(0) 111 , m_cancelled(false) 112 , m_formDataStream(loader) 113 #endif 114 #if USE(SOUP) 115 , m_cancelled(false) 116 , m_buffer(0) 117 , m_bodySize(0) 118 , m_bodyDataSent(0) 119 , m_gotChunkHandler(0) 120 #endif 121 #if PLATFORM(QT) 122 , m_job(0) 123 #endif 124 #if PLATFORM(MAC) 125 , m_startWhenScheduled(false) 126 , m_needsSiteSpecificQuirks(false) 127 , m_currentMacChallenge(nil) 128 #endif 129 , m_scheduledFailureType(ResourceHandle::NoFailure) 130 , m_failureTimer(loader, &ResourceHandle::fireFailure) 131 { 132 const KURL& url = m_firstRequest.url(); 133 m_user = url.user(); 134 m_pass = url.pass(); 135 m_firstRequest.removeCredentials(); 136 } 137 138 ~ResourceHandleInternal(); 139 140 ResourceHandleClient* client() { return m_client; } 141 ResourceHandleClient* m_client; 142 143 ResourceRequest m_firstRequest; 144 String m_lastHTTPMethod; 145 146 // Suggested credentials for the current redirection step. 147 String m_user; 148 String m_pass; 149 150 Credential m_initialCredential; 151 152 int status; 153 154 bool m_defersLoading; 155 bool m_shouldContentSniff; 156 #if USE(CFNETWORK) 157 RetainPtr<CFURLConnectionRef> m_connection; 158 #elif PLATFORM(MAC) 159 RetainPtr<NSURLConnection> m_connection; 160 RetainPtr<WebCoreResourceHandleAsDelegate> m_delegate; 161 RetainPtr<id> m_proxy; 162 bool m_startWhenScheduled; 163 bool m_needsSiteSpecificQuirks; 164 #endif 165 #if USE(WININET) 166 Timer<ResourceHandle> m_fileLoadTimer; 167 HINTERNET m_internetHandle; 168 HINTERNET m_connectHandle; 169 HINTERNET m_requestHandle; 170 bool m_sentEndRequest; 171 Vector<char> m_formData; 172 size_t m_bytesRemainingToWrite; 173 bool m_loadSynchronously; 174 bool m_hasReceivedResponse; 175 String m_redirectUrl; 176 #endif 177 #if USE(CURL) 178 CURL* m_handle; 179 char* m_url; 180 struct curl_slist* m_customHeaders; 181 ResourceResponse m_response; 182 bool m_cancelled; 183 184 FormDataStream m_formDataStream; 185 Vector<char> m_postBytes; 186 #endif 187 #if USE(SOUP) 188 GRefPtr<SoupMessage> m_soupMessage; 189 ResourceResponse m_response; 190 bool m_cancelled; 191 GRefPtr<SoupRequest> m_soupRequest; 192 GRefPtr<GInputStream> m_inputStream; 193 GRefPtr<GCancellable> m_cancellable; 194 char* m_buffer; 195 unsigned long m_bodySize; 196 unsigned long m_bodyDataSent; 197 RefPtr<NetworkingContext> m_context; 198 gulong m_gotChunkHandler; 199 #endif 200 #if PLATFORM(QT) 201 QNetworkReplyHandler* m_job; 202 RefPtr<NetworkingContext> m_context; 203 #endif 204 205 #if PLATFORM(MAC) 206 // We need to keep a reference to the original challenge to be able to cancel it. 207 // It is almost identical to m_currentWebChallenge.nsURLAuthenticationChallenge(), but has a different sender. 208 NSURLAuthenticationChallenge *m_currentMacChallenge; 209 #endif 210 #if PLATFORM(ANDROID) 211 RefPtr<ResourceLoaderAndroid> m_loader; 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 222