зеркало из https://github.com/mozilla/gecko-dev.git
backing out my changes -- rjc says it causes moz not to startup!
This commit is contained in:
Родитель
cbfdbcc0bc
Коммит
d876a8d7cc
|
@ -20,8 +20,6 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Alec Flett <alecf@netscape.com>
|
|
||||||
* Darin Fisher <darin@netscape.com>
|
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
@ -37,14 +35,13 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
/* Mac-specific local file url parsing */
|
|
||||||
#include "nsIOService.h"
|
#include "nsIOService.h"
|
||||||
#include "nsEscape.h"
|
#include "nsEscape.h"
|
||||||
#include "nsPrintfCString.h"
|
#include "nsPrintfCString.h"
|
||||||
|
|
||||||
static void SwapSlashColon(char *s)
|
static void SwapSlashColon(char * s)
|
||||||
{
|
{
|
||||||
while (*s) {
|
while (*s){
|
||||||
if (*s == '/')
|
if (*s == '/')
|
||||||
*s++ = ':';
|
*s++ = ':';
|
||||||
else if (*s == ':')
|
else if (*s == ':')
|
||||||
|
@ -54,7 +51,7 @@ static void SwapSlashColon(char *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PascalStringCopy(Str255 dst, const char *src)
|
static void PascalStringCopy(Str255 dst, const char* src)
|
||||||
{
|
{
|
||||||
int srcLength = strlen(src);
|
int srcLength = strlen(src);
|
||||||
NS_ASSERTION(srcLength <= 255, "Oops, Str255 can't hold >255 chars");
|
NS_ASSERTION(srcLength <= 255, "Oops, Str255 can't hold >255 chars");
|
||||||
|
@ -65,98 +62,102 @@ static void PascalStringCopy(Str255 dst, const char *src)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL)
|
||||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, char **aURL)
|
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(aURL);
|
NS_ENSURE_ARG_POINTER(aURL);
|
||||||
*aURL = nsnull;
|
*aURL = nsnull;
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsXPIDLCString ePath;
|
char* ePath = nsnull;
|
||||||
|
nsCAutoString escPath;
|
||||||
rv = aFile->GetPath(getter_Copies(ePath));
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
SwapSlashColon((char *) ePath.get());
|
rv = aFile->GetPath(&ePath);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
nsCAutoString escPath;
|
|
||||||
NS_NAMED_LITERAL_CSTRING(prefix, "file://");
|
|
||||||
|
|
||||||
// Escape the path with the directory mask
|
|
||||||
if (NS_EscapeURLPart(ePath.get(), ePath.Length(), esc_Directory+esc_Forced, escPath))
|
|
||||||
escPath.Insert(prefix, 0);
|
|
||||||
else
|
|
||||||
escPath.Assign(prefix + ePath);
|
|
||||||
|
|
||||||
// XXX this should be unnecessary
|
|
||||||
if (escPath[escPath.Length() - 1] != '/') {
|
|
||||||
PRBool dir;
|
|
||||||
rv = aFile->IsDirectory(&dir);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
|
|
||||||
else if (dir) {
|
|
||||||
// make sure we have a trailing slash
|
|
||||||
escPath += "/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*aURL = ToNewCString(escPath);
|
|
||||||
return *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsIOService::InitFileFromURLSpec(nsIFile *aFile, const char *aURL)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG(aURL);
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
|
||||||
|
|
||||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile, &rv);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
NS_ERROR("Only nsILocalFile supported right now");
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = ParseFileURL(aURL, getter_Copies(host),
|
|
||||||
getter_Copies(directory),
|
|
||||||
getter_Copies(fileBaseName),
|
|
||||||
getter_Copies(fileExtension));
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
nsCAutoString path;
|
|
||||||
|
|
||||||
if (host) {
|
SwapSlashColon(ePath);
|
||||||
// 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;
|
|
||||||
|
|
||||||
PascalStringCopy(volName, host);
|
// Escape the path with the directory mask
|
||||||
volName[++volName[0]] = ':';
|
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||||
if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr)
|
if (NS_SUCCEEDED(rv)) {
|
||||||
path += host;
|
|
||||||
}
|
if (escPath[escPath.Length() - 1] != '/') {
|
||||||
if (directory) {
|
|
||||||
if (!NS_EscapeURLPart(directory.get(), directory.Length(), esc_Directory, path))
|
|
||||||
path += directory;
|
|
||||||
SwapSlashColon((char *) path.get());
|
|
||||||
}
|
|
||||||
if (fileBaseName) {
|
|
||||||
if (!NS_EscapeURLPart(fileBaseName.get(), fileBaseName.Length(), esc_FileBaseName, path))
|
|
||||||
path += fileBaseName;
|
|
||||||
}
|
|
||||||
if (fileExtension) {
|
|
||||||
path += '.';
|
|
||||||
if (!NS_EscapeURLPart(fileExtension.get(), fileExtension.Length(), esc_FileExtension, path))
|
|
||||||
path += fileExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_UnescapeURL((char *) path.get());
|
|
||||||
|
|
||||||
// wack off leading :'s
|
PRBool dir;
|
||||||
if (path.CharAt(0) == ':')
|
rv = aFile->IsDirectory(&dir);
|
||||||
path.Cut(0, 1);
|
|
||||||
|
if (NS_FAILED(rv))
|
||||||
return localFile->InitWithPath(path.get());
|
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
|
||||||
|
|
||||||
|
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 nsIOService::InitFileFromURLSpec(nsIFile* aFile, const char * aURL)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG(aURL);
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||||
|
|
||||||
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile, &rv);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Only nsILocalFile supported right now");
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = ParseFileURL(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;
|
||||||
|
|
||||||
|
PascalStringCopy(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 = localFile->InitWithPath(path.get());
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче