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
32 #include "mshtml_private.h"
33 #include "pluginhost.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 const IID IID_HTMLPluginContainer =
40 {0xbd7a6050,0xb373,0x4f6f,{0xa4,0x93,0xdd,0x40,0xc5,0x23,0xa8,0x6a}};
42 static BOOL check_load_safety(PluginHost *host)
44 DWORD policy_size, policy;
45 struct CONFIRMSAFETY cs;
49 cs.clsid = host->clsid;
50 cs.pUnk = host->plugin_unk;
51 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
53 hres = IInternetHostSecurityManager_QueryCustomPolicy(&host->doc->IInternetHostSecurityManager_iface,
54 &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
58 policy = *(DWORD*)ppolicy;
59 CoTaskMemFree(ppolicy);
60 return policy == URLPOLICY_ALLOW;
63 static BOOL check_script_safety(PluginHost *host)
65 DISPPARAMS params = {NULL,NULL,0,0};
66 DWORD policy_size, policy;
67 struct CONFIRMSAFETY cs;
73 cs.clsid = host->clsid;
74 cs.pUnk = host->plugin_unk;
77 hres = IInternetHostSecurityManager_QueryCustomPolicy(&host->doc->IInternetHostSecurityManager_iface,
78 &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
82 policy = *(DWORD*)ppolicy;
83 CoTaskMemFree(ppolicy);
85 if(policy != URLPOLICY_ALLOW)
89 hres = IDispatch_Invoke(host->disp, DISPID_SECURITYCTX, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, &v, NULL, &err);
91 FIXME("Handle security ctx %s\n", debugstr_variant(&v));
98 static void update_readystate(PluginHost *host)
100 DISPPARAMS params = {NULL,NULL,0,0};
107 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatchEx, (void**)&dispex);
108 if(SUCCEEDED(hres)) {
109 FIXME("Use IDispatchEx\n");
110 IDispatchEx_Release(dispex);
113 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
117 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, &v, NULL, &err);
118 IDispatch_Release(disp);
119 if(SUCCEEDED(hres)) {
120 /* FIXME: make plugin readystate affect document readystate */
121 TRACE("readystate = %s\n", debugstr_variant(&v));
126 /* FIXME: We shouldn't need this function and we should embed plugin directly in the main document */
127 static void get_pos_rect(PluginHost *host, RECT *ret)
131 ret->bottom = host->rect.bottom - host->rect.top;
132 ret->right = host->rect.right - host->rect.left;
135 static void load_prop_bag(PluginHost *host, IPersistPropertyBag *persist_prop_bag)
137 IPropertyBag *prop_bag;
140 hres = create_param_prop_bag(host->element->element.nselem, &prop_bag);
144 if(prop_bag && !check_load_safety(host)) {
145 IPropertyBag_Release(prop_bag);
150 hres = IPersistPropertyBag_Load(persist_prop_bag, prop_bag, NULL);
151 IPropertyBag_Release(prop_bag);
153 WARN("Load failed: %08x\n", hres);
155 hres = IPersistPropertyBag_InitNew(persist_prop_bag);
157 WARN("InitNew failed: %08x\n", hres);
161 static void load_plugin(PluginHost *host)
163 IPersistPropertyBag2 *persist_prop_bag2;
164 IPersistPropertyBag *persist_prop_bag;
167 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IPersistPropertyBag2, (void**)&persist_prop_bag2);
168 if(SUCCEEDED(hres)) {
169 FIXME("Use IPersistPropertyBag2 iface\n");
170 IPersistPropertyBag2_Release(persist_prop_bag2);
174 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IPersistPropertyBag, (void**)&persist_prop_bag);
175 if(SUCCEEDED(hres)) {
176 load_prop_bag(host, persist_prop_bag);
177 IPersistPropertyBag_Release(persist_prop_bag);
181 FIXME("No IPersistPropertyBag iface\n");
184 static void activate_plugin(PluginHost *host)
186 IClientSecurity *client_security;
187 IQuickActivate *quick_activate;
188 IOleObject *ole_obj = NULL;
189 IOleCommandTarget *cmdtrg;
190 IViewObjectEx *view_obj;
196 if(!host->plugin_unk)
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);
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 TRACE("Using IQuickActivate\n");
217 container.pClientSite = &host->IOleClientSite_iface;
218 container.dwAmbientFlags = QACONTAINER_SUPPORTSMNEMONICS|QACONTAINER_MESSAGEREFLECT|QACONTAINER_USERMODE;
219 container.pAdviseSink = &host->IAdviseSinkEx_iface;
220 container.pPropertyNotifySink = &host->IPropertyNotifySink_iface;
222 hres = IQuickActivate_QuickActivate(quick_activate, &container, &control);
223 IQuickActivate_Release(quick_activate);
225 FIXME("QuickActivate failed: %08x\n", hres);
229 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
230 if(SUCCEEDED(hres)) {
231 hres = IOleObject_GetMiscStatus(ole_obj, DVASPECT_CONTENT, &status);
232 TRACE("GetMiscStatus returned %08x %x\n", hres, status);
234 hres = IOleObject_SetClientSite(ole_obj, &host->IOleClientSite_iface);
235 IOleObject_Release(ole_obj);
237 FIXME("SetClientSite failed: %08x\n", hres);
241 TRACE("Plugin does not support IOleObject\n");
248 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IViewObjectEx, (void**)&view_obj);
249 if(SUCCEEDED(hres)) {
250 DWORD view_status = 0;
252 hres = IViewObjectEx_SetAdvise(view_obj, DVASPECT_CONTENT, 0, (IAdviseSink*)&host->IAdviseSinkEx_iface);
254 WARN("SetAdvise failed: %08x\n", hres);
256 hres = IViewObjectEx_GetViewStatus(view_obj, &view_status);
257 IViewObjectEx_Release(view_obj);
258 TRACE("GetViewStatus returned %08x %x\n", hres, view_status);
262 update_readystate(host);
264 /* NOTE: Native QIs for IActiveScript, an undocumented IID, IOleControl and IRunnableObject */
266 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatchEx, (void**)&dispex);
267 if(SUCCEEDED(hres)) {
268 FIXME("Use IDispatchEx\n");
269 host->disp = (IDispatch*)dispex;
271 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
275 TRACE("no IDispatch iface\n");
278 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
279 if(SUCCEEDED(hres)) {
280 FIXME("Use IOleCommandTarget\n");
281 IOleCommandTarget_Release(cmdtrg);
284 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
286 FIXME("Plugin does not support IOleObject\n");
291 get_pos_rect(host, &rect);
292 hres = IOleObject_DoVerb(ole_obj, OLEIVERB_INPLACEACTIVATE, NULL, &host->IOleClientSite_iface, 0, host->hwnd, &rect);
293 IOleObject_Release(ole_obj);
295 WARN("DoVerb failed: %08x\n", hres);
298 if(host->ip_object) {
301 hres = IOleInPlaceObject_GetWindow(host->ip_object, &hwnd);
303 TRACE("hwnd %p\n", hwnd);
307 void update_plugin_window(PluginHost *host, HWND hwnd, const RECT *rect)
309 BOOL rect_changed = FALSE;
311 if(!hwnd || (host->hwnd && host->hwnd != hwnd)) {
312 FIXME("unhandled hwnd\n");
316 TRACE("%p %s\n", hwnd, wine_dbgstr_rect(rect));
318 if(memcmp(rect, &host->rect, sizeof(RECT))) {
325 activate_plugin(host);
328 if(rect_changed && host->ip_object)
329 IOleInPlaceObject_SetObjectRects(host->ip_object, &host->rect, &host->rect);
332 HRESULT get_plugin_disp(HTMLPluginContainer *plugin_container, IDispatch **ret)
336 host = plugin_container->plugin_host;
338 ERR("No plugin host\n");
347 if(!check_script_safety(host)) {
348 FIXME("Insecure object\n");
352 IDispatch_AddRef(host->disp);
357 HRESULT get_plugin_dispid(HTMLPluginContainer *plugin_container, WCHAR *name, DISPID *ret)
364 if(!plugin_container->plugin_host) {
365 WARN("no plugin host\n");
366 return DISP_E_UNKNOWNNAME;
369 disp = plugin_container->plugin_host->disp;
371 return DISP_E_UNKNOWNNAME;
373 hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, &id);
375 TRACE("no prop %s\n", debugstr_w(name));
376 return DISP_E_UNKNOWNNAME;
379 for(i=0; i < plugin_container->props_len; i++) {
380 if(id == plugin_container->props[i]) {
381 *ret = MSHTML_DISPID_CUSTOM_MIN+i;
386 if(!plugin_container->props) {
387 plugin_container->props = heap_alloc(8*sizeof(DISPID));
388 if(!plugin_container->props)
389 return E_OUTOFMEMORY;
390 plugin_container->props_size = 8;
391 }else if(plugin_container->props_len == plugin_container->props_size) {
394 new_props = heap_realloc(plugin_container->props, plugin_container->props_size*2*sizeof(DISPID));
396 return E_OUTOFMEMORY;
398 plugin_container->props = new_props;
399 plugin_container->props_size *= 2;
402 plugin_container->props[plugin_container->props_len] = id;
403 *ret = MSHTML_DISPID_CUSTOM_MIN+plugin_container->props_len;
404 plugin_container->props_len++;
408 HRESULT invoke_plugin_prop(HTMLPluginContainer *plugin_container, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
409 VARIANT *res, EXCEPINFO *ei)
413 host = plugin_container->plugin_host;
414 if(!host || !host->disp) {
415 FIXME("Called with no disp\n");
419 if(!check_script_safety(host)) {
420 FIXME("Insecure object\n");
424 if(id < MSHTML_DISPID_CUSTOM_MIN || id > MSHTML_DISPID_CUSTOM_MIN + plugin_container->props_len) {
429 return IDispatch_Invoke(host->disp, plugin_container->props[id-MSHTML_DISPID_CUSTOM_MIN], &IID_NULL,
430 lcid, flags, params, res, ei, NULL);
433 static inline PluginHost *impl_from_IOleClientSite(IOleClientSite *iface)
435 return CONTAINING_RECORD(iface, PluginHost, IOleClientSite_iface);
438 static HRESULT WINAPI PHClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
440 PluginHost *This = impl_from_IOleClientSite(iface);
442 if(IsEqualGUID(&IID_IUnknown, riid)) {
443 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
444 *ppv = &This->IOleClientSite_iface;
445 }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
446 TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
447 *ppv = &This->IOleClientSite_iface;
448 }else if(IsEqualGUID(&IID_IAdviseSink, riid)) {
449 TRACE("(%p)->(IID_IAdviseSink %p)\n", This, ppv);
450 *ppv = &This->IAdviseSinkEx_iface;
451 }else if(IsEqualGUID(&IID_IAdviseSinkEx, riid)) {
452 TRACE("(%p)->(IID_IAdviseSinkEx %p)\n", This, ppv);
453 *ppv = &This->IAdviseSinkEx_iface;
454 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
455 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv);
456 *ppv = &This->IPropertyNotifySink_iface;
457 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
458 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
459 *ppv = &This->IDispatch_iface;
460 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
461 TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
462 *ppv = &This->IOleInPlaceSiteEx_iface;
463 }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
464 TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
465 *ppv = &This->IOleInPlaceSiteEx_iface;
466 }else if(IsEqualGUID(&IID_IOleInPlaceSiteEx, riid)) {
467 TRACE("(%p)->(IID_IOleInPlaceSiteEx %p)\n", This, ppv);
468 *ppv = &This->IOleInPlaceSiteEx_iface;
469 }else if(IsEqualGUID(&IID_IOleControlSite, riid)) {
470 TRACE("(%p)->(IID_IOleControlSite %p)\n", This, ppv);
471 *ppv = &This->IOleControlSite_iface;
472 }else if(IsEqualGUID(&IID_IBindHost, riid)) {
473 TRACE("(%p)->(IID_IBindHost %p)\n", This, ppv);
474 *ppv = &This->IBindHost_iface;
475 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
476 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
477 *ppv = &This->IServiceProvider_iface;
479 WARN("Unsupported interface %s\n", debugstr_guid(riid));
481 return E_NOINTERFACE;
484 IOleClientSite_AddRef((IUnknown*)*ppv);
488 static ULONG WINAPI PHClientSite_AddRef(IOleClientSite *iface)
490 PluginHost *This = impl_from_IOleClientSite(iface);
491 LONG ref = InterlockedIncrement(&This->ref);
493 TRACE("(%p) ref=%d\n", This, ref);
498 static ULONG WINAPI PHClientSite_Release(IOleClientSite *iface)
500 PluginHost *This = impl_from_IOleClientSite(iface);
501 LONG ref = InterlockedDecrement(&This->ref);
503 TRACE("(%p) ref=%d\n", This, ref);
507 IDispatch_Release(This->disp);
509 IOleInPlaceObject_Release(This->ip_object);
510 list_remove(&This->entry);
512 This->element->plugin_host = NULL;
514 IUnknown_Release(This->plugin_unk);
521 static HRESULT WINAPI PHClientSite_SaveObject(IOleClientSite *iface)
523 PluginHost *This = impl_from_IOleClientSite(iface);
524 FIXME("(%p)\n", This);
528 static HRESULT WINAPI PHClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
529 DWORD dwWhichMoniker, IMoniker **ppmk)
531 PluginHost *This = impl_from_IOleClientSite(iface);
533 TRACE("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
535 switch(dwWhichMoniker) {
536 case OLEWHICHMK_CONTAINER:
537 if(!This->doc || !This->doc->basedoc.window || !This->doc->basedoc.window->mon) {
538 FIXME("no moniker\n");
542 *ppmk = This->doc->basedoc.window->mon;
543 IMoniker_AddRef(*ppmk);
546 FIXME("which %d\n", dwWhichMoniker);
553 static HRESULT WINAPI PHClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
555 PluginHost *This = impl_from_IOleClientSite(iface);
557 TRACE("(%p)->(%p)\n", This, ppContainer);
560 ERR("Called on detached object\n");
564 *ppContainer = &This->doc->basedoc.IOleContainer_iface;
565 IOleContainer_AddRef(*ppContainer);
569 static HRESULT WINAPI PHClientSite_ShowObject(IOleClientSite *iface)
571 PluginHost *This = impl_from_IOleClientSite(iface);
573 TRACE("(%p)\n", This);
578 static HRESULT WINAPI PHClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
580 PluginHost *This = impl_from_IOleClientSite(iface);
581 FIXME("(%p)->(%x)\n", This, fShow);
585 static HRESULT WINAPI PHClientSite_RequestNewObjectLayout(IOleClientSite *iface)
587 PluginHost *This = impl_from_IOleClientSite(iface);
588 FIXME("(%p)\n", This);
592 static const IOleClientSiteVtbl OleClientSiteVtbl = {
593 PHClientSite_QueryInterface,
595 PHClientSite_Release,
596 PHClientSite_SaveObject,
597 PHClientSite_GetMoniker,
598 PHClientSite_GetContainer,
599 PHClientSite_ShowObject,
600 PHClientSite_OnShowWindow,
601 PHClientSite_RequestNewObjectLayout
604 static inline PluginHost *impl_from_IAdviseSinkEx(IAdviseSinkEx *iface)
606 return CONTAINING_RECORD(iface, PluginHost, IAdviseSinkEx_iface);
609 static HRESULT WINAPI PHAdviseSinkEx_QueryInterface(IAdviseSinkEx *iface, REFIID riid, void **ppv)
611 PluginHost *This = impl_from_IAdviseSinkEx(iface);
612 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
615 static ULONG WINAPI PHAdviseSinkEx_AddRef(IAdviseSinkEx *iface)
617 PluginHost *This = impl_from_IAdviseSinkEx(iface);
618 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
621 static ULONG WINAPI PHAdviseSinkEx_Release(IAdviseSinkEx *iface)
623 PluginHost *This = impl_from_IAdviseSinkEx(iface);
624 return IOleClientSite_Release(&This->IOleClientSite_iface);
627 static void WINAPI PHAdviseSinkEx_OnDataChange(IAdviseSinkEx *iface, FORMATETC *pFormatetc, STGMEDIUM *pStgMedium)
629 PluginHost *This = impl_from_IAdviseSinkEx(iface);
630 FIXME("(%p)->(%p %p)\n", This, pFormatetc, pStgMedium);
633 static void WINAPI PHAdviseSinkEx_OnViewChange(IAdviseSinkEx *iface, DWORD dwAspect, LONG lindex)
635 PluginHost *This = impl_from_IAdviseSinkEx(iface);
636 FIXME("(%p)->(%d %d)\n", This, dwAspect, lindex);
639 static void WINAPI PHAdviseSinkEx_OnRename(IAdviseSinkEx *iface, IMoniker *pmk)
641 PluginHost *This = impl_from_IAdviseSinkEx(iface);
642 FIXME("(%p)->(%p)\n", This, pmk);
645 static void WINAPI PHAdviseSinkEx_OnSave(IAdviseSinkEx *iface)
647 PluginHost *This = impl_from_IAdviseSinkEx(iface);
648 FIXME("(%p)\n", This);
651 static void WINAPI PHAdviseSinkEx_OnClose(IAdviseSinkEx *iface)
653 PluginHost *This = impl_from_IAdviseSinkEx(iface);
654 FIXME("(%p)\n", This);
657 static void WINAPI PHAdviseSinkEx_OnViewStatusChange(IAdviseSinkEx *iface, DWORD dwViewStatus)
659 PluginHost *This = impl_from_IAdviseSinkEx(iface);
660 FIXME("(%p)->(%d)\n", This, dwViewStatus);
663 static const IAdviseSinkExVtbl AdviseSinkExVtbl = {
664 PHAdviseSinkEx_QueryInterface,
665 PHAdviseSinkEx_AddRef,
666 PHAdviseSinkEx_Release,
667 PHAdviseSinkEx_OnDataChange,
668 PHAdviseSinkEx_OnViewChange,
669 PHAdviseSinkEx_OnRename,
670 PHAdviseSinkEx_OnSave,
671 PHAdviseSinkEx_OnClose,
672 PHAdviseSinkEx_OnViewStatusChange
675 static inline PluginHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
677 return CONTAINING_RECORD(iface, PluginHost, IPropertyNotifySink_iface);
680 static HRESULT WINAPI PHPropertyNotifySink_QueryInterface(IPropertyNotifySink *iface, REFIID riid, void **ppv)
682 PluginHost *This = impl_from_IPropertyNotifySink(iface);
683 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
686 static ULONG WINAPI PHPropertyNotifySink_AddRef(IPropertyNotifySink *iface)
688 PluginHost *This = impl_from_IPropertyNotifySink(iface);
689 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
692 static ULONG WINAPI PHPropertyNotifySink_Release(IPropertyNotifySink *iface)
694 PluginHost *This = impl_from_IPropertyNotifySink(iface);
695 return IOleClientSite_Release(&This->IOleClientSite_iface);
698 static HRESULT WINAPI PHPropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
700 PluginHost *This = impl_from_IPropertyNotifySink(iface);
702 TRACE("(%p)->(%d)\n", This, dispID);
705 case DISPID_READYSTATE:
706 update_readystate(This);
709 FIXME("Unimplemented dispID %d\n", dispID);
716 static HRESULT WINAPI PHPropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
718 PluginHost *This = impl_from_IPropertyNotifySink(iface);
719 FIXME("(%p)->(%d)\n", This, dispID);
723 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
724 PHPropertyNotifySink_QueryInterface,
725 PHPropertyNotifySink_AddRef,
726 PHPropertyNotifySink_Release,
727 PHPropertyNotifySink_OnChanged,
728 PHPropertyNotifySink_OnRequestEdit
731 static inline PluginHost *impl_from_IDispatch(IDispatch *iface)
733 return CONTAINING_RECORD(iface, PluginHost, IDispatch_iface);
736 static HRESULT WINAPI PHDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
738 PluginHost *This = impl_from_IDispatch(iface);
739 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
742 static ULONG WINAPI PHDispatch_AddRef(IDispatch *iface)
744 PluginHost *This = impl_from_IDispatch(iface);
745 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
748 static ULONG WINAPI PHDispatch_Release(IDispatch *iface)
750 PluginHost *This = impl_from_IDispatch(iface);
751 return IOleClientSite_Release(&This->IOleClientSite_iface);
754 static HRESULT WINAPI PHDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
756 PluginHost *This = impl_from_IDispatch(iface);
757 FIXME("(%p)->(%p)\n", This, pctinfo);
761 static HRESULT WINAPI PHDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo,
762 LCID lcid, ITypeInfo **ppTInfo)
764 PluginHost *This = impl_from_IDispatch(iface);
765 FIXME("(%p)->(%d %d %p)\n", This, iTInfo, lcid, ppTInfo);
769 static HRESULT WINAPI PHDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid,
770 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
772 PluginHost *This = impl_from_IDispatch(iface);
773 FIXME("(%p)->(%s %p %d %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
777 static HRESULT WINAPI PHDispatch_Invoke(IDispatch *iface, DISPID dispid, REFIID riid, LCID lcid,
778 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
780 PluginHost *This = impl_from_IDispatch(iface);
781 FIXME("(%p)->(%d %x %p %p)\n", This, dispid, wFlags, pDispParams, pVarResult);
785 static const IDispatchVtbl DispatchVtbl = {
786 PHDispatch_QueryInterface,
789 PHDispatch_GetTypeInfoCount,
790 PHDispatch_GetTypeInfo,
791 PHDispatch_GetIDsOfNames,
795 static inline PluginHost *impl_from_IOleInPlaceSiteEx(IOleInPlaceSiteEx *iface)
797 return CONTAINING_RECORD(iface, PluginHost, IOleInPlaceSiteEx_iface);
800 static HRESULT WINAPI PHInPlaceSite_QueryInterface(IOleInPlaceSiteEx *iface, REFIID riid, void **ppv)
802 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
803 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
806 static ULONG WINAPI PHInPlaceSite_AddRef(IOleInPlaceSiteEx *iface)
808 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
809 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
812 static ULONG WINAPI PHInPlaceSite_Release(IOleInPlaceSiteEx *iface)
814 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
815 return IOleClientSite_Release(&This->IOleClientSite_iface);
818 static HRESULT WINAPI PHInPlaceSite_GetWindow(IOleInPlaceSiteEx *iface, HWND *phwnd)
820 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
822 TRACE("(%p)->(%p)\n", This, phwnd);
828 static HRESULT WINAPI PHInPlaceSite_ContextSensitiveHelp(IOleInPlaceSiteEx *iface, BOOL fEnterMode)
830 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
831 FIXME("(%p)->(%x)\n", This, fEnterMode);
835 static HRESULT WINAPI PHInPlaceSite_CanInPlaceActivate(IOleInPlaceSiteEx *iface)
837 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
838 FIXME("(%p)\n", This);
842 static HRESULT WINAPI PHInPlaceSite_OnInPlaceActivate(IOleInPlaceSiteEx *iface)
844 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
845 FIXME("(%p)\n", This);
849 static HRESULT WINAPI PHInPlaceSite_OnUIActivate(IOleInPlaceSiteEx *iface)
851 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
852 DISPPARAMS args = {NULL, NULL, 0, 0};
858 TRACE("(%p)\n", This);
860 if(!This->plugin_unk) {
861 ERR("No plugin object\n");
865 This->ui_active = TRUE;
867 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IDispatch, (void**)&disp);
869 FIXME("Could not get IDispatch iface: %08x\n", hres);
873 V_VT(&res) = VT_EMPTY;
874 hres = IDispatch_Invoke(disp, DISPID_ENABLED, &IID_NULL, 0/*FIXME*/, DISPATCH_PROPERTYGET, &args, &res, NULL, &err);
875 IDispatch_Release(disp);
876 if(SUCCEEDED(hres)) {
877 FIXME("Got enabled %s\n", debugstr_variant(&res));
884 static HRESULT WINAPI PHInPlaceSite_GetWindowContext(IOleInPlaceSiteEx *iface,
885 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, RECT *lprcPosRect,
886 RECT *lprcClipRect, OLEINPLACEFRAMEINFO *frame_info)
888 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
889 IOleInPlaceUIWindow *ip_window;
890 IOleInPlaceFrame *ip_frame;
894 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, frame_info);
896 if(!This->doc || !This->doc->basedoc.doc_obj || !This->doc->basedoc.doc_obj->ipsite) {
897 FIXME("No ipsite\n");
901 hres = IOleInPlaceSite_GetWindowContext(This->doc->basedoc.doc_obj->ipsite, &ip_frame, &ip_window, &pr, &cr, frame_info);
903 WARN("GetWindowContext failed: %08x\n", hres);
908 IOleInPlaceUIWindow_Release(ip_window);
910 IOleInPlaceFrame_Release(ip_frame);
912 hres = create_ip_frame(&ip_frame);
916 hres = create_ip_window(ppDoc);
921 *lprcPosRect = This->rect;
922 *lprcClipRect = This->rect;
926 static HRESULT WINAPI PHInPlaceSite_Scroll(IOleInPlaceSiteEx *iface, SIZE scrollExtent)
928 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
929 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
933 static HRESULT WINAPI PHInPlaceSite_OnUIDeactivate(IOleInPlaceSiteEx *iface, BOOL fUndoable)
935 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
936 FIXME("(%p)->(%x)\n", This, fUndoable);
940 static HRESULT WINAPI PHInPlaceSite_OnInPlaceDeactivate(IOleInPlaceSiteEx *iface)
942 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
944 TRACE("(%p)\n", This);
946 if(This->ip_object) {
947 IOleInPlaceObject_Release(This->ip_object);
948 This->ip_object = NULL;
954 static HRESULT WINAPI PHInPlaceSite_DiscardUndoState(IOleInPlaceSiteEx *iface)
956 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
957 FIXME("(%p)\n", This);
961 static HRESULT WINAPI PHInPlaceSite_DeactivateAndUndo(IOleInPlaceSiteEx *iface)
963 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
964 FIXME("(%p)\n", This);
968 static HRESULT WINAPI PHInPlaceSite_OnPosRectChange(IOleInPlaceSiteEx *iface, LPCRECT lprcPosRect)
970 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
971 FIXME("(%p)->(%p)\n", This, lprcPosRect);
975 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceActivateEx(IOleInPlaceSiteEx *iface, BOOL *pfNoRedraw, DWORD dwFlags)
977 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
981 TRACE("(%p)->(%p %x)\n", This, pfNoRedraw, dwFlags);
986 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IOleInPlaceObject, (void**)&This->ip_object);
990 hres = IOleInPlaceObject_GetWindow(This->ip_object, &hwnd);
992 FIXME("Use hwnd %p\n", hwnd);
998 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface, BOOL fNoRedraw)
1000 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1001 FIXME("(%p)->(%x)\n", This, fNoRedraw);
1005 static HRESULT WINAPI PHInPlaceSiteEx_RequestUIActivate(IOleInPlaceSiteEx *iface)
1007 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1008 FIXME("(%p)\n", This);
1012 static const IOleInPlaceSiteExVtbl OleInPlaceSiteExVtbl = {
1013 PHInPlaceSite_QueryInterface,
1014 PHInPlaceSite_AddRef,
1015 PHInPlaceSite_Release,
1016 PHInPlaceSite_GetWindow,
1017 PHInPlaceSite_ContextSensitiveHelp,
1018 PHInPlaceSite_CanInPlaceActivate,
1019 PHInPlaceSite_OnInPlaceActivate,
1020 PHInPlaceSite_OnUIActivate,
1021 PHInPlaceSite_GetWindowContext,
1022 PHInPlaceSite_Scroll,
1023 PHInPlaceSite_OnUIDeactivate,
1024 PHInPlaceSite_OnInPlaceDeactivate,
1025 PHInPlaceSite_DiscardUndoState,
1026 PHInPlaceSite_DeactivateAndUndo,
1027 PHInPlaceSite_OnPosRectChange,
1028 PHInPlaceSiteEx_OnInPlaceActivateEx,
1029 PHInPlaceSiteEx_OnInPlaceDeactivateEx,
1030 PHInPlaceSiteEx_RequestUIActivate
1033 static inline PluginHost *impl_from_IOleControlSite(IOleControlSite *iface)
1035 return CONTAINING_RECORD(iface, PluginHost, IOleControlSite_iface);
1038 static HRESULT WINAPI PHControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
1040 PluginHost *This = impl_from_IOleControlSite(iface);
1041 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1044 static ULONG WINAPI PHControlSite_AddRef(IOleControlSite *iface)
1046 PluginHost *This = impl_from_IOleControlSite(iface);
1047 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1050 static ULONG WINAPI PHControlSite_Release(IOleControlSite *iface)
1052 PluginHost *This = impl_from_IOleControlSite(iface);
1053 return IOleClientSite_Release(&This->IOleClientSite_iface);
1056 static HRESULT WINAPI PHControlSite_OnControlInfoChanged(IOleControlSite *iface)
1058 PluginHost *This = impl_from_IOleControlSite(iface);
1059 FIXME("(%p)\n", This);
1063 static HRESULT WINAPI PHControlSite_LockInPlaceActive(IOleControlSite *iface, BOOL fLock)
1065 PluginHost *This = impl_from_IOleControlSite(iface);
1066 FIXME("(%p)->(%x)\n", This, fLock);
1070 static HRESULT WINAPI PHControlSite_GetExtendedControl(IOleControlSite *iface, IDispatch **ppDisp)
1072 PluginHost *This = impl_from_IOleControlSite(iface);
1073 FIXME("(%p)->(%p)\n", This, ppDisp);
1077 static HRESULT WINAPI PHControlSite_TransformCoords(IOleControlSite *iface, POINTL *pPtlHimetric, POINTF *pPtfContainer, DWORD dwFlags)
1079 PluginHost *This = impl_from_IOleControlSite(iface);
1080 FIXME("(%p)->(%p %p %x)\n", This, pPtlHimetric, pPtfContainer, dwFlags);
1084 static HRESULT WINAPI PHControlSite_TranslateAccelerator(IOleControlSite *iface, MSG *pMsg, DWORD grfModifiers)
1086 PluginHost *This = impl_from_IOleControlSite(iface);
1087 FIXME("(%p)->(%x)\n", This, grfModifiers);
1091 static HRESULT WINAPI PHControlSite_OnFocus(IOleControlSite *iface, BOOL fGotFocus)
1093 PluginHost *This = impl_from_IOleControlSite(iface);
1094 FIXME("(%p)->(%x)\n", This, fGotFocus);
1098 static HRESULT WINAPI PHControlSite_ShowPropertyFrame(IOleControlSite *iface)
1100 PluginHost *This = impl_from_IOleControlSite(iface);
1101 FIXME("(%p)\n", This);
1105 static const IOleControlSiteVtbl OleControlSiteVtbl = {
1106 PHControlSite_QueryInterface,
1107 PHControlSite_AddRef,
1108 PHControlSite_Release,
1109 PHControlSite_OnControlInfoChanged,
1110 PHControlSite_LockInPlaceActive,
1111 PHControlSite_GetExtendedControl,
1112 PHControlSite_TransformCoords,
1113 PHControlSite_TranslateAccelerator,
1114 PHControlSite_OnFocus,
1115 PHControlSite_ShowPropertyFrame
1118 static inline PluginHost *impl_from_IBindHost(IBindHost *iface)
1120 return CONTAINING_RECORD(iface, PluginHost, IBindHost_iface);
1123 static HRESULT WINAPI PHBindHost_QueryInterface(IBindHost *iface, REFIID riid, void **ppv)
1125 PluginHost *This = impl_from_IBindHost(iface);
1126 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1129 static ULONG WINAPI PHBindHost_AddRef(IBindHost *iface)
1131 PluginHost *This = impl_from_IBindHost(iface);
1132 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1135 static ULONG WINAPI PHBindHost_Release(IBindHost *iface)
1137 PluginHost *This = impl_from_IBindHost(iface);
1138 return IOleClientSite_Release(&This->IOleClientSite_iface);
1141 static HRESULT WINAPI PHBindHost_CreateMoniker(IBindHost *iface, LPOLESTR szName, IBindCtx *pBC, IMoniker **ppmk, DWORD dwReserved)
1143 PluginHost *This = impl_from_IBindHost(iface);
1145 TRACE("(%p)->(%s %p %p %x)\n", This, debugstr_w(szName), pBC, ppmk, dwReserved);
1147 if(!This->doc || !This->doc->basedoc.window || !This->doc->basedoc.window->mon) {
1148 FIXME("no moniker\n");
1149 return E_UNEXPECTED;
1152 return CreateURLMoniker(This->doc->basedoc.window->mon, szName, ppmk);
1155 static HRESULT WINAPI PHBindHost_MonikerBindToStorage(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1156 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1158 PluginHost *This = impl_from_IBindHost(iface);
1159 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1163 static HRESULT WINAPI PHBindHost_MonikerBindToObject(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1164 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1166 PluginHost *This = impl_from_IBindHost(iface);
1167 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1171 static const IBindHostVtbl BindHostVtbl = {
1172 PHBindHost_QueryInterface,
1175 PHBindHost_CreateMoniker,
1176 PHBindHost_MonikerBindToStorage,
1177 PHBindHost_MonikerBindToObject
1180 static inline PluginHost *impl_from_IServiceProvider(IServiceProvider *iface)
1182 return CONTAINING_RECORD(iface, PluginHost, IServiceProvider_iface);
1185 static HRESULT WINAPI PHServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1187 PluginHost *This = impl_from_IServiceProvider(iface);
1188 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1191 static ULONG WINAPI PHServiceProvider_AddRef(IServiceProvider *iface)
1193 PluginHost *This = impl_from_IServiceProvider(iface);
1194 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1197 static ULONG WINAPI PHServiceProvider_Release(IServiceProvider *iface)
1199 PluginHost *This = impl_from_IServiceProvider(iface);
1200 return IOleClientSite_Release(&This->IOleClientSite_iface);
1203 static HRESULT WINAPI PHServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
1205 PluginHost *This = impl_from_IServiceProvider(iface);
1207 if(IsEqualGUID(guidService, &SID_SBindHost)) {
1208 TRACE("SID_SBindHost service\n");
1209 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1212 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1214 if(!This->doc || !This->doc->basedoc.window) {
1216 return E_NOINTERFACE;
1219 return IServiceProvider_QueryService(&This->doc->basedoc.window->IServiceProvider_iface,
1220 guidService, riid, ppv);
1223 static const IServiceProviderVtbl ServiceProviderVtbl = {
1224 PHServiceProvider_QueryInterface,
1225 PHServiceProvider_AddRef,
1226 PHServiceProvider_Release,
1227 PHServiceProvider_QueryService
1230 static HRESULT assoc_element(PluginHost *host, HTMLDocumentNode *doc, nsIDOMElement *nselem)
1232 HTMLPluginContainer *container_elem;
1236 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1240 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
1241 (void**)&container_elem);
1243 ERR("Not an object element\n");
1247 container_elem->plugin_host = host;
1248 host->element = container_elem;
1252 void detach_plugin_host(PluginHost *host)
1256 TRACE("%p\n", host);
1261 if(host->ip_object) {
1263 IOleInPlaceObject_UIDeactivate(host->ip_object);
1264 IOleInPlaceObject_InPlaceDeactivate(host->ip_object);
1267 if(host->plugin_unk) {
1268 IOleObject *ole_obj;
1270 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
1271 if(SUCCEEDED(hres)) {
1272 if(!host->ip_object)
1273 IOleObject_Close(ole_obj, OLECLOSE_NOSAVE);
1274 IOleObject_SetClientSite(ole_obj, NULL);
1275 IOleObject_Release(ole_obj);
1280 host->element->plugin_host = NULL;
1281 host->element = NULL;
1284 list_remove(&host->entry);
1285 list_init(&host->entry);
1289 HRESULT create_plugin_host(HTMLDocumentNode *doc, nsIDOMElement *nselem, IUnknown *unk, const CLSID *clsid, PluginHost **ret)
1294 host = heap_alloc_zero(sizeof(*host));
1296 return E_OUTOFMEMORY;
1298 host->IOleClientSite_iface.lpVtbl = &OleClientSiteVtbl;
1299 host->IAdviseSinkEx_iface.lpVtbl = &AdviseSinkExVtbl;
1300 host->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1301 host->IDispatch_iface.lpVtbl = &DispatchVtbl;
1302 host->IOleInPlaceSiteEx_iface.lpVtbl = &OleInPlaceSiteExVtbl;
1303 host->IOleControlSite_iface.lpVtbl = &OleControlSiteVtbl;
1304 host->IBindHost_iface.lpVtbl = &BindHostVtbl;
1305 host->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
1309 hres = assoc_element(host, doc, nselem);
1315 IUnknown_AddRef(unk);
1316 host->plugin_unk = unk;
1317 host->clsid = *clsid;
1320 list_add_tail(&doc->plugin_hosts, &host->entry);