crypt32: NULL ptr could leak into function (Coverity).
[wine] / dlls / mshtml / htmlstyleelem.c
1 /*
2  * Copyright 2010 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "ole2.h"
28
29 #include "wine/debug.h"
30
31 #include "mshtml_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 typedef struct {
36     HTMLElement element;
37
38     const IHTMLStyleElementVtbl *lpIHTMLStyleElementVtbl;
39
40     nsIDOMHTMLStyleElement *nsstyle;
41 } HTMLStyleElement;
42
43 #define HTMLSTYLE(x)  (&(x)->lpIHTMLStyleElementVtbl)
44
45 #define HTMLSTYLE_THIS(iface) DEFINE_THIS(HTMLStyleElement, IHTMLStyleElement, iface)
46
47 static HRESULT WINAPI HTMLStyleElement_QueryInterface(IHTMLStyleElement *iface,
48         REFIID riid, void **ppv)
49 {
50     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
51
52     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
53 }
54
55 static ULONG WINAPI HTMLStyleElement_AddRef(IHTMLStyleElement *iface)
56 {
57     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
58
59     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
60 }
61
62 static ULONG WINAPI HTMLStyleElement_Release(IHTMLStyleElement *iface)
63 {
64     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
65
66     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
67 }
68
69 static HRESULT WINAPI HTMLStyleElement_GetTypeInfoCount(IHTMLStyleElement *iface, UINT *pctinfo)
70 {
71     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
72     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
73 }
74
75 static HRESULT WINAPI HTMLStyleElement_GetTypeInfo(IHTMLStyleElement *iface, UINT iTInfo,
76         LCID lcid, ITypeInfo **ppTInfo)
77 {
78     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
79     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
80             ppTInfo);
81 }
82
83 static HRESULT WINAPI HTMLStyleElement_GetIDsOfNames(IHTMLStyleElement *iface, REFIID riid,
84         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
85 {
86     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
87     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
88             cNames, lcid, rgDispId);
89 }
90
91 static HRESULT WINAPI HTMLStyleElement_Invoke(IHTMLStyleElement *iface, DISPID dispIdMember,
92         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
93         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
94 {
95     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
96     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
97             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
98 }
99
100 static HRESULT WINAPI HTMLStyleElement_put_type(IHTMLStyleElement *iface, BSTR v)
101 {
102     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
103     nsAString type_str;
104     nsresult nsres;
105
106     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
107
108     nsAString_InitDepend(&type_str, v);
109     nsres = nsIDOMHTMLStyleElement_SetType(This->nsstyle, &type_str);
110     nsAString_Finish(&type_str);
111     if(NS_FAILED(nsres)) {
112         ERR("SetType failed: %08x\n", nsres);
113         return E_FAIL;
114     }
115
116     return S_OK;
117 }
118
119 static HRESULT WINAPI HTMLStyleElement_get_type(IHTMLStyleElement *iface, BSTR *p)
120 {
121     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
122     nsAString nsstr;
123     nsresult nsres;
124
125     TRACE("(%p)->(%p)\n", This, p);
126
127     nsAString_Init(&nsstr, NULL);
128     nsres = nsIDOMHTMLStyleElement_GetType(This->nsstyle, &nsstr);
129     return return_nsstr(nsres, &nsstr, p);
130 }
131
132 static HRESULT WINAPI HTMLStyleElement_get_readyState(IHTMLStyleElement *iface, BSTR *p)
133 {
134     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
135     FIXME("(%p)->(%p)\n", This, p);
136     return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI HTMLStyleElement_put_onreadystatechange(IHTMLStyleElement *iface, VARIANT v)
140 {
141     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
142     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
143     return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI HTMLStyleElement_get_onreadystatechange(IHTMLStyleElement *iface, VARIANT *p)
147 {
148     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
149     FIXME("(%p)->(%p)\n", This, p);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI HTMLStyleElement_put_onload(IHTMLStyleElement *iface, VARIANT v)
154 {
155     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
156     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI HTMLStyleElement_get_onload(IHTMLStyleElement *iface, VARIANT *p)
161 {
162     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
163     FIXME("(%p)->(%p)\n", This, p);
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI HTMLStyleElement_put_onerror(IHTMLStyleElement *iface, VARIANT v)
168 {
169     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
170     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
171     return E_NOTIMPL;
172 }
173
174 static HRESULT WINAPI HTMLStyleElement_get_onerror(IHTMLStyleElement *iface, VARIANT *p)
175 {
176     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
177     FIXME("(%p)->(%p)\n", This, p);
178     return E_NOTIMPL;
179 }
180
181 static HRESULT WINAPI HTMLStyleElement_get_styleSheet(IHTMLStyleElement *iface, IHTMLStyleSheet **p)
182 {
183     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
184     FIXME("(%p)->(%p)\n", This, p);
185     return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI HTMLStyleElement_put_disabled(IHTMLStyleElement *iface, VARIANT_BOOL v)
189 {
190     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
191     FIXME("(%p)->(%x)\n", This, v);
192     return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI HTMLStyleElement_get_disabled(IHTMLStyleElement *iface, VARIANT_BOOL *p)
196 {
197     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
198     FIXME("(%p)->(%p)\n", This, p);
199     return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI HTMLStyleElement_put_media(IHTMLStyleElement *iface, BSTR v)
203 {
204     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
205     nsAString media_str;
206     nsresult nsres;
207
208     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
209
210     nsAString_InitDepend(&media_str, v);
211     nsres = nsIDOMHTMLStyleElement_SetMedia(This->nsstyle, &media_str);
212     nsAString_Finish(&media_str);
213     if(NS_FAILED(nsres)) {
214         ERR("SetMedia failed: %08x\n", nsres);
215         return E_FAIL;
216     }
217
218     return S_OK;
219 }
220
221 static HRESULT WINAPI HTMLStyleElement_get_media(IHTMLStyleElement *iface, BSTR *p)
222 {
223     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
224     nsAString nsstr;
225     nsresult nsres;
226
227     TRACE("(%p)->(%p)\n", This, p);
228
229     nsAString_Init(&nsstr, NULL);
230     nsres = nsIDOMHTMLStyleElement_GetMedia(This->nsstyle, &nsstr);
231     return return_nsstr(nsres, &nsstr, p);
232 }
233
234 #undef HTMLSTYLE_THIS
235
236 static const IHTMLStyleElementVtbl HTMLStyleElementVtbl = {
237     HTMLStyleElement_QueryInterface,
238     HTMLStyleElement_AddRef,
239     HTMLStyleElement_Release,
240     HTMLStyleElement_GetTypeInfoCount,
241     HTMLStyleElement_GetTypeInfo,
242     HTMLStyleElement_GetIDsOfNames,
243     HTMLStyleElement_Invoke,
244     HTMLStyleElement_put_type,
245     HTMLStyleElement_get_type,
246     HTMLStyleElement_get_readyState,
247     HTMLStyleElement_put_onreadystatechange,
248     HTMLStyleElement_get_onreadystatechange,
249     HTMLStyleElement_put_onload,
250     HTMLStyleElement_get_onload,
251     HTMLStyleElement_put_onerror,
252     HTMLStyleElement_get_onerror,
253     HTMLStyleElement_get_styleSheet,
254     HTMLStyleElement_put_disabled,
255     HTMLStyleElement_get_disabled,
256     HTMLStyleElement_put_media,
257     HTMLStyleElement_get_media
258 };
259
260 static inline HTMLStyleElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
261 {
262     return CONTAINING_RECORD(iface, HTMLStyleElement, element.node);
263 }
264
265 static HRESULT HTMLStyleElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
266 {
267     HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);
268
269     if(IsEqualGUID(&IID_IUnknown, riid)) {
270         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
271         *ppv = HTMLSTYLE(This);
272     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
273         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
274         *ppv = HTMLSTYLE(This);
275     }else if(IsEqualGUID(&IID_IHTMLStyleElement, riid)) {
276         TRACE("(%p)->(IID_IHTMLStyleElement %p)\n", This, ppv);
277         *ppv = HTMLSTYLE(This);
278     }else {
279         return HTMLElement_QI(&This->element.node, riid, ppv);
280     }
281
282     IUnknown_AddRef((IUnknown*)*ppv);
283     return S_OK;
284 }
285
286 static void HTMLStyleElement_destructor(HTMLDOMNode *iface)
287 {
288     HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);
289
290     if(This->nsstyle)
291         nsIDOMHTMLStyleElement_Release(This->nsstyle);
292
293     HTMLElement_destructor(&This->element.node);
294 }
295
296 static const NodeImplVtbl HTMLStyleElementImplVtbl = {
297     HTMLStyleElement_QI,
298     HTMLStyleElement_destructor,
299     HTMLElement_clone
300 };
301
302 static const tid_t HTMLStyleElement_iface_tids[] = {
303     HTMLELEMENT_TIDS,
304     IHTMLStyleElement_tid,
305     0
306 };
307 static dispex_static_data_t HTMLStyleElement_dispex = {
308     NULL,
309     DispHTMLStyleElement_tid,
310     NULL,
311     HTMLStyleElement_iface_tids
312 };
313
314 HRESULT HTMLStyleElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
315 {
316     HTMLStyleElement *ret;
317     nsresult nsres;
318
319     ret = heap_alloc_zero(sizeof(*ret));
320     if(!ret)
321         return E_OUTOFMEMORY;
322
323     ret->lpIHTMLStyleElementVtbl = &HTMLStyleElementVtbl;
324     ret->element.node.vtbl = &HTMLStyleElementImplVtbl;
325
326     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLStyleElement, (void**)&ret->nsstyle);
327     if(NS_FAILED(nsres)) {
328         ERR("Could not get nsIDOMHTMLStyleElement iface: %08x\n", nsres);
329         heap_free(ret);
330         return E_FAIL;
331     }
332
333     HTMLElement_Init(&ret->element, doc, nselem, &HTMLStyleElement_dispex);
334     *elem = &ret->element;
335     return S_OK;
336 }