Bug 573149: Expose whether an addon requires a restart to enable/disable/uninstall/install. r=dtownsend

This commit is contained in:
Asaf Romano 2010-07-26 10:34:06 -07:00
Родитель 8d8e080229
Коммит 4741a5ddf9
9 изменённых файлов: 59 добавлений и 7 удалений

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

@ -880,6 +880,18 @@ var AddonManager = {
PENDING_INSTALL: 8,
PENDING_UPGRADE: 16,
// Constants for operations in Addon.operationsRequiringRestart
// Indicates that restart isn't required for any operation.
OP_NEEDS_RESTART_NONE: 0,
// Indicates that restart is required for enabling the addon.
OP_NEEDS_RESTART_ENABLE: 1,
// Indicates that restart is required for disabling the addon.
OP_NEEDS_RESTART_DISABLE: 2,
// Indicates that restart is required for uninstalling the addon.
OP_NEEDS_RESTART_UNINSTALL: 4,
// Indicates that restart is required for installing the addon.
OP_NEEDS_RESTART_INSTALL: 8,
// Constants for permissions in Addon.permissions.
// Indicates that the Addon can be uninstalled.
PERM_CAN_UNINSTALL: 1,

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

@ -421,6 +421,10 @@ function AddonWrapper(aTheme, aBeingEnabled) {
return pending;
});
this.__defineGetter__("operationsRequiringRestart", function() {
return AddonManager.OP_NEEDS_RESTART_NONE;
});
this.__defineGetter__("size", function() {
// The size changes depending on whether the theme is in use or not, this is
// probably not worth exposing.

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

@ -264,7 +264,11 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
});
this.__defineGetter__("pendingOperations", function() {
return 0;
return AddonManager.PENDING_NONE;
});
this.__defineGetter__("operationsRequiringRestart", function() {
return AddonManager.OP_NEEDS_RESTART_NONE;
});
this.__defineGetter__("permissions", function() {

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

@ -5149,6 +5149,20 @@ function AddonWrapper(aAddon) {
return pending;
});
this.__defineGetter__("operationsRequiringRestart", function() {
let ops = 0;
if (XPIProvider.installRequiresRestart(aAddon))
ops |= AddonManager.OP_NEEDS_RESTART_INSTALL;
if (XPIProvider.uninstallRequiresRestart(aAddon))
ops |= AddonManager.OP_NEEDS_RESTART_UNINSTALL;
if (XPIProvider.enableRequiresRestart(aAddon))
ops |= AddonManager.OP_NEEDS_RESTART_ENABLE;
if (XPIProvider.disableRequiresRestart(aAddon))
ops |= AddonManager.OP_NEEDS_RESTART_DISABLE;
return ops;
});
this.__defineGetter__("permissions", function() {
let permissions = 0;
if (!aAddon.appDisabled) {

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

@ -286,8 +286,10 @@ MockProvider.prototype = {
if (!this.started)
return;
let requiresRestart = (aAddon.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_INSTALL) != 0;
AddonManagerPrivate.callInstallListeners("onExternalInstall", null, aAddon,
null, false)
null, requiresRestart)
},
/**
@ -576,8 +578,8 @@ MockProvider.prototype = {
/***** Mock Addon object for the Mock Provider *****/
function MockAddon(aId, aName, aType, aRestartless) {
// Only set required attributes
function MockAddon(aId, aName, aType, aOperationsRequiringRestart) {
// Only set required attributes.
this.id = aId || "";
this.name = aName || "";
this.type = aType || "extension";
@ -592,8 +594,11 @@ function MockAddon(aId, aName, aType, aRestartless) {
this.creator = "";
this.pendingOperations = 0;
this.permissions = 0;
this._restartless = aRestartless || false;
this.operationsRequiringRestart = aOperationsRequiringRestart ||
(AddonManager.OP_NEEDS_RESTART_INSTALL |
AddonManager.OP_NEEDS_RESTART_UNINSTALL |
AddonManager.OP_NEEDS_RESTART_ENABLE |
AddonManager.OP_NEEDS_RESTART_DISABLE);
}
MockAddon.prototype = {

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

@ -61,6 +61,8 @@ function run_test_1() {
do_check_true(install.addon.hasResource("install.rdf"));
do_check_true(install.addon.hasResource("bootstrap.js"));
do_check_false(install.addon.hasResource("foo.bar"));
do_check_eq(install.addon.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
prepare_test({
@ -121,6 +123,8 @@ function run_test_2() {
]
});
do_check_eq(b1.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
b1.userDisabled = true;
ensure_test_completed();
@ -179,6 +183,8 @@ function run_test_4() {
]
});
do_check_eq(b1.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
b1.userDisabled = false;
ensure_test_completed();
@ -285,6 +291,8 @@ function run_test_7() {
]
});
do_check_eq(b1.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
b1.uninstall();
check_test_7();

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

@ -72,6 +72,8 @@ function run_test_1() {
});
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
do_check_neq(a1.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
a1.userDisabled = true;
do_check_eq(a1.aboutURL, "chrome://foo/content/about.xul");
do_check_eq(a1.optionsURL, "chrome://foo/content/options.xul");

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

@ -65,7 +65,8 @@ function run_test_1() {
do_check_true(install.addon.hasResource("install.rdf"));
do_check_eq(install.addon.install, install);
do_check_eq(install.addon.size, ADDON1_SIZE);
do_check_neq(install.addon.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
let file = do_get_addon("test_install1");
let uri = Services.io.newFileURI(file).spec;
do_check_eq(install.addon.getResourceURI("install.rdf").spec, "jar:" + uri + "!/install.rdf");

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

@ -60,6 +60,8 @@ function run_test_1() {
});
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
do_check_eq(a1.pendingOperations, 0);
do_check_neq(a1.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
a1.uninstall();
do_check_true(hasFlag(a1.pendingOperations, AddonManager.PENDING_UNINSTALL));
do_check_in_crash_annotation(addon1.id, addon1.version);