urlmon: Recognize <body> tag in FindMimeFromData function.
[wine/multimedia.git] / dlls / mshtml / htmllink.c
blobb5ae29a5e68d1c6a8d6b616780182216f565d878
1 /*
2 * Copyright 2012 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 HTMLElement element;
37 IHTMLLinkElement IHTMLLinkElement_iface;
39 nsIDOMHTMLLinkElement *nslink;
40 } HTMLLinkElement;
42 static inline HTMLLinkElement *impl_from_IHTMLLinkElement(IHTMLLinkElement *iface)
44 return CONTAINING_RECORD(iface, HTMLLinkElement, IHTMLLinkElement_iface);
47 static HRESULT WINAPI HTMLLinkElement_QueryInterface(IHTMLLinkElement *iface,
48 REFIID riid, void **ppv)
50 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
52 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 static ULONG WINAPI HTMLLinkElement_AddRef(IHTMLLinkElement *iface)
57 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLLinkElement_Release(IHTMLLinkElement *iface)
64 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
66 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 static HRESULT WINAPI HTMLLinkElement_GetTypeInfoCount(IHTMLLinkElement *iface, UINT *pctinfo)
71 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
73 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
76 static HRESULT WINAPI HTMLLinkElement_GetTypeInfo(IHTMLLinkElement *iface, UINT iTInfo,
77 LCID lcid, ITypeInfo **ppTInfo)
79 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
81 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
82 ppTInfo);
85 static HRESULT WINAPI HTMLLinkElement_GetIDsOfNames(IHTMLLinkElement *iface, REFIID riid,
86 LPOLESTR *rgszNames, UINT cNames,
87 LCID lcid, DISPID *rgDispId)
89 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
91 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
92 cNames, lcid, rgDispId);
95 static HRESULT WINAPI HTMLLinkElement_Invoke(IHTMLLinkElement *iface, DISPID dispIdMember,
96 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
97 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
99 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
101 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
102 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
105 static HRESULT WINAPI HTMLLinkElement_put_href(IHTMLLinkElement *iface, BSTR v)
107 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
108 nsAString href_str;
109 nsresult nsres;
111 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
113 nsAString_InitDepend(&href_str, v);
114 nsres = nsIDOMHTMLLinkElement_SetHref(This->nslink, &href_str);
115 nsAString_Finish(&href_str);
117 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
120 static HRESULT WINAPI HTMLLinkElement_get_href(IHTMLLinkElement *iface, BSTR *p)
122 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
123 nsAString href_str;
124 nsresult nsres;
126 TRACE("(%p)->(%p)\n", This, p);
128 nsAString_Init(&href_str, NULL);
129 nsres = nsIDOMHTMLLinkElement_GetHref(This->nslink, &href_str);
130 return return_nsstr(nsres, &href_str, p);
133 static HRESULT WINAPI HTMLLinkElement_put_rel(IHTMLLinkElement *iface, BSTR v)
135 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
136 nsAString rel_str;
137 nsresult nsres;
139 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
141 nsAString_InitDepend(&rel_str, v);
142 nsres = nsIDOMHTMLLinkElement_SetRel(This->nslink, &rel_str);
143 nsAString_Finish(&rel_str);
145 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
148 static HRESULT WINAPI HTMLLinkElement_get_rel(IHTMLLinkElement *iface, BSTR *p)
150 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
151 nsAString rel_str;
152 nsresult nsres;
154 TRACE("(%p)->(%p)\n", This, p);
156 nsAString_Init(&rel_str, NULL);
157 nsres = nsIDOMHTMLLinkElement_GetRel(This->nslink, &rel_str);
158 return return_nsstr(nsres, &rel_str, p);
161 static HRESULT WINAPI HTMLLinkElement_put_rev(IHTMLLinkElement *iface, BSTR v)
163 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
164 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
165 return E_NOTIMPL;
168 static HRESULT WINAPI HTMLLinkElement_get_rev(IHTMLLinkElement *iface, BSTR *p)
170 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
171 FIXME("(%p)->(%p)\n", This, p);
172 return E_NOTIMPL;
175 static HRESULT WINAPI HTMLLinkElement_put_type(IHTMLLinkElement *iface, BSTR v)
177 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
178 nsAString type_str;
179 nsresult nsres;
181 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
183 nsAString_InitDepend(&type_str, v);
184 nsres = nsIDOMHTMLLinkElement_SetType(This->nslink, &type_str);
185 nsAString_Finish(&type_str);
187 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
190 static HRESULT WINAPI HTMLLinkElement_get_type(IHTMLLinkElement *iface, BSTR *p)
192 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
193 nsAString type_str;
194 nsresult nsres;
196 TRACE("(%p)->(%p)\n", This, p);
198 nsAString_Init(&type_str, NULL);
199 nsres = nsIDOMHTMLLinkElement_GetType(This->nslink, &type_str);
200 return return_nsstr(nsres, &type_str, p);
203 static HRESULT WINAPI HTMLLinkElement_get_readyState(IHTMLLinkElement *iface, BSTR *p)
205 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
206 FIXME("(%p)->(%p)\n", This, p);
207 return E_NOTIMPL;
210 static HRESULT WINAPI HTMLLinkElement_put_onreadystatechange(IHTMLLinkElement *iface, VARIANT v)
212 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
213 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
214 return E_NOTIMPL;
217 static HRESULT WINAPI HTMLLinkElement_get_onreadystatechange(IHTMLLinkElement *iface, VARIANT *p)
219 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
220 FIXME("(%p)->(%p)\n", This, p);
221 return E_NOTIMPL;
224 static HRESULT WINAPI HTMLLinkElement_put_onload(IHTMLLinkElement *iface, VARIANT v)
226 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
227 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
228 return E_NOTIMPL;
231 static HRESULT WINAPI HTMLLinkElement_get_onload(IHTMLLinkElement *iface, VARIANT *p)
233 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
234 FIXME("(%p)->(%p)\n", This, p);
235 return E_NOTIMPL;
238 static HRESULT WINAPI HTMLLinkElement_put_onerror(IHTMLLinkElement *iface, VARIANT v)
240 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
241 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
242 return E_NOTIMPL;
245 static HRESULT WINAPI HTMLLinkElement_get_onerror(IHTMLLinkElement *iface, VARIANT *p)
247 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
248 FIXME("(%p)->(%p)\n", This, p);
249 return E_NOTIMPL;
252 static HRESULT WINAPI HTMLLinkElement_get_styleSheet(IHTMLLinkElement *iface, IHTMLStyleSheet **p)
254 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
255 FIXME("(%p)->(%p)\n", This, p);
256 return E_NOTIMPL;
259 static HRESULT WINAPI HTMLLinkElement_put_disabled(IHTMLLinkElement *iface, VARIANT_BOOL v)
261 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
262 nsresult nsres;
264 TRACE("(%p)->(%x)\n", This, v);
266 nsres = nsIDOMHTMLLinkElement_SetDisabled(This->nslink, !!v);
267 return SUCCEEDED(nsres) ? S_OK : E_FAIL;
270 static HRESULT WINAPI HTMLLinkElement_get_disabled(IHTMLLinkElement *iface, VARIANT_BOOL *p)
272 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
273 cpp_bool ret;
274 nsresult nsres;
276 TRACE("(%p)->(%p)\n", This, p);
278 nsres = nsIDOMHTMLLinkElement_GetDisabled(This->nslink, &ret);
279 if(NS_FAILED(nsres))
280 return E_FAIL;
282 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
283 return S_OK;
286 static HRESULT WINAPI HTMLLinkElement_put_media(IHTMLLinkElement *iface, BSTR v)
288 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
289 nsresult nsres;
290 nsAString str;
292 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
294 nsAString_InitDepend(&str, v);
296 nsres = nsIDOMHTMLLinkElement_SetMedia(This->nslink, &str);
297 nsAString_Finish(&str);
299 if(NS_FAILED(nsres)) {
300 ERR("Set Media(%s) failed: %08x\n", debugstr_w(v), nsres);
301 return E_FAIL;
303 return S_OK;
306 static HRESULT WINAPI HTMLLinkElement_get_media(IHTMLLinkElement *iface, BSTR *p)
308 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
309 nsresult nsres;
310 nsAString str;
312 TRACE("(%p)->(%p)\n", This, p);
314 nsAString_Init(&str, NULL);
315 nsres = nsIDOMHTMLLinkElement_GetMedia(This->nslink, &str);
317 return return_nsstr(nsres, &str, p);
320 static const IHTMLLinkElementVtbl HTMLLinkElementVtbl = {
321 HTMLLinkElement_QueryInterface,
322 HTMLLinkElement_AddRef,
323 HTMLLinkElement_Release,
324 HTMLLinkElement_GetTypeInfoCount,
325 HTMLLinkElement_GetTypeInfo,
326 HTMLLinkElement_GetIDsOfNames,
327 HTMLLinkElement_Invoke,
328 HTMLLinkElement_put_href,
329 HTMLLinkElement_get_href,
330 HTMLLinkElement_put_rel,
331 HTMLLinkElement_get_rel,
332 HTMLLinkElement_put_rev,
333 HTMLLinkElement_get_rev,
334 HTMLLinkElement_put_type,
335 HTMLLinkElement_get_type,
336 HTMLLinkElement_get_readyState,
337 HTMLLinkElement_put_onreadystatechange,
338 HTMLLinkElement_get_onreadystatechange,
339 HTMLLinkElement_put_onload,
340 HTMLLinkElement_get_onload,
341 HTMLLinkElement_put_onerror,
342 HTMLLinkElement_get_onerror,
343 HTMLLinkElement_get_styleSheet,
344 HTMLLinkElement_put_disabled,
345 HTMLLinkElement_get_disabled,
346 HTMLLinkElement_put_media,
347 HTMLLinkElement_get_media
350 static inline HTMLLinkElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
352 return CONTAINING_RECORD(iface, HTMLLinkElement, element.node);
355 static HRESULT HTMLLinkElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
357 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
359 if(IsEqualGUID(&IID_IHTMLLinkElement, riid)) {
360 TRACE("(%p)->(IID_IHTMLLinkElement %p)\n", This, ppv);
361 *ppv = &This->IHTMLLinkElement_iface;
362 }else {
363 return HTMLElement_QI(&This->element.node, riid, ppv);
366 IUnknown_AddRef((IUnknown*)*ppv);
367 return S_OK;
370 static HRESULT HTMLLinkElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
372 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
373 return IHTMLLinkElement_put_disabled(&This->IHTMLLinkElement_iface, v);
376 static HRESULT HTMLLinkElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
378 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
379 return IHTMLLinkElement_get_disabled(&This->IHTMLLinkElement_iface, p);
382 static const NodeImplVtbl HTMLLinkElementImplVtbl = {
383 HTMLLinkElement_QI,
384 HTMLElement_destructor,
385 HTMLElement_cpc,
386 HTMLElement_clone,
387 HTMLElement_handle_event,
388 HTMLElement_get_attr_col,
389 NULL,
390 NULL,
391 HTMLLinkElementImpl_put_disabled,
392 HTMLLinkElementImpl_get_disabled,
395 static const tid_t HTMLLinkElement_iface_tids[] = {
396 HTMLELEMENT_TIDS,
397 IHTMLLinkElement_tid,
400 static dispex_static_data_t HTMLLinkElement_dispex = {
401 NULL,
402 DispHTMLLinkElement_tid,
403 NULL,
404 HTMLLinkElement_iface_tids
407 HRESULT HTMLLinkElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
409 HTMLLinkElement *ret;
410 nsresult nsres;
412 ret = heap_alloc_zero(sizeof(*ret));
413 if(!ret)
414 return E_OUTOFMEMORY;
416 ret->IHTMLLinkElement_iface.lpVtbl = &HTMLLinkElementVtbl;
417 ret->element.node.vtbl = &HTMLLinkElementImplVtbl;
419 HTMLElement_Init(&ret->element, doc, nselem, &HTMLLinkElement_dispex);
421 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLLinkElement, (void**)&ret->nslink);
423 /* Share nslink reference with nsnode */
424 assert(nsres == NS_OK && (nsIDOMNode*)ret->nslink == ret->element.node.nsnode);
425 nsIDOMNode_Release(ret->element.node.nsnode);
427 *elem = &ret->element;
428 return S_OK;