зеркало из https://github.com/mozilla/gecko-dev.git
Fixed scheme parsing code. Added outer param to NewLoadGroup.
This commit is contained in:
Родитель
5fe24074f1
Коммит
73a8f5ba23
|
@ -137,9 +137,10 @@ interface nsIIOService : nsISupports
|
|||
* 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.
|
||||
* a convenience for the caller. The outer parameter can be used for aggregation.
|
||||
*/
|
||||
nsILoadGroup NewLoadGroup(in nsILoadGroup parent);
|
||||
nsILoadGroup NewLoadGroup(in nsILoadGroup parent,
|
||||
in nsISupports outer);
|
||||
|
||||
/**
|
||||
* Returns a simple channel implementation that uses the given input
|
||||
|
|
|
@ -104,40 +104,57 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
PRUint32 i = 0;
|
||||
PRUint32 length = 0;
|
||||
// skip leading white space
|
||||
while (isspace(*URI))
|
||||
URI++;
|
||||
while ((c = *URI++) != '\0') {
|
||||
if (c == ':') {
|
||||
char* newScheme = (char *)PR_Malloc(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 (isalpha(c)) {
|
||||
length++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
|
||||
nsIURI* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
char* scheme;
|
||||
rv = GetScheme(aSpec, &scheme);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (aBaseURI)
|
||||
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;
|
||||
|
||||
nsAutoString scheme(aSpec);
|
||||
scheme.CompressWhitespace(); // remove any leading/trailing spaces;
|
||||
int firstColon = scheme.Find(":");
|
||||
if (-1 == firstColon)
|
||||
{
|
||||
if (aBaseURI)
|
||||
{
|
||||
nsXPIDLCString sch;
|
||||
rv = aBaseURI->GetScheme(getter_Copies(sch));
|
||||
if (NS_FAILED(rv) || !sch || (0 == nsCRT::strlen(sch)))
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
scheme = sch;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_MALFORMED_URI; // Must have a scheme
|
||||
}
|
||||
else
|
||||
scheme.Truncate(firstColon);
|
||||
|
||||
// Use the scheme to find the handler and ask it to create a new URI
|
||||
nsCOMPtr<nsIProtocolHandler> handler;
|
||||
rv = GetProtocolHandler(nsCAutoString(scheme),
|
||||
getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
// Didn't find any handler for this scheme
|
||||
return rv;
|
||||
}
|
||||
return handler->NewURI(aSpec, aBaseURI, result);
|
||||
}
|
||||
|
||||
|
@ -194,30 +211,25 @@ nsIOService::MakeAbsolute(const char *aSpec,
|
|||
{
|
||||
nsresult rv;
|
||||
NS_ASSERTION(aBaseURI, "It doesn't make sense to not supply a base URI");
|
||||
if (!aBaseURI)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (aSpec == nsnull)
|
||||
return aBaseURI->GetSpec(result);
|
||||
if (aSpec == nsnull)
|
||||
return aBaseURI->GetSpec(result);
|
||||
|
||||
nsAutoString scheme(aSpec);
|
||||
scheme.CompressWhitespace(); // remove any leading/trailing spaces;
|
||||
int firstColon = scheme.Find(":");
|
||||
if (-1 != firstColon)
|
||||
{
|
||||
// if aSpec has a scheme, then it's already absolute
|
||||
*result = nsCRT::strdup(aSpec);
|
||||
return (*result == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
char* scheme;
|
||||
rv = GetScheme(aSpec, &scheme);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// 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
|
||||
nsXPIDLCString baseScheme;
|
||||
rv = aBaseURI->GetScheme(getter_Copies(baseScheme));
|
||||
// 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((const char*)baseScheme,
|
||||
getter_AddRefs(handler));
|
||||
rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
|
||||
nsCRT::free(scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return handler->MakeAbsolute(aSpec, aBaseURI, result);
|
||||
|
@ -316,18 +328,27 @@ nsIOService::NewChannelFromNativePath(const char *nativePath, nsIFileChannel **r
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewLoadGroup(nsILoadGroup* parent, nsILoadGroup **result)
|
||||
nsIOService::NewLoadGroup(nsILoadGroup* parent, nsISupports* outer,
|
||||
nsILoadGroup **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsILoadGroup* group;
|
||||
rv = nsLoadGroup::Create(nsnull, nsCOMTypeInfo<nsILoadGroup>::GetIID(),
|
||||
rv = nsLoadGroup::Create(outer, nsCOMTypeInfo<nsILoadGroup>::GetIID(),
|
||||
(void**)&group);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (parent) {
|
||||
rv = parent->AddSubGroup(group);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(group);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
*result = group;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewInputStreamChannel(nsIURI* uri, const char *contentType,
|
||||
nsIInputStream *inStr, nsIChannel **result)
|
||||
|
@ -343,6 +364,9 @@ nsIOService::NewInputStreamChannel(nsIURI* uri, const char *contentType,
|
|||
return rv;
|
||||
}
|
||||
*result = channel;
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
NS_IMETHOD NewAsyncStreamListener(nsIStreamListener *receiver, nsIEventQueue *eventQueue, nsIStreamListener **_retval);
|
||||
NS_IMETHOD NewSyncStreamListener(nsIInputStream **inStream, nsIBufferOutputStream **outStream, nsIStreamListener **_retval);
|
||||
NS_IMETHOD NewChannelFromNativePath(const char *nativePath, nsIFileChannel **_retval);
|
||||
NS_IMETHOD NewLoadGroup(nsILoadGroup* parent, nsILoadGroup **result);
|
||||
NS_IMETHOD NewLoadGroup(nsILoadGroup* parent, nsISupports* outer, nsILoadGroup **result);
|
||||
NS_IMETHOD NewInputStreamChannel(nsIURI* uri, const char *contentType, nsIInputStream *inStr, nsIChannel **result);
|
||||
|
||||
// nsIOService methods:
|
||||
|
|
Загрузка…
Ссылка в новой задаче