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 #include <WebCore/BString.h>
34 #include <WebCore/Frame.h>
35 #include <WebCore/HTMLInputElement.h>
36 #include <WebCore/TextResourceDecoder.h>
38 using namespace WebCore;
40 // WebHTMLRepresentation ------------------------------------------------------
42 WebHTMLRepresentation::WebHTMLRepresentation()
46 WebHTMLRepresentationCount++;
48 gClassNameCount.add("WebHTMLRepresentation");
51 WebHTMLRepresentation::~WebHTMLRepresentation()
58 WebHTMLRepresentationCount--;
60 gClassNameCount.remove("WebHTMLRepresentation");
63 WebHTMLRepresentation* WebHTMLRepresentation::createInstance(WebFrame* frame)
65 WebHTMLRepresentation* instance = new WebHTMLRepresentation();
66 instance->m_frame = frame;
72 // IUnknown -------------------------------------------------------------------
74 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::QueryInterface(REFIID riid, void** ppvObject)
77 if (IsEqualGUID(riid, IID_IUnknown))
78 *ppvObject = static_cast<IWebHTMLRepresentation*>(this);
79 else if (IsEqualGUID(riid, IID_IWebHTMLRepresentation))
80 *ppvObject = static_cast<IWebHTMLRepresentation*>(this);
81 else if (IsEqualGUID(riid, IID_IWebDocumentRepresentation))
82 *ppvObject = static_cast<IWebDocumentRepresentation*>(this);
90 ULONG STDMETHODCALLTYPE WebHTMLRepresentation::AddRef()
95 ULONG STDMETHODCALLTYPE WebHTMLRepresentation::Release()
97 ULONG newRef = --m_refCount;
104 // IWebHTMLRepresentation --------------------------------------------------------------------
106 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::supportedMIMETypes(
107 /* [out][in] */ BSTR* /*types*/,
108 /* [out][in] */ int* /*cTypes*/)
110 ASSERT_NOT_REACHED();
114 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::supportedNonImageMIMETypes(
115 /* [out][in] */ BSTR* /*types*/,
116 /* [out][in] */ int* /*cTypes*/)
118 ASSERT_NOT_REACHED();
122 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::supportedImageMIMETypes(
123 /* [out][in] */ BSTR* /*types*/,
124 /* [out][in] */ int* /*cTypes*/)
126 ASSERT_NOT_REACHED();
130 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::attributedStringFromDOMNodes(
131 /* [in] */ IDOMNode* /*startNode*/,
132 /* [in] */ int /*startOffset*/,
133 /* [in] */ IDOMNode* /*endNode*/,
134 /* [in] */ int /*endOffset*/,
135 /* [retval][out] */ IDataObject** /*attributedString*/)
137 ASSERT_NOT_REACHED();
141 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::elementWithName(
142 /* [in] */ BSTR name,
143 /* [in] */ IDOMElement* form,
144 /* [retval][out] */ IDOMElement** element)
149 return m_frame->elementWithName(name, form, element);
152 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::elementDoesAutoComplete(
153 /* [in] */ IDOMElement* element,
154 /* [retval][out] */ BOOL* result)
156 BOOL doesAutoComplete;
157 HRESULT hr = m_frame->elementDoesAutoComplete(element, &doesAutoComplete);
158 *result = doesAutoComplete ? TRUE : FALSE;
162 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::elementIsPassword(
163 /* [in] */ IDOMElement* element,
164 /* [retval][out] */ BOOL* result)
167 HRESULT hr = m_frame->elementIsPassword(element, &isPassword);
168 *result = isPassword ? TRUE : FALSE;
172 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::formForElement(
173 /* [in] */ IDOMElement* element,
174 /* [retval][out] */ IDOMElement** form)
179 return m_frame->formForElement(element, form);
182 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::currentForm(
183 /* [retval][out] */ IDOMElement** form)
188 return m_frame->currentForm(form);
191 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::controlsInForm(
192 /* [in] */ IDOMElement* form,
193 /* [out][in] */ IDOMElement** controls,
194 /* [out][in] */ int* cControls)
196 return m_frame->controlsInForm(form, controls, cControls);
199 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::deprecatedSearchForLabels(
200 /* [size_is][in] */ BSTR* labels,
201 /* [in] */ int cLabels,
202 /* [in] */ IDOMElement* beforeElement,
203 /* [retval][out] */ BSTR* result)
205 return m_frame->searchForLabelsBeforeElement(labels, cLabels, beforeElement, 0, 0, result);
208 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::matchLabels(
209 /* [size_is][in] */ BSTR* labels,
210 /* [in] */ int cLabels,
211 /* [in] */ IDOMElement* againstElement,
212 /* [retval][out] */ BSTR* result)
214 return m_frame->matchLabelsAgainstElement(labels, cLabels, againstElement, result);
217 HRESULT WebHTMLRepresentation::searchForLabels(BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* resultDistance, BOOL* resultIsInCellAbove, BSTR* result)
219 return m_frame->searchForLabelsBeforeElement(labels, cLabels, beforeElement, resultDistance, resultIsInCellAbove, result);
222 // IWebDocumentRepresentation ----------------------------------------------------------------
224 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::setDataSource(
225 /* [in] */ IWebDataSource* /*dataSource*/)
227 ASSERT_NOT_REACHED();
231 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::receivedData(
232 /* [in] */ IStream* /*data*/,
233 /* [in] */ IWebDataSource* /*dataSource*/)
235 ASSERT_NOT_REACHED();
239 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::receivedError(
240 /* [in] */ IWebError* /*error*/,
241 /* [in] */ IWebDataSource* /*dataSource*/)
243 ASSERT_NOT_REACHED();
247 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::finishedLoadingWithDataSource(
248 /* [in] */ IWebDataSource* /*dataSource*/)
250 ASSERT_NOT_REACHED();
254 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::canProvideDocumentSource(
255 /* [retval][out] */ BOOL* result)
257 bool canProvideSource;
258 HRESULT hr = this->m_frame->canProvideDocumentSource(&canProvideSource);
259 *result = canProvideSource ? TRUE : FALSE;
263 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::documentSource(
264 /* [retval][out] */ BSTR* source)
273 COMPtr<IWebDataSource> dataSource;
274 hr = m_frame->dataSource(&dataSource);
278 COMPtr<IStream> data;
279 hr = dataSource->data(&data);
284 hr = data->Stat(&stat, STATFLAG_NONAME);
288 if (stat.cbSize.HighPart || !stat.cbSize.LowPart)
291 Vector<char> dataBuffer(stat.cbSize.LowPart);
294 hr = data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read);
298 WebCore::Frame* frame = core(m_frame);
302 WebCore::Document* doc = frame->document();
306 WebCore::TextResourceDecoder* decoder = doc->decoder();
310 *source = WebCore::BString(decoder->encoding().decode(dataBuffer.data(), dataBuffer.size())).release();
314 HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::title(
315 /* [retval][out] */ BSTR* /*docTitle*/)
317 ASSERT_NOT_REACHED();