|
1 /* |
|
2 * Copyright (C) 2006, 2007 Apple 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 #include "config.h" |
|
27 #include "WebKitDLL.h" |
|
28 #include "WebMutableURLRequest.h" |
|
29 |
|
30 #include "IWebURLResponse.h" |
|
31 #include "MarshallingHelpers.h" |
|
32 #include "WebKit.h" |
|
33 #pragma warning(push, 0) |
|
34 #include <WebCore/BString.h> |
|
35 #include <WebCore/CString.h> |
|
36 #include <WebCore/FormData.h> |
|
37 #include <WebCore/ResourceHandle.h> |
|
38 #pragma warning(pop) |
|
39 |
|
40 using namespace WebCore; |
|
41 |
|
42 // IWebURLRequest ---------------------------------------------------------------- |
|
43 |
|
44 WebMutableURLRequest::WebMutableURLRequest(bool isMutable) |
|
45 : m_refCount(0) |
|
46 , m_isMutable(isMutable) |
|
47 { |
|
48 gClassCount++; |
|
49 } |
|
50 |
|
51 WebMutableURLRequest* WebMutableURLRequest::createInstance() |
|
52 { |
|
53 WebMutableURLRequest* instance = new WebMutableURLRequest(true); |
|
54 instance->AddRef(); |
|
55 return instance; |
|
56 } |
|
57 |
|
58 WebMutableURLRequest* WebMutableURLRequest::createInstance(IWebMutableURLRequest* req) |
|
59 { |
|
60 WebMutableURLRequest* instance = new WebMutableURLRequest(true); |
|
61 instance->AddRef(); |
|
62 instance->m_request = static_cast<WebMutableURLRequest*>(req)->m_request; |
|
63 return instance; |
|
64 } |
|
65 |
|
66 WebMutableURLRequest* WebMutableURLRequest::createInstance(const ResourceRequest& request) |
|
67 { |
|
68 WebMutableURLRequest* instance = new WebMutableURLRequest(true); |
|
69 instance->AddRef(); |
|
70 instance->m_request = request; |
|
71 return instance; |
|
72 } |
|
73 |
|
74 WebMutableURLRequest* WebMutableURLRequest::createImmutableInstance() |
|
75 { |
|
76 WebMutableURLRequest* instance = new WebMutableURLRequest(false); |
|
77 instance->AddRef(); |
|
78 return instance; |
|
79 } |
|
80 |
|
81 WebMutableURLRequest* WebMutableURLRequest::createImmutableInstance(const ResourceRequest& request) |
|
82 { |
|
83 WebMutableURLRequest* instance = new WebMutableURLRequest(false); |
|
84 instance->AddRef(); |
|
85 instance->m_request = request; |
|
86 return instance; |
|
87 } |
|
88 |
|
89 WebMutableURLRequest::~WebMutableURLRequest() |
|
90 { |
|
91 gClassCount--; |
|
92 } |
|
93 |
|
94 // IUnknown ------------------------------------------------------------------- |
|
95 |
|
96 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::QueryInterface(REFIID riid, void** ppvObject) |
|
97 { |
|
98 *ppvObject = 0; |
|
99 if (IsEqualGUID(riid, CLSID_WebMutableURLRequest)) |
|
100 *ppvObject = this; |
|
101 else if (IsEqualGUID(riid, IID_IUnknown)) |
|
102 *ppvObject = static_cast<IWebURLRequest*>(this); |
|
103 else if (IsEqualGUID(riid, IID_IWebMutableURLRequest) && m_isMutable) |
|
104 *ppvObject = static_cast<IWebMutableURLRequest*>(this); |
|
105 else if (IsEqualGUID(riid, IID_IWebURLRequest)) |
|
106 *ppvObject = static_cast<IWebURLRequest*>(this); |
|
107 else |
|
108 return E_NOINTERFACE; |
|
109 |
|
110 AddRef(); |
|
111 return S_OK; |
|
112 } |
|
113 |
|
114 ULONG STDMETHODCALLTYPE WebMutableURLRequest::AddRef(void) |
|
115 { |
|
116 return ++m_refCount; |
|
117 } |
|
118 |
|
119 ULONG STDMETHODCALLTYPE WebMutableURLRequest::Release(void) |
|
120 { |
|
121 ULONG newRef = --m_refCount; |
|
122 if (!newRef) |
|
123 delete(this); |
|
124 |
|
125 return newRef; |
|
126 } |
|
127 |
|
128 // IWebURLRequest -------------------------------------------------------------------- |
|
129 |
|
130 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::requestWithURL( |
|
131 /* [in] */ BSTR /*theURL*/, |
|
132 /* [optional][in] */ WebURLRequestCachePolicy /*cachePolicy*/, |
|
133 /* [optional][in] */ double /*timeoutInterval*/) |
|
134 { |
|
135 ASSERT_NOT_REACHED(); |
|
136 return E_NOTIMPL; |
|
137 } |
|
138 |
|
139 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::allHTTPHeaderFields( |
|
140 /* [retval][out] */ IPropertyBag** /*result*/) |
|
141 { |
|
142 ASSERT_NOT_REACHED(); |
|
143 return E_NOTIMPL; |
|
144 } |
|
145 |
|
146 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::cachePolicy( |
|
147 /* [retval][out] */ WebURLRequestCachePolicy* result) |
|
148 { |
|
149 *result = kit(m_request.cachePolicy()); |
|
150 return S_OK; |
|
151 } |
|
152 |
|
153 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPBody( |
|
154 /* [retval][out] */ IStream** /*result*/) |
|
155 { |
|
156 ASSERT_NOT_REACHED(); |
|
157 return E_NOTIMPL; |
|
158 } |
|
159 |
|
160 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPBodyStream( |
|
161 /* [retval][out] */ IStream** /*result*/) |
|
162 { |
|
163 ASSERT_NOT_REACHED(); |
|
164 return E_NOTIMPL; |
|
165 } |
|
166 |
|
167 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPMethod( |
|
168 /* [retval][out] */ BSTR* result) |
|
169 { |
|
170 BString httpMethod = BString(m_request.httpMethod()); |
|
171 *result = httpMethod.release(); |
|
172 return S_OK; |
|
173 } |
|
174 |
|
175 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPShouldHandleCookies( |
|
176 /* [retval][out] */ BOOL* /*result*/) |
|
177 { |
|
178 ASSERT_NOT_REACHED(); |
|
179 return E_NOTIMPL; |
|
180 } |
|
181 |
|
182 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::initWithURL( |
|
183 /* [in] */ BSTR url, |
|
184 /* [optional][in] */ WebURLRequestCachePolicy cachePolicy, |
|
185 /* [optional][in] */ double timeoutInterval) |
|
186 { |
|
187 m_request.setURL(MarshallingHelpers::BSTRToKURL(url)); |
|
188 m_request.setCachePolicy(core(cachePolicy)); |
|
189 m_request.setTimeoutInterval(timeoutInterval); |
|
190 |
|
191 return S_OK; |
|
192 } |
|
193 |
|
194 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::mainDocumentURL( |
|
195 /* [retval][out] */ BSTR* result) |
|
196 { |
|
197 *result = MarshallingHelpers::KURLToBSTR(m_request.url()); |
|
198 return S_OK; |
|
199 } |
|
200 |
|
201 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::timeoutInterval( |
|
202 /* [retval][out] */ double* result) |
|
203 { |
|
204 *result = m_request.timeoutInterval(); |
|
205 return S_OK; |
|
206 } |
|
207 |
|
208 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::URL( |
|
209 /* [retval][out] */ BSTR* result) |
|
210 { |
|
211 *result = MarshallingHelpers::KURLToBSTR(m_request.url()); |
|
212 return S_OK; |
|
213 } |
|
214 |
|
215 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::valueForHTTPHeaderField( |
|
216 /* [in] */ BSTR field, |
|
217 /* [retval][out] */ BSTR* result) |
|
218 { |
|
219 if (!result) { |
|
220 ASSERT_NOT_REACHED(); |
|
221 return E_POINTER; |
|
222 } |
|
223 |
|
224 *result = BString(m_request.httpHeaderField(String(field, SysStringLen(field)))).release(); |
|
225 return S_OK; |
|
226 } |
|
227 |
|
228 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::isEmpty( |
|
229 /* [retval][out] */ BOOL* result) |
|
230 { |
|
231 *result = m_request.isEmpty(); |
|
232 return S_OK; |
|
233 } |
|
234 |
|
235 // IWebMutableURLRequest -------------------------------------------------------- |
|
236 |
|
237 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::addValue( |
|
238 /* [in] */ BSTR /*value*/, |
|
239 /* [in] */ BSTR /*field*/) |
|
240 { |
|
241 ASSERT_NOT_REACHED(); |
|
242 return E_NOTIMPL; |
|
243 } |
|
244 |
|
245 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setAllHTTPHeaderFields( |
|
246 /* [in] */ IPropertyBag* /*headerFields*/) |
|
247 { |
|
248 ASSERT_NOT_REACHED(); |
|
249 return E_NOTIMPL; |
|
250 } |
|
251 |
|
252 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setCachePolicy( |
|
253 /* [in] */ WebURLRequestCachePolicy policy) |
|
254 { |
|
255 m_request.setCachePolicy(core(policy)); |
|
256 return S_OK; |
|
257 } |
|
258 |
|
259 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPBody( |
|
260 /* [in] */ IStream* /*data*/) |
|
261 { |
|
262 ASSERT_NOT_REACHED(); |
|
263 return E_NOTIMPL; |
|
264 } |
|
265 |
|
266 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPBodyStream( |
|
267 /* [in] */ IStream* /*data*/) |
|
268 { |
|
269 ASSERT_NOT_REACHED(); |
|
270 return E_NOTIMPL; |
|
271 } |
|
272 |
|
273 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPMethod( |
|
274 /* [in] */ BSTR method) |
|
275 { |
|
276 m_request.setHTTPMethod(String(method)); |
|
277 return S_OK; |
|
278 } |
|
279 |
|
280 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPShouldHandleCookies( |
|
281 /* [in] */ BOOL /*handleCookies*/) |
|
282 { |
|
283 ASSERT_NOT_REACHED(); |
|
284 return E_NOTIMPL; |
|
285 } |
|
286 |
|
287 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setMainDocumentURL( |
|
288 /* [in] */ BSTR /*theURL*/) |
|
289 { |
|
290 ASSERT_NOT_REACHED(); |
|
291 return E_NOTIMPL; |
|
292 } |
|
293 |
|
294 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setTimeoutInterval( |
|
295 /* [in] */ double /*timeoutInterval*/) |
|
296 { |
|
297 ASSERT_NOT_REACHED(); |
|
298 return E_NOTIMPL; |
|
299 } |
|
300 |
|
301 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setURL( |
|
302 /* [in] */ BSTR url) |
|
303 { |
|
304 m_request.setURL(MarshallingHelpers::BSTRToKURL(url)); |
|
305 return S_OK; |
|
306 } |
|
307 |
|
308 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setValue( |
|
309 /* [in] */ BSTR /*value*/, |
|
310 /* [in] */ BSTR /*field*/) |
|
311 { |
|
312 ASSERT_NOT_REACHED(); |
|
313 return E_NOTIMPL; |
|
314 } |
|
315 |
|
316 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setAllowsAnyHTTPSCertificate(void) |
|
317 { |
|
318 ResourceHandle::setHostAllowsAnyHTTPSCertificate(m_request.url().host()); |
|
319 |
|
320 return S_OK; |
|
321 } |
|
322 |
|
323 // IWebMutableURLRequest ---------------------------------------------------- |
|
324 |
|
325 void WebMutableURLRequest::setFormData(const PassRefPtr<FormData> data) |
|
326 { |
|
327 m_request.setHTTPBody(data); |
|
328 } |
|
329 |
|
330 const PassRefPtr<FormData> WebMutableURLRequest::formData() const |
|
331 { |
|
332 return m_request.httpBody(); |
|
333 } |
|
334 |
|
335 void WebMutableURLRequest::addHTTPHeaderFields(const HTTPHeaderMap& headerFields) |
|
336 { |
|
337 m_request.addHTTPHeaderFields(headerFields); |
|
338 } |
|
339 |
|
340 const HTTPHeaderMap& WebMutableURLRequest::httpHeaderFields() const |
|
341 { |
|
342 return m_request.httpHeaderFields(); |
|
343 } |
|
344 |
|
345 const ResourceRequest& WebMutableURLRequest::resourceRequest() const |
|
346 { |
|
347 return m_request; |
|
348 } |