Bug 558834: Use targetPlatform when making compatibility judgements. r=robstrong

This commit is contained in:
Dave Townsend 2010-07-01 11:37:32 -07:00
Родитель 04448d9481
Коммит 7a7598e3b8
5 изменённых файлов: 217 добавлений и 4 удалений

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

@ -476,6 +476,10 @@ AddonWrapper.prototype = {
return true;
},
get isPlatformCompatible() {
return true;
},
get scope() {
return AddonManager.SCOPE_PROFILE;
},

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

@ -247,6 +247,10 @@ PluginWrapper.prototype = {
return true;
},
get isPlatformCompatible() {
return true;
},
get providesUpdatesSecurely() {
return true;
},

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

@ -232,6 +232,16 @@ function isUsableAddon(aAddon) {
// Hack to ensure the default theme is always usable
if (aAddon.type == "theme" && aAddon.internalName == XPIProvider.defaultSkin)
return true;
if (aAddon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
return false;
if (XPIProvider.checkUpdateSecurity && !aAddon.providesUpdatesSecurely)
return false;
if (!aAddon.isPlatformCompatible)
return false;
if (XPIProvider.checkCompatibility) {
if (!aAddon.isCompatible)
return false;
@ -240,9 +250,8 @@ function isUsableAddon(aAddon) {
if (!aAddon.matchingTargetApplication)
return false;
}
if (XPIProvider.checkUpdateSecurity && !aAddon.providesUpdatesSecurely)
return false;
return aAddon.blocklistState != Ci.nsIBlocklistService.STATE_BLOCKED;
return true;
}
this.__defineGetter__("gRDF", function() {
@ -4760,6 +4769,40 @@ AddonInternal.prototype = {
return this.isCompatibleWith();
},
get isPlatformCompatible() {
if (this.targetPlatforms.length == 0)
return true;
let matchedOS = false;
// If any targetPlatform matches the OS and contains an ABI then we will
// only match a targetPlatform that contains both the current OS and ABI
let needsABI = false;
// Some platforms do not specify an ABI, test against null in that case.
let abi = null;
try {
abi = Services.appinfo.XPCOMABI;
}
catch (e) { }
for (let i = 0; i < this.targetPlatforms.length; i++) {
let platform = this.targetPlatforms[i];
if (platform.os == Services.appinfo.OS) {
if (platform.abi) {
needsABI = true;
if (platform.abi === abi)
return true;
}
else {
matchedOS = true;
}
}
}
return matchedOS && !needsABI;
},
isCompatibleWith: function(aAppVersion, aPlatformVersion) {
let app = this.matchingTargetApplication;
if (!app)
@ -4938,7 +4981,7 @@ function createWrapper(aAddon) {
* the public API.
*/
function AddonWrapper(aAddon) {
["id", "version", "type", "isCompatible",
["id", "version", "type", "isCompatible", "isPlatformCompatible",
"providesUpdatesSecurely", "blocklistState", "appDisabled",
"userDisabled", "skinnable", "size"].forEach(function(aProp) {
this.__defineGetter__(aProp, function() aAddon[aProp]);

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

@ -362,6 +362,12 @@ function writeInstallRDFToDir(aData, aDir) {
rdf += writeLocaleStrings(aData);
if ("targetPlatforms" in aData) {
aData.targetPlatforms.forEach(function(aPlatform) {
rdf += "<em:targetPlatform>" + escapeXML(aPlatform) + "</em:targetPlatform>\n";
});
}
if ("targetApplications" in aData) {
aData.targetApplications.forEach(function(aApp) {
rdf += "<em:targetApplication><Description>\n";

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

@ -0,0 +1,156 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This verifies that the targetPlatform entries are checked when deciding
// if an add-on is incompatible.
// No targetPlatforms so should be compatible
var addon1 = {
id: "addon1@tests.mozilla.org",
version: "1.0",
name: "Test 1",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
// Matches the OS
var addon2 = {
id: "addon2@tests.mozilla.org",
version: "1.0",
name: "Test 2",
targetPlatforms: [
"XPCShell",
"WINNT_x86",
"XPCShell"
],
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
// Matches the OS and ABI
var addon3 = {
id: "addon3@tests.mozilla.org",
version: "1.0",
name: "Test 3",
targetPlatforms: [
"WINNT",
"XPCShell_noarch-spidermonkey"
],
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
// Doesn't match
var addon4 = {
id: "addon4@tests.mozilla.org",
version: "1.0",
name: "Test 4",
targetPlatforms: [
"WINNT_noarch-spidermonkey",
"Darwin",
"WINNT_noarch-spidermonkey"
],
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
// Matches the OS but since a different entry specifies ABI this doesn't match.
var addon5 = {
id: "addon5@tests.mozilla.org",
version: "1.0",
name: "Test 5",
targetPlatforms: [
"XPCShell",
"XPCShell_foo"
],
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
const profileDir = gProfD.clone();
profileDir.append("extensions");
// Set up the profile
function run_test() {
do_test_pending();
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
var dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
var dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
var dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon4, dest);
var dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir(addon5, dest);
restartManager(1);
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org",
"addon5@tests.mozilla.org"],
function([a1, a2, a3, a4, a5]) {
do_check_neq(a1, null);
do_check_false(a1.appDisabled);
do_check_true(a1.isPlatformCompatible);
do_check_true(a1.isActive);
do_check_true(isExtensionInAddonsList(profileDir, a1.id));
do_check_in_crash_annotation(addon1.id, addon1.version);
do_check_neq(a2, null);
do_check_false(a2.appDisabled);
do_check_true(a2.isPlatformCompatible);
do_check_true(a2.isActive);
do_check_true(isExtensionInAddonsList(profileDir, a2.id));
do_check_in_crash_annotation(addon2.id, addon2.version);
do_check_neq(a3, null);
do_check_false(a3.appDisabled);
do_check_true(a3.isPlatformCompatible);
do_check_true(a3.isActive);
do_check_true(isExtensionInAddonsList(profileDir, a3.id));
do_check_in_crash_annotation(addon3.id, addon3.version);
do_check_neq(a4, null);
do_check_true(a4.appDisabled);
do_check_false(a4.isPlatformCompatible);
do_check_false(a4.isActive);
do_check_false(isExtensionInAddonsList(profileDir, a4.id));
do_check_not_in_crash_annotation(addon4.id, addon4.version);
do_check_neq(a5, null);
do_check_true(a5.appDisabled);
do_check_false(a5.isPlatformCompatible);
do_check_false(a5.isActive);
do_check_false(isExtensionInAddonsList(profileDir, a5.id));
do_check_not_in_crash_annotation(addon5.id, addon5.version);
do_test_finished();
});
}