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

  1. var PROT_globalStore;
  2. var PROT_listManager;
  3. var PROT_phishingWarden;
  4. function PROT_Application() {
  5. this.debugZone= "application";
  6. function runUnittests() {
  7. if (G_GDEBUG) {
  8. G_DebugL("UNITTESTS", "STARTING UNITTESTS");
  9. TEST_G_Protocol4Parser();
  10. TEST_G_Base64();
  11. TEST_G_CryptoHasher();
  12. TEST_PROT_EnchashDecrypter();
  13. TEST_PROT_TRTable();
  14. TEST_PROT_ListManager();
  15. TEST_PROT_ListWarden();
  16. TEST_PROT_PhishingWarden();
  17. TEST_PROT_TRFetcher();
  18. TEST_G_ObjectSafeMap();
  19. TEST_PROT_URLCanonicalizer();
  20. TEST_G_Preferences();
  21. TEST_G_Observer();
  22. TEST_G_File();
  23. TEST_PROT_WireFormat();
  24. TEST_PROT_UrlCrypto();
  25. TEST_PROT_UrlCryptoKeyManager();
  26. TEST_G_MozVersionNumber();
  27. TEST_G_ThisFirefoxVersion();
  28. G_DebugL("UNITTESTS", "END UNITTESTS");
  29. }
  30. };
  31. PROT_globalStore =
  32. new PROT_GlobalStore("google.toolbar.button_option.safebrowsing.",
  33. this.getLocale());
  34. var prefs = new G_Preferences();
  35. if (!prefs.getPref(PROT_globalStore.getHaveRunBeforePrefName(), false)) {
  36. prefs.setPref(PROT_globalStore.getHaveRunBeforePrefName(), true);
  37. var optedIn = prefs.getPref(PROT_globalStore.getToolbarPageRankPrefName(),
  38. false);
  39. G_Debug(this, "First run of SafeBrowsing. Disabling advanced " +
  40. "due to page rank being off? " +
  41. (optedIn === false));
  42. prefs.setPref(PROT_globalStore.getServerCheckEnabledPrefName(), optedIn);
  43. prefs.setPref(PROT_globalStore.getServerCheckEnabledDefaultPrefName(),
  44. optedIn);
  45. }
  46. PROT_listManager = new PROT_ListManager();
  47. PROT_phishingWarden = new PROT_PhishingWarden(PROT_listManager);
  48. var threadConfig = {
  49. "interleave": true,
  50. "runtime": 80,
  51. "delay": 700,
  52. };
  53. var threadQueue = new TH_ThreadQueue(threadConfig);
  54. this.contentAnalyzer = new PROT_ContentAnalyzer(PROT_phishingWarden,
  55. threadQueue,
  56. false /* testing */);
  57. new PROT_UrlCryptoKeyManager();
  58. runUnittests();
  59. PROT_listManager.maybeStartManagingUpdates();
  60. }
  61. PROT_Application.isCompatibleWithThisFirefox = function() {
  62. var z = "application";
  63. var compatibleVersion = (new G_ThisFirefoxVersion()).isVersionOf("1.5");
  64. G_Debug(z, "Firefox version is compatible (1.5)? " + compatibleVersion);
  65. var binaryCompatible = false;
  66. var dbcomp = Cc["@google.com/dbupdateservice;1"];
  67. if (dbcomp)
  68. binaryCompatible = true;
  69. G_Debug(z, "Binary compatible? " + binaryCompatible);
  70. var extensionInstalled = false;
  71. try {
  72. var em = Cc["@mozilla.org/extensions/manager;1"]
  73. .getService(Ci.nsIExtensionManager);
  74. var loc = em.getInstallLocation("safebrowsing@google.com");
  75. if (loc != null)
  76. extensionInstalled = true;
  77. } catch(e) {
  78. dump("Masked in isCompatibleWithThisFirefox: " + e);
  79. }
  80. G_Debug(z, "SafeBrowsing extension already installed? " +
  81. extensionInstalled);
  82. return !extensionInstalled && compatibleVersion && binaryCompatible;
  83. }
  84. PROT_Application.prototype.getLocale = function() {
  85. var locale = 'en';
  86. var bundle_service = Cc["@mozilla.org/intl/stringbundle;1"]
  87. .getService(Ci.nsIStringBundleService);
  88. var stringBundle = bundle_service.createBundle(
  89. "chrome://google-toolbar/locale/prefs.properties");
  90. if (stringBundle) {
  91. locale = stringBundle.GetStringFromName('lang');
  92. }
  93. return locale;
  94. }
  95. function PROT_ApplicationDirectory() {
  96. this.debugZone = "appdir";
  97. this.appDir_ = G_File.getProfileFile();
  98. this.appDir_.append(PROT_globalStore.getAppDirectoryName());
  99. G_Debug(this, "Application directory is " + this.appDir_.path);
  100. }
  101. PROT_ApplicationDirectory.prototype.exists = function() {
  102. return this.appDir_.exists() && this.appDir_.isDirectory();
  103. }
  104. PROT_ApplicationDirectory.prototype.create = function() {
  105. G_Debug(this, "Creating app directory: " + this.appDir_.path);
  106. try {
  107. this.appDir_.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
  108. } catch(e) {
  109. G_Error(this, this.appDir_.path + " couldn't be created.");
  110. }
  111. }
  112. PROT_ApplicationDirectory.prototype.getAppDirFileInterface = function() {
  113. return this.appDir_;
  114. }
  115.