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 <libsoup/soup.h> 50 class Frame; 51 #endif 52 53 #if PLATFORM(QT) 54 class QWebFrame; 55 class QWebNetworkJob; 56 namespace WebCore { 57 class QNetworkReplyHandler; 58 } 59 #endif 60 61 #if PLATFORM(MAC) 62 #ifdef __OBJC__ 63 @class NSURLAuthenticationChallenge; 64 @class NSURLConnection; 65 #else 66 class NSURLAuthenticationChallenge; 67 class NSURLConnection; 68 #endif 69 #endif 70 71 #if PLATFORM(ANDROID) 72 namespace android { 73 class WebCoreResourceLoader; 74 } 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 : public Noncopyable { 85 public: ResourceHandleInternal(ResourceHandle * loader,const ResourceRequest & request,ResourceHandleClient * c,bool defersLoading,bool shouldContentSniff,bool mightDownloadFromHandle)86 ResourceHandleInternal(ResourceHandle* loader, const ResourceRequest& request, ResourceHandleClient* c, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle) 87 : m_client(c) 88 , m_request(request) 89 , status(0) 90 , m_defersLoading(defersLoading) 91 , m_shouldContentSniff(shouldContentSniff) 92 , m_mightDownloadFromHandle(mightDownloadFromHandle) 93 #if USE(CFNETWORK) 94 , m_connection(0) 95 #endif 96 #if USE(WININET) 97 , m_fileHandle(INVALID_HANDLE_VALUE) 98 , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer) 99 , m_resourceHandle(0) 100 , m_secondaryHandle(0) 101 , m_jobId(0) 102 , m_threadId(0) 103 , m_writing(false) 104 , m_formDataString(0) 105 , m_formDataLength(0) 106 , m_bytesRemainingToWrite(0) 107 , m_hasReceivedResponse(false) 108 , m_resend(false) 109 #endif 110 #if USE(CURL) 111 , m_handle(0) 112 , m_url(0) 113 , m_customHeaders(0) 114 , m_cancelled(false) 115 , m_formDataStream(loader) 116 #endif 117 #if USE(SOUP) 118 , m_msg(0) 119 , m_cancelled(false) 120 , m_gfile(0) 121 , m_inputStream(0) 122 , m_cancellable(0) 123 , m_buffer(0) 124 , m_bufferSize(0) 125 , m_total(0) 126 , m_idleHandler(0) 127 , m_frame(0) 128 #endif 129 #if PLATFORM(QT) 130 , m_job(0) 131 , m_frame(0) 132 #endif 133 #if PLATFORM(MAC) 134 , m_startWhenScheduled(false) 135 , m_needsSiteSpecificQuirks(false) 136 , m_currentMacChallenge(nil) 137 #elif USE(CFNETWORK) 138 , m_currentCFChallenge(0) 139 #endif 140 #if PLATFORM(ANDROID) 141 , m_loader(0) 142 #endif 143 , m_failureTimer(loader, &ResourceHandle::fireFailure) 144 { 145 const KURL& url = m_request.url(); 146 m_user = url.user(); 147 m_pass = url.pass(); 148 m_request.removeCredentials(); 149 } 150 151 ~ResourceHandleInternal(); 152 client()153 ResourceHandleClient* client() { return m_client; } 154 ResourceHandleClient* m_client; 155 156 ResourceRequest m_request; 157 158 // Suggested credentials for the current redirection step. 159 String m_user; 160 String m_pass; 161 162 int status; 163 164 bool m_defersLoading; 165 bool m_shouldContentSniff; 166 bool m_mightDownloadFromHandle; 167 #if USE(CFNETWORK) 168 RetainPtr<CFURLConnectionRef> m_connection; 169 #elif PLATFORM(MAC) 170 RetainPtr<NSURLConnection> m_connection; 171 RetainPtr<WebCoreResourceHandleAsDelegate> m_delegate; 172 RetainPtr<id> m_proxy; 173 bool m_startWhenScheduled; 174 bool m_needsSiteSpecificQuirks; 175 #endif 176 #if USE(WININET) 177 HANDLE m_fileHandle; 178 Timer<ResourceHandle> m_fileLoadTimer; 179 HINTERNET m_resourceHandle; 180 HINTERNET m_secondaryHandle; 181 unsigned m_jobId; 182 DWORD m_threadId; 183 bool m_writing; 184 char* m_formDataString; 185 int m_formDataLength; 186 int m_bytesRemainingToWrite; 187 String m_postReferrer; 188 bool m_hasReceivedResponse; 189 bool m_resend; 190 #endif 191 #if USE(CURL) 192 CURL* m_handle; 193 char* m_url; 194 struct curl_slist* m_customHeaders; 195 ResourceResponse m_response; 196 bool m_cancelled; 197 198 FormDataStream m_formDataStream; 199 Vector<char> m_postBytes; 200 #endif 201 #if USE(SOUP) 202 SoupMessage* m_msg; 203 ResourceResponse m_response; 204 bool m_cancelled; 205 GFile* m_gfile; 206 GInputStream* m_inputStream; 207 GCancellable* m_cancellable; 208 char* m_buffer; 209 gsize m_bufferSize, m_total; 210 guint m_idleHandler; 211 Frame* m_frame; 212 #endif 213 #if PLATFORM(QT) 214 #if QT_VERSION < 0x040400 215 QWebNetworkJob* m_job; 216 #else 217 QNetworkReplyHandler* m_job; 218 #endif 219 QWebFrame* m_frame; 220 #endif 221 222 // FIXME: The platform challenge is almost identical to the one stored in m_currentWebChallenge, but it has a different sender. We only need to store a sender reference here. 223 #if PLATFORM(MAC) 224 NSURLAuthenticationChallenge *m_currentMacChallenge; 225 #endif 226 #if USE(CFNETWORK) 227 CFURLAuthChallengeRef m_currentCFChallenge; 228 #endif 229 #if PLATFORM(ANDROID) 230 android::WebCoreResourceLoader* m_loader; 231 #endif 232 AuthenticationChallenge m_currentWebChallenge; 233 234 ResourceHandle::FailureType m_failureType; 235 Timer<ResourceHandle> m_failureTimer; 236 }; 237 238 } // namespace WebCore 239 240 #endif // ResourceHandleInternal_h 241