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 "WebHTMLRepresentation.h"
32 #include "WebKitStatisticsPrivate.h"
33 #pragma warning(push, 0)
34 #include <WebCore/BString.h>
35 #include <WebCore/HTMLInputElement.h>
36 #include <WebCore/TextResourceDecoder.h>
39 using namespace WebCore;
41 // WebHTMLRepresentation ------------------------------------------------------
43 WebHTMLRepresentation::WebHTMLRepresentation()
47 WebHTMLRepresentationCount++;
51 WebHTMLRepresentation::~WebHTMLRepresentation()
58 WebHTMLRepresentationCount--;
62 WebHTMLRepresentation* WebHTMLRepresentation::createInstance(WebFrame* frame)
64 WebHTMLRepresentation* instance = new WebHTMLRepresentation();
65 instance->m_frame = frame;
71 // IUnknown -------------------------------------------------------------------
73 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::QueryInterface(REFIID riid, void** ppvObject)
76 if (IsEqualGUID(riid, IID_IUnknown))
77 *ppvObject = static_cast<IWebHTMLRepresentation*>(this);
78 else if (IsEqualGUID(riid, IID_IWebHTMLRepresentation))
79 *ppvObject = static_cast<IWebHTMLRepresentation*>(this);
80 else if (IsEqualGUID(riid, IID_IWebDocumentRepresentation))
81 *ppvObject = static_cast<IWebDocumentRepresentation*>(this);
89 ULONG STDMETHODCALLTYPE WebHTMLRepresentation::AddRef()
94 ULONG STDMETHODCALLTYPE WebHTMLRepresentation::Release()
96 ULONG newRef = --m_refCount;
103 // IWebHTMLRepresentation --------------------------------------------------------------------
105 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::supportedMIMETypes(
106 /* [out][in] */ BSTR* /*types*/,
107 /* [out][in] */ int* /*cTypes*/)
109 ASSERT_NOT_REACHED();
113 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::supportedNonImageMIMETypes(
114 /* [out][in] */ BSTR* /*types*/,
115 /* [out][in] */ int* /*cTypes*/)
117 ASSERT_NOT_REACHED();
121 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::supportedImageMIMETypes(
122 /* [out][in] */ BSTR* /*types*/,
123 /* [out][in] */ int* /*cTypes*/)
125 ASSERT_NOT_REACHED();
129 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::attributedStringFromDOMNodes(
130 /* [in] */ IDOMNode* /*startNode*/,
131 /* [in] */ int /*startOffset*/,
132 /* [in] */ IDOMNode* /*endNode*/,
133 /* [in] */ int /*endOffset*/,
134 /* [retval][out] */ IDataObject** /*attributedString*/)
136 ASSERT_NOT_REACHED();
140 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::elementWithName(
141 /* [in] */ BSTR name,
142 /* [in] */ IDOMElement* form,
143 /* [retval][out] */ IDOMElement** element)
148 return m_frame->elementWithName(name, form, element);
151 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::elementDoesAutoComplete(
152 /* [in] */ IDOMElement* element,
153 /* [retval][out] */ BOOL* result)
155 bool doesAutoComplete;
156 HRESULT hr = m_frame->elementDoesAutoComplete(element, &doesAutoComplete);
157 *result = doesAutoComplete ? TRUE : FALSE;
161 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::elementIsPassword(
162 /* [in] */ IDOMElement* element,
163 /* [retval][out] */ BOOL* result)
166 HRESULT hr = m_frame->elementIsPassword(element, &isPassword);
167 *result = isPassword ? TRUE : FALSE;
171 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::formForElement(
172 /* [in] */ IDOMElement* element,
173 /* [retval][out] */ IDOMElement** form)
178 return m_frame->formForElement(element, form);
181 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::currentForm(
182 /* [retval][out] */ IDOMElement** form)
187 return m_frame->currentForm(form);
190 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::controlsInForm(
191 /* [in] */ IDOMElement* form,
192 /* [out][in] */ IDOMElement** controls,
193 /* [out][in] */ int* cControls)
195 return m_frame->controlsInForm(form, controls, cControls);
198 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::searchForLabels(
199 /* [size_is][in] */ BSTR* labels,
200 /* [in] */ int cLabels,
201 /* [in] */ IDOMElement* beforeElement,
202 /* [retval][out] */ BSTR* result)
204 return m_frame->searchForLabelsBeforeElement(labels, cLabels, beforeElement, result);
207 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::matchLabels(
208 /* [size_is][in] */ BSTR* labels,
209 /* [in] */ int cLabels,
210 /* [in] */ IDOMElement* againstElement,
211 /* [retval][out] */ BSTR* result)
213 return m_frame->matchLabelsAgainstElement(labels, cLabels, againstElement, result);
216 // IWebDocumentRepresentation ----------------------------------------------------------------
218 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::setDataSource(
219 /* [in] */ IWebDataSource* /*dataSource*/)
221 ASSERT_NOT_REACHED();
225 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::receivedData(
226 /* [in] */ IStream* /*data*/,
227 /* [in] */ IWebDataSource* /*dataSource*/)
229 ASSERT_NOT_REACHED();
233 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::receivedError(
234 /* [in] */ IWebError* /*error*/,
235 /* [in] */ IWebDataSource* /*dataSource*/)
237 ASSERT_NOT_REACHED();
241 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::finishedLoadingWithDataSource(
242 /* [in] */ IWebDataSource* /*dataSource*/)
244 ASSERT_NOT_REACHED();
248 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::canProvideDocumentSource(
249 /* [retval][out] */ BOOL* result)
251 bool canProvideSource;
252 HRESULT hr = this->m_frame->canProvideDocumentSource(&canProvideSource);
253 *result = canProvideSource ? TRUE : FALSE;
257 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::documentSource(
258 /* [retval][out] */ BSTR* source)
267 COMPtr<IWebDataSource> dataSource;
268 hr = m_frame->dataSource(&dataSource);
272 COMPtr<IStream> data;
273 hr = dataSource->data(&data);
278 hr = data->Stat(&stat, STATFLAG_NONAME);
282 if (stat.cbSize.HighPart || !stat.cbSize.LowPart)
285 Vector<char> dataBuffer(stat.cbSize.LowPart);
288 hr = data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read);
292 WebCore::Frame* frame = core(m_frame);
296 WebCore::Document* doc = frame->document();
300 WebCore::TextResourceDecoder* decoder = doc->decoder();
304 *source = WebCore::BString(decoder->encoding().decode(dataBuffer.data(), dataBuffer.size())).release();
308 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::title(
309 /* [retval][out] */ BSTR* /*docTitle*/)
311 ASSERT_NOT_REACHED();