Fixing bug 281284. Don't share the plugin temp directory among all users on the same system, and don't delete directories we didn't create. r=peterv@propagandism.org, sr=dveditz@cruzio.com

This commit is contained in:
jst%mozilla.jstenback.com 2005-02-11 23:37:51 +00:00
parent 4b5a2fad7a
commit 3a3e51d9e9
2 changed files with 43 additions and 30 deletions

View File

@ -270,6 +270,8 @@ static nsActivePluginList *gActivePluginList;
PRBool gSkipPluginSafeCalls = PR_FALSE; PRBool gSkipPluginSafeCalls = PR_FALSE;
#endif #endif
nsIFile *nsPluginHostImpl::sPluginTempDir;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// flat file reg funcs // flat file reg funcs
static static
@ -1860,14 +1862,10 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel)
if (!useExistingCacheFile) { if (!useExistingCacheFile) {
nsCOMPtr<nsIFile> pluginTmp; nsCOMPtr<nsIFile> pluginTmp;
// Is this the best place to put this temp file? rv = nsPluginHostImpl::GetPluginTempDir(getter_AddRefs(pluginTmp));
rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); if (NS_FAILED(rv)) {
if (NS_FAILED(rv)) return rv; return rv;
}
rv = pluginTmp->AppendNative(kPluginTmpDirName);
if (NS_FAILED(rv)) return rv;
(void) pluginTmp->Create(nsIFile::DIRECTORY_TYPE,0777);
// Get the filename from the channel // Get the filename from the channel
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
@ -3246,19 +3244,17 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void)
} }
// Lets remove any of the temporary files that we created. // Lets remove any of the temporary files that we created.
nsCOMPtr<nsIFile> pluginTmp; if (sPluginTempDir) {
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); sPluginTempDir->Remove(PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = pluginTmp->AppendNative(kPluginTmpDirName); NS_RELEASE(sPluginTempDir);
if (NS_FAILED(rv)) return rv; }
pluginTmp->Remove(PR_TRUE);
if (mPrivateDirServiceProvider) if (mPrivateDirServiceProvider)
{ {
nsCOMPtr<nsIDirectoryService> dirService(do_GetService(kDirectoryServiceContractID, &rv)); nsCOMPtr<nsIDirectoryService> dirService =
if (NS_SUCCEEDED(rv)) do_GetService(kDirectoryServiceContractID);
if (dirService)
dirService->UnregisterProvider(mPrivateDirServiceProvider); dirService->UnregisterProvider(mPrivateDirServiceProvider);
mPrivateDirServiceProvider = nsnull; mPrivateDirServiceProvider = nsnull;
} }
@ -3279,6 +3275,27 @@ void nsPluginHostImpl::UnloadUnusedLibraries()
mUnusedLibraries.Clear(); mUnusedLibraries.Clear();
} }
nsresult
nsPluginHostImpl::GetPluginTempDir(nsIFile **aDir)
{
if (!sPluginTempDir) {
nsCOMPtr<nsIFile> tmpDir;
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR,
getter_AddRefs(tmpDir));
NS_ENSURE_SUCCESS(rv, rv);
rv = tmpDir->AppendNative(kPluginTmpDirName);
// make it unique, and mode == 0700, not world-readable
rv = tmpDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700);
NS_ENSURE_SUCCESS(rv, rv);
tmpDir.swap(sPluginTempDir);
}
return sPluginTempDir->Clone(aDir);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/* Called by nsPluginInstanceOwner (nsObjectFrame.cpp - embeded case) */ /* Called by nsPluginInstanceOwner (nsObjectFrame.cpp - embeded case) */
@ -6391,22 +6408,14 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStream), inFile); rv = NS_NewLocalFileInputStream(getter_AddRefs(inStream), inFile);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// Create a temporary file to write the http Content-length: %ld\r\n\" header // Create a temporary file to write the http Content-length:
// and "\r\n" == end of headers for post data to // %ld\r\n\" header and "\r\n" == end of headers for post data to
nsCOMPtr<nsIFile> tempFile; nsCOMPtr<nsIFile> tempFile;
rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempFile)); rv = GetPluginTempDir(getter_AddRefs(tempFile));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
rv = tempFile->AppendNative(kPluginTmpDirName);
if (NS_FAILED(rv))
return rv;
PRBool dirExists;
tempFile->Exists(&dirExists);
if (!dirExists)
(void) tempFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
nsCAutoString inFileName; nsCAutoString inFileName;
inFile->GetNativeLeafName(inFileName); inFile->GetNativeLeafName(inFileName);
// XXX hack around bug 70083 // XXX hack around bug 70083

View File

@ -408,6 +408,8 @@ public:
NS_IMETHOD NS_IMETHOD
AddUnusedLibrary(PRLibrary * aLibrary); AddUnusedLibrary(PRLibrary * aLibrary);
static nsresult GetPluginTempDir(nsIFile **aDir);
private: private:
NS_IMETHOD NS_IMETHOD
TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner); TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner);
@ -507,8 +509,10 @@ private:
nsCOMPtr<nsIFile> mPluginRegFile; nsCOMPtr<nsIFile> mPluginRegFile;
nsCOMPtr<nsIPrefBranch> mPrefService; nsCOMPtr<nsIPrefBranch> mPrefService;
nsRefPtr<nsPluginDirServiceProvider> mPrivateDirServiceProvider; nsRefPtr<nsPluginDirServiceProvider> mPrivateDirServiceProvider;
nsWeakPtr mCurrentDocument; // weak reference, we use it to id document only nsWeakPtr mCurrentDocument; // weak reference, we use it to id document only
static nsIFile *sPluginTempDir;
}; };
#endif #endif