[or-cvs] [https-everywhere/master 3/3] Make log verbosity an about:config variable

pde at torproject.org pde at torproject.org
Wed Oct 13 19:09:10 UTC 2010


Author: Peter Eckersley <pde at eff.org>
Date: Wed, 13 Oct 2010 11:57:27 -0700
Subject: Make log verbosity an about:config variable
Commit: 97c364e7f88abe62dd41f056780ef25de9c0454b

---
 src/components/https-everywhere.js |   47 +++++++++++++++++++++++-------------
 src/install.rdf                    |    2 +-
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/components/https-everywhere.js b/src/components/https-everywhere.js
index b0e73c7..597025a 100644
--- a/src/components/https-everywhere.js
+++ b/src/components/https-everywhere.js
@@ -27,6 +27,8 @@ const SERVICE_CTRID = "@eff.org/https-everywhere;1";
 const SERVICE_ID=Components.ID("{32c165b4-fe5e-4964-9250-603c410631b4}");
 const SERVICE_NAME = "Encrypts your communications with a number of major websites";
 
+const LLVAR = "LogLevel";
+
 const IOS = CC["@mozilla.org/network/io-service;1"].getService(CI.nsIIOService);
 const OS = CC['@mozilla.org/observer-service;1'].getService(CI.nsIObserverService);
 const LOADER = CC["@mozilla.org/moz/jssubscript-loader;1"].getService(CI.mozIJSSubScriptLoader);
@@ -94,9 +96,6 @@ const DUMMYOBJ = {};
 
 const EARLY_VERSION_CHECK = !("nsISessionStore" in CI && typeof(/ /) === "object");
 
-
-
-
 function xpcom_generateQI(iids) {
   var checks = [];
   for each (var iid in iids) {
@@ -300,41 +299,55 @@ HTTPSEverywhere.prototype = {
       var branch_name = "extensions.https_everywhere.";
       var o_prefs = false;
       var o_branch = false;
+      // this function needs to be called from inside https_everywhereLog, so
+      // it needs to do its own logging...
+      var econsole = Components.classes["@mozilla.org/consoleservice;1"]
+          .getService(Components.interfaces.nsIConsoleService);
 
-      this.log(1, "called get_prefbranch()");
       o_prefs = Components.classes["@mozilla.org/preferences-service;1"]
                           .getService(Components.interfaces.nsIPrefService);
+
       if (!o_prefs)
       {
-          this.log(WARN, "Failed to get preferences-service!");
+          econsole.logStringMessage("HTTPS Everywhere: Failed to get preferences-service!");
           return false;
       }
 
       o_branch = o_prefs.getBranch(branch_name);
       if (!o_branch)
       {
-          this.log(WARN, "Failed to get prefs branch!");
+          econsole.logStringMessage("HTTPS Everywhere: Failed to get prefs branch!");
           return false;
       }
 
+      // make sure there's an entry for our log level
+      try {
+        o_branch.getIntPref(LLVAR);
+      } catch (e) {
+        econsole.logStringMessage("Creating new about:config https_everywhere.LogLevel variable");
+        o_branch.setIntPref(LLVAR, WARN);
+      }
+
       return o_branch;
   },
 
 };
 
-const LLVAR = "LogLevel";
-var prefs = HTTPSEverywhere.instance.get_prefs();
-try {
-  prefs.getBoolPref(LLVAR);
-} catch (e) {
-  prefs.setBoolPref(LLVAR, true);
-}
-
+var prefs = 0;
 function https_everywhereLog(level, str) {
-  if (level >= prefs.getBoolPref(LLVAR)) {
+  var econsole = Components.classes["@mozilla.org/consoleservice;1"]
+      .getService(Components.interfaces.nsIConsoleService);
+  if (prefs == 0) {
+    prefs = HTTPSEverywhere.instance.get_prefs();
+  } 
+  try {
+    var threshold = prefs.getIntPref(LLVAR);
+  } catch (e) {
+    econsole.logStringMessage( "HTTPS Everywhere: Failed to read about:config LogLevel");
+    threshold = WARN;
+  }
+  if (level >= threshold) {
     dump(str+"\n");
-    var econsole = Components.classes["@mozilla.org/consoleservice;1"]
-        .getService(Components.interfaces.nsIConsoleService);
     econsole.logStringMessage("HTTPS Everywhere: " +str);
   }
 }
diff --git a/src/install.rdf b/src/install.rdf
index b97f1a9..c995027 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -6,7 +6,7 @@
         <em:name>HTTPS-Everywhere (Development branch)</em:name>
         <em:creator>Mike Perry &amp; Peter Eckersley</em:creator>
         <em:id>https-everywhere at eff.org</em:id>
-        <em:version>0.2.2.development.1</em:version>
+        <em:version>0.2.3.development.1</em:version>
         <em:homepageURL>https://www.eff.org/https-everywhere</em:homepageURL>
         <em:optionsURL>chrome://https-everywhere/content/preferences.xul</em:optionsURL>
         <em:iconURL>chrome://https-everywhere/skin/https-everywhere.png</em:iconURL>
-- 
1.7.1



More information about the tor-commits mailing list