Bug 1285289 - Use the URL of the addon sourceBundle as the sourceURI of temporary addon. r?aswan
MozReview-Commit-ID: KKeIFOMN3yo
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -7610,16 +7610,26 @@ function defineAddonWrapperProperty(name
defineAddonWrapperProperty(aProp, function() {
return new Date(addonFor(this)[aProp]);
});
});
["sourceURI", "releaseNotesURI"].forEach(function(aProp) {
defineAddonWrapperProperty(aProp, function() {
let addon = addonFor(this);
+
+ // Temporary Installed Addons do not have a "sourceURI",
+ // But we can use the "_sourceBundle" as an alternative,
+ // which points to the path of the addon xpi installed
+ // or its source dir (if it has been installed from a
+ // directory).
+ if (aProp == "sourceURI" && this.temporarilyInstalled) {
+ return Services.io.newFileURI(addon._sourceBundle);
+ }
+
let [target, fromRepo] = chooseValue(addon, addon, aProp);
if (!target)
return null;
if (fromRepo)
return target;
return NetUtil.newURI(target);
});
});
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
@@ -52,16 +52,21 @@ add_task(function* test_implicit_id_temp
do_check_eq(addon, null);
let xpifile = do_get_file(IMPLICIT_ID_XPI);
yield AddonManager.installTemporaryAddon(xpifile);
addon = yield promiseAddonByID(IMPLICIT_ID_ID);
do_check_neq(addon, null);
+ // The sourceURI of a temporary installed addon should be equal to the
+ // file url of the installed xpi file.
+ do_check_eq(addon.sourceURI && addon.sourceURI.spec,
+ Services.io.newFileURI(xpifile).spec);
+
addon.uninstall();
});
// We should be able to temporarily install an unsigned web extension
// that does not have an ID in its manifest.
add_task(function* test_unsigned_no_id_temp_install() {
if (!TEST_UNPACKED) {
do_print("This test does not apply when using packed extensions");
@@ -74,16 +79,21 @@ add_task(function* test_unsigned_no_id_t
version: "1.0"
};
const addonDir = writeWebManifestForExtension(manifest, gTmpD,
"the-addon-sub-dir");
const addon = yield AddonManager.installTemporaryAddon(addonDir);
ok(addon.id, "ID should have been auto-generated");
+ // The sourceURI of a temporary installed addon should be equal to the
+ // file url of the installed source dir.
+ do_check_eq(addon.sourceURI && addon.sourceURI.spec,
+ Services.io.newFileURI(addonDir).spec);
+
// Install the same directory again, as if re-installing or reloading.
const secondAddon = yield AddonManager.installTemporaryAddon(addonDir);
// The IDs should be the same.
equal(secondAddon.id, addon.id);
secondAddon.uninstall();
addonDir.remove(true);
});