From 412eeea36ea3e81e85cd96dd5980047192ccf1a8 Mon Sep 17 00:00:00 2001 From: "amusil%netscape.com" Date: Thu, 4 Feb 1999 23:37:20 +0000 Subject: [PATCH] Fixed bugs with the stream as file implementation. git-svn-id: svn://10.0.0.236/trunk@19763 18797224-902f-48f8-a5cc-f745e15eee43 --- .../plugin/base/src/nsPluginHostImpl.cpp | 58 ++++++++++++++----- .../plugin/base/src/nsPluginHostImpl.h | 2 + .../plugin/nglsrc/nsPluginHostImpl.cpp | 58 ++++++++++++++----- .../modules/plugin/nglsrc/nsPluginHostImpl.h | 2 + 4 files changed, 92 insertions(+), 28 deletions(-) diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index fa68d7b3716..deeee5c9f02 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -369,6 +369,7 @@ private: #ifdef NEW_PLUGIN_STREAM_API nsIPluginStreamListener *mPStreamListener; nsPluginStreamInfo *mPluginStreamInfo; + PRBool mSetUpListener; #else nsPluginStreamPeer *mPeer; nsIPluginStream *mStream; @@ -384,7 +385,7 @@ private: PRUint32 mBufSize; nsIPluginHost *mHost; PRBool mGotProgress; - PRBool mOnStartBinding; + PRBool mOnStartBinding; #ifdef USE_CACHE nsCacheObject* mCachedFile; @@ -404,6 +405,7 @@ nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer() #ifdef NEW_PLUGIN_STREAM_API mPStreamListener = nsnull; mPluginStreamInfo = nsnull; + mSetUpListener = PR_FALSE; #else mPeer = nsnull; mStream = nsnull; @@ -677,7 +679,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStartBinding(nsIURL* aURL, const c #ifdef NEW_PLUGIN_STREAM_API // only set up the stream listener if we have both the mimetype and // have mLength set (as indicated by the mGotProgress bool) - if(mGotProgress == PR_TRUE) + if(mGotProgress == PR_TRUE && mSetUpListener == PR_FALSE) rv = SetUpStreamListener(aURL); #else if ((PR_TRUE == mGotProgress) && (nsnull == mPeer) && (nsnull != mInstance)) @@ -697,7 +699,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnProgress(nsIURL* aURL, PRUint32 aP mPluginStreamInfo->SetLength(aProgressMax); // if OnStartBinding already got called, - if(mOnStartBinding == PR_TRUE) + if(mOnStartBinding == PR_TRUE && mSetUpListener == PR_FALSE) rv = SetUpStreamListener(aURL); #else @@ -825,8 +827,8 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult #ifdef NEW_PLUGIN_STREAM_API const char* urlString; aURL->GetSpec(&urlString); - if (mPStreamListener) - mPStreamListener->OnFileAvailable(urlString, pathAndFilename); + if (mPStreamListener) + mPStreamListener->OnFileAvailable(urlString, pathAndFilename); #else mStream->AsFile(pathAndFilename); #endif // NEW_PLUGIN_STREAM_API @@ -856,8 +858,8 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult #ifdef NEW_PLUGIN_STREAM_API const char* urlString; aURL->GetSpec(&urlString); - if (mPStreamListener) - mPStreamListener->OnFileAvailable(urlString, buf); + if (mPStreamListener) + mPStreamListener->OnFileAvailable(urlString, buf); #else mStream->AsFile(buf); #endif // NEW_PLUGIN_STREAM_API @@ -868,11 +870,11 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult #ifdef NEW_PLUGIN_STREAM_API const char* url; aURL->GetSpec(&url); - if (mPStreamListener) - { + if (mPStreamListener) + { mPStreamListener->OnStopBinding(url, aStatus, (nsIPluginStreamInfo*)mPluginStreamInfo); mPStreamListener->OnNotify(url, aStatus); - } + } #else nsIPluginInstance *instance = nsnull; @@ -965,7 +967,7 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL) nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL) { - nsresult rv; + nsresult rv = NS_OK; // If we don't yet have a stream listener, we need to get one from the plugin. // NOTE: this should only happen when a stream was NOT created with GetURL or @@ -979,6 +981,8 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL) if(mPStreamListener == nsnull) return NS_ERROR_NULL_POINTER; + + mSetUpListener = PR_TRUE; mPStreamListener->GetStreamType(&mStreamType); if ((mStreamType == nsPluginStreamType_AsFile) || @@ -1739,7 +1743,7 @@ NS_IMETHODIMP nsPluginHostImpl :: SetUpPluginInstance(const char *aMimeType, PL_strcat(path, plugins->mName); // load the plugin - plugins->mLibrary = PR_LoadLibrary(path); + plugins->mLibrary = LoadPluginLibrary(mPluginPath, path); } if (nsnull != plugins->mLibrary) @@ -1792,7 +1796,7 @@ NS_IMETHODIMP nsPluginHostImpl :: SetUpPluginInstance(const char *aMimeType, } } else - return NS_ERROR_UNEXPECTED; // PR_LoadLibrary failure + return NS_ERROR_UNEXPECTED; // LoadPluginLibrary failure return NS_OK; } @@ -1904,7 +1908,7 @@ NS_IMETHODIMP nsPluginHostImpl :: LoadPlugins(void) PL_strcpy(path, mPluginPath); PL_strcat(path, dent->name); - plugin = PR_LoadLibrary(path); + plugin = LoadPluginLibrary(mPluginPath, path); if (NULL != plugin) { @@ -2168,7 +2172,33 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS // private methods +PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path) +{ +#ifdef XP_PC + BOOL restoreOrigDir = FALSE; + char aOrigDir[MAX_PATH + 1]; + DWORD dwCheck = ::GetCurrentDirectory(sizeof(aOrigDir), aOrigDir); + PR_ASSERT(dwCheck <= MAX_PATH + 1); + if (dwCheck <= MAX_PATH + 1) + { + restoreOrigDir = ::SetCurrentDirectory(pluginPath); + PR_ASSERT(restoreOrigDir); + } + + PRLibrary* plugin = PR_LoadLibrary(path); + + if (restoreOrigDir) + { + BOOL bCheck = ::SetCurrentDirectory(aOrigDir); + PR_ASSERT(bCheck); + } + + return plugin; +#else + return NULL; +#endif +} /* Called by GetURL and PostURL */ diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index cadb827594f..8566ed09ed3 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -211,6 +211,8 @@ private: nsresult NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance); + PRLibrary* LoadPluginLibrary(const char* pluginPath, const char* path); + char *mPluginPath; nsPluginTag *mPlugins; nsIMalloc *mMalloc; diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index fa68d7b3716..deeee5c9f02 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -369,6 +369,7 @@ private: #ifdef NEW_PLUGIN_STREAM_API nsIPluginStreamListener *mPStreamListener; nsPluginStreamInfo *mPluginStreamInfo; + PRBool mSetUpListener; #else nsPluginStreamPeer *mPeer; nsIPluginStream *mStream; @@ -384,7 +385,7 @@ private: PRUint32 mBufSize; nsIPluginHost *mHost; PRBool mGotProgress; - PRBool mOnStartBinding; + PRBool mOnStartBinding; #ifdef USE_CACHE nsCacheObject* mCachedFile; @@ -404,6 +405,7 @@ nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer() #ifdef NEW_PLUGIN_STREAM_API mPStreamListener = nsnull; mPluginStreamInfo = nsnull; + mSetUpListener = PR_FALSE; #else mPeer = nsnull; mStream = nsnull; @@ -677,7 +679,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStartBinding(nsIURL* aURL, const c #ifdef NEW_PLUGIN_STREAM_API // only set up the stream listener if we have both the mimetype and // have mLength set (as indicated by the mGotProgress bool) - if(mGotProgress == PR_TRUE) + if(mGotProgress == PR_TRUE && mSetUpListener == PR_FALSE) rv = SetUpStreamListener(aURL); #else if ((PR_TRUE == mGotProgress) && (nsnull == mPeer) && (nsnull != mInstance)) @@ -697,7 +699,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnProgress(nsIURL* aURL, PRUint32 aP mPluginStreamInfo->SetLength(aProgressMax); // if OnStartBinding already got called, - if(mOnStartBinding == PR_TRUE) + if(mOnStartBinding == PR_TRUE && mSetUpListener == PR_FALSE) rv = SetUpStreamListener(aURL); #else @@ -825,8 +827,8 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult #ifdef NEW_PLUGIN_STREAM_API const char* urlString; aURL->GetSpec(&urlString); - if (mPStreamListener) - mPStreamListener->OnFileAvailable(urlString, pathAndFilename); + if (mPStreamListener) + mPStreamListener->OnFileAvailable(urlString, pathAndFilename); #else mStream->AsFile(pathAndFilename); #endif // NEW_PLUGIN_STREAM_API @@ -856,8 +858,8 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult #ifdef NEW_PLUGIN_STREAM_API const char* urlString; aURL->GetSpec(&urlString); - if (mPStreamListener) - mPStreamListener->OnFileAvailable(urlString, buf); + if (mPStreamListener) + mPStreamListener->OnFileAvailable(urlString, buf); #else mStream->AsFile(buf); #endif // NEW_PLUGIN_STREAM_API @@ -868,11 +870,11 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult #ifdef NEW_PLUGIN_STREAM_API const char* url; aURL->GetSpec(&url); - if (mPStreamListener) - { + if (mPStreamListener) + { mPStreamListener->OnStopBinding(url, aStatus, (nsIPluginStreamInfo*)mPluginStreamInfo); mPStreamListener->OnNotify(url, aStatus); - } + } #else nsIPluginInstance *instance = nsnull; @@ -965,7 +967,7 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL) nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL) { - nsresult rv; + nsresult rv = NS_OK; // If we don't yet have a stream listener, we need to get one from the plugin. // NOTE: this should only happen when a stream was NOT created with GetURL or @@ -979,6 +981,8 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL) if(mPStreamListener == nsnull) return NS_ERROR_NULL_POINTER; + + mSetUpListener = PR_TRUE; mPStreamListener->GetStreamType(&mStreamType); if ((mStreamType == nsPluginStreamType_AsFile) || @@ -1739,7 +1743,7 @@ NS_IMETHODIMP nsPluginHostImpl :: SetUpPluginInstance(const char *aMimeType, PL_strcat(path, plugins->mName); // load the plugin - plugins->mLibrary = PR_LoadLibrary(path); + plugins->mLibrary = LoadPluginLibrary(mPluginPath, path); } if (nsnull != plugins->mLibrary) @@ -1792,7 +1796,7 @@ NS_IMETHODIMP nsPluginHostImpl :: SetUpPluginInstance(const char *aMimeType, } } else - return NS_ERROR_UNEXPECTED; // PR_LoadLibrary failure + return NS_ERROR_UNEXPECTED; // LoadPluginLibrary failure return NS_OK; } @@ -1904,7 +1908,7 @@ NS_IMETHODIMP nsPluginHostImpl :: LoadPlugins(void) PL_strcpy(path, mPluginPath); PL_strcat(path, dent->name); - plugin = PR_LoadLibrary(path); + plugin = LoadPluginLibrary(mPluginPath, path); if (NULL != plugin) { @@ -2168,7 +2172,33 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS // private methods +PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path) +{ +#ifdef XP_PC + BOOL restoreOrigDir = FALSE; + char aOrigDir[MAX_PATH + 1]; + DWORD dwCheck = ::GetCurrentDirectory(sizeof(aOrigDir), aOrigDir); + PR_ASSERT(dwCheck <= MAX_PATH + 1); + if (dwCheck <= MAX_PATH + 1) + { + restoreOrigDir = ::SetCurrentDirectory(pluginPath); + PR_ASSERT(restoreOrigDir); + } + + PRLibrary* plugin = PR_LoadLibrary(path); + + if (restoreOrigDir) + { + BOOL bCheck = ::SetCurrentDirectory(aOrigDir); + PR_ASSERT(bCheck); + } + + return plugin; +#else + return NULL; +#endif +} /* Called by GetURL and PostURL */ diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h index cadb827594f..8566ed09ed3 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h @@ -211,6 +211,8 @@ private: nsresult NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance); + PRLibrary* LoadPluginLibrary(const char* pluginPath, const char* path); + char *mPluginPath; nsPluginTag *mPlugins; nsIMalloc *mMalloc;