diff --git a/xpcom/io/nsEscape.cpp b/xpcom/io/nsEscape.cpp index 3f64586b4c2b..c6839fe69506 100644 --- a/xpcom/io/nsEscape.cpp +++ b/xpcom/io/nsEscape.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file diff --git a/xpcom/io/nsIFile.idl b/xpcom/io/nsIFile.idl index ec4eff6bf1da..4e49333e9d72 100644 --- a/xpcom/io/nsIFile.idl +++ b/xpcom/io/nsIFile.idl @@ -295,6 +295,12 @@ interface nsIFile : nsISupports * not specify a directory. */ readonly attribute nsISimpleEnumerator directoryEntries; + + /** + * Accesses the file: url for the nsIFile. Setting this causes the path + * to be reset. + */ + attribute string URL; }; %{C++ diff --git a/xpcom/io/nsLocalFileMac.cpp b/xpcom/io/nsLocalFileMac.cpp index 140dc450836c..2a2fd8d72771 100644 --- a/xpcom/io/nsLocalFileMac.cpp +++ b/xpcom/io/nsLocalFileMac.cpp @@ -2091,6 +2091,16 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) return NS_OK; } +NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) { diff --git a/xpcom/io/nsLocalFileOS2.cpp b/xpcom/io/nsLocalFileOS2.cpp index b09fc660fb65..c4cdb4398454 100644 --- a/xpcom/io/nsLocalFileOS2.cpp +++ b/xpcom/io/nsLocalFileOS2.cpp @@ -2088,6 +2088,45 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) return NS_OK; } +NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL) +{ + nsresult rv; + char* ePath = (char*) nsMemory::Clone(mWorkingPath, strlen(mWorkingPath)+1); + if (ePath == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + // Replace \ with / to convert to an url + char* s = ePath; + while (*s) { + if (*s == '\\') + *s = '/'; + s++; + } + // Escape the path with the directory mask + nsCAutoString tmp = ePath; + tmp.ReplaceChar(":", '|'); + nsCAutoString escPath = "file://"; + escPath += tmp; +// rv = nsURLEscape(ePath,nsIIOService::url_Directory + nsIIOService::url_Forced, escPath); +// if (NS_SUCCEEDED(rv)) { + PRBool dir; + rv = IsDirectory(&dir); + if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') { + // make sure we have a trailing slash + escPath += "/"; + } + *aURL = escPath.ToNewCString(); + if (*aURL == nsnull) + return NS_ERROR_OUT_OF_MEMORY; +// } + + return rv; +} + +NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) { diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index 6a684b7fa712..8771c07a5ba3 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -1321,6 +1321,16 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries) (void **)entries); } +NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsLocalFile::Load(PRLibrary **_retval) { diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 5bedd06b9421..caa3f792b358 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -1848,6 +1848,55 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) return NS_OK; } +NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL) +{ + nsresult rv; + char* ePath = (char*) nsMemory::Clone(mWorkingPath, strlen(mWorkingPath)+1); + if (ePath == nsnull) + return NS_ERROR_OUT_OF_MEMORY; +#if defined (XP_PC) + // Replace \ with / to convert to an url + char* s = ePath; + while (*s) + { + // We need to call IsDBCSLeadByte because + // Japanese windows can have 0x5C in the sencond byte + // of a Japanese character, for example 0x8F 0x5C is + // one Japanese character + if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull) { + s++; + } else + if (*s == '\\') + *s = '/'; + s++; + } +#endif + // Escape the path with the directory mask + nsCAutoString tmp(ePath); + tmp.ReplaceChar(":", '|'); + nsCAutoString escPath("file://"); + escPath += tmp; +// rv = nsURLEscape(ePath,nsIIOService::url_Directory + nsIIOService::url_Forced, escPath); +// if (NS_SUCCEEDED(rv)) { + PRBool dir; + rv = IsDirectory(&dir); + if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') { + // make sure we have a trailing slash + escPath += "/"; + } + *aURL = escPath.ToNewCString(); + if (*aURL == nsnull) + return NS_ERROR_OUT_OF_MEMORY; +// } + + return rv; +} + +NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) {