Bug 1170837 - Add static GetPackageURI method to PackagedAppService r=honzab

This commit is contained in:
Valentin Gosu 2015-07-23 17:38:36 +02:00
parent 922ebfe6d5
commit 3cc3aa4723
2 changed files with 38 additions and 0 deletions

View File

@ -518,6 +518,41 @@ PackagedAppService::~PackagedAppService()
gPackagedAppService = nullptr;
}
/* static */ nsresult
PackagedAppService::GetPackageURI(nsIURI *aURI, nsIURI **aPackageURI)
{
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
if (!url) {
return NS_ERROR_INVALID_ARG;
}
nsAutoCString path;
nsresult rv = url->GetFilePath(path);
if (NS_FAILED(rv)) {
return rv;
}
int32_t pos = path.Find(PACKAGED_APP_TOKEN);
if (pos == kNotFound) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIURI> packageURI;
rv = aURI->CloneIgnoringRef(getter_AddRefs(packageURI));
if (NS_FAILED(rv)) {
return rv;
}
rv = packageURI->SetPath(Substring(path, 0, pos));
if (NS_FAILED(rv)) {
return rv;
}
packageURI.forget(aPackageURI);
return NS_OK;
}
NS_IMETHODIMP
PackagedAppService::RequestURI(nsIURI *aURI,
nsILoadContextInfo *aInfo,

View File

@ -61,6 +61,9 @@ private:
// Should be called on the main thread.
nsresult NotifyPackageDownloaded(nsCString aKey);
// Extract the URI of a package from the given packaged resource URI.
static nsresult GetPackageURI(nsIURI *aUri, nsIURI **aPackageURI);
// This class is used to write data into the cache entry corresponding to the
// packaged resource being downloaded.
// The PackagedAppDownloader will hold a ref to a CacheEntryWriter that