1/* 2 * Copyright (C) 2004, 2006 Apple 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 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 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#endif 56 57#if PLATFORM(COCOA) 58OBJC_CLASS NSURLAuthenticationChallenge; 59OBJC_CLASS NSURLConnection; 60#endif 61 62#if PLATFORM(COCOA) || USE(CFNETWORK) 63typedef const struct __CFURLStorageSession* CFURLStorageSessionRef; 64#endif 65 66// The allocations and releases in ResourceHandleInternal are 67// Cocoa-exception-free (either simple Foundation classes or 68// WebCoreResourceLoaderImp which avoids doing work in dealloc). 69 70namespace WebCore { 71 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_currentRequest(request) 87#endif 88#if USE(WININET) 89 , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer) 90 , m_internetHandle(0) 91 , m_connectHandle(0) 92 , m_requestHandle(0) 93 , m_sentEndRequest(false) 94 , m_bytesRemainingToWrite(0) 95 , m_loadSynchronously(false) 96 , m_hasReceivedResponse(false) 97#endif 98#if USE(CURL) 99 , m_handle(0) 100 , m_url(0) 101 , m_customHeaders(0) 102 , m_cancelled(false) 103 , m_authFailureCount(0) 104 , m_formDataStream(loader) 105 , m_sslErrors(0) 106#endif 107#if USE(SOUP) 108 , m_cancelled(false) 109 , m_bodySize(0) 110 , m_bodyDataSent(0) 111 , m_redirectCount(0) 112 , m_previousPosition(0) 113 , m_useAuthenticationManager(true) 114#endif 115#if PLATFORM(COCOA) 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(COCOA) && !USE(CFNETWORK) 154 RetainPtr<NSURLConnection> m_connection; 155 RetainPtr<id> m_delegate; 156#endif 157#if PLATFORM(COCOA) 158 bool m_startWhenScheduled; 159 bool m_needsSiteSpecificQuirks; 160#endif 161#if PLATFORM(COCOA) || 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 bool m_useAuthenticationManager; 207#endif 208#if PLATFORM(GTK) 209 struct { 210 Credential credential; 211 AuthenticationChallenge challenge; 212 } m_credentialDataToSaveInPersistentStore; 213#endif 214 215#if PLATFORM(COCOA) 216 // We need to keep a reference to the original challenge to be able to cancel it. 217 // It is almost identical to m_currentWebChallenge.nsURLAuthenticationChallenge(), but has a different sender. 218 NSURLAuthenticationChallenge *m_currentMacChallenge; 219#endif 220 221 AuthenticationChallenge m_currentWebChallenge; 222 ResourceHandle::FailureType m_scheduledFailureType; 223 Timer<ResourceHandle> m_failureTimer; 224 }; 225 226} // namespace WebCore 227 228#endif // ResourceHandleInternal_h 229