mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-02 03:49:37 +00:00
Structural changes for MakeAbsolute performance. bug#10736 r=valeski
This commit is contained in:
parent
424eae7fa3
commit
d3b9c9c3cc
@ -87,23 +87,6 @@ nsChromeProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChromeProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// XXX optimize this to not needlessly construct the URL
|
||||
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
rv = NewURI(aSpec, aBaseURI, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetSpec(result);
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChromeProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -154,20 +154,6 @@ nsJSProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// presumably, there's no such thing as a relative javascript: URI,
|
||||
// so just copy the input spec
|
||||
char* dup = nsCRT::strdup(aSpec);
|
||||
if (!dup)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*result = dup;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -385,6 +385,11 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetRelativePath(const char *i_RelativePath)
|
||||
return m_baseURL->SetRelativePath(i_RelativePath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::Resolve(const char *relativePath, char **result)
|
||||
{
|
||||
return m_baseURL->Resolve(relativePath, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetDirectory(char * *aDirectory)
|
||||
{
|
||||
return m_baseURL->GetDirectory(aDirectory);
|
||||
|
@ -214,12 +214,6 @@ NS_IMETHODIMP nsSmtpService::GetDefaultPort(PRInt32 *aDefaultPort)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSmtpService::MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI, char **_retval)
|
||||
{
|
||||
// no such thing as relative urls for smtp.....
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSmtpService::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval)
|
||||
{
|
||||
// i just haven't implemented this yet...I will be though....
|
||||
|
@ -2122,12 +2122,6 @@ NS_IMETHODIMP nsImapService::GetDefaultPort(PRInt32 *aDefaultPort)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImapService::MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI, char **_retval)
|
||||
{
|
||||
// no such thing as relative urls for smtp.....
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImapService::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIImapUrl> aImapUrl;
|
||||
|
@ -272,12 +272,6 @@ NS_IMETHODIMP nsMailboxService::GetDefaultPort(PRInt32 *aDefaultPort)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMailboxService::MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI, char **_retval)
|
||||
{
|
||||
// no such thing as relative urls for smtp.....
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMailboxService::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIMailboxUrl> aMsgUrl;
|
||||
|
@ -249,12 +249,6 @@ NS_IMETHODIMP nsPop3Service::GetDefaultPort(PRInt32 *aDefaultPort)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPop3Service::MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI, char **_retval)
|
||||
{
|
||||
// no such thing as relative urls for smtp.....
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPop3Service::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval)
|
||||
{
|
||||
// i just haven't implemented this yet...I will be though....
|
||||
|
@ -917,12 +917,6 @@ NS_IMETHODIMP nsNntpService::GetDefaultPort(PRInt32 *aDefaultPort)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNntpService::MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI, char **_retval)
|
||||
{
|
||||
// no such thing as relative urls for smtp.....
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNntpService::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -81,14 +81,6 @@ nsJARProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// JAR urls have the following syntax
|
||||
//
|
||||
// jar:<url>!/(entry)
|
||||
|
@ -33,18 +33,7 @@ class nsJARProtocolHandler : public nsIProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIProtocolHandler methods:
|
||||
NS_IMETHOD GetScheme(char * *aScheme);
|
||||
NS_IMETHOD GetDefaultPort(PRInt32 *aDefaultPort);
|
||||
NS_IMETHOD MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI,
|
||||
char **_retval);
|
||||
NS_IMETHOD NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **_retval);
|
||||
NS_IMETHOD NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup *loadGroup,
|
||||
nsIEventSinkGetter *eventSinkGetter,
|
||||
nsIChannel **_retval);
|
||||
ns_DECL_NSIPROTOCOLHANDLER
|
||||
|
||||
// nsJARProtocolHandler methods:
|
||||
nsJARProtocolHandler();
|
||||
|
@ -32,7 +32,7 @@ interface nsIFileChannel;
|
||||
interface nsILoadGroup;
|
||||
interface nsILoadGroupObserver;
|
||||
|
||||
[scriptable, uuid(01f0a170-1881-11d3-9337-00104ba0fd40)]
|
||||
[scriptable, uuid(1daf19f0-8ea7-11d3-93ad-00104ba0fd40)]
|
||||
interface nsIIOService : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -40,12 +40,6 @@ interface nsIIOService : nsISupports
|
||||
*/
|
||||
nsIProtocolHandler getProtocolHandler(in string scheme);
|
||||
|
||||
/**
|
||||
* Returns an absolute URI string from a relative specification and
|
||||
* a base URI.
|
||||
*/
|
||||
string makeAbsolute(in string aRelativeSpec, in nsIURI aBaseURI);
|
||||
|
||||
/**
|
||||
* This method constructs a new URI by first determining the scheme
|
||||
* of the URI spec, and then delegating the construction of the URI
|
||||
@ -147,16 +141,6 @@ interface nsIIOService : nsISupports
|
||||
*/
|
||||
nsIFileChannel newChannelFromNativePath(in string nativePath);
|
||||
|
||||
/**
|
||||
* Returns a new load group. Load groups can be used to manage collections
|
||||
* of channels so that they can be reloaded or canceled en mass. Note that
|
||||
* their use is not required by other parts of the system, they are primarily
|
||||
* a convenience for the caller. The outer parameter can be used for aggregation.
|
||||
*/
|
||||
nsILoadGroup newLoadGroup(in nsISupports outer,
|
||||
in nsIStreamObserver observer,
|
||||
in nsILoadGroup parent);
|
||||
|
||||
/**
|
||||
* Returns a simple channel implementation that uses the given input
|
||||
* stream and content type. A URI may also be supplied which will be returned
|
||||
|
@ -23,15 +23,13 @@ interface nsIEventSinkGetter;
|
||||
interface nsIChannel;
|
||||
interface nsILoadGroup;
|
||||
|
||||
[scriptable, uuid(8984a6f0-1893-11d3-9337-00104ba0fd40)]
|
||||
[scriptable, uuid(15fd6940-8ea7-11d3-93ad-00104ba0fd40)]
|
||||
interface nsIProtocolHandler : nsISupports
|
||||
{
|
||||
readonly attribute string scheme;
|
||||
|
||||
readonly attribute long defaultPort;
|
||||
|
||||
string makeAbsolute(in string aRelativeSpec, in nsIURI aBaseURI);
|
||||
|
||||
/**
|
||||
* Makes a URI object that is suitable for loading by this protocol.
|
||||
* In the usual case (when only the accessors provided by nsIURI are
|
||||
|
@ -117,18 +117,26 @@ interface nsIURI : nsISupports
|
||||
*/
|
||||
nsIURI clone();
|
||||
|
||||
/**
|
||||
* Sets the given string to be a relative path for this URL, and
|
||||
* changes this to read relative. Thus for example- if this =
|
||||
* http://foo.com/bar/index.html, then calling SetRelativePath("/baz") will
|
||||
* change this to http://foo.com/baz and calling it with "baz" will
|
||||
* change this to http://foo.com/bar/baz.
|
||||
*/
|
||||
void setRelativePath(in string i_RelativePath);
|
||||
/**
|
||||
* Sets the given string to be a relative path for this URI, and
|
||||
* changes this to read relative. Thus for example- if this =
|
||||
* http://foo.com/bar/index.html, then calling SetRelativePath("/baz") will
|
||||
* change this to http://foo.com/baz and calling it with "baz" will
|
||||
* change this to http://foo.com/bar/baz.
|
||||
*/
|
||||
void setRelativePath(in string relativePath);
|
||||
|
||||
/**
|
||||
* This method resolves a relative string into an absolute URI string,
|
||||
* using the URI as the base.
|
||||
*
|
||||
* This method subsumes the deprecated method nsIIOService::MakeAbsolute.
|
||||
*/
|
||||
string resolve(in string relativePath);
|
||||
};
|
||||
|
||||
%{C++
|
||||
// Malformed URL Error
|
||||
// Malformed URI Error
|
||||
#define NS_ERROR_MALFORMED_URI NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 10)
|
||||
|
||||
/**
|
||||
|
@ -251,38 +251,6 @@ nsIOService::NewChannel(const char* verb, const char *aSpec,
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::MakeAbsolute(const char *aSpec,
|
||||
nsIURI *aBaseURI,
|
||||
char **result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ASSERTION(aBaseURI, "It doesn't make sense to not supply a base URI");
|
||||
|
||||
if (aSpec == nsnull)
|
||||
return aBaseURI->GetSpec(result);
|
||||
|
||||
char* scheme;
|
||||
rv = GetScheme(aSpec, &scheme);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAllocator::Free(scheme);
|
||||
// if aSpec has a scheme, then it's already absolute
|
||||
*result = nsCRT::strdup(aSpec);
|
||||
return (*result == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
// else ask the protocol handler for the base URI to deal with it
|
||||
rv = aBaseURI->GetScheme(&scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> handler;
|
||||
rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
|
||||
nsCRT::free(scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return handler->MakeAbsolute(aSpec, aBaseURI, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetAppCodeName(PRUnichar* *aAppCodeName)
|
||||
{
|
||||
@ -395,26 +363,6 @@ nsIOService::NewChannelFromNativePath(const char *nativePath, nsIFileChannel **r
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewLoadGroup(nsISupports* outer, nsIStreamObserver* observer,
|
||||
nsILoadGroup* parent, nsILoadGroup **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsILoadGroup* group;
|
||||
rv = nsLoadGroup::Create(outer, NS_GET_IID(nsILoadGroup),
|
||||
(void**)&group);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = group->Init(observer, parent);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(group);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = group;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewInputStreamChannel(nsIURI* uri, const char *contentType,
|
||||
PRInt32 contentLength,
|
||||
|
@ -221,6 +221,13 @@ nsSimpleURI::SetRelativePath(const char *i_RelativePath)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSimpleURI::Resolve(const char *relativePath, char **result)
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "This is meaningless in hack context!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
static NS_DEFINE_CID(kStdURLCID, NS_STANDARDURL_CID);
|
||||
static NS_DEFINE_CID(kThisStdURLImplementationCID,
|
||||
@ -879,6 +880,21 @@ nsStdURL::SetRelativePath(const char* i_Relative)
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStdURL::Resolve(const char *relativePath, char **result)
|
||||
{
|
||||
// XXX Judson: optimize this
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = Clone(getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = uri->SetRelativePath(relativePath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return uri->GetSpec(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsStdURL::ReconstructPath(void)
|
||||
{
|
||||
|
@ -83,20 +83,6 @@ nsAboutProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// presumably, there's no such thing as a relative about: URI,
|
||||
// so just copy the input spec
|
||||
char* dup = nsCRT::strdup(aSpec);
|
||||
if (dup == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*result = dup;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -68,16 +68,6 @@ nsDataHandler::GetDefaultPort(PRInt32 *result) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result) {
|
||||
// no concept of a relative data url
|
||||
*result = nsCRT::strdup(aSpec);
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result) {
|
||||
|
@ -90,23 +90,6 @@ nsFileProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// XXX optimize this to not needlessly construct the URL
|
||||
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
rv = NewURI(aSpec, aBaseURI, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetSpec(result);
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -134,23 +134,6 @@ nsFtpProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFtpProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// XXX optimize this to not needlessly construct the URL
|
||||
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
rv = NewURI(aSpec, aBaseURI, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetSpec(result);
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFtpProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -268,22 +268,6 @@ nsHTTPHandler::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
|
||||
NS_IMPL_RELEASE(nsHTTPHandler);
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI,
|
||||
char **_retval)
|
||||
{
|
||||
// XXX optimize this to not needlessly construct the URL
|
||||
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
rv = NewURI(aRelativeSpec, aBaseURI, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetSpec(_retval);
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -77,10 +77,6 @@ public:
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
NS_IMETHOD MakeAbsolute(const char *aRelativeSpec,
|
||||
nsIURI *aBaseURI,
|
||||
char **_retval);
|
||||
|
||||
NS_IMETHOD NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup *aGroup,
|
||||
nsIEventSinkGetter *eventSinkGetter,
|
||||
|
@ -81,14 +81,6 @@ nsJARProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// JAR urls have the following syntax
|
||||
//
|
||||
// jar:<url>!/(entry)
|
||||
|
@ -33,18 +33,7 @@ class nsJARProtocolHandler : public nsIProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIProtocolHandler methods:
|
||||
NS_IMETHOD GetScheme(char * *aScheme);
|
||||
NS_IMETHOD GetDefaultPort(PRInt32 *aDefaultPort);
|
||||
NS_IMETHOD MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI,
|
||||
char **_retval);
|
||||
NS_IMETHOD NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **_retval);
|
||||
NS_IMETHOD NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup *loadGroup,
|
||||
nsIEventSinkGetter *eventSinkGetter,
|
||||
nsIChannel **_retval);
|
||||
ns_DECL_NSIPROTOCOLHANDLER
|
||||
|
||||
// nsJARProtocolHandler methods:
|
||||
nsJARProtocolHandler();
|
||||
|
@ -76,18 +76,6 @@ nsKeywordProtocolHandler::GetDefaultPort(PRInt32 *result) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsKeywordProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result) {
|
||||
// presumably, there's no such thing as a relative Keyword: URI,
|
||||
// so just copy the input spec
|
||||
char* dup = nsCRT::strdup(aSpec);
|
||||
if (!dup) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*result = dup;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// digests a spec _without_ the preceeding "keyword:" scheme.
|
||||
static char *
|
||||
MangleKeywordIntoHTTPURL(const char *aSpec) {
|
||||
|
@ -97,23 +97,6 @@ nsResourceProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsResourceProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// XXX optimize this to not needlessly construct the URL
|
||||
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
rv = NewURI(aSpec, aBaseURI, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetSpec(result);
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsResourceProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
static NS_DEFINE_CID(kLoadGroupCID, NS_LOADGROUP_CID);
|
||||
|
||||
NECKO_EXPORT(nsresult)
|
||||
NS_NewURI(nsIURI* *result, const char* spec, nsIURI* baseURI)
|
||||
@ -101,14 +102,58 @@ NS_OpenURI(nsIStreamListener* aConsumer, nsISupports* context, nsIURI* uri,
|
||||
return rv;
|
||||
}
|
||||
|
||||
// XXX copied from nsIOService.cpp (for now):
|
||||
static nsresult
|
||||
GetScheme(const char* inURI, char* *scheme)
|
||||
{
|
||||
// search for something up to a colon, and call it the scheme
|
||||
NS_ASSERTION(inURI, "null pointer");
|
||||
if (!inURI) return NS_ERROR_NULL_POINTER;
|
||||
char c;
|
||||
const char* URI = inURI;
|
||||
PRUint8 length = 0;
|
||||
// skip leading white space
|
||||
while (nsString::IsSpace(*URI))
|
||||
URI++;
|
||||
while ((c = *URI++) != '\0') {
|
||||
if (c == ':') {
|
||||
char* newScheme = (char *)nsAllocator::Alloc(length+1);
|
||||
if (newScheme == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCRT::memcpy(newScheme, inURI, length);
|
||||
newScheme[length] = '\0';
|
||||
*scheme = newScheme;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (nsString::IsAlpha(c)) {
|
||||
length++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
NECKO_EXPORT(nsresult)
|
||||
NS_MakeAbsoluteURI(const char* spec, nsIURI* baseURI, char* *result)
|
||||
NS_MakeAbsoluteURI(const char* aSpec, nsIURI* aBaseURI, char* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return serv->MakeAbsolute(spec, baseURI, result);
|
||||
NS_ASSERTION(aBaseURI, "It doesn't make sense to not supply a base URI");
|
||||
|
||||
if (aSpec == nsnull)
|
||||
return aBaseURI->GetSpec(result);
|
||||
|
||||
char* scheme;
|
||||
rv = GetScheme(aSpec, &scheme);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAllocator::Free(scheme);
|
||||
// if aSpec has a scheme, then it's already absolute
|
||||
*result = nsCRT::strdup(aSpec);
|
||||
return (*result == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
return aBaseURI->Resolve(aSpec, result);
|
||||
}
|
||||
|
||||
NECKO_EXPORT(nsresult)
|
||||
@ -133,10 +178,19 @@ NS_NewLoadGroup(nsISupports* outer, nsIStreamObserver* observer,
|
||||
nsILoadGroup* parent, nsILoadGroup* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
nsILoadGroup* group;
|
||||
rv = nsComponentManager::CreateInstance(kLoadGroupCID, outer,
|
||||
NS_GET_IID(nsILoadGroup),
|
||||
(void**)&group);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return serv->NewLoadGroup(outer, observer, parent, result);
|
||||
|
||||
rv = group->Init(observer, parent);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(group);
|
||||
return rv;
|
||||
}
|
||||
*result = group;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NECKO_EXPORT(nsresult)
|
||||
|
@ -47,6 +47,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
#include "nsXPIDLString.h"
|
||||
#include "prtime.h"
|
||||
#include "rdfutil.h"
|
||||
#include "nsNeckoUtil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -90,29 +91,13 @@ rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI)
|
||||
nsresult rv;
|
||||
nsAutoString result;
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
|
||||
nsCOMPtr<nsIURI> base;
|
||||
rv = NS_NewURI(getter_AddRefs(base), aBaseURI);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> baseUri;
|
||||
|
||||
char *uriStr = aBaseURI.ToNewCString();
|
||||
if (! uriStr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = service->NewURI(uriStr, nsnull, getter_AddRefs(baseUri));
|
||||
nsCRT::free(uriStr);
|
||||
|
||||
rv = NS_MakeAbsoluteURI(aURI, base, result);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString absUrlStr;
|
||||
char *urlSpec = aURI.ToNewCString();
|
||||
if (! urlSpec)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = service->MakeAbsolute(urlSpec, baseUri, getter_Copies(absUrlStr));
|
||||
nsCRT::free(urlSpec);
|
||||
|
||||
result = (const char*) absUrlStr;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aURI = result;
|
||||
}
|
||||
@ -132,18 +117,8 @@ rdf_MakeAbsoluteURI(nsIURI* aURL, nsString& aURI)
|
||||
nsresult rv;
|
||||
nsAutoString result;
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = NS_MakeAbsoluteURI(aURI, aURL, result);
|
||||
|
||||
nsIURI *baseUri = nsnull;
|
||||
rv = aURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *absUrlStr = nsnull;
|
||||
rv = service->MakeAbsolute(nsCAutoString(aURI), baseUri, &absUrlStr);
|
||||
NS_RELEASE(baseUri);
|
||||
result = absUrlStr;
|
||||
nsCRT::free(absUrlStr);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aURI = result;
|
||||
}
|
||||
|
@ -87,23 +87,6 @@ nsChromeProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChromeProtocolHandler::MakeAbsolute(const char* aSpec,
|
||||
nsIURI* aBaseURI,
|
||||
char* *result)
|
||||
{
|
||||
// XXX optimize this to not needlessly construct the URL
|
||||
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
rv = NewURI(aSpec, aBaseURI, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetSpec(result);
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChromeProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user