diff --git a/dlls/mshtml/htmlobject.c b/dlls/mshtml/htmlobject.c
index a2f5322f373..c911dd8ae41 100644
--- a/dlls/mshtml/htmlobject.c
+++ b/dlls/mshtml/htmlobject.c
@@ -422,6 +422,8 @@ static void HTMLObjectElement_destructor(HTMLDOMNode *iface)
{
HTMLObjectElement *This = HTMLOBJECT_NODE_THIS(iface);
+ if(This->plugin_container.plugin_host)
+ This->plugin_container.plugin_host->element = NULL;
if(This->nsobject)
nsIDOMHTMLObjectElement_Release(This->nsobject);
diff --git a/dlls/mshtml/npplugin.c b/dlls/mshtml/npplugin.c
index a1c1c47b73c..93e22da93a6 100644
--- a/dlls/mshtml/npplugin.c
+++ b/dlls/mshtml/npplugin.c
@@ -272,7 +272,7 @@ static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, I
PluginHost *host;
HRESULT hres;
- hres = create_plugin_host(window->doc, obj, &host);
+ hres = create_plugin_host(window->doc, nselem, obj, &host);
nsIDOMElement_Release(nselem);
IUnknown_Release(obj);
if(SUCCEEDED(hres))
diff --git a/dlls/mshtml/pluginhost.c b/dlls/mshtml/pluginhost.c
index 2af929c96a2..785abdd0c63 100644
--- a/dlls/mshtml/pluginhost.c
+++ b/dlls/mshtml/pluginhost.c
@@ -164,6 +164,8 @@ static ULONG WINAPI PHClientSite_Release(IOleClientSite *iface)
if(!ref) {
list_remove(&This->entry);
+ if(This->element)
+ This->element->plugin_host = NULL;
if(This->plugin_unk)
IUnknown_Release(This->plugin_unk);
heap_free(This);
@@ -735,6 +737,27 @@ static const IServiceProviderVtbl ServiceProviderVtbl = {
PHServiceProvider_QueryService
};
+static HRESULT assoc_element(PluginHost *host, HTMLDocumentNode *doc, nsIDOMElement *nselem)
+{
+ HTMLPluginContainer *container_elem;
+ HTMLDOMNode *node;
+ HRESULT hres;
+
+ hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
+ if(FAILED(hres))
+ return hres;
+
+ hres = IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_HTMLPluginContainer, (void**)&container_elem);
+ if(FAILED(hres)) {
+ ERR("Not an object element\n");
+ return hres;
+ }
+
+ container_elem->plugin_host = host;
+ host->element = container_elem;
+ return S_OK;
+}
+
void detach_plugin_hosts(HTMLDocumentNode *doc)
{
PluginHost *iter;
@@ -746,9 +769,10 @@ void detach_plugin_hosts(HTMLDocumentNode *doc)
}
}
-HRESULT create_plugin_host(HTMLDocumentNode *doc, IUnknown *unk, PluginHost **ret)
+HRESULT create_plugin_host(HTMLDocumentNode *doc, nsIDOMElement *nselem, IUnknown *unk, PluginHost **ret)
{
PluginHost *host;
+ HRESULT hres;
host = heap_alloc_zero(sizeof(*host));
if(!host)
@@ -765,6 +789,12 @@ HRESULT create_plugin_host(HTMLDocumentNode *doc, IUnknown *unk, PluginHost **re
host->ref = 1;
+ hres = assoc_element(host, doc, nselem);
+ if(FAILED(hres)) {
+ heap_free(host);
+ return hres;
+ }
+
IUnknown_AddRef(unk);
host->plugin_unk = unk;
diff --git a/dlls/mshtml/pluginhost.h b/dlls/mshtml/pluginhost.h
index 1c80a9ce12b..d030a3ee9e1 100644
--- a/dlls/mshtml/pluginhost.h
+++ b/dlls/mshtml/pluginhost.h
@@ -35,6 +35,8 @@ typedef struct {
HTMLDocumentNode *doc;
struct list entry;
+
+ HTMLPluginContainer *element;
} PluginHost;
struct HTMLPluginContainer {
@@ -45,6 +47,6 @@ struct HTMLPluginContainer {
extern const IID IID_HTMLPluginContainer;
-HRESULT create_plugin_host(HTMLDocumentNode*,IUnknown*,PluginHost**);
+HRESULT create_plugin_host(HTMLDocumentNode*,nsIDOMElement*,IUnknown*,PluginHost**);
void update_plugin_window(PluginHost*,HWND,const RECT*);
void detach_plugin_hosts(HTMLDocumentNode*);