msxml3: Basic support for startElement()/endElement().
[wine/multimedia.git] / dlls / mshtml / pluginhost.c
blob1cfae5f04edd176f4fed578ecdf57f62eec497df
1 /*
2 * Copyright 2010 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "shlobj.h"
30 #include "mshtmdid.h"
32 #include "mshtml_private.h"
33 #include "pluginhost.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 const IID IID_HTMLPluginContainer =
41 {0xbd7a6050,0xb373,0x4f6f,{0xa4,0x93,0xdd,0x40,0xc5,0x23,0xa8,0x6a}};
43 static BOOL check_load_safety(PluginHost *host)
45 DWORD policy_size, policy;
46 struct CONFIRMSAFETY cs;
47 BYTE *ppolicy;
48 HRESULT hres;
50 cs.clsid = host->clsid;
51 cs.pUnk = host->plugin_unk;
52 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
54 hres = IInternetHostSecurityManager_QueryCustomPolicy(&host->doc->IInternetHostSecurityManager_iface,
55 &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
56 if(FAILED(hres))
57 return FALSE;
59 policy = *(DWORD*)ppolicy;
60 CoTaskMemFree(ppolicy);
61 return policy == URLPOLICY_ALLOW;
64 static BOOL check_script_safety(PluginHost *host)
66 DISPPARAMS params = {NULL,NULL,0,0};
67 DWORD policy_size, policy;
68 struct CONFIRMSAFETY cs;
69 BYTE *ppolicy;
70 ULONG err = 0;
71 VARIANT v;
72 HRESULT hres;
74 cs.clsid = host->clsid;
75 cs.pUnk = host->plugin_unk;
76 cs.dwFlags = 0;
78 hres = IInternetHostSecurityManager_QueryCustomPolicy(&host->doc->IInternetHostSecurityManager_iface,
79 &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
80 if(FAILED(hres))
81 return FALSE;
83 policy = *(DWORD*)ppolicy;
84 CoTaskMemFree(ppolicy);
86 if(policy != URLPOLICY_ALLOW)
87 return FALSE;
89 V_VT(&v) = VT_EMPTY;
90 hres = IDispatch_Invoke(host->disp, DISPID_SECURITYCTX, &IID_NULL, 0, DISPATCH_PROPERTYGET, &params, &v, NULL, &err);
91 if(SUCCEEDED(hres)) {
92 FIXME("Handle security ctx %s\n", debugstr_variant(&v));
93 return FALSE;
96 return TRUE;
99 static void update_readystate(PluginHost *host)
101 DISPPARAMS params = {NULL,NULL,0,0};
102 IDispatchEx *dispex;
103 IDispatch *disp;
104 ULONG err = 0;
105 VARIANT v;
106 HRESULT hres;
108 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatchEx, (void**)&dispex);
109 if(SUCCEEDED(hres)) {
110 FIXME("Use IDispatchEx\n");
111 IDispatchEx_Release(dispex);
114 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
115 if(FAILED(hres))
116 return;
118 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, 0, DISPATCH_PROPERTYGET, &params, &v, NULL, &err);
119 IDispatch_Release(disp);
120 if(SUCCEEDED(hres)) {
121 /* FIXME: make plugin readystate affect document readystate */
122 TRACE("readystate = %s\n", debugstr_variant(&v));
123 VariantClear(&v);
127 /* FIXME: We shouldn't need this function and we should embed plugin directly in the main document */
128 static void get_pos_rect(PluginHost *host, RECT *ret)
130 ret->top = 0;
131 ret->left = 0;
132 ret->bottom = host->rect.bottom - host->rect.top;
133 ret->right = host->rect.right - host->rect.left;
136 static void load_prop_bag(PluginHost *host, IPersistPropertyBag *persist_prop_bag)
138 IPropertyBag *prop_bag;
139 HRESULT hres;
141 hres = create_param_prop_bag(host->element->element.nselem, &prop_bag);
142 if(FAILED(hres))
143 return;
145 if(prop_bag && !check_load_safety(host)) {
146 IPropertyBag_Release(prop_bag);
147 prop_bag = NULL;
150 if(prop_bag) {
151 hres = IPersistPropertyBag_Load(persist_prop_bag, prop_bag, NULL);
152 IPropertyBag_Release(prop_bag);
153 if(FAILED(hres))
154 WARN("Load failed: %08x\n", hres);
155 }else {
156 hres = IPersistPropertyBag_InitNew(persist_prop_bag);
157 if(FAILED(hres))
158 WARN("InitNew failed: %08x\n", hres);
162 static void load_plugin(PluginHost *host)
164 IPersistPropertyBag2 *persist_prop_bag2;
165 IPersistPropertyBag *persist_prop_bag;
166 HRESULT hres;
168 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IPersistPropertyBag2, (void**)&persist_prop_bag2);
169 if(SUCCEEDED(hres)) {
170 FIXME("Use IPersistPropertyBag2 iface\n");
171 IPersistPropertyBag2_Release(persist_prop_bag2);
172 return;
175 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IPersistPropertyBag, (void**)&persist_prop_bag);
176 if(SUCCEEDED(hres)) {
177 load_prop_bag(host, persist_prop_bag);
178 IPersistPropertyBag_Release(persist_prop_bag);
179 return;
182 FIXME("No IPersistPropertyBag iface\n");
185 static void activate_plugin(PluginHost *host)
187 IClientSecurity *client_security;
188 IQuickActivate *quick_activate;
189 IOleCommandTarget *cmdtrg;
190 IOleObject *ole_obj;
191 IDispatchEx *dispex;
192 IDispatch *disp;
193 RECT rect;
194 HRESULT hres;
196 if(!host->plugin_unk)
197 return;
199 /* Note native calls QI on plugin for an undocumented IID and CLSID_HTMLDocument */
201 /* FIXME: call FreezeEvents(TRUE) */
203 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IClientSecurity, (void**)&client_security);
204 if(SUCCEEDED(hres)) {
205 FIXME("Handle IClientSecurity\n");
206 IClientSecurity_Release(client_security);
207 return;
210 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IQuickActivate, (void**)&quick_activate);
211 if(SUCCEEDED(hres)) {
212 QACONTAINER container = {sizeof(container)};
213 QACONTROL control = {sizeof(control)};
215 container.pClientSite = &host->IOleClientSite_iface;
216 container.dwAmbientFlags = QACONTAINER_SUPPORTSMNEMONICS|QACONTAINER_MESSAGEREFLECT|QACONTAINER_USERMODE;
217 container.pAdviseSink = &host->IAdviseSinkEx_iface;
218 container.pPropertyNotifySink = &host->IPropertyNotifySink_iface;
220 hres = IQuickActivate_QuickActivate(quick_activate, &container, &control);
221 if(FAILED(hres))
222 FIXME("QuickActivate failed: %08x\n", hres);
223 }else {
224 FIXME("No IQuickActivate\n");
225 return;
228 load_plugin(host);
230 /* NOTE: Native QIs for IViewObjectEx, IActiveScript, an undocumented IID, IOleControl and IRunnableObject */
232 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatchEx, (void**)&dispex);
233 if(SUCCEEDED(hres)) {
234 FIXME("Use IDispatchEx\n");
235 host->disp = (IDispatch*)dispex;
236 }else {
237 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
238 if(SUCCEEDED(hres))
239 host->disp = disp;
240 else
241 TRACE("no IDispatch iface\n");
244 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
245 if(SUCCEEDED(hres)) {
246 FIXME("Use IOleCommandTarget\n");
247 IOleCommandTarget_Release(cmdtrg);
250 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
251 if(FAILED(hres)) {
252 FIXME("Plugin does not support IOleObject\n");
253 return;
256 get_pos_rect(host, &rect);
257 hres = IOleObject_DoVerb(ole_obj, OLEIVERB_INPLACEACTIVATE, NULL, &host->IOleClientSite_iface, 0, host->hwnd, &rect);
258 IOleObject_Release(ole_obj);
259 if(FAILED(hres))
260 WARN("DoVerb failed: %08x\n", hres);
262 if(host->ip_object) {
263 HWND hwnd;
265 hres = IOleInPlaceObject_GetWindow(host->ip_object, &hwnd);
266 if(SUCCEEDED(hres))
267 TRACE("hwnd %p\n", hwnd);
271 void update_plugin_window(PluginHost *host, HWND hwnd, const RECT *rect)
273 BOOL rect_changed = FALSE;
275 if(!hwnd || (host->hwnd && host->hwnd != hwnd)) {
276 FIXME("unhandled hwnd\n");
277 return;
280 TRACE("%p %s\n", hwnd, wine_dbgstr_rect(rect));
282 if(memcmp(rect, &host->rect, sizeof(RECT))) {
283 host->rect = *rect;
284 rect_changed = TRUE;
287 if(!host->hwnd) {
288 host->hwnd = hwnd;
289 activate_plugin(host);
292 if(rect_changed && host->ip_object)
293 IOleInPlaceObject_SetObjectRects(host->ip_object, &host->rect, &host->rect);
296 HRESULT get_plugin_disp(HTMLPluginContainer *plugin_container, IDispatch **ret)
298 PluginHost *host;
300 host = plugin_container->plugin_host;
301 if(!host) {
302 ERR("No plugin host\n");
303 return E_UNEXPECTED;
306 if(!host->disp) {
307 *ret = NULL;
308 return S_OK;
311 if(!check_script_safety(host)) {
312 FIXME("Insecure object\n");
313 return E_FAIL;
316 IDispatch_AddRef(host->disp);
317 *ret = host->disp;
318 return S_OK;
321 HRESULT get_plugin_dispid(HTMLPluginContainer *plugin_container, WCHAR *name, DISPID *ret)
323 IDispatch *disp;
324 DISPID id;
325 DWORD i;
326 HRESULT hres;
328 if(!plugin_container->plugin_host) {
329 WARN("no plugin host\n");
330 return DISP_E_UNKNOWNNAME;
333 disp = plugin_container->plugin_host->disp;
334 if(!disp)
335 return DISP_E_UNKNOWNNAME;
337 hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, &id);
338 if(FAILED(hres)) {
339 TRACE("no prop %s\n", debugstr_w(name));
340 return DISP_E_UNKNOWNNAME;
343 for(i=0; i < plugin_container->props_len; i++) {
344 if(id == plugin_container->props[i]) {
345 *ret = MSHTML_DISPID_CUSTOM_MIN+i;
346 return S_OK;
350 if(!plugin_container->props) {
351 plugin_container->props = heap_alloc(8*sizeof(DISPID));
352 if(!plugin_container->props)
353 return E_OUTOFMEMORY;
354 plugin_container->props_size = 8;
355 }else if(plugin_container->props_len == plugin_container->props_size) {
356 DISPID *new_props;
358 new_props = heap_realloc(plugin_container->props, plugin_container->props_size*2);
359 if(!new_props)
360 return E_OUTOFMEMORY;
362 plugin_container->props = new_props;
363 plugin_container->props_size *= 2;
366 plugin_container->props[plugin_container->props_len] = id;
367 *ret = MSHTML_DISPID_CUSTOM_MIN+plugin_container->props_len;
368 plugin_container->props_len++;
369 return S_OK;
372 HRESULT invoke_plugin_prop(HTMLPluginContainer *plugin_container, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
373 VARIANT *res, EXCEPINFO *ei)
375 PluginHost *host;
377 host = plugin_container->plugin_host;
378 if(!host || !host->disp) {
379 FIXME("Called with no disp\n");
380 return E_UNEXPECTED;
383 if(!check_script_safety(host)) {
384 FIXME("Insecure object\n");
385 return E_FAIL;
388 if(id < MSHTML_DISPID_CUSTOM_MIN || id > MSHTML_DISPID_CUSTOM_MIN + plugin_container->props_len) {
389 ERR("Invalid id\n");
390 return E_FAIL;
393 return IDispatch_Invoke(host->disp, plugin_container->props[id-MSHTML_DISPID_CUSTOM_MIN], &IID_NULL,
394 lcid, flags, params, res, ei, NULL);
397 static inline PluginHost *impl_from_IOleClientSite(IOleClientSite *iface)
399 return CONTAINING_RECORD(iface, PluginHost, IOleClientSite_iface);
402 static HRESULT WINAPI PHClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
404 PluginHost *This = impl_from_IOleClientSite(iface);
406 if(IsEqualGUID(&IID_IUnknown, riid)) {
407 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
408 *ppv = &This->IOleClientSite_iface;
409 }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
410 TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
411 *ppv = &This->IOleClientSite_iface;
412 }else if(IsEqualGUID(&IID_IAdviseSink, riid)) {
413 TRACE("(%p)->(IID_IAdviseSink %p)\n", This, ppv);
414 *ppv = &This->IAdviseSinkEx_iface;
415 }else if(IsEqualGUID(&IID_IAdviseSinkEx, riid)) {
416 TRACE("(%p)->(IID_IAdviseSinkEx %p)\n", This, ppv);
417 *ppv = &This->IAdviseSinkEx_iface;
418 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
419 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv);
420 *ppv = &This->IPropertyNotifySink_iface;
421 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
422 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
423 *ppv = &This->IDispatch_iface;
424 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
425 TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
426 *ppv = &This->IOleInPlaceSiteEx_iface;
427 }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
428 TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
429 *ppv = &This->IOleInPlaceSiteEx_iface;
430 }else if(IsEqualGUID(&IID_IOleInPlaceSiteEx, riid)) {
431 TRACE("(%p)->(IID_IOleInPlaceSiteEx %p)\n", This, ppv);
432 *ppv = &This->IOleInPlaceSiteEx_iface;
433 }else if(IsEqualGUID(&IID_IOleControlSite, riid)) {
434 TRACE("(%p)->(IID_IOleControlSite %p)\n", This, ppv);
435 *ppv = &This->IOleControlSite_iface;
436 }else if(IsEqualGUID(&IID_IBindHost, riid)) {
437 TRACE("(%p)->(IID_IBindHost %p)\n", This, ppv);
438 *ppv = &This->IBindHost_iface;
439 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
440 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
441 *ppv = &This->IServiceProvider_iface;
442 }else {
443 WARN("Unsupported interface %s\n", debugstr_guid(riid));
444 *ppv = NULL;
445 return E_NOINTERFACE;
448 IOleClientSite_AddRef((IUnknown*)*ppv);
449 return S_OK;
452 static ULONG WINAPI PHClientSite_AddRef(IOleClientSite *iface)
454 PluginHost *This = impl_from_IOleClientSite(iface);
455 LONG ref = InterlockedIncrement(&This->ref);
457 TRACE("(%p) ref=%d\n", This, ref);
459 return ref;
462 static ULONG WINAPI PHClientSite_Release(IOleClientSite *iface)
464 PluginHost *This = impl_from_IOleClientSite(iface);
465 LONG ref = InterlockedDecrement(&This->ref);
467 TRACE("(%p) ref=%d\n", This, ref);
469 if(!ref) {
470 if(This->disp)
471 IDispatch_Release(This->disp);
472 if(This->ip_object)
473 IOleInPlaceObject_Release(This->ip_object);
474 list_remove(&This->entry);
475 if(This->element)
476 This->element->plugin_host = NULL;
477 if(This->plugin_unk)
478 IUnknown_Release(This->plugin_unk);
479 heap_free(This);
482 return ref;
485 static HRESULT WINAPI PHClientSite_SaveObject(IOleClientSite *iface)
487 PluginHost *This = impl_from_IOleClientSite(iface);
488 FIXME("(%p)\n", This);
489 return E_NOTIMPL;
492 static HRESULT WINAPI PHClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
493 DWORD dwWhichMoniker, IMoniker **ppmk)
495 PluginHost *This = impl_from_IOleClientSite(iface);
497 TRACE("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
499 switch(dwWhichMoniker) {
500 case OLEWHICHMK_CONTAINER:
501 if(!This->doc || !This->doc->basedoc.window || !This->doc->basedoc.window->mon) {
502 FIXME("no moniker\n");
503 return E_UNEXPECTED;
506 *ppmk = This->doc->basedoc.window->mon;
507 IMoniker_AddRef(*ppmk);
508 break;
509 default:
510 FIXME("which %d\n", dwWhichMoniker);
511 return E_NOTIMPL;
514 return S_OK;
517 static HRESULT WINAPI PHClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
519 PluginHost *This = impl_from_IOleClientSite(iface);
521 TRACE("(%p)->(%p)\n", This, ppContainer);
523 if(!This->doc) {
524 ERR("Called on detached object\n");
525 return E_UNEXPECTED;
528 *ppContainer = &This->doc->basedoc.IOleContainer_iface;
529 IOleContainer_AddRef(*ppContainer);
530 return S_OK;
533 static HRESULT WINAPI PHClientSite_ShowObject(IOleClientSite *iface)
535 PluginHost *This = impl_from_IOleClientSite(iface);
537 TRACE("(%p)\n", This);
539 return S_OK;
542 static HRESULT WINAPI PHClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
544 PluginHost *This = impl_from_IOleClientSite(iface);
545 FIXME("(%p)->(%x)\n", This, fShow);
546 return E_NOTIMPL;
549 static HRESULT WINAPI PHClientSite_RequestNewObjectLayout(IOleClientSite *iface)
551 PluginHost *This = impl_from_IOleClientSite(iface);
552 FIXME("(%p)\n", This);
553 return E_NOTIMPL;
556 static const IOleClientSiteVtbl OleClientSiteVtbl = {
557 PHClientSite_QueryInterface,
558 PHClientSite_AddRef,
559 PHClientSite_Release,
560 PHClientSite_SaveObject,
561 PHClientSite_GetMoniker,
562 PHClientSite_GetContainer,
563 PHClientSite_ShowObject,
564 PHClientSite_OnShowWindow,
565 PHClientSite_RequestNewObjectLayout
568 static inline PluginHost *impl_from_IAdviseSinkEx(IAdviseSinkEx *iface)
570 return CONTAINING_RECORD(iface, PluginHost, IAdviseSinkEx_iface);
573 static HRESULT WINAPI PHAdviseSinkEx_QueryInterface(IAdviseSinkEx *iface, REFIID riid, void **ppv)
575 PluginHost *This = impl_from_IAdviseSinkEx(iface);
576 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
579 static ULONG WINAPI PHAdviseSinkEx_AddRef(IAdviseSinkEx *iface)
581 PluginHost *This = impl_from_IAdviseSinkEx(iface);
582 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
585 static ULONG WINAPI PHAdviseSinkEx_Release(IAdviseSinkEx *iface)
587 PluginHost *This = impl_from_IAdviseSinkEx(iface);
588 return IOleClientSite_Release(&This->IOleClientSite_iface);
591 static void WINAPI PHAdviseSinkEx_OnDataChange(IAdviseSinkEx *iface, FORMATETC *pFormatetc, STGMEDIUM *pStgMedium)
593 PluginHost *This = impl_from_IAdviseSinkEx(iface);
594 FIXME("(%p)->(%p %p)\n", This, pFormatetc, pStgMedium);
597 static void WINAPI PHAdviseSinkEx_OnViewChange(IAdviseSinkEx *iface, DWORD dwAspect, LONG lindex)
599 PluginHost *This = impl_from_IAdviseSinkEx(iface);
600 FIXME("(%p)->(%d %d)\n", This, dwAspect, lindex);
603 static void WINAPI PHAdviseSinkEx_OnRename(IAdviseSinkEx *iface, IMoniker *pmk)
605 PluginHost *This = impl_from_IAdviseSinkEx(iface);
606 FIXME("(%p)->(%p)\n", This, pmk);
609 static void WINAPI PHAdviseSinkEx_OnSave(IAdviseSinkEx *iface)
611 PluginHost *This = impl_from_IAdviseSinkEx(iface);
612 FIXME("(%p)\n", This);
615 static void WINAPI PHAdviseSinkEx_OnClose(IAdviseSinkEx *iface)
617 PluginHost *This = impl_from_IAdviseSinkEx(iface);
618 FIXME("(%p)\n", This);
621 static void WINAPI PHAdviseSinkEx_OnViewStatusChange(IAdviseSinkEx *iface, DWORD dwViewStatus)
623 PluginHost *This = impl_from_IAdviseSinkEx(iface);
624 FIXME("(%p)->(%d)\n", This, dwViewStatus);
627 static const IAdviseSinkExVtbl AdviseSinkExVtbl = {
628 PHAdviseSinkEx_QueryInterface,
629 PHAdviseSinkEx_AddRef,
630 PHAdviseSinkEx_Release,
631 PHAdviseSinkEx_OnDataChange,
632 PHAdviseSinkEx_OnViewChange,
633 PHAdviseSinkEx_OnRename,
634 PHAdviseSinkEx_OnSave,
635 PHAdviseSinkEx_OnClose,
636 PHAdviseSinkEx_OnViewStatusChange
639 static inline PluginHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
641 return CONTAINING_RECORD(iface, PluginHost, IPropertyNotifySink_iface);
644 static HRESULT WINAPI PHPropertyNotifySink_QueryInterface(IPropertyNotifySink *iface, REFIID riid, void **ppv)
646 PluginHost *This = impl_from_IPropertyNotifySink(iface);
647 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
650 static ULONG WINAPI PHPropertyNotifySink_AddRef(IPropertyNotifySink *iface)
652 PluginHost *This = impl_from_IPropertyNotifySink(iface);
653 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
656 static ULONG WINAPI PHPropertyNotifySink_Release(IPropertyNotifySink *iface)
658 PluginHost *This = impl_from_IPropertyNotifySink(iface);
659 return IOleClientSite_Release(&This->IOleClientSite_iface);
662 static HRESULT WINAPI PHPropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
664 PluginHost *This = impl_from_IPropertyNotifySink(iface);
666 TRACE("(%p)->(%d)\n", This, dispID);
668 switch(dispID) {
669 case DISPID_READYSTATE:
670 update_readystate(This);
671 break;
672 default :
673 FIXME("Unimplemented dispID %d\n", dispID);
674 return E_NOTIMPL;
677 return S_OK;
680 static HRESULT WINAPI PHPropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
682 PluginHost *This = impl_from_IPropertyNotifySink(iface);
683 FIXME("(%p)->(%d)\n", This, dispID);
684 return E_NOTIMPL;
687 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
688 PHPropertyNotifySink_QueryInterface,
689 PHPropertyNotifySink_AddRef,
690 PHPropertyNotifySink_Release,
691 PHPropertyNotifySink_OnChanged,
692 PHPropertyNotifySink_OnRequestEdit
695 static inline PluginHost *impl_from_IDispatch(IDispatch *iface)
697 return CONTAINING_RECORD(iface, PluginHost, IDispatch_iface);
700 static HRESULT WINAPI PHDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
702 PluginHost *This = impl_from_IDispatch(iface);
703 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
706 static ULONG WINAPI PHDispatch_AddRef(IDispatch *iface)
708 PluginHost *This = impl_from_IDispatch(iface);
709 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
712 static ULONG WINAPI PHDispatch_Release(IDispatch *iface)
714 PluginHost *This = impl_from_IDispatch(iface);
715 return IOleClientSite_Release(&This->IOleClientSite_iface);
718 static HRESULT WINAPI PHDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
720 PluginHost *This = impl_from_IDispatch(iface);
721 FIXME("(%p)->(%p)\n", This, pctinfo);
722 return E_NOTIMPL;
725 static HRESULT WINAPI PHDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo,
726 LCID lcid, ITypeInfo **ppTInfo)
728 PluginHost *This = impl_from_IDispatch(iface);
729 FIXME("(%p)->(%d %d %p)\n", This, iTInfo, lcid, ppTInfo);
730 return E_NOTIMPL;
733 static HRESULT WINAPI PHDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid,
734 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
736 PluginHost *This = impl_from_IDispatch(iface);
737 FIXME("(%p)->(%s %p %d %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
738 return E_NOTIMPL;
741 static HRESULT WINAPI PHDispatch_Invoke(IDispatch *iface, DISPID dispid, REFIID riid, LCID lcid,
742 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
744 PluginHost *This = impl_from_IDispatch(iface);
745 FIXME("(%p)->(%d %x %p %p)\n", This, dispid, wFlags, pDispParams, pVarResult);
746 return E_NOTIMPL;
749 static const IDispatchVtbl DispatchVtbl = {
750 PHDispatch_QueryInterface,
751 PHDispatch_AddRef,
752 PHDispatch_Release,
753 PHDispatch_GetTypeInfoCount,
754 PHDispatch_GetTypeInfo,
755 PHDispatch_GetIDsOfNames,
756 PHDispatch_Invoke
759 static inline PluginHost *impl_from_IOleInPlaceSiteEx(IOleInPlaceSiteEx *iface)
761 return CONTAINING_RECORD(iface, PluginHost, IOleInPlaceSiteEx_iface);
764 static HRESULT WINAPI PHInPlaceSite_QueryInterface(IOleInPlaceSiteEx *iface, REFIID riid, void **ppv)
766 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
767 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
770 static ULONG WINAPI PHInPlaceSite_AddRef(IOleInPlaceSiteEx *iface)
772 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
773 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
776 static ULONG WINAPI PHInPlaceSite_Release(IOleInPlaceSiteEx *iface)
778 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
779 return IOleClientSite_Release(&This->IOleClientSite_iface);
782 static HRESULT WINAPI PHInPlaceSite_GetWindow(IOleInPlaceSiteEx *iface, HWND *phwnd)
784 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
786 TRACE("(%p)->(%p)\n", This, phwnd);
788 *phwnd = This->hwnd;
789 return S_OK;
792 static HRESULT WINAPI PHInPlaceSite_ContextSensitiveHelp(IOleInPlaceSiteEx *iface, BOOL fEnterMode)
794 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
795 FIXME("(%p)->(%x)\n", This, fEnterMode);
796 return E_NOTIMPL;
799 static HRESULT WINAPI PHInPlaceSite_CanInPlaceActivate(IOleInPlaceSiteEx *iface)
801 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
802 FIXME("(%p)\n", This);
803 return E_NOTIMPL;
806 static HRESULT WINAPI PHInPlaceSite_OnInPlaceActivate(IOleInPlaceSiteEx *iface)
808 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
809 FIXME("(%p)\n", This);
810 return E_NOTIMPL;
813 static HRESULT WINAPI PHInPlaceSite_OnUIActivate(IOleInPlaceSiteEx *iface)
815 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
816 DISPPARAMS args = {NULL, NULL, 0, 0};
817 IDispatch *disp;
818 ULONG err = 0;
819 VARIANT res;
820 HRESULT hres;
822 TRACE("(%p)\n", This);
824 if(!This->plugin_unk) {
825 ERR("No plugin object\n");
826 return E_UNEXPECTED;
829 This->ui_active = TRUE;
831 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IDispatch, (void**)&disp);
832 if(FAILED(hres)) {
833 FIXME("Could not get IDispatch iface: %08x\n", hres);
834 return hres;
837 V_VT(&res) = VT_EMPTY;
838 hres = IDispatch_Invoke(disp, DISPID_ENABLED, &IID_NULL, 0/*FIXME*/, DISPATCH_PROPERTYGET, &args, &res, NULL, &err);
839 IDispatch_Release(disp);
840 if(SUCCEEDED(hres)) {
841 FIXME("Got enabled %s\n", debugstr_variant(&res));
842 VariantClear(&res);
845 return S_OK;
848 static HRESULT WINAPI PHInPlaceSite_GetWindowContext(IOleInPlaceSiteEx *iface,
849 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, RECT *lprcPosRect,
850 RECT *lprcClipRect, OLEINPLACEFRAMEINFO *frame_info)
852 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
853 IOleInPlaceUIWindow *ip_window;
854 IOleInPlaceFrame *ip_frame;
855 RECT pr, cr;
856 HRESULT hres;
858 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, frame_info);
860 if(!This->doc || !This->doc->basedoc.doc_obj || !This->doc->basedoc.doc_obj->ipsite) {
861 FIXME("No ipsite\n");
862 return E_UNEXPECTED;
865 hres = IOleInPlaceSite_GetWindowContext(This->doc->basedoc.doc_obj->ipsite, &ip_frame, &ip_window, &pr, &cr, frame_info);
866 if(FAILED(hres)) {
867 WARN("GetWindowContext failed: %08x\n", hres);
868 return hres;
871 if(ip_window)
872 IOleInPlaceUIWindow_Release(ip_window);
873 if(ip_frame)
874 IOleInPlaceFrame_Release(ip_frame);
876 hres = create_ip_frame(&ip_frame);
877 if(FAILED(hres))
878 return hres;
880 hres = create_ip_window(ppDoc);
881 if(FAILED(hres))
882 return hres;
884 *ppFrame = ip_frame;
885 *lprcPosRect = This->rect;
886 *lprcClipRect = This->rect;
887 return S_OK;
890 static HRESULT WINAPI PHInPlaceSite_Scroll(IOleInPlaceSiteEx *iface, SIZE scrollExtent)
892 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
893 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
894 return E_NOTIMPL;
897 static HRESULT WINAPI PHInPlaceSite_OnUIDeactivate(IOleInPlaceSiteEx *iface, BOOL fUndoable)
899 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
900 FIXME("(%p)->(%x)\n", This, fUndoable);
901 return E_NOTIMPL;
904 static HRESULT WINAPI PHInPlaceSite_OnInPlaceDeactivate(IOleInPlaceSiteEx *iface)
906 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
908 TRACE("(%p)\n", This);
910 if(This->ip_object) {
911 IOleInPlaceObject_Release(This->ip_object);
912 This->ip_object = NULL;
915 return S_OK;
918 static HRESULT WINAPI PHInPlaceSite_DiscardUndoState(IOleInPlaceSiteEx *iface)
920 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
921 FIXME("(%p)\n", This);
922 return E_NOTIMPL;
925 static HRESULT WINAPI PHInPlaceSite_DeactivateAndUndo(IOleInPlaceSiteEx *iface)
927 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
928 FIXME("(%p)\n", This);
929 return E_NOTIMPL;
932 static HRESULT WINAPI PHInPlaceSite_OnPosRectChange(IOleInPlaceSiteEx *iface, LPCRECT lprcPosRect)
934 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
935 FIXME("(%p)->(%p)\n", This, lprcPosRect);
936 return E_NOTIMPL;
939 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceActivateEx(IOleInPlaceSiteEx *iface, BOOL *pfNoRedraw, DWORD dwFlags)
941 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
942 HWND hwnd;
943 HRESULT hres;
945 TRACE("(%p)->(%p %x)\n", This, pfNoRedraw, dwFlags);
947 if(This->ip_object)
948 return S_OK;
950 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IOleInPlaceObject, (void**)&This->ip_object);
951 if(FAILED(hres))
952 return hres;
954 hres = IOleInPlaceObject_GetWindow(This->ip_object, &hwnd);
955 if(SUCCEEDED(hres))
956 FIXME("Use hwnd %p\n", hwnd);
958 *pfNoRedraw = FALSE;
959 return S_OK;
962 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface, BOOL fNoRedraw)
964 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
965 FIXME("(%p)->(%x)\n", This, fNoRedraw);
966 return E_NOTIMPL;
969 static HRESULT WINAPI PHInPlaceSiteEx_RequestUIActivate(IOleInPlaceSiteEx *iface)
971 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
972 FIXME("(%p)\n", This);
973 return E_NOTIMPL;
976 static const IOleInPlaceSiteExVtbl OleInPlaceSiteExVtbl = {
977 PHInPlaceSite_QueryInterface,
978 PHInPlaceSite_AddRef,
979 PHInPlaceSite_Release,
980 PHInPlaceSite_GetWindow,
981 PHInPlaceSite_ContextSensitiveHelp,
982 PHInPlaceSite_CanInPlaceActivate,
983 PHInPlaceSite_OnInPlaceActivate,
984 PHInPlaceSite_OnUIActivate,
985 PHInPlaceSite_GetWindowContext,
986 PHInPlaceSite_Scroll,
987 PHInPlaceSite_OnUIDeactivate,
988 PHInPlaceSite_OnInPlaceDeactivate,
989 PHInPlaceSite_DiscardUndoState,
990 PHInPlaceSite_DeactivateAndUndo,
991 PHInPlaceSite_OnPosRectChange,
992 PHInPlaceSiteEx_OnInPlaceActivateEx,
993 PHInPlaceSiteEx_OnInPlaceDeactivateEx,
994 PHInPlaceSiteEx_RequestUIActivate
997 static inline PluginHost *impl_from_IOleControlSite(IOleControlSite *iface)
999 return CONTAINING_RECORD(iface, PluginHost, IOleControlSite_iface);
1002 static HRESULT WINAPI PHControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
1004 PluginHost *This = impl_from_IOleControlSite(iface);
1005 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1008 static ULONG WINAPI PHControlSite_AddRef(IOleControlSite *iface)
1010 PluginHost *This = impl_from_IOleControlSite(iface);
1011 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1014 static ULONG WINAPI PHControlSite_Release(IOleControlSite *iface)
1016 PluginHost *This = impl_from_IOleControlSite(iface);
1017 return IOleClientSite_Release(&This->IOleClientSite_iface);
1020 static HRESULT WINAPI PHControlSite_OnControlInfoChanged(IOleControlSite *iface)
1022 PluginHost *This = impl_from_IOleControlSite(iface);
1023 FIXME("(%p)\n", This);
1024 return E_NOTIMPL;
1027 static HRESULT WINAPI PHControlSite_LockInPlaceActive(IOleControlSite *iface, BOOL fLock)
1029 PluginHost *This = impl_from_IOleControlSite(iface);
1030 FIXME("(%p)->(%x)\n", This, fLock);
1031 return E_NOTIMPL;
1034 static HRESULT WINAPI PHControlSite_GetExtendedControl(IOleControlSite *iface, IDispatch **ppDisp)
1036 PluginHost *This = impl_from_IOleControlSite(iface);
1037 FIXME("(%p)->(%p)\n", This, ppDisp);
1038 return E_NOTIMPL;
1041 static HRESULT WINAPI PHControlSite_TransformCoords(IOleControlSite *iface, POINTL *pPtlHimetric, POINTF *pPtfContainer, DWORD dwFlags)
1043 PluginHost *This = impl_from_IOleControlSite(iface);
1044 FIXME("(%p)->(%p %p %x)\n", This, pPtlHimetric, pPtfContainer, dwFlags);
1045 return E_NOTIMPL;
1048 static HRESULT WINAPI PHControlSite_TranslateAccelerator(IOleControlSite *iface, MSG *pMsg, DWORD grfModifiers)
1050 PluginHost *This = impl_from_IOleControlSite(iface);
1051 FIXME("(%p)->(%x)\n", This, grfModifiers);
1052 return E_NOTIMPL;
1055 static HRESULT WINAPI PHControlSite_OnFocus(IOleControlSite *iface, BOOL fGotFocus)
1057 PluginHost *This = impl_from_IOleControlSite(iface);
1058 FIXME("(%p)->(%x)\n", This, fGotFocus);
1059 return E_NOTIMPL;
1062 static HRESULT WINAPI PHControlSite_ShowPropertyFrame(IOleControlSite *iface)
1064 PluginHost *This = impl_from_IOleControlSite(iface);
1065 FIXME("(%p)\n", This);
1066 return E_NOTIMPL;
1069 static const IOleControlSiteVtbl OleControlSiteVtbl = {
1070 PHControlSite_QueryInterface,
1071 PHControlSite_AddRef,
1072 PHControlSite_Release,
1073 PHControlSite_OnControlInfoChanged,
1074 PHControlSite_LockInPlaceActive,
1075 PHControlSite_GetExtendedControl,
1076 PHControlSite_TransformCoords,
1077 PHControlSite_TranslateAccelerator,
1078 PHControlSite_OnFocus,
1079 PHControlSite_ShowPropertyFrame
1082 static inline PluginHost *impl_from_IBindHost(IBindHost *iface)
1084 return CONTAINING_RECORD(iface, PluginHost, IBindHost_iface);
1087 static HRESULT WINAPI PHBindHost_QueryInterface(IBindHost *iface, REFIID riid, void **ppv)
1089 PluginHost *This = impl_from_IBindHost(iface);
1090 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1093 static ULONG WINAPI PHBindHost_AddRef(IBindHost *iface)
1095 PluginHost *This = impl_from_IBindHost(iface);
1096 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1099 static ULONG WINAPI PHBindHost_Release(IBindHost *iface)
1101 PluginHost *This = impl_from_IBindHost(iface);
1102 return IOleClientSite_Release(&This->IOleClientSite_iface);
1105 static HRESULT WINAPI PHBindHost_CreateMoniker(IBindHost *iface, LPOLESTR szName, IBindCtx *pBC, IMoniker **ppmk, DWORD dwReserved)
1107 PluginHost *This = impl_from_IBindHost(iface);
1109 TRACE("(%p)->(%s %p %p %x)\n", This, debugstr_w(szName), pBC, ppmk, dwReserved);
1111 if(!This->doc || !This->doc->basedoc.window || !This->doc->basedoc.window->mon) {
1112 FIXME("no moniker\n");
1113 return E_UNEXPECTED;
1116 return CreateURLMoniker(This->doc->basedoc.window->mon, szName, ppmk);
1119 static HRESULT WINAPI PHBindHost_MonikerBindToStorage(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1120 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1122 PluginHost *This = impl_from_IBindHost(iface);
1123 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1124 return E_NOTIMPL;
1127 static HRESULT WINAPI PHBindHost_MonikerBindToObject(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1128 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1130 PluginHost *This = impl_from_IBindHost(iface);
1131 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1132 return E_NOTIMPL;
1135 static const IBindHostVtbl BindHostVtbl = {
1136 PHBindHost_QueryInterface,
1137 PHBindHost_AddRef,
1138 PHBindHost_Release,
1139 PHBindHost_CreateMoniker,
1140 PHBindHost_MonikerBindToStorage,
1141 PHBindHost_MonikerBindToObject
1144 static inline PluginHost *impl_from_IServiceProvider(IServiceProvider *iface)
1146 return CONTAINING_RECORD(iface, PluginHost, IServiceProvider_iface);
1149 static HRESULT WINAPI PHServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1151 PluginHost *This = impl_from_IServiceProvider(iface);
1152 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1155 static ULONG WINAPI PHServiceProvider_AddRef(IServiceProvider *iface)
1157 PluginHost *This = impl_from_IServiceProvider(iface);
1158 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1161 static ULONG WINAPI PHServiceProvider_Release(IServiceProvider *iface)
1163 PluginHost *This = impl_from_IServiceProvider(iface);
1164 return IOleClientSite_Release(&This->IOleClientSite_iface);
1167 static HRESULT WINAPI PHServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
1169 PluginHost *This = impl_from_IServiceProvider(iface);
1171 if(IsEqualGUID(guidService, &SID_SBindHost)) {
1172 TRACE("SID_SBindHost service\n");
1173 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1176 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1178 if(!This->doc || !This->doc->basedoc.window) {
1179 *ppv = NULL;
1180 return E_NOINTERFACE;
1183 return IServiceProvider_QueryService(&This->doc->basedoc.window->IServiceProvider_iface,
1184 guidService, riid, ppv);
1187 static const IServiceProviderVtbl ServiceProviderVtbl = {
1188 PHServiceProvider_QueryInterface,
1189 PHServiceProvider_AddRef,
1190 PHServiceProvider_Release,
1191 PHServiceProvider_QueryService
1194 static HRESULT assoc_element(PluginHost *host, HTMLDocumentNode *doc, nsIDOMElement *nselem)
1196 HTMLPluginContainer *container_elem;
1197 HTMLDOMNode *node;
1198 HRESULT hres;
1200 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1201 if(FAILED(hres))
1202 return hres;
1204 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
1205 (void**)&container_elem);
1206 if(FAILED(hres)) {
1207 ERR("Not an object element\n");
1208 return hres;
1211 container_elem->plugin_host = host;
1212 host->element = container_elem;
1213 return S_OK;
1216 void detach_plugin_host(PluginHost *host)
1218 HRESULT hres;
1220 TRACE("%p\n", host);
1222 if(!host->doc)
1223 return;
1225 if(host->ip_object) {
1226 if(host->ui_active)
1227 IOleInPlaceObject_UIDeactivate(host->ip_object);
1228 IOleInPlaceObject_InPlaceDeactivate(host->ip_object);
1231 if(host->plugin_unk) {
1232 IOleObject *ole_obj;
1234 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
1235 if(SUCCEEDED(hres)) {
1236 if(!host->ip_object)
1237 IOleObject_Close(ole_obj, OLECLOSE_NOSAVE);
1238 IOleObject_SetClientSite(ole_obj, NULL);
1239 IOleObject_Release(ole_obj);
1243 if(host->element) {
1244 host->element->plugin_host = NULL;
1245 host->element = NULL;
1248 list_remove(&host->entry);
1249 host->doc = NULL;
1252 HRESULT create_plugin_host(HTMLDocumentNode *doc, nsIDOMElement *nselem, IUnknown *unk, const CLSID *clsid, PluginHost **ret)
1254 PluginHost *host;
1255 HRESULT hres;
1257 host = heap_alloc_zero(sizeof(*host));
1258 if(!host)
1259 return E_OUTOFMEMORY;
1261 host->IOleClientSite_iface.lpVtbl = &OleClientSiteVtbl;
1262 host->IAdviseSinkEx_iface.lpVtbl = &AdviseSinkExVtbl;
1263 host->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1264 host->IDispatch_iface.lpVtbl = &DispatchVtbl;
1265 host->IOleInPlaceSiteEx_iface.lpVtbl = &OleInPlaceSiteExVtbl;
1266 host->IOleControlSite_iface.lpVtbl = &OleControlSiteVtbl;
1267 host->IBindHost_iface.lpVtbl = &BindHostVtbl;
1268 host->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
1270 host->ref = 1;
1272 hres = assoc_element(host, doc, nselem);
1273 if(FAILED(hres)) {
1274 heap_free(host);
1275 return hres;
1278 IUnknown_AddRef(unk);
1279 host->plugin_unk = unk;
1280 host->clsid = *clsid;
1282 host->doc = doc;
1283 list_add_tail(&doc->plugin_hosts, &host->entry);
1285 *ret = host;
1286 return S_OK;