From 6301651fb78b912340b8e0c6f635e848587fba4c Mon Sep 17 00:00:00 2001 From: "amusil%netscape.com" Date: Tue, 23 Mar 1999 03:18:12 +0000 Subject: [PATCH] Made destructors virtual, added APIs to nsIPluginHost for determining if a plugin is available for a particular mimetype or file extension. --- modules/plugin/base/src/ns4xPlugin.h | 2 +- modules/plugin/base/src/ns4xPluginInstance.h | 2 +- modules/plugin/base/src/nsIPluginHost.h | 6 + modules/plugin/base/src/nsPluginHostImpl.cpp | 251 +++++++----------- modules/plugin/base/src/nsPluginHostImpl.h | 8 +- .../plugin/base/src/nsPluginInstancePeer.cpp | 2 +- .../plugin/base/src/nsPluginInstancePeer.h | 2 +- modules/plugin/nglsrc/ns4xPlugin.h | 2 +- modules/plugin/nglsrc/ns4xPluginInstance.h | 2 +- modules/plugin/nglsrc/nsIPluginHost.h | 6 + modules/plugin/nglsrc/nsPluginHostImpl.cpp | 251 +++++++----------- modules/plugin/nglsrc/nsPluginHostImpl.h | 8 +- .../plugin/nglsrc/nsPluginInstancePeer.cpp | 2 +- modules/plugin/nglsrc/nsPluginInstancePeer.h | 2 +- 14 files changed, 222 insertions(+), 324 deletions(-) diff --git a/modules/plugin/base/src/ns4xPlugin.h b/modules/plugin/base/src/ns4xPlugin.h index 5e38f7c3e1f3..f7dea6da853d 100644 --- a/modules/plugin/base/src/ns4xPlugin.h +++ b/modules/plugin/base/src/ns4xPlugin.h @@ -56,7 +56,7 @@ class ns4xPlugin : public nsIPlugin public: ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr); - ~ns4xPlugin(void); + virtual ~ns4xPlugin(void); NS_DECL_ISUPPORTS diff --git a/modules/plugin/base/src/ns4xPluginInstance.h b/modules/plugin/base/src/ns4xPluginInstance.h index be9334d4df38..d0c46183b288 100644 --- a/modules/plugin/base/src/ns4xPluginInstance.h +++ b/modules/plugin/base/src/ns4xPluginInstance.h @@ -104,7 +104,7 @@ public: ns4xPluginInstance(NPPluginFuncs* callbacks); // Use Release() to destroy this - ~ns4xPluginInstance(void); + virtual ~ns4xPluginInstance(void); protected: diff --git a/modules/plugin/base/src/nsIPluginHost.h b/modules/plugin/base/src/nsIPluginHost.h index 0fa39f791cc7..5466b65f2554 100644 --- a/modules/plugin/base/src/nsIPluginHost.h +++ b/modules/plugin/base/src/nsIPluginHost.h @@ -59,6 +59,12 @@ public: NS_IMETHOD SetUpPluginInstance(const char *aMimeType, nsIURL *aURL, nsIPluginInstanceOwner *aOwner) = 0; + NS_IMETHOD + IsPluginAvailableForType(const char* aMimeType) = 0; + + NS_IMETHOD + IsPluginAvailableForExtension(const char* aExtension, const char* &aMimeType) = 0; + }; #endif // nsIPluginHost_h___ diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index b221e987eb3b..70029242e1cb 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -153,7 +153,7 @@ class nsPluginStreamInfo : public nsIPluginStreamInfo public: nsPluginStreamInfo(); - ~nsPluginStreamInfo(); + virtual ~nsPluginStreamInfo(); NS_DECL_ISUPPORTS @@ -337,7 +337,7 @@ class nsPluginStreamListenerPeer : public nsIStreamListener { public: nsPluginStreamListenerPeer(); - ~nsPluginStreamListenerPeer(); + virtual ~nsPluginStreamListenerPeer(); NS_DECL_ISUPPORTS @@ -408,7 +408,7 @@ class nsPluginCacheListener : public nsIStreamListener { public: nsPluginCacheListener(nsPluginStreamListenerPeer* aListener); - ~nsPluginCacheListener(); + virtual ~nsPluginCacheListener(); NS_DECL_ISUPPORTS @@ -646,13 +646,6 @@ nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer() mOnStopBinding = PR_FALSE; mCacheDone = PR_FALSE; mStatus = NS_OK; - -#ifdef USE_CACHE - mCachedFile = nsnull; -#else - mStreamFile = nsnull; - mFileName = nsnull; -#endif } nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer() @@ -671,24 +664,6 @@ nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer() NS_IF_RELEASE(mInstance); NS_IF_RELEASE(mPStreamListener); NS_IF_RELEASE(mHost); - -#ifdef USE_CACHE - if (nsnull != mCachedFile) - { - delete mCachedFile; - mCachedFile = nsnull; - } -#else // USE_CACHE - if(nsnull != mStreamFile) - { - fclose(mStreamFile); - mStreamFile = nsnull; - } - - if(nsnull != mFileName) - PL_strfree(mFileName); - -#endif // USE_CACHE } NS_IMPL_ADDREF(nsPluginStreamListenerPeer); @@ -882,8 +857,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnDataAvailable(nsIURL* aURL, nsIInp { nsresult rv = NS_OK; const char* url; - char* buffer; - PRUint32 readlen; if(!mPStreamListener) return NS_ERROR_FAILURE; @@ -892,25 +865,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnDataAvailable(nsIURL* aURL, nsIInp aURL->GetSpec(&urlString); mPluginStreamInfo->SetURL(urlString); -#if 0 - // determine if we need to write the data to the cache - if((mStreamType == nsPluginStreamType_AsFile) || (mStreamType == nsPluginStreamType_AsFileOnly)) - { - buffer = (char*) PR_Malloc(aLength); - if(buffer) - aIStream->Read(buffer, aLength, &readlen); - -#ifdef USE_CACHE - if(nsnull != mCachedFile) - mCachedFile->Write((char*)buffer, aLength); -#else - if(nsnull != mStreamFile) - fwrite(buffer, sizeof(char), aLength, mStreamFile); -#endif // USE_CACHE - PR_Free(buffer); - } -#endif - // if the plugin has requested an AsFileOnly stream, then don't call OnDataAvailable if(mStreamType != nsPluginStreamType_AsFileOnly) { @@ -935,44 +889,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult aURL->GetSpec(&urlString); mPluginStreamInfo->SetURL(urlString); -#if 0 - // see if we need to close out the cache - if ((mStreamType == nsPluginStreamType_AsFile) || - (mStreamType == nsPluginStreamType_AsFileOnly)) - { -#ifdef USE_CACHE - if (nsnull != mCachedFile) - { - PRInt32 len; - nsCachePref* cachePref = nsCachePref::GetInstance(); - - const char* cachePath = cachePref->DiskCacheFolder(); - const char* filename = mCachedFile->Filename(); - - // we need to pass the whole path and filename to the plugin - len = PL_strlen(cachePath) + PL_strlen(filename) + 1; - char* pathAndFilename = (char*)PR_Malloc(len * sizeof(char)); - pathAndFilename = PL_strcpy(pathAndFilename, cachePath); - pathAndFilename = PL_strcat(pathAndFilename, filename); - - const char* urlString; - aURL->GetSpec(&urlString); - if (mPStreamListener) - mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, pathAndFilename); - } -#else // USE_CACHE - if(nsnull != mStreamFile) - { - fclose(mStreamFile); - mStreamFile = nsnull; - - if (mPStreamListener) - mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, mFileName); - } -#endif // USE_CACHE - } -#endif - // tell the plugin that the stream has ended only if the cache is done if(mCacheDone) mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus); @@ -988,68 +904,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL) { -#if 0 -#ifdef USE_CACHE - nsString urlString; - char* cString; - char* fileName; - - aURL->ToString(urlString); - cString = urlString.ToNewCString(); - mCachedFile = new nsCacheObject(cString); - delete [] cString; - - if(mCachedFile == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - // use the actual filename of the net-based file as the cache filename - aURL->GetFile(fileName); - mCachedFile->Filename(fileName); - - nsCacheManager* cacheManager = nsCacheManager::GetInstance(); - nsDiskModule* diskCache = cacheManager->GetDiskModule(); - diskCache->AddObject(mCachedFile); -#else // USE_CACHE - - char buf[400], tpath[300]; -#ifdef XP_PC - ::GetTempPath(sizeof(tpath), tpath); - PRInt32 len = PL_strlen(tpath); - - if((len > 0) && (tpath[len-1] != '\\')) - { - tpath[len] = '\\'; - tpath[len+1] = 0; - } -#elif defined (XP_UNIX) - PL_strcpy(tpath, "/tmp/"); -#else - tpath[0] = 0; -#endif // XP_PC - const char* pathName; - char* fileName; - aURL->GetFile(&pathName); - - // since GetFile actually returns us the full path, move to the last \ and skip it - fileName = PL_strrchr(pathName, '/'); - if(fileName) - ++fileName; - - // if we don't get a filename for some reason, just make one up using the address of this - // object to ensure uniqueness of the filename per stream - if(!fileName) - PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this); - else - PR_snprintf(buf, sizeof(buf), "%s%s", tpath, fileName); - - mStreamFile = fopen(buf, "wb"); - //setbuf(mStreamFile, NULL); - - mFileName = PL_strdup(buf); -#endif // USE_CACHE - return NS_OK; -#endif - nsPluginCacheListener* cacheListener = new nsPluginCacheListener(this); return NS_OpenURL(aURL, cacheListener); } @@ -1095,12 +949,17 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL) nsresult nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename) { - nsresult rv = NS_ERROR_FAILURE; - if (mPStreamListener) - rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename); + nsresult rv; + if (!mPStreamListener) + return NS_ERROR_FAILURE; + + if((rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename)) != NS_OK) + return rv; + // if OnStopBinding has already been called, we need to make sure the plugin gets notified + // we do this here because OnStopBinding must always be called after OnFileAvailable if(mOnStopBinding) - mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, mStatus); + rv = mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, mStatus); mCacheDone = PR_TRUE; return rv; @@ -1458,6 +1317,11 @@ NS_IMETHODIMP nsPluginHostImpl :: InstantiateEmbededPlugin(const char *aMimeType if(rv == NS_OK) rv = aOwner->GetInstance(instance); + // if we have a failure error, it means we found a plugin for the mimetype, + // but we had a problem with the entry point + if(rv == NS_ERROR_FAILURE) + return rv; + if(rv != NS_OK) { // we have not been able to load a plugin because we have not determined the mimetype @@ -1740,6 +1604,8 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, NS_RELEASE(instance); } } + else + return NS_ERROR_FAILURE; } else return NS_ERROR_UNEXPECTED; // LoadPluginLibrary failure @@ -1759,6 +1625,77 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, #endif /* !XP_MAC */ +NS_IMETHODIMP +nsPluginHostImpl::IsPluginAvailableForType(const char* aMimeType) +{ + nsPluginTag *plugins = nsnull; + PRInt32 variants, cnt; + + if (PR_FALSE == mPluginsLoaded) + LoadPlugins(); + + // if we have a mimetype passed in, search the mPlugins linked list for a match + if (nsnull != aMimeType) + { + plugins = mPlugins; + + while (nsnull != plugins) + { + variants = plugins->mVariants; + + for (cnt = 0; cnt < variants; cnt++) + { + if (0 == strcmp(plugins->mMimeTypeArray[cnt], aMimeType)) + return NS_OK; + } + + if (cnt < variants) + break; + + plugins = plugins->mNext; + } + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsPluginHostImpl::IsPluginAvailableForExtension(const char* aExtension, const char* &aMimeType) +{ + nsPluginTag *plugins = nsnull; + PRInt32 variants, cnt; + + if (PR_FALSE == mPluginsLoaded) + LoadPlugins(); + + // if we have a mimetype passed in, search the mPlugins linked list for a match + if (nsnull != aExtension) + { + plugins = mPlugins; + + while (nsnull != plugins) + { + variants = plugins->mVariants; + + for (cnt = 0; cnt < variants; cnt++) + { + if (0 == strcmp(plugins->mExtensionsArray[cnt], aExtension)) + { + aMimeType = plugins->mMimeTypeArray[cnt]; + return NS_OK; + } + } + + if (cnt < variants) + break; + + plugins = plugins->mNext; + } + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) { nsresult res = NS_ERROR_FAILURE; @@ -2236,7 +2173,7 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const nsFileSpec &pluginSpec) PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path) { #ifdef XP_PC - /*BOOL restoreOrigDir = FALSE; + BOOL restoreOrigDir = FALSE; char aOrigDir[MAX_PATH + 1]; DWORD dwCheck = ::GetCurrentDirectory(sizeof(aOrigDir), aOrigDir); PR_ASSERT(dwCheck <= MAX_PATH + 1); @@ -2245,15 +2182,15 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha { restoreOrigDir = ::SetCurrentDirectory(pluginPath); PR_ASSERT(restoreOrigDir); - }*/ + } PRLibrary* plugin = PR_LoadLibrary(path); - /*if (restoreOrigDir) + if (restoreOrigDir) { BOOL bCheck = ::SetCurrentDirectory(aOrigDir); PR_ASSERT(bCheck); - }*/ + } return plugin; #else diff --git a/modules/plugin/base/src/nsPluginHostImpl.h b/modules/plugin/base/src/nsPluginHostImpl.h index 385cdf4af04e..d6c2029f462e 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.h +++ b/modules/plugin/base/src/nsPluginHostImpl.h @@ -63,7 +63,7 @@ class nsPluginHostImpl : public nsIPluginManager2, { public: nsPluginHostImpl(nsIServiceManager *serviceMgr); - ~nsPluginHostImpl(); + virtual ~nsPluginHostImpl(); NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW @@ -126,6 +126,12 @@ public: NS_IMETHOD SetUpPluginInstance(const char *aMimeType, nsIURL *aURL, nsIPluginInstanceOwner *aOwner); + NS_IMETHOD + IsPluginAvailableForType(const char* aMimeType); + + NS_IMETHOD + IsPluginAvailableForExtension(const char* aExtension, const char* &aMimeType); + //nsIPluginManager2 interface - secondary methods that nsIPlugin communicates to NS_IMETHOD diff --git a/modules/plugin/base/src/nsPluginInstancePeer.cpp b/modules/plugin/base/src/nsPluginInstancePeer.cpp index 34db3d53fe80..2e79df18ab8a 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -142,7 +142,7 @@ class nsPluginStreamToFile : public nsIOutputStream public: nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner); - ~nsPluginStreamToFile(); + virtual ~nsPluginStreamToFile(); NS_DECL_ISUPPORTS diff --git a/modules/plugin/base/src/nsPluginInstancePeer.h b/modules/plugin/base/src/nsPluginInstancePeer.h index 785d1aab6a89..6d0e6599878c 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.h +++ b/modules/plugin/base/src/nsPluginInstancePeer.h @@ -34,7 +34,7 @@ class nsPluginInstancePeerImpl : public nsIPluginInstancePeer, { public: nsPluginInstancePeerImpl(); - ~nsPluginInstancePeerImpl(); + virtual ~nsPluginInstancePeerImpl(); NS_DECL_ISUPPORTS diff --git a/modules/plugin/nglsrc/ns4xPlugin.h b/modules/plugin/nglsrc/ns4xPlugin.h index 5e38f7c3e1f3..f7dea6da853d 100644 --- a/modules/plugin/nglsrc/ns4xPlugin.h +++ b/modules/plugin/nglsrc/ns4xPlugin.h @@ -56,7 +56,7 @@ class ns4xPlugin : public nsIPlugin public: ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr); - ~ns4xPlugin(void); + virtual ~ns4xPlugin(void); NS_DECL_ISUPPORTS diff --git a/modules/plugin/nglsrc/ns4xPluginInstance.h b/modules/plugin/nglsrc/ns4xPluginInstance.h index be9334d4df38..d0c46183b288 100644 --- a/modules/plugin/nglsrc/ns4xPluginInstance.h +++ b/modules/plugin/nglsrc/ns4xPluginInstance.h @@ -104,7 +104,7 @@ public: ns4xPluginInstance(NPPluginFuncs* callbacks); // Use Release() to destroy this - ~ns4xPluginInstance(void); + virtual ~ns4xPluginInstance(void); protected: diff --git a/modules/plugin/nglsrc/nsIPluginHost.h b/modules/plugin/nglsrc/nsIPluginHost.h index 0fa39f791cc7..5466b65f2554 100644 --- a/modules/plugin/nglsrc/nsIPluginHost.h +++ b/modules/plugin/nglsrc/nsIPluginHost.h @@ -59,6 +59,12 @@ public: NS_IMETHOD SetUpPluginInstance(const char *aMimeType, nsIURL *aURL, nsIPluginInstanceOwner *aOwner) = 0; + NS_IMETHOD + IsPluginAvailableForType(const char* aMimeType) = 0; + + NS_IMETHOD + IsPluginAvailableForExtension(const char* aExtension, const char* &aMimeType) = 0; + }; #endif // nsIPluginHost_h___ diff --git a/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/modules/plugin/nglsrc/nsPluginHostImpl.cpp index b221e987eb3b..70029242e1cb 100644 --- a/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -153,7 +153,7 @@ class nsPluginStreamInfo : public nsIPluginStreamInfo public: nsPluginStreamInfo(); - ~nsPluginStreamInfo(); + virtual ~nsPluginStreamInfo(); NS_DECL_ISUPPORTS @@ -337,7 +337,7 @@ class nsPluginStreamListenerPeer : public nsIStreamListener { public: nsPluginStreamListenerPeer(); - ~nsPluginStreamListenerPeer(); + virtual ~nsPluginStreamListenerPeer(); NS_DECL_ISUPPORTS @@ -408,7 +408,7 @@ class nsPluginCacheListener : public nsIStreamListener { public: nsPluginCacheListener(nsPluginStreamListenerPeer* aListener); - ~nsPluginCacheListener(); + virtual ~nsPluginCacheListener(); NS_DECL_ISUPPORTS @@ -646,13 +646,6 @@ nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer() mOnStopBinding = PR_FALSE; mCacheDone = PR_FALSE; mStatus = NS_OK; - -#ifdef USE_CACHE - mCachedFile = nsnull; -#else - mStreamFile = nsnull; - mFileName = nsnull; -#endif } nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer() @@ -671,24 +664,6 @@ nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer() NS_IF_RELEASE(mInstance); NS_IF_RELEASE(mPStreamListener); NS_IF_RELEASE(mHost); - -#ifdef USE_CACHE - if (nsnull != mCachedFile) - { - delete mCachedFile; - mCachedFile = nsnull; - } -#else // USE_CACHE - if(nsnull != mStreamFile) - { - fclose(mStreamFile); - mStreamFile = nsnull; - } - - if(nsnull != mFileName) - PL_strfree(mFileName); - -#endif // USE_CACHE } NS_IMPL_ADDREF(nsPluginStreamListenerPeer); @@ -882,8 +857,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnDataAvailable(nsIURL* aURL, nsIInp { nsresult rv = NS_OK; const char* url; - char* buffer; - PRUint32 readlen; if(!mPStreamListener) return NS_ERROR_FAILURE; @@ -892,25 +865,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnDataAvailable(nsIURL* aURL, nsIInp aURL->GetSpec(&urlString); mPluginStreamInfo->SetURL(urlString); -#if 0 - // determine if we need to write the data to the cache - if((mStreamType == nsPluginStreamType_AsFile) || (mStreamType == nsPluginStreamType_AsFileOnly)) - { - buffer = (char*) PR_Malloc(aLength); - if(buffer) - aIStream->Read(buffer, aLength, &readlen); - -#ifdef USE_CACHE - if(nsnull != mCachedFile) - mCachedFile->Write((char*)buffer, aLength); -#else - if(nsnull != mStreamFile) - fwrite(buffer, sizeof(char), aLength, mStreamFile); -#endif // USE_CACHE - PR_Free(buffer); - } -#endif - // if the plugin has requested an AsFileOnly stream, then don't call OnDataAvailable if(mStreamType != nsPluginStreamType_AsFileOnly) { @@ -935,44 +889,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult aURL->GetSpec(&urlString); mPluginStreamInfo->SetURL(urlString); -#if 0 - // see if we need to close out the cache - if ((mStreamType == nsPluginStreamType_AsFile) || - (mStreamType == nsPluginStreamType_AsFileOnly)) - { -#ifdef USE_CACHE - if (nsnull != mCachedFile) - { - PRInt32 len; - nsCachePref* cachePref = nsCachePref::GetInstance(); - - const char* cachePath = cachePref->DiskCacheFolder(); - const char* filename = mCachedFile->Filename(); - - // we need to pass the whole path and filename to the plugin - len = PL_strlen(cachePath) + PL_strlen(filename) + 1; - char* pathAndFilename = (char*)PR_Malloc(len * sizeof(char)); - pathAndFilename = PL_strcpy(pathAndFilename, cachePath); - pathAndFilename = PL_strcat(pathAndFilename, filename); - - const char* urlString; - aURL->GetSpec(&urlString); - if (mPStreamListener) - mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, pathAndFilename); - } -#else // USE_CACHE - if(nsnull != mStreamFile) - { - fclose(mStreamFile); - mStreamFile = nsnull; - - if (mPStreamListener) - mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, mFileName); - } -#endif // USE_CACHE - } -#endif - // tell the plugin that the stream has ended only if the cache is done if(mCacheDone) mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus); @@ -988,68 +904,6 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL) { -#if 0 -#ifdef USE_CACHE - nsString urlString; - char* cString; - char* fileName; - - aURL->ToString(urlString); - cString = urlString.ToNewCString(); - mCachedFile = new nsCacheObject(cString); - delete [] cString; - - if(mCachedFile == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - // use the actual filename of the net-based file as the cache filename - aURL->GetFile(fileName); - mCachedFile->Filename(fileName); - - nsCacheManager* cacheManager = nsCacheManager::GetInstance(); - nsDiskModule* diskCache = cacheManager->GetDiskModule(); - diskCache->AddObject(mCachedFile); -#else // USE_CACHE - - char buf[400], tpath[300]; -#ifdef XP_PC - ::GetTempPath(sizeof(tpath), tpath); - PRInt32 len = PL_strlen(tpath); - - if((len > 0) && (tpath[len-1] != '\\')) - { - tpath[len] = '\\'; - tpath[len+1] = 0; - } -#elif defined (XP_UNIX) - PL_strcpy(tpath, "/tmp/"); -#else - tpath[0] = 0; -#endif // XP_PC - const char* pathName; - char* fileName; - aURL->GetFile(&pathName); - - // since GetFile actually returns us the full path, move to the last \ and skip it - fileName = PL_strrchr(pathName, '/'); - if(fileName) - ++fileName; - - // if we don't get a filename for some reason, just make one up using the address of this - // object to ensure uniqueness of the filename per stream - if(!fileName) - PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this); - else - PR_snprintf(buf, sizeof(buf), "%s%s", tpath, fileName); - - mStreamFile = fopen(buf, "wb"); - //setbuf(mStreamFile, NULL); - - mFileName = PL_strdup(buf); -#endif // USE_CACHE - return NS_OK; -#endif - nsPluginCacheListener* cacheListener = new nsPluginCacheListener(this); return NS_OpenURL(aURL, cacheListener); } @@ -1095,12 +949,17 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL) nsresult nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename) { - nsresult rv = NS_ERROR_FAILURE; - if (mPStreamListener) - rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename); + nsresult rv; + if (!mPStreamListener) + return NS_ERROR_FAILURE; + + if((rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename)) != NS_OK) + return rv; + // if OnStopBinding has already been called, we need to make sure the plugin gets notified + // we do this here because OnStopBinding must always be called after OnFileAvailable if(mOnStopBinding) - mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, mStatus); + rv = mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, mStatus); mCacheDone = PR_TRUE; return rv; @@ -1458,6 +1317,11 @@ NS_IMETHODIMP nsPluginHostImpl :: InstantiateEmbededPlugin(const char *aMimeType if(rv == NS_OK) rv = aOwner->GetInstance(instance); + // if we have a failure error, it means we found a plugin for the mimetype, + // but we had a problem with the entry point + if(rv == NS_ERROR_FAILURE) + return rv; + if(rv != NS_OK) { // we have not been able to load a plugin because we have not determined the mimetype @@ -1740,6 +1604,8 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, NS_RELEASE(instance); } } + else + return NS_ERROR_FAILURE; } else return NS_ERROR_UNEXPECTED; // LoadPluginLibrary failure @@ -1759,6 +1625,77 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, #endif /* !XP_MAC */ +NS_IMETHODIMP +nsPluginHostImpl::IsPluginAvailableForType(const char* aMimeType) +{ + nsPluginTag *plugins = nsnull; + PRInt32 variants, cnt; + + if (PR_FALSE == mPluginsLoaded) + LoadPlugins(); + + // if we have a mimetype passed in, search the mPlugins linked list for a match + if (nsnull != aMimeType) + { + plugins = mPlugins; + + while (nsnull != plugins) + { + variants = plugins->mVariants; + + for (cnt = 0; cnt < variants; cnt++) + { + if (0 == strcmp(plugins->mMimeTypeArray[cnt], aMimeType)) + return NS_OK; + } + + if (cnt < variants) + break; + + plugins = plugins->mNext; + } + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsPluginHostImpl::IsPluginAvailableForExtension(const char* aExtension, const char* &aMimeType) +{ + nsPluginTag *plugins = nsnull; + PRInt32 variants, cnt; + + if (PR_FALSE == mPluginsLoaded) + LoadPlugins(); + + // if we have a mimetype passed in, search the mPlugins linked list for a match + if (nsnull != aExtension) + { + plugins = mPlugins; + + while (nsnull != plugins) + { + variants = plugins->mVariants; + + for (cnt = 0; cnt < variants; cnt++) + { + if (0 == strcmp(plugins->mExtensionsArray[cnt], aExtension)) + { + aMimeType = plugins->mMimeTypeArray[cnt]; + return NS_OK; + } + } + + if (cnt < variants) + break; + + plugins = plugins->mNext; + } + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) { nsresult res = NS_ERROR_FAILURE; @@ -2236,7 +2173,7 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const nsFileSpec &pluginSpec) PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path) { #ifdef XP_PC - /*BOOL restoreOrigDir = FALSE; + BOOL restoreOrigDir = FALSE; char aOrigDir[MAX_PATH + 1]; DWORD dwCheck = ::GetCurrentDirectory(sizeof(aOrigDir), aOrigDir); PR_ASSERT(dwCheck <= MAX_PATH + 1); @@ -2245,15 +2182,15 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha { restoreOrigDir = ::SetCurrentDirectory(pluginPath); PR_ASSERT(restoreOrigDir); - }*/ + } PRLibrary* plugin = PR_LoadLibrary(path); - /*if (restoreOrigDir) + if (restoreOrigDir) { BOOL bCheck = ::SetCurrentDirectory(aOrigDir); PR_ASSERT(bCheck); - }*/ + } return plugin; #else diff --git a/modules/plugin/nglsrc/nsPluginHostImpl.h b/modules/plugin/nglsrc/nsPluginHostImpl.h index 385cdf4af04e..d6c2029f462e 100644 --- a/modules/plugin/nglsrc/nsPluginHostImpl.h +++ b/modules/plugin/nglsrc/nsPluginHostImpl.h @@ -63,7 +63,7 @@ class nsPluginHostImpl : public nsIPluginManager2, { public: nsPluginHostImpl(nsIServiceManager *serviceMgr); - ~nsPluginHostImpl(); + virtual ~nsPluginHostImpl(); NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW @@ -126,6 +126,12 @@ public: NS_IMETHOD SetUpPluginInstance(const char *aMimeType, nsIURL *aURL, nsIPluginInstanceOwner *aOwner); + NS_IMETHOD + IsPluginAvailableForType(const char* aMimeType); + + NS_IMETHOD + IsPluginAvailableForExtension(const char* aExtension, const char* &aMimeType); + //nsIPluginManager2 interface - secondary methods that nsIPlugin communicates to NS_IMETHOD diff --git a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index 34db3d53fe80..2e79df18ab8a 100644 --- a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -142,7 +142,7 @@ class nsPluginStreamToFile : public nsIOutputStream public: nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner); - ~nsPluginStreamToFile(); + virtual ~nsPluginStreamToFile(); NS_DECL_ISUPPORTS diff --git a/modules/plugin/nglsrc/nsPluginInstancePeer.h b/modules/plugin/nglsrc/nsPluginInstancePeer.h index 785d1aab6a89..6d0e6599878c 100644 --- a/modules/plugin/nglsrc/nsPluginInstancePeer.h +++ b/modules/plugin/nglsrc/nsPluginInstancePeer.h @@ -34,7 +34,7 @@ class nsPluginInstancePeerImpl : public nsIPluginInstancePeer, { public: nsPluginInstancePeerImpl(); - ~nsPluginInstancePeerImpl(); + virtual ~nsPluginInstancePeerImpl(); NS_DECL_ISUPPORTS