2 * Copyright (C) 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 "WebResource.h"
30 #include "MarshallingHelpers.h"
31 #include "MemoryStream.h"
32 #include <WebCore/BString.h>
34 using namespace WebCore;
36 // WebResource ---------------------------------------------------------------------
38 WebResource::WebResource(IStream* data, const WebCore::KURL& url, const WTF::String& mimeType, const WTF::String& textEncodingName, const WTF::String& frameName)
42 , m_mimeType(mimeType)
43 , m_textEncodingName(textEncodingName)
44 , m_frameName(frameName)
47 gClassNameCount.add("WebResource");
50 WebResource::~WebResource()
53 gClassNameCount.remove("WebResource");
56 WebResource* WebResource::createInstance(PassRefPtr<WebCore::SharedBuffer> data, const WebCore::ResourceResponse& response)
58 COMPtr<MemoryStream> memoryStream = MemoryStream::createInstance(data);
60 WebResource* instance = new WebResource(memoryStream.get(), response.url(), response.mimeType(), response.textEncodingName(), String());
65 // IUnknown -------------------------------------------------------------------
67 HRESULT STDMETHODCALLTYPE WebResource::QueryInterface(REFIID riid, void** ppvObject)
70 if (IsEqualGUID(riid, IID_IUnknown))
71 *ppvObject = static_cast<IUnknown*>(this);
72 else if (IsEqualGUID(riid, IID_IWebResource))
73 *ppvObject = static_cast<IWebResource*>(this);
81 ULONG STDMETHODCALLTYPE WebResource::AddRef(void)
86 ULONG STDMETHODCALLTYPE WebResource::Release(void)
88 ULONG newRef = --m_refCount;
95 // WebResource ------------------------------------------------------------------
97 HRESULT STDMETHODCALLTYPE WebResource::initWithData(
98 /* [in] */ IStream *data,
100 /* [in] */ BSTR mimeType,
101 /* [in] */ BSTR textEncodingName,
102 /* [in] */ BSTR frameName)
105 m_url = MarshallingHelpers::BSTRToKURL(url);
106 m_mimeType = String(mimeType);
107 m_textEncodingName = String(textEncodingName);
108 m_frameName = String(frameName);
114 HRESULT STDMETHODCALLTYPE WebResource::data(
115 /* [retval][out] */ IStream **data)
117 return m_data.copyRefTo(data);
120 HRESULT STDMETHODCALLTYPE WebResource::URL(
121 /* [retval][out] */ BSTR *url)
124 ASSERT_NOT_REACHED();
128 *url = BString(String(m_url.string())).release();
132 HRESULT STDMETHODCALLTYPE WebResource::MIMEType(
133 /* [retval][out] */ BSTR *mime)
136 ASSERT_NOT_REACHED();
140 *mime = BString(m_mimeType).release();
144 HRESULT STDMETHODCALLTYPE WebResource::textEncodingName(
145 /* [retval][out] */ BSTR *encodingName)
148 ASSERT_NOT_REACHED();
152 *encodingName = BString(m_textEncodingName).release();
156 HRESULT STDMETHODCALLTYPE WebResource::frameName(
157 /* [retval][out] */ BSTR *name)
160 ASSERT_NOT_REACHED();
164 *name = BString(m_frameName).release();