зеркало из https://github.com/mozilla/gecko-dev.git
fixes bug 166792 "move nsIIOService::GetURLSpecFromFile, etc. to
nsIFileProtocolHandler" r=dougt sr=alecf
This commit is contained in:
Родитель
4f321562af
Коммит
d47b2f5e65
|
@ -930,6 +930,7 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, ahtmlDocum
|
|||
// assuming we have information needed (like prior saved location)
|
||||
try {
|
||||
var ioService = GetIOService();
|
||||
var fileHandler = GetFileProtocolHandler();
|
||||
|
||||
var isLocalFile = true;
|
||||
try {
|
||||
|
@ -941,7 +942,7 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, ahtmlDocum
|
|||
var parentLocation = null;
|
||||
if (isLocalFile)
|
||||
{
|
||||
var fileLocation = ioService.getFileFromURLSpec(aDocumentURLString); // this asserts if url is not local
|
||||
var fileLocation = fileHandler.getFileFromURLSpec(aDocumentURLString); // this asserts if url is not local
|
||||
parentLocation = fileLocation.parent;
|
||||
}
|
||||
if (parentLocation)
|
||||
|
@ -964,7 +965,7 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, ahtmlDocum
|
|||
if (dialogResult.filepickerClick != nsIFilePicker.returnCancel)
|
||||
{
|
||||
// reset urlstring to new save location
|
||||
dialogResult.resultingURIString = ioService.getURLSpecFromFile(fp.file);
|
||||
dialogResult.resultingURIString = fileHandler.getURLSpecFromFile(fp.file);
|
||||
dialogResult.resultingLocalFile = fp.file;
|
||||
SaveFilePickerDirectory(fp, aEditorType);
|
||||
}
|
||||
|
@ -1757,8 +1758,8 @@ function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
|
|||
|
||||
if (docURI.schemeIs("file"))
|
||||
{
|
||||
ioService = GetIOService();
|
||||
tempLocalFile = ioService.getFileFromURLSpec(urlstring).QueryInterface(Components.interfaces.nsILocalFile);
|
||||
var fileHandler = GetFileProtocolHandler();
|
||||
tempLocalFile = fileHandler.getFileFromURLSpec(urlstring).QueryInterface(Components.interfaces.nsILocalFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2433,8 +2434,8 @@ var nsValidateCommand =
|
|||
// See if it's a file:
|
||||
var ifile;
|
||||
try {
|
||||
var ioService = GetIOService();
|
||||
ifile = ioService.getFileFromURLSpec(URL2Validate);
|
||||
var fileHandler = GetFileProtocolHandler();
|
||||
ifile = fileHandler.getFileFromURLSpec(URL2Validate);
|
||||
// nsIFile throws an exception if it's not a file url
|
||||
} catch (e) { ifile = null; }
|
||||
if (ifile)
|
||||
|
|
|
@ -305,6 +305,13 @@ function GetIOService()
|
|||
return gIOService;
|
||||
}
|
||||
|
||||
function GetFileProtocolHandler()
|
||||
{
|
||||
var ios = GetIOService();
|
||||
var handler = ios.getProtocolHandler("file");
|
||||
return handler.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
}
|
||||
|
||||
function GetPrefsService()
|
||||
{
|
||||
if (gPrefsService)
|
||||
|
|
|
@ -538,8 +538,8 @@ function GetLocalFileURL(filterType)
|
|||
}
|
||||
SaveFilePickerDirectory(fp, fileType);
|
||||
|
||||
var ioService = GetIOService();
|
||||
return fp.file ? ioService.getURLSpecFromFile(fp.file) : null;
|
||||
var fileHandler = GetFileProtocolHandler();
|
||||
return fp.file ? fileHandler.getURLSpecFromFile(fp.file) : null;
|
||||
}
|
||||
|
||||
function GetMetaElement(name)
|
||||
|
|
|
@ -550,7 +550,8 @@ nsHelperAppDialog.prototype = {
|
|||
// Get the data source; load it synchronously if it must be
|
||||
// initialized.
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
var fileurl = ioService.getURLSpecFromFile(file);
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
var fileurl = fileHandler.getURLSpecFromFile(file);
|
||||
|
||||
var ds = rdf.GetDataSourceBlocking( fileurl );
|
||||
|
||||
|
|
|
@ -175,10 +175,10 @@ InspectorApp.prototype =
|
|||
var file = FilePickerUtils.pickFile("Find Search File", path, ["filterXML"], "Open");
|
||||
if (file) {
|
||||
var ioService = XPCU.getService("@mozilla.org/network/io-service;1","nsIIOService");
|
||||
var fileHandler = XPCU.QI(ioService.getProtocolHandler("file"), "nsIFileProtocolHandler");
|
||||
|
||||
var url = fileHandler.getURLSpecFromFile(file);
|
||||
|
||||
var url = ioService.getURLSpecFromFile(file);
|
||||
// XX temporary until 56354 is fixed
|
||||
url = url.replace("file://", "file:///");
|
||||
this.startSearchModule(url);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -61,7 +61,9 @@ var DiskSearch =
|
|||
for (var i = 0; i < aExtList.length; i++) {
|
||||
extHash[aExtList[i]] = true;
|
||||
}
|
||||
this.ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
this.fileHandler = ios.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
|
||||
// recursively build the list of results
|
||||
var results = [];
|
||||
|
@ -81,7 +83,7 @@ var DiskSearch =
|
|||
ext = this.getExtension(entry.leafName);
|
||||
if (ext) {
|
||||
if (aExtHash[ext])
|
||||
aResults.push(this.ioService.getURLSpecFromFile(entry));
|
||||
aResults.push(this.fileHandler.getURLSpecFromFile(entry));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -145,8 +145,9 @@ SidebarPrefs.prototype =
|
|||
return null;
|
||||
|
||||
var ioService = XPCU.getService("@mozilla.org/network/io-service;1", "nsIIOService");
|
||||
var fileHandler = XPCU.QI(ioService.getProtocolHandler("file"), "nsIFileProtocolHandler");
|
||||
|
||||
return ioService.getURLSpecFromFile(file);
|
||||
return fileHandler.getURLSpecFromFile(file);
|
||||
|
||||
} catch (ex) {
|
||||
return null;
|
||||
|
|
|
@ -518,8 +518,9 @@ inSearchModule.prototype =
|
|||
var file = XPCU.QI(file, "nsIFile");
|
||||
|
||||
var ioService = XPCU.getService("@mozilla.org/network/io-service;1", "nsIIOService");
|
||||
var fileHandler = XPCU.QI(ioService.getProtocolHandler("file"), "nsIFileProtocolHandler");
|
||||
|
||||
this.mDialogURL = ioService.getURLSpecFromFile(basefile);
|
||||
this.mDialogURL = fileHandler.getURLSpecFromFile(basefile);
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
|
@ -496,6 +496,7 @@ function getURLSpecFromFile (file)
|
|||
|
||||
const nsIIOService = Components.interfaces.nsIIOService;
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
const nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
|
||||
|
||||
if (typeof file == "string")
|
||||
{
|
||||
|
@ -506,7 +507,9 @@ function getURLSpecFromFile (file)
|
|||
}
|
||||
|
||||
var service = Components.classes[IOS_CTRID].getService(nsIIOService);
|
||||
return service.getURLSpecFromFile(file);
|
||||
var fileHandler = service.getProtocolHandler("file")
|
||||
.QueryInterface(nsIFileProtocolHandler);
|
||||
return fileHandler.getURLSpecFromFile(file);
|
||||
}
|
||||
|
||||
function getCommonPfx (list)
|
||||
|
|
|
@ -2677,7 +2677,9 @@ var attachmentBucketObserver = {
|
|||
{
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
rawData = ioService.getURLSpecFromFile(rawData);
|
||||
var fileHandler = ioService.getProtocolHandler("file")
|
||||
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
rawData = fileHandler.getURLSpecFromFile(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@ nsJARURI::SetSpec(const nsACString &aSpec)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString scheme;
|
||||
rv = ::ExtractURLScheme(aSpec, nsnull, nsnull, &scheme);
|
||||
rv = net_ExtractURLScheme(aSpec, nsnull, nsnull, &scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (strcmp("jar", scheme.get()) != 0)
|
||||
|
@ -127,9 +127,9 @@ nsJARURI::SetSpec(const nsACString &aSpec)
|
|||
while (*delim_end == '/')
|
||||
++delim_end;
|
||||
|
||||
rv = ::ResolveRelativePath(Substring(delim_end, end),
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
rv = net_ResolveRelativePath(Substring(delim_end, end),
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ nsJARURI::Resolve(const nsACString &relativePath, nsACString &result)
|
|||
nsresult rv;
|
||||
|
||||
nsCAutoString scheme;
|
||||
rv = ::ExtractURLScheme(relativePath, nsnull, nsnull, &scheme);
|
||||
rv = net_ExtractURLScheme(relativePath, nsnull, nsnull, &scheme);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// then aSpec is absolute
|
||||
result = relativePath;
|
||||
|
@ -344,8 +344,8 @@ nsJARURI::Resolve(const nsACString &relativePath, nsACString &result)
|
|||
path = "";
|
||||
|
||||
nsCAutoString resolvedEntry;
|
||||
rv = ::ResolveRelativePath(relativePath, path,
|
||||
resolvedEntry);
|
||||
rv = net_ResolveRelativePath(relativePath, path,
|
||||
resolvedEntry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return FormatSpec(resolvedEntry, result);
|
||||
|
@ -385,9 +385,9 @@ nsJARURI::SetJAREntry(const nsACString &entryPath)
|
|||
{
|
||||
mJAREntry.Truncate();
|
||||
|
||||
return ::ResolveRelativePath(entryPath,
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
return net_ResolveRelativePath(entryPath,
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -56,10 +56,6 @@ interface nsIFile;
|
|||
[scriptable, uuid(bddeda3f-9020-4d12-8c70-984ee9f7935e)]
|
||||
interface nsIIOService : nsISupports
|
||||
{
|
||||
/*************************************************************************
|
||||
* Protocol handler utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a protocol handler for a given URI scheme.
|
||||
*
|
||||
|
@ -133,44 +129,18 @@ interface nsIIOService : nsISupports
|
|||
*/
|
||||
boolean allowPort(in long aPort, in string aScheme);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* URL parsing utilities
|
||||
*
|
||||
* The set of methods provided here is intentionally limited. Most of
|
||||
* Necko's URL parsing functionality is provided via nsIURI. This is
|
||||
* done to ensure a common point of access to URL parsing, which is
|
||||
* protocol dependent. Do not try to parse a random URL string as the
|
||||
* result will likely differ (perhaps only in some subtle way) from the
|
||||
* value of the corresponding nsIURI attribute. Violating this rule
|
||||
* may make your code vulnerable to various kinds of security exploits.
|
||||
* DON'T RISK IT! --darin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility to extract the scheme from a URL string, consistently and
|
||||
* according to spec (see RFC 2396).
|
||||
*
|
||||
* NOTE: Most URL parsing is done via nsIURI, and in fact the scheme
|
||||
* can also be extracted from a URL string via nsIURI. This method
|
||||
* is provided purely as an optimization.
|
||||
*
|
||||
* @param aSpec the URL string to parse
|
||||
* @return URL scheme
|
||||
*
|
||||
* @throws NS_ERROR_MALFORMED_URI if URL string is not of the right form.
|
||||
*/
|
||||
ACString extractScheme(in AUTF8String urlString);
|
||||
|
||||
/**
|
||||
* Converts the nsIFile to the corresponding URL string. NOTE: under
|
||||
* some platforms this is a lossy conversion (e.g., Mac Carbon build).
|
||||
* If the nsIFile is a local file, then the result will be a file://
|
||||
* URL string.
|
||||
*
|
||||
* The resulting string may contain URL-escaped characters.
|
||||
*/
|
||||
AUTF8String getURLSpecFromFile(in nsIFile file);
|
||||
|
||||
/**
|
||||
* Converts the URL string into the corresponding nsIFile if possible.
|
||||
* A local file will be created if the URL string begins with file://.
|
||||
*/
|
||||
nsIFile getFileFromURLSpec(in AUTF8String url);
|
||||
};
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#include "nsIStreamIO.h"
|
||||
#include "nsIPipe.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIFileProtocolHandler.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIFileStreams.h"
|
||||
|
@ -763,31 +764,45 @@ NS_NewProxyInfo(const char* type, const char* host, PRInt32 port, nsIProxyInfo*
|
|||
}
|
||||
|
||||
inline nsresult
|
||||
NS_GetFileFromURLSpec(const nsACString &inURL, nsIFile **result,
|
||||
nsIIOService *ioService=nsnull)
|
||||
NS_GetFileProtocolHandler(nsIFileProtocolHandler **result,
|
||||
nsIIOService *ioService=nsnull)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIIOService> serv;
|
||||
if (ioService == nsnull) {
|
||||
nsresult rv;
|
||||
serv = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ioService = serv.get();
|
||||
}
|
||||
return ioService->GetFileFromURLSpec(inURL, result);
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> handler;
|
||||
rv = ioService->GetProtocolHandler("file", getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return CallQueryInterface(handler, result);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_GetFileFromURLSpec(const nsACString &inURL, nsIFile **result,
|
||||
nsIIOService *ioService=nsnull)
|
||||
{
|
||||
nsCOMPtr<nsIFileProtocolHandler> fileHandler;
|
||||
nsresult rv = NS_GetFileProtocolHandler(getter_AddRefs(fileHandler), ioService);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return fileHandler->GetFileFromURLSpec(inURL, result);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_GetURLSpecFromFile(nsIFile* aFile, nsACString &aUrl,
|
||||
nsIIOService *ioService=nsnull)
|
||||
{
|
||||
nsCOMPtr<nsIIOService> serv;
|
||||
if (ioService == nsnull) {
|
||||
nsresult rv;
|
||||
serv = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ioService = serv.get();
|
||||
}
|
||||
return ioService->GetURLSpecFromFile(aFile, aUrl);
|
||||
nsCOMPtr<nsIFileProtocolHandler> fileHandler;
|
||||
nsresult rv = NS_GetFileProtocolHandler(getter_AddRefs(fileHandler), ioService);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return fileHandler->GetURLSpecFromFile(aFile, aUrl);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
|
|
|
@ -74,14 +74,14 @@ CPPSRCS = \
|
|||
$(NULL)
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsIOServiceOS2.cpp
|
||||
CPPSRCS += nsURLHelperOS2.cpp
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
CPPSRCS += nsIOServiceWin.cpp
|
||||
CPPSRCS += nsURLHelperWin.cpp
|
||||
CPPSRCS += nsNativeConnectionHelper.cpp
|
||||
CPPSRCS += nsAutodialWin.cpp
|
||||
else
|
||||
CPPSRCS += nsIOServiceUnix.cpp
|
||||
CPPSRCS += nsURLHelperUnix.cpp
|
||||
endif
|
||||
endif
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ static PRLogModuleInfo* gLog;
|
|||
#include "nsCollationCID.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
@ -216,7 +217,7 @@ nsDirectoryIndexStream::Init(nsIFile* aDir)
|
|||
|
||||
mBuf.Append("300: ");
|
||||
nsCAutoString url;
|
||||
rv = NS_GetURLSpecFromFile(mDir, url);
|
||||
rv = net_GetURLSpecFromFile(mDir, url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mBuf.Append(url);
|
||||
mBuf.Append('\n');
|
||||
|
|
|
@ -58,7 +58,6 @@
|
|||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsIPrefLocalizedString.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIProxiedProtocolHandler.h"
|
||||
|
@ -267,13 +266,6 @@ nsIOService::Init()
|
|||
|
||||
nsIOService::~nsIOService()
|
||||
{
|
||||
// mURLParsers is a voidarray; we must release ourselves
|
||||
for (PRInt32 i = 0; i < mURLParsers.Count(); i++)
|
||||
{
|
||||
nsISupports *temp;
|
||||
temp = NS_STATIC_CAST(nsISupports*, mURLParsers[i]);
|
||||
NS_IF_RELEASE(temp);
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
|
@ -324,7 +316,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsIOService,
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsIOService::CacheProtocolHandler(const char *scheme, nsIProtocolHandler *handler)
|
||||
{
|
||||
for (unsigned int i=0; i<NS_N(gScheme); i++)
|
||||
|
@ -351,7 +343,7 @@ nsIOService::CacheProtocolHandler(const char *scheme, nsIProtocolHandler *handle
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsIOService::GetCachedProtocolHandler(const char *scheme, nsIProtocolHandler **result, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
PRUint32 len = end - start - 1;
|
||||
|
@ -378,50 +370,6 @@ nsIOService::GetCachedProtocolHandler(const char *scheme, nsIProtocolHandler **r
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::CacheURLParser(const char *scheme, nsIURLParser *parser)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(scheme);
|
||||
NS_ENSURE_ARG_POINTER(parser);
|
||||
for (PRInt32 i=0; i< (PRInt32) NS_N(gScheme); i++)
|
||||
{
|
||||
if (!nsCRT::strcasecmp(scheme, gScheme[i]))
|
||||
{
|
||||
// we're going to store this in an nsVoidArray, which extends,
|
||||
// unlike nsSupportsArray, which doesn't. We must release
|
||||
// them on delete!
|
||||
// grab this before overwriting it
|
||||
nsIURLParser *old_parser;
|
||||
old_parser = NS_STATIC_CAST(nsIURLParser*,mURLParsers.SafeElementAt(i));
|
||||
|
||||
NS_ADDREF(parser);
|
||||
mURLParsers.ReplaceElementAt(parser, i);
|
||||
// release any old entry, if any, AFTER adding new entry in
|
||||
// case they were the same (paranoia)
|
||||
NS_IF_RELEASE(old_parser);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetCachedURLParser(const char *scheme, nsIURLParser **result)
|
||||
{
|
||||
PRInt32 count = mURLParsers.Count();
|
||||
for (PRInt32 i=0; i < count; i++)
|
||||
{
|
||||
if (!nsCRT::strcasecmp(scheme, gScheme[i]))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsIURLParser*, mURLParsers[i]);
|
||||
NS_IF_ADDREF(*result);
|
||||
return *result ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
|
||||
{
|
||||
|
@ -473,238 +421,9 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
|
|||
NS_IMETHODIMP
|
||||
nsIOService::ExtractScheme(const nsACString &inURI, nsACString &scheme)
|
||||
{
|
||||
return ExtractURLScheme(inURI, nsnull, nsnull, &scheme);
|
||||
return net_ExtractURLScheme(inURI, nsnull, nsnull, &scheme);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsIOService::GetParserForScheme(const char *scheme, nsIURLParser **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = GetCachedURLParser(scheme, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK;
|
||||
|
||||
|
||||
if (!scheme) {
|
||||
if (!mDefaultURLParser) {
|
||||
rv = nsServiceManager::GetService(kStdURLParserCID,
|
||||
NS_GET_IID(nsIURLParser),
|
||||
getter_AddRefs(mDefaultURLParser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*_retval = mDefaultURLParser;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> parserList;
|
||||
rv = catmgr->EnumerateCategory(NS_IURLPARSER_KEY, getter_AddRefs(parserList));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupportsCString> entry;
|
||||
|
||||
// Walk the list of parsers...
|
||||
while (1) {
|
||||
rv = parserList->GetNext(getter_AddRefs(entry));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
// get the entry string
|
||||
nsCAutoString entryString;
|
||||
rv = entry->GetData(entryString);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
if (entryString.Equals(scheme)) {
|
||||
nsXPIDLCString contractID;
|
||||
rv = catmgr->GetCategoryEntry(NS_IURLPARSER_KEY, entryString.get(), getter_Copies(contractID));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
rv = nsServiceManager::GetService(contractID, NS_GET_IID(nsIURLParser), (nsISupports **)_retval);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (*_retval)
|
||||
CacheURLParser(scheme, *_retval);
|
||||
return *_retval ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// no registered url parser. Just use the default...
|
||||
if (!mDefaultURLParser) {
|
||||
rv = nsServiceManager::GetService(kStdURLParserCID,
|
||||
NS_GET_IID(nsIURLParser),
|
||||
getter_AddRefs(mDefaultURLParser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*_retval = mDefaultURLParser;
|
||||
NS_ADDREF(*_retval);
|
||||
CacheURLParser(scheme, *_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static inline void
|
||||
ExtractUrlPart_Helper(const nsACString &src, PRUint32 pos, PRInt32 len, nsACString &result)
|
||||
{
|
||||
if (len >= 0)
|
||||
result = Substring(src, pos, len);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::ExtractUrlPart(const nsACString &urlString, PRInt16 flag, nsACString &urlPart)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString scheme;
|
||||
|
||||
rv = ExtractURLScheme(urlString, nsnull, nsnull, &scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (flag == url_Scheme) {
|
||||
urlPart = scheme;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
urlPart.Truncate();
|
||||
|
||||
nsCOMPtr<nsIURLParser> parser;
|
||||
rv = GetParserForScheme(scheme.get(), getter_AddRefs(parser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// we work only with flat strings around these parts
|
||||
const nsPromiseFlatCString &flat = PromiseFlatCString(urlString);
|
||||
const char *url = flat.get();
|
||||
|
||||
PRUint32 authPos, pathPos;
|
||||
PRInt32 authLen, pathLen;
|
||||
|
||||
rv = parser->ParseURL(url, -1,
|
||||
nsnull, nsnull,
|
||||
&authPos, &authLen,
|
||||
&pathPos, &pathLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (flag == url_Path)
|
||||
ExtractUrlPart_Helper(urlString, pathPos, pathLen, urlPart);
|
||||
else if (flag < url_Directory || flag & url_Port) {
|
||||
PRUint32 usernamePos, passwordPos, hostnamePos;
|
||||
PRInt32 usernameLen, passwordLen, hostnameLen;
|
||||
PRInt32 port;
|
||||
|
||||
if (authLen < 0)
|
||||
return NS_OK;
|
||||
|
||||
rv = parser->ParseAuthority(url + authPos, authLen,
|
||||
&usernamePos, &usernameLen,
|
||||
&passwordPos, &passwordLen,
|
||||
&hostnamePos, &hostnameLen,
|
||||
&port);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
usernamePos += authPos;
|
||||
passwordPos += authPos;
|
||||
hostnamePos += authPos;
|
||||
|
||||
switch (flag) {
|
||||
case url_Username:
|
||||
ExtractUrlPart_Helper(urlString, usernamePos, usernameLen, urlPart);
|
||||
break;
|
||||
case url_Password:
|
||||
ExtractUrlPart_Helper(urlString, passwordPos, passwordLen, urlPart);
|
||||
break;
|
||||
case url_Host:
|
||||
ExtractUrlPart_Helper(urlString, hostnamePos, hostnameLen, urlPart);
|
||||
break;
|
||||
case url_Port:
|
||||
if (port != -1) {
|
||||
PRInt32 pos = hostnamePos + hostnameLen + 1;
|
||||
ExtractUrlPart_Helper(urlString, pos, pathPos - pos, urlPart);
|
||||
}
|
||||
break;
|
||||
case url_Host | url_Port:
|
||||
if (port != -1 && hostnameLen > 0) {
|
||||
urlPart = Substring(urlString, hostnamePos, hostnameLen)
|
||||
+ NS_LITERAL_CSTRING(":")
|
||||
+ nsPrintfCString("%d", port);
|
||||
}
|
||||
else
|
||||
ExtractUrlPart_Helper(urlString, hostnamePos, hostnameLen, urlPart);
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("unexpected flag");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRUint32 filepathPos, paramPos, queryPos, refPos;
|
||||
PRInt32 filepathLen, paramLen, queryLen, refLen;
|
||||
|
||||
if (pathLen < 0)
|
||||
return NS_OK;
|
||||
|
||||
rv = parser->ParsePath(url + pathPos, pathLen,
|
||||
&filepathPos, &filepathLen,
|
||||
¶mPos, ¶mLen,
|
||||
&queryPos, &queryLen,
|
||||
&refPos, &refLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
filepathPos += pathPos;
|
||||
paramPos += pathPos;
|
||||
queryPos += pathPos;
|
||||
refPos += pathPos;
|
||||
|
||||
if (flag < url_Param) {
|
||||
PRUint32 directoryPos, basenamePos, extensionPos;
|
||||
PRInt32 directoryLen, basenameLen, extensionLen;
|
||||
|
||||
rv = parser->ParseFilePath(url + filepathPos, filepathLen,
|
||||
&directoryPos, &directoryLen,
|
||||
&basenamePos, &basenameLen,
|
||||
&extensionPos, &extensionLen);
|
||||
|
||||
directoryPos += filepathPos;
|
||||
basenamePos += filepathPos;
|
||||
extensionPos += filepathPos;
|
||||
|
||||
switch (flag) {
|
||||
case url_Directory:
|
||||
ExtractUrlPart_Helper(urlString, directoryPos, directoryLen, urlPart);
|
||||
break;
|
||||
case url_FileBaseName:
|
||||
ExtractUrlPart_Helper(urlString, basenamePos, basenameLen, urlPart);
|
||||
break;
|
||||
case url_FileExtension:
|
||||
ExtractUrlPart_Helper(urlString, extensionPos, extensionLen, urlPart);
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("unexpected flag");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (flag) {
|
||||
case url_Param:
|
||||
ExtractUrlPart_Helper(urlString, paramPos, paramLen, urlPart);
|
||||
break;
|
||||
case url_Query:
|
||||
ExtractUrlPart_Helper(urlString, queryPos, queryLen, urlPart);
|
||||
break;
|
||||
case url_Ref:
|
||||
ExtractUrlPart_Helper(urlString, refPos, refLen, urlPart);
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("unexpected flag");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetProtocolFlags(const char* scheme, PRUint32 *flags)
|
||||
{
|
||||
|
@ -716,7 +435,6 @@ nsIOService::GetProtocolFlags(const char* scheme, PRUint32 *flags)
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsIOService::NewURI(const nsACString &aSpec, const char *aCharset, nsIURI *aBaseURI, nsIURI **result)
|
||||
{
|
||||
|
@ -1005,71 +723,3 @@ nsIOService::Observe(nsISupports *subject,
|
|||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsIOService::ParseFileURL(const nsACString &inURL,
|
||||
nsACString &outDirectory,
|
||||
nsACString &outFileBaseName,
|
||||
nsACString &outFileExtension)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
outDirectory.Truncate();
|
||||
outFileBaseName.Truncate();
|
||||
outFileExtension.Truncate();
|
||||
|
||||
nsCAutoString scheme;
|
||||
rv = ExtractScheme(inURL, scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (strcmp(scheme.get(), "file") != 0) {
|
||||
NS_ERROR("must be a file:// url");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
const nsPromiseFlatCString &flatURL = PromiseFlatCString(inURL);
|
||||
const char *url = flatURL.get();
|
||||
|
||||
nsCOMPtr<nsIURLParser> parser;
|
||||
rv = GetParserForScheme(scheme.get(), getter_AddRefs(parser));
|
||||
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(url, -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(url + 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(url + filepathPos, filepathLen,
|
||||
&directoryPos, &directoryLen,
|
||||
&basenamePos, &basenameLen,
|
||||
&extensionPos, &extensionLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (directoryLen > 0)
|
||||
outDirectory = Substring(inURL, filepathPos + directoryPos, directoryLen);
|
||||
if (basenameLen > 0)
|
||||
outFileBaseName = Substring(inURL, filepathPos + basenamePos, basenameLen);
|
||||
if (extensionLen > 0)
|
||||
outFileExtension = Substring(inURL, filepathPos + extensionPos, extensionLen);
|
||||
// since we are using a no-auth url parser, there will never be a host
|
||||
// XXX not strictly true... file://localhost/foo/bar.html is a valid URL
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,45 +87,30 @@ public:
|
|||
nsIURI* *result, nsIProtocolHandler* *hdlrResult);
|
||||
|
||||
protected:
|
||||
NS_METHOD GetCachedProtocolHandler(const char *scheme,
|
||||
nsresult GetCachedProtocolHandler(const char *scheme,
|
||||
nsIProtocolHandler* *hdlrResult,
|
||||
PRUint32 start=0,
|
||||
PRUint32 end=0);
|
||||
NS_METHOD CacheProtocolHandler(const char *scheme,
|
||||
nsresult CacheProtocolHandler(const char *scheme,
|
||||
nsIProtocolHandler* hdlr);
|
||||
|
||||
NS_METHOD GetCachedURLParser(const char *scheme,
|
||||
nsIURLParser* *hdlrResult);
|
||||
|
||||
NS_METHOD CacheURLParser(const char *scheme,
|
||||
nsIURLParser* hdlr);
|
||||
|
||||
NS_METHOD GetParserForScheme(const char *scheme, nsIURLParser **);
|
||||
|
||||
// Prefs wrangling
|
||||
void PrefsChanged(nsIPrefBranch *prefs, const char *pref = nsnull);
|
||||
void GetPrefBranch(nsIPrefBranch **);
|
||||
void ParsePortList(nsIPrefBranch *prefBranch, const char *pref, PRBool remove);
|
||||
|
||||
nsresult ParseFileURL(const nsACString &inURL,
|
||||
nsACString &outDirectory,
|
||||
nsACString &outFileBaseName,
|
||||
nsACString &outFileExtension);
|
||||
protected:
|
||||
PRPackedBool mOffline;
|
||||
PRPackedBool mOfflineForProfileChange;
|
||||
PRPackedBool mOffline;
|
||||
PRPackedBool mOfflineForProfileChange;
|
||||
nsCOMPtr<nsISocketTransportService> mSocketTransportService;
|
||||
nsCOMPtr<nsIFileTransportService> mFileTransportService;
|
||||
nsCOMPtr<nsIDNSService> mDNSService;
|
||||
nsCOMPtr<nsIProtocolProxyService> mProxyService;
|
||||
nsCOMPtr<nsIEventQueueService> mEventQueueService;
|
||||
nsCOMPtr<nsIEventQueueService> mEventQueueService;
|
||||
|
||||
// Cached protocol handlers
|
||||
nsWeakPtr mWeakHandler[NS_N(gScheme)];
|
||||
nsWeakPtr mWeakHandler[NS_N(gScheme)];
|
||||
|
||||
// Cached url handlers
|
||||
nsCOMPtr<nsIURLParser> mDefaultURLParser;
|
||||
nsAutoVoidArray mURLParsers;
|
||||
nsVoidArray mRestrictedPortList;
|
||||
|
||||
public:
|
||||
|
|
|
@ -57,10 +57,6 @@
|
|||
static NS_DEFINE_CID(kThisImplCID, NS_THIS_STANDARDURL_IMPL_CID);
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
nsIIOService *nsStandardURL::gIOService = nsnull;
|
||||
nsIURLParser *nsStandardURL::gNoAuthParser = nsnull;
|
||||
nsIURLParser *nsStandardURL::gAuthParser = nsnull;
|
||||
nsIURLParser *nsStandardURL::gStdParser = nsnull;
|
||||
nsIIDNService *nsStandardURL::gIDNService = nsnull;
|
||||
nsICharsetConverterManager2 *nsStandardURL::gCharsetMgr = nsnull;
|
||||
PRBool nsStandardURL::gInitialized = PR_FALSE;
|
||||
|
@ -329,7 +325,7 @@ nsStandardURL::nsStandardURL()
|
|||
}
|
||||
|
||||
// default parser in case nsIStandardURL::Init is never called
|
||||
mParser = gStdParser;
|
||||
mParser = net_GetStdURLParser();
|
||||
}
|
||||
|
||||
nsStandardURL::~nsStandardURL()
|
||||
|
@ -342,36 +338,6 @@ nsStandardURL::~nsStandardURL()
|
|||
void
|
||||
nsStandardURL::InitGlobalObjects()
|
||||
{
|
||||
nsCOMPtr<nsIURLParser> parser;
|
||||
|
||||
parser = do_GetService(NS_NOAUTHURLPARSER_CONTRACTID);
|
||||
NS_ASSERTION(parser, "failed getting 'noauth' url parser");
|
||||
if (parser) {
|
||||
gNoAuthParser = parser.get();
|
||||
NS_ADDREF(gNoAuthParser);
|
||||
}
|
||||
|
||||
parser = do_GetService(NS_AUTHURLPARSER_CONTRACTID);
|
||||
NS_ASSERTION(parser, "failed getting 'auth' url parser");
|
||||
if (parser) {
|
||||
gAuthParser = parser.get();
|
||||
NS_ADDREF(gAuthParser);
|
||||
}
|
||||
|
||||
parser = do_GetService(NS_STDURLPARSER_CONTRACTID);
|
||||
NS_ASSERTION(parser, "failed getting 'std' url parser");
|
||||
if (parser) {
|
||||
gStdParser = parser.get();
|
||||
NS_ADDREF(gStdParser);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIIOService> serv(do_GetIOService());
|
||||
NS_ASSERTION(serv, "failed getting IO service");
|
||||
if (serv) {
|
||||
gIOService = serv.get();
|
||||
NS_ADDREF(gIOService);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefService( do_GetService(NS_PREFSERVICE_CONTRACTID) );
|
||||
if (prefService) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
|
@ -390,10 +356,6 @@ nsStandardURL::InitGlobalObjects()
|
|||
void
|
||||
nsStandardURL::ShutdownGlobalObjects()
|
||||
{
|
||||
NS_IF_RELEASE(gIOService);
|
||||
NS_IF_RELEASE(gNoAuthParser);
|
||||
NS_IF_RELEASE(gAuthParser);
|
||||
NS_IF_RELEASE(gStdParser);
|
||||
NS_IF_RELEASE(gIDNService);
|
||||
NS_IF_RELEASE(gCharsetMgr);
|
||||
}
|
||||
|
@ -453,7 +415,7 @@ nsStandardURL::EncodeHost(const char *host, nsCString &result)
|
|||
void
|
||||
nsStandardURL::CoalescePath(char *path)
|
||||
{
|
||||
CoalesceDirsAbs(path);
|
||||
net_CoalesceDirsAbs(path);
|
||||
PRInt32 newLen = strlen(path);
|
||||
if (newLen < mPath.mLen) {
|
||||
PRInt32 diff = newLen - mPath.mLen;
|
||||
|
@ -549,7 +511,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
|||
|
||||
if (mScheme.mLen > 0) {
|
||||
i = AppendSegmentToBuf(buf, i, spec, mScheme);
|
||||
ToLowerCase(buf + mScheme.mPos, mScheme.mLen);
|
||||
net_ToLowerCase(buf + mScheme.mPos, mScheme.mLen);
|
||||
i = AppendToBuf(buf, i, "://", 3);
|
||||
}
|
||||
|
||||
|
@ -567,7 +529,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
|||
}
|
||||
if (mHost.mLen > 0) {
|
||||
i = AppendSegmentToBuf(buf, i, spec, mHost);
|
||||
ToLowerCase(buf + mHost.mPos, mHost.mLen);
|
||||
net_ToLowerCase(buf + mHost.mPos, mHost.mLen);
|
||||
if (mPort != -1 && mPort != mDefaultPort) {
|
||||
nsCAutoString portbuf;
|
||||
portbuf.AppendInt(mPort);
|
||||
|
@ -1087,7 +1049,7 @@ nsStandardURL::SetScheme(const nsACString &input)
|
|||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (!IsValidScheme(scheme)) {
|
||||
if (!net_IsValidScheme(scheme)) {
|
||||
NS_ERROR("the given url scheme contains invalid characters");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
@ -1105,7 +1067,7 @@ nsStandardURL::SetScheme(const nsACString &input)
|
|||
//
|
||||
// XXX the string code unfortunately doesn't provide a ToLowerCase
|
||||
// that operates on a substring.
|
||||
ToLowerCase((char *) mSpec.get(), mScheme.mLen);
|
||||
net_ToLowerCase((char *) mSpec.get(), mScheme.mLen);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1542,7 +1504,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
|||
LOG(("nsStandardURL::Resolve [this=%p spec=%s relpath=%s]\n",
|
||||
this, mSpec.get(), relpath));
|
||||
|
||||
NS_ASSERTION(gNoAuthParser, "no parser: unitialized");
|
||||
NS_ASSERTION(mParser, "no parser: unitialized");
|
||||
|
||||
// NOTE: there is no need for this function to produce normalized
|
||||
// output. normalization will occur when the result is used to
|
||||
|
@ -1562,10 +1524,10 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
|||
// relative urls should never contain a host, so we always want to use
|
||||
// the noauth url parser.
|
||||
// use it to extract a possible scheme
|
||||
rv = gNoAuthParser->ParseURL(relpath, flat.Length(),
|
||||
&scheme.mPos, &scheme.mLen,
|
||||
nsnull, nsnull,
|
||||
nsnull, nsnull);
|
||||
rv = mParser->ParseURL(relpath, flat.Length(),
|
||||
&scheme.mPos, &scheme.mLen,
|
||||
nsnull, nsnull,
|
||||
nsnull, nsnull);
|
||||
|
||||
// if the parser fails (for example because there is no valid scheme)
|
||||
// reset the scheme and assume a relative url
|
||||
|
@ -1638,14 +1600,14 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (resultPath)
|
||||
CoalesceDirsRel(resultPath);
|
||||
net_CoalesceDirsRel(resultPath);
|
||||
else {
|
||||
// locate result path
|
||||
resultPath = PL_strstr(*result, "://");
|
||||
if (resultPath) {
|
||||
resultPath = PL_strchr(resultPath + 3, '/');
|
||||
if (resultPath)
|
||||
CoalesceDirsRel(resultPath);
|
||||
net_CoalesceDirsRel(resultPath);
|
||||
}
|
||||
}
|
||||
// XXX avoid extra copy
|
||||
|
@ -1888,10 +1850,10 @@ nsStandardURL::SetFilePath(const nsACString &input)
|
|||
PRInt32 dirLen, baseLen, extLen;
|
||||
nsresult rv;
|
||||
|
||||
rv = gNoAuthParser->ParseFilePath(filepath, -1,
|
||||
&dirPos, &dirLen,
|
||||
&basePos, &baseLen,
|
||||
&extPos, &extLen);
|
||||
rv = mParser->ParseFilePath(filepath, -1,
|
||||
&dirPos, &dirLen,
|
||||
&basePos, &baseLen,
|
||||
&extPos, &extLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// build up new candidate spec
|
||||
|
@ -2110,9 +2072,9 @@ nsStandardURL::SetFileName(const nsACString &input)
|
|||
URLSegment basename, extension;
|
||||
|
||||
// let the parser locate the basename and extension
|
||||
rv = gNoAuthParser->ParseFileName(filename, -1,
|
||||
&basename.mPos, &basename.mLen,
|
||||
&extension.mPos, &extension.mLen);
|
||||
rv = mParser->ParseFileName(filename, -1,
|
||||
&basename.mPos, &basename.mLen,
|
||||
&extension.mPos, &extension.mLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (basename.mLen < 0) {
|
||||
|
@ -2207,7 +2169,7 @@ nsStandardURL::GetFile(nsIFile **result)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv = gIOService->GetFileFromURLSpec(mSpec, result);
|
||||
nsresult rv = net_GetFileFromURLSpec(mSpec, result);
|
||||
|
||||
// XXX ultimately, we should probably cache this result to speed
|
||||
// up subsequent calls, but past attempts to do so have been
|
||||
|
@ -2240,7 +2202,7 @@ nsStandardURL::SetFile(nsIFile *file)
|
|||
nsresult rv;
|
||||
nsCAutoString url;
|
||||
|
||||
rv = gIOService->GetURLSpecFromFile(file, url);
|
||||
rv = net_GetURLSpecFromFile(file, url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetSpec(url);
|
||||
|
@ -2274,13 +2236,13 @@ nsStandardURL::Init(PRUint32 urlType,
|
|||
|
||||
switch (urlType) {
|
||||
case URLTYPE_STANDARD:
|
||||
mParser = gStdParser;
|
||||
mParser = net_GetStdURLParser();
|
||||
break;
|
||||
case URLTYPE_AUTHORITY:
|
||||
mParser = gAuthParser;
|
||||
mParser = net_GetAuthURLParser();
|
||||
break;
|
||||
case URLTYPE_NO_AUTHORITY:
|
||||
mParser = gNoAuthParser;
|
||||
mParser = net_GetNoAuthURLParser();
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("bad urlType");
|
||||
|
@ -2309,11 +2271,11 @@ nsStandardURL::Init(PRUint32 urlType,
|
|||
if (baseURI) {
|
||||
PRUint32 start, end;
|
||||
// pull out the scheme and where it ends
|
||||
nsresult rv = ExtractURLScheme(spec, &start, &end, nsnull);
|
||||
if (NS_SUCCEEDED(rv) && spec.Length() > end+1) {
|
||||
nsresult rv = net_ExtractURLScheme(spec, &start, &end, nsnull);
|
||||
if (NS_SUCCEEDED(rv) && spec.Length() > end+2) {
|
||||
nsACString::const_iterator slash;
|
||||
spec.BeginReading(slash);
|
||||
slash.advance(end);
|
||||
slash.advance(end+1);
|
||||
// then check if // follows
|
||||
// if it follows, aSpec is really absolute ...
|
||||
// ignore aBaseURI in this case
|
||||
|
@ -2360,13 +2322,13 @@ nsStandardURL::Read(nsIObjectInputStream *stream)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
switch (mURLType) {
|
||||
case URLTYPE_STANDARD:
|
||||
mParser = gStdParser;
|
||||
mParser = net_GetStdURLParser();
|
||||
break;
|
||||
case URLTYPE_AUTHORITY:
|
||||
mParser = gAuthParser;
|
||||
mParser = net_GetAuthURLParser();
|
||||
break;
|
||||
case URLTYPE_NO_AUTHORITY:
|
||||
mParser = gNoAuthParser;
|
||||
mParser = net_GetNoAuthURLParser();
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("bad urlType");
|
||||
|
|
|
@ -240,10 +240,6 @@ private:
|
|||
|
||||
// global objects. don't use COMPtr as its destructor will cause a
|
||||
// coredump if we leak it.
|
||||
static nsIIOService *gIOService;
|
||||
static nsIURLParser *gNoAuthParser;
|
||||
static nsIURLParser *gAuthParser;
|
||||
static nsIURLParser *gStdParser;
|
||||
static nsIIDNService *gIDNService;
|
||||
static nsICharsetConverterManager2 *gCharsetMgr;
|
||||
static PRBool gInitialized;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
|
@ -36,22 +37,178 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsURLHelper.h"
|
||||
#include "prprf.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "netCore.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <windows.h> // ::IsDBCSLeadByte need
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Init/Shutdown
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
static PRBool gInitialized = PR_FALSE;
|
||||
static nsIURLParser *gNoAuthURLParser = nsnull;
|
||||
static nsIURLParser *gAuthURLParser = nsnull;
|
||||
static nsIURLParser *gStdURLParser = nsnull;
|
||||
|
||||
static void
|
||||
InitGlobals()
|
||||
{
|
||||
nsCOMPtr<nsIURLParser> parser;
|
||||
|
||||
parser = do_GetService(NS_NOAUTHURLPARSER_CONTRACTID);
|
||||
NS_ASSERTION(parser, "failed getting 'noauth' url parser");
|
||||
if (parser) {
|
||||
gNoAuthURLParser = parser.get();
|
||||
NS_ADDREF(gNoAuthURLParser);
|
||||
}
|
||||
|
||||
parser = do_GetService(NS_AUTHURLPARSER_CONTRACTID);
|
||||
NS_ASSERTION(parser, "failed getting 'auth' url parser");
|
||||
if (parser) {
|
||||
gAuthURLParser = parser.get();
|
||||
NS_ADDREF(gAuthURLParser);
|
||||
}
|
||||
|
||||
parser = do_GetService(NS_STDURLPARSER_CONTRACTID);
|
||||
NS_ASSERTION(parser, "failed getting 'std' url parser");
|
||||
if (parser) {
|
||||
gStdURLParser = parser.get();
|
||||
NS_ADDREF(gStdURLParser);
|
||||
}
|
||||
|
||||
gInitialized = PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
net_ShutdownURLHelper()
|
||||
{
|
||||
if (gInitialized) {
|
||||
NS_IF_RELEASE(gNoAuthURLParser);
|
||||
NS_IF_RELEASE(gAuthURLParser);
|
||||
NS_IF_RELEASE(gStdURLParser);
|
||||
gInitialized = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// nsIURLParser getters
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
nsIURLParser *
|
||||
net_GetAuthURLParser()
|
||||
{
|
||||
if (!gInitialized)
|
||||
InitGlobals();
|
||||
return gAuthURLParser;
|
||||
}
|
||||
|
||||
nsIURLParser *
|
||||
net_GetNoAuthURLParser()
|
||||
{
|
||||
if (!gInitialized)
|
||||
InitGlobals();
|
||||
return gNoAuthURLParser;
|
||||
}
|
||||
|
||||
nsIURLParser *
|
||||
net_GetStdURLParser()
|
||||
{
|
||||
if (!gInitialized)
|
||||
InitGlobals();
|
||||
return gStdURLParser;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// file:// URL parsing
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
nsresult
|
||||
net_ParseFileURL(const nsACString &inURL,
|
||||
nsACString &outDirectory,
|
||||
nsACString &outFileBaseName,
|
||||
nsACString &outFileExtension)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
outDirectory.Truncate();
|
||||
outFileBaseName.Truncate();
|
||||
outFileExtension.Truncate();
|
||||
|
||||
// XXX optimization: no need to copy scheme
|
||||
PRUint32 schemeBeg, schemeEnd;
|
||||
rv = net_ExtractURLScheme(inURL, &schemeBeg, &schemeEnd, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (Substring(inURL, schemeBeg, schemeBeg + schemeEnd) != NS_LITERAL_CSTRING("file")) {
|
||||
NS_ERROR("must be a file:// url");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
const nsPromiseFlatCString &flatURL = PromiseFlatCString(inURL);
|
||||
const char *url = flatURL.get();
|
||||
|
||||
nsIURLParser *parser = net_GetNoAuthURLParser();
|
||||
NS_ENSURE_TRUE(parser, NS_ERROR_UNEXPECTED);
|
||||
|
||||
PRUint32 pathPos, filepathPos, directoryPos, basenamePos, extensionPos;
|
||||
PRInt32 pathLen, filepathLen, directoryLen, basenameLen, extensionLen;
|
||||
|
||||
// invoke the parser to extract the URL path
|
||||
rv = parser->ParseURL(url, flatURL.Length(),
|
||||
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(url + 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(url + filepathPos, filepathLen,
|
||||
&directoryPos, &directoryLen,
|
||||
&basenamePos, &basenameLen,
|
||||
&extensionPos, &extensionLen);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (directoryLen > 0)
|
||||
outDirectory = Substring(inURL, filepathPos + directoryPos, directoryLen);
|
||||
if (basenameLen > 0)
|
||||
outFileBaseName = Substring(inURL, filepathPos + basenamePos, basenameLen);
|
||||
if (extensionLen > 0)
|
||||
outFileExtension = Substring(inURL, filepathPos + extensionPos, extensionLen);
|
||||
// since we are using a no-auth url parser, there will never be a host
|
||||
// XXX not strictly true... file://localhost/foo/bar.html is a valid URL
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// path manipulation functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Replace all /./ with a / while resolving relative URLs
|
||||
// But only till #?
|
||||
void
|
||||
CoalesceDirsRel(char* io_Path)
|
||||
net_CoalesceDirsRel(char* io_Path)
|
||||
{
|
||||
/* Stolen from the old netlib's mkparse.c.
|
||||
*
|
||||
|
@ -125,7 +282,7 @@ CoalesceDirsRel(char* io_Path)
|
|||
// Replace all /./ with a / while resolving absolute URLs
|
||||
// But only till #?
|
||||
void
|
||||
CoalesceDirsAbs(char* io_Path)
|
||||
net_CoalesceDirsAbs(char* io_Path)
|
||||
{
|
||||
/* Stolen from the old netlib's mkparse.c.
|
||||
*
|
||||
|
@ -214,97 +371,10 @@ CoalesceDirsAbs(char* io_Path)
|
|||
*(urlPtr-1) = '\0';
|
||||
}
|
||||
|
||||
static inline
|
||||
void ToLower(char &c)
|
||||
{
|
||||
if ((unsigned)(c - 'A') <= (unsigned)('Z' - 'A'))
|
||||
c += 'a' - 'A';
|
||||
}
|
||||
|
||||
void
|
||||
ToLowerCase(char *str, PRUint32 length)
|
||||
{
|
||||
for (char *end = str + length; str < end; ++str)
|
||||
ToLower(*str);
|
||||
}
|
||||
|
||||
void
|
||||
ToLowerCase(char *str)
|
||||
{
|
||||
for (; *str; ++str)
|
||||
ToLower(*str);
|
||||
}
|
||||
|
||||
/* Extract URI-Scheme if possible */
|
||||
nsresult ExtractURLScheme(const nsACString &inURI, PRUint32 *startPos,
|
||||
PRUint32 *endPos, nsACString *scheme)
|
||||
{
|
||||
// search for something up to a colon, and call it the scheme
|
||||
const nsPromiseFlatCString flatURI( PromiseFlatCString(inURI) );
|
||||
const char* uri_start = flatURI.get();
|
||||
const char* uri = uri_start;
|
||||
|
||||
// skip leading white space
|
||||
while (nsCRT::IsAsciiSpace(*uri))
|
||||
uri++;
|
||||
|
||||
PRUint32 start = uri - uri_start;
|
||||
if (startPos) {
|
||||
*startPos = start;
|
||||
}
|
||||
|
||||
PRUint32 length = 0;
|
||||
char c;
|
||||
while ((c = *uri++) != '\0') {
|
||||
// First char must be Alpha
|
||||
if (length == 0 && nsCRT::IsAsciiAlpha(c)) {
|
||||
length++;
|
||||
}
|
||||
// Next chars can be alpha + digit + some special chars
|
||||
else if (length > 0 && (nsCRT::IsAsciiAlpha(c) ||
|
||||
nsCRT::IsAsciiDigit(c) || c == '+' ||
|
||||
c == '.' || c == '-')) {
|
||||
length++;
|
||||
}
|
||||
// stop if colon reached but not as first char
|
||||
else if (c == ':' && length > 0) {
|
||||
if (endPos) {
|
||||
*endPos = start + length + 1;
|
||||
}
|
||||
|
||||
if (scheme)
|
||||
scheme->Assign(Substring(inURI, start, length));
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
PRBool
|
||||
IsValidScheme(const char *scheme, PRUint32 schemeLen)
|
||||
{
|
||||
// first char much be alpha
|
||||
if (!nsCRT::IsAsciiAlpha(*scheme))
|
||||
return PR_FALSE;
|
||||
|
||||
for (; schemeLen && *scheme; ++scheme, --schemeLen) {
|
||||
if (!(nsCRT::IsAsciiAlpha(*scheme) ||
|
||||
nsCRT::IsAsciiDigit(*scheme) ||
|
||||
*scheme == '+' ||
|
||||
*scheme == '.' ||
|
||||
*scheme == '-'))
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ResolveRelativePath(const nsACString &relativePath,
|
||||
const nsACString &basePath,
|
||||
nsACString &result)
|
||||
net_ResolveRelativePath(const nsACString &relativePath,
|
||||
const nsACString &basePath,
|
||||
nsACString &result)
|
||||
{
|
||||
nsCAutoString name;
|
||||
nsCAutoString path(basePath);
|
||||
|
@ -370,3 +440,101 @@ ResolveRelativePath(const nsACString &relativePath,
|
|||
result = path;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// scheme fu
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
/* Extract URI-Scheme if possible */
|
||||
nsresult
|
||||
net_ExtractURLScheme(const nsACString &inURI,
|
||||
PRUint32 *startPos,
|
||||
PRUint32 *endPos,
|
||||
nsACString *scheme)
|
||||
{
|
||||
// search for something up to a colon, and call it the scheme
|
||||
const nsPromiseFlatCString flatURI( PromiseFlatCString(inURI) );
|
||||
const char* uri_start = flatURI.get();
|
||||
const char* uri = uri_start;
|
||||
|
||||
// skip leading white space
|
||||
while (nsCRT::IsAsciiSpace(*uri))
|
||||
uri++;
|
||||
|
||||
PRUint32 start = uri - uri_start;
|
||||
if (startPos) {
|
||||
*startPos = start;
|
||||
}
|
||||
|
||||
PRUint32 length = 0;
|
||||
char c;
|
||||
while ((c = *uri++) != '\0') {
|
||||
// First char must be Alpha
|
||||
if (length == 0 && nsCRT::IsAsciiAlpha(c)) {
|
||||
length++;
|
||||
}
|
||||
// Next chars can be alpha + digit + some special chars
|
||||
else if (length > 0 && (nsCRT::IsAsciiAlpha(c) ||
|
||||
nsCRT::IsAsciiDigit(c) || c == '+' ||
|
||||
c == '.' || c == '-')) {
|
||||
length++;
|
||||
}
|
||||
// stop if colon reached but not as first char
|
||||
else if (c == ':' && length > 0) {
|
||||
if (endPos) {
|
||||
*endPos = start + length;
|
||||
}
|
||||
|
||||
if (scheme)
|
||||
scheme->Assign(Substring(inURI, start, length));
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
PRBool
|
||||
net_IsValidScheme(const char *scheme, PRUint32 schemeLen)
|
||||
{
|
||||
// first char much be alpha
|
||||
if (!nsCRT::IsAsciiAlpha(*scheme))
|
||||
return PR_FALSE;
|
||||
|
||||
for (; schemeLen && *scheme; ++scheme, --schemeLen) {
|
||||
if (!(nsCRT::IsAsciiAlpha(*scheme) ||
|
||||
nsCRT::IsAsciiDigit(*scheme) ||
|
||||
*scheme == '+' ||
|
||||
*scheme == '.' ||
|
||||
*scheme == '-'))
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// miscellaneous (i.e., stuff that should really be elsewhere)
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
static inline
|
||||
void ToLower(char &c)
|
||||
{
|
||||
if ((unsigned)(c - 'A') <= (unsigned)('Z' - 'A'))
|
||||
c += 'a' - 'A';
|
||||
}
|
||||
|
||||
void
|
||||
net_ToLowerCase(char *str, PRUint32 length)
|
||||
{
|
||||
for (char *end = str + length; str < end; ++str)
|
||||
ToLower(*str);
|
||||
}
|
||||
|
||||
void
|
||||
net_ToLowerCase(char *str)
|
||||
{
|
||||
for (; *str; ++str)
|
||||
ToLower(*str);
|
||||
}
|
||||
|
|
|
@ -35,35 +35,41 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _nsURLHelper_h_
|
||||
#define _nsURLHelper_h_
|
||||
#ifndef nsURLHelper_h__
|
||||
#define nsURLHelper_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsIURLParser;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// This module contains some private helper functions related to URL parsing.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
/* shutdown frees URL parser */
|
||||
void net_ShutdownURLHelper();
|
||||
|
||||
/* access URL parsers */
|
||||
nsIURLParser *net_GetAuthURLParser();
|
||||
nsIURLParser *net_GetNoAuthURLParser();
|
||||
nsIURLParser *net_GetStdURLParser();
|
||||
|
||||
/* convert between nsIFile and file:// URL spec */
|
||||
nsresult net_GetURLSpecFromFile(nsIFile *, nsACString &);
|
||||
nsresult net_GetFileFromURLSpec(const nsACString &, nsIFile **);
|
||||
|
||||
/* extract file path components from file:// URL */
|
||||
nsresult net_ParseFileURL(const nsACString &inURL,
|
||||
nsACString &outDirectory,
|
||||
nsACString &outFileBaseName,
|
||||
nsACString &outFileExtension);
|
||||
|
||||
/* handle .. in dirs while resolving relative URLs */
|
||||
void CoalesceDirsRel(char* io_Path);
|
||||
void net_CoalesceDirsRel(char* io_Path);
|
||||
|
||||
/* handle .. in dirs while resolving absolute URLs */
|
||||
void CoalesceDirsAbs(char* io_Path);
|
||||
|
||||
/* convert to lower case */
|
||||
void ToLowerCase(char* str, PRUint32 length);
|
||||
void ToLowerCase(char* str);
|
||||
|
||||
/* Extract URI-Scheme if possible */
|
||||
nsresult ExtractURLScheme(const nsACString &inURI, PRUint32 *startPos,
|
||||
PRUint32 *endPos, nsACString *scheme = nsnull);
|
||||
|
||||
/* check that the given scheme conforms to RFC 2396 */
|
||||
PRBool IsValidScheme(const char *scheme, PRUint32 schemeLen);
|
||||
|
||||
inline PRBool IsValidScheme(const nsAFlatCString &scheme)
|
||||
{
|
||||
return IsValidScheme(scheme.get(), scheme.Length());
|
||||
}
|
||||
void net_CoalesceDirsAbs(char* io_Path);
|
||||
|
||||
/**
|
||||
* Resolves a relative path string containing "." and ".."
|
||||
|
@ -78,8 +84,33 @@ inline PRBool IsValidScheme(const nsAFlatCString &scheme)
|
|||
*
|
||||
* @return a new string, representing canonical uri
|
||||
*/
|
||||
nsresult ResolveRelativePath(const nsACString &relativePath,
|
||||
const nsACString &basePath,
|
||||
nsACString &result);
|
||||
nsresult net_ResolveRelativePath(const nsACString &relativePath,
|
||||
const nsACString &basePath,
|
||||
nsACString &result);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Extract URI-Scheme if possible
|
||||
*
|
||||
* @param inURI URI spec
|
||||
* @param startPos start of scheme (may be null)
|
||||
* @param endPos end of scheme; index of colon (may be null)
|
||||
* @param scheme scheme copied to this buffer on return (may be null)
|
||||
*/
|
||||
nsresult net_ExtractURLScheme(const nsACString &inURI,
|
||||
PRUint32 *startPos,
|
||||
PRUint32 *endPos,
|
||||
nsACString *scheme = nsnull);
|
||||
|
||||
/* check that the given scheme conforms to RFC 2396 */
|
||||
PRBool net_IsValidScheme(const char *scheme, PRUint32 schemeLen);
|
||||
|
||||
inline PRBool net_IsValidScheme(const nsAFlatCString &scheme)
|
||||
{
|
||||
return net_IsValidScheme(scheme.get(), scheme.Length());
|
||||
}
|
||||
|
||||
/* convert to lower case (XXX this needs to be factored out) */
|
||||
void net_ToLowerCase(char* str, PRUint32 length);
|
||||
void net_ToLowerCase(char* str);
|
||||
|
||||
#endif // !nsURLHelper_h__
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Mac-specific local file url parsing */
|
||||
#include "nsIOService.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
|
@ -65,8 +65,8 @@ static void PascalStringCopy(Str255 dst, const char *src)
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &aURL)
|
||||
nsresult
|
||||
net_GetURLSpecFromFile(nsIFile *aFile, nsACString &aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG(aFile);
|
||||
|
@ -109,8 +109,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &aURL)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
nsresult
|
||||
net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -123,7 +123,7 @@ nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
|||
|
||||
nsCAutoString directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
|
@ -40,14 +40,14 @@
|
|||
/* OS/2-specific local file uri parsing */
|
||||
#define INCL_DOSERRORS
|
||||
#define INCL_DOS
|
||||
#include "nsIOService.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
static int isleadbyte(int c);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
nsresult
|
||||
net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString ePath;
|
||||
|
@ -95,8 +95,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
nsresult
|
||||
net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -109,7 +109,7 @@ nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
|||
|
||||
nsCAutoString directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
|
@ -38,12 +38,12 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Unix-specific local file uri parsing */
|
||||
#include "nsIOService.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
nsresult
|
||||
net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString ePath;
|
||||
|
@ -79,8 +79,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
nsresult
|
||||
net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -93,7 +93,7 @@ nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
|||
|
||||
nsCAutoString directory, fileBaseName, fileExtension, path;
|
||||
|
||||
rv = ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!directory.IsEmpty())
|
|
@ -38,13 +38,13 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Windows-specific local file uri parsing */
|
||||
#include "nsIOService.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include <windows.h>
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
nsresult
|
||||
net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString ePath;
|
||||
|
@ -92,8 +92,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
nsresult
|
||||
net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -106,7 +106,7 @@ nsIOService::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
|||
|
||||
nsCAutoString directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
|
@ -144,7 +144,7 @@ nsBaseURLParser::ParseURL(const char *spec, PRInt32 specLen,
|
|||
// spec = <scheme>:<authority>
|
||||
// spec = <scheme>:<path-no-slashes>
|
||||
//
|
||||
if (!IsValidScheme(spec, colon - spec) || (*(colon+1) == ':')) {
|
||||
if (!net_IsValidScheme(spec, colon - spec) || (*(colon+1) == ':')) {
|
||||
NS_WARNING("malformed uri");
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
|
|
@ -147,71 +147,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsResumableEntityID)
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_METHOD
|
||||
RegisterBuiltInURLParsers(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString previous;
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"file",
|
||||
NS_NOAUTHURLPARSER_CONTRACTID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"ftp",
|
||||
NS_AUTHURLPARSER_CONTRACTID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"http",
|
||||
NS_AUTHURLPARSER_CONTRACTID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"https",
|
||||
NS_AUTHURLPARSER_CONTRACTID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
UnregisterBuiltInURLParsers(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "file", PR_TRUE);
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "ftp", PR_TRUE);
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "http", PR_TRUE);
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "https", PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsFileChannel.h"
|
||||
#include "nsFileProtocolHandler.h"
|
||||
#include "nsDataHandler.h"
|
||||
|
@ -554,6 +489,9 @@ static void PR_CALLBACK nsNeckoShutdown(nsIModule *neckoModule)
|
|||
|
||||
// Release buffer cache
|
||||
NS_IF_RELEASE(nsIOService::gBufferCache);
|
||||
|
||||
// Release global state used by the URL helper module.
|
||||
net_ShutdownURLHelper();
|
||||
}
|
||||
|
||||
static const nsModuleComponentInfo gNetModuleInfo[] = {
|
||||
|
@ -671,9 +609,7 @@ static const nsModuleComponentInfo gNetModuleInfo[] = {
|
|||
{ NS_STDURLPARSER_CLASSNAME,
|
||||
NS_STDURLPARSER_CID,
|
||||
NS_STDURLPARSER_CONTRACTID,
|
||||
nsStdURLParserConstructor,
|
||||
RegisterBuiltInURLParsers,
|
||||
UnregisterBuiltInURLParsers},
|
||||
nsStdURLParserConstructor},
|
||||
{ NS_NOAUTHURLPARSER_CLASSNAME,
|
||||
NS_NOAUTHURLPARSER_CID,
|
||||
NS_NOAUTHURLPARSER_CONTRACTID,
|
||||
|
|
|
@ -1599,7 +1599,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -2065,7 +2065,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -3621,7 +3621,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -4087,7 +4087,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -5629,7 +5629,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -6085,7 +6085,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -7627,7 +7627,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -8083,7 +8083,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -8161,7 +8161,7 @@
|
|||
<FILEREF>
|
||||
<TARGETNAME>Necko.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIOServiceMac.cpp</PATH>
|
||||
<PATH>nsURLHelperMac.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
|
|
@ -50,4 +50,20 @@ interface nsIFileProtocolHandler : nsIProtocolHandler
|
|||
* @return reference to a new nsIURI object
|
||||
*/
|
||||
nsIURI newFileURI(in nsIFile aFile);
|
||||
|
||||
/**
|
||||
* Converts the nsIFile to the corresponding URL string. NOTE: under
|
||||
* some platforms this is a lossy conversion (e.g., Mac Carbon build).
|
||||
* If the nsIFile is a local file, then the result will be a file://
|
||||
* URL string.
|
||||
*
|
||||
* The resulting string may contain URL-escaped characters.
|
||||
*/
|
||||
AUTF8String getURLSpecFromFile(in nsIFile file);
|
||||
|
||||
/**
|
||||
* Converts the URL string into the corresponding nsIFile if possible.
|
||||
* A local file will be created if the URL string begins with file://.
|
||||
*/
|
||||
nsIFile getFileFromURLSpec(in AUTF8String url);
|
||||
};
|
||||
|
|
|
@ -44,6 +44,10 @@ CPPSRCS = \
|
|||
# static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(topsrcdir)/netwerk/base/src \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "nsAutoLock.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsURLHelper.h"
|
||||
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
@ -204,3 +205,15 @@ nsFileProtocolHandler::NewFileURI(nsIFile *file, nsIURI **result)
|
|||
|
||||
return CallQueryInterface(url, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileProtocolHandler::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
|
||||
{
|
||||
return net_GetURLSpecFromFile(aFile, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileProtocolHandler::GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
|
||||
{
|
||||
return net_GetFileFromURLSpec(aURL, result);
|
||||
}
|
||||
|
|
|
@ -123,14 +123,6 @@ struct nsHttp
|
|||
// utilities...
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static inline nsresult
|
||||
DupString(const char *src, char **dst)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(dst);
|
||||
*dst = PL_strdup(src);
|
||||
return *dst ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
static inline PRUint32
|
||||
PRTimeToSeconds(PRTime t_usec)
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@ nsJARURI::SetSpec(const nsACString &aSpec)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString scheme;
|
||||
rv = ::ExtractURLScheme(aSpec, nsnull, nsnull, &scheme);
|
||||
rv = net_ExtractURLScheme(aSpec, nsnull, nsnull, &scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (strcmp("jar", scheme.get()) != 0)
|
||||
|
@ -127,9 +127,9 @@ nsJARURI::SetSpec(const nsACString &aSpec)
|
|||
while (*delim_end == '/')
|
||||
++delim_end;
|
||||
|
||||
rv = ::ResolveRelativePath(Substring(delim_end, end),
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
rv = net_ResolveRelativePath(Substring(delim_end, end),
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ nsJARURI::Resolve(const nsACString &relativePath, nsACString &result)
|
|||
nsresult rv;
|
||||
|
||||
nsCAutoString scheme;
|
||||
rv = ::ExtractURLScheme(relativePath, nsnull, nsnull, &scheme);
|
||||
rv = net_ExtractURLScheme(relativePath, nsnull, nsnull, &scheme);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// then aSpec is absolute
|
||||
result = relativePath;
|
||||
|
@ -344,8 +344,8 @@ nsJARURI::Resolve(const nsACString &relativePath, nsACString &result)
|
|||
path = "";
|
||||
|
||||
nsCAutoString resolvedEntry;
|
||||
rv = ::ResolveRelativePath(relativePath, path,
|
||||
resolvedEntry);
|
||||
rv = net_ResolveRelativePath(relativePath, path,
|
||||
resolvedEntry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return FormatSpec(resolvedEntry, result);
|
||||
|
@ -385,9 +385,9 @@ nsJARURI::SetJAREntry(const nsACString &entryPath)
|
|||
{
|
||||
mJAREntry.Truncate();
|
||||
|
||||
return ::ResolveRelativePath(entryPath,
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
return net_ResolveRelativePath(entryPath,
|
||||
NS_LITERAL_CSTRING(""),
|
||||
mJAREntry);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "nsIFile.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsURLHelper.h"
|
||||
|
||||
static nsResProtocolHandler *gResHandler = nsnull;
|
||||
|
||||
|
@ -91,7 +92,7 @@ nsResURL::GetFile(nsIFile **result)
|
|||
rv = gResHandler->ResolveURI(this, spec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_GetFileFromURLSpec(spec, result, gResHandler->mIOService);
|
||||
return net_GetFileFromURLSpec(spec, result);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "nsIDirIndex.h"
|
||||
#include "prtime.h"
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS4(nsIndexedToHTML,
|
||||
|
@ -208,7 +209,7 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) {
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString url;
|
||||
rv = NS_GetURLSpecFromFile(file, url);
|
||||
rv = net_GetURLSpecFromFile(file, url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
baseUri.Assign(url);
|
||||
|
||||
|
@ -216,7 +217,7 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) {
|
|||
rv = file->GetParent(getter_AddRefs(parent));
|
||||
|
||||
if (parent && NS_SUCCEEDED(rv)) {
|
||||
NS_GetURLSpecFromFile(parent, url);
|
||||
net_GetURLSpecFromFile(parent, url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
parentStr.Assign(url);
|
||||
}
|
||||
|
|
|
@ -281,7 +281,9 @@ function getNormalizedURL(url)
|
|||
kLF.initWithPath(url);
|
||||
if (kLF.exists()) {
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.classes.nsIIOService);
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = ioService.getProtocolHandler("file")
|
||||
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
|
||||
url = ioService.getURLSpecFromFile(kLF);
|
||||
}
|
||||
|
|
|
@ -183,7 +183,8 @@
|
|||
fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIProperties);
|
||||
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
gDS = gRDF.GetDataSource(ioService.getURLSpecFromFile(file));
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
|
||||
}
|
||||
|
||||
function onAccept()
|
||||
|
|
|
@ -99,8 +99,9 @@ function onOK()
|
|||
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
||||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
|
||||
gDS = gRDF.GetDataSource(ioService.getURLSpecFromFile(file));
|
||||
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
|
||||
|
||||
gMIMEField.value = gMIMEField.value.toLowerCase();
|
||||
|
||||
|
|
|
@ -89,8 +89,9 @@ function Startup()
|
|||
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
||||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
dump("spec is " + ioService.getURLSpecFromFile(file));
|
||||
gDS = gRDF.GetDataSource(ioService.getURLSpecFromFile(file));
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
dump("spec is " + fileHandler.getURLSpecFromFile(file));
|
||||
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
|
||||
|
||||
// intialize the listbox
|
||||
gList.database.AddDataSource(gDS);
|
||||
|
|
|
@ -868,8 +868,9 @@ function get_sidebar_datasource_uri() {
|
|||
var sidebar_file = sidebar_get_panels_file();
|
||||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
|
||||
return ioService.getURLSpecFromFile(sidebar_file);
|
||||
return fileHandler.getURLSpecFromFile(sidebar_file);
|
||||
} catch (ex) {
|
||||
// This should not happen
|
||||
debug("Error: Unable to load panels file.\n");
|
||||
|
|
|
@ -429,7 +429,8 @@ function getSidebarDatasourceURI(panels_file_id)
|
|||
}
|
||||
|
||||
var io_service = Components.classes[IO_SERV_CONTRACTID].getService(Components.interfaces.nsIIOService);
|
||||
var sidebar_uri = io_service.getURLSpecFromFile(sidebar_file);
|
||||
var file_handler = io_service.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
var sidebar_uri = file_handler.getURLSpecFromFile(sidebar_file);
|
||||
debug("sidebar uri is " + sidebar_uri);
|
||||
return sidebar_uri;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче