webengine/osswebengine/WebKit/win/WebResource.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 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 "WebResource.h"
       
    29 
       
    30 #include "MemoryStream.h"
       
    31 
       
    32 #pragma warning(push, 0)
       
    33 #include <WebCore/BString.h>
       
    34 #pragma warning(pop)
       
    35 
       
    36 using namespace WebCore;
       
    37 
       
    38 // WebResource ---------------------------------------------------------------------
       
    39 
       
    40 WebResource::WebResource(IStream* data, const WebCore::KURL& url, const WebCore::String& mimeType, const WebCore::String& textEncodingName, const WebCore::String& frameName)
       
    41     : m_refCount(0)
       
    42     , m_data(data)
       
    43     , m_url(url)
       
    44     , m_mimeType(mimeType)
       
    45     , m_textEncodingName(textEncodingName)
       
    46     , m_frameName(frameName)
       
    47 {
       
    48     gClassCount++;
       
    49 }
       
    50 
       
    51 WebResource::~WebResource()
       
    52 {
       
    53     gClassCount--;
       
    54 }
       
    55 
       
    56 WebResource* WebResource::createInstance(PassRefPtr<WebCore::SharedBuffer> data, const WebCore::ResourceResponse& response)
       
    57 {
       
    58     COMPtr<IStream> memoryStream;
       
    59     memoryStream.adoptRef(MemoryStream::createInstance(data));
       
    60 
       
    61     WebResource* instance = new WebResource(memoryStream.get(), response.url(), response.mimeType(), response.textEncodingName(), String());
       
    62     instance->AddRef();
       
    63     return instance;
       
    64 }
       
    65 
       
    66 // IUnknown -------------------------------------------------------------------
       
    67 
       
    68 HRESULT STDMETHODCALLTYPE WebResource::QueryInterface(REFIID riid, void** ppvObject)
       
    69 {
       
    70     *ppvObject = 0;
       
    71     if (IsEqualGUID(riid, IID_IUnknown))
       
    72         *ppvObject = static_cast<IUnknown*>(this);
       
    73     else if (IsEqualGUID(riid, IID_IWebResource))
       
    74         *ppvObject = static_cast<IWebResource*>(this);
       
    75     else
       
    76         return E_NOINTERFACE;
       
    77 
       
    78     AddRef();
       
    79     return S_OK;
       
    80 }
       
    81 
       
    82 ULONG STDMETHODCALLTYPE WebResource::AddRef(void)
       
    83 {
       
    84     return ++m_refCount;
       
    85 }
       
    86 
       
    87 ULONG STDMETHODCALLTYPE WebResource::Release(void)
       
    88 {
       
    89     ULONG newRef = --m_refCount;
       
    90     if (!newRef)
       
    91         delete(this);
       
    92 
       
    93     return newRef;
       
    94 }
       
    95 
       
    96 // WebResource ------------------------------------------------------------------
       
    97 
       
    98 HRESULT STDMETHODCALLTYPE WebResource::initWithData( 
       
    99     /* [in] */ IStream *data,
       
   100     /* [in] */ BSTR url,
       
   101     /* [in] */ BSTR mimeType,
       
   102     /* [in] */ BSTR textEncodingName,
       
   103     /* [in] */ BSTR frameName)
       
   104 {
       
   105     m_data = data;
       
   106     m_url = KURL(String(url).deprecatedString());
       
   107     m_mimeType = String(mimeType);
       
   108     m_textEncodingName = String(textEncodingName);
       
   109     m_frameName = String(frameName);
       
   110 
       
   111     return S_OK;
       
   112 }
       
   113 
       
   114     
       
   115 HRESULT STDMETHODCALLTYPE WebResource::data( 
       
   116     /* [retval][out] */ IStream **data)
       
   117 {
       
   118     return m_data.copyRefTo(data);
       
   119 }
       
   120    
       
   121 HRESULT STDMETHODCALLTYPE WebResource::URL( 
       
   122     /* [retval][out] */ BSTR *url)
       
   123 {
       
   124     if (!url) {
       
   125         ASSERT_NOT_REACHED();
       
   126         return E_POINTER;
       
   127     }
       
   128 
       
   129     *url = BString(String(m_url.url())).release();
       
   130     return S_OK;
       
   131 }
       
   132     
       
   133 HRESULT STDMETHODCALLTYPE WebResource::MIMEType( 
       
   134     /* [retval][out] */ BSTR *mime)
       
   135 {
       
   136     if (!mime) {
       
   137         ASSERT_NOT_REACHED();
       
   138         return E_POINTER;
       
   139     }
       
   140 
       
   141     *mime = BString(m_mimeType).release();
       
   142     return S_OK;
       
   143 }
       
   144    
       
   145 HRESULT STDMETHODCALLTYPE WebResource::textEncodingName( 
       
   146     /* [retval][out] */ BSTR *encodingName)
       
   147 {
       
   148     if (!encodingName) {
       
   149         ASSERT_NOT_REACHED();
       
   150         return E_POINTER;
       
   151     }
       
   152 
       
   153     *encodingName = BString(m_textEncodingName).release();
       
   154     return S_OK;
       
   155 }
       
   156     
       
   157 HRESULT STDMETHODCALLTYPE WebResource::frameName( 
       
   158     /* [retval][out] */ BSTR *name)
       
   159 {
       
   160     if (!name) {
       
   161         ASSERT_NOT_REACHED();
       
   162         return E_POINTER;
       
   163     }
       
   164 
       
   165     *name = BString(m_frameName).release();
       
   166     return S_OK;
       
   167 }