Bug 619730: Support arbitrary blocklist items passed through the observer service. r=robstrong, a=dtownsend

This commit is contained in:
Dave Townsend 2010-12-20 14:01:12 -08:00
Родитель a719cc9a9a
Коммит 3b6b33540e
3 изменённых файлов: 81 добавлений и 18 удалений

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

@ -47,6 +47,7 @@ const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
const TOOLKIT_ID = "toolkit@mozilla.org"
const KEY_PROFILEDIR = "ProfD";
@ -637,10 +638,25 @@ Blocklist.prototype = {
}
var childNodes = doc.documentElement.childNodes;
this._addonEntries = this._processItemNodes(childNodes, "em",
this._handleEmItemNode);
this._pluginEntries = this._processItemNodes(childNodes, "plugin",
this._handlePluginItemNode);
for (var i = 0; i < childNodes.length; ++i) {
var element = childNodes[i];
if (!(element instanceof Ci.nsIDOMElement))
continue;
switch (element.localName) {
case "emItems":
this._processItemNodes(element.childNodes, "em",
this._handleEmItemNode);
break;
case "pluginItems":
this._processItemNodes(element.childNodes, "plugin",
this._handleEmItemNode);
break;
default:
Services.obs.notifyObservers(element,
"blocklist-data-" + element.localName,
null);
}
}
}
catch (e) {
LOG("Blocklist::_loadBlocklistFromFile: Error constructing blocklist " + e);
@ -649,21 +665,8 @@ Blocklist.prototype = {
fileStream.close();
},
_processItemNodes: function(deChildNodes, prefix, handler) {
_processItemNodes: function(itemNodes, prefix, handler) {
var result = [];
var itemNodes;
var containerName = prefix + "Items";
for (var i = 0; i < deChildNodes.length; ++i) {
var emItemsElement = deChildNodes.item(i);
if (emItemsElement instanceof Ci.nsIDOMElement &&
emItemsElement.localName == containerName) {
itemNodes = emItemsElement.childNodes;
break;
}
}
if (!itemNodes)
return result;
var itemName = prefix + "Item";
for (var i = 0; i < itemNodes.length; ++i) {
var blocklistElement = itemNodes.item(i);

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

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist">
<gfxItems testattr="GFX"><gfxItem/><gfxItem/></gfxItems>
<testItems testattr="FOO"><testItem/><testItem/><testItem/></testItems>
<fooItems/>
</blocklist>

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

@ -0,0 +1,53 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests whether
do_load_httpd_js();
var gTestserver = null;
function load_blocklist(file) {
Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file);
var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
getService(Ci.nsITimerCallback);
blocklist.notify(null);
}
var gSawGFX = false;
var gSawTest = false;
// Performs the initial setup
function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8");
startupManager();
gTestserver = new nsHttpServer();
gTestserver.registerDirectory("/data/", do_get_file("data"));
gTestserver.start(4444);
do_test_pending();
Services.obs.addObserver(function(aSubject, aTopic, aData) {
do_check_true(aSubject instanceof AM_Ci.nsIDOMElement);
do_check_eq(aSubject.getAttribute("testattr"), "GFX");
do_check_eq(aSubject.childNodes.length, 2);
gSawGFX = true;
}, "blocklist-data-gfxItems", false);
Services.obs.addObserver(function(aSubject, aTopic, aData) {
do_check_true(aSubject instanceof AM_Ci.nsIDOMElement);
do_check_eq(aSubject.getAttribute("testattr"), "FOO");
do_check_eq(aSubject.childNodes.length, 3);
gSawTest = true;
}, "blocklist-data-testItems", false);
Services.obs.addObserver(function(aSubject, aTopic, aData) {
do_check_true(gSawGFX);
do_check_true(gSawTest);
gTestserver.stop(do_test_finished);
}, "blocklist-data-fooItems", false);
load_blocklist("test_bug619730.xml");
}