зеркало из 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.
|
||||
*
|
||||
* 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
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -37,7 +35,6 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Mac-specific local file url parsing */
|
||||
#include "nsIOService.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
@ -65,47 +62,47 @@ static void PascalStringCopy(Str255 dst, const char *src)
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, char **aURL)
|
||||
NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
nsXPIDLCString ePath;
|
||||
|
||||
rv = aFile->GetPath(getter_Copies(ePath));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
SwapSlashColon((char *) ePath.get());
|
||||
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "file://");
|
||||
|
||||
rv = aFile->GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
SwapSlashColon(ePath);
|
||||
|
||||
// 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);
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// 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) {
|
||||
|
||||
if (NS_SUCCEEDED(rv) && dir)
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
}
|
||||
|
||||
escPath.Insert("file:///", 0);
|
||||
*aURL = ToNewCString(escPath);
|
||||
return *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::InitFileFromURLSpec(nsIFile *aFile, const char *aURL)
|
||||
NS_IMETHODIMP nsIOService::InitFileFromURLSpec(nsIFile* aFile, const char * aURL)
|
||||
{
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
@ -113,20 +110,18 @@ nsIOService::InitFileFromURLSpec(nsIFile *aFile, const char *aURL)
|
|||
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;
|
||||
}
|
||||
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));
|
||||
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) {
|
||||
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;
|
||||
|
@ -137,26 +132,32 @@ nsIOService::InitFileFromURLSpec(nsIFile *aFile, const char *aURL)
|
|||
if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr)
|
||||
path += host;
|
||||
}
|
||||
if (directory) {
|
||||
if (!NS_EscapeURLPart(directory.get(), directory.Length(), esc_Directory, path))
|
||||
path += directory;
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
SwapSlashColon((char*)path.get());
|
||||
}
|
||||
if (fileBaseName) {
|
||||
if (!NS_EscapeURLPart(fileBaseName.get(), fileBaseName.Length(), esc_FileBaseName, path))
|
||||
path += fileBaseName;
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension) {
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
if (!NS_EscapeURLPart(fileExtension.get(), fileExtension.Length(), esc_FileExtension, path))
|
||||
path += fileExtension;
|
||||
path += component;
|
||||
}
|
||||
|
||||
NS_UnescapeURL((char *) path.get());
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
// wack off leading :'s
|
||||
if (path.CharAt(0) == ':')
|
||||
path.Cut(0, 1);
|
||||
|
||||
return localFile->InitWithPath(path.get());
|
||||
rv = localFile->InitWithPath(path.get());
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче