From bd2a05ee702a7ef8480e4f00a5fceabbc39690b8 Mon Sep 17 00:00:00 2001 From: "av%netscape.com" Date: Sat, 21 Jul 2001 02:31:29 +0000 Subject: [PATCH] Fixing 91140, the Acrobat blocker -- latering plugin stream destruction, r=peterl, bnesse, sr=vidur --- .../plugin/base/src/ns4xPluginInstance.cpp | 158 +++++++++++------- .../base/src/ns4xPluginStreamListener.h | 3 + modules/plugin/nglsrc/ns4xPluginInstance.cpp | 158 +++++++++++------- .../plugin/nglsrc/ns4xPluginStreamListener.h | 3 + 4 files changed, 202 insertions(+), 120 deletions(-) diff --git a/modules/plugin/base/src/ns4xPluginInstance.cpp b/modules/plugin/base/src/ns4xPluginInstance.cpp index 594f68e8fb99..a56d00b92aca 100644 --- a/modules/plugin/base/src/ns4xPluginInstance.cpp +++ b/modules/plugin/base/src/ns4xPluginInstance.cpp @@ -50,22 +50,94 @@ static NS_DEFINE_IID(kIPluginStreamListener2IID, NS_IPLUGINSTREAMLISTENER2_IID); ns4xPluginStreamListener::ns4xPluginStreamListener(nsIPluginInstance* inst, void* notifyData) : mNotifyData(notifyData), - mStreamInfo(nsnull) + mStreamInfo(nsnull), + mStreamStarted(PR_FALSE), + mStreamCleanedUp(PR_FALSE) { - NS_INIT_REFCNT(); - mInst = (ns4xPluginInstance*) inst; - mStreamBuffer=nsnull; - mPosition = 0; - mCurrentStreamOffset = -1; - // Initialize the 4.x interface structure - memset(&mNPStream, 0, sizeof(mNPStream)); + NS_INIT_REFCNT(); + mInst = (ns4xPluginInstance*) inst; + mStreamBuffer=nsnull; + mPosition = 0; + mCurrentStreamOffset = -1; + // Initialize the 4.x interface structure + memset(&mNPStream, 0, sizeof(mNPStream)); - NS_IF_ADDREF(mInst); + NS_IF_ADDREF(mInst); } ns4xPluginStreamListener::~ns4xPluginStreamListener(void) { - NS_IF_RELEASE(mInst); +#ifdef NS_DEBUG + printf("ns4xPluginStreamListener::~ns4xPluginStreamListener\n"); +#endif + CleanUpStream(); + NS_IF_RELEASE(mInst); +} + +nsresult ns4xPluginStreamListener::CleanUpStream() +{ + if(!mStreamStarted || mStreamCleanedUp) + return NS_OK; + + if(!mInst) + return NS_ERROR_FAILURE; + + NPP npp; + const NPPluginFuncs *callbacks = nsnull; + + mInst->GetCallbacks(&callbacks); + mInst->GetNPP(&npp); + + if(!callbacks) + return NS_ERROR_FAILURE; + + NPError error; + + if (callbacks->destroystream != NULL) + { + // XXX need to convert status to NPReason + PRLibrary* lib = nsnull; + lib = mInst->fLibrary; + +#ifdef NS_DEBUG + printf("calling NPP_DestroyStream\n"); +#endif + + NS_TRY_SAFE_CALL_RETURN(error, CallNPP_DestroyStreamProc(callbacks->destroystream, + npp, + &mNPStream, + NPRES_DONE), lib); + if(error != NPERR_NO_ERROR) + return NS_ERROR_FAILURE; + } + + // check to see if we have a call back and a + // XXX nasty hack for Shockwave Registration. + // we seem to crash doing URLNotify so just always exclude it. + // See bug 85334. + if (callbacks->urlnotify != NULL && mNotifyData != nsnull && + strcmp(mNPStream.url,"http://pinger.macromedia.com") < 0 ) + { + PRLibrary* lib = nsnull; + lib = mInst->fLibrary; + + NS_TRY_SAFE_CALL_VOID(CallNPP_URLNotifyProc(callbacks->urlnotify, + npp, + mNPStream.url, + nsPluginReason_Done, + mNotifyData), lib); + } + + // lets get rid of the buffer if we made one globally + if (mStreamBuffer) + { + PR_Free(mStreamBuffer); + mStreamBuffer=nsnull; + } + + mStreamCleanedUp = PR_TRUE; + mStreamStarted = PR_FALSE; + return NS_OK; } NS_IMPL_ISUPPORTS2(ns4xPluginStreamListener, nsIPluginStreamListener, @@ -144,6 +216,7 @@ ns4xPluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo) return NS_ERROR_OUT_OF_MEMORY; } + mStreamStarted = PR_TRUE; return NS_OK; } @@ -447,62 +520,27 @@ NS_IMETHODIMP ns4xPluginStreamListener::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status) { +#ifdef NS_DEBUG + printf("ns4xPluginStreamListener::OnStopBinding\n"); +#endif + if(!mInst || !mInst->IsStarted()) return NS_ERROR_FAILURE; - NPP npp; - const NPPluginFuncs *callbacks = nsnull; + if(pluginInfo) { + pluginInfo->GetURL(&mNPStream.url); + pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified)); + } - mInst->GetCallbacks(&callbacks); - mInst->GetNPP(&npp); - - if(!callbacks) + // check if the stream is not of asfileonly type and later its destruction + // see bug 91140 + nsresult rv = NS_OK; + if(mStreamType == nsPluginStreamType_AsFileOnly) + rv = CleanUpStream(); + + if(rv != NPERR_NO_ERROR) return NS_ERROR_FAILURE; - NPError error; - - pluginInfo->GetURL(&mNPStream.url); - pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified)); - - if (callbacks->destroystream != NULL) - { - // XXX need to convert status to NPReason - PRLibrary* lib = nsnull; - lib = mInst->fLibrary; - - NS_TRY_SAFE_CALL_RETURN(error, CallNPP_DestroyStreamProc(callbacks->destroystream, - npp, - &mNPStream, - NPRES_DONE), lib); - if(error != NPERR_NO_ERROR) - return NS_ERROR_FAILURE; - } - - // check to see if we have a call back and a - // XXX nasty hack for Shockwave Registration. - // we seem to crash doing URLNotify so just always exclude it. - // See bug 85334. - if (callbacks->urlnotify != NULL && mNotifyData != nsnull && - strcmp(mNPStream.url,"http://pinger.macromedia.com") < 0 ) - { - PRLibrary* lib = nsnull; - lib = mInst->fLibrary; - - NS_TRY_SAFE_CALL_VOID(CallNPP_URLNotifyProc(callbacks->urlnotify, - npp, - mNPStream.url, - nsPluginReason_Done, - mNotifyData), lib); - } - - - // lets get rid of the buffer if we made one globally - if (mStreamBuffer) - { - PR_Free(mStreamBuffer); - mStreamBuffer=nsnull; - } - return NS_OK; } diff --git a/modules/plugin/base/src/ns4xPluginStreamListener.h b/modules/plugin/base/src/ns4xPluginStreamListener.h index 8eb3674d1207..daf86a2e7d73 100644 --- a/modules/plugin/base/src/ns4xPluginStreamListener.h +++ b/modules/plugin/base/src/ns4xPluginStreamListener.h @@ -48,6 +48,7 @@ public: ns4xPluginStreamListener(nsIPluginInstance* inst, void* notifyData); virtual ~ns4xPluginStreamListener(); PRBool IsStarted(); + nsresult CleanUpStream(); protected: void* mNotifyData; @@ -57,6 +58,8 @@ protected: PRUint32 mPosition; PRUint32 mCurrentStreamOffset; nsPluginStreamType mStreamType; + PRBool mStreamStarted; + PRBool mStreamCleanedUp; public: nsIPluginStreamInfo * mStreamInfo; diff --git a/modules/plugin/nglsrc/ns4xPluginInstance.cpp b/modules/plugin/nglsrc/ns4xPluginInstance.cpp index 594f68e8fb99..a56d00b92aca 100644 --- a/modules/plugin/nglsrc/ns4xPluginInstance.cpp +++ b/modules/plugin/nglsrc/ns4xPluginInstance.cpp @@ -50,22 +50,94 @@ static NS_DEFINE_IID(kIPluginStreamListener2IID, NS_IPLUGINSTREAMLISTENER2_IID); ns4xPluginStreamListener::ns4xPluginStreamListener(nsIPluginInstance* inst, void* notifyData) : mNotifyData(notifyData), - mStreamInfo(nsnull) + mStreamInfo(nsnull), + mStreamStarted(PR_FALSE), + mStreamCleanedUp(PR_FALSE) { - NS_INIT_REFCNT(); - mInst = (ns4xPluginInstance*) inst; - mStreamBuffer=nsnull; - mPosition = 0; - mCurrentStreamOffset = -1; - // Initialize the 4.x interface structure - memset(&mNPStream, 0, sizeof(mNPStream)); + NS_INIT_REFCNT(); + mInst = (ns4xPluginInstance*) inst; + mStreamBuffer=nsnull; + mPosition = 0; + mCurrentStreamOffset = -1; + // Initialize the 4.x interface structure + memset(&mNPStream, 0, sizeof(mNPStream)); - NS_IF_ADDREF(mInst); + NS_IF_ADDREF(mInst); } ns4xPluginStreamListener::~ns4xPluginStreamListener(void) { - NS_IF_RELEASE(mInst); +#ifdef NS_DEBUG + printf("ns4xPluginStreamListener::~ns4xPluginStreamListener\n"); +#endif + CleanUpStream(); + NS_IF_RELEASE(mInst); +} + +nsresult ns4xPluginStreamListener::CleanUpStream() +{ + if(!mStreamStarted || mStreamCleanedUp) + return NS_OK; + + if(!mInst) + return NS_ERROR_FAILURE; + + NPP npp; + const NPPluginFuncs *callbacks = nsnull; + + mInst->GetCallbacks(&callbacks); + mInst->GetNPP(&npp); + + if(!callbacks) + return NS_ERROR_FAILURE; + + NPError error; + + if (callbacks->destroystream != NULL) + { + // XXX need to convert status to NPReason + PRLibrary* lib = nsnull; + lib = mInst->fLibrary; + +#ifdef NS_DEBUG + printf("calling NPP_DestroyStream\n"); +#endif + + NS_TRY_SAFE_CALL_RETURN(error, CallNPP_DestroyStreamProc(callbacks->destroystream, + npp, + &mNPStream, + NPRES_DONE), lib); + if(error != NPERR_NO_ERROR) + return NS_ERROR_FAILURE; + } + + // check to see if we have a call back and a + // XXX nasty hack for Shockwave Registration. + // we seem to crash doing URLNotify so just always exclude it. + // See bug 85334. + if (callbacks->urlnotify != NULL && mNotifyData != nsnull && + strcmp(mNPStream.url,"http://pinger.macromedia.com") < 0 ) + { + PRLibrary* lib = nsnull; + lib = mInst->fLibrary; + + NS_TRY_SAFE_CALL_VOID(CallNPP_URLNotifyProc(callbacks->urlnotify, + npp, + mNPStream.url, + nsPluginReason_Done, + mNotifyData), lib); + } + + // lets get rid of the buffer if we made one globally + if (mStreamBuffer) + { + PR_Free(mStreamBuffer); + mStreamBuffer=nsnull; + } + + mStreamCleanedUp = PR_TRUE; + mStreamStarted = PR_FALSE; + return NS_OK; } NS_IMPL_ISUPPORTS2(ns4xPluginStreamListener, nsIPluginStreamListener, @@ -144,6 +216,7 @@ ns4xPluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo) return NS_ERROR_OUT_OF_MEMORY; } + mStreamStarted = PR_TRUE; return NS_OK; } @@ -447,62 +520,27 @@ NS_IMETHODIMP ns4xPluginStreamListener::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status) { +#ifdef NS_DEBUG + printf("ns4xPluginStreamListener::OnStopBinding\n"); +#endif + if(!mInst || !mInst->IsStarted()) return NS_ERROR_FAILURE; - NPP npp; - const NPPluginFuncs *callbacks = nsnull; + if(pluginInfo) { + pluginInfo->GetURL(&mNPStream.url); + pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified)); + } - mInst->GetCallbacks(&callbacks); - mInst->GetNPP(&npp); - - if(!callbacks) + // check if the stream is not of asfileonly type and later its destruction + // see bug 91140 + nsresult rv = NS_OK; + if(mStreamType == nsPluginStreamType_AsFileOnly) + rv = CleanUpStream(); + + if(rv != NPERR_NO_ERROR) return NS_ERROR_FAILURE; - NPError error; - - pluginInfo->GetURL(&mNPStream.url); - pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified)); - - if (callbacks->destroystream != NULL) - { - // XXX need to convert status to NPReason - PRLibrary* lib = nsnull; - lib = mInst->fLibrary; - - NS_TRY_SAFE_CALL_RETURN(error, CallNPP_DestroyStreamProc(callbacks->destroystream, - npp, - &mNPStream, - NPRES_DONE), lib); - if(error != NPERR_NO_ERROR) - return NS_ERROR_FAILURE; - } - - // check to see if we have a call back and a - // XXX nasty hack for Shockwave Registration. - // we seem to crash doing URLNotify so just always exclude it. - // See bug 85334. - if (callbacks->urlnotify != NULL && mNotifyData != nsnull && - strcmp(mNPStream.url,"http://pinger.macromedia.com") < 0 ) - { - PRLibrary* lib = nsnull; - lib = mInst->fLibrary; - - NS_TRY_SAFE_CALL_VOID(CallNPP_URLNotifyProc(callbacks->urlnotify, - npp, - mNPStream.url, - nsPluginReason_Done, - mNotifyData), lib); - } - - - // lets get rid of the buffer if we made one globally - if (mStreamBuffer) - { - PR_Free(mStreamBuffer); - mStreamBuffer=nsnull; - } - return NS_OK; } diff --git a/modules/plugin/nglsrc/ns4xPluginStreamListener.h b/modules/plugin/nglsrc/ns4xPluginStreamListener.h index 8eb3674d1207..daf86a2e7d73 100644 --- a/modules/plugin/nglsrc/ns4xPluginStreamListener.h +++ b/modules/plugin/nglsrc/ns4xPluginStreamListener.h @@ -48,6 +48,7 @@ public: ns4xPluginStreamListener(nsIPluginInstance* inst, void* notifyData); virtual ~ns4xPluginStreamListener(); PRBool IsStarted(); + nsresult CleanUpStream(); protected: void* mNotifyData; @@ -57,6 +58,8 @@ protected: PRUint32 mPosition; PRUint32 mCurrentStreamOffset; nsPluginStreamType mStreamType; + PRBool mStreamStarted; + PRBool mStreamCleanedUp; public: nsIPluginStreamInfo * mStreamInfo;