2 * Copyright (C) 2004, 2006, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef ResourceHandle_h
27 #define ResourceHandle_h
29 #include "AuthenticationClient.h"
30 #include "HTTPHeaderMap.h"
31 #include "ResourceHandleTypes.h"
32 #include "ResourceLoadPriority.h"
33 #include <wtf/OwnPtr.h>
34 #include <wtf/RefCounted.h>
37 typedef struct _GTlsCertificate GTlsCertificate;
38 typedef struct _SoupSession SoupSession;
39 typedef struct _SoupRequest SoupRequest;
43 typedef const struct __CFData * CFDataRef;
47 typedef unsigned long DWORD;
48 typedef unsigned long DWORD_PTR;
50 typedef LPVOID HINTERNET;
53 #if PLATFORM(MAC) || USE(CFNETWORK)
54 #include <wtf/RetainPtr.h>
60 OBJC_CLASS NSURLConnection;
61 OBJC_CLASS WebCoreResourceHandleAsDelegate;
63 typedef struct objc_object *id;
68 typedef struct _CFURLConnection* CFURLConnectionRef;
69 typedef int CFHTTPCookieStorageAcceptPolicy;
70 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
73 #if PLATFORM(MAC) || USE(CFNETWORK)
74 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
82 class AuthenticationChallenge;
86 class NetworkingContext;
87 class ProtectionSpace;
89 class ResourceHandleClient;
90 class ResourceHandleInternal;
91 class ResourceRequest;
92 class ResourceResponse;
95 template <typename T> class Timer;
97 class ResourceHandle : public RefCounted<ResourceHandle>
98 #if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL) || USE(SOUP)
99 , public AuthenticationClient
103 static PassRefPtr<ResourceHandle> create(NetworkingContext*, const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff);
104 static void loadResourceSynchronously(NetworkingContext*, const ResourceRequest&, StoredCredentials, ResourceError&, ResourceResponse&, Vector<char>& data);
106 static void cacheMetadata(const ResourceResponse&, const Vector<char>&);
108 virtual ~ResourceHandle();
110 #if PLATFORM(MAC) || USE(CFNETWORK)
111 void willSendRequest(ResourceRequest&, const ResourceResponse& redirectResponse);
112 bool shouldUseCredentialStorage();
114 #if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL) || USE(SOUP)
115 void didReceiveAuthenticationChallenge(const AuthenticationChallenge&);
116 virtual void receivedCredential(const AuthenticationChallenge&, const Credential&);
117 virtual void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&);
118 virtual void receivedCancellation(const AuthenticationChallenge&);
122 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
123 bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace&);
126 void didCancelAuthenticationChallenge(const AuthenticationChallenge&);
127 NSURLConnection *connection() const;
128 WebCoreResourceHandleAsDelegate *delegate();
129 void releaseDelegate();
133 void schedule(WTF::SchedulePair*);
134 void unschedule(WTF::SchedulePair*);
137 CFURLStorageSessionRef storageSession() const;
138 CFURLConnectionRef connection() const;
139 CFURLConnectionRef releaseConnectionForDownload();
140 static void setHostAllowsAnyHTTPSCertificate(const String&);
141 static void setClientCertificate(const String& host, CFDataRef);
144 #if PLATFORM(WIN) && USE(CURL)
145 static void setHostAllowsAnyHTTPSCertificate(const String&);
147 #if PLATFORM(WIN) && USE(CURL) && USE(CF)
148 static void setClientCertificate(const String& host, CFDataRef);
151 bool shouldContentSniff() const;
152 static bool shouldContentSniffURL(const KURL&);
154 static void forceContentSniffing();
157 void setSynchronousInternetHandle(HINTERNET);
158 void fileLoadTimer(Timer<ResourceHandle>*);
160 bool onRequestComplete();
161 static void CALLBACK internetStatusCallback(HINTERNET, DWORD_PTR, DWORD, LPVOID, DWORD);
164 #if PLATFORM(QT) || USE(CURL) || USE(SOUP) || PLATFORM(BLACKBERRY)
165 ResourceHandleInternal* getInternal() { return d.get(); }
169 void continueDidReceiveAuthenticationChallenge(const Credential& credentialFromPersistentStorage);
170 void sendPendingRequest();
171 bool shouldUseCredentialStorage();
172 bool cancelledOrClientless();
173 static SoupSession* defaultSession();
174 static uint64_t getSoupRequestInitiatingPageID(SoupRequest*);
175 static void setHostAllowsAnyHTTPSCertificate(const String&);
176 static void setClientCertificate(const String& host, GTlsCertificate*);
177 static void setIgnoreSSLErrors(bool);
180 // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the one you're in.
181 static bool loadsBlocked();
183 bool hasAuthenticationChallenge() const;
184 void clearAuthentication();
185 virtual void cancel();
187 // The client may be 0, in which case no callbacks will be made.
188 ResourceHandleClient* client() const;
189 void setClient(ResourceHandleClient*);
191 void setDefersLoading(bool);
193 #if PLATFORM(BLACKBERRY)
194 void pauseLoad(bool);
197 void didChangePriority(ResourceLoadPriority);
199 ResourceRequest& firstRequest();
200 const String& lastHTTPMethod() const;
202 void fireFailure(Timer<ResourceHandle>*);
204 NetworkingContext* context() const;
206 using RefCounted<ResourceHandle>::ref;
207 using RefCounted<ResourceHandle>::deref;
209 #if PLATFORM(MAC) || USE(CFNETWORK)
210 static CFStringRef synchronousLoadRunLoopMode();
213 #if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
214 void handleDataArray(CFArrayRef dataArray);
217 typedef PassRefPtr<ResourceHandle> (*BuiltinConstructor)(const ResourceRequest& request, ResourceHandleClient* client);
218 static void registerBuiltinConstructor(const AtomicString& protocol, BuiltinConstructor);
220 typedef void (*BuiltinSynchronousLoader)(NetworkingContext*, const ResourceRequest&, StoredCredentials, ResourceError&, ResourceResponse&, Vector<char>& data);
221 static void registerBuiltinSynchronousLoader(const AtomicString& protocol, BuiltinSynchronousLoader);
224 ResourceHandle(NetworkingContext*, const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff);
233 void platformSetDefersLoading(bool);
235 void scheduleFailure(FailureType);
238 static void platformLoadResourceSynchronously(NetworkingContext*, const ResourceRequest&, StoredCredentials, ResourceError&, ResourceResponse&, Vector<char>& data);
240 virtual void refAuthenticationClient() { ref(); }
241 virtual void derefAuthenticationClient() { deref(); }
243 #if PLATFORM(MAC) && !USE(CFNETWORK)
244 void createNSURLConnection(id delegate, bool shouldUseCredentialStorage, bool shouldContentSniff);
246 void createCFURLConnection(bool shouldUseCredentialStorage, bool shouldContentSniff);
249 friend class ResourceHandleInternal;
250 OwnPtr<ResourceHandleInternal> d;
255 #endif // ResourceHandle_h