Allow retrieving the Soup session and modify the code to take
[WebKit-https.git] / WebCore / platform / network / 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 USE(SOUP)
34 typedef struct _SoupSession SoupSession;
35 #endif
36
37 #if PLATFORM(CF)
38 typedef const struct __CFData * CFDataRef;
39 #endif
40
41 #if PLATFORM(WIN)
42 typedef unsigned long DWORD;
43 typedef unsigned long DWORD_PTR;
44 typedef void* LPVOID;
45 typedef LPVOID HINTERNET;
46 typedef unsigned WPARAM;
47 typedef long LPARAM;
48 typedef struct HWND__* HWND;
49 typedef _W64 long LONG_PTR;
50 typedef LONG_PTR LRESULT;
51 #endif
52
53
54 #if PLATFORM(MAC)
55 #include <wtf/RetainPtr.h>
56 #ifdef __OBJC__
57 @class NSData;
58 @class NSError;
59 @class NSURLConnection;
60 @class WebCoreResourceHandleAsDelegate;
61 #else
62 class NSData;
63 class NSError;
64 class NSURLConnection;
65 class WebCoreResourceHandleAsDelegate;
66 typedef struct objc_object *id;
67 #endif
68 #endif
69
70 #if USE(CFNETWORK)
71 typedef struct _CFURLConnection* CFURLConnectionRef;
72 typedef int CFHTTPCookieStorageAcceptPolicy;
73 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
74 #endif
75
76 namespace WebCore {
77
78 class AuthenticationChallenge;
79 class Credential;
80 class FormData;
81 class Frame;
82 class KURL;
83 class ResourceError;
84 class ResourceHandleClient;
85 class ResourceHandleInternal;
86 class ResourceRequest;
87 class ResourceResponse;
88 class SchedulePair;
89 class SharedBuffer;
90
91 template <typename T> class Timer;
92
93 class ResourceHandle : public RefCounted<ResourceHandle> {
94 private:
95     ResourceHandle(const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle);
96
97     enum FailureType {
98         BlockedFailure,
99         InvalidURLFailure
100     };
101
102 public:
103     // FIXME: should not need the Frame
104     static PassRefPtr<ResourceHandle> create(const ResourceRequest&, ResourceHandleClient*, Frame*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle = false);
105
106     static void loadResourceSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data, Frame* frame);
107     static bool willLoadFromCache(ResourceRequest&);
108 #if PLATFORM(MAC)
109     static bool didSendBodyDataDelegateExists();
110 #endif
111
112     ~ResourceHandle();
113
114 #if PLATFORM(MAC) || USE(CFNETWORK)
115     bool shouldUseCredentialStorage();
116 #endif
117 #if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL)
118     void didReceiveAuthenticationChallenge(const AuthenticationChallenge&);
119     void receivedCredential(const AuthenticationChallenge&, const Credential&);
120     void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&);
121     void receivedCancellation(const AuthenticationChallenge&);
122 #endif
123
124 #if PLATFORM(MAC)
125     void didCancelAuthenticationChallenge(const AuthenticationChallenge&);
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 #if USE(SOUP)
167     static SoupSession* defaultSession();
168 #endif
169
170     // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the one you're in.
171     static bool loadsBlocked();    
172     
173     void clearAuthentication();
174     void cancel();
175
176     // The client may be 0, in which case no callbacks will be made.
177     ResourceHandleClient* client() const;
178     void setClient(ResourceHandleClient*);
179
180     void setDefersLoading(bool);
181       
182     const ResourceRequest& request() const;
183
184     void fireFailure(Timer<ResourceHandle>*);
185
186 private:
187 #if USE(SOUP)
188     bool startData(String urlString);
189     bool startHttp(String urlString);
190     bool startGio(KURL url);
191 #endif
192
193     void scheduleFailure(FailureType);
194
195     bool start(Frame*);
196
197     friend class ResourceHandleInternal;
198     OwnPtr<ResourceHandleInternal> d;
199 };
200
201 }
202
203 #endif // ResourceHandle_h