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"
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;
50 cs.clsid = host->clsid;
51 cs.pUnk = host->plugin_unk;
52 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
54 hres = IInternetHostSecurityManager_QueryCustomPolicy(HOSTSECMGR(host->doc),
55 &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
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;
74 cs.clsid = host->clsid;
75 cs.pUnk = host->plugin_unk;
78 hres = IInternetHostSecurityManager_QueryCustomPolicy(HOSTSECMGR(host->doc),
79 &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
83 policy = *(DWORD*)ppolicy;
84 CoTaskMemFree(ppolicy);
86 if(policy != URLPOLICY_ALLOW)
90 hres = IDispatch_Invoke(host->disp, DISPID_SECURITYCTX, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, &v, NULL, &err);
92 FIXME("Handle security ctx %s\n", debugstr_variant(&v));
99 static void update_readystate(PluginHost *host)
101 DISPPARAMS params = {NULL,NULL,0,0};
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);
118 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, &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));
127 /* FIXME: We shouldn't need this function and we should embed plugin directly in the main document */
128 void get_pos_rect(PluginHost *host, RECT *ret)
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;
141 hres = create_param_prop_bag(host->element->element.nselem, &prop_bag);
145 if(prop_bag && !check_load_safety(host)) {
146 IPropertyBag_Release(prop_bag);
151 hres = IPersistPropertyBag_Load(persist_prop_bag, prop_bag, NULL);
152 IPropertyBag_Release(prop_bag);
154 WARN("Load failed: %08x\n", hres);
156 hres = IPersistPropertyBag_InitNew(persist_prop_bag);
158 WARN("InitNew failed: %08x\n", hres);
162 static void load_plugin(PluginHost *host)
164 IPersistPropertyBag2 *persist_prop_bag2;
165 IPersistPropertyBag *persist_prop_bag;
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);
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);
182 FIXME("No IPersistPropertyBag iface\n");
185 static void activate_plugin(PluginHost *host)
187 IClientSecurity *client_security;
188 IQuickActivate *quick_activate;
189 IOleCommandTarget *cmdtrg;
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 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);
222 FIXME("QuickActivate failed: %08x\n", hres);
224 FIXME("No IQuickActivate\n");
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;
237 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
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);
252 FIXME("Plugin does not support IOleObject\n");
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);
260 WARN("DoVerb failed: %08x\n", hres);
262 if(host->ip_object) {
265 hres = IOleInPlaceObject_GetWindow(host->ip_object, &hwnd);
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");
280 TRACE("%p %s\n", hwnd, wine_dbgstr_rect(rect));
282 if(memcmp(rect, &host->rect, sizeof(RECT))) {
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)
300 host = plugin_container->plugin_host;
302 ERR("No plugin host\n");
311 if(!check_script_safety(host)) {
312 FIXME("Insecure object\n");
316 IDispatch_AddRef(host->disp);
321 HRESULT get_plugin_dispid(HTMLPluginContainer *plugin_container, WCHAR *name, DISPID *ret)
328 if(!plugin_container->plugin_host) {
329 WARN("no plugin host\n");
330 return DISP_E_UNKNOWNNAME;
333 disp = plugin_container->plugin_host->disp;
335 return DISP_E_UNKNOWNNAME;
337 hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, &id);
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;
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) {
358 new_props = heap_realloc(plugin_container->props, plugin_container->props_size*2);
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++;
372 HRESULT invoke_plugin_prop(HTMLPluginContainer *plugin_container, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
373 VARIANT *res, EXCEPINFO *ei)
377 host = plugin_container->plugin_host;
378 if(!host || !host->disp) {
379 FIXME("Called with no disp\n");
383 if(!check_script_safety(host)) {
384 FIXME("Insecure object\n");
388 if(id < MSHTML_DISPID_CUSTOM_MIN || id > MSHTML_DISPID_CUSTOM_MIN + plugin_container->props_len) {
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;
443 WARN("Unsupported interface %s\n", debugstr_guid(riid));
445 return E_NOINTERFACE;
448 IOleClientSite_AddRef((IUnknown*)*ppv);
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);
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);
471 IDispatch_Release(This->disp);
473 IOleInPlaceObject_Release(This->ip_object);
474 list_remove(&This->entry);
476 This->element->plugin_host = NULL;
478 IUnknown_Release(This->plugin_unk);
485 static HRESULT WINAPI PHClientSite_SaveObject(IOleClientSite *iface)
487 PluginHost *This = impl_from_IOleClientSite(iface);
488 FIXME("(%p)\n", This);
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");
506 *ppmk = This->doc->basedoc.window->mon;
507 IMoniker_AddRef(*ppmk);
510 FIXME("which %d\n", dwWhichMoniker);
517 static HRESULT WINAPI PHClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
519 PluginHost *This = impl_from_IOleClientSite(iface);
521 TRACE("(%p)->(%p)\n", This, ppContainer);
524 ERR("Called on detached object\n");
528 *ppContainer = &This->doc->basedoc.IOleContainer_iface;
529 IOleContainer_AddRef(*ppContainer);
533 static HRESULT WINAPI PHClientSite_ShowObject(IOleClientSite *iface)
535 PluginHost *This = impl_from_IOleClientSite(iface);
537 TRACE("(%p)\n", This);
542 static HRESULT WINAPI PHClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
544 PluginHost *This = impl_from_IOleClientSite(iface);
545 FIXME("(%p)->(%x)\n", This, fShow);
549 static HRESULT WINAPI PHClientSite_RequestNewObjectLayout(IOleClientSite *iface)
551 PluginHost *This = impl_from_IOleClientSite(iface);
552 FIXME("(%p)\n", This);
556 static const IOleClientSiteVtbl OleClientSiteVtbl = {
557 PHClientSite_QueryInterface,
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);
669 case DISPID_READYSTATE:
670 update_readystate(This);
673 FIXME("Unimplemented dispID %d\n", dispID);
680 static HRESULT WINAPI PHPropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
682 PluginHost *This = impl_from_IPropertyNotifySink(iface);
683 FIXME("(%p)->(%d)\n", This, dispID);
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);
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);
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);
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);
749 static const IDispatchVtbl DispatchVtbl = {
750 PHDispatch_QueryInterface,
753 PHDispatch_GetTypeInfoCount,
754 PHDispatch_GetTypeInfo,
755 PHDispatch_GetIDsOfNames,
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);
792 static HRESULT WINAPI PHInPlaceSite_ContextSensitiveHelp(IOleInPlaceSiteEx *iface, BOOL fEnterMode)
794 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
795 FIXME("(%p)->(%x)\n", This, fEnterMode);
799 static HRESULT WINAPI PHInPlaceSite_CanInPlaceActivate(IOleInPlaceSiteEx *iface)
801 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
802 FIXME("(%p)\n", This);
806 static HRESULT WINAPI PHInPlaceSite_OnInPlaceActivate(IOleInPlaceSiteEx *iface)
808 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
809 FIXME("(%p)\n", This);
813 static HRESULT WINAPI PHInPlaceSite_OnUIActivate(IOleInPlaceSiteEx *iface)
815 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
816 DISPPARAMS args = {NULL, NULL, 0, 0};
822 TRACE("(%p)\n", This);
824 if(!This->plugin_unk) {
825 ERR("No plugin object\n");
829 This->ui_active = TRUE;
831 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IDispatch, (void**)&disp);
833 FIXME("Could not get IDispatch iface: %08x\n", 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));
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;
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");
865 hres = IOleInPlaceSite_GetWindowContext(This->doc->basedoc.doc_obj->ipsite, &ip_frame, &ip_window, &pr, &cr, frame_info);
867 WARN("GetWindowContext failed: %08x\n", hres);
872 IOleInPlaceUIWindow_Release(ip_window);
874 IOleInPlaceFrame_Release(ip_frame);
876 hres = create_ip_frame(&ip_frame);
880 hres = create_ip_window(ppDoc);
885 *lprcPosRect = This->rect;
886 *lprcClipRect = This->rect;
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);
897 static HRESULT WINAPI PHInPlaceSite_OnUIDeactivate(IOleInPlaceSiteEx *iface, BOOL fUndoable)
899 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
900 FIXME("(%p)->(%x)\n", This, fUndoable);
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;
918 static HRESULT WINAPI PHInPlaceSite_DiscardUndoState(IOleInPlaceSiteEx *iface)
920 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
921 FIXME("(%p)\n", This);
925 static HRESULT WINAPI PHInPlaceSite_DeactivateAndUndo(IOleInPlaceSiteEx *iface)
927 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
928 FIXME("(%p)\n", This);
932 static HRESULT WINAPI PHInPlaceSite_OnPosRectChange(IOleInPlaceSiteEx *iface, LPCRECT lprcPosRect)
934 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
935 FIXME("(%p)->(%p)\n", This, lprcPosRect);
939 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceActivateEx(IOleInPlaceSiteEx *iface, BOOL *pfNoRedraw, DWORD dwFlags)
941 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
945 TRACE("(%p)->(%p %x)\n", This, pfNoRedraw, dwFlags);
950 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IOleInPlaceObject, (void**)&This->ip_object);
954 hres = IOleInPlaceObject_GetWindow(This->ip_object, &hwnd);
956 FIXME("Use hwnd %p\n", hwnd);
962 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface, BOOL fNoRedraw)
964 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
965 FIXME("(%p)->(%x)\n", This, fNoRedraw);
969 static HRESULT WINAPI PHInPlaceSiteEx_RequestUIActivate(IOleInPlaceSiteEx *iface)
971 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
972 FIXME("(%p)\n", This);
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);
1027 static HRESULT WINAPI PHControlSite_LockInPlaceActive(IOleControlSite *iface, BOOL fLock)
1029 PluginHost *This = impl_from_IOleControlSite(iface);
1030 FIXME("(%p)->(%x)\n", This, fLock);
1034 static HRESULT WINAPI PHControlSite_GetExtendedControl(IOleControlSite *iface, IDispatch **ppDisp)
1036 PluginHost *This = impl_from_IOleControlSite(iface);
1037 FIXME("(%p)->(%p)\n", This, ppDisp);
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);
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);
1055 static HRESULT WINAPI PHControlSite_OnFocus(IOleControlSite *iface, BOOL fGotFocus)
1057 PluginHost *This = impl_from_IOleControlSite(iface);
1058 FIXME("(%p)->(%x)\n", This, fGotFocus);
1062 static HRESULT WINAPI PHControlSite_ShowPropertyFrame(IOleControlSite *iface)
1064 PluginHost *This = impl_from_IOleControlSite(iface);
1065 FIXME("(%p)\n", This);
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);
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);
1135 static const IBindHostVtbl BindHostVtbl = {
1136 PHBindHost_QueryInterface,
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) {
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;
1200 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1204 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
1205 (void**)&container_elem);
1207 ERR("Not an object element\n");
1211 container_elem->plugin_host = host;
1212 host->element = container_elem;
1216 void detach_plugin_host(PluginHost *host)
1220 TRACE("%p\n", host);
1225 if(host->ip_object) {
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);
1244 host->element->plugin_host = NULL;
1245 host->element = NULL;
1248 list_remove(&host->entry);
1252 HRESULT create_plugin_host(HTMLDocumentNode *doc, nsIDOMElement *nselem, IUnknown *unk, const CLSID *clsid, PluginHost **ret)
1257 host = heap_alloc_zero(sizeof(*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;
1272 hres = assoc_element(host, doc, nselem);
1278 IUnknown_AddRef(unk);
1279 host->plugin_unk = unk;
1280 host->clsid = *clsid;
1283 list_add_tail(&doc->plugin_hosts, &host->entry);