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