Bug 559850: Update providers to have consistent properties. r=robstrong

This commit is contained in:
Dave Townsend 2010-04-26 10:48:27 -07:00
Родитель 18492f29cf
Коммит c7f9d1cc3f
4 изменённых файлов: 72 добавлений и 23 удалений

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

@ -468,6 +468,10 @@ AddonWrapper.prototype = {
return true;
},
get scope() {
return AddonManager.SCOPE_PROFILE;
},
// Lightweight themes are always compatible
isCompatibleWith: function(appVersion, platformVersion) {
return true;

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

@ -43,6 +43,7 @@ const Ci = Components.interfaces;
var EXPORTED_SYMBOLS = [];
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
/**
* Logs a debug message.
@ -199,12 +200,12 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
this.__defineGetter__("id", function() aId);
this.__defineGetter__("type", function() "plugin");
this.__defineGetter__("name", function() aName);
this.__defineGetter__("creator", function() "");
this.__defineGetter__("description", function() safedesc);
this.__defineGetter__("version", function() aTags[0].version);
this.__defineGetter__("homepageURL", function() homepageURL);
this.__defineGetter__("isActive", function() !aTags[0].blocklisted && !aTags[0].disabled);
this.__defineGetter__("isCompatible", function() true);
this.__defineGetter__("appDisabled", function() aTags[0].blocklisted);
this.__defineGetter__("userDisabled", function() aTags[0].disabled);
this.__defineSetter__("userDisabled", function(aVal) {
@ -219,6 +220,33 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
return aVal;
});
this.__defineGetter__("blocklistState", function() {
let bs = Cc["@mozilla.org/extensions/blocklist;1"].
getService(Ci.nsIBlocklistService);
return bs.getPluginBlocklistState(aTags[0]);
});
this.__defineGetter__("scope", function() {
let path = aTags[0].fullpath;
// Plugins inside the application directory are in the application scope
let dir = Services.dirsvc.get("APlugns", Ci.nsILocalFile);
if (path.substring(0, dir.path.length) == dir.path)
return AddonManager.SCOPE_APPLICATION;
// Plugins inside the profile directory are in the profile scope
dir = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
if (path.substring(0, dir.path.length) == dir.path)
return AddonManager.SCOPE_PROFILE;
// Plugins anywhere else in the user's home are in the user scope
dir = Services.dirsvc.get("Home", Ci.nsILocalFile);
if (path.substring(0, dir.path.length) == dir.path)
return AddonManager.SCOPE_USER;
// Any other locations are system scope
return AddonManager.SCOPE_SYSTEM;
});
this.__defineGetter__("pendingOperations", function() {
return 0;
});
@ -233,28 +261,29 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
}
return permissions;
});
this.uninstall = function() {
throw new Error("Cannot uninstall plugins");
};
this.cancelUninstall = function() {
throw new Error("Plugin is not marked to be uninstalled");
};
this.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) {
throw new Error("Cannot search for updates for plugins");
};
this.hasResource = function(aPath) {
return false;
},
this.getResourceURL = function(aPath) {
return null;
}
}
PluginWrapper.prototype = { };
PluginWrapper.prototype = {
get isCompatible() {
return true;
},
get providesUpdatesSecurely() {
return true;
},
isCompatibleWith: function(aAppVerison, aPlatformVersion) {
return true;
},
findUpdates: function(aListener, aReason, aAppVersion, aPlatformVersion) {
if ("onNoCompatibilityUpdateAvailable" in aListener)
aListener.onNoCompatibilityUpdateAvailable(this);
if ("onNoUpdateAvailable" in aListener)
aListener.onNoUpdateAvailable(this);
if ("onUpdateFinished" in aListener)
aListener.onUpdateFinished(this);
}
};
AddonManagerPrivate.registerProvider(PluginProvider);

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

@ -30,10 +30,22 @@ function run_test_1() {
AddonManager.getAddonByID(gID, function(p) {
do_check_neq(p, null)
do_check_eq(p.name, "Test Plug-in");
do_check_eq(p.description, "Plug-in for testing purposes.");
do_check_eq(p.creator, "");
do_check_eq(p.version, "1.0.0.0");
do_check_eq(p.type, "plugin");
do_check_false(p.userDisabled);
do_check_false(p.appDisabled);
do_check_true(p.isActive);
do_check_eq(p.name, "Test Plug-in");
do_check_true(p.isCompatible);
do_check_true(p.providesUpdatesSecurely);
do_check_eq(p.blocklistState, 0);
do_check_eq(p.permissions, AddonManager.PERM_CAN_DISABLE);
do_check_eq(p.pendingOperations, 0);
do_check_eq(p.scope, AddonManager.SCOPE_APPLICATION);
do_check_true("isCompatibleWith" in p);
do_check_true("findUpdates" in p);
run_test_2(p);
});

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

@ -227,6 +227,7 @@ function run_test_3() {
do_check_neq(null, p1);
do_check_eq(p1.name, "Test LW Theme");
do_check_eq(p1.version, "1");
do_check_eq(p1.type, "theme");
do_check_eq(p1.description, "A test theme");
do_check_eq(p1.creator, "Mozilla");
do_check_eq(p1.homepageURL, "http://localhost:4444/data/index.html");
@ -241,6 +242,9 @@ function run_test_3() {
do_check_true(p1.isActive);
do_check_eq(p1.pendingOperations, 0);
do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL);
do_check_eq(p1.scope, AddonManager.SCOPE_PROFILE);
do_check_true("isCompatibleWith" in p1);
do_check_true("findUpdates" in p1);
AddonManager.getAddonsByTypes(["theme"], function(addons) {
let seen = false;