]> git.saurik.com Git - iphone-api.git/blob - WebCore/ResourceHandle.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / ResourceHandle.h
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 <wtf/OwnPtr.h>
32
33 #if PLATFORM(CF)
34 typedef const struct __CFData * CFDataRef;
35 #endif
36
37 #if PLATFORM(WIN)
38 typedef unsigned long DWORD;
39 typedef unsigned long DWORD_PTR;
40 typedef void* LPVOID;
41 typedef LPVOID HINTERNET;
42 typedef unsigned WPARAM;
43 typedef long LPARAM;
44 typedef struct HWND__* HWND;
45 typedef _W64 long LONG_PTR;
46 typedef LONG_PTR LRESULT;
47 #endif
48
49
50 #if PLATFORM(MAC)
51 #include <wtf/RetainPtr.h>
52 #ifdef __OBJC__
53 @class NSData;
54 @class NSError;
55 @class NSURLConnection;
56 @class WebCoreResourceHandleAsDelegate;
57 #else
58 class NSData;
59 class NSError;
60 class NSURLConnection;
61 class WebCoreResourceHandleAsDelegate;
62 typedef struct objc_object *id;
63 #endif
64 #endif
65
66 #if USE(CFNETWORK)
67 typedef struct _CFURLConnection* CFURLConnectionRef;
68 typedef int CFHTTPCookieStorageAcceptPolicy;
69 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
70 #endif
71
72 namespace WebCore {
73
74 class AuthenticationChallenge;
75 class Credential;
76 class FormData;
77 class Frame;
78 class KURL;
79 class ProtectionSpace;
80 class ResourceError;
81 class ResourceHandleClient;
82 class ResourceHandleInternal;
83 class ResourceRequest;
84 class ResourceResponse;
85 class SchedulePair;
86 class SharedBuffer;
87
88 template <typename T> class Timer;
89
90 class ResourceHandle : public RefCounted<ResourceHandle> {
91 private:
92 ResourceHandle(const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle);
93
94 enum FailureType {
95 BlockedFailure,
96 InvalidURLFailure
97 };
98
99 public:
100 // FIXME: should not need the Frame
101 static PassRefPtr<ResourceHandle> create(const ResourceRequest&, ResourceHandleClient*, Frame*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle = false);
102
103 static void loadResourceSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data, Frame* frame);
104 static bool willLoadFromCache(ResourceRequest&);
105 #if PLATFORM(MAC)
106 static bool didSendBodyDataDelegateExists();
107 #endif
108
109 ~ResourceHandle();
110
111 #if PLATFORM(MAC) || USE(CFNETWORK)
112 bool shouldUseCredentialStorage();
113 #endif
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&);
119 #endif
120
121 #if PLATFORM(MAC)
122 void didCancelAuthenticationChallenge(const AuthenticationChallenge&);
123
124 bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace&);
125
126 NSURLConnection *connection() const;
127 WebCoreResourceHandleAsDelegate *delegate();
128 void releaseDelegate();
129 id releaseProxy();
130
131 void schedule(SchedulePair*);
132 void unschedule(SchedulePair*);
133 #elif USE(CFNETWORK)
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);
139 #endif
140
141 #if PLATFORM(WIN) && USE(CURL)
142 static void setHostAllowsAnyHTTPSCertificate(const String&);
143 #endif
144 #if PLATFORM(WIN) && USE(CURL) && PLATFORM(CF)
145 static void setClientCertificate(const String& host, CFDataRef);
146 #endif
147
148 PassRefPtr<SharedBuffer> bufferedData();
149 static bool supportsBufferedData();
150
151 #if USE(WININET)
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);
160 #endif
161
162 #if PLATFORM(QT) || USE(CURL) || USE(SOUP)
163 ResourceHandleInternal* getInternal() { return d.get(); }
164 #endif
165
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();
168
169 void clearAuthentication();
170 void cancel();
171
172 // The client may be 0, in which case no callbacks will be made.
173 ResourceHandleClient* client() const;
174 void setClient(ResourceHandleClient*);
175
176 void setDefersLoading(bool);
177
178 const ResourceRequest& request() const;
179
180 void fireFailure(Timer<ResourceHandle>*);
181
182 private:
183 #if USE(SOUP)
184 bool startData(String urlString);
185 bool startHttp(String urlString);
186 bool startGio(String urlString);
187 #endif
188
189 void scheduleFailure(FailureType);
190
191 bool start(Frame*);
192
193 friend class ResourceHandleInternal;
194 OwnPtr<ResourceHandleInternal> d;
195 };
196
197 void addQLPreviewConverterForURL(NSURL *, id converter);
198 void removeQLPreviewConverterForURL(NSURL *);
199 const KURL safeQLURLForDocumentURLAndResourceURL(const KURL& documentURL, const String& resourceURL);
200
201 }
202
203 #endif // ResourceHandle_h