2 * Copyright (C) 2008 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 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 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 "WebArchive.h"
30 #include "DOMCoreClasses.h"
31 #include "MemoryStream.h"
32 #include <WebCore/LegacyWebArchive.h>
34 using namespace WebCore;
36 // WebArchive ----------------------------------------------------------------
38 WebArchive* WebArchive::createInstance()
40 WebArchive* instance = new WebArchive(0);
45 WebArchive* WebArchive::createInstance(PassRefPtr<LegacyWebArchive> coreArchive)
47 WebArchive* instance = new WebArchive(coreArchive);
53 WebArchive::WebArchive(PassRefPtr<LegacyWebArchive> coreArchive)
55 , m_archive(coreArchive)
58 gClassNameCount.add("WebArchive");
61 WebArchive::~WebArchive()
64 gClassNameCount.remove("WebArchive");
67 HRESULT STDMETHODCALLTYPE WebArchive::QueryInterface(REFIID riid, void** ppvObject)
70 if (IsEqualGUID(riid, IID_IUnknown))
71 *ppvObject = static_cast<IWebArchive*>(this);
72 else if (IsEqualGUID(riid, __uuidof(IWebArchive)))
73 *ppvObject = static_cast<IWebArchive*>(this);
81 ULONG STDMETHODCALLTYPE WebArchive::AddRef()
86 ULONG STDMETHODCALLTYPE WebArchive::Release()
88 ULONG newRef = --m_refCount;
95 HRESULT STDMETHODCALLTYPE WebArchive::initWithMainResource(
96 /* [in] */ IWebResource*,
97 /* [in, size_is(cSubResources)] */ IWebResource**,
99 /* in, size_is(cSubFrameArchives)] */ IWebArchive**,
105 HRESULT STDMETHODCALLTYPE WebArchive::initWithData(
111 HRESULT STDMETHODCALLTYPE WebArchive::initWithNode(
112 /* [in] */ IDOMNode* node)
117 COMPtr<DOMNode> domNode(Query, node);
119 return E_NOINTERFACE;
121 m_archive = LegacyWebArchive::create(domNode->node());
126 HRESULT STDMETHODCALLTYPE WebArchive::mainResource(
127 /* [out, retval] */ IWebResource**)
132 HRESULT STDMETHODCALLTYPE WebArchive::subResources(
133 /* [out, retval] */ IEnumVARIANT**)
138 HRESULT STDMETHODCALLTYPE WebArchive::subframeArchives(
139 /* [out, retval] */ IEnumVARIANT**)
144 HRESULT STDMETHODCALLTYPE WebArchive::data(
145 /* [out, retval] */ IStream** stream)
147 RetainPtr<CFDataRef> cfData = m_archive->rawDataRepresentation();
151 RefPtr<SharedBuffer> buffer = SharedBuffer::create(CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()));
153 return MemoryStream::createInstance(buffer).copyRefTo(stream);