home *** CD-ROM | disk | FTP | other *** search
/ Minami 81 / MINAMI81.ISO / Extra / DivXInstaller.exe / $PLUGINSDIR / GoogleToolbarFirefox.msi / xpi / amulet-jslib / list-warden.js < prev    next >
Text File  |  2006-05-15  |  3KB  |  99 lines

  1. function PROT_ListWarden(listManager) {
  2. this.debugZone = "listwarden";
  3. this.listManager_ = listManager;
  4. this.prefs_ = new G_Preferences();
  5. this.blackTables_ = [];
  6. this.whiteTables_ = [];
  7. this.sandboxUpdates_ = [];
  8. }
  9. PROT_ListWarden.prototype.enableBlacklistTableUpdates = function() {
  10. this.listManager_.enableUpdateTables(this.blackTables_);
  11. }
  12. PROT_ListWarden.prototype.disableBlacklistTableUpdates = function() {
  13. this.listManager_.disableUpdateTables(this.blackTables_);
  14. }
  15. PROT_ListWarden.prototype.enableWhitelistTableUpdates = function() {
  16. this.listManager_.enableUpdateTables(this.whiteTables_);
  17. }
  18. PROT_ListWarden.prototype.disableWhitelistTableUpdates = function() {
  19. this.listManager_.disableUpdateTables(this.whiteTables_);
  20. }
  21. PROT_ListWarden.prototype.enableSandboxUpdates = function() {
  22. this.listManager_.enableUpdateTables(this.sandboxUpdates_);
  23. }
  24. PROT_ListWarden.prototype.disableSandboxUpdates = function() {
  25. this.listManager_.disableUpdateTables(this.sandboxUpdates_);
  26. }
  27. PROT_ListWarden.prototype.registerBlackTable = function(tableName) {
  28. var result = this.listManager_.registerTable(tableName);
  29. if (result)
  30. this.blackTables_.push(tableName);
  31. return result;
  32. }
  33. PROT_ListWarden.prototype.registerWhiteTable = function(tableName) {
  34. var result = this.listManager_.registerTable(tableName);
  35. if (result)
  36. this.whiteTables_.push(tableName);
  37. return result;
  38. }
  39. PROT_ListWarden.prototype.registerSandboxUpdate = function(tableName, callback) {
  40. var result = this.listManager_.registerTable(tableName,
  41. true, /* requireMac */
  42. callback);
  43. if (result)
  44. this.sandboxUpdates_.push(tableName);
  45. return result;
  46. }
  47. PROT_ListWarden.prototype.isURLInTables_ = function(tables, url) {
  48. for (var i = 0; i < tables.length; ++i) {
  49. if (this.listManager_.safeLookup(tables[i], url))
  50. return true;
  51. }
  52. return false;
  53. }
  54. PROT_ListWarden.prototype.isWhiteURL_ = function(url) {
  55. if (!this.listManager_)
  56. return false;
  57. var whitelisted = this.isURLInTables_(this.whiteTables_, url);
  58. if (whitelisted)
  59. G_Debug(this, "Whitelist hit: " + url);
  60. return whitelisted;
  61. }
  62. PROT_ListWarden.prototype.isWhiteURL = function(url) {
  63. return this.isWhiteURL_(url);
  64. }
  65. PROT_ListWarden.prototype.isBlackURL_ = function(url) {
  66. if (!this.listManager_)
  67. return false;
  68. var blacklisted = this.isURLInTables_(this.blackTables_, url);
  69. if (blacklisted)
  70. G_Debug(this, "Blacklist hit: " + url);
  71. return blacklisted;
  72. }
  73. PROT_ListWarden.prototype.isEvilURL_ = function(url) {
  74. return !this.isWhiteURL_(url) && this.isBlackURL_(url);
  75. }
  76. function TEST_PROT_ListWarden() {
  77. if (G_GDEBUG) {
  78. var z = "listwarden UNITTEST";
  79. G_debugService.enableZone(z);
  80. G_Debug(z, "Starting");
  81. var listManager = new PROT_ListManager(true /* testing */);
  82. var warden = new PROT_ListWarden(listManager);
  83. G_Assert(z, warden.registerWhiteTable("test-white-domain"),
  84. "Failed to register test-white-domain table");
  85. G_Assert(z, warden.registerBlackTable("test-black-url"),
  86. "Failed to register test-black-url table");
  87. listManager.safeInsert("test-white-domain", "foo.com", "1");
  88. listManager.safeInsert("test-black-url", "http://foo.com/good/1", "1");
  89. listManager.safeInsert("test-black-url", "http://foo.com/bad/1", "1");
  90. G_Assert(z, !warden.isEvilURL_("http://foo.com/good/1"),
  91. "White listing is not working.");
  92. G_Assert(z, warden.isBlackURL_("http://foo.com/bad/1"),
  93. "Black listing is not working.");
  94. G_Assert(z, !warden.isEvilURL_("http://foo.com/bad/1"),
  95. "Whitelist should have priority.");
  96. G_Debug(z, "PASSED");
  97. }
  98. }
  99.