mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
final fix for bug 100212 - removal final dependency on necko from xpcom by removing nsIFile.URL r=dougt, sr=darin Yay!
This commit is contained in:
parent
b1655936f8
commit
63991ddfde
@ -31,7 +31,6 @@ XPIDL_MODULE = xpcom_io
|
||||
LIBRARY_NAME = xpcomio_s
|
||||
REQUIRES = uconv \
|
||||
string \
|
||||
necko \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -23,7 +23,6 @@ DEPTH=..\..
|
||||
MODULE = xpcom
|
||||
REQUIRES = uconv \
|
||||
string \
|
||||
necko \
|
||||
$(NULL)
|
||||
|
||||
################################################################################
|
||||
|
@ -297,11 +297,6 @@ interface nsIFile : nsISupports
|
||||
*/
|
||||
readonly attribute nsISimpleEnumerator directoryEntries;
|
||||
|
||||
/**
|
||||
* Accesses the file: url for the nsIFile. Setting this causes the path
|
||||
* to be reset.
|
||||
*/
|
||||
attribute string URL;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
@ -35,11 +35,6 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIServiceManager.h"
|
||||
#ifndef XPCOM_STANDALONE
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsNetCID.h"
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
|
||||
#include "nsLocalFile.h" // includes platform-specific headers
|
||||
#include "nsLocalFileUnicode.h"
|
||||
@ -48,9 +43,6 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
static NS_DEFINE_CID(kURLParserCID, NS_NOAUTHURLPARSER_CID);
|
||||
#endif
|
||||
|
||||
|
||||
void NS_StartupLocalFile()
|
||||
@ -122,61 +114,7 @@ nsLocalFile::CreateUnique(PRUint32 type, PRUint32 attributes)
|
||||
return NS_ERROR_FILE_TOO_BIG;
|
||||
}
|
||||
|
||||
nsresult nsLocalFile::ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
NS_ENSURE_ARG(inURL);
|
||||
NS_ENSURE_ARG_POINTER(outHost);
|
||||
*outHost = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(outDirectory);
|
||||
*outDirectory = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(outFileBaseName);
|
||||
*outFileBaseName = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(outFileExtension);
|
||||
*outFileExtension = nsnull;
|
||||
|
||||
nsCOMPtr<nsIURLParser> parser(do_GetService(kURLParserCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUint32 pathPos, filepathPos, directoryPos, basenamePos, extensionPos;
|
||||
PRInt32 pathLen, filepathLen, directoryLen, basenameLen, extensionLen;
|
||||
|
||||
// invoke the parser to extract the URL path
|
||||
rv = parser->ParseURL(inURL, -1,
|
||||
nsnull, nsnull, // dont care about scheme
|
||||
nsnull, nsnull, // dont care about authority
|
||||
&pathPos, &pathLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// invoke the parser to extract filepath from the path
|
||||
rv = parser->ParsePath(inURL + pathPos, pathLen,
|
||||
&filepathPos, &filepathLen,
|
||||
nsnull, nsnull, // dont care about param
|
||||
nsnull, nsnull, // dont care about query
|
||||
nsnull, nsnull); // dont care about ref
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
filepathPos += pathPos;
|
||||
|
||||
// invoke the parser to extract the directory and filename from filepath
|
||||
rv = parser->ParseFilePath(inURL + filepathPos, filepathLen,
|
||||
&directoryPos, &directoryLen,
|
||||
&basenamePos, &basenameLen,
|
||||
&extensionPos, &extensionLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (directoryLen > 0)
|
||||
*outDirectory = PL_strndup(inURL + filepathPos + directoryPos, directoryLen);
|
||||
if (basenameLen > 0)
|
||||
*outFileBaseName = PL_strndup(inURL + filepathPos + basenamePos, basenameLen);
|
||||
if (extensionLen > 0)
|
||||
*outFileExtension = PL_strndup(inURL + filepathPos + extensionPos, extensionLen);
|
||||
// since we are using a no-auth url parser, there will never be a host
|
||||
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -434,19 +434,6 @@ static nsresult ConvertMillisecondsToMacTime(PRInt64 aTime, PRUint32 *aOutMacTim
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void SwapSlashColon(char * s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
if (*s == '/')
|
||||
*s++ = ':';
|
||||
else if (*s == ':')
|
||||
*s++ = '/';
|
||||
else
|
||||
*s++;
|
||||
}
|
||||
}
|
||||
|
||||
static void myPLstrcpy(Str255 dst, const char* src)
|
||||
{
|
||||
int srcLength = strlen(src);
|
||||
@ -2251,98 +2238,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
SwapSlashColon(ePath);
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (escPath[escPath.Length() - 1] != '/') {
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir) {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
}
|
||||
escPath.Insert("file:///", 0);
|
||||
|
||||
*aURL = ToNewCString(escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (host)
|
||||
{
|
||||
// We can end up with a host when given: file:// instead of file:///
|
||||
// Check to see if the host is a volume name - If so prepend it
|
||||
Str255 volName;
|
||||
FSSpec volSpec;
|
||||
|
||||
myPLstrcpy(volName, host);
|
||||
volName[++volName[0]] = ':';
|
||||
if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr)
|
||||
path += host;
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
SwapSlashColon((char*)path.get());
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
// wack off leading :'s
|
||||
if (path.CharAt(0) == ':')
|
||||
path.Cut(0, 1);
|
||||
|
||||
rv = InitWithPath(path.get());
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor)
|
||||
{
|
||||
|
@ -59,9 +59,6 @@ public:
|
||||
// nsILocalFileMac interface
|
||||
NS_DECL_NSILOCALFILEMAC
|
||||
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
|
||||
protected:
|
||||
|
||||
void MakeDirty();
|
||||
|
@ -2052,114 +2052,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// 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
|
||||
#ifdef XP_OS2
|
||||
if(::isleadbyte(*s) && *(s+1) != nsnull)
|
||||
#else
|
||||
if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull)
|
||||
#endif
|
||||
{
|
||||
s++;
|
||||
}
|
||||
else if (*s == '\\') {
|
||||
*s = '/';
|
||||
}
|
||||
s++;
|
||||
}
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
escPath.Insert("file:///", 0);
|
||||
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
*aURL = ToNewCString(escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (host)
|
||||
{
|
||||
// We can end up with a host when given: file://C|/ instead of file:///
|
||||
if (strlen((const char *)host) == 2 && ((const char *)host)[1] == '|')
|
||||
{
|
||||
path += host;
|
||||
path.SetCharAt(':', 1);
|
||||
}
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
if (!host && component.Length() > 2 && component.CharAt(2) == '|')
|
||||
component.SetCharAt(':', 2);
|
||||
component.ReplaceChar('/', '\\');
|
||||
path += component;
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
// remove leading '\'
|
||||
if (path.CharAt(0) == '\\')
|
||||
path.Cut(0, 1);
|
||||
|
||||
rv = InitWithPath(path.get());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor)
|
||||
{
|
||||
|
@ -140,8 +140,6 @@ private:
|
||||
|
||||
nsresult SetModDate(PRInt64 aLastModifiedTime, PRBool resolveTerminal);
|
||||
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1477,81 +1477,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries)
|
||||
(void **)entries);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (escPath[escPath.Length() - 1] != '/') {
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir) {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
}
|
||||
|
||||
escPath.Insert("file://", 0);
|
||||
|
||||
*aURL = ToNewCString(escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host),
|
||||
getter_Copies(directory),
|
||||
getter_Copies(fileBaseName),
|
||||
getter_Copies(fileExtension));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (directory) {
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
rv = InitWithPath(path.get());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::Load(PRLibrary **_retval)
|
||||
{
|
||||
|
@ -104,8 +104,6 @@ protected:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
};
|
||||
|
||||
#endif /* _nsLocalFileUNIX_H_ */
|
||||
|
@ -1893,111 +1893,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// 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++;
|
||||
}
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (escPath[escPath.Length() - 1] != '/') {
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir) {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
}
|
||||
escPath.Insert("file:///", 0);
|
||||
*aURL = ToNewCString(escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (host)
|
||||
{
|
||||
// We can end up with a host when given: file://C|/ instead of file:///
|
||||
if (strlen((const char *)host) == 2 && ((const char *)host)[1] == '|')
|
||||
{
|
||||
path += host;
|
||||
path.SetCharAt(':', 1);
|
||||
}
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
if (!host && component.Length() > 2 && component.CharAt(2) == '|')
|
||||
component.SetCharAt(':', 2);
|
||||
component.ReplaceChar('/', '\\');
|
||||
path += component;
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
// remove leading '\'
|
||||
if (path.CharAt(0) == '\\')
|
||||
path.Cut(0, 1);
|
||||
|
||||
rv = InitWithPath(path.get());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor)
|
||||
{
|
||||
|
@ -90,8 +90,6 @@ private:
|
||||
|
||||
nsresult SetModDate(PRInt64 aLastModifiedTime, PRBool resolveTerminal);
|
||||
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user