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#include <libsoup/soup.h> 51#include <wtf/gobject/GOwnPtr.h> 52#include <wtf/gobject/GRefPtr.h> 53class Frame; 54#endif 55 56#if PLATFORM(QT) 57QT_BEGIN_NAMESPACE 58class QWebNetworkJob; 59QT_END_NAMESPACE 60namespace WebCore { 61class QNetworkReplyHandler; 62} 63#endif 64 65#if PLATFORM(MAC) 66OBJC_CLASS NSURLAuthenticationChallenge; 67OBJC_CLASS NSURLConnection; 68#endif 69 70#if PLATFORM(MAC) || USE(CFNETWORK) 71typedef const struct __CFURLStorageSession* CFURLStorageSessionRef; 72#endif 73 74// The allocations and releases in ResourceHandleInternal are 75// Cocoa-exception-free (either simple Foundation classes or 76// WebCoreResourceLoaderImp which avoids doing work in dealloc). 77 78namespace WebCore { 79 class ResourceHandleClient; 80 81 class ResourceHandleInternal { 82 WTF_MAKE_NONCOPYABLE(ResourceHandleInternal); WTF_MAKE_FAST_ALLOCATED; 83 public: 84 ResourceHandleInternal(ResourceHandle* loader, NetworkingContext* context, const ResourceRequest& request, ResourceHandleClient* client, bool defersLoading, bool shouldContentSniff) 85 : m_context(context) 86 , m_client(client) 87 , m_firstRequest(request) 88 , m_lastHTTPMethod(request.httpMethod()) 89 , status(0) 90 , m_defersLoading(defersLoading) 91 , m_shouldContentSniff(shouldContentSniff) 92#if USE(CFNETWORK) 93 , m_connection(0) 94#endif 95#if USE(WININET) 96 , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer) 97 , m_internetHandle(0) 98 , m_connectHandle(0) 99 , m_requestHandle(0) 100 , m_sentEndRequest(false) 101 , m_bytesRemainingToWrite(0) 102 , m_loadSynchronously(false) 103 , m_hasReceivedResponse(false) 104#endif 105#if USE(CURL) 106 , m_handle(0) 107 , m_url(0) 108 , m_customHeaders(0) 109 , m_cancelled(false) 110 , m_formDataStream(loader) 111#endif 112#if USE(SOUP) 113 , m_cancelled(false) 114 , m_readBufferPtr(0) 115 , m_readBufferSize(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 141 RefPtr<NetworkingContext> m_context; 142 ResourceHandleClient* m_client; 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#endif 159#if PLATFORM(MAC) && !USE(CFNETWORK) 160 RetainPtr<NSURLConnection> m_connection; 161 RetainPtr<id> m_delegate; 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 GOwnPtr<char> m_defaultReadBuffer; 203 char* m_readBufferPtr; 204 size_t m_readBufferSize; 205 unsigned long m_bodySize; 206 unsigned long m_bodyDataSent; 207 SoupSession* soupSession(); 208 int m_redirectCount; 209#endif 210#if PLATFORM(GTK) 211 struct { 212 Credential credential; 213 AuthenticationChallenge challenge; 214 } m_credentialDataToSaveInPersistentStore; 215#endif 216#if PLATFORM(QT) 217 QNetworkReplyHandler* m_job; 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#if PLATFORM(BLACKBERRY) 227 // We need to store the credentials for host and proxy separately for the platform 228 // networking layer. One of these will always be equal to m_currentWebChallenge. 229 AuthenticationChallenge m_hostWebChallenge; 230 AuthenticationChallenge m_proxyWebChallenge; 231#endif 232 233 ResourceHandle::FailureType m_scheduledFailureType; 234 Timer<ResourceHandle> m_failureTimer; 235 }; 236 237} // namespace WebCore 238 239#endif // ResourceHandleInternal_h 240