mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1383215: Part 2 - Split out URI resolution code into ResolveURI helper. r=mccr8
MozReview-Commit-ID: Bfr67WQPq9l --HG-- extra : rebase_source : bbf9090d03c15d6c541aec12b090ab4dadcdab68 extra : histedit_source : 68a54268e601c1cb7521abb305fad2288ab4a03a
This commit is contained in:
parent
8f6455242f
commit
b136b1f059
@ -145,6 +145,47 @@ canonicalizeBase(nsAutoCString &spec,
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* ResolveURI transforms a chrome: or resource: URI into the URI for its
|
||||
* underlying resource, or returns any other URI unchanged.
|
||||
*/
|
||||
nsresult
|
||||
ResolveURI(nsIURI *in, nsIURI **out)
|
||||
{
|
||||
bool equals;
|
||||
nsresult rv;
|
||||
|
||||
// Resolve resource:// URIs. At the end of this if/else block, we
|
||||
// have both spec and uri variables identifying the same URI.
|
||||
if (NS_SUCCEEDED(in->SchemeIs("resource", &equals)) && equals) {
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> ph;
|
||||
rv = ioService->GetProtocolHandler("resource", getter_AddRefs(ph));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIResProtocolHandler> irph(do_QueryInterface(ph, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString spec;
|
||||
rv = irph->ResolveURI(in, spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return ioService->NewURI(spec, nullptr, nullptr, out);
|
||||
} else if (NS_SUCCEEDED(in->SchemeIs("chrome", &equals)) && equals) {
|
||||
nsCOMPtr<nsIChromeRegistry> chromeReg =
|
||||
mozilla::services::GetChromeRegistryService();
|
||||
if (!chromeReg)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return chromeReg->ConvertChromeURL(in, out);
|
||||
}
|
||||
|
||||
*out = do_AddRef(in).take();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* PathifyURI transforms uris into useful zip paths
|
||||
* to make it easier to manipulate startup cache entries
|
||||
@ -175,41 +216,14 @@ PathifyURI(nsIURI *in, nsACString &out)
|
||||
{
|
||||
bool equals;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri = in;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = ResolveURI(in, getter_AddRefs(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString spec;
|
||||
|
||||
// Resolve resource:// URIs. At the end of this if/else block, we
|
||||
// have both spec and uri variables identifying the same URI.
|
||||
if (NS_SUCCEEDED(in->SchemeIs("resource", &equals)) && equals) {
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> ph;
|
||||
rv = ioService->GetProtocolHandler("resource", getter_AddRefs(ph));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIResProtocolHandler> irph(do_QueryInterface(ph, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = irph->ResolveURI(in, spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = ioService->NewURI(spec, nullptr, nullptr, getter_AddRefs(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
if (NS_SUCCEEDED(in->SchemeIs("chrome", &equals)) && equals) {
|
||||
nsCOMPtr<nsIChromeRegistry> chromeReg =
|
||||
mozilla::services::GetChromeRegistryService();
|
||||
if (!chromeReg)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = chromeReg->ConvertChromeURL(in, getter_AddRefs(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
rv = uri->GetSpec(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
rv = uri->GetSpec(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!canonicalizeBase(spec, out)) {
|
||||
if (NS_SUCCEEDED(uri->SchemeIs("file", &equals)) && equals) {
|
||||
|
@ -38,6 +38,9 @@ nsresult
|
||||
NewBufferFromStorageStream(nsIStorageStream *storageStream,
|
||||
UniquePtr<char[]>* buffer, uint32_t* len);
|
||||
|
||||
nsresult
|
||||
ResolveURI(nsIURI *in, nsIURI **out);
|
||||
|
||||
nsresult
|
||||
PathifyURI(nsIURI *in, nsACString &out);
|
||||
} // namespace scache
|
||||
|
Loading…
Reference in New Issue
Block a user