Bug 1525762: Part 1c - Resolve built-in add-on resource: URIs at startup, not install. r=aswan

It's possible for the application install location to vary from session to
session, particularly when the same profile is used with multiple app
versions, or with both packed and unpacked builds. Resolving resource: URIs at
install time causes problems in those instances, since it will always point to
the inital app location.

Resolving the resource URIs at runtime solves this.

Differential Revision: https://phabricator.services.mozilla.com/D24617

--HG--
extra : rebase_source : 9597c34e7349e6f4a524027c2b041c497c5c6632
This commit is contained in:
Kris Maglione 2019-03-22 09:34:29 -07:00
parent f45da34602
commit b8ed7b46a0
3 changed files with 23 additions and 10 deletions

View File

@ -275,6 +275,10 @@ class AddonInternal {
return this._wrapper;
}
get resolvedRootURI() {
return XPIInternal.maybeResolveURI(Services.io.newURI(this.rootURI));
}
addedToDatabase() {
this._key = `${this.location.name}:${this.id}`;
this.inDatabase = true;

View File

@ -375,7 +375,7 @@ function waitForAllPromises(promises) {
* be read
*/
async function loadManifestFromWebManifest(aPackage) {
let extension = new ExtensionData(aPackage.rootURI);
let extension = new ExtensionData(XPIInternal.maybeResolveURI(aPackage.rootURI));
let manifest = await extension.loadManifest();
@ -3656,14 +3656,9 @@ var XPIInstall = {
throw new Error("Built-in addons must use resource: URLS");
}
let root = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsISubstitutingProtocolHandler)
.resolveURI(baseURL);
let rootURI = Services.io.newURI(root);
// Enough of the Package interface to allow loadManifest() to work.
let pkg = {
rootURI,
rootURI: baseURL,
filePath: baseURL,
file: null,
verifySignedState() {
@ -3679,7 +3674,7 @@ var XPIInstall = {
};
let addon = await loadManifest(pkg, XPIInternal.BuiltInLocation);
addon.rootURI = root;
addon.rootURI = base;
await this._activateAddon(addon);
},

View File

@ -43,6 +43,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
XPCOMUtils.defineLazyServiceGetters(this, {
aomStartup: ["@mozilla.org/addons/addon-manager-startup;1", "amIAddonManagerStartup"],
resProto: ["@mozilla.org/network/protocol;1?name=resource", "nsISubstitutingProtocolHandler"],
spellCheck: ["@mozilla.org/spellchecker/engine;1", "mozISpellCheckingEngine"],
timerManager: ["@mozilla.org/updates/timer-manager;1", "nsIUpdateTimerManager"],
});
@ -325,6 +326,13 @@ function buildJarURI(aJarfile, aPath) {
return Services.io.newURI(uri);
}
function maybeResolveURI(uri) {
if (uri.schemeIs("resource")) {
return Services.io.newURI(resProto.resolveURI(uri));
}
return uri;
}
/**
* Iterates over the entries in a given directory.
*
@ -554,6 +562,10 @@ class XPIState {
return encoded`${this.id}:${this.version}`;
}
get resolvedRootURI() {
return maybeResolveURI(Services.io.newURI(this.rootURI));
}
/**
* Update the XPIState to match an XPIDatabase entry; if 'enabled' is changed to true,
* update the last-modified time. This should probably be made async, but for now we
@ -598,7 +610,8 @@ class XPIState {
// Built-in addons should have jar: rootURIs, use the mod time
// for the containing jar file for those.
if (!file) {
let fileUrl = Services.io.newURI(this.rootURI);
let fileUrl = this.resolvedRootURI;
if (fileUrl instanceof Ci.nsIJARURI) {
fileUrl = fileUrl.JARFile;
}
@ -1685,7 +1698,7 @@ class BootstrapScope {
let params = {
id: addon.id,
version: addon.version,
resourceURI: Services.io.newURI(addon.rootURI),
resourceURI: addon.resolvedRootURI,
signedState: addon.signedState,
temporarilyInstalled: addon.location.isTemporary,
builtIn: addon.location.isBuiltin,
@ -2879,6 +2892,7 @@ var XPIInternal = {
getURIForResourceInFile,
isXPI,
iterDirectory,
maybeResolveURI,
migrateAddonLoader,
resolveDBReady,
};