diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp
index 72281f24eca..ce9b43d5679 100644
--- a/mozilla/layout/html/base/src/nsObjectFrame.cpp
+++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp
@@ -510,6 +510,11 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext)
inst->SetWindow(nsnull);
inst->Stop();
}
+
+ nsCOMPtr pluginHost = do_GetService(kCPluginManagerCID);
+ if(pluginHost)
+ pluginHost->StopPluginInstance(inst);
+
NS_RELEASE(inst);
}
}
@@ -1618,13 +1623,7 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner()
CancelTimer();
}
- if (nsnull != mInstance)
- {
- if (mPluginHost)
- mPluginHost->StopPluginInstance(mInstance);
- NS_IF_RELEASE(mInstance);
- }
-
+ NS_IF_RELEASE(mInstance);
NS_IF_RELEASE(mPluginHost);
mOwner = nsnull;
diff --git a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp
index 96123c6d1ae..b018d84cbd4 100644
--- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp
+++ b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp
@@ -55,7 +55,7 @@ nsPluginInstancePeerImpl::nsPluginInstancePeerImpl()
nsPluginInstancePeerImpl::~nsPluginInstancePeerImpl()
{
mInstance = nsnull;
- mOwner = nsnull;
+ NS_IF_RELEASE(mOwner);
if (nsnull != mMIMEType)
{
@@ -895,11 +895,10 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext)
nsresult nsPluginInstancePeerImpl::Initialize(nsIPluginInstanceOwner *aOwner,
const nsMIMEType aMIMEType)
{
- //don't add a ref to prevent circular references... MMP
mOwner = aOwner;
+ NS_IF_ADDREF(mOwner);
aOwner->GetInstance(mInstance);
- //release this one too... MMP
NS_IF_RELEASE(mInstance);
if (nsnull != aMIMEType)
@@ -918,8 +917,12 @@ nsresult nsPluginInstancePeerImpl::Initialize(nsIPluginInstanceOwner *aOwner,
nsresult nsPluginInstancePeerImpl::SetOwner(nsIPluginInstanceOwner *aOwner)
{
- // do not add refs to these objects to prevent circular references
+ // get rid of the previous owner
+ NS_IF_RELEASE(mOwner);
+
mOwner = aOwner;
+ NS_IF_ADDREF(mOwner);
+
aOwner->GetInstance(mInstance);
NS_IF_RELEASE(mInstance);
return NS_OK;
diff --git a/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp
index 4d499300bcb..c733869c7b9 100644
--- a/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp
+++ b/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp
@@ -274,6 +274,19 @@ PluginViewerImpl::~PluginViewerImpl()
if (mOwner) mOwner->CancelTimer();
#endif
+ if(mOwner) {
+ nsIPluginInstance * inst;
+ mOwner->GetInstance(inst);
+
+ if(inst) {
+ nsCOMPtr host = do_GetService(kCPluginManagerCID);
+ if(host)
+ host->StopPluginInstance(inst);
+
+ NS_RELEASE(inst);
+ }
+ }
+
NS_IF_RELEASE(mOwner);
if (nsnull != mWindow) {
mWindow->Destroy();
@@ -925,26 +938,7 @@ pluginInstanceOwner :: ~pluginInstanceOwner()
CancelTimer();
}
- if (nsnull != mInstance)
- {
- PRBool doCache = PR_TRUE;
-
- // determine if the plugin wants to be cached
- mInstance->GetValue(nsPluginInstanceVariable_DoCacheBool,
- (void *) &doCache);
- mInstance->Stop();
- if (!doCache) {
- // if not, destroy the instance
- mInstance->Destroy();
- }
- else {
- nsCOMPtr host;
- host = do_GetService(kCPluginManagerCID);
- if(host)
- host->StopPluginInstance(mInstance);
- }
- NS_IF_RELEASE(mInstance);
- }
+ NS_IF_RELEASE(mInstance);
mWindow = nsnull;
mViewer = nsnull;