home *** CD-ROM | disk | FTP | other *** search
/ Minami 83 / MINAMI83.iso / Extra / DivXInstaller.exe / $PLUGINSDIR / GoogleToolbarFirefox.msi / xpi / amulet-jslib / multi-querier.js < prev    next >
Text File  |  2006-08-07  |  2KB  |  74 lines

  1. function PROT_MultiQuerier(tokens, tableName, callback) {
  2. this.tokens_ = tokens;
  3. this.tableName_ = tableName;
  4. this.callback_ = callback;
  5. this.dbservice_ = Cc["@google.com/dbupdateservice;1"]
  6. .getService(Ci.GTBIDbUpdateService);
  7. this.key_ = null;
  8. }
  9. PROT_MultiQuerier.prototype.run = function() {
  10. if (this.tokens_.length == 0) {
  11. this.callback_(false);
  12. this.dbservice_ = null;
  13. this.callback_ = null;
  14. return;
  15. }
  16. this.key_ = this.tokens_.pop();
  17. G_Debug(this, "Looking up " + this.key_ + " in " + this.tableName_);
  18. this.dbservice_.exists(this.tableName_, this.key_,
  19. BindToObject(this.resultCallback_, this));
  20. }
  21. PROT_MultiQuerier.prototype.resultCallback_ = function(value) {
  22. if (this.checkValue_(value)) {
  23. this.callback_(true)
  24. this.dbservice_ = null;
  25. this.callback_ = null;
  26. } else {
  27. this.run();
  28. }
  29. }
  30. PROT_MultiQuerier.prototype.checkValue_ = function(value) {
  31. throw "PROT_MultiQuerier is an abstract base class";
  32. }
  33. function PROT_ExistsMultiQuerier(tokens, tableName, callback) {
  34. PROT_MultiQuerier.call(this, tokens, tableName, callback);
  35. this.debugZone = "existsMultiQuerier";
  36. }
  37. PROT_ExistsMultiQuerier.inherits(PROT_MultiQuerier);
  38. PROT_ExistsMultiQuerier.prototype.checkValue_ = function(value) {
  39. return value.length > 0;
  40. }
  41. function PROT_EnchashMultiQuerier(tokens, tableName, callback, url) {
  42. PROT_MultiQuerier.call(this, tokens, tableName, callback);
  43. this.url_ = url;
  44. this.enchashDecrypter_ = new PROT_EnchashDecrypter();
  45. this.debugZone = "enchashMultiQuerier";
  46. }
  47. PROT_EnchashMultiQuerier.inherits(PROT_MultiQuerier);
  48. PROT_EnchashMultiQuerier.prototype.run = function() {
  49. if (this.tokens_.length == 0) {
  50. this.callback_(false);
  51. this.dbservice_ = null;
  52. this.callback_ = null;
  53. return;
  54. }
  55. var host = this.tokens_.pop();
  56. this.key_ = host;
  57. var lookupKey = this.enchashDecrypter_.getLookupKey(host);
  58. this.dbservice_.exists(this.tableName_, lookupKey,
  59. BindToObject(this.resultCallback_, this));
  60. }
  61. PROT_EnchashMultiQuerier.prototype.checkValue_ = function(encryptedValue) {
  62. if (encryptedValue.length > 0) {
  63. var decrypted = this.enchashDecrypter_.decryptData(encryptedValue,
  64. this.key_);
  65. var res = this.enchashDecrypter_.parseRegExps(decrypted);
  66. for (var j = 0; j < res.length; j++) {
  67. if (res[j].test(this.url_)) {
  68. return true;
  69. }
  70. }
  71. }
  72. return false;
  73. }
  74.