2 * Copyright (C) 2004, 2006 Apple Computer, 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 "AuthenticationChallenge.h"
30 #include "HTTPHeaderMap.h"
31 #include <wtf/OwnPtr.h>
34 typedef const struct __CFData
* CFDataRef
;
38 typedef unsigned long DWORD
;
39 typedef unsigned long DWORD_PTR
;
41 typedef LPVOID HINTERNET
;
42 typedef unsigned WPARAM
;
44 typedef struct HWND__
* HWND
;
45 typedef _W64
long LONG_PTR
;
46 typedef LONG_PTR LRESULT
;
51 #include <wtf/RetainPtr.h>
55 @
class NSURLConnection
;
56 @
class WebCoreResourceHandleAsDelegate
;
60 class NSURLConnection
;
61 class WebCoreResourceHandleAsDelegate
;
62 typedef struct objc_object
*id
;
67 typedef struct _CFURLConnection
* CFURLConnectionRef
;
68 typedef int CFHTTPCookieStorageAcceptPolicy
;
69 typedef struct OpaqueCFHTTPCookieStorage
* CFHTTPCookieStorageRef
;
74 class AuthenticationChallenge
;
79 class ProtectionSpace
;
81 class ResourceHandleClient
;
82 class ResourceHandleInternal
;
83 class ResourceRequest
;
84 class ResourceResponse
;
88 template <typename T
> class Timer
;
90 class ResourceHandle
: public RefCounted
<ResourceHandle
> {
92 ResourceHandle(const ResourceRequest
&, ResourceHandleClient
*, bool defersLoading
, bool shouldContentSniff
, bool mightDownloadFromHandle
);
100 // FIXME: should not need the Frame
101 static PassRefPtr
<ResourceHandle
> create(const ResourceRequest
&, ResourceHandleClient
*, Frame
*, bool defersLoading
, bool shouldContentSniff
, bool mightDownloadFromHandle
= false);
103 static void loadResourceSynchronously(const ResourceRequest
&, ResourceError
&, ResourceResponse
&, Vector
<char>& data
, Frame
* frame
);
104 static bool willLoadFromCache(ResourceRequest
&);
106 static bool didSendBodyDataDelegateExists();
111 #if PLATFORM(MAC) || USE(CFNETWORK)
112 bool shouldUseCredentialStorage();
114 #if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL)
115 void didReceiveAuthenticationChallenge(const AuthenticationChallenge
&);
116 void receivedCredential(const AuthenticationChallenge
&, const Credential
&);
117 void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge
&);
118 void receivedCancellation(const AuthenticationChallenge
&);
122 void didCancelAuthenticationChallenge(const AuthenticationChallenge
&);
124 bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace
&);
126 NSURLConnection
*connection() const;
127 WebCoreResourceHandleAsDelegate
*delegate();
128 void releaseDelegate();
131 void schedule(SchedulePair
*);
132 void unschedule(SchedulePair
*);
134 static CFRunLoopRef
loaderRunLoop();
135 CFURLConnectionRef
connection() const;
136 CFURLConnectionRef
releaseConnectionForDownload();
137 static void setHostAllowsAnyHTTPSCertificate(const String
&);
138 static void setClientCertificate(const String
& host
, CFDataRef
);
141 #if PLATFORM(WIN) && USE(CURL)
142 static void setHostAllowsAnyHTTPSCertificate(const String
&);
144 #if PLATFORM(WIN) && USE(CURL) && PLATFORM(CF)
145 static void setClientCertificate(const String
& host
, CFDataRef
);
148 PassRefPtr
<SharedBuffer
> bufferedData();
149 static bool supportsBufferedData();
152 void setHasReceivedResponse(bool = true);
153 bool hasReceivedResponse() const;
154 void fileLoadTimer(Timer
<ResourceHandle
>*);
155 void onHandleCreated(LPARAM
);
156 void onRequestRedirected(LPARAM
);
157 void onRequestComplete(LPARAM
);
158 friend void __stdcall
transferJobStatusCallback(HINTERNET
, DWORD_PTR
, DWORD
, LPVOID
, DWORD
);
159 friend LRESULT __stdcall
ResourceHandleWndProc(HWND
, unsigned message
, WPARAM
, LPARAM
);
162 #if PLATFORM(QT) || USE(CURL) || USE(SOUP)
163 ResourceHandleInternal
* getInternal() { return d
.get(); }
166 // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the one you're in.
167 static bool loadsBlocked();
169 void clearAuthentication();
172 // The client may be 0, in which case no callbacks will be made.
173 ResourceHandleClient
* client() const;
174 void setClient(ResourceHandleClient
*);
176 void setDefersLoading(bool);
178 const ResourceRequest
& request() const;
180 void fireFailure(Timer
<ResourceHandle
>*);
184 bool startData(String urlString
);
185 bool startHttp(String urlString
);
186 bool startGio(String urlString
);
189 void scheduleFailure(FailureType
);
193 friend class ResourceHandleInternal
;
194 OwnPtr
<ResourceHandleInternal
> d
;
197 void addQLPreviewConverterForURL(NSURL
*, id converter
);
198 void removeQLPreviewConverterForURL(NSURL
*);
199 const KURL
safeQLURLForDocumentURLAndResourceURL(const KURL
& documentURL
, const String
& resourceURL
);
203 #endif // ResourceHandle_h