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
33 #include "mshtml_private.h"
34 #include "pluginhost.h"
36 #include "wine/debug.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(&host->doc->IInternetHostSecurityManager_iface,
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(&host->doc->IInternetHostSecurityManager_iface,
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 static 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 IOleObject *ole_obj = NULL;
190 IOleCommandTarget *cmdtrg;
191 IViewObjectEx *view_obj;
197 if(!host->plugin_unk)
200 /* Note native calls QI on plugin for an undocumented IID and CLSID_HTMLDocument */
202 /* FIXME: call FreezeEvents(TRUE) */
204 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IClientSecurity, (void**)&client_security);
205 if(SUCCEEDED(hres)) {
206 FIXME("Handle IClientSecurity\n");
207 IClientSecurity_Release(client_security);
211 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IQuickActivate, (void**)&quick_activate);
212 if(SUCCEEDED(hres)) {
213 QACONTAINER container = {sizeof(container)};
214 QACONTROL control = {sizeof(control)};
216 TRACE("Using IQuickActivate\n");
218 container.pClientSite = &host->IOleClientSite_iface;
219 container.dwAmbientFlags = QACONTAINER_SUPPORTSMNEMONICS|QACONTAINER_MESSAGEREFLECT|QACONTAINER_USERMODE;
220 container.pAdviseSink = &host->IAdviseSinkEx_iface;
221 container.pPropertyNotifySink = &host->IPropertyNotifySink_iface;
223 hres = IQuickActivate_QuickActivate(quick_activate, &container, &control);
224 IQuickActivate_Release(quick_activate);
226 FIXME("QuickActivate failed: %08x\n", hres);
230 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
231 if(SUCCEEDED(hres)) {
232 hres = IOleObject_GetMiscStatus(ole_obj, DVASPECT_CONTENT, &status);
233 TRACE("GetMiscStatus returned %08x %x\n", hres, status);
235 hres = IOleObject_SetClientSite(ole_obj, &host->IOleClientSite_iface);
236 IOleObject_Release(ole_obj);
238 FIXME("SetClientSite failed: %08x\n", hres);
242 TRACE("Plugin does not support IOleObject\n");
249 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IViewObjectEx, (void**)&view_obj);
250 if(SUCCEEDED(hres)) {
251 DWORD view_status = 0;
253 hres = IViewObjectEx_SetAdvise(view_obj, DVASPECT_CONTENT, 0, (IAdviseSink*)&host->IAdviseSinkEx_iface);
255 WARN("SetAdvise failed: %08x\n", hres);
257 hres = IViewObjectEx_GetViewStatus(view_obj, &view_status);
258 IViewObjectEx_Release(view_obj);
259 TRACE("GetViewStatus returned %08x %x\n", hres, view_status);
263 update_readystate(host);
265 /* NOTE: Native QIs for IActiveScript, an undocumented IID, IOleControl and IRunnableObject */
267 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatchEx, (void**)&dispex);
268 if(SUCCEEDED(hres)) {
269 FIXME("Use IDispatchEx\n");
270 host->disp = (IDispatch*)dispex;
272 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IDispatch, (void**)&disp);
276 TRACE("no IDispatch iface\n");
279 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
280 if(SUCCEEDED(hres)) {
281 FIXME("Use IOleCommandTarget\n");
282 IOleCommandTarget_Release(cmdtrg);
285 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
287 FIXME("Plugin does not support IOleObject\n");
292 get_pos_rect(host, &rect);
293 hres = IOleObject_DoVerb(ole_obj, OLEIVERB_INPLACEACTIVATE, NULL, &host->IOleClientSite_iface, 0, host->hwnd, &rect);
294 IOleObject_Release(ole_obj);
296 WARN("DoVerb failed: %08x\n", hres);
299 if(host->ip_object) {
302 hres = IOleInPlaceObject_GetWindow(host->ip_object, &hwnd);
304 TRACE("hwnd %p\n", hwnd);
308 void update_plugin_window(PluginHost *host, HWND hwnd, const RECT *rect)
310 BOOL rect_changed = FALSE;
312 if(!hwnd || (host->hwnd && host->hwnd != hwnd)) {
313 FIXME("unhandled hwnd\n");
317 TRACE("%p %s\n", hwnd, wine_dbgstr_rect(rect));
319 if(memcmp(rect, &host->rect, sizeof(RECT))) {
326 activate_plugin(host);
329 if(rect_changed && host->ip_object)
330 IOleInPlaceObject_SetObjectRects(host->ip_object, &host->rect, &host->rect);
333 static void notif_enabled(PluginHost *plugin_host)
335 DISPPARAMS args = {NULL, NULL, 0, 0};
341 hres = IUnknown_QueryInterface(plugin_host->plugin_unk, &IID_IDispatch, (void**)&disp);
343 FIXME("Could not get IDispatch iface: %08x\n", hres);
347 V_VT(&res) = VT_EMPTY;
348 hres = IDispatch_Invoke(disp, DISPID_ENABLED, &IID_NULL, 0/*FIXME*/, DISPATCH_PROPERTYGET, &args, &res, NULL, &err);
349 IDispatch_Release(disp);
350 if(SUCCEEDED(hres)) {
351 FIXME("Got enabled %s\n", debugstr_variant(&res));
356 void notif_container_change(HTMLPluginContainer *plugin_container, DISPID dispid)
358 IOleControl *ole_control;
361 if(!plugin_container->plugin_host || !plugin_container->plugin_host->plugin_unk)
364 notif_enabled(plugin_container->plugin_host);
366 hres = IUnknown_QueryInterface(plugin_container->plugin_host->plugin_unk, &IID_IOleControl, (void**)&ole_control);
367 if(SUCCEEDED(hres)) {
368 IOleControl_OnAmbientPropertyChange(ole_control, dispid);
369 IOleControl_Release(ole_control);
373 HRESULT get_plugin_disp(HTMLPluginContainer *plugin_container, IDispatch **ret)
377 host = plugin_container->plugin_host;
379 ERR("No plugin host\n");
388 if(!check_script_safety(host)) {
389 FIXME("Insecure object\n");
393 IDispatch_AddRef(host->disp);
398 HRESULT get_plugin_dispid(HTMLPluginContainer *plugin_container, WCHAR *name, DISPID *ret)
405 if(!plugin_container->plugin_host) {
406 WARN("no plugin host\n");
407 return DISP_E_UNKNOWNNAME;
410 disp = plugin_container->plugin_host->disp;
412 return DISP_E_UNKNOWNNAME;
414 hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, &id);
416 TRACE("no prop %s\n", debugstr_w(name));
417 return DISP_E_UNKNOWNNAME;
420 for(i=0; i < plugin_container->props_len; i++) {
421 if(id == plugin_container->props[i]) {
422 *ret = MSHTML_DISPID_CUSTOM_MIN+i;
427 if(!plugin_container->props) {
428 plugin_container->props = heap_alloc(8*sizeof(DISPID));
429 if(!plugin_container->props)
430 return E_OUTOFMEMORY;
431 plugin_container->props_size = 8;
432 }else if(plugin_container->props_len == plugin_container->props_size) {
435 new_props = heap_realloc(plugin_container->props, plugin_container->props_size*2*sizeof(DISPID));
437 return E_OUTOFMEMORY;
439 plugin_container->props = new_props;
440 plugin_container->props_size *= 2;
443 plugin_container->props[plugin_container->props_len] = id;
444 *ret = MSHTML_DISPID_CUSTOM_MIN+plugin_container->props_len;
445 plugin_container->props_len++;
449 HRESULT invoke_plugin_prop(HTMLPluginContainer *plugin_container, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
450 VARIANT *res, EXCEPINFO *ei)
454 host = plugin_container->plugin_host;
455 if(!host || !host->disp) {
456 FIXME("Called with no disp\n");
460 if(!check_script_safety(host)) {
461 FIXME("Insecure object\n");
465 if(id < MSHTML_DISPID_CUSTOM_MIN || id > MSHTML_DISPID_CUSTOM_MIN + plugin_container->props_len) {
470 return IDispatch_Invoke(host->disp, plugin_container->props[id-MSHTML_DISPID_CUSTOM_MIN], &IID_NULL,
471 lcid, flags, params, res, ei, NULL);
480 IDispatch IDispatch_iface;
490 sink_entry_t *handlers;
495 static sink_entry_t *find_sink_entry(PHEventSink *sink, DISPID id)
499 for(iter = sink->handlers; iter < sink->handlers+sink->handlers_cnt; iter++) {
507 static void add_sink_handler(PHEventSink *sink, DISPID id, IDispatch *disp)
509 sink_entry_t *entry = find_sink_entry(sink, id);
513 IDispatch_Release(entry->disp);
515 if(!sink->handlers_size) {
516 sink->handlers = heap_alloc(4*sizeof(*sink->handlers));
519 sink->handlers_size = 4;
520 }else if(sink->handlers_cnt == sink->handlers_size) {
521 sink_entry_t *new_handlers;
523 new_handlers = heap_realloc(sink->handlers, 2*sink->handlers_size*sizeof(*sink->handlers));
526 sink->handlers = new_handlers;
527 sink->handlers_size *= 2;
529 entry = sink->handlers + sink->handlers_cnt++;
533 IDispatch_AddRef(disp);
537 static inline PHEventSink *PHEventSink_from_IDispatch(IDispatch *iface)
539 return CONTAINING_RECORD(iface, PHEventSink, IDispatch_iface);
542 static HRESULT WINAPI PHEventSink_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
544 PHEventSink *This = PHEventSink_from_IDispatch(iface);
546 if(IsEqualGUID(riid, &IID_IUnknown)) {
547 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
548 *ppv = &This->IDispatch_iface;
549 }else if(IsEqualGUID(riid, &IID_IDispatch)) {
550 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
551 *ppv = &This->IDispatch_iface;
552 }else if(This->is_dispiface && IsEqualGUID(riid, &This->iid)) {
553 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
554 *ppv = &This->IDispatch_iface;
556 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
558 return E_NOINTERFACE;
561 IUnknown_AddRef((IUnknown*)*ppv);
565 static ULONG WINAPI PHEventSink_AddRef(IDispatch *iface)
567 PHEventSink *This = PHEventSink_from_IDispatch(iface);
568 LONG ref = InterlockedIncrement(&This->ref);
570 TRACE("(%p)\n", This);
575 static ULONG WINAPI PHEventSink_Release(IDispatch *iface)
577 PHEventSink *This = PHEventSink_from_IDispatch(iface);
578 LONG ref = InterlockedDecrement(&This->ref);
580 TRACE("(%p)\n", This);
587 for(i=0; i < This->handlers_cnt; i++) {
588 if(This->handlers[i].disp)
589 IDispatch_Release(This->handlers[i].disp);
591 heap_free(This->handlers);
598 static HRESULT WINAPI PHEventSink_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
600 PHEventSink *This = PHEventSink_from_IDispatch(iface);
601 FIXME("(%p)->(%p)\n", This, pctinfo);
605 static HRESULT WINAPI PHEventSink_GetTypeInfo(IDispatch *iface, UINT iTInfo,
606 LCID lcid, ITypeInfo **ppTInfo)
608 PHEventSink *This = PHEventSink_from_IDispatch(iface);
609 FIXME("(%p)->(%d %d %p)\n", This, iTInfo, lcid, ppTInfo);
613 static HRESULT WINAPI PHEventSink_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
614 UINT cNames, LCID lcid, DISPID *rgDispId)
616 PHEventSink *This = PHEventSink_from_IDispatch(iface);
617 FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
621 static HRESULT WINAPI PHEventSink_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
622 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
624 PHEventSink *This = PHEventSink_from_IDispatch(iface);
629 TRACE("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid, wFlags,
630 pDispParams, pVarResult, pExcepInfo, puArgErr);
637 entry = find_sink_entry(This, dispIdMember);
638 if(!entry || !entry->disp) {
639 WARN("No handler %d\n", dispIdMember);
641 V_VT(pVarResult) = VT_EMPTY;
645 hres = IDispatch_QueryInterface(entry->disp, &IID_IDispatchEx, (void**)&dispex);
647 TRACE("(%p) %d >>>\n", This, entry->id);
648 if(SUCCEEDED(hres)) {
649 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, NULL);
650 IDispatchEx_Release(dispex);
652 hres = IDispatch_Invoke(entry->disp, DISPID_VALUE, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
655 TRACE("(%p) %d <<<\n", This, entry->id);
657 WARN("(%p) %d <<< %08x\n", This, entry->id, hres);
661 static const IDispatchVtbl PHCPDispatchVtbl = {
662 PHEventSink_QueryInterface,
665 PHEventSink_GetTypeInfoCount,
666 PHEventSink_GetTypeInfo,
667 PHEventSink_GetIDsOfNames,
671 static PHEventSink *create_event_sink(PluginHost *plugin_host, ITypeInfo *typeinfo)
673 IConnectionPointContainer *cp_container;
675 IConnectionPoint *cp;
681 hres = ITypeInfo_GetTypeAttr(typeinfo, &typeattr);
685 typekind = typeattr->typekind;
686 guid = typeattr->guid;
687 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
689 TRACE("guid %s typekind %d\n", debugstr_guid(&guid), typekind);
691 if(typekind != TKIND_INTERFACE && typekind != TKIND_DISPATCH) {
692 WARN("invalid typekind %d\n", typekind);
696 hres = IUnknown_QueryInterface(plugin_host->plugin_unk, &IID_IConnectionPointContainer, (void**)&cp_container);
698 WARN("Could not get IConnectionPointContainer iface: %08x\n", hres);
702 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &guid, &cp);
703 IConnectionPointContainer_Release(cp_container);
705 WARN("Could not find %s connection point\n", debugstr_guid(&guid));
709 ret = heap_alloc_zero(sizeof(*ret));
711 ret->IDispatch_iface.lpVtbl = &PHCPDispatchVtbl;
713 ret->host = plugin_host;
715 ret->is_dispiface = typekind == TKIND_DISPATCH;
717 ITypeInfo_AddRef(typeinfo);
718 ret->typeinfo = typeinfo;
720 hres = IConnectionPoint_Advise(cp, (IUnknown*)&ret->IDispatch_iface, &ret->cookie);
722 hres = E_OUTOFMEMORY;
725 IConnectionPoint_Release(cp);
727 WARN("Advise failed: %08x\n", hres);
734 static ITypeInfo *get_eventiface_info(HTMLPluginContainer *plugin_container, ITypeInfo *class_info)
736 int impl_types, i, impl_flags;
737 ITypeInfo *ret = NULL;
742 hres = ITypeInfo_GetTypeAttr(class_info, &typeattr);
746 if(typeattr->typekind != TKIND_COCLASS) {
747 WARN("not coclass\n");
748 ITypeInfo_ReleaseTypeAttr(class_info, typeattr);
752 impl_types = typeattr->cImplTypes;
753 ITypeInfo_ReleaseTypeAttr(class_info, typeattr);
755 for(i=0; i<impl_types; i++) {
756 hres = ITypeInfo_GetImplTypeFlags(class_info, i, &impl_flags);
760 if((impl_flags & IMPLTYPEFLAG_FSOURCE)) {
761 if(!(impl_flags & IMPLTYPEFLAG_FDEFAULT)) {
762 FIXME("Handle non-default source iface\n");
766 hres = ITypeInfo_GetRefTypeOfImplType(class_info, i, &ref);
770 hres = ITypeInfo_GetRefTypeInfo(class_info, ref, &ret);
779 void bind_activex_event(HTMLDocumentNode *doc, HTMLPluginContainer *plugin_container, WCHAR *event, IDispatch *disp)
781 PluginHost *plugin_host = plugin_container->plugin_host;
782 ITypeInfo *class_info, *source_info;
786 TRACE("(%p %p %s %p)\n", doc, plugin_host, debugstr_w(event), disp);
788 if(!plugin_host || !plugin_host->plugin_unk) {
789 WARN("detached element %p\n", plugin_host);
793 if(plugin_host->sink) {
794 source_info = plugin_host->sink->typeinfo;
795 ITypeInfo_AddRef(source_info);
797 IProvideClassInfo *provide_ci;
799 hres = IUnknown_QueryInterface(plugin_host->plugin_unk, &IID_IProvideClassInfo, (void**)&provide_ci);
801 FIXME("No IProvideClassInfo, try GetTypeInfo?\n");
805 hres = IProvideClassInfo_GetClassInfo(provide_ci, &class_info);
806 IProvideClassInfo_Release(provide_ci);
807 if(FAILED(hres) || !class_info) {
808 WARN("GetClassInfo failed: %08x\n", hres);
812 source_info = get_eventiface_info(plugin_container, class_info);
813 ITypeInfo_Release(class_info);
818 hres = ITypeInfo_GetIDsOfNames(source_info, &event, 1, &id);
820 WARN("Could not get disp id: %08x\n", hres);
821 else if(!plugin_host->sink)
822 plugin_host->sink = create_event_sink(plugin_host, source_info);
824 ITypeInfo_Release(source_info);
825 if(FAILED(hres) || !plugin_host->sink)
828 add_sink_handler(plugin_host->sink, id, disp);
831 static inline PluginHost *impl_from_IOleClientSite(IOleClientSite *iface)
833 return CONTAINING_RECORD(iface, PluginHost, IOleClientSite_iface);
836 static HRESULT WINAPI PHClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
838 PluginHost *This = impl_from_IOleClientSite(iface);
840 if(IsEqualGUID(&IID_IUnknown, riid)) {
841 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
842 *ppv = &This->IOleClientSite_iface;
843 }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
844 TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
845 *ppv = &This->IOleClientSite_iface;
846 }else if(IsEqualGUID(&IID_IAdviseSink, riid)) {
847 TRACE("(%p)->(IID_IAdviseSink %p)\n", This, ppv);
848 *ppv = &This->IAdviseSinkEx_iface;
849 }else if(IsEqualGUID(&IID_IAdviseSinkEx, riid)) {
850 TRACE("(%p)->(IID_IAdviseSinkEx %p)\n", This, ppv);
851 *ppv = &This->IAdviseSinkEx_iface;
852 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
853 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv);
854 *ppv = &This->IPropertyNotifySink_iface;
855 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
856 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
857 *ppv = &This->IDispatch_iface;
858 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
859 TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
860 *ppv = &This->IOleInPlaceSiteEx_iface;
861 }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
862 TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
863 *ppv = &This->IOleInPlaceSiteEx_iface;
864 }else if(IsEqualGUID(&IID_IOleInPlaceSiteEx, riid)) {
865 TRACE("(%p)->(IID_IOleInPlaceSiteEx %p)\n", This, ppv);
866 *ppv = &This->IOleInPlaceSiteEx_iface;
867 }else if(IsEqualGUID(&IID_IOleControlSite, riid)) {
868 TRACE("(%p)->(IID_IOleControlSite %p)\n", This, ppv);
869 *ppv = &This->IOleControlSite_iface;
870 }else if(IsEqualGUID(&IID_IBindHost, riid)) {
871 TRACE("(%p)->(IID_IBindHost %p)\n", This, ppv);
872 *ppv = &This->IBindHost_iface;
873 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
874 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
875 *ppv = &This->IServiceProvider_iface;
877 WARN("Unsupported interface %s\n", debugstr_guid(riid));
879 return E_NOINTERFACE;
882 IUnknown_AddRef((IUnknown*)*ppv);
886 static ULONG WINAPI PHClientSite_AddRef(IOleClientSite *iface)
888 PluginHost *This = impl_from_IOleClientSite(iface);
889 LONG ref = InterlockedIncrement(&This->ref);
891 TRACE("(%p) ref=%d\n", This, ref);
896 static ULONG WINAPI PHClientSite_Release(IOleClientSite *iface)
898 PluginHost *This = impl_from_IOleClientSite(iface);
899 LONG ref = InterlockedDecrement(&This->ref);
901 TRACE("(%p) ref=%d\n", This, ref);
905 IDispatch_Release(This->disp);
907 IOleInPlaceObject_Release(This->ip_object);
909 This->sink->host = NULL;
910 IDispatch_Release(&This->sink->IDispatch_iface);
913 list_remove(&This->entry);
915 This->element->plugin_host = NULL;
917 IUnknown_Release(This->plugin_unk);
924 static HRESULT WINAPI PHClientSite_SaveObject(IOleClientSite *iface)
926 PluginHost *This = impl_from_IOleClientSite(iface);
927 FIXME("(%p)\n", This);
931 static HRESULT WINAPI PHClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
932 DWORD dwWhichMoniker, IMoniker **ppmk)
934 PluginHost *This = impl_from_IOleClientSite(iface);
936 TRACE("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
938 switch(dwWhichMoniker) {
939 case OLEWHICHMK_CONTAINER:
940 if(!This->doc || !This->doc->window || !This->doc->window->mon) {
941 FIXME("no moniker\n");
945 *ppmk = This->doc->window->mon;
946 IMoniker_AddRef(*ppmk);
949 FIXME("which %d\n", dwWhichMoniker);
956 static HRESULT WINAPI PHClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
958 PluginHost *This = impl_from_IOleClientSite(iface);
960 TRACE("(%p)->(%p)\n", This, ppContainer);
963 ERR("Called on detached object\n");
967 *ppContainer = &This->doc->basedoc.IOleContainer_iface;
968 IOleContainer_AddRef(*ppContainer);
972 static HRESULT WINAPI PHClientSite_ShowObject(IOleClientSite *iface)
974 PluginHost *This = impl_from_IOleClientSite(iface);
976 TRACE("(%p)\n", This);
981 static HRESULT WINAPI PHClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
983 PluginHost *This = impl_from_IOleClientSite(iface);
984 FIXME("(%p)->(%x)\n", This, fShow);
988 static HRESULT WINAPI PHClientSite_RequestNewObjectLayout(IOleClientSite *iface)
990 PluginHost *This = impl_from_IOleClientSite(iface);
991 FIXME("(%p)\n", This);
995 static const IOleClientSiteVtbl OleClientSiteVtbl = {
996 PHClientSite_QueryInterface,
998 PHClientSite_Release,
999 PHClientSite_SaveObject,
1000 PHClientSite_GetMoniker,
1001 PHClientSite_GetContainer,
1002 PHClientSite_ShowObject,
1003 PHClientSite_OnShowWindow,
1004 PHClientSite_RequestNewObjectLayout
1007 static inline PluginHost *impl_from_IAdviseSinkEx(IAdviseSinkEx *iface)
1009 return CONTAINING_RECORD(iface, PluginHost, IAdviseSinkEx_iface);
1012 static HRESULT WINAPI PHAdviseSinkEx_QueryInterface(IAdviseSinkEx *iface, REFIID riid, void **ppv)
1014 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1015 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1018 static ULONG WINAPI PHAdviseSinkEx_AddRef(IAdviseSinkEx *iface)
1020 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1021 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1024 static ULONG WINAPI PHAdviseSinkEx_Release(IAdviseSinkEx *iface)
1026 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1027 return IOleClientSite_Release(&This->IOleClientSite_iface);
1030 static void WINAPI PHAdviseSinkEx_OnDataChange(IAdviseSinkEx *iface, FORMATETC *pFormatetc, STGMEDIUM *pStgMedium)
1032 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1033 FIXME("(%p)->(%p %p)\n", This, pFormatetc, pStgMedium);
1036 static void WINAPI PHAdviseSinkEx_OnViewChange(IAdviseSinkEx *iface, DWORD dwAspect, LONG lindex)
1038 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1039 FIXME("(%p)->(%d %d)\n", This, dwAspect, lindex);
1042 static void WINAPI PHAdviseSinkEx_OnRename(IAdviseSinkEx *iface, IMoniker *pmk)
1044 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1045 FIXME("(%p)->(%p)\n", This, pmk);
1048 static void WINAPI PHAdviseSinkEx_OnSave(IAdviseSinkEx *iface)
1050 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1051 FIXME("(%p)\n", This);
1054 static void WINAPI PHAdviseSinkEx_OnClose(IAdviseSinkEx *iface)
1056 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1057 FIXME("(%p)\n", This);
1060 static void WINAPI PHAdviseSinkEx_OnViewStatusChange(IAdviseSinkEx *iface, DWORD dwViewStatus)
1062 PluginHost *This = impl_from_IAdviseSinkEx(iface);
1063 FIXME("(%p)->(%d)\n", This, dwViewStatus);
1066 static const IAdviseSinkExVtbl AdviseSinkExVtbl = {
1067 PHAdviseSinkEx_QueryInterface,
1068 PHAdviseSinkEx_AddRef,
1069 PHAdviseSinkEx_Release,
1070 PHAdviseSinkEx_OnDataChange,
1071 PHAdviseSinkEx_OnViewChange,
1072 PHAdviseSinkEx_OnRename,
1073 PHAdviseSinkEx_OnSave,
1074 PHAdviseSinkEx_OnClose,
1075 PHAdviseSinkEx_OnViewStatusChange
1078 static inline PluginHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
1080 return CONTAINING_RECORD(iface, PluginHost, IPropertyNotifySink_iface);
1083 static HRESULT WINAPI PHPropertyNotifySink_QueryInterface(IPropertyNotifySink *iface, REFIID riid, void **ppv)
1085 PluginHost *This = impl_from_IPropertyNotifySink(iface);
1086 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1089 static ULONG WINAPI PHPropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1091 PluginHost *This = impl_from_IPropertyNotifySink(iface);
1092 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1095 static ULONG WINAPI PHPropertyNotifySink_Release(IPropertyNotifySink *iface)
1097 PluginHost *This = impl_from_IPropertyNotifySink(iface);
1098 return IOleClientSite_Release(&This->IOleClientSite_iface);
1101 static HRESULT WINAPI PHPropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1103 PluginHost *This = impl_from_IPropertyNotifySink(iface);
1105 TRACE("(%p)->(%d)\n", This, dispID);
1108 case DISPID_READYSTATE:
1109 update_readystate(This);
1112 FIXME("Unimplemented dispID %d\n", dispID);
1119 static HRESULT WINAPI PHPropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1121 PluginHost *This = impl_from_IPropertyNotifySink(iface);
1122 FIXME("(%p)->(%d)\n", This, dispID);
1126 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1127 PHPropertyNotifySink_QueryInterface,
1128 PHPropertyNotifySink_AddRef,
1129 PHPropertyNotifySink_Release,
1130 PHPropertyNotifySink_OnChanged,
1131 PHPropertyNotifySink_OnRequestEdit
1134 static inline PluginHost *impl_from_IDispatch(IDispatch *iface)
1136 return CONTAINING_RECORD(iface, PluginHost, IDispatch_iface);
1139 static HRESULT WINAPI PHDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
1141 PluginHost *This = impl_from_IDispatch(iface);
1142 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1145 static ULONG WINAPI PHDispatch_AddRef(IDispatch *iface)
1147 PluginHost *This = impl_from_IDispatch(iface);
1148 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1151 static ULONG WINAPI PHDispatch_Release(IDispatch *iface)
1153 PluginHost *This = impl_from_IDispatch(iface);
1154 return IOleClientSite_Release(&This->IOleClientSite_iface);
1157 static HRESULT WINAPI PHDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
1159 PluginHost *This = impl_from_IDispatch(iface);
1160 FIXME("(%p)->(%p)\n", This, pctinfo);
1164 static HRESULT WINAPI PHDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo,
1165 LCID lcid, ITypeInfo **ppTInfo)
1167 PluginHost *This = impl_from_IDispatch(iface);
1168 FIXME("(%p)->(%d %d %p)\n", This, iTInfo, lcid, ppTInfo);
1172 static HRESULT WINAPI PHDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid,
1173 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1175 PluginHost *This = impl_from_IDispatch(iface);
1176 FIXME("(%p)->(%s %p %d %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1180 static HRESULT WINAPI PHDispatch_Invoke(IDispatch *iface, DISPID dispid, REFIID riid, LCID lcid,
1181 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1183 PluginHost *This = impl_from_IDispatch(iface);
1184 FIXME("(%p)->(%d %x %p %p)\n", This, dispid, wFlags, pDispParams, pVarResult);
1188 static const IDispatchVtbl DispatchVtbl = {
1189 PHDispatch_QueryInterface,
1192 PHDispatch_GetTypeInfoCount,
1193 PHDispatch_GetTypeInfo,
1194 PHDispatch_GetIDsOfNames,
1198 static inline PluginHost *impl_from_IOleInPlaceSiteEx(IOleInPlaceSiteEx *iface)
1200 return CONTAINING_RECORD(iface, PluginHost, IOleInPlaceSiteEx_iface);
1203 static HRESULT WINAPI PHInPlaceSite_QueryInterface(IOleInPlaceSiteEx *iface, REFIID riid, void **ppv)
1205 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1206 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1209 static ULONG WINAPI PHInPlaceSite_AddRef(IOleInPlaceSiteEx *iface)
1211 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1212 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1215 static ULONG WINAPI PHInPlaceSite_Release(IOleInPlaceSiteEx *iface)
1217 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1218 return IOleClientSite_Release(&This->IOleClientSite_iface);
1221 static HRESULT WINAPI PHInPlaceSite_GetWindow(IOleInPlaceSiteEx *iface, HWND *phwnd)
1223 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1225 TRACE("(%p)->(%p)\n", This, phwnd);
1227 *phwnd = This->hwnd;
1231 static HRESULT WINAPI PHInPlaceSite_ContextSensitiveHelp(IOleInPlaceSiteEx *iface, BOOL fEnterMode)
1233 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1234 FIXME("(%p)->(%x)\n", This, fEnterMode);
1238 static HRESULT WINAPI PHInPlaceSite_CanInPlaceActivate(IOleInPlaceSiteEx *iface)
1240 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1242 TRACE("(%p)\n", This);
1247 static HRESULT WINAPI PHInPlaceSite_OnInPlaceActivate(IOleInPlaceSiteEx *iface)
1249 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1250 FIXME("(%p)\n", This);
1254 static HRESULT WINAPI PHInPlaceSite_OnUIActivate(IOleInPlaceSiteEx *iface)
1256 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1258 TRACE("(%p)\n", This);
1260 if(!This->plugin_unk) {
1261 ERR("No plugin object\n");
1262 return E_UNEXPECTED;
1265 This->ui_active = TRUE;
1267 notif_enabled(This);
1271 static HRESULT WINAPI PHInPlaceSite_GetWindowContext(IOleInPlaceSiteEx *iface,
1272 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, RECT *lprcPosRect,
1273 RECT *lprcClipRect, OLEINPLACEFRAMEINFO *frame_info)
1275 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1276 IOleInPlaceUIWindow *ip_window;
1277 IOleInPlaceFrame *ip_frame;
1281 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, frame_info);
1283 if(!This->doc || !This->doc->basedoc.doc_obj || !This->doc->basedoc.doc_obj->ipsite) {
1284 FIXME("No ipsite\n");
1285 return E_UNEXPECTED;
1288 hres = IOleInPlaceSite_GetWindowContext(This->doc->basedoc.doc_obj->ipsite, &ip_frame, &ip_window, &pr, &cr, frame_info);
1290 WARN("GetWindowContext failed: %08x\n", hres);
1295 IOleInPlaceUIWindow_Release(ip_window);
1297 IOleInPlaceFrame_Release(ip_frame);
1299 hres = create_ip_frame(&ip_frame);
1303 hres = create_ip_window(ppDoc);
1307 *ppFrame = ip_frame;
1308 *lprcPosRect = This->rect;
1309 *lprcClipRect = This->rect;
1313 static HRESULT WINAPI PHInPlaceSite_Scroll(IOleInPlaceSiteEx *iface, SIZE scrollExtent)
1315 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1316 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
1320 static HRESULT WINAPI PHInPlaceSite_OnUIDeactivate(IOleInPlaceSiteEx *iface, BOOL fUndoable)
1322 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1323 FIXME("(%p)->(%x)\n", This, fUndoable);
1327 static HRESULT WINAPI PHInPlaceSite_OnInPlaceDeactivate(IOleInPlaceSiteEx *iface)
1329 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1331 TRACE("(%p)\n", This);
1333 if(This->ip_object) {
1334 IOleInPlaceObject_Release(This->ip_object);
1335 This->ip_object = NULL;
1341 static HRESULT WINAPI PHInPlaceSite_DiscardUndoState(IOleInPlaceSiteEx *iface)
1343 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1344 FIXME("(%p)\n", This);
1348 static HRESULT WINAPI PHInPlaceSite_DeactivateAndUndo(IOleInPlaceSiteEx *iface)
1350 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1351 FIXME("(%p)\n", This);
1355 static HRESULT WINAPI PHInPlaceSite_OnPosRectChange(IOleInPlaceSiteEx *iface, LPCRECT lprcPosRect)
1357 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1358 FIXME("(%p)->(%p)\n", This, lprcPosRect);
1362 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceActivateEx(IOleInPlaceSiteEx *iface, BOOL *pfNoRedraw, DWORD dwFlags)
1364 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1368 TRACE("(%p)->(%p %x)\n", This, pfNoRedraw, dwFlags);
1373 hres = IUnknown_QueryInterface(This->plugin_unk, &IID_IOleInPlaceObject, (void**)&This->ip_object);
1377 hres = IOleInPlaceObject_GetWindow(This->ip_object, &hwnd);
1379 FIXME("Use hwnd %p\n", hwnd);
1381 *pfNoRedraw = FALSE;
1385 static HRESULT WINAPI PHInPlaceSiteEx_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface, BOOL fNoRedraw)
1387 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1388 FIXME("(%p)->(%x)\n", This, fNoRedraw);
1392 static HRESULT WINAPI PHInPlaceSiteEx_RequestUIActivate(IOleInPlaceSiteEx *iface)
1394 PluginHost *This = impl_from_IOleInPlaceSiteEx(iface);
1395 FIXME("(%p)\n", This);
1399 static const IOleInPlaceSiteExVtbl OleInPlaceSiteExVtbl = {
1400 PHInPlaceSite_QueryInterface,
1401 PHInPlaceSite_AddRef,
1402 PHInPlaceSite_Release,
1403 PHInPlaceSite_GetWindow,
1404 PHInPlaceSite_ContextSensitiveHelp,
1405 PHInPlaceSite_CanInPlaceActivate,
1406 PHInPlaceSite_OnInPlaceActivate,
1407 PHInPlaceSite_OnUIActivate,
1408 PHInPlaceSite_GetWindowContext,
1409 PHInPlaceSite_Scroll,
1410 PHInPlaceSite_OnUIDeactivate,
1411 PHInPlaceSite_OnInPlaceDeactivate,
1412 PHInPlaceSite_DiscardUndoState,
1413 PHInPlaceSite_DeactivateAndUndo,
1414 PHInPlaceSite_OnPosRectChange,
1415 PHInPlaceSiteEx_OnInPlaceActivateEx,
1416 PHInPlaceSiteEx_OnInPlaceDeactivateEx,
1417 PHInPlaceSiteEx_RequestUIActivate
1420 static inline PluginHost *impl_from_IOleControlSite(IOleControlSite *iface)
1422 return CONTAINING_RECORD(iface, PluginHost, IOleControlSite_iface);
1425 static HRESULT WINAPI PHControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
1427 PluginHost *This = impl_from_IOleControlSite(iface);
1428 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1431 static ULONG WINAPI PHControlSite_AddRef(IOleControlSite *iface)
1433 PluginHost *This = impl_from_IOleControlSite(iface);
1434 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1437 static ULONG WINAPI PHControlSite_Release(IOleControlSite *iface)
1439 PluginHost *This = impl_from_IOleControlSite(iface);
1440 return IOleClientSite_Release(&This->IOleClientSite_iface);
1443 static HRESULT WINAPI PHControlSite_OnControlInfoChanged(IOleControlSite *iface)
1445 PluginHost *This = impl_from_IOleControlSite(iface);
1446 FIXME("(%p)\n", This);
1450 static HRESULT WINAPI PHControlSite_LockInPlaceActive(IOleControlSite *iface, BOOL fLock)
1452 PluginHost *This = impl_from_IOleControlSite(iface);
1453 FIXME("(%p)->(%x)\n", This, fLock);
1457 static HRESULT WINAPI PHControlSite_GetExtendedControl(IOleControlSite *iface, IDispatch **ppDisp)
1459 PluginHost *This = impl_from_IOleControlSite(iface);
1460 FIXME("(%p)->(%p)\n", This, ppDisp);
1464 static HRESULT WINAPI PHControlSite_TransformCoords(IOleControlSite *iface, POINTL *pPtlHimetric, POINTF *pPtfContainer, DWORD dwFlags)
1466 PluginHost *This = impl_from_IOleControlSite(iface);
1467 FIXME("(%p)->(%p %p %x)\n", This, pPtlHimetric, pPtfContainer, dwFlags);
1471 static HRESULT WINAPI PHControlSite_TranslateAccelerator(IOleControlSite *iface, MSG *pMsg, DWORD grfModifiers)
1473 PluginHost *This = impl_from_IOleControlSite(iface);
1474 FIXME("(%p)->(%x)\n", This, grfModifiers);
1478 static HRESULT WINAPI PHControlSite_OnFocus(IOleControlSite *iface, BOOL fGotFocus)
1480 PluginHost *This = impl_from_IOleControlSite(iface);
1481 FIXME("(%p)->(%x)\n", This, fGotFocus);
1485 static HRESULT WINAPI PHControlSite_ShowPropertyFrame(IOleControlSite *iface)
1487 PluginHost *This = impl_from_IOleControlSite(iface);
1488 FIXME("(%p)\n", This);
1492 static const IOleControlSiteVtbl OleControlSiteVtbl = {
1493 PHControlSite_QueryInterface,
1494 PHControlSite_AddRef,
1495 PHControlSite_Release,
1496 PHControlSite_OnControlInfoChanged,
1497 PHControlSite_LockInPlaceActive,
1498 PHControlSite_GetExtendedControl,
1499 PHControlSite_TransformCoords,
1500 PHControlSite_TranslateAccelerator,
1501 PHControlSite_OnFocus,
1502 PHControlSite_ShowPropertyFrame
1505 static inline PluginHost *impl_from_IBindHost(IBindHost *iface)
1507 return CONTAINING_RECORD(iface, PluginHost, IBindHost_iface);
1510 static HRESULT WINAPI PHBindHost_QueryInterface(IBindHost *iface, REFIID riid, void **ppv)
1512 PluginHost *This = impl_from_IBindHost(iface);
1513 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1516 static ULONG WINAPI PHBindHost_AddRef(IBindHost *iface)
1518 PluginHost *This = impl_from_IBindHost(iface);
1519 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1522 static ULONG WINAPI PHBindHost_Release(IBindHost *iface)
1524 PluginHost *This = impl_from_IBindHost(iface);
1525 return IOleClientSite_Release(&This->IOleClientSite_iface);
1528 static HRESULT WINAPI PHBindHost_CreateMoniker(IBindHost *iface, LPOLESTR szName, IBindCtx *pBC, IMoniker **ppmk, DWORD dwReserved)
1530 PluginHost *This = impl_from_IBindHost(iface);
1532 TRACE("(%p)->(%s %p %p %x)\n", This, debugstr_w(szName), pBC, ppmk, dwReserved);
1534 if(!This->doc || !This->doc->window || !This->doc->window->mon) {
1535 FIXME("no moniker\n");
1536 return E_UNEXPECTED;
1539 return CreateURLMoniker(This->doc->window->mon, szName, ppmk);
1542 static HRESULT WINAPI PHBindHost_MonikerBindToStorage(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1543 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1545 PluginHost *This = impl_from_IBindHost(iface);
1546 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1550 static HRESULT WINAPI PHBindHost_MonikerBindToObject(IBindHost *iface, IMoniker *pMk, IBindCtx *pBC,
1551 IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
1553 PluginHost *This = impl_from_IBindHost(iface);
1554 FIXME("(%p)->(%p %p %p %s %p)\n", This, pMk, pBC, pBSC, debugstr_guid(riid), ppvObj);
1558 static const IBindHostVtbl BindHostVtbl = {
1559 PHBindHost_QueryInterface,
1562 PHBindHost_CreateMoniker,
1563 PHBindHost_MonikerBindToStorage,
1564 PHBindHost_MonikerBindToObject
1567 static inline PluginHost *impl_from_IServiceProvider(IServiceProvider *iface)
1569 return CONTAINING_RECORD(iface, PluginHost, IServiceProvider_iface);
1572 static HRESULT WINAPI PHServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1574 PluginHost *This = impl_from_IServiceProvider(iface);
1575 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1578 static ULONG WINAPI PHServiceProvider_AddRef(IServiceProvider *iface)
1580 PluginHost *This = impl_from_IServiceProvider(iface);
1581 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1584 static ULONG WINAPI PHServiceProvider_Release(IServiceProvider *iface)
1586 PluginHost *This = impl_from_IServiceProvider(iface);
1587 return IOleClientSite_Release(&This->IOleClientSite_iface);
1590 static HRESULT WINAPI PHServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
1592 PluginHost *This = impl_from_IServiceProvider(iface);
1594 if(IsEqualGUID(guidService, &SID_SBindHost)) {
1595 TRACE("SID_SBindHost service\n");
1596 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1599 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1601 if(!This->doc || !This->doc->basedoc.window) {
1603 return E_NOINTERFACE;
1606 return IServiceProvider_QueryService(&This->doc->basedoc.window->base.IServiceProvider_iface,
1607 guidService, riid, ppv);
1610 static const IServiceProviderVtbl ServiceProviderVtbl = {
1611 PHServiceProvider_QueryInterface,
1612 PHServiceProvider_AddRef,
1613 PHServiceProvider_Release,
1614 PHServiceProvider_QueryService
1617 static HRESULT assoc_element(PluginHost *host, HTMLDocumentNode *doc, nsIDOMElement *nselem)
1619 HTMLPluginContainer *container_elem;
1623 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1627 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
1628 (void**)&container_elem);
1631 ERR("Not an object element\n");
1635 container_elem->plugin_host = host;
1636 host->element = container_elem;
1640 void detach_plugin_host(PluginHost *host)
1644 TRACE("%p\n", host);
1649 if(host->ip_object) {
1651 IOleInPlaceObject_UIDeactivate(host->ip_object);
1652 IOleInPlaceObject_InPlaceDeactivate(host->ip_object);
1655 if(host->plugin_unk) {
1656 IOleObject *ole_obj;
1658 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IOleObject, (void**)&ole_obj);
1659 if(SUCCEEDED(hres)) {
1660 if(!host->ip_object)
1661 IOleObject_Close(ole_obj, OLECLOSE_NOSAVE);
1662 IOleObject_SetClientSite(ole_obj, NULL);
1663 IOleObject_Release(ole_obj);
1668 IConnectionPointContainer *cp_container;
1669 IConnectionPoint *cp;
1671 assert(host->plugin_unk != NULL);
1673 hres = IUnknown_QueryInterface(host->plugin_unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1674 if(SUCCEEDED(hres)) {
1675 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &host->sink->iid, &cp);
1676 IConnectionPointContainer_Release(cp_container);
1677 if(SUCCEEDED(hres)) {
1678 IConnectionPoint_Unadvise(cp, host->sink->cookie);
1679 IConnectionPoint_Release(cp);
1683 host->sink->host = NULL;
1684 IDispatch_Release(&host->sink->IDispatch_iface);
1689 host->element->plugin_host = NULL;
1690 host->element = NULL;
1693 list_remove(&host->entry);
1694 list_init(&host->entry);
1698 HRESULT create_plugin_host(HTMLDocumentNode *doc, nsIDOMElement *nselem, IUnknown *unk, const CLSID *clsid, PluginHost **ret)
1703 host = heap_alloc_zero(sizeof(*host));
1705 return E_OUTOFMEMORY;
1707 host->IOleClientSite_iface.lpVtbl = &OleClientSiteVtbl;
1708 host->IAdviseSinkEx_iface.lpVtbl = &AdviseSinkExVtbl;
1709 host->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1710 host->IDispatch_iface.lpVtbl = &DispatchVtbl;
1711 host->IOleInPlaceSiteEx_iface.lpVtbl = &OleInPlaceSiteExVtbl;
1712 host->IOleControlSite_iface.lpVtbl = &OleControlSiteVtbl;
1713 host->IBindHost_iface.lpVtbl = &BindHostVtbl;
1714 host->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
1718 hres = assoc_element(host, doc, nselem);
1724 IUnknown_AddRef(unk);
1725 host->plugin_unk = unk;
1726 host->clsid = *clsid;
1729 list_add_tail(&doc->plugin_hosts, &host->entry);