mshtml: Added noscript tag handling tests.
[wine] / dlls / mshtml / htmldoc5.c
1 /*
2  * Copyright 2007 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 "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30
31 #include "wine/debug.h"
32
33 #include "mshtml_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36
37 static inline HTMLDocument *impl_from_IHTMLDocument5(IHTMLDocument5 *iface)
38 {
39     return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument5_iface);
40 }
41
42 static HRESULT WINAPI HTMLDocument5_QueryInterface(IHTMLDocument5 *iface,
43         REFIID riid, void **ppv)
44 {
45     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
46     return htmldoc_query_interface(This, riid, ppv);
47 }
48
49 static ULONG WINAPI HTMLDocument5_AddRef(IHTMLDocument5 *iface)
50 {
51     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
52     return htmldoc_addref(This);
53 }
54
55 static ULONG WINAPI HTMLDocument5_Release(IHTMLDocument5 *iface)
56 {
57     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
58     return htmldoc_release(This);
59 }
60
61 static HRESULT WINAPI HTMLDocument5_GetTypeInfoCount(IHTMLDocument5 *iface, UINT *pctinfo)
62 {
63     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
64     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
65 }
66
67 static HRESULT WINAPI HTMLDocument5_GetTypeInfo(IHTMLDocument5 *iface, UINT iTInfo,
68         LCID lcid, ITypeInfo **ppTInfo)
69 {
70     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
71     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
72 }
73
74 static HRESULT WINAPI HTMLDocument5_GetIDsOfNames(IHTMLDocument5 *iface, REFIID riid,
75         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
76 {
77     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
78     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
79             rgDispId);
80 }
81
82 static HRESULT WINAPI HTMLDocument5_Invoke(IHTMLDocument5 *iface, DISPID dispIdMember,
83                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
84                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
85 {
86     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
87     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
88             pDispParams, pVarResult, pExcepInfo, puArgErr);
89 }
90
91 static HRESULT WINAPI HTMLDocument5_put_onmousewheel(IHTMLDocument5 *iface, VARIANT v)
92 {
93     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
94     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
95     return E_NOTIMPL;
96 }
97
98 static HRESULT WINAPI HTMLDocument5_get_onmousewheel(IHTMLDocument5 *iface, VARIANT *p)
99 {
100     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
101     FIXME("(%p)->(%p)\n", This, p);
102     return E_NOTIMPL;
103 }
104
105 static HRESULT WINAPI HTMLDocument5_get_doctype(IHTMLDocument5 *iface, IHTMLDOMNode **p)
106 {
107     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
108     FIXME("(%p)->(%p)\n", This, p);
109     return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI HTMLDocument5_get_implementation(IHTMLDocument5 *iface, IHTMLDOMImplementation **p)
113 {
114     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
115     FIXME("(%p)->(%p)\n", This, p);
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI HTMLDocument5_createAttribute(IHTMLDocument5 *iface, BSTR bstrattrName,
120         IHTMLDOMAttribute **ppattribute)
121 {
122     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
123     FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrattrName), ppattribute);
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bstrdata,
128         IHTMLDOMNode **ppRetNode)
129 {
130     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
131     nsIDOMComment *nscomment;
132     HTMLElement *elem;
133     nsAString str;
134     nsresult nsres;
135     HRESULT hres;
136
137     TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrdata), ppRetNode);
138
139     if(!This->doc_node->nsdoc) {
140         WARN("NULL nsdoc\n");
141         return E_UNEXPECTED;
142     }
143
144     nsAString_InitDepend(&str, bstrdata);
145     nsres = nsIDOMHTMLDocument_CreateComment(This->doc_node->nsdoc, &str, &nscomment);
146     nsAString_Finish(&str);
147     if(NS_FAILED(nsres)) {
148         ERR("CreateTextNode failed: %08x\n", nsres);
149         return E_FAIL;
150     }
151
152     hres = HTMLCommentElement_Create(This->doc_node, (nsIDOMNode*)nscomment, &elem);
153     nsIDOMComment_Release(nscomment);
154     if(FAILED(hres))
155         return hres;
156
157     *ppRetNode = &elem->node.IHTMLDOMNode_iface;
158     return S_OK;
159 }
160
161 static HRESULT WINAPI HTMLDocument5_put_onfocusin(IHTMLDocument5 *iface, VARIANT v)
162 {
163     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
164     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
165     return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI HTMLDocument5_get_onfocusin(IHTMLDocument5 *iface, VARIANT *p)
169 {
170     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
171     FIXME("(%p)->(%p)\n", This, p);
172     return E_NOTIMPL;
173 }
174
175 static HRESULT WINAPI HTMLDocument5_put_onfocusout(IHTMLDocument5 *iface, VARIANT v)
176 {
177     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
178     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
179     return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI HTMLDocument5_get_onfocusout(IHTMLDocument5 *iface, VARIANT *p)
183 {
184     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
185     FIXME("(%p)->(%p)\n", This, p);
186     return E_NOTIMPL;
187 }
188
189 static HRESULT WINAPI HTMLDocument5_put_onactivate(IHTMLDocument5 *iface, VARIANT v)
190 {
191     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
192     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
193     return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI HTMLDocument5_get_onactivate(IHTMLDocument5 *iface, VARIANT *p)
197 {
198     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
199     FIXME("(%p)->(%p)\n", This, p);
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI HTMLDocument5_put_ondeactivate(IHTMLDocument5 *iface, VARIANT v)
204 {
205     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
206     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI HTMLDocument5_get_ondeactivate(IHTMLDocument5 *iface, VARIANT *p)
211 {
212     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
213     FIXME("(%p)->(%p)\n", This, p);
214     return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI HTMLDocument5_put_onbeforeactivate(IHTMLDocument5 *iface, VARIANT v)
218 {
219     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
220     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI HTMLDocument5_get_onbeforeactivate(IHTMLDocument5 *iface, VARIANT *p)
225 {
226     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
227     FIXME("(%p)->(%p)\n", This, p);
228     return E_NOTIMPL;
229 }
230
231 static HRESULT WINAPI HTMLDocument5_put_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT v)
232 {
233     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
234     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
235     return E_NOTIMPL;
236 }
237
238 static HRESULT WINAPI HTMLDocument5_get_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT *p)
239 {
240     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
241     FIXME("(%p)->(%p)\n", This, p);
242     return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI HTMLDocument5_get_compatMode(IHTMLDocument5 *iface, BSTR *p)
246 {
247     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
248     nsAString mode_str;
249     const PRUnichar *mode;
250
251     TRACE("(%p)->(%p)\n", This, p);
252
253     if(!This->doc_node->nsdoc) {
254         WARN("NULL nsdoc\n");
255         return E_UNEXPECTED;
256     }
257
258     nsAString_Init(&mode_str, NULL);
259     nsIDOMHTMLDocument_GetCompatMode(This->doc_node->nsdoc, &mode_str);
260
261     nsAString_GetData(&mode_str, &mode);
262     *p = SysAllocString(mode);
263     nsAString_Finish(&mode_str);
264
265     return S_OK;
266 }
267
268 static const IHTMLDocument5Vtbl HTMLDocument5Vtbl = {
269     HTMLDocument5_QueryInterface,
270     HTMLDocument5_AddRef,
271     HTMLDocument5_Release,
272     HTMLDocument5_GetTypeInfoCount,
273     HTMLDocument5_GetTypeInfo,
274     HTMLDocument5_GetIDsOfNames,
275     HTMLDocument5_Invoke,
276     HTMLDocument5_put_onmousewheel,
277     HTMLDocument5_get_onmousewheel,
278     HTMLDocument5_get_doctype,
279     HTMLDocument5_get_implementation,
280     HTMLDocument5_createAttribute,
281     HTMLDocument5_createComment,
282     HTMLDocument5_put_onfocusin,
283     HTMLDocument5_get_onfocusin,
284     HTMLDocument5_put_onfocusout,
285     HTMLDocument5_get_onfocusout,
286     HTMLDocument5_put_onactivate,
287     HTMLDocument5_get_onactivate,
288     HTMLDocument5_put_ondeactivate,
289     HTMLDocument5_get_ondeactivate,
290     HTMLDocument5_put_onbeforeactivate,
291     HTMLDocument5_get_onbeforeactivate,
292     HTMLDocument5_put_onbeforedeactivate,
293     HTMLDocument5_get_onbeforedeactivate,
294     HTMLDocument5_get_compatMode
295 };
296
297 static inline HTMLDocument *impl_from_IHTMLDocument6(IHTMLDocument6 *iface)
298 {
299     return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument6_iface);
300 }
301
302 static HRESULT WINAPI HTMLDocument6_QueryInterface(IHTMLDocument6 *iface,
303         REFIID riid, void **ppv)
304 {
305     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
306     return htmldoc_query_interface(This, riid, ppv);
307 }
308
309 static ULONG WINAPI HTMLDocument6_AddRef(IHTMLDocument6 *iface)
310 {
311     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
312     return htmldoc_addref(This);
313 }
314
315 static ULONG WINAPI HTMLDocument6_Release(IHTMLDocument6 *iface)
316 {
317     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
318     return htmldoc_release(This);
319 }
320
321 static HRESULT WINAPI HTMLDocument6_GetTypeInfoCount(IHTMLDocument6 *iface, UINT *pctinfo)
322 {
323     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
324     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
325 }
326
327 static HRESULT WINAPI HTMLDocument6_GetTypeInfo(IHTMLDocument6 *iface, UINT iTInfo,
328         LCID lcid, ITypeInfo **ppTInfo)
329 {
330     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
331     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
332 }
333
334 static HRESULT WINAPI HTMLDocument6_GetIDsOfNames(IHTMLDocument6 *iface, REFIID riid,
335         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
336 {
337     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
338     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
339             rgDispId);
340 }
341
342 static HRESULT WINAPI HTMLDocument6_Invoke(IHTMLDocument6 *iface, DISPID dispIdMember,
343                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
344                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
345 {
346     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
347     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
348             pDispParams, pVarResult, pExcepInfo, puArgErr);
349 }
350
351 static HRESULT WINAPI HTMLDocument6_get_compatible(IHTMLDocument6 *iface,
352         IHTMLDocumentCompatibleInfoCollection **p)
353 {
354     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
355     FIXME("(%p)->(%p)\n", This, p);
356     return E_NOTIMPL;
357 }
358
359 static HRESULT WINAPI HTMLDocument6_get_documentMode(IHTMLDocument6 *iface,
360         VARIANT *p)
361 {
362     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
363     FIXME("(%p)->(%p)\n", This, p);
364     return E_NOTIMPL;
365 }
366
367 static HRESULT WINAPI HTMLDocument6_get_onstorage(IHTMLDocument6 *iface,
368         VARIANT *p)
369 {
370     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
371     FIXME("(%p)->(%p)\n", This, p);
372     return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI HTMLDocument6_put_onstorage(IHTMLDocument6 *iface, VARIANT v)
376 {
377     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
378     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
379     return E_NOTIMPL;
380 }
381
382 static HRESULT WINAPI HTMLDocument6_get_onstoragecommit(IHTMLDocument6 *iface,
383         VARIANT *p)
384 {
385     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
386     FIXME("(%p)->(%p)\n", This, p);
387     return E_NOTIMPL;
388 }
389
390 static HRESULT WINAPI HTMLDocument6_put_onstoragecommit(IHTMLDocument6 *iface, VARIANT v)
391 {
392     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
393     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
394     return E_NOTIMPL;
395 }
396
397 static HRESULT WINAPI HTMLDocument6_getElementById(IHTMLDocument6 *iface,
398         BSTR bstrId, IHTMLElement2 **p)
399 {
400     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
401     FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrId), p);
402     return E_NOTIMPL;
403 }
404
405 static HRESULT WINAPI HTMLDocument6_updateSettings(IHTMLDocument6 *iface)
406 {
407     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
408     FIXME("(%p)->()\n", This);
409     return E_NOTIMPL;
410 }
411
412 static const IHTMLDocument6Vtbl HTMLDocument6Vtbl = {
413     HTMLDocument6_QueryInterface,
414     HTMLDocument6_AddRef,
415     HTMLDocument6_Release,
416     HTMLDocument6_GetTypeInfoCount,
417     HTMLDocument6_GetTypeInfo,
418     HTMLDocument6_GetIDsOfNames,
419     HTMLDocument6_Invoke,
420     HTMLDocument6_get_compatible,
421     HTMLDocument6_get_documentMode,
422     HTMLDocument6_put_onstorage,
423     HTMLDocument6_get_onstorage,
424     HTMLDocument6_put_onstoragecommit,
425     HTMLDocument6_get_onstoragecommit,
426     HTMLDocument6_getElementById,
427     HTMLDocument6_updateSettings
428 };
429
430 void HTMLDocument_HTMLDocument5_Init(HTMLDocument *This)
431 {
432     This->IHTMLDocument5_iface.lpVtbl = &HTMLDocument5Vtbl;
433     This->IHTMLDocument6_iface.lpVtbl = &HTMLDocument6Vtbl;
434 }