Bug 553092: Initialise the permissions manager on startup. r=robstrong

This commit is contained in:
Dave Townsend 2010-04-26 12:19:18 -07:00
parent 91ecf90f1a
commit 31ac0d3f18
5 changed files with 109 additions and 63 deletions

View File

@ -7522,27 +7522,8 @@ var LightWeightThemeWebInstaller = {
},
_isAllowed: function (node) {
var pm = Services.perms;
var prefs = [["xpinstall.whitelist.add", pm.ALLOW_ACTION],
["xpinstall.whitelist.add.36", pm.ALLOW_ACTION],
["xpinstall.blacklist.add", pm.DENY_ACTION]];
prefs.forEach(function ([pref, permission]) {
try {
var hosts = gPrefService.getCharPref(pref);
} catch (e) {}
if (hosts) {
hosts.split(",").forEach(function (host) {
pm.add(makeURI("http://" + host), "install", permission);
});
gPrefService.setCharPref(pref, "");
}
});
var uri = node.ownerDocument.documentURIObject;
return pm.testPermission(uri, "install") == pm.ALLOW_ACTION;
return Services.perms.testPermission(uri, "install") == pm.ALLOW_ACTION;
},
_getThemeFromNode: function (node) {

View File

@ -208,12 +208,6 @@ var gPermissionManager = {
.getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "perm-changed", false);
if (this._type == "install") {
var enumerator = this._pm.enumerator;
if (!enumerator.hasMoreElements())
this._updatePermissions();
}
this._loadPermissions();
urlField.focus();
@ -363,43 +357,6 @@ var gPermissionManager = {
}
},
_updatePermissions: function ()
{
try {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var pbi = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
var prefList = [["xpinstall.whitelist.add", nsIPermissionManager.ALLOW_ACTION],
["xpinstall.whitelist.add.36", nsIPermissionManager.ALLOW_ACTION],
["xpinstall.blacklist.add", nsIPermissionManager.DENY_ACTION]];
for (var i = 0; i < prefList.length; ++i) {
try {
// this pref is a comma-delimited list of hosts
var hosts = pbi.getCharPref(prefList[i][0]);
} catch(ex) {
continue;
}
if (!hosts)
continue;
hostList = hosts.split(",");
var capability = prefList[i][1];
for (var j = 0; j < hostList.length; ++j) {
// trim leading and trailing spaces
var host = hostList[j].replace(/^\s*/,"").replace(/\s*$/,"");
try {
var uri = ioService.newURI("http://" + host, null, null);
this._pm.add(uri, this._type, capability);
} catch(ex) { }
}
pbi.setCharPref(prefList[i][0], "");
}
} catch(ex) { }
},
setHost: function (aHost)
{
document.getElementById("url").value = aHost;

View File

@ -521,6 +521,7 @@ var AddonManagerInternal = {
callProvider(this.providers[i], "isInstallAllowed", null, aURI))
return true;
}
return false;
},
/**

View File

@ -66,6 +66,8 @@ const PREF_EM_EXTENSION_FORMAT = "extensions.";
const PREF_EM_ENABLED_SCOPES = "extensions.enabledScopes";
const PREF_XPI_ENABLED = "xpinstall.enabled";
const PREF_XPI_WHITELIST_REQUIRED = "xpinstall.whitelist.required";
const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add";
const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add";
const DIR_EXTENSIONS = "extensions";
const DIR_STAGE = "staged";
@ -1504,6 +1506,31 @@ var XPIProvider = {
return changed;
},
/**
* Imports the xpinstall permissions from preferences into the permissions
* manager for the user to change later.
*/
importPermissions: function XPI_importPermissions() {
function importList(aPrefBranch, aAction) {
let list = Services.prefs.getChildList(aPrefBranch, {});
list.forEach(function(aPref) {
let hosts = Prefs.getCharPref(aPref, "");
if (!hosts)
return;
hosts.split(",").forEach(function(aHost) {
Services.perms.add(NetUtil.newURI("http://" + aHost), XPI_PERMISSION,
aAction);
});
});
}
importList(PREF_XPI_WHITELIST_PERMISSIONS,
Ci.nsIPermissionManager.ALLOW_ACTION);
importList(PREF_XPI_BLACKLIST_PERMISSIONS,
Ci.nsIPermissionManager.DENY_ACTION);
},
/**
* Checks for any changes that have occurred since the last time the
* application was launched.
@ -1516,6 +1543,10 @@ var XPIProvider = {
checkForChanges: function XPI_checkForChanges(aAppChanged) {
LOG("checkForChanges");
// Import the website installation permisisons if the applicatio has changed
if (aAppChanged)
this.importPermissions();
// First install any new add-ons into the locations, we'll detect these when
// we read the install state
let manifests = {};

View File

@ -0,0 +1,76 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
Components.utils.import("resource://gre/modules/NetUtil.jsm");
// Checks that permissions set in preferences are correctly imported but can
// be removed by the user.
const XPI_MIMETYPE = "application/x-xpinstall";
function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
Services.prefs.setCharPref("xpinstall.whitelist.add", "test1.com,test2.com");
Services.prefs.setCharPref("xpinstall.whitelist.add.36", "test3.com,www.test4.com");
Services.prefs.setCharPref("xpinstall.whitelist.add.test5", "test5.com");
Services.perms.add(NetUtil.newURI("http://www.test9.com"), "install",
AM_Ci.nsIPermissionManager.ALLOW_ACTION);
startupManager();
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://test1.com")));
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test2.com")));
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://test3.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://test4.com")));
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test4.com")));
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://www.test5.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://www.test6.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://test7.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://www.test8.com")));
// This should remain unaffected
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://www.test9.com")));
do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test9.com")));
Services.perms.removeAll();
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://test1.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test2.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://test3.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test4.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://www.test5.com")));
// Upgrade the application and verify that the permissions are still not there
restartManager(1, "2");
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://test1.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test2.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://test3.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("https://www.test4.com")));
do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE,
NetUtil.newURI("http://www.test5.com")));
}