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 IOleCommandTarget *cmdtrg;
195 if(!host->plugin_unk)
198 /* Note native calls QI on plugin for an undocumented IID and CLSID_HTMLDocument */
200 /* FIXME: call FreezeEvents(TRUE) */
202 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IClientSecurity, (void**)&client_security);
203 if(SUCCEEDED(hres)) {
204 FIXME("Handle IClientSecurity\n");
205 IClientSecurity_Release(client_security);
209 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IQuickActivate, (void**)&quick_activate);
210 if(SUCCEEDED(hres)) {
211 QACONTAINER container = {sizeof(container)};
212 QACONTROL control = {sizeof(control)};
214 container.pClientSite = &host->IOleClientSite_iface;
215 container.dwAmbientFlags = QACONTAINER_SUPPORTSMNEMONICS|QACONTAINER_MESSAGEREFLECT|QACONTAINER_USERMODE;
216 container.pAdviseSink = &host->IAdviseSinkEx_iface;
217 container.pPropertyNotifySink = &host->IPropertyNotifySink_iface;
219 hres = IQuickActivate_QuickActivate(quick_activate, &container, &control);
221 FIXME("QuickActivate failed: %08x\n", hres);
223 FIXME("No IQuickActivate\n");
229 /* NOTE: Native QIs for IViewObjectEx, IActiveScript, an undocumented IID, IOleControl and IRunnableObject */
231 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatchEx, (void**)&dispex);
232 if(SUCCEEDED(hres)) {
233 FIXME("Use IDispatchEx\n");
234 host->disp = (IDispatch*)dispex;
236 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
240 TRACE("no IDispatch iface\n");
243 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
244 if(SUCCEEDED(hres)) {
245 FIXME("Use IOleCommandTarget\n");
246 IOleCommandTarget_Release(cmdtrg);
249 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
251 FIXME("Plugin does not support IOleObject\n");
255 get_pos_rect(host, &rect);
256 hres = IOleObject_DoVerb(ole_obj, OLEIVERB_INPLACEACTIVATE, NULL, &host->IOleClientSite_iface, 0, host->hwnd, &rect);
257 IOleObject_Release(ole_obj);
259 WARN("DoVerb failed: %08x\n", hres);
261 if(host->ip_object) {
264 hres = IOleInPlaceObject_GetWindow(host->ip_object, &hwnd);
266 TRACE("hwnd %p\n", hwnd);
270 void update_plugin_window(PluginHost *host, HWND hwnd, const RECT *rect)
272 BOOL rect_changed = FALSE;
274 if(!hwnd || (host->hwnd && host->hwnd != hwnd)) {
275 FIXME("unhandled hwnd\n");
279 TRACE("%p %s\n", hwnd, wine_dbgstr_rect(rect));
281 if(memcmp(rect, &host->rect, sizeof(RECT))) {
288 activate_plugin(host);
291 if(rect_changed && host->ip_object)
292 IOleInPlaceObject_SetObjectRects(host->ip_object, &host->rect, &host->rect);
295 HRESULT get_plugin_disp(HTMLPluginContainer *plugin_container, IDispatch **ret)
299 host = plugin_container->plugin_host;
301 ERR("No plugin host\n");
310 if(!check_script_safety(host)) {
311 FIXME("Insecure object\n");
315 IDispatch_AddRef(host->disp);
320 HRESULT get_plugin_dispid(HTMLPluginContainer *plugin_container, WCHAR *name, DISPID *ret)
327 if(!plugin_container->plugin_host) {
328 WARN("no plugin host\n");
329 return DISP_E_UNKNOWNNAME;
332 disp = plugin_container->plugin_host->disp;
334 return DISP_E_UNKNOWNNAME;
336 hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, &id);
338 TRACE("no prop %s\n", debugstr_w(name));
339 return DISP_E_UNKNOWNNAME;
342 for(i=0; i < plugin_container->props_len; i++) {
343 if(id == plugin_container->props[i]) {
344 *ret = MSHTML_DISPID_CUSTOM_MIN+i;
349 if(!plugin_container->props) {
350 plugin_container->props = heap_alloc(8*sizeof(DISPID));
351 if(!plugin_container->props)
352 return E_OUTOFMEMORY;
353 plugin_container->props_size = 8;
354 }else if(plugin_container->props_len == plugin_container->props_size) {
357 new_props = heap_realloc(plugin_container->props, plugin_container->props_size*2);
359 return E_OUTOFMEMORY;
361 plugin_container->props = new_props;
362 plugin_container->props_size *= 2;
365 plugin_container->props[plugin_container->props_len] = id;
366 *ret = MSHTML_DISPID_CUSTOM_MIN+plugin_container->props_len;
367 plugin_container->props_len++;
371 HRESULT invoke_plugin_prop(HTMLPluginContainer *plugin_container, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
372 VARIANT *res, EXCEPINFO *ei)
376 host = plugin_container->plugin_host;
377 if(!host || !host->disp) {
378 FIXME("Called with no disp\n");
382 if(!check_script_safety(host)) {
383 FIXME("Insecure object\n");
387 if(id < MSHTML_DISPID_CUSTOM_MIN || id > MSHTML_DISPID_CUSTOM_MIN + plugin_container->props_len) {
392 return IDispatch_Invoke(host->disp, plugin_container->props[id-MSHTML_DISPID_CUSTOM_MIN], &IID_NULL,
393 lcid, flags, params, res, ei, NULL);
396 static inline PluginHost *impl_from_IOleClientSite(IOleClientSite *iface)
398 return CONTAINING_RECORD(iface, PluginHost, IOleClientSite_iface);
401 static HRESULT WINAPI PHClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
403 PluginHost *This = impl_from_IOleClientSite(iface);
405 if(IsEqualGUID(&IID_IUnknown, riid)) {
406 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
407 *ppv = &This->IOleClientSite_iface;
408 }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
409 TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
410 *ppv = &This->IOleClientSite_iface;
411 }else if(IsEqualGUID(&IID_IAdviseSink, riid)) {
412 TRACE("(%p)->(IID_IAdviseSink %p)\n", This, ppv);
413 *ppv = &This->IAdviseSinkEx_iface;
414 }else if(IsEqualGUID(&IID_IAdviseSinkEx, riid)) {
415 TRACE("(%p)->(IID_IAdviseSinkEx %p)\n", This, ppv);
416 *ppv = &This->IAdviseSinkEx_iface;
417 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
418 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv);
419 *ppv = &This->IPropertyNotifySink_iface;
420 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
421 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
422 *ppv = &This->IDispatch_iface;
423 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
424 TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
425 *ppv = &This->IOleInPlaceSiteEx_iface;
426 }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
427 TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
428 *ppv = &This->IOleInPlaceSiteEx_iface;
429 }else if(IsEqualGUID(&IID_IOleInPlaceSiteEx, riid)) {
430 TRACE("(%p)->(IID_IOleInPlaceSiteEx %p)\n", This, ppv);
431 *ppv = &This->IOleInPlaceSiteEx_iface;
432 }else if(IsEqualGUID(&IID_IOleControlSite, riid)) {
433 TRACE("(%p)->(IID_IOleControlSite %p)\n", This, ppv);
434 *ppv = &This->IOleControlSite_iface;
435 }else if(IsEqualGUID(&IID_IBindHost, riid)) {
436 TRACE("(%p)->(IID_IBindHost %p)\n", This, ppv);
437 *ppv = &This->IBindHost_iface;
438 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
439 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
440 *ppv = &This->IServiceProvider_iface;
442 WARN("Unsupported interface %s\n", debugstr_guid(riid));
444 return E_NOINTERFACE;
447 IOleClientSite_AddRef((IUnknown*)*ppv);
451 static ULONG WINAPI PHClientSite_AddRef(IOleClientSite *iface)
453 PluginHost *This = impl_from_IOleClientSite(iface);
454 LONG ref = InterlockedIncrement(&This->ref);
456 TRACE("(%p) ref=%d\n", This, ref);
461 static ULONG WINAPI PHClientSite_Release(IOleClientSite *iface)
463 PluginHost *This = impl_from_IOleClientSite(iface);
464 LONG ref = InterlockedDecrement(&This->ref);
466 TRACE("(%p) ref=%d\n", This, ref);
470 IDispatch_Release(This->disp);
472 IOleInPlaceObject_Release(This->ip_object);
473 list_remove(&This->entry);
475 This->element->plugin_host = NULL;
477 IUnknown_Release(This->plugin_unk);
484 static HRESULT WINAPI PHClientSite_SaveObject(IOleClientSite *iface)
486 PluginHost *This = impl_from_IOleClientSite(iface);
487 FIXME("(%p)\n", This);
491 static HRESULT WINAPI PHClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
492 DWORD dwWhichMoniker, IMoniker **ppmk)
494 PluginHost *This = impl_from_IOleClientSite(iface);
496 TRACE("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
498 switch(dwWhichMoniker) {
499 case OLEWHICHMK_CONTAINER:
500 if(!This->doc || !This->doc->basedoc.window || !This->doc->basedoc.window->mon) {
501 FIXME("no moniker\n");
505 *ppmk = This->doc->basedoc.window->mon;
506 IMoniker_AddRef(*ppmk);
509 FIXME("which %d\n", dwWhichMoniker);
516 static HRESULT WINAPI PHClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
518 PluginHost *This = impl_from_IOleClientSite(iface);
520 TRACE("(%p)->(%p)\n", This, ppContainer);
523 ERR("Called on detached object\n");
527 *ppContainer = &This->doc->basedoc.IOleContainer_iface;
528 IOleContainer_AddRef(*ppContainer);
532 static HRESULT WINAPI PHClientSite_ShowObject(IOleClientSite *iface)
534 PluginHost *This = impl_from_IOleClientSite(iface);
536 TRACE("(%p)\n", This);
541 static HRESULT WINAPI PHClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
543 PluginHost *This = impl_from_IOleClientSite(iface);
544 FIXME("(%p)->(%x)\n", This, fShow);
548 static HRESULT WINAPI PHClientSite_RequestNewObjectLayout(IOleClientSite *iface)
550 PluginHost *This = impl_from_IOleClientSite(iface);
551 FIXME("(%p)\n", This);
555 static const IOleClientSiteVtbl OleClientSiteVtbl = {
556 PHClientSite_QueryInterface,
558 PHClientSite_Release,
559 PHClientSite_SaveObject,
560 PHClientSite_GetMoniker,
561 PHClientSite_GetContainer,
562 PHClientSite_ShowObject,
563 PHClientSite_OnShowWindow,
564 PHClientSite_RequestNewObjectLayout
567 static inline PluginHost *impl_from_IAdviseSinkEx(IAdviseSinkEx *iface)
569 return CONTAINING_RECORD(iface, PluginHost, IAdviseSinkEx_iface);
572 static HRESULT WINAPI PHAdviseSinkEx_QueryInterface(IAdviseSinkEx *iface, REFIID riid, void **ppv)
574 PluginHost *This = impl_from_IAdviseSinkEx(iface);
575 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
578 static ULONG WINAPI PHAdviseSinkEx_AddRef(IAdviseSinkEx *iface)
580 PluginHost *This = impl_from_IAdviseSinkEx(iface);
581 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
584 static ULONG WINAPI PHAdviseSinkEx_Release(IAdviseSinkEx *iface)
586 PluginHost *This = impl_from_IAdviseSinkEx(iface);
587 return IOleClientSite_Release(&This->IOleClientSite_iface);
590 static void WINAPI PHAdviseSinkEx_OnDataChange(IAdviseSinkEx *iface, FORMATETC *pFormatetc, STGMEDIUM *pStgMedium)
592 PluginHost *This = impl_from_IAdviseSinkEx(iface);
593 FIXME("(%p)->(%p %p)\n", This, pFormatetc, pStgMedium);
596 static void WINAPI PHAdviseSinkEx_OnViewChange(IAdviseSinkEx *iface, DWORD dwAspect, LONG lindex)
598 PluginHost *This = impl_from_IAdviseSinkEx(iface);
599 FIXME("(%p)->(%d %d)\n", This, dwAspect, lindex);
602 static void WINAPI PHAdviseSinkEx_OnRename(IAdviseSinkEx *iface, IMoniker *pmk)
604 PluginHost *This = impl_from_IAdviseSinkEx(iface);
605 FIXME("(%p)->(%p)\n", This, pmk);
608 static void WINAPI PHAdviseSinkEx_OnSave(IAdviseSinkEx *iface)
610 PluginHost *This = impl_from_IAdviseSinkEx(iface);
611 FIXME("(%p)\n", This);
614 static void WINAPI PHAdviseSinkEx_OnClose(IAdviseSinkEx *iface)
616 PluginHost *This = impl_from_IAdviseSinkEx(iface);
617 FIXME("(%p)\n", This);
620 static void WINAPI PHAdviseSinkEx_OnViewStatusChange(IAdviseSinkEx *iface, DWORD dwViewStatus)
622 PluginHost *This = impl_from_IAdviseSinkEx(iface);
623 FIXME("(%p)->(%d)\n", This, dwViewStatus);
626 static const IAdviseSinkExVtbl AdviseSinkExVtbl = {
627 PHAdviseSinkEx_QueryInterface,
628 PHAdviseSinkEx_AddRef,
629 PHAdviseSinkEx_Release,
630 PHAdviseSinkEx_OnDataChange,
631 PHAdviseSinkEx_OnViewChange,
632 PHAdviseSinkEx_OnRename,
633 PHAdviseSinkEx_OnSave,
634 PHAdviseSinkEx_OnClose,
635 PHAdviseSinkEx_OnViewStatusChange
638 static inline PluginHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
640 return CONTAINING_RECORD(iface, PluginHost, IPropertyNotifySink_iface);
643 static HRESULT WINAPI PHPropertyNotifySink_QueryInterface(IPropertyNotifySink *iface, REFIID riid, void **ppv)
645 PluginHost *This = impl_from_IPropertyNotifySink(iface);
646 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
649 static ULONG WINAPI PHPropertyNotifySink_AddRef(IPropertyNotifySink *iface)
651 PluginHost *This = impl_from_IPropertyNotifySink(iface);
652 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
655 static ULONG WINAPI PHPropertyNotifySink_Release(IPropertyNotifySink *iface)
657 PluginHost *This = impl_from_IPropertyNotifySink(iface);
658 return IOleClientSite_Release(&This->IOleClientSite_iface);
661 static HRESULT WINAPI PHPropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
663 PluginHost *This = impl_from_IPropertyNotifySink(iface);
665 TRACE("(%p)->(%d)\n", This, dispID);
668 case DISPID_READYSTATE:
669 update_readystate(This);
672 FIXME("Unimplemented dispID %d\n", dispID);
679 static HRESULT WINAPI PHPropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
681 PluginHost *This = impl_from_IPropertyNotifySink(iface);
682 FIXME("(%p)->(%d)\n", This, dispID);
686 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
687 PHPropertyNotifySink_QueryInterface,
688 PHPropertyNotifySink_AddRef,
689 PHPropertyNotifySink_Release,
690 PHPropertyNotifySink_OnChanged,
691 PHPropertyNotifySink_OnRequestEdit
694 static inline PluginHost *impl_from_IDispatch(IDispatch *iface)
696 return CONTAINING_RECORD(iface, PluginHost, IDispatch_iface);
699 static HRESULT WINAPI PHDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
701 PluginHost *This = impl_from_IDispatch(iface);
702 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
705 static ULONG WINAPI PHDispatch_AddRef(IDispatch *iface)
707 PluginHost *This = impl_from_IDispatch(iface);
708 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
711 static ULONG WINAPI PHDispatch_Release(IDispatch *iface)
713 PluginHost *This = impl_from_IDispatch(iface);
714 return IOleClientSite_Release(&This->IOleClientSite_iface);
717 static HRESULT WINAPI PHDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
719 PluginHost *This = impl_from_IDispatch(iface);
720 FIXME("(%p)->(%p)\n", This, pctinfo);
724 static HRESULT WINAPI PHDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo,
725 LCID lcid, ITypeInfo **ppTInfo)
727 PluginHost *This = impl_from_IDispatch(iface);
728 FIXME("(%p)->(%d %d %p)\n", This, iTInfo, lcid, ppTInfo);
732 static HRESULT WINAPI PHDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid,
733 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
735 PluginHost *This = impl_from_IDispatch(iface);
736 FIXME("(%p)->(%s %p %d %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
740 static HRESULT WINAPI PHDispatch_Invoke(IDispatch *iface, DISPID dispid, REFIID riid, LCID lcid,
741 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
743 PluginHost *This = impl_from_IDispatch(iface);
744 FIXME("(%p)->(%d %x %p %p)\n", This, dispid, wFlags, pDispParams, pVarResult);
748 static const IDispatchVtbl DispatchVtbl = {
749 PHDispatch_QueryInterface,
752 PHDispatch_GetTypeInfoCount,
753 PHDispatch_GetTypeInfo,
754 PHDispatch_GetIDsOfNames,
758 static inline PluginHost *impl_from_IOleInPlaceSiteEx(IOleInPlaceSiteEx *iface)
760 return CONTAINING_RECORD(iface, PluginHost, IOleInPlaceSiteEx_iface);
763 static HRESULT WINAPI PHInPlaceSite_QueryInterface(IOleInPlaceSiteEx *iface, REFIID riid, void **ppv)
765 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
766 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
769 static ULONG WINAPI PHInPlaceSite_AddRef(IOleInPlaceSiteEx *iface)
771 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
772 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
775 static ULONG WINAPI PHInPlaceSite_Release(IOleInPlaceSiteEx *iface)
777 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
778 return IOleClientSite_Release(&This->IOleClientSite_iface);
781 static HRESULT WINAPI PHInPlaceSite_GetWindow(IOleInPlaceSiteEx *iface, HWND *phwnd)
783 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
785 TRACE("(%p)->(%p)\n", This, phwnd);
791 static HRESULT WINAPI PHInPlaceSite_ContextSensitiveHelp(IOleInPlaceSiteEx *iface, BOOL fEnterMode)
793 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
794 FIXME("(%p)->(%x)\n", This, fEnterMode);
798 static HRESULT WINAPI PHInPlaceSite_CanInPlaceActivate(IOleInPlaceSiteEx *iface)
800 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
801 FIXME("(%p)\n", This);
805 static HRESULT WINAPI PHInPlaceSite_OnInPlaceActivate(IOleInPlaceSiteEx *iface)
807 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
808 FIXME("(%p)\n", This);
812 static HRESULT WINAPI PHInPlaceSite_OnUIActivate(IOleInPlaceSiteEx *iface)
814 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
815 DISPPARAMS args = {NULL, NULL, 0, 0};
821 TRACE("(%p)\n", This);
823 if(!This->plugin_unk) {
824 ERR("No plugin object\n");
828 This->ui_active = TRUE;
830 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IDispatch, (void**)&disp);
832 FIXME("Could not get IDispatch iface: %08x\n", hres);
836 V_VT(&res) = VT_EMPTY;
837 hres = IDispatch_Invoke(disp, DISPID_ENABLED, &IID_NULL, 0/*FIXME*/, DISPATCH_PROPERTYGET, &args, &res, NULL, &err);
838 IDispatch_Release(disp);
839 if(SUCCEEDED(hres)) {
840 FIXME("Got enabled %s\n", debugstr_variant(&res));
847 static HRESULT WINAPI PHInPlaceSite_GetWindowContext(IOleInPlaceSiteEx *iface,
848 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, RECT *lprcPosRect,
849 RECT *lprcClipRect, OLEINPLACEFRAMEINFO *frame_info)
851 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
852 IOleInPlaceUIWindow *ip_window;
853 IOleInPlaceFrame *ip_frame;
857 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, frame_info);
859 if(!This->doc || !This->doc->basedoc.doc_obj || !This->doc->basedoc.doc_obj->ipsite) {
860 FIXME("No ipsite\n");
864 hres = IOleInPlaceSite_GetWindowContext(This->doc->basedoc.doc_obj->ipsite, &ip_frame, &ip_window, &pr, &cr, frame_info);
866 WARN("GetWindowContext failed: %08x\n", hres);
871 IOleInPlaceUIWindow_Release(ip_window);
873 IOleInPlaceFrame_Release(ip_frame);
875 hres = create_ip_frame(&ip_frame);
879 hres = create_ip_window(ppDoc);
884 *lprcPosRect = This->rect;
885 *lprcClipRect = This->rect;
889 static HRESULT WINAPI PHInPlaceSite_Scroll(IOleInPlaceSiteEx *iface, SIZE scrollExtent)
891 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
892 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
896 static HRESULT WINAPI PHInPlaceSite_OnUIDeactivate(IOleInPlaceSiteEx *iface, BOOL fUndoable)
898 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
899 FIXME("(%p)->(%x)\n", This, fUndoable);
903 static HRESULT WINAPI PHInPlaceSite_OnInPlaceDeactivate(IOleInPlaceSiteEx *iface)
905 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
907 TRACE("(%p)\n", This);
909 if(This->ip_object) {
910 IOleInPlaceObject_Release(This->ip_object);
911 This->ip_object = NULL;
917 static HRESULT WINAPI PHInPlaceSite_DiscardUndoState(IOleInPlaceSiteEx *iface)
919 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
920 FIXME("(%p)\n", This);
924 static HRESULT WINAPI PHInPlaceSite_DeactivateAndUndo(IOleInPlaceSiteEx *iface)
926 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
927 FIXME("(%p)\n", This);
931 static HRESULT WINAPI PHInPlaceSite_OnPosRectChange(IOleInPlaceSiteEx *iface, LPCRECT lprcPosRect)
933 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
934 FIXME("(%p)->(%p)\n", This, lprcPosRect);
938 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceActivateEx(IOleInPlaceSiteEx *iface, BOOL *pfNoRedraw, DWORD dwFlags)
940 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
944 TRACE("(%p)->(%p %x)\n", This, pfNoRedraw, dwFlags);
949 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IOleInPlaceObject, (void**)&This->ip_object);
953 hres = IOleInPlaceObject_GetWindow(This->ip_object, &hwnd);
955 FIXME("Use hwnd %p\n", hwnd);
961 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface, BOOL fNoRedraw)
963 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
964 FIXME("(%p)->(%x)\n", This, fNoRedraw);
968 static HRESULT WINAPI PHInPlaceSiteEx_RequestUIActivate(IOleInPlaceSiteEx *iface)
970 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
971 FIXME("(%p)\n", This);
975 static const IOleInPlaceSiteExVtbl OleInPlaceSiteExVtbl = {
976 PHInPlaceSite_QueryInterface,
977 PHInPlaceSite_AddRef,
978 PHInPlaceSite_Release,
979 PHInPlaceSite_GetWindow,
980 PHInPlaceSite_ContextSensitiveHelp,
981 PHInPlaceSite_CanInPlaceActivate,
982 PHInPlaceSite_OnInPlaceActivate,
983 PHInPlaceSite_OnUIActivate,
984 PHInPlaceSite_GetWindowContext,
985 PHInPlaceSite_Scroll,
986 PHInPlaceSite_OnUIDeactivate,
987 PHInPlaceSite_OnInPlaceDeactivate,
988 PHInPlaceSite_DiscardUndoState,
989 PHInPlaceSite_DeactivateAndUndo,
990 PHInPlaceSite_OnPosRectChange,
991 PHInPlaceSiteEx_OnInPlaceActivateEx,
992 PHInPlaceSiteEx_OnInPlaceDeactivateEx,
993 PHInPlaceSiteEx_RequestUIActivate
996 static inline PluginHost *impl_from_IOleControlSite(IOleControlSite *iface)
998 return CONTAINING_RECORD(iface, PluginHost, IOleControlSite_iface);
1001 static HRESULT WINAPI PHControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
1003 PluginHost *This = impl_from_IOleControlSite(iface);
1004 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1007 static ULONG WINAPI PHControlSite_AddRef(IOleControlSite *iface)
1009 PluginHost *This = impl_from_IOleControlSite(iface);
1010 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1013 static ULONG WINAPI PHControlSite_Release(IOleControlSite *iface)
1015 PluginHost *This = impl_from_IOleControlSite(iface);
1016 return IOleClientSite_Release(&This->IOleClientSite_iface);
1019 static HRESULT WINAPI PHControlSite_OnControlInfoChanged(IOleControlSite *iface)
1021 PluginHost *This = impl_from_IOleControlSite(iface);
1022 FIXME("(%p)\n", This);
1026 static HRESULT WINAPI PHControlSite_LockInPlaceActive(IOleControlSite *iface, BOOL fLock)
1028 PluginHost *This = impl_from_IOleControlSite(iface);
1029 FIXME("(%p)->(%x)\n", This, fLock);
1033 static HRESULT WINAPI PHControlSite_GetExtendedControl(IOleControlSite *iface, IDispatch **ppDisp)
1035 PluginHost *This = impl_from_IOleControlSite(iface);
1036 FIXME("(%p)->(%p)\n", This, ppDisp);
1040 static HRESULT WINAPI PHControlSite_TransformCoords(IOleControlSite *iface, POINTL *pPtlHimetric, POINTF *pPtfContainer, DWORD dwFlags)
1042 PluginHost *This = impl_from_IOleControlSite(iface);
1043 FIXME("(%p)->(%p %p %x)\n", This, pPtlHimetric, pPtfContainer, dwFlags);
1047 static HRESULT WINAPI PHControlSite_TranslateAccelerator(IOleControlSite *iface, MSG *pMsg, DWORD grfModifiers)
1049 PluginHost *This = impl_from_IOleControlSite(iface);
1050 FIXME("(%p)->(%x)\n", This, grfModifiers);
1054 static HRESULT WINAPI PHControlSite_OnFocus(IOleControlSite *iface, BOOL fGotFocus)
1056 PluginHost *This = impl_from_IOleControlSite(iface);
1057 FIXME("(%p)->(%x)\n", This, fGotFocus);
1061 static HRESULT WINAPI PHControlSite_ShowPropertyFrame(IOleControlSite *iface)
1063 PluginHost *This = impl_from_IOleControlSite(iface);
1064 FIXME("(%p)\n", This);
1068 static const IOleControlSiteVtbl OleControlSiteVtbl = {
1069 PHControlSite_QueryInterface,
1070 PHControlSite_AddRef,
1071 PHControlSite_Release,
1072 PHControlSite_OnControlInfoChanged,
1073 PHControlSite_LockInPlaceActive,
1074 PHControlSite_GetExtendedControl,
1075 PHControlSite_TransformCoords,
1076 PHControlSite_TranslateAccelerator,
1077 PHControlSite_OnFocus,
1078 PHControlSite_ShowPropertyFrame
1081 static inline PluginHost *impl_from_IBindHost(IBindHost *iface)
1083 return CONTAINING_RECORD(iface, PluginHost, IBindHost_iface);
1086 static HRESULT WINAPI PHBindHost_QueryInterface(IBindHost *iface, REFIID riid, void **ppv)
1088 PluginHost *This = impl_from_IBindHost(iface);
1089 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1092 static ULONG WINAPI PHBindHost_AddRef(IBindHost *iface)
1094 PluginHost *This = impl_from_IBindHost(iface);
1095 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1098 static ULONG WINAPI PHBindHost_Release(IBindHost *iface)
1100 PluginHost *This = impl_from_IBindHost(iface);
1101 return IOleClientSite_Release(&This->IOleClientSite_iface);
1104 static HRESULT WINAPI PHBindHost_CreateMoniker(IBindHost *iface, LPOLESTR szName, IBindCtx *pBC, IMoniker **ppmk, DWORD dwReserved)
1106 PluginHost *This = impl_from_IBindHost(iface);
1108 TRACE("(%p)->(%s %p %p %x)\n", This, debugstr_w(szName), pBC, ppmk, dwReserved);
1110 if(!This->doc || !This->doc->basedoc.window || !This->doc->basedoc.window->mon) {
1111 FIXME("no moniker\n");
1112 return E_UNEXPECTED;
1115 return CreateURLMoniker(This->doc->basedoc.window->mon, szName, ppmk);
1118 static HRESULT WINAPI PHBindHost_MonikerBindToStorage(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1119 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1121 PluginHost *This = impl_from_IBindHost(iface);
1122 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1126 static HRESULT WINAPI PHBindHost_MonikerBindToObject(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1127 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1129 PluginHost *This = impl_from_IBindHost(iface);
1130 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1134 static const IBindHostVtbl BindHostVtbl = {
1135 PHBindHost_QueryInterface,
1138 PHBindHost_CreateMoniker,
1139 PHBindHost_MonikerBindToStorage,
1140 PHBindHost_MonikerBindToObject
1143 static inline PluginHost *impl_from_IServiceProvider(IServiceProvider *iface)
1145 return CONTAINING_RECORD(iface, PluginHost, IServiceProvider_iface);
1148 static HRESULT WINAPI PHServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1150 PluginHost *This = impl_from_IServiceProvider(iface);
1151 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1154 static ULONG WINAPI PHServiceProvider_AddRef(IServiceProvider *iface)
1156 PluginHost *This = impl_from_IServiceProvider(iface);
1157 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1160 static ULONG WINAPI PHServiceProvider_Release(IServiceProvider *iface)
1162 PluginHost *This = impl_from_IServiceProvider(iface);
1163 return IOleClientSite_Release(&This->IOleClientSite_iface);
1166 static HRESULT WINAPI PHServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
1168 PluginHost *This = impl_from_IServiceProvider(iface);
1170 if(IsEqualGUID(guidService, &SID_SBindHost)) {
1171 TRACE("SID_SBindHost service\n");
1172 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1175 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1177 if(!This->doc || !This->doc->basedoc.window) {
1179 return E_NOINTERFACE;
1182 return IServiceProvider_QueryService(&This->doc->basedoc.window->IServiceProvider_iface,
1183 guidService, riid, ppv);
1186 static const IServiceProviderVtbl ServiceProviderVtbl = {
1187 PHServiceProvider_QueryInterface,
1188 PHServiceProvider_AddRef,
1189 PHServiceProvider_Release,
1190 PHServiceProvider_QueryService
1193 static HRESULT assoc_element(PluginHost *host, HTMLDocumentNode *doc, nsIDOMElement *nselem)
1195 HTMLPluginContainer *container_elem;
1199 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1203 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
1204 (void**)&container_elem);
1206 ERR("Not an object element\n");
1210 container_elem->plugin_host = host;
1211 host->element = container_elem;
1215 void detach_plugin_host(PluginHost *host)
1219 TRACE("%p\n", host);
1224 if(host->ip_object) {
1226 IOleInPlaceObject_UIDeactivate(host->ip_object);
1227 IOleInPlaceObject_InPlaceDeactivate(host->ip_object);
1230 if(host->plugin_unk) {
1231 IOleObject *ole_obj;
1233 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
1234 if(SUCCEEDED(hres)) {
1235 if(!host->ip_object)
1236 IOleObject_Close(ole_obj, OLECLOSE_NOSAVE);
1237 IOleObject_SetClientSite(ole_obj, NULL);
1238 IOleObject_Release(ole_obj);
1243 host->element->plugin_host = NULL;
1244 host->element = NULL;
1247 list_remove(&host->entry);
1251 HRESULT create_plugin_host(HTMLDocumentNode *doc, nsIDOMElement *nselem, IUnknown *unk, const CLSID *clsid, PluginHost **ret)
1256 host = heap_alloc_zero(sizeof(*host));
1258 return E_OUTOFMEMORY;
1260 host->IOleClientSite_iface.lpVtbl = &OleClientSiteVtbl;
1261 host->IAdviseSinkEx_iface.lpVtbl = &AdviseSinkExVtbl;
1262 host->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1263 host->IDispatch_iface.lpVtbl = &DispatchVtbl;
1264 host->IOleInPlaceSiteEx_iface.lpVtbl = &OleInPlaceSiteExVtbl;
1265 host->IOleControlSite_iface.lpVtbl = &OleControlSiteVtbl;
1266 host->IBindHost_iface.lpVtbl = &BindHostVtbl;
1267 host->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
1271 hres = assoc_element(host, doc, nselem);
1277 IUnknown_AddRef(unk);
1278 host->plugin_unk = unk;
1279 host->clsid = *clsid;
1282 list_add_tail(&doc->plugin_hosts, &host->entry);