mshtml: COM cleanup for the IHTMLDOMNode iface.
[wine] / dlls / mshtml / htmlobject.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 #include "pluginhost.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 typedef struct {
37     HTMLPluginContainer plugin_container;
38
39     IHTMLObjectElement IHTMLObjectElement_iface;
40
41     nsIDOMHTMLObjectElement *nsobject;
42 } HTMLObjectElement;
43
44 static inline HTMLObjectElement *impl_from_IHTMLObjectElement(IHTMLObjectElement *iface)
45 {
46     return CONTAINING_RECORD(iface, HTMLObjectElement, IHTMLObjectElement_iface);
47 }
48
49 static HRESULT WINAPI HTMLObjectElement_QueryInterface(IHTMLObjectElement *iface,
50         REFIID riid, void **ppv)
51 {
52     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
53
54     return IHTMLDOMNode_QueryInterface(&This->plugin_container.element.node.IHTMLDOMNode_iface,
55             riid, ppv);
56 }
57
58 static ULONG WINAPI HTMLObjectElement_AddRef(IHTMLObjectElement *iface)
59 {
60     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
61
62     return IHTMLDOMNode_AddRef(&This->plugin_container.element.node.IHTMLDOMNode_iface);
63 }
64
65 static ULONG WINAPI HTMLObjectElement_Release(IHTMLObjectElement *iface)
66 {
67     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
68
69     return IHTMLDOMNode_Release(&This->plugin_container.element.node.IHTMLDOMNode_iface);
70 }
71
72 static HRESULT WINAPI HTMLObjectElement_GetTypeInfoCount(IHTMLObjectElement *iface, UINT *pctinfo)
73 {
74     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
75     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->plugin_container.element.node.dispex), pctinfo);
76 }
77
78 static HRESULT WINAPI HTMLObjectElement_GetTypeInfo(IHTMLObjectElement *iface, UINT iTInfo,
79                                               LCID lcid, ITypeInfo **ppTInfo)
80 {
81     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
82     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->plugin_container.element.node.dispex), iTInfo, lcid, ppTInfo);
83 }
84
85 static HRESULT WINAPI HTMLObjectElement_GetIDsOfNames(IHTMLObjectElement *iface, REFIID riid,
86                                                 LPOLESTR *rgszNames, UINT cNames,
87                                                 LCID lcid, DISPID *rgDispId)
88 {
89     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
90     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->plugin_container.element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
91 }
92
93 static HRESULT WINAPI HTMLObjectElement_Invoke(IHTMLObjectElement *iface, DISPID dispIdMember,
94                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 {
97     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
98     return IDispatchEx_Invoke(DISPATCHEX(&This->plugin_container.element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
99             pVarResult, pExcepInfo, puArgErr);
100 }
101
102 static HRESULT WINAPI HTMLObjectElement_get_object(IHTMLObjectElement *iface, IDispatch **p)
103 {
104     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
105
106     TRACE("(%p)->(%p)\n", This, p);
107
108     return get_plugin_disp(&This->plugin_container, p);
109 }
110
111 static HRESULT WINAPI HTMLObjectElement_get_classid(IHTMLObjectElement *iface, BSTR *p)
112 {
113     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
114     FIXME("(%p)->(%p)\n", This, p);
115     return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI HTMLObjectElement_get_data(IHTMLObjectElement *iface, BSTR *p)
119 {
120     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
121     FIXME("(%p)->(%p)\n", This, p);
122     return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI HTMLObjectElement_put_recordset(IHTMLObjectElement *iface, IDispatch *v)
126 {
127     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
128     FIXME("(%p)->(%p)\n", This, v);
129     return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI HTMLObjectElement_get_recordset(IHTMLObjectElement *iface, IDispatch **p)
133 {
134     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
135     FIXME("(%p)->(%p)\n", This, p);
136     return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI HTMLObjectElement_put_align(IHTMLObjectElement *iface, BSTR v)
140 {
141     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
142     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
143     return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI HTMLObjectElement_get_align(IHTMLObjectElement *iface, BSTR *p)
147 {
148     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
149     FIXME("(%p)->(%p)\n", This, p);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI HTMLObjectElement_put_name(IHTMLObjectElement *iface, BSTR v)
154 {
155     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
156     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI HTMLObjectElement_get_name(IHTMLObjectElement *iface, BSTR *p)
161 {
162     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
163     FIXME("(%p)->(%p)\n", This, p);
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI HTMLObjectElement_put_codeBase(IHTMLObjectElement *iface, BSTR v)
168 {
169     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
170     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
171     return E_NOTIMPL;
172 }
173
174 static HRESULT WINAPI HTMLObjectElement_get_codeBase(IHTMLObjectElement *iface, BSTR *p)
175 {
176     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
177     FIXME("(%p)->(%p)\n", This, p);
178     return E_NOTIMPL;
179 }
180
181 static HRESULT WINAPI HTMLObjectElement_put_codeType(IHTMLObjectElement *iface, BSTR v)
182 {
183     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
184     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
185     return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI HTMLObjectElement_get_codeType(IHTMLObjectElement *iface, BSTR *p)
189 {
190     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
191     FIXME("(%p)->(%p)\n", This, p);
192     return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI HTMLObjectElement_put_code(IHTMLObjectElement *iface, BSTR v)
196 {
197     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
198     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
199     return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI HTMLObjectElement_get_code(IHTMLObjectElement *iface, BSTR *p)
203 {
204     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
205     FIXME("(%p)->(%p)\n", This, p);
206     return E_NOTIMPL;
207 }
208
209 static HRESULT WINAPI HTMLObjectElement_get_BaseHref(IHTMLObjectElement *iface, BSTR *p)
210 {
211     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
212     FIXME("(%p)->(%p)\n", This, p);
213     return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI HTMLObjectElement_put_type(IHTMLObjectElement *iface, BSTR v)
217 {
218     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
219     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
220     return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI HTMLObjectElement_get_type(IHTMLObjectElement *iface, BSTR *p)
224 {
225     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
226     FIXME("(%p)->(%p)\n", This, p);
227     return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI HTMLObjectElement_get_form(IHTMLObjectElement *iface, IHTMLFormElement **p)
231 {
232     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
233     FIXME("(%p)->(%p)\n", This, p);
234     return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI HTMLObjectElement_put_width(IHTMLObjectElement *iface, VARIANT v)
238 {
239     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
240     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
241     return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI HTMLObjectElement_get_width(IHTMLObjectElement *iface, VARIANT *p)
245 {
246     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
247     FIXME("(%p)->(%p)\n", This, p);
248     return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI HTMLObjectElement_put_height(IHTMLObjectElement *iface, VARIANT v)
252 {
253     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
254     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI HTMLObjectElement_get_height(IHTMLObjectElement *iface, VARIANT *p)
259 {
260     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
261     FIXME("(%p)->(%p)\n", This, p);
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI HTMLObjectElement_get_readyState(IHTMLObjectElement *iface, LONG *p)
266 {
267     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
268     FIXME("(%p)->(%p)\n", This, p);
269     return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI HTMLObjectElement_put_onreadystatechange(IHTMLObjectElement *iface, VARIANT v)
273 {
274     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
275     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI HTMLObjectElement_get_onreadystatechange(IHTMLObjectElement *iface, VARIANT *p)
280 {
281     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
282     FIXME("(%p)->(%p)\n", This, p);
283     return E_NOTIMPL;
284 }
285
286 static HRESULT WINAPI HTMLObjectElement_put_onerror(IHTMLObjectElement *iface, VARIANT v)
287 {
288     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
289     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
290     return E_NOTIMPL;
291 }
292
293 static HRESULT WINAPI HTMLObjectElement_get_onerror(IHTMLObjectElement *iface, VARIANT *p)
294 {
295     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
296     FIXME("(%p)->(%p)\n", This, p);
297     return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI HTMLObjectElement_put_altHtml(IHTMLObjectElement *iface, BSTR v)
301 {
302     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
303     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
304     return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI HTMLObjectElement_get_altHtml(IHTMLObjectElement *iface, BSTR *p)
308 {
309     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
310     FIXME("(%p)->(%p)\n", This, p);
311     return E_NOTIMPL;
312 }
313
314 static HRESULT WINAPI HTMLObjectElement_put_vspace(IHTMLObjectElement *iface, LONG v)
315 {
316     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
317     FIXME("(%p)->(%d)\n", This, v);
318     return E_NOTIMPL;
319 }
320
321 static HRESULT WINAPI HTMLObjectElement_get_vspace(IHTMLObjectElement *iface, LONG *p)
322 {
323     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
324     PRInt32 vspace;
325     nsresult nsres;
326
327     TRACE("(%p)->(%p)\n", This, p);
328
329     nsres = nsIDOMHTMLObjectElement_GetVspace(This->nsobject, &vspace);
330     if(NS_FAILED(nsres)) {
331         ERR("GetVspace failed: %08x\n", nsres);
332         return E_FAIL;
333     }
334
335     *p = vspace;
336     return S_OK;
337 }
338
339 static HRESULT WINAPI HTMLObjectElement_put_hspace(IHTMLObjectElement *iface, LONG v)
340 {
341     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
342     FIXME("(%p)->(%d)\n", This, v);
343     return E_NOTIMPL;
344 }
345
346 static HRESULT WINAPI HTMLObjectElement_get_hspace(IHTMLObjectElement *iface, LONG *p)
347 {
348     HTMLObjectElement *This = impl_from_IHTMLObjectElement(iface);
349     FIXME("(%p)->(%p)\n", This, p);
350     return E_NOTIMPL;
351 }
352
353 static const IHTMLObjectElementVtbl HTMLObjectElementVtbl = {
354     HTMLObjectElement_QueryInterface,
355     HTMLObjectElement_AddRef,
356     HTMLObjectElement_Release,
357     HTMLObjectElement_GetTypeInfoCount,
358     HTMLObjectElement_GetTypeInfo,
359     HTMLObjectElement_GetIDsOfNames,
360     HTMLObjectElement_Invoke,
361     HTMLObjectElement_get_object,
362     HTMLObjectElement_get_classid,
363     HTMLObjectElement_get_data,
364     HTMLObjectElement_put_recordset,
365     HTMLObjectElement_get_recordset,
366     HTMLObjectElement_put_align,
367     HTMLObjectElement_get_align,
368     HTMLObjectElement_put_name,
369     HTMLObjectElement_get_name,
370     HTMLObjectElement_put_codeBase,
371     HTMLObjectElement_get_codeBase,
372     HTMLObjectElement_put_codeType,
373     HTMLObjectElement_get_codeType,
374     HTMLObjectElement_put_code,
375     HTMLObjectElement_get_code,
376     HTMLObjectElement_get_BaseHref,
377     HTMLObjectElement_put_type,
378     HTMLObjectElement_get_type,
379     HTMLObjectElement_get_form,
380     HTMLObjectElement_put_width,
381     HTMLObjectElement_get_width,
382     HTMLObjectElement_put_height,
383     HTMLObjectElement_get_height,
384     HTMLObjectElement_get_readyState,
385     HTMLObjectElement_put_onreadystatechange,
386     HTMLObjectElement_get_onreadystatechange,
387     HTMLObjectElement_put_onerror,
388     HTMLObjectElement_get_onerror,
389     HTMLObjectElement_put_altHtml,
390     HTMLObjectElement_get_altHtml,
391     HTMLObjectElement_put_vspace,
392     HTMLObjectElement_get_vspace,
393     HTMLObjectElement_put_hspace,
394     HTMLObjectElement_get_hspace
395 };
396
397 static inline HTMLObjectElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
398 {
399     return CONTAINING_RECORD(iface, HTMLObjectElement, plugin_container.element.node);
400 }
401
402 static HRESULT HTMLObjectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
403 {
404     HTMLObjectElement *This = impl_from_HTMLDOMNode(iface);
405
406     if(IsEqualGUID(&IID_IUnknown, riid)) {
407         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
408         *ppv = &This->IHTMLObjectElement_iface;
409     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
410         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
411         *ppv = &This->IHTMLObjectElement_iface;
412     }else if(IsEqualGUID(&IID_IHTMLObjectElement, riid)) {
413         TRACE("(%p)->(IID_IHTMLObjectElement %p)\n", This, ppv);
414         *ppv = &This->IHTMLObjectElement_iface;
415     }else if(IsEqualGUID(&IID_HTMLPluginContainer, riid)) {
416         TRACE("(%p)->(IID_HTMLPluginContainer %p)\n", This, ppv);
417         *ppv = &This->plugin_container;
418         return S_OK;
419     }else {
420         return HTMLElement_QI(&This->plugin_container.element.node, riid, ppv);
421     }
422
423     IUnknown_AddRef((IUnknown*)*ppv);
424     return S_OK;
425 }
426
427 static void HTMLObjectElement_destructor(HTMLDOMNode *iface)
428 {
429     HTMLObjectElement *This = impl_from_HTMLDOMNode(iface);
430
431     if(This->plugin_container.plugin_host)
432         detach_plugin_host(This->plugin_container.plugin_host);
433     if(This->nsobject)
434         nsIDOMHTMLObjectElement_Release(This->nsobject);
435
436     HTMLElement_destructor(&This->plugin_container.element.node);
437 }
438
439 static HRESULT HTMLObjectElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
440 {
441     HTMLObjectElement *This = impl_from_HTMLDOMNode(iface);
442     FIXME("(%p)->(%p)\n", This, p);
443     return E_NOTIMPL;
444 }
445
446 static HRESULT HTMLObjectElement_get_dispid(HTMLDOMNode *iface, BSTR name,
447         DWORD grfdex, DISPID *pid)
448 {
449     HTMLObjectElement *This = impl_from_HTMLDOMNode(iface);
450
451     TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), grfdex, pid);
452
453     return get_plugin_dispid(&This->plugin_container, name, pid);
454 }
455
456 static HRESULT HTMLObjectElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid,
457         WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
458 {
459     HTMLObjectElement *This = impl_from_HTMLDOMNode(iface);
460
461     TRACE("(%p)->(%d)\n", This, id);
462
463     return invoke_plugin_prop(&This->plugin_container, id, lcid, flags, params, res, ei);
464 }
465
466 #undef impl_from_HTMLDOMNode
467
468 static const NodeImplVtbl HTMLObjectElementImplVtbl = {
469     HTMLObjectElement_QI,
470     HTMLObjectElement_destructor,
471     HTMLElement_clone,
472     NULL,
473     NULL,
474     NULL,
475     NULL,
476     NULL,
477     HTMLObjectElement_get_readystate,
478     HTMLObjectElement_get_dispid,
479     HTMLObjectElement_invoke
480 };
481
482 static const tid_t HTMLObjectElement_iface_tids[] = {
483     HTMLELEMENT_TIDS,
484     IHTMLObjectElement_tid,
485     0
486 };
487 static dispex_static_data_t HTMLObjectElement_dispex = {
488     NULL,
489     DispHTMLObjectElement_tid,
490     NULL,
491     HTMLObjectElement_iface_tids
492 };
493
494 HRESULT HTMLObjectElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
495 {
496     HTMLObjectElement *ret;
497     nsresult nsres;
498
499     ret = heap_alloc_zero(sizeof(*ret));
500     if(!ret)
501         return E_OUTOFMEMORY;
502
503     ret->IHTMLObjectElement_iface.lpVtbl = &HTMLObjectElementVtbl;
504     ret->plugin_container.element.node.vtbl = &HTMLObjectElementImplVtbl;
505
506     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLObjectElement, (void**)&ret->nsobject);
507     if(NS_FAILED(nsres)) {
508         ERR("Could not get nsIDOMHTMLObjectElement iface: %08x\n", nsres);
509         heap_free(ret);
510         return E_FAIL;
511     }
512
513     HTMLElement_Init(&ret->plugin_container.element, doc, nselem, &HTMLObjectElement_dispex);
514
515     *elem = &ret->plugin_container.element;
516     return S_OK;
517 }