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 ResourceHandle_h 27 #define ResourceHandle_h 28 29 #include "AuthenticationChallenge.h" 30 #include "HTTPHeaderMap.h" 31 #include "ThreadableLoader.h" 32 #include <wtf/OwnPtr.h> 33 34 #if USE(SOUP) 35 typedef struct _SoupSession SoupSession; 36 #endif 37 38 #if PLATFORM(CF) 39 typedef const struct __CFData * CFDataRef; 40 #endif 41 42 #if PLATFORM(WIN) 43 typedef unsigned long DWORD; 44 typedef unsigned long DWORD_PTR; 45 typedef void* LPVOID; 46 typedef LPVOID HINTERNET; 47 typedef unsigned WPARAM; 48 typedef long LPARAM; 49 typedef struct HWND__* HWND; 50 typedef _W64 long LONG_PTR; 51 typedef LONG_PTR LRESULT; 52 #endif 53 54 55 #if PLATFORM(MAC) 56 #include <wtf/RetainPtr.h> 57 #ifdef __OBJC__ 58 @class NSData; 59 @class NSError; 60 @class NSURLConnection; 61 @class WebCoreResourceHandleAsDelegate; 62 #else 63 class NSData; 64 class NSError; 65 class NSURLConnection; 66 class WebCoreResourceHandleAsDelegate; 67 typedef struct objc_object *id; 68 #endif 69 #endif 70 71 #if USE(CFNETWORK) 72 typedef struct _CFURLConnection* CFURLConnectionRef; 73 typedef int CFHTTPCookieStorageAcceptPolicy; 74 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef; 75 #endif 76 77 namespace WebCore { 78 79 class AuthenticationChallenge; 80 class Credential; 81 class FormData; 82 class Frame; 83 class KURL; 84 class ResourceError; 85 class ResourceHandleClient; 86 class ResourceHandleInternal; 87 struct ResourceRequest; 88 class ResourceResponse; 89 class SchedulePair; 90 class SharedBuffer; 91 92 template <typename T> class Timer; 93 94 class ResourceHandle : public RefCounted<ResourceHandle> { 95 private: 96 ResourceHandle(const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle); 97 98 enum FailureType { 99 BlockedFailure, 100 InvalidURLFailure 101 }; 102 103 public: 104 // FIXME: should not need the Frame 105 static PassRefPtr<ResourceHandle> create(const ResourceRequest&, ResourceHandleClient*, Frame*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle = false); 106 107 static void loadResourceSynchronously(const ResourceRequest&, StoredCredentials, ResourceError&, ResourceResponse&, Vector<char>& data, Frame* frame); 108 static bool willLoadFromCache(ResourceRequest&, Frame*); 109 #if PLATFORM(MAC) 110 static bool didSendBodyDataDelegateExists(); 111 #endif 112 113 ~ResourceHandle(); 114 115 #if PLATFORM(MAC) || USE(CFNETWORK) 116 void willSendRequest(ResourceRequest&, const ResourceResponse& redirectResponse); 117 bool shouldUseCredentialStorage(); 118 #endif 119 #if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL) 120 void didReceiveAuthenticationChallenge(const AuthenticationChallenge&); 121 void receivedCredential(const AuthenticationChallenge&, const Credential&); 122 void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&); 123 void receivedCancellation(const AuthenticationChallenge&); 124 #endif 125 126 #if PLATFORM(MAC) 127 void didCancelAuthenticationChallenge(const AuthenticationChallenge&); 128 NSURLConnection *connection() const; 129 WebCoreResourceHandleAsDelegate *delegate(); 130 void releaseDelegate(); 131 id releaseProxy(); 132 133 void schedule(SchedulePair*); 134 void unschedule(SchedulePair*); 135 #elif USE(CFNETWORK) 136 static CFRunLoopRef loaderRunLoop(); 137 CFURLConnectionRef connection() const; 138 CFURLConnectionRef releaseConnectionForDownload(); 139 static void setHostAllowsAnyHTTPSCertificate(const String&); 140 static void setClientCertificate(const String& host, CFDataRef); 141 #endif 142 143 #if PLATFORM(WIN) && USE(CURL) 144 static void setHostAllowsAnyHTTPSCertificate(const String&); 145 #endif 146 #if PLATFORM(WIN) && USE(CURL) && PLATFORM(CF) 147 static void setClientCertificate(const String& host, CFDataRef); 148 #endif 149 150 PassRefPtr<SharedBuffer> bufferedData(); 151 static bool supportsBufferedData(); 152 153 bool shouldContentSniff() const; 154 static bool shouldContentSniffURL(const KURL&); 155 156 static void forceContentSniffing(); 157 158 #if USE(WININET) 159 void setHasReceivedResponse(bool = true); 160 bool hasReceivedResponse() const; 161 void fileLoadTimer(Timer<ResourceHandle>*); 162 void onHandleCreated(LPARAM); 163 void onRequestRedirected(LPARAM); 164 void onRequestComplete(LPARAM); 165 friend void __stdcall transferJobStatusCallback(HINTERNET, DWORD_PTR, DWORD, LPVOID, DWORD); 166 friend LRESULT __stdcall ResourceHandleWndProc(HWND, unsigned message, WPARAM, LPARAM); 167 #endif 168 169 #if PLATFORM(QT) || USE(CURL) || USE(SOUP) || defined(ANDROID) getInternal()170 ResourceHandleInternal* getInternal() { return d.get(); } 171 #endif 172 173 #if USE(SOUP) 174 static SoupSession* defaultSession(); 175 #endif 176 177 // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the one you're in. 178 static bool loadsBlocked(); 179 180 void clearAuthentication(); 181 void cancel(); 182 183 // The client may be 0, in which case no callbacks will be made. 184 ResourceHandleClient* client() const; 185 void setClient(ResourceHandleClient*); 186 187 void setDefersLoading(bool); 188 189 const ResourceRequest& request() const; 190 191 void fireFailure(Timer<ResourceHandle>*); 192 193 private: 194 void scheduleFailure(FailureType); 195 196 bool start(Frame*); 197 198 friend class ResourceHandleInternal; 199 OwnPtr<ResourceHandleInternal> d; 200 }; 201 202 } 203 204 #endif // ResourceHandle_h 205