mshtml: Store security manager in HTMLWindow instead of HTMLDocumentNode.
[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)->(v)\n", This);
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     nsIDOMElement_Release(nscomment);
154     if(FAILED(hres))
155         return hres;
156
157     *ppRetNode = &elem->node.IHTMLDOMNode_iface;
158     IHTMLDOMNode_AddRef(&elem->node.IHTMLDOMNode_iface);
159     return S_OK;
160 }
161
162 static HRESULT WINAPI HTMLDocument5_put_onfocusin(IHTMLDocument5 *iface, VARIANT v)
163 {
164     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
165     FIXME("(%p)->(v)\n", This);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI HTMLDocument5_get_onfocusin(IHTMLDocument5 *iface, VARIANT *p)
170 {
171     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
172     FIXME("(%p)->(%p)\n", This, p);
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI HTMLDocument5_put_onfocusout(IHTMLDocument5 *iface, VARIANT v)
177 {
178     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
179     FIXME("(%p)->(v)\n", This);
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLDocument5_get_onfocusout(IHTMLDocument5 *iface, VARIANT *p)
184 {
185     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
186     FIXME("(%p)->(%p)\n", This, p);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLDocument5_put_onactivate(IHTMLDocument5 *iface, VARIANT v)
191 {
192     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
193     FIXME("(%p)->(v)\n", This);
194     return E_NOTIMPL;
195 }
196
197 static HRESULT WINAPI HTMLDocument5_get_onactivate(IHTMLDocument5 *iface, VARIANT *p)
198 {
199     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
200     FIXME("(%p)->(%p)\n", This, p);
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI HTMLDocument5_put_ondeactivate(IHTMLDocument5 *iface, VARIANT v)
205 {
206     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
207     FIXME("(%p)->(v)\n", This);
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI HTMLDocument5_get_ondeactivate(IHTMLDocument5 *iface, VARIANT *p)
212 {
213     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
214     FIXME("(%p)->(%p)\n", This, p);
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI HTMLDocument5_put_onbeforeactivate(IHTMLDocument5 *iface, VARIANT v)
219 {
220     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
221     FIXME("(%p)->(v)\n", This);
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI HTMLDocument5_get_onbeforeactivate(IHTMLDocument5 *iface, VARIANT *p)
226 {
227     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
228     FIXME("(%p)->(%p)\n", This, p);
229     return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI HTMLDocument5_put_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT v)
233 {
234     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
235     FIXME("(%p)->(v)\n", This);
236     return E_NOTIMPL;
237 }
238
239 static HRESULT WINAPI HTMLDocument5_get_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT *p)
240 {
241     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
242     FIXME("(%p)->(%p)\n", This, p);
243     return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI HTMLDocument5_get_compatMode(IHTMLDocument5 *iface, BSTR *p)
247 {
248     HTMLDocument *This = impl_from_IHTMLDocument5(iface);
249     nsIDOMNSHTMLDocument *nshtmldoc;
250     nsAString mode_str;
251     const PRUnichar *mode;
252     nsresult nsres;
253
254     TRACE("(%p)->(%p)\n", This, p);
255
256     if(!This->doc_node->nsdoc) {
257         WARN("NULL nsdoc\n");
258         return E_UNEXPECTED;
259     }
260
261     nsres = nsIDOMHTMLDocument_QueryInterface(This->doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nshtmldoc);
262     if(NS_FAILED(nsres)) {
263         ERR("Could not get nsIDOMNSHTMLDocument: %08x\n", nsres);
264         return S_OK;
265     }
266
267     nsAString_Init(&mode_str, NULL);
268     nsIDOMNSHTMLDocument_GetCompatMode(nshtmldoc, &mode_str);
269     nsIDOMNSHTMLDocument_Release(nshtmldoc);
270
271     nsAString_GetData(&mode_str, &mode);
272     *p = SysAllocString(mode);
273     nsAString_Finish(&mode_str);
274
275     return S_OK;
276 }
277
278 static const IHTMLDocument5Vtbl HTMLDocument5Vtbl = {
279     HTMLDocument5_QueryInterface,
280     HTMLDocument5_AddRef,
281     HTMLDocument5_Release,
282     HTMLDocument5_GetTypeInfoCount,
283     HTMLDocument5_GetTypeInfo,
284     HTMLDocument5_GetIDsOfNames,
285     HTMLDocument5_Invoke,
286     HTMLDocument5_put_onmousewheel,
287     HTMLDocument5_get_onmousewheel,
288     HTMLDocument5_get_doctype,
289     HTMLDocument5_get_implementation,
290     HTMLDocument5_createAttribute,
291     HTMLDocument5_createComment,
292     HTMLDocument5_put_onfocusin,
293     HTMLDocument5_get_onfocusin,
294     HTMLDocument5_put_onfocusout,
295     HTMLDocument5_get_onfocusout,
296     HTMLDocument5_put_onactivate,
297     HTMLDocument5_get_onactivate,
298     HTMLDocument5_put_ondeactivate,
299     HTMLDocument5_get_ondeactivate,
300     HTMLDocument5_put_onbeforeactivate,
301     HTMLDocument5_get_onbeforeactivate,
302     HTMLDocument5_put_onbeforedeactivate,
303     HTMLDocument5_get_onbeforedeactivate,
304     HTMLDocument5_get_compatMode
305 };
306
307 static inline HTMLDocument *impl_from_IHTMLDocument6(IHTMLDocument6 *iface)
308 {
309     return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument6_iface);
310 }
311
312 static HRESULT WINAPI HTMLDocument6_QueryInterface(IHTMLDocument6 *iface,
313         REFIID riid, void **ppv)
314 {
315     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
316     return htmldoc_query_interface(This, riid, ppv);
317 }
318
319 static ULONG WINAPI HTMLDocument6_AddRef(IHTMLDocument6 *iface)
320 {
321     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
322     return htmldoc_addref(This);
323 }
324
325 static ULONG WINAPI HTMLDocument6_Release(IHTMLDocument6 *iface)
326 {
327     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
328     return htmldoc_release(This);
329 }
330
331 static HRESULT WINAPI HTMLDocument6_GetTypeInfoCount(IHTMLDocument6 *iface, UINT *pctinfo)
332 {
333     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
334     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
335 }
336
337 static HRESULT WINAPI HTMLDocument6_GetTypeInfo(IHTMLDocument6 *iface, UINT iTInfo,
338         LCID lcid, ITypeInfo **ppTInfo)
339 {
340     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
341     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
342 }
343
344 static HRESULT WINAPI HTMLDocument6_GetIDsOfNames(IHTMLDocument6 *iface, REFIID riid,
345         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
346 {
347     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
348     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
349             rgDispId);
350 }
351
352 static HRESULT WINAPI HTMLDocument6_Invoke(IHTMLDocument6 *iface, DISPID dispIdMember,
353                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
354                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
355 {
356     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
357     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
358             pDispParams, pVarResult, pExcepInfo, puArgErr);
359 }
360
361 static HRESULT WINAPI HTMLDocument6_get_compatible(IHTMLDocument6 *iface,
362         IHTMLDocumentCompatibleInfoCollection **p)
363 {
364     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
365     FIXME("(%p)->(%p)\n", This, p);
366     return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI HTMLDocument6_get_documentMode(IHTMLDocument6 *iface,
370         VARIANT *p)
371 {
372     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
373     FIXME("(%p)->(%p)\n", This, p);
374     return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI HTMLDocument6_get_onstorage(IHTMLDocument6 *iface,
378         VARIANT *p)
379 {
380     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
381     FIXME("(%p)->(%p)\n", This, p);
382     return E_NOTIMPL;
383 }
384
385 static HRESULT WINAPI HTMLDocument6_put_onstorage(IHTMLDocument6 *iface,
386         VARIANT p)
387 {
388     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
389     FIXME("(%p)->(v)\n", This);
390     return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI HTMLDocument6_get_onstoragecommit(IHTMLDocument6 *iface,
394         VARIANT *p)
395 {
396     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
397     FIXME("(%p)->(%p)\n", This, p);
398     return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI HTMLDocument6_put_onstoragecommit(IHTMLDocument6 *iface,
402         VARIANT p)
403 {
404     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
405     FIXME("(%p)->(v)\n", This);
406     return E_NOTIMPL;
407 }
408
409 static HRESULT WINAPI HTMLDocument6_getElementById(IHTMLDocument6 *iface,
410         BSTR bstrId, IHTMLElement2 **p)
411 {
412     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
413     FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrId), p);
414     return E_NOTIMPL;
415 }
416
417 static HRESULT WINAPI HTMLDocument6_updateSettings(IHTMLDocument6 *iface)
418 {
419     HTMLDocument *This = impl_from_IHTMLDocument6(iface);
420     FIXME("(%p)->()\n", This);
421     return E_NOTIMPL;
422 }
423
424 static const IHTMLDocument6Vtbl HTMLDocument6Vtbl = {
425     HTMLDocument6_QueryInterface,
426     HTMLDocument6_AddRef,
427     HTMLDocument6_Release,
428     HTMLDocument6_GetTypeInfoCount,
429     HTMLDocument6_GetTypeInfo,
430     HTMLDocument6_GetIDsOfNames,
431     HTMLDocument6_Invoke,
432     HTMLDocument6_get_compatible,
433     HTMLDocument6_get_documentMode,
434     HTMLDocument6_put_onstorage,
435     HTMLDocument6_get_onstorage,
436     HTMLDocument6_put_onstoragecommit,
437     HTMLDocument6_get_onstoragecommit,
438     HTMLDocument6_getElementById,
439     HTMLDocument6_updateSettings
440 };
441
442 void HTMLDocument_HTMLDocument5_Init(HTMLDocument *This)
443 {
444     This->IHTMLDocument5_iface.lpVtbl = &HTMLDocument5Vtbl;
445     This->IHTMLDocument6_iface.lpVtbl = &HTMLDocument6Vtbl;
446 }