fixes bug 129279 "nsIFile unicode/utf8/ascii task"

r=dougt sr=alecf


git-svn-id: svn://10.0.0.236/trunk@120092 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
darin%netscape.com
2002-04-27 05:33:09 +00:00
parent fadd9c12b4
commit 824def02af
210 changed files with 3081 additions and 2903 deletions

View File

@@ -142,7 +142,7 @@ NS_NewPluginPostDataStream(nsIInputStream **result,
} else {
nsCOMPtr<nsILocalFile> file; // tmp file will be deleted on release of stream
nsCOMPtr<nsIInputStream> fileStream;
if (NS_SUCCEEDED(rv = NS_NewLocalFile(data, PR_FALSE, getter_AddRefs(file))) &&
if (NS_SUCCEEDED(rv = NS_NewNativeLocalFile(nsDependentCString(data), PR_FALSE, getter_AddRefs(file))) &&
NS_SUCCEEDED(rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream),
file,
PR_RDONLY,

View File

@@ -40,6 +40,7 @@
#include "nsCRT.h"
#include "nsILocalFile.h"
#include "nsDependentString.h"
#if defined (XP_WIN)
#include <windows.h>
@@ -109,7 +110,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil
result = ::RegQueryValueEx(keyloc, "Plugins Directory", NULL, &type, (LPBYTE)&path, &pathlen);
if (result == ERROR_SUCCESS)
rv = NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(localFile));
rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_TRUE, getter_AddRefs(localFile));
::RegCloseKey(keyloc);
}
}
@@ -176,7 +177,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil
if (newestPath[0] != 0)
{
PL_strcat(newestPath,"\\bin");
rv = NS_NewLocalFile(newestPath, PR_TRUE, getter_AddRefs(localFile));
rv = NS_NewNativeLocalFile(nsDependentCString(newestPath), PR_TRUE, getter_AddRefs(localFile));
}
#endif
}

View File

@@ -187,7 +187,7 @@
// this is the name of the directory which will be created
// to cache temporary files.
static const char *kPluginTmpDirName = "plugtmp";
#define kPluginTmpDirName NS_LITERAL_CSTRING("plugtmp")
// Version of cached plugin info
// 0.01 first implementation
@@ -1175,10 +1175,10 @@ public:
MakeByteRangeString(nsByteRange* aRangeList, nsACString &string, PRInt32 *numRequests);
void
SetLocalCachedFile(const char* path);
SetLocalCachedFile(nsIFile *file);
void
GetLocalCachedFile(char** path);
GetLocalCachedFile(nsIFile** file);
void
SetLocalCachedFileStream(nsIOutputStream *stream);
@@ -1190,7 +1190,7 @@ private:
char* mContentType;
char* mURL;
char* mFilePath;
nsCOMPtr<nsIFile> mCachedFile;
PRBool mSeekable;
PRUint32 mLength;
PRUint32 mModified;
@@ -1231,11 +1231,11 @@ public:
nsresult InitializeFullPage(nsIPluginInstance *aInstance);
nsresult OnFileAvailable(const char* aFilename);
nsresult OnFileAvailable(nsIFile* aFile);
nsILoadGroup* GetLoadGroup();
nsresult SetLocalFile(const char* aFilename);
nsresult SetLocalFile(nsIFile* aFile);
private:
nsresult SetUpCache(nsIURI* aURL); // todo: see about removing this...
@@ -1269,7 +1269,7 @@ private:
nsIPluginHost *mHost;
// local file which was used to post data and which should be deleted after that
char *mLocalFile;
nsCOMPtr<nsIFile> mLocalFile;
nsHashtable *mDataForwardToRequest;
public:
@@ -1289,7 +1289,6 @@ nsPluginStreamInfo::nsPluginStreamInfo()
mContentType = nsnull;
mURL = nsnull;
mFilePath = nsnull;
mSeekable = PR_FALSE;
mLength = 0;
mModified = 0;
@@ -1312,17 +1311,10 @@ nsPluginStreamInfo::~nsPluginStreamInfo()
mFileCacheOutputStream->Close();
// ONLY delete our cached file if we created it
if(mLocallyCached && mFilePath)
if(mLocallyCached && mCachedFile)
{
nsCOMPtr<nsILocalFile> localFile;
nsresult res = NS_NewLocalFile(mFilePath,
PR_FALSE,
getter_AddRefs(localFile));
if(NS_SUCCEEDED(res))
localFile->Remove(PR_FALSE);
mCachedFile->Remove(PR_FALSE);
}
if (mFilePath)
PL_strfree(mFilePath);
NS_IF_RELEASE(mPluginInstance);
}
@@ -1569,23 +1561,18 @@ nsPluginStreamInfo::SetURL(const char* url)
////////////////////////////////////////////////////////////////////////
void
nsPluginStreamInfo::SetLocalCachedFile(const char* path)
nsPluginStreamInfo::SetLocalCachedFile(nsIFile* file)
{
if(mFilePath != nsnull)
PL_strfree(mFilePath);
mFilePath = PL_strdup(path);
file->Clone(getter_AddRefs(mCachedFile));
}
////////////////////////////////////////////////////////////////////////
void
nsPluginStreamInfo::GetLocalCachedFile(char** path)
nsPluginStreamInfo::GetLocalCachedFile(nsIFile** file)
{
if (mFilePath)
*path = PL_strdup(mFilePath);
else
*path = nsnull;
*file = mCachedFile;
NS_IF_ADDREF(*file);
}
@@ -1718,7 +1705,6 @@ nsPluginStreamListenerPeer::nsPluginStreamListenerPeer()
mHost = nsnull;
mStreamType = nsPluginStreamType_Normal;
mStartBinding = PR_FALSE;
mLocalFile = nsnull;
mAbort = PR_FALSE;
mRequestFailed = PR_FALSE;
@@ -1735,8 +1721,11 @@ nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer()
nsCAutoString urlSpec;
if(mURL != nsnull) (void)mURL->GetSpec(urlSpec);
nsCAutoString filePath;
if(mLocalFile != nsnull) (void)mLocalFile->GetNativePath(filePath);
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginStreamListenerPeer::dtor this=%p, url=%s, POST_file=%s\n",this, urlSpec.get(), mLocalFile));
("nsPluginStreamListenerPeer::dtor this=%p, url=%s, POST_file=%s\n",this, urlSpec.get(), filePath.get()));
PR_LogFlush();
#endif
@@ -1751,13 +1740,8 @@ nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer()
// if we have mLocalFile (temp file used to post data) it should be
// safe to delete it now, and hopefully the owner doesn't hold it.
if(mLocalFile)
{
nsCOMPtr<nsILocalFile> localFile;
nsresult res = NS_NewLocalFile(mLocalFile, PR_FALSE, getter_AddRefs(localFile));
if(NS_SUCCEEDED(res))
localFile->Remove(PR_FALSE);
delete [] mLocalFile;
}
mLocalFile->Remove(PR_FALSE);
delete mDataForwardToRequest;
}
@@ -1931,18 +1915,15 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel)
if (NS_FAILED(rv)) return rv;
// Create a file to save our stream into. Should we scramble the name?
rv = pluginTmp->Append(filename.get());
rv = pluginTmp->AppendNative(filename);
if (NS_FAILED(rv)) return rv;
// Yes, make it unique.
rv = pluginTmp->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0777);
if (NS_FAILED(rv)) return rv;
// save the file path off.
nsXPIDLCString saveToFilename;
(void) pluginTmp->GetPath(getter_Copies(saveToFilename));
mPluginStreamInfo->SetLocalCachedFile(saveToFilename);
// save the file.
mPluginStreamInfo->SetLocalCachedFile(pluginTmp);
// create a file output stream to write to...
nsCOMPtr<nsIOutputStream> outstream;
@@ -2102,7 +2083,7 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
// it's possible for the server to not send a Content-Length. We should
// still work in this case.
if (NS_FAILED(rv)) {
mPluginStreamInfo->SetLength(-1);
mPluginStreamInfo->SetLength(PRUint32(-1));
}
else {
mPluginStreamInfo->SetLength(length);
@@ -2355,11 +2336,10 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,
return NS_OK;
}
nsXPIDLCString pathAndFilename;
mPluginStreamInfo->GetLocalCachedFile(getter_Copies(pathAndFilename));
nsCOMPtr<nsIFile> localFile;
mPluginStreamInfo->GetLocalCachedFile(getter_AddRefs(localFile));
if (!pathAndFilename) {
nsCOMPtr<nsIFile> localFile;
if (!localFile) {
nsCOMPtr<nsICachingChannel> cacheChannel = do_QueryInterface(request);
if (cacheChannel) {
cacheChannel->GetCacheFile(getter_AddRefs(localFile));
@@ -2370,13 +2350,10 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,
fileChannel->GetFile(getter_AddRefs(localFile));
}
}
if (localFile) {
localFile->GetPath(getter_Copies(pathAndFilename));
}
}
if (pathAndFilename && *pathAndFilename) {
OnFileAvailable(pathAndFilename);
if (localFile) {
OnFileAvailable(localFile);
}
if (mStartBinding)
@@ -2443,9 +2420,9 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
// set seekability (seekable if the stream has a known length and if the
// http server accepts byte ranges).
PRBool bSeekable = PR_FALSE;
PRUint32 length = -1;
PRUint32 length = PRUint32(-1);
mPluginStreamInfo->GetLength(&length);
if ((length != -1) && httpChannel)
if ((length != PRUint32(-1)) && httpChannel)
{
nsCAutoString range;
if(NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("accept-ranges"), range)))
@@ -2507,13 +2484,22 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
////////////////////////////////////////////////////////////////////////
nsresult
nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename)
nsPluginStreamListenerPeer::OnFileAvailable(nsIFile* aFile)
{
nsresult rv;
if (!mPStreamListener)
return NS_ERROR_FAILURE;
rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename);
nsCAutoString path;
rv = aFile->GetNativePath(path);
if (NS_FAILED(rv)) return rv;
if (path.IsEmpty()) {
NS_WARNING("empty path");
return NS_OK;
}
rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, path.get());
return rv;
}
@@ -2547,25 +2533,18 @@ nsPluginStreamListenerPeer::VisitHeader(const nsACString &header, const nsACStri
////////////////////////////////////////////////////////////////////////
nsresult nsPluginStreamListenerPeer::SetLocalFile(const char* aFilename)
nsresult nsPluginStreamListenerPeer::SetLocalFile(nsIFile* aFile)
{
NS_ENSURE_ARG_POINTER(aFilename);
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(aFile);
if(mLocalFile)
{
NS_ASSERTION(!mLocalFile, "nsPluginStreamListenerPeer::SetLocalFile -- path already set, cleaning...");
delete [] mLocalFile;
mLocalFile = nsnull;
}
mLocalFile = new char[PL_strlen(aFilename) + 1];
if(!mLocalFile)
return NS_ERROR_OUT_OF_MEMORY;
PL_strcpy(mLocalFile, aFilename);
return rv;
// clone file to prevent it from being changed out from under us
return aFile->Clone(getter_AddRefs(mLocalFile));
}
/////////////////////////////////////////////////////////////////////////
@@ -3894,9 +3873,9 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType,
if (NS_SUCCEEDED(result))
{
nsXPIDLCString path;
binDirectory->GetPath(getter_Copies(path));
restoreOrigDir = ::SetCurrentDirectory(path);
nsCAutoString path;
binDirectory->GetNativePath(path);
restoreOrigDir = ::SetCurrentDirectory(path.get());
}
}
#endif
@@ -4732,8 +4711,8 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir,
*aPluginsChanged = PR_FALSE;
#ifdef PLUGIN_LOGGING
nsXPIDLCString dirPath;
pluginsDir->GetPath(getter_Copies(dirPath));
nsCAutoString dirPath;
pluginsDir->GetNativePath(dirPath);
PLUGIN_LOG(PLUGIN_LOG_BASIC,
("nsPluginHostImpl::ScanPluginsDirectory dir=%s\n", dirPath.get()));
#endif
@@ -4751,15 +4730,15 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir,
rv = iter->GetNext(getter_AddRefs(supports));
if (NS_FAILED(rv))
continue;
nsCOMPtr<nsIFile> dirEntry(do_QueryInterface(supports, &rv));
nsCOMPtr<nsILocalFile> dirEntry(do_QueryInterface(supports, &rv));
if (NS_FAILED(rv))
continue;
nsXPIDLCString filePath;
rv = dirEntry->GetPath(getter_Copies(filePath));
nsCAutoString filePath;
rv = dirEntry->GetNativePath(filePath);
if (NS_FAILED(rv))
continue;
nsFileSpec file(filePath);
nsFileSpec file(filePath.get());
PRBool wasSymlink;
file.ResolveSymlink(wasSymlink);
@@ -5174,10 +5153,8 @@ void nsPluginHostImpl::ClearCachedPluginInfoList()
static nsresult
cidToDllname(nsIComponentManager* aComponentManager, nsIRegistry* aRegistry,
const char *aCID, char **dllName)
const nsACString &aCID, nsACString &dllName)
{
NS_ENSURE_ARG_POINTER(dllName);
// To figure out the filename of the plugin, we'll need to get the
// plugin's CID, and then navigate through the XPCOM registry to
// pull out the DLL name to which the CID is registered.
@@ -5452,13 +5429,13 @@ nsPluginHostImpl::LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFi
nsRegistryKey key;
node->GetKey(&key);
nsXPIDLCString filename;
rv = cidToDllname(aComponentManager, registry, cid, getter_Copies(filename));
nsCAutoString filename;
rv = cidToDllname(aComponentManager, registry, cid, filename);
if (NS_FAILED(rv))
continue;
nsPluginTag* tag = nsnull;
rv = LoadXPCOMPlugin(registry, filename, key, &tag);
rv = LoadXPCOMPlugin(registry, filename.get(), key, &tag);
if (NS_FAILED(rv))
continue;
@@ -5984,14 +5961,14 @@ NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result)
nsCOMPtr<nsIProperties> dirService(do_GetService(kDirectoryServiceContractID, &rv));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIFile> programDir;
rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(programDir));
nsCOMPtr<nsILocalFile> programDir;
rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(programDir));
if (NS_FAILED(rv))
return rv;
char *temp;
rv = programDir->GetPath(&temp);
*result = temp;
nsCAutoString temp;
rv = programDir->GetNativePath(temp);
*result = ToNewCString(temp);
return rv;
}
@@ -6006,14 +5983,14 @@ NS_IMETHODIMP nsPluginHostImpl::GetTempDirPath(const char* *result)
nsCOMPtr<nsIProperties> dirService(do_GetService(kDirectoryServiceContractID, &rv));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIFile> tempDir;
rv = dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(tempDir));
nsCOMPtr<nsILocalFile> tempDir;
rv = dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(tempDir));
if (NS_FAILED(rv))
return rv;
char *temp;
rv = tempDir->GetPath(&temp);
*result = temp;
nsCAutoString temp;
rv = tempDir->GetNativePath(temp);
*result = ToNewCString(temp);
return rv;
}
@@ -6404,14 +6381,14 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
*pTmpFileName = 0;
nsresult rv;
PRInt64 fileSize;
nsXPIDLCString filename;
nsCAutoString filename;
// stat file == get size & convert file:///c:/ to c: if needed
nsCOMPtr<nsILocalFile> inFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv) ||
(NS_FAILED(rv = NS_InitFileFromURLSpec(inFile, nsDependentCString(postDataURL))) &&
NS_FAILED(rv = inFile->InitWithPath(postDataURL))) ||
NS_FAILED(rv = inFile->InitWithNativePath(nsDependentCString(postDataURL)))) ||
NS_FAILED(rv = inFile->GetFileSize(&fileSize)) ||
NS_FAILED(rv = inFile->GetPath(getter_Copies(filename)))
NS_FAILED(rv = inFile->GetNativePath(filename))
)
return rv;
if (!LL_IS_ZERO(fileSize)) {
@@ -6435,11 +6412,9 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
if (!dirExists)
(void) tempFile->Create(nsIFile::DIRECTORY_TYPE, 0600);
nsXPIDLCString inFileName;
inFile->GetLeafName(getter_Copies(inFileName));
nsCAutoString tempFileName("post-");
tempFileName += inFileName;
rv = tempFile->Append(tempFileName.get());
nsCAutoString inFileName;
inFile->GetLeafName(inFileName);
rv = tempFile->Append(NS_LITERAL_CSTRING("post-") + inFileName);
if (NS_FAILED(rv))
return rv;
@@ -6497,7 +6472,9 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
inStream->Close();
outStream->Close();
if (NS_SUCCEEDED(rv)) {
tempFile->GetPath(pTmpFileName);
nsCAutoString path;
if (NS_SUCCEEDED(tempFile->GetNativePath(path)))
*pTmpFileName = ToNewCString(path);
}
}
return rv;