crypt32: NULL ptr could leak into function (Coverity).
[wine] / dlls / mshtml / htmlstylesheet.c
1 /*
2  * Copyright 2006 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 "ole2.h"
27
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
30
31 #include "mshtml_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 struct HTMLStyleSheet {
36     const IHTMLStyleSheetVtbl *lpHTMLStyleSheetVtbl;
37
38     LONG ref;
39
40     nsIDOMCSSStyleSheet *nsstylesheet;
41 };
42
43 struct HTMLStyleSheetsCollection {
44     DispatchEx dispex;
45     const IHTMLStyleSheetsCollectionVtbl *lpHTMLStyleSheetsCollectionVtbl;
46
47     LONG ref;
48
49     nsIDOMStyleSheetList *nslist;
50 };
51
52 struct HTMLStyleSheetRulesCollection {
53     const IHTMLStyleSheetRulesCollectionVtbl *lpHTMLStyleSheetRulesCollectionVtbl;
54
55     LONG ref;
56
57     nsIDOMCSSRuleList *nslist;
58 };
59
60 #define HTMLSTYLESHEET(x)     ((IHTMLStyleSheet*)                &(x)->lpHTMLStyleSheetVtbl)
61 #define HTMLSTYLESHEETSCOL(x) ((IHTMLStyleSheetsCollection*)     &(x)->lpHTMLStyleSheetsCollectionVtbl)
62 #define HTMLSTYLERULESCOL(x)  ((IHTMLStyleSheetRulesCollection*) &(x)->lpHTMLStyleSheetRulesCollectionVtbl)
63
64 #define HTMLSTYLERULESCOL_THIS(iface) \
65     DEFINE_THIS(HTMLStyleSheetRulesCollection, HTMLStyleSheetRulesCollection, iface)
66
67 static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
68         REFIID riid, void **ppv)
69 {
70     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
71
72     if(IsEqualGUID(&IID_IUnknown, riid)) {
73         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
74         *ppv = HTMLSTYLERULESCOL(This);
75     }else if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid)) {
76         TRACE("(%p)->(IID_IHTMLStyleSheetRulesCollection %p)\n", This, ppv);
77         *ppv = HTMLSTYLERULESCOL(This);
78     }
79
80     if(*ppv) {
81         IUnknown_AddRef((IUnknown*)*ppv);
82         return S_OK;
83     }
84
85     FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
86     return E_NOINTERFACE;
87 }
88
89 static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
90 {
91     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
92     LONG ref = InterlockedIncrement(&This->ref);
93
94     TRACE("(%p) ref=%d\n", This, ref);
95
96     return ref;
97 }
98
99 static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
100 {
101     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
102     LONG ref = InterlockedDecrement(&This->ref);
103
104     TRACE("(%p) ref=%d\n", This, ref);
105
106     if(!ref) {
107         if(This->nslist)
108             nsIDOMCSSRuleList_Release(This->nslist);
109         heap_free(This);
110     }
111
112     return ref;
113 }
114
115 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
116         IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
117 {
118     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
119     FIXME("(%p)->(%p)\n", This, pctinfo);
120     return E_NOTIMPL;
121 }
122
123 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
124         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
125 {
126     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
127     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
128     return E_NOTIMPL;
129 }
130
131 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
132         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
133 {
134     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
135     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
136           lcid, rgDispId);
137     return E_NOTIMPL;
138 }
139
140 static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
141         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
142         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
143 {
144     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
145     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
146           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
151         LONG *p)
152 {
153     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
154     PRUint32 len = 0;
155
156     TRACE("(%p)->(%p)\n", This, p);
157
158     if(This->nslist) {
159         nsresult nsres;
160
161         nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
162         if(NS_FAILED(nsres))
163             ERR("GetLength failed: %08x\n", nsres);
164     }
165
166     *p = len;
167     return S_OK;
168 }
169
170 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
171         LONG index, IHTMLStyleSheetRule **ppHTMLStyleSheetRule)
172 {
173     HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
174     FIXME("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
175     return E_NOTIMPL;
176 }
177
178 #undef HTMLSTYLERULECOL_THIS
179
180 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
181     HTMLStyleSheetRulesCollection_QueryInterface,
182     HTMLStyleSheetRulesCollection_AddRef,
183     HTMLStyleSheetRulesCollection_Release,
184     HTMLStyleSheetRulesCollection_GetTypeInfoCount,
185     HTMLStyleSheetRulesCollection_GetTypeInfo,
186     HTMLStyleSheetRulesCollection_GetIDsOfNames,
187     HTMLStyleSheetRulesCollection_Invoke,
188     HTMLStyleSheetRulesCollection_get_length,
189     HTMLStyleSheetRulesCollection_item
190 };
191
192 static IHTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_Create(nsIDOMCSSRuleList *nslist)
193 {
194     HTMLStyleSheetRulesCollection *ret;
195
196     ret = heap_alloc(sizeof(*ret));
197     ret->lpHTMLStyleSheetRulesCollectionVtbl = &HTMLStyleSheetRulesCollectionVtbl;
198     ret->ref = 1;
199     ret->nslist = nslist;
200
201     if(nslist)
202         nsIDOMCSSRuleList_AddRef(nslist);
203
204     return HTMLSTYLERULESCOL(ret);
205 }
206
207 #define HTMLSTYLESHEETSCOL_THIS(iface) \
208     DEFINE_THIS(HTMLStyleSheetsCollection, HTMLStyleSheetsCollection, iface)
209
210 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
211          REFIID riid, void **ppv)
212 {
213     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
214
215     *ppv = NULL;
216
217     if(IsEqualGUID(&IID_IUnknown, riid)) {
218         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
219         *ppv = HTMLSTYLESHEETSCOL(This);
220     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
221         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
222         *ppv = HTMLSTYLESHEETSCOL(This);
223     }else if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid)) {
224         TRACE("(%p)->(IID_IHTMLStyleSheetsCollection %p)\n", This, ppv);
225         *ppv = HTMLSTYLESHEETSCOL(This);
226     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
227         return *ppv ? S_OK : E_NOINTERFACE;
228     }
229
230     if(*ppv) {
231         IUnknown_AddRef((IUnknown*)*ppv);
232         return S_OK;
233     }
234
235     WARN("unsupported %s\n", debugstr_guid(riid));
236     return E_NOINTERFACE;
237 }
238
239 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
240 {
241     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
242     LONG ref = InterlockedIncrement(&This->ref);
243
244     TRACE("(%p) ref=%d\n", This, ref);
245
246     return ref;
247 }
248
249 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
250 {
251     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
252     LONG ref = InterlockedDecrement(&This->ref);
253
254     TRACE("(%p) ref=%d\n", This, ref);
255
256     if(!ref) {
257         if(This->nslist)
258             nsIDOMStyleSheetList_Release(This->nslist);
259         heap_free(This);
260     }
261
262     return ref;
263 }
264
265 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
266         UINT *pctinfo)
267 {
268     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
269     return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
270 }
271
272 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
273         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
274 {
275     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
276     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
277 }
278
279 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
280         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
281 {
282     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
283     return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
284             lcid, rgDispId);
285 }
286
287 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
288         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
289         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
290 {
291     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
292     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
293             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
294 }
295
296 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
297         LONG *p)
298 {
299     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
300     PRUint32 len = 0;
301
302     TRACE("(%p)->(%p)\n", This, p);
303
304     if(This->nslist)
305         nsIDOMStyleSheetList_GetLength(This->nslist, &len);
306
307     *p = len;
308     return S_OK;
309 }
310
311 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
312         IUnknown **p)
313 {
314     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
315     FIXME("(%p)->(%p)\n", This, p);
316     return E_NOTIMPL;
317 }
318
319 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
320         VARIANT *pvarIndex, VARIANT *pvarResult)
321 {
322     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
323
324     TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
325
326     switch(V_VT(pvarIndex)) {
327     case VT_I4: {
328         nsIDOMStyleSheet *nsstylesheet;
329         nsresult nsres;
330
331         TRACE("index=%d\n", V_I4(pvarIndex));
332
333         nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
334         if(NS_FAILED(nsres) || !nsstylesheet) {
335             WARN("Item failed: %08x\n", nsres);
336             V_VT(pvarResult) = VT_EMPTY;
337             return E_INVALIDARG;
338         }
339
340         V_VT(pvarResult) = VT_DISPATCH;
341         V_DISPATCH(pvarResult) = (IDispatch*)HTMLStyleSheet_Create(nsstylesheet);
342
343         return S_OK;
344     }
345
346     case VT_BSTR:
347         FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
348         return E_NOTIMPL;
349
350     default:
351         WARN("Invalid vt=%d\n", V_VT(pvarIndex));
352     }
353
354     return E_INVALIDARG;
355 }
356
357 #undef HTMLSTYLESHEETSCOL_THIS
358
359 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
360     HTMLStyleSheetsCollection_QueryInterface,
361     HTMLStyleSheetsCollection_AddRef,
362     HTMLStyleSheetsCollection_Release,
363     HTMLStyleSheetsCollection_GetTypeInfoCount,
364     HTMLStyleSheetsCollection_GetTypeInfo,
365     HTMLStyleSheetsCollection_GetIDsOfNames,
366     HTMLStyleSheetsCollection_Invoke,
367     HTMLStyleSheetsCollection_get_length,
368     HTMLStyleSheetsCollection_get__newEnum,
369     HTMLStyleSheetsCollection_item
370 };
371
372 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
373     IHTMLStyleSheetsCollection_tid,
374     0
375 };
376 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
377     NULL,
378     DispHTMLStyleSheetsCollection_tid,
379     NULL,
380     HTMLStyleSheetsCollection_iface_tids
381 };
382
383 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList *nslist)
384 {
385     HTMLStyleSheetsCollection *ret = heap_alloc(sizeof(HTMLStyleSheetsCollection));
386
387     ret->lpHTMLStyleSheetsCollectionVtbl = &HTMLStyleSheetsCollectionVtbl;
388     ret->ref = 1;
389
390     if(nslist)
391         nsIDOMStyleSheetList_AddRef(nslist);
392     ret->nslist = nslist;
393
394     init_dispex(&ret->dispex, (IUnknown*)HTMLSTYLESHEETSCOL(ret),  &HTMLStyleSheetsCollection_dispex);
395
396     return HTMLSTYLESHEETSCOL(ret);
397 }
398
399 #define HTMLSTYLESHEET_THIS(iface) DEFINE_THIS(HTMLStyleSheet, HTMLStyleSheet, iface)
400
401 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
402 {
403     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
404
405     *ppv = NULL;
406
407     if(IsEqualGUID(&IID_IUnknown, riid)) {
408         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
409         *ppv = HTMLSTYLESHEET(This);
410     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
411         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
412         *ppv = HTMLSTYLESHEET(This);
413     }else if(IsEqualGUID(&IID_IHTMLStyleSheet, riid)) {
414         TRACE("(%p)->(IID_IHTMLStyleSheet %p)\n", This, ppv);
415         *ppv = HTMLSTYLESHEET(This);
416     }
417
418     if(*ppv) {
419         IUnknown_AddRef((IUnknown*)*ppv);
420         return S_OK;
421     }
422
423     WARN("unsupported %s\n", debugstr_guid(riid));
424     return E_NOINTERFACE;
425 }
426
427 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
428 {
429     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
430     LONG ref = InterlockedIncrement(&This->ref);
431
432     TRACE("(%p) ref=%d\n", This, ref);
433
434     return ref;
435 }
436
437 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
438 {
439     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
440     LONG ref = InterlockedDecrement(&This->ref);
441
442     TRACE("(%p) ref=%d\n", This, ref);
443
444     if(!ref)
445         heap_free(This);
446
447     return ref;
448 }
449
450 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
451 {
452     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
453     FIXME("(%p)->(%p)\n", This, pctinfo);
454     return E_NOTIMPL;
455 }
456
457 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
458                                               LCID lcid, ITypeInfo **ppTInfo)
459 {
460     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
461     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
462     return E_NOTIMPL;
463 }
464
465 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
466                                                 LPOLESTR *rgszNames, UINT cNames,
467                                                 LCID lcid, DISPID *rgDispId)
468 {
469     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
470     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
471           lcid, rgDispId);
472     return E_NOTIMPL;
473 }
474
475 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
476                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
477                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
478 {
479     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
480     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
481           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
482     return E_NOTIMPL;
483 }
484
485 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
486 {
487     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
488     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
489     return E_NOTIMPL;
490 }
491
492 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
493 {
494     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
495     FIXME("(%p)->(%p)\n", This, p);
496     return E_NOTIMPL;
497 }
498
499 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
500                                                           IHTMLStyleSheet **p)
501 {
502     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
503     FIXME("(%p)->(%p)\n", This, p);
504     return E_NOTIMPL;
505 }
506
507 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
508 {
509     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
510     FIXME("(%p)->(%p)\n", This, p);
511     return E_NOTIMPL;
512 }
513
514 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
515 {
516     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
517     FIXME("(%p)->(%x)\n", This, v);
518     return E_NOTIMPL;
519 }
520
521 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
522 {
523     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
524     FIXME("(%p)->(%p)\n", This, p);
525     return E_NOTIMPL;
526 }
527
528 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
529 {
530     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
531     FIXME("(%p)->(%p)\n", This, p);
532     return E_NOTIMPL;
533 }
534
535 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
536                                                  IHTMLStyleSheetsCollection **p)
537 {
538     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
539     FIXME("(%p)->(%p)\n", This, p);
540     return E_NOTIMPL;
541 }
542
543 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
544 {
545     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
546     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
547     return E_NOTIMPL;
548 }
549
550 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
551 {
552     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
553     FIXME("(%p)->(%p)\n", This, p);
554     return E_NOTIMPL;
555 }
556
557 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
558 {
559     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
560     FIXME("(%p)->(%p)\n", This, p);
561     return E_NOTIMPL;
562 }
563
564 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
565 {
566     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
567     FIXME("(%p)->(%p)\n", This, p);
568     return E_NOTIMPL;
569 }
570
571 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
572                                                LONG lIndex, LONG *plIndex)
573 {
574     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
575     FIXME("(%p)->(%s %d %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
576     return E_NOTIMPL;
577 }
578
579 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
580                                              BSTR bstrStyle, LONG lIndex, LONG *plIndex)
581 {
582     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
583     FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
584           lIndex, plIndex);
585     return E_NOTIMPL;
586 }
587
588 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
589 {
590     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
591     FIXME("(%p)->(%d)\n", This, lIndex);
592     return E_NOTIMPL;
593 }
594
595 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
596 {
597     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
598     FIXME("(%p)->(%d)\n", This, lIndex);
599     return E_NOTIMPL;
600 }
601
602 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
603 {
604     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
605     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
606     return E_NOTIMPL;
607 }
608
609 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
610 {
611     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
612     FIXME("(%p)->(%p)\n", This, p);
613     return E_NOTIMPL;
614 }
615
616 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
617 {
618     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
619     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
620     return E_NOTIMPL;
621 }
622
623 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
624 {
625     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
626     FIXME("(%p)->(%p)\n", This, p);
627     return E_NOTIMPL;
628 }
629
630 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
631                                                IHTMLStyleSheetRulesCollection **p)
632 {
633     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
634     nsIDOMCSSRuleList *nslist = NULL;
635     nsresult nsres;
636
637     TRACE("(%p)->(%p)\n", This, p);
638
639     /* Gecko has buggy security checks and GetCssRules will fail. We have a correct
640      * implementation and it will work when the bug will be fixed in Gecko. */
641     nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
642     if(NS_FAILED(nsres))
643         WARN("GetCssRules failed: %08x\n", nsres);
644
645     *p = HTMLStyleSheetRulesCollection_Create(nslist);
646     return S_OK;
647 }
648
649 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
650     HTMLStyleSheet_QueryInterface,
651     HTMLStyleSheet_AddRef,
652     HTMLStyleSheet_Release,
653     HTMLStyleSheet_GetTypeInfoCount,
654     HTMLStyleSheet_GetTypeInfo,
655     HTMLStyleSheet_GetIDsOfNames,
656     HTMLStyleSheet_Invoke,
657     HTMLStyleSheet_put_title,
658     HTMLStyleSheet_get_title,
659     HTMLStyleSheet_get_parentStyleSheet,
660     HTMLStyleSheet_get_owningElement,
661     HTMLStyleSheet_put_disabled,
662     HTMLStyleSheet_get_disabled,
663     HTMLStyleSheet_get_readOnly,
664     HTMLStyleSheet_get_imports,
665     HTMLStyleSheet_put_href,
666     HTMLStyleSheet_get_href,
667     HTMLStyleSheet_get_type,
668     HTMLStyleSheet_get_id,
669     HTMLStyleSheet_addImport,
670     HTMLStyleSheet_addRule,
671     HTMLStyleSheet_removeImport,
672     HTMLStyleSheet_removeRule,
673     HTMLStyleSheet_put_media,
674     HTMLStyleSheet_get_media,
675     HTMLStyleSheet_put_cssText,
676     HTMLStyleSheet_get_cssText,
677     HTMLStyleSheet_get_rules
678 };
679
680 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet *nsstylesheet)
681 {
682     HTMLStyleSheet *ret = heap_alloc(sizeof(HTMLStyleSheet));
683     nsresult nsres;
684
685     ret->lpHTMLStyleSheetVtbl = &HTMLStyleSheetVtbl;
686     ret->ref = 1;
687     ret->nsstylesheet = NULL;
688
689     if(nsstylesheet) {
690         nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
691                 (void**)&ret->nsstylesheet);
692         if(NS_FAILED(nsres))
693             ERR("Could not get nsICSSStyleSheet interface: %08x\n", nsres);
694     }
695
696     return HTMLSTYLESHEET(ret);
697 }