Bug 773214 - Make AddonInstall/AddonInstallWrapper aware of different icon sizes; r=Unfocused

This commit is contained in:
Geoff Lankow 2012-08-23 18:49:29 +12:00
parent e3dbe8e8d3
commit 91d6a852b1
5 changed files with 91 additions and 26 deletions

View File

@ -1276,8 +1276,8 @@ var AddonManagerInternal = {
* An optional hash of the add-on
* @param aName
* An optional placeholder name while the add-on is being downloaded
* @param aIconURL
* An optional placeholder icon URL while the add-on is being downloaded
* @param aIcons
* Optional placeholder icons while the add-on is being downloaded
* @param aVersion
* An optional placeholder version while the add-on is being downloaded
* @param aLoadGroup
@ -1285,7 +1285,7 @@ var AddonManagerInternal = {
* @throws if the aUrl, aCallback or aMimetype arguments are not specified
*/
getInstallForURL: function AMI_getInstallForURL(aUrl, aCallback, aMimetype,
aHash, aName, aIconURL,
aHash, aName, aIcons,
aVersion, aLoadGroup) {
if (!gStarted)
throw Components.Exception("AddonManager is not initialized",
@ -1311,9 +1311,15 @@ var AddonManagerInternal = {
throw Components.Exception("aName must be a string or null",
Cr.NS_ERROR_INVALID_ARG);
if (aIconURL && typeof aIconURL != "string")
throw Components.Exception("aIconURL must be a string or null",
Cr.NS_ERROR_INVALID_ARG);
if (aIcons) {
if (typeof aIcons == "string")
aIcons = { "32": aIcons };
else if (typeof aIcons != "object")
throw Components.Exception("aIcons must be a string, an object or null",
Cr.NS_ERROR_INVALID_ARG);
} else {
aIcons = {};
}
if (aVersion && typeof aVersion != "string")
throw Components.Exception("aVersion must be a string or null",
@ -1327,7 +1333,7 @@ var AddonManagerInternal = {
for (let provider of providers) {
if (callProvider(provider, "supportsMimetype", false, aMimetype)) {
callProvider(provider, "getInstallForURL", null,
aUrl, aHash, aName, aIconURL, aVersion, aLoadGroup,
aUrl, aHash, aName, aIcons, aVersion, aLoadGroup,
function(aInstall) {
safeCall(aCallback, aInstall);
});
@ -2221,10 +2227,10 @@ var AddonManager = {
#endif
getInstallForURL: function AM_getInstallForURL(aUrl, aCallback, aMimetype,
aHash, aName, aIconURL,
aHash, aName, aIcons,
aVersion, aLoadGroup) {
AddonManagerInternal.getInstallForURL(aUrl, aCallback, aMimetype, aHash,
aName, aIconURL, aVersion, aLoadGroup);
aName, aIcons, aVersion, aLoadGroup);
},
getInstallForFile: function AM_getInstallForFile(aFile, aCallback, aMimetype) {

View File

@ -1250,7 +1250,7 @@ var AddonRepository = {
if (aResult.xpiURL) {
AddonManager.getInstallForURL(aResult.xpiURL, callback,
"application/x-xpinstall", aResult.xpiHash,
addon.name, addon.iconURL, addon.version);
addon.name, addon.icons, addon.version);
}
else {
callback(null);

View File

@ -3143,8 +3143,8 @@ var XPIProvider = {
* A hash for the install
* @param aName
* A name for the install
* @param aIconURL
* An icon URL for the install
* @param aIcons
* Icon URLs for the install
* @param aVersion
* A version for the install
* @param aLoadGroup
@ -3152,11 +3152,11 @@ var XPIProvider = {
* @param aCallback
* A callback to pass the AddonInstall to
*/
getInstallForURL: function XPI_getInstallForURL(aUrl, aHash, aName, aIconURL,
getInstallForURL: function XPI_getInstallForURL(aUrl, aHash, aName, aIcons,
aVersion, aLoadGroup, aCallback) {
AddonInstall.createDownload(function getInstallForURL_createDownload(aInstall) {
aCallback(aInstall.wrapper);
}, aUrl, aHash, aName, aIconURL, aVersion, aLoadGroup);
}, aUrl, aHash, aName, aIcons, aVersion, aLoadGroup);
},
/**
@ -4050,6 +4050,7 @@ function AddonInstall(aInstallLocation, aUrl, aHash, aReleaseNotesURI,
this.hash = this.originalHash;
this.loadGroup = aLoadGroup;
this.listeners = [];
this.icons = {};
this.existingAddon = aExistingAddon;
this.error = 0;
if (aLoadGroup)
@ -4074,7 +4075,7 @@ AddonInstall.prototype = {
name: null,
type: null,
version: null,
iconURL: null,
icons: null,
releaseNotesURI: null,
sourceURI: null,
file: null,
@ -4101,7 +4102,7 @@ AddonInstall.prototype = {
this.name = aManifest.name;
this.type = aManifest.type;
this.version = aManifest.version;
this.iconURL = aManifest.iconURL;
this.icons = aManifest.icons;
this.releaseNotesURI = aManifest.releaseNotesURI ?
NetUtil.newURI(aManifest.releaseNotesURI) :
null
@ -4220,17 +4221,17 @@ AddonInstall.prototype = {
* An optional name for the add-on
* @param aType
* An optional type for the add-on
* @param aIconURL
* An optional icon for the add-on
* @param aIcons
* Optional icons for the add-on
* @param aVersion
* An optional version for the add-on
*/
initAvailableDownload: function AI_initAvailableDownload(aName, aType, aIconURL, aVersion, aCallback) {
initAvailableDownload: function AI_initAvailableDownload(aName, aType, aIcons, aVersion, aCallback) {
this.state = AddonManager.STATE_AVAILABLE;
this.name = aName;
this.type = aType;
this.version = aVersion;
this.iconURL = aIconURL;
this.icons = aIcons;
this.progress = 0;
this.maxProgress = -1;
@ -5157,14 +5158,14 @@ AddonInstall.createInstall = function AI_createInstall(aCallback, aFile) {
* A hash for the add-on
* @param aName
* A name for the add-on
* @param aIconURL
* An icon URL for the add-on
* @param aIcons
* An icon URLs for the add-on
* @param aVersion
* A version for the add-on
* @param aLoadGroup
* An nsILoadGroup to associate the download with
*/
AddonInstall.createDownload = function AI_createDownload(aCallback, aUri, aHash, aName, aIconURL,
AddonInstall.createDownload = function AI_createDownload(aCallback, aUri, aHash, aName, aIcons,
aVersion, aLoadGroup) {
let location = XPIProvider.installLocationsByName[KEY_APP_PROFILE];
let url = NetUtil.newURI(aUri);
@ -5173,7 +5174,7 @@ AddonInstall.createDownload = function AI_createDownload(aCallback, aUri, aHash,
if (url instanceof Ci.nsIFileURL)
install.initLocalInstall(aCallback);
else
install.initAvailableDownload(aName, null, aIconURL, aVersion, aCallback);
install.initAvailableDownload(aName, null, aIcons, aVersion, aCallback);
};
/**
@ -5204,7 +5205,7 @@ AddonInstall.createUpdate = function AI_createUpdate(aCallback, aAddon, aUpdate)
}
else {
install.initAvailableDownload(aAddon.selectedLocale.name, aAddon.type,
aAddon.iconURL, aUpdate.version, aCallback);
aAddon.icons, aUpdate.version, aCallback);
}
};
@ -5221,11 +5222,13 @@ function AddonInstallWrapper(aInstall) {
});
#endif
["name", "type", "version", "iconURL", "releaseNotesURI", "file", "state", "error",
["name", "type", "version", "icons", "releaseNotesURI", "file", "state", "error",
"progress", "maxProgress", "certificate", "certName"].forEach(function(aProp) {
this.__defineGetter__(aProp, function AIW_propertyGetter() aInstall[aProp]);
}, this);
this.__defineGetter__("iconURL", function AIW_iconURL() aInstall.icons[32]);
this.__defineGetter__("existingAddon", function AIW_existingAddonGetter() {
return createWrapper(aInstall.existingAddon);
});

View File

@ -0,0 +1,55 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var addon_url = "http://localhost:4444/test.xpi";
var icon32_url = "http://localhost:4444/icon.png";
var icon64_url = "http://localhost:4444/icon64.png";
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
startupManager();
test_1();
}
function test_1() {
AddonManager.getInstallForURL(addon_url, function(aInstall) {
do_check_eq(aInstall.iconURL, null);
do_check_neq(aInstall.icons, null);
do_check_eq(aInstall.icons[32], undefined);
do_check_eq(aInstall.icons[64], undefined);
test_2();
}, "application/x-xpinstall", null, null, null, null, null);
}
function test_2() {
AddonManager.getInstallForURL(addon_url, function(aInstall) {
do_check_eq(aInstall.iconURL, icon32_url);
do_check_neq(aInstall.icons, null);
do_check_eq(aInstall.icons[32], icon32_url);
do_check_eq(aInstall.icons[64], undefined);
test_3();
}, "application/x-xpinstall", null, null, icon32_url, null, null);
}
function test_3() {
AddonManager.getInstallForURL(addon_url, function(aInstall) {
do_check_eq(aInstall.iconURL, icon32_url);
do_check_neq(aInstall.icons, null);
do_check_eq(aInstall.icons[32], icon32_url);
do_check_eq(aInstall.icons[64], undefined);
test_4();
}, "application/x-xpinstall", null, null, { "32": icon32_url }, null, null);
}
function test_4() {
AddonManager.getInstallForURL(addon_url, function(aInstall) {
do_check_eq(aInstall.iconURL, icon32_url);
do_check_neq(aInstall.icons, null);
do_check_eq(aInstall.icons[32], icon32_url);
do_check_eq(aInstall.icons[64], icon64_url);
do_test_finished();
}, "application/x-xpinstall", null, null, { "32": icon32_url, "64": icon64_url }, null, null);
}

View File

@ -169,6 +169,7 @@ skip-if = os == "android"
[test_hasbinarycomponents.js]
[test_hotfix.js]
[test_install.js]
[test_install_icons.js]
# Bug 676992: test consistently hangs on Android
skip-if = os == "android"
[test_install_strictcompat.js]