Replace CaseFoldingHash with ASCIICaseInsensitiveHash
[WebKit-https.git] / Source / WebKit / win / WebURLResponse.cpp
index f8afa9a..cc9e497 100644 (file)
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -23,7 +23,6 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#include "config.h"
 #include "WebURLResponse.h"
 
 #include "WebKitDLL.h"
 #include "COMPropertyBag.h"
 #include "MarshallingHelpers.h"
 
+#if USE(CG)
+#include <CoreGraphics/CoreGraphics.h>
+#endif
+
 #if USE(CFNETWORK)
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
 
-#include <wtf/platform.h>
 #include <WebCore/BString.h>
-#include <WebCore/KURL.h>
+#include <WebCore/URL.h>
 #include <WebCore/LocalizedStrings.h>
 #include <WebCore/ResourceHandle.h>
 #include <shlobj.h>
@@ -47,7 +49,7 @@
 
 using namespace WebCore;
 
-static String CFHTTPMessageCopyLocalizedShortDescriptionForStatusCode(CFIndex statusCode)
+static String localizedShortDescriptionForStatusCode(int statusCode)
 {
     String result;
     if (statusCode < 100 || statusCode >= 600)
@@ -210,23 +212,22 @@ static String CFHTTPMessageCopyLocalizedShortDescriptionForStatusCode(CFIndex st
 // IWebURLResponse ----------------------------------------------------------------
 
 WebURLResponse::WebURLResponse()
-    :m_refCount(0)
 {
     gClassCount++;
-    gClassNameCount.add("WebURLResponse");
+    gClassNameCount().add("WebURLResponse");
 }
 
 WebURLResponse::~WebURLResponse()
 {
     gClassCount--;
-    gClassNameCount.remove("WebURLResponse");
+    gClassNameCount().remove("WebURLResponse");
 }
 
 WebURLResponse* WebURLResponse::createInstance()
 {
     WebURLResponse* instance = new WebURLResponse();
     // fake an http response - so it has the IWebHTTPURLResponse interface
-    instance->m_response = ResourceResponse(KURL(ParsedURLString, "http://"), String(), 0, String(), String());
+    instance->m_response = ResourceResponse(WebCore::URL(ParsedURLString, "http://"), String(), 0, String());
     instance->AddRef();
     return instance;
 }
@@ -245,9 +246,11 @@ WebURLResponse* WebURLResponse::createInstance(const ResourceResponse& response)
 
 // IUnknown -------------------------------------------------------------------
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::QueryInterface(REFIID riid, void** ppvObject)
+HRESULT WebURLResponse::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
 {
-    *ppvObject = 0;
+    if (!ppvObject)
+        return E_POINTER;
+    *ppvObject = nullptr;
     if (IsEqualGUID(riid, IID_IUnknown))
         *ppvObject = static_cast<IWebURLResponse*>(this);
     else if (IsEqualGUID(riid, __uuidof(this)))
@@ -265,12 +268,12 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::QueryInterface(REFIID riid, void** ppv
     return S_OK;
 }
 
-ULONG STDMETHODCALLTYPE WebURLResponse::AddRef(void)
+ULONG WebURLResponse::AddRef()
 {
     return ++m_refCount;
 }
 
-ULONG STDMETHODCALLTYPE WebURLResponse::Release(void)
+ULONG WebURLResponse::Release()
 {
     ULONG newRef = --m_refCount;
     if (!newRef)
@@ -281,26 +284,25 @@ ULONG STDMETHODCALLTYPE WebURLResponse::Release(void)
 
 // IWebURLResponse --------------------------------------------------------------------
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::expectedContentLength( 
-    /* [retval][out] */ long long* result)
+HRESULT WebURLResponse::expectedContentLength(_Out_ long long* result)
 {
+    if (!result)
+        return E_POINTER;
     *result = m_response.expectedContentLength();
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::initWithURL( 
-    /* [in] */ BSTR url,
-    /* [in] */ BSTR mimeType,
-    /* [in] */ int expectedContentLength,
-    /* [in] */ BSTR textEncodingName)
+HRESULT WebURLResponse::initWithURL(_In_ BSTR url, _In_ BSTR mimeType, int expectedContentLength, _In_ BSTR textEncodingName)
 {
-    m_response = ResourceResponse(MarshallingHelpers::BSTRToKURL(url), String(mimeType), expectedContentLength, String(textEncodingName), String());
+    m_response = ResourceResponse(MarshallingHelpers::BSTRToKURL(url), String(mimeType), expectedContentLength, String(textEncodingName));
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::MIMEType( 
-    /* [retval][out] */ BSTR* result)
+HRESULT WebURLResponse::MIMEType(__deref_opt_out BSTR* result)
 {
+    if (!result)
+        return E_POINTER;
+
     BString mimeType(m_response.mimeType());
     *result = mimeType.release();
     if (!m_response.mimeType().isNull() && !*result)
@@ -309,15 +311,14 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::MIMEType(
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::suggestedFilename( 
-    /* [retval][out] */ BSTR* result)
+HRESULT WebURLResponse::suggestedFilename(__deref_opt_out BSTR* result)
 {
     if (!result) {
         ASSERT_NOT_REACHED();
         return E_POINTER;
     }
 
-    *result = 0;
+    *result = nullptr;
 
     if (m_response.url().isEmpty())
         return E_FAIL;
@@ -326,8 +327,7 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::suggestedFilename(
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::textEncodingName( 
-    /* [retval][out] */ BSTR* result)
+HRESULT WebURLResponse::textEncodingName(__deref_opt_out BSTR* result)
 {
     if (!result)
         return E_INVALIDARG;
@@ -340,8 +340,7 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::textEncodingName(
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::URL( 
-    /* [retval][out] */ BSTR* result)
+HRESULT WebURLResponse::URL(__deref_opt_out BSTR* result)
 {
     if (!result)
         return E_INVALIDARG;
@@ -356,32 +355,36 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::URL(
 
 // IWebHTTPURLResponse --------------------------------------------------------
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::allHeaderFields( 
-    /* [retval][out] */ IPropertyBag** headerFields)
+HRESULT WebURLResponse::allHeaderFields(_COM_Outptr_opt_ IPropertyBag** headerFields)
 {
     ASSERT(m_response.isHTTP());
 
-    *headerFields = COMPropertyBag<String, AtomicString, CaseFoldingHash>::createInstance(m_response.httpHeaderFields());
+    if (!headerFields)
+        return E_POINTER;
+
+    HashMap<String, String, ASCIICaseInsensitiveHash> fields;
+    for (const auto& keyValuePair : m_response.httpHeaderFields())
+        fields.add(keyValuePair.key, keyValuePair.value);
+
+    *headerFields = COMPropertyBag<String, String, ASCIICaseInsensitiveHash>::adopt(fields);
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::localizedStringForStatusCode( 
-    /* [in] */ int statusCode,
-    /* [retval][out] */ BSTR* statusString)
+HRESULT WebURLResponse::localizedStringForStatusCode(int statusCode, __deref_opt_out BSTR* statusString)
 {
     ASSERT(m_response.isHTTP());
-    if (statusString)
-        *statusString = 0;
-    String statusText = CFHTTPMessageCopyLocalizedShortDescriptionForStatusCode(statusCode);
+    if (!statusString)
+        return E_POINTER;
+
+    *statusString = nullptr;
+    const String& statusText = localizedShortDescriptionForStatusCode(statusCode);
     if (!statusText)
         return E_FAIL;
-    if (statusString)
-        *statusString = BString(statusText).release();
+    *statusString = BString(statusText).release();
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::statusCode( 
-    /* [retval][out] */ int* statusCode)
+HRESULT WebURLResponse::statusCode(_Out_ int* statusCode)
 {
     ASSERT(m_response.isHTTP());
     if (statusCode)
@@ -389,16 +392,15 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::statusCode(
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebURLResponse::isAttachment( 
-    /* [retval][out] */ BOOL *attachment)
+HRESULT WebURLResponse::isAttachment(_Out_ BOOL* attachment)
 {
+    if (!attachment)
+        return E_POINTER;
     *attachment = m_response.isAttachment();
     return S_OK;
 }
 
-
-HRESULT STDMETHODCALLTYPE WebURLResponse::sslPeerCertificate( 
-    /* [retval][out] */ OLE_HANDLE* result)
+HRESULT WebURLResponse::sslPeerCertificate(_Out_ ULONG_PTR* result)
 {
     if (!result)
         return E_POINTER;
@@ -411,7 +413,7 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::sslPeerCertificate(
     void* data = wkGetSSLPeerCertificateDataBytePtr(dict);
     if (!data)
         return E_FAIL;
-    *result = (OLE_HANDLE)(ULONG64)data;
+    *result = reinterpret_cast<ULONG_PTR>(data);
 #endif
 
     return *result ? S_OK : E_FAIL;
@@ -419,12 +421,12 @@ HRESULT STDMETHODCALLTYPE WebURLResponse::sslPeerCertificate(
 
 // WebURLResponse -------------------------------------------------------------
 
-HRESULT WebURLResponse::suggestedFileExtension(BSTR *result)
+HRESULT WebURLResponse::suggestedFileExtension(BSTRresult)
 {
     if (!result)
         return E_POINTER;
 
-    *result = 0;
+    *result = nullptr;
 
     if (m_response.mimeType().isEmpty())
         return E_FAIL;
@@ -481,7 +483,7 @@ CFDictionaryRef WebURLResponse::certificateDictionary() const
 
     CFURLResponseRef cfResponse = m_response.cfURLResponse();
     if (!cfResponse)
-        return 0;
+        return nullptr;
     m_SSLCertificateInfo = wkGetSSLCertificateInfo(cfResponse);
     return m_SSLCertificateInfo.get();
 }