home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Minami 83
/
MINAMI83.iso
/
Extra
/
DivXInstaller.exe
/
$PLUGINSDIR
/
GoogleToolbarFirefox.msi
/
xpi
/
amulet-jslib
/
list-warden.js
< prev
next >
Wrap
Text File
|
2006-08-07
|
4KB
|
121 lines
function PROT_ListWarden(listManager) {
this.debugZone = "listwarden";
this.listManager_ = listManager;
this.prefs_ = new G_Preferences();
this.blackTables_ = [];
this.whiteTables_ = [];
this.sandboxUpdates_ = [];
}
PROT_ListWarden.IN_BLACKLIST = 0
PROT_ListWarden.IN_WHITELIST = 1
PROT_ListWarden.NOT_FOUND = 2
PROT_ListWarden.prototype.enableBlacklistTableUpdates = function() {
this.listManager_.enableUpdateTables(this.blackTables_);
}
PROT_ListWarden.prototype.disableBlacklistTableUpdates = function() {
this.listManager_.disableUpdateTables(this.blackTables_);
}
PROT_ListWarden.prototype.enableWhitelistTableUpdates = function() {
this.listManager_.enableUpdateTables(this.whiteTables_);
}
PROT_ListWarden.prototype.disableWhitelistTableUpdates = function() {
this.listManager_.disableUpdateTables(this.whiteTables_);
}
PROT_ListWarden.prototype.enableSandboxUpdates = function() {
this.listManager_.enableUpdateTables(this.sandboxUpdates_);
}
PROT_ListWarden.prototype.disableSandboxUpdates = function() {
this.listManager_.disableUpdateTables(this.sandboxUpdates_);
}
PROT_ListWarden.prototype.registerBlackTable = function(tableName) {
var result = this.listManager_.registerTable(tableName);
if (result) {
this.blackTables_.push(tableName);
}
return result;
}
PROT_ListWarden.prototype.registerWhiteTable = function(tableName) {
var result = this.listManager_.registerTable(tableName);
if (result) {
this.whiteTables_.push(tableName);
}
return result;
}
PROT_ListWarden.prototype.registerSandboxUpdate = function(tableName, callback) {
var result = this.listManager_.registerTable(tableName,
true, /* requireMac */
callback);
if (result) {
this.sandboxUpdates_.push(tableName);
}
return result;
}
PROT_ListWarden.prototype.isWhiteURL = function(url, callback) {
(new PROT_MultiTableQuerier(url,
this.whiteTables_,
[],
this.listManager_,
callback)).run();
}
PROT_ListWarden.prototype.isEvilURL = function(url, callback) {
(new PROT_MultiTableQuerier(url,
this.whiteTables_,
this.blackTables_,
this.listManager_,
callback)).run();
}
function TEST_PROT_ListWarden() {
if (G_GDEBUG) {
var z = "listwarden UNITTEST";
G_debugService.enableZone(z);
G_Debug(z, "Starting");
var listManager = new PROT_ListManager(true /* testing */);
var warden = new PROT_ListWarden(listManager);
G_Assert(z, warden.registerWhiteTable("test-white-domain"),
"Failed to register test-white-domain table");
G_Assert(z, warden.registerBlackTable("test-black-url"),
"Failed to register test-black-url table");
var dbservice = Cc["@google.com/dbupdateservice;1"]
.getService(Ci.GTBIDbUpdateService);
var data =
"[test-white-domain 1.1]\n" +
"+foo.com\t1\n" +
"\n[test-black-url 1.1]\n" +
"+http://foo.com/good/1\t1\n" +
"+http://foo.com/bad/1\t1\n" +
"+http://betz.com/bad/1\t1\n";
function checkTables(tableName) {
if ("[test-white-domain 1.1]" == tableName) {
G_Debug(z, "first table callback");
} else if ("[test-black-url 1.1]" == tableName) {
G_Debug(z, "second table callback; checking");
function isEvilCallback(status) {
G_Assert(z, PROT_ListWarden.IN_BLACKLIST == status,
"should be blacklisted")
}
function isNotEvilCallback(status) {
G_Assert(z, PROT_ListWarden.IN_BLACKLIST != status,
"should not be blacklisted");
}
warden.isEvilURL("http://foo.com/good/1", isNotEvilCallback);
warden.isEvilURL("http://foo.com/bad/1", isNotEvilCallback);
warden.isEvilURL("http://betz.com/bad/1", isEvilCallback);
function isWhiteCallback(status) {
G_Assert(z, PROT_ListWarden.IN_WHITELIST == status,
"should be whitelisted");
}
function isNotWhiteCallback(status) {
G_Assert(z, PROT_ListWarden.IN_WHITELIST != status,
"should not be whitelisted");
}
warden.isWhiteURL("http://foo.com/", isWhiteCallback);
warden.isWhiteURL("http://bar.com/", isNotWhiteCallback);
G_Debug(z, "PASSED");
} else {
G_Error(z, "unknown table version string");
}
}
dbservice.updateTables(data, checkTables);
}
}