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