diff --git a/build/automation.py.in b/build/automation.py.in index e1d252cdc2d7..a195d2345f7e 100644 --- a/build/automation.py.in +++ b/build/automation.py.in @@ -363,6 +363,8 @@ user_pref("app.update.enabled", false); // Only load extensions from the application and user profile // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION user_pref("extensions.enabledScopes", 5); +// Disable metadata caching for installed add-ons by default +user_pref("extensions.getAddons.cache.enabled", false); user_pref("extensions.testpilot.runStudies", false); diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index d1c36eee7db7..882419d5d72c 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -4562,6 +4562,25 @@ AddonInstall.prototype = { * XPI is incorrectly signed */ loadManifest: function AI_loadManifest(aCallback) { + function addRepositoryData(aAddon) { + // Try to load from the existing cache first + AddonRepository.getCachedAddonByID(aAddon.id, function(aRepoAddon) { + if (aRepoAddon) { + aAddon._repositoryAddon = aRepoAddon; + aCallback(); + return; + } + + // It wasn't there so try to re-download it + AddonRepository.cacheAddons([aAddon.id], function() { + AddonRepository.getCachedAddonByID(aAddon.id, function(aRepoAddon) { + aAddon._repositoryAddon = aRepoAddon; + aCallback(); + }); + }); + }); + } + let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"]. createInstance(Ci.nsIZipReader); try { @@ -4599,7 +4618,10 @@ AddonInstall.prototype = { } if (this.addon.type == "multipackage") { - this.loadMultipackageManifests(zipreader, aCallback); + let self = this; + this.loadMultipackageManifests(zipreader, function() { + addRepositoryData(self.addon); + }); return; } @@ -4618,7 +4640,7 @@ AddonInstall.prototype = { //if (newIcon) // this.iconURL = newIcon; - aCallback(); + addRepositoryData(this.addon); }, observe: function AI_observe(aSubject, aTopic, aData) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/data/test_install.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_install.xml new file mode 100644 index 000000000000..7c47f8a42bf4 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_install.xml @@ -0,0 +1,34 @@ + + + + Real Test 2 + Extension + addon2@tests.mozilla.org + 1.0 + + + Test Creator + http://example.com/creator.html + + + Public + Repository summary + Repository description + + + Firefox + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 0 + * + + + SeaMonkey + {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} + 0 + * + + + ALL + http://example.com/browser/toolkit/mozapps/extensions/test/browser/addons/browser_install1_2.xpi + + diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_install.js b/toolkit/mozapps/extensions/test/xpcshell/test_install.js index 1e5080030ebd..fe5c3bfbb1f9 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js @@ -1169,7 +1169,7 @@ function run_test_18() { a2.uninstall(); restartManager(); - end_test(); + run_test_19(); }); } }); @@ -1181,3 +1181,57 @@ function run_test_18() { aInstall.install(); }, "application/x-xpinstall"); } + +// Checks that metadata is downloaded for new installs and is visible before and +// after restart +function run_test_19() { + Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true); + Services.prefs.setCharPref("extensions.getAddons.get.url", + "http://localhost:4444/data/test_install.xml"); + + let url = "http://localhost:4444/addons/test_install2_1.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallEnded: function(aInstall, aAddon) { + do_check_eq(aAddon.fullDescription, "Repository description"); + + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_eq(a2.fullDescription, "Repository description"); + + a2.uninstall(); + restartManager(); + + run_test_20(); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); +} + +// Do the same again to make sure it works when the data is already in the cache +function run_test_20() { + let url = "http://localhost:4444/addons/test_install2_1.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallEnded: function(aInstall, aAddon) { + do_check_eq(aAddon.fullDescription, "Repository description"); + + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_eq(a2.fullDescription, "Repository description"); + + a2.uninstall(); + restartManager(); + + Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false); + end_test(); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); +}