Bug 1752212 - Part 1: Pass loader type to PathifyURI. r=nbp

Differential Revision: https://phabricator.services.mozilla.com/D143574
This commit is contained in:
Tooru Fujisawa 2022-04-13 11:41:10 +00:00
Родитель 21c7930924
Коммит 7f252a9982
5 изменённых файлов: 52 добавлений и 39 удалений

Просмотреть файл

@ -208,8 +208,8 @@ nsresult nsXULPrototypeCache::WritePrototype(
nsresult nsXULPrototypeCache::GetInputStream(nsIURI* uri,
nsIObjectInputStream** stream) {
nsAutoCString spec(kXULCachePrefix);
nsresult rv = PathifyURI(uri, spec);
nsAutoCString spec;
nsresult rv = PathifyURI(kXULCachePrefix, uri, spec);
if (NS_FAILED(rv)) return NS_ERROR_NOT_AVAILABLE;
const char* buf;
@ -278,8 +278,8 @@ nsresult nsXULPrototypeCache::FinishOutputStream(nsIURI* uri) {
NS_ENSURE_SUCCESS(rv, rv);
if (!mStartupCacheURITable.GetEntry(uri)) {
nsAutoCString spec(kXULCachePrefix);
rv = PathifyURI(uri, spec);
nsAutoCString spec;
rv = PathifyURI(kXULCachePrefix, uri, spec);
if (NS_FAILED(rv)) return NS_ERROR_NOT_AVAILABLE;
rv = sc->PutBuffer(spec.get(), std::move(buf), len);
if (NS_SUCCEEDED(rv)) {
@ -298,8 +298,8 @@ nsresult nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists) {
*exists = true;
return NS_OK;
}
nsAutoCString spec(kXULCachePrefix);
nsresult rv = PathifyURI(uri, spec);
nsAutoCString spec;
nsresult rv = PathifyURI(kXULCachePrefix, uri, spec);
if (NS_FAILED(rv)) {
*exists = false;
return NS_OK;

Просмотреть файл

@ -747,8 +747,9 @@ nsresult mozJSComponentLoader::ObjectForLocation(
aInfo.EnsureResolvedURI();
nsAutoCString cachePath(JS_CACHE_PREFIX("non-syntactic"));
rv = PathifyURI(aInfo.ResolvedURI(), cachePath);
nsAutoCString cachePath;
rv = PathifyURI(JS_CACHE_PREFIX("non-syntactic"), aInfo.ResolvedURI(),
cachePath);
NS_ENSURE_SUCCESS(rv, rv);
JS::DecodeOptions decodeOptions;

Просмотреть файл

@ -89,11 +89,10 @@ static void SubscriptCachePath(JSContext* cx, nsIURI* uri,
// StartupCache must distinguish between non-syntactic vs global when
// computing the cache key.
if (!JS_IsGlobalObject(targetObj)) {
cachePath.AssignLiteral(JSSUB_CACHE_PREFIX("non-syntactic"));
PathifyURI(JSSUB_CACHE_PREFIX("non-syntactic"), uri, cachePath);
} else {
cachePath.AssignLiteral(JSSUB_CACHE_PREFIX("global"));
PathifyURI(JSSUB_CACHE_PREFIX("global"), uri, cachePath);
}
PathifyURI(uri, cachePath);
}
static void ReportError(JSContext* cx, const nsACString& msg) {

Просмотреть файл

@ -166,32 +166,7 @@ nsresult ResolveURI(nsIURI* in, nsIURI** out) {
return NS_OK;
}
/**
* PathifyURI transforms uris into useful zip paths
* to make it easier to manipulate startup cache entries
* using standard zip tools.
* Transformations applied:
* * resource:// URIs are resolved to their corresponding file/jar URI to
* canonicalize resources URIs other than gre and app.
* * Paths under GRE or APP directory have their base path replaced with
* resource/gre or resource/app to avoid depending on install location.
* * jar:file:///path/to/file.jar!/sub/path urls are replaced with
* /path/to/file.jar/sub/path
*
* The result is appended to the string passed in. Adding a prefix before
* calling is recommended to avoid colliding with other cache users.
*
* For example, in the js loader (string is prefixed with jsloader by caller):
* resource://gre/modules/XPCOMUtils.jsm or
* file://$GRE_DIR/modules/XPCOMUtils.jsm or
* jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm becomes
* jsloader/resource/gre/modules/XPCOMUtils.jsm
* file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
* jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js
* jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
* jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
*/
nsresult PathifyURI(nsIURI* in, nsACString& out) {
static nsresult PathifyURIImpl(nsIURI* in, nsACString& out) {
nsCOMPtr<nsIURI> uri;
nsresult rv = ResolveURI(in, getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
@ -219,7 +194,7 @@ nsresult PathifyURI(nsIURI* in, nsACString& out) {
rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = PathifyURI(jarFileURI, out);
rv = PathifyURIImpl(jarFileURI, out);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString path;
@ -238,5 +213,12 @@ nsresult PathifyURI(nsIURI* in, nsACString& out) {
return NS_OK;
}
nsresult PathifyURI(const char* loaderType, size_t loaderTypeLength, nsIURI* in,
nsACString& out) {
out.AssignASCII(loaderType, loaderTypeLength);
return PathifyURIImpl(in, out);
}
} // namespace scache
} // namespace mozilla

Просмотреть файл

@ -37,7 +37,38 @@ nsresult NewBufferFromStorageStream(nsIStorageStream* storageStream,
nsresult ResolveURI(nsIURI* in, nsIURI** out);
nsresult PathifyURI(nsIURI* in, nsACString& out);
// PathifyURI transforms uris into useful zip paths
// to make it easier to manipulate startup cache entries
// using standard zip tools.
//
// Transformations applied:
// * resource:// URIs are resolved to their corresponding file/jar URI to
// canonicalize resources URIs other than gre and app.
// * Paths under GRE or APP directory have their base path replaced with
// resource/gre or resource/app to avoid depending on install location.
// * jar:file:///path/to/file.jar!/sub/path urls are replaced with
// /path/to/file.jar/sub/path
//
// The result is concatenated with loaderType and stored into the string
// passed in.
//
// For example, in the js loader (loaderType = "jsloader"):
// resource://gre/modules/XPCOMUtils.jsm or
// file://$GRE_DIR/modules/XPCOMUtils.jsm or
// jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm becomes
// jsloader/resource/gre/modules/XPCOMUtils.jsm
// file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
// jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js
// jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
// jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
nsresult PathifyURI(const char* loaderType, size_t loaderTypeLength, nsIURI* in,
nsACString& out);
template <int N>
nsresult PathifyURI(const char (&loaderType)[N], nsIURI* in, nsACString& out) {
return PathifyURI(loaderType, N - 1, in, out);
}
} // namespace scache
} // namespace mozilla