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