2 * Copyright (C) 2006, 2007 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.
27 #include "WebKitDLL.h"
28 #include "WebMutableURLRequest.h"
31 #include "MarshallingHelpers.h"
33 #include <WebCore/BString.h>
34 #include <WebCore/COMPtr.h>
35 #include <WebCore/FormData.h>
36 #include <WebCore/NotImplemented.h>
37 #include <WebCore/ResourceHandle.h>
38 #include <wtf/text/CString.h>
39 #include <wtf/RetainPtr.h>
42 #include <WebCore/CertificateCFWin.h>
46 #include <CFNetwork/CFURLRequestPriv.h>
49 using namespace WebCore;
51 // IWebURLRequest ----------------------------------------------------------------
53 WebMutableURLRequest::WebMutableURLRequest(bool isMutable)
55 , m_isMutable(isMutable)
58 gClassNameCount.add("WebMutableURLRequest");
61 WebMutableURLRequest* WebMutableURLRequest::createInstance()
63 WebMutableURLRequest* instance = new WebMutableURLRequest(true);
68 WebMutableURLRequest* WebMutableURLRequest::createInstance(IWebMutableURLRequest* req)
70 WebMutableURLRequest* instance = new WebMutableURLRequest(true);
72 instance->m_request = static_cast<WebMutableURLRequest*>(req)->m_request;
76 WebMutableURLRequest* WebMutableURLRequest::createInstance(const ResourceRequest& request)
78 WebMutableURLRequest* instance = new WebMutableURLRequest(true);
80 instance->m_request = request;
84 WebMutableURLRequest* WebMutableURLRequest::createImmutableInstance()
86 WebMutableURLRequest* instance = new WebMutableURLRequest(false);
91 WebMutableURLRequest* WebMutableURLRequest::createImmutableInstance(const ResourceRequest& request)
93 WebMutableURLRequest* instance = new WebMutableURLRequest(false);
95 instance->m_request = request;
99 WebMutableURLRequest::~WebMutableURLRequest()
102 gClassNameCount.remove("WebMutableURLRequest");
105 // IUnknown -------------------------------------------------------------------
107 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::QueryInterface(REFIID riid, void** ppvObject)
110 if (IsEqualGUID(riid, CLSID_WebMutableURLRequest))
112 else if (IsEqualGUID(riid, IID_IUnknown))
113 *ppvObject = static_cast<IWebURLRequest*>(this);
114 else if (IsEqualGUID(riid, IID_IWebMutableURLRequest) && m_isMutable)
115 *ppvObject = static_cast<IWebMutableURLRequest*>(this);
116 else if (IsEqualGUID(riid, __uuidof(IWebMutableURLRequestPrivate)) && m_isMutable)
117 *ppvObject = static_cast<IWebMutableURLRequestPrivate*>(this);
118 else if (IsEqualGUID(riid, IID_IWebURLRequest))
119 *ppvObject = static_cast<IWebURLRequest*>(this);
121 return E_NOINTERFACE;
127 ULONG STDMETHODCALLTYPE WebMutableURLRequest::AddRef(void)
132 ULONG STDMETHODCALLTYPE WebMutableURLRequest::Release(void)
134 ULONG newRef = --m_refCount;
141 // IWebURLRequest --------------------------------------------------------------------
143 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::requestWithURL(
144 /* [in] */ BSTR /*theURL*/,
145 /* [optional][in] */ WebURLRequestCachePolicy /*cachePolicy*/,
146 /* [optional][in] */ double /*timeoutInterval*/)
148 ASSERT_NOT_REACHED();
152 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::allHTTPHeaderFields(
153 /* [retval][out] */ IPropertyBag** /*result*/)
155 ASSERT_NOT_REACHED();
159 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::cachePolicy(
160 /* [retval][out] */ WebURLRequestCachePolicy* result)
162 *result = kit(m_request.cachePolicy());
166 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPBody(
167 /* [retval][out] */ IStream** /*result*/)
169 ASSERT_NOT_REACHED();
173 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPBodyStream(
174 /* [retval][out] */ IStream** /*result*/)
176 ASSERT_NOT_REACHED();
180 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPMethod(
181 /* [retval][out] */ BSTR* result)
183 BString httpMethod = BString(m_request.httpMethod());
184 *result = httpMethod.release();
188 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::HTTPShouldHandleCookies(
189 /* [retval][out] */ BOOL* /*result*/)
191 ASSERT_NOT_REACHED();
195 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::initWithURL(
197 /* [optional][in] */ WebURLRequestCachePolicy cachePolicy,
198 /* [optional][in] */ double timeoutInterval)
200 m_request.setURL(MarshallingHelpers::BSTRToKURL(url));
201 m_request.setCachePolicy(core(cachePolicy));
202 m_request.setTimeoutInterval(timeoutInterval);
207 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::mainDocumentURL(
208 /* [retval][out] */ BSTR* result)
210 *result = MarshallingHelpers::KURLToBSTR(m_request.firstPartyForCookies());
214 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::timeoutInterval(
215 /* [retval][out] */ double* result)
217 *result = m_request.timeoutInterval();
221 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::URL(
222 /* [retval][out] */ BSTR* result)
224 *result = MarshallingHelpers::KURLToBSTR(m_request.url());
228 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::valueForHTTPHeaderField(
229 /* [in] */ BSTR field,
230 /* [retval][out] */ BSTR* result)
233 ASSERT_NOT_REACHED();
237 *result = BString(m_request.httpHeaderField(String(field, SysStringLen(field)))).release();
241 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::isEmpty(
242 /* [retval][out] */ BOOL* result)
244 *result = m_request.isEmpty();
248 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::isEqual(
249 /* [in] */ IWebURLRequest* other,
250 /* [out, retval] */ BOOL* result)
252 COMPtr<WebMutableURLRequest> requestImpl(Query, other);
259 *result = m_request == requestImpl->resourceRequest();
264 // IWebMutableURLRequest --------------------------------------------------------
266 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::addValue(
267 /* [in] */ BSTR /*value*/,
268 /* [in] */ BSTR /*field*/)
270 ASSERT_NOT_REACHED();
274 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setAllHTTPHeaderFields(
275 /* [in] */ IPropertyBag* /*headerFields*/)
277 ASSERT_NOT_REACHED();
281 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setCachePolicy(
282 /* [in] */ WebURLRequestCachePolicy policy)
284 m_request.setCachePolicy(core(policy));
288 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPBody(
289 /* [in] */ IStream* /*data*/)
291 ASSERT_NOT_REACHED();
295 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPBodyStream(
296 /* [in] */ IStream* /*data*/)
298 ASSERT_NOT_REACHED();
302 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPMethod(
303 /* [in] */ BSTR method)
305 m_request.setHTTPMethod(String(method));
309 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setHTTPShouldHandleCookies(
310 /* [in] */ BOOL handleCookies)
312 m_request.setAllowCookies(handleCookies);
316 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setMainDocumentURL(
317 /* [in] */ BSTR /*theURL*/)
319 ASSERT_NOT_REACHED();
323 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setTimeoutInterval(
324 /* [in] */ double timeoutInterval)
326 m_request.setTimeoutInterval(timeoutInterval);
330 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setURL(
333 m_request.setURL(MarshallingHelpers::BSTRToKURL(url));
337 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setValue(
338 /* [in] */ BSTR value,
339 /* [in] */ BSTR field)
341 String valueString(value, SysStringLen(value));
342 String fieldString(field, SysStringLen(field));
343 m_request.setHTTPHeaderField(fieldString, valueString);
347 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setAllowsAnyHTTPSCertificate(void)
349 ResourceHandle::setHostAllowsAnyHTTPSCertificate(m_request.url().host());
354 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::setClientCertificate(
355 /* [in] */ OLE_HANDLE cert)
360 PCCERT_CONTEXT certContext = reinterpret_cast<PCCERT_CONTEXT>((ULONG64)cert);
361 RetainPtr<CFDataRef> certData = WebCore::copyCertificateToData(certContext);
362 ResourceHandle::setClientCertificate(m_request.url().host(), certData.get());
366 CFURLRequestRef STDMETHODCALLTYPE WebMutableURLRequest::cfRequest()
368 return m_request.cfURLRequest();
371 HRESULT STDMETHODCALLTYPE WebMutableURLRequest::mutableCopy(
372 /* [out, retval] */ IWebMutableURLRequest** result)
378 RetainPtr<CFMutableURLRequestRef> mutableRequest(AdoptCF, CFURLRequestCreateMutableCopy(kCFAllocatorDefault, m_request.cfURLRequest()));
379 *result = createInstance(ResourceRequest(mutableRequest.get()));
382 *result = createInstance(m_request);
387 // IWebMutableURLRequest ----------------------------------------------------
389 void WebMutableURLRequest::setFormData(const PassRefPtr<FormData> data)
391 m_request.setHTTPBody(data);
394 const PassRefPtr<FormData> WebMutableURLRequest::formData() const
396 return m_request.httpBody();
399 void WebMutableURLRequest::addHTTPHeaderFields(const HTTPHeaderMap& headerFields)
401 m_request.addHTTPHeaderFields(headerFields);
404 const HTTPHeaderMap& WebMutableURLRequest::httpHeaderFields() const
406 return m_request.httpHeaderFields();
409 const ResourceRequest& WebMutableURLRequest::resourceRequest() const