[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r12312: Transmutate the ghettologger into a nice unified logging sys (in torbutton/trunk/src: . chrome/content components defaults/preferences)
Author: mikeperry
Date: 2007-11-01 04:37:56 -0400 (Thu, 01 Nov 2007)
New Revision: 12312
Added:
torbutton/trunk/src/components/torbutton-logger.js
Removed:
torbutton/trunk/src/components/ghetto-logger.js
Modified:
torbutton/trunk/src/chrome/content/torbutton.js
torbutton/trunk/src/chrome/content/torbutton_util.js
torbutton/trunk/src/components/cssblocker.js
torbutton/trunk/src/components/window-mapper.js
torbutton/trunk/src/defaults/preferences/preferences.js
torbutton/trunk/src/install.rdf
Log:
Transmutate the ghettologger into a nice unified logging
system. This should help us find a couple pesky hooking
issues and some occasional content policy hiccups.
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -71,7 +71,7 @@
torbutton_set_status();
break;
case "extensions.torbutton.crashed":
- // can we say getto hack, boys and girls?
+ // can we say ghetto hack, boys and girls?
torbutton_crash_recover();
break;
case "extensions.torbutton.disable_referer":
@@ -562,6 +562,8 @@
torbutton_clear_history();
}
+ // XXX: This is kind of not so user friendly to people who like
+ // to keep their own prefs.. Not sure what to do though..
if(mode) {
if(torprefs.getBoolPref('block_thwrite')) {
m_tb_prefs.setIntPref("browser.download.manager.retention", 0);
@@ -1204,10 +1206,10 @@
if(doc && doc.domain)
torbutton_hookdoc(aProgress.DOMWindow.window, doc);
} catch(e) {
- torbutton_log(3, "Hit about:plugins? "+doc.location);
+ torbutton_eclog(3, "Hit about:plugins? "+doc.location);
}
} else {
- torbutton_log(3, "No aProgress for location!");
+ torbutton_eclog(3, "No aProgress for location!");
}
return 0;
}
@@ -1254,7 +1256,7 @@
onSecurityChange: function() {return 0;},
onLinkIconAvailable: function()
- { /*torbutton_log(1, 'called linkIcon'); */ return 0; }
+ { /*torbutton_eclog(1, 'called linkIcon'); */ return 0; }
}
Modified: torbutton/trunk/src/chrome/content/torbutton_util.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton_util.js 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/chrome/content/torbutton_util.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -1,53 +1,16 @@
-var m_tb_logger = false;
-var m_tb_console = false;
-var m_tb_ghetto = false;
-var m_tb_debug = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch)
- .getBoolPref("extensions.torbutton.debug");
-
-var m_tb_loglevel = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch)
- .getIntPref("extensions.torbutton.loglevel");
-
-try {
- var logMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"]
- .getService(Components.interfaces.nsIDebugLoggerManager);
- m_tb_logger = logMngr.registerLogger("torbutton");
-} catch (exErr) {
- m_tb_logger = false;
-}
-m_tb_console = Components.classes["@mozilla.org/consoleservice;1"]
-.getService(Components.interfaces.nsIConsoleService);
-
-m_tb_ghetto = Components.classes["@torproject.org/ghetto-logger;1"]
+var m_tb_torlog = Components.classes["@torproject.org/torbutton-logger;1"]
.getService(Components.interfaces.nsISupports).wrappedJSObject;
function torbutton_eclog(nLevel, sMsg) {
- if(!m_tb_debug) return true;
- var rDate = new Date();
-
- if (m_tb_console && nLevel >= m_tb_loglevel) {
- m_tb_console.logStringMessage(rDate.getTime()+': '+sMsg);
- } else if (nLevel >= m_tb_loglevel) {
- m_tb_ghetto.log(nLevel, rDate.getTime()+': '+sMsg+"\n");
- }
+ m_tb_torlog.eclog(nLevel, sMsg);
+
return true;
}
function torbutton_log(nLevel, sMsg) {
- if(!m_tb_debug) return true;
+ m_tb_torlog.log(nLevel, sMsg);
- var rDate = new Date();
-
- if (m_tb_logger) {
- m_tb_logger.log((6-nLevel), rDate.getTime()+': '+sMsg);
- } else if (m_tb_console && nLevel >= m_tb_loglevel) {
- m_tb_console.logStringMessage(rDate.getTime()+': '+sMsg);
- } else if (nLevel >= m_tb_loglevel) {
- m_tb_ghetto.log(nLevel, rDate.getTime()+': '+sMsg+"\n");
- }
-
// So we can use it in boolean expressions to determine where the
// short-circuit is..
return true;
Modified: torbutton/trunk/src/components/cssblocker.js
===================================================================
--- torbutton/trunk/src/components/cssblocker.js 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/components/cssblocker.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -88,21 +88,17 @@
init: function() {
this._prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
- this._loglevel = this._prefs.getIntPref("extensions.torbutton.loglevel");
this.wm = Components.classes["@torproject.org/content-window-mapper;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
- this.log("init done\n");
+ // XXX: Ewww. torbutton.logger may not be loaded yet..
+ this.logger = Components.classes["@torproject.org/torbutton-logger;1"]
+ .getService(Components.interfaces.nsISupports).wrappedJSObject;
+
+ dump("Content policy component initialized\n");
return;
},
- log: function(str) {
- // TODO: This could be done better/unified with the main log system..
- if(this._loglevel <= 2) {
- dump(str);
- }
- },
-
isLocalScheme: function(loc) {
if (loc.indexOf(":") < 0)
return false;
@@ -119,26 +115,28 @@
/*. Debugging hack. DO NOT UNCOMMENT IN PRODUCTION ENVIRONMENTS
if(contentLocation.spec.search("venkman") != -1) {
- this.log("chrome-venk\n");
+ this.logger.log(3, "chrome-venk");
return ok;
}*/
if(!insecNode) {
// Happens on startup
- this.log("Skipping insec: "+contentLocation.spec+"\n");
+ this.logger.log(3, "Skipping no insec: "+contentLocation.spec);
return ok;
}
if(!this._prefs.getBoolPref("extensions.torbutton.isolate_content")) {
- this.log("disabled\n");
+ this.logger.eclog(1, "Content policy disabled");
return ok;
}
var node = wrapNode(insecNode);
var wind = getWindow(wrapNode(insecNode));
- if (this.isLocalScheme(unwrapURL(contentLocation.spec))) {
- this.log("Skipping local: "+contentLocation.spec+"\n");
+ // Local stuff has to be eclog because otherwise debuglogger will
+ // get into an infinite log-loop w/ its chrome updates
+ if (this.isLocalScheme(unwrapURL(contentLocation.spec))) {
+ this.logger.eclog(1, "Skipping local: "+contentLocation.spec);
return ok;
}
@@ -147,7 +145,8 @@
node = node.contentWindow;
wind = node;
}
-
+
+ // XXX: Something is rotten in denmark
var torTag = !this._prefs.getBoolPref("extensions.torbutton.tor_enabled");
if (contentType == 5) { // Object
@@ -156,21 +155,21 @@
// the webprogresslistener
if(!torTag) {
if(this._prefs.getBoolPref("extensions.torbutton.no_tor_plugins")) {
- this.log("Blocking object at "+contentLocation.spec+"\n");
+ this.logger.log(4, "Blocking object at "+contentLocation.spec);
return block;
}
}
}
if (!wind || !wind.top.location || !wind.top.location.href) {
- this.log("Skipping no location: "+contentLocation.spec+"\n");
+ this.logger.log(4, "Skipping no location: "+contentLocation.spec);
return ok;
}
var doc = wind.top.document;
if(!doc) {
// 1st load of a page in a new location
- this.log("Skipping no doc: "+contentLocation.spec+"\n");
+ this.logger.log(3, "Skipping no doc: "+contentLocation.spec);
return ok;
}
@@ -178,12 +177,12 @@
if(!browser) {
// This happens on the first load of a doc
// XXX: Other cases?
- this.log("No window found: "+contentLocation.spec+"\n");
+ this.logger.log(3, "No window found: "+contentLocation.spec);
return ok;
}
if (typeof(browser.__tb_js_state) == 'undefined') {
- this.log("UNTAGGED WINDOW2!!!!!!!!! "+contentLocation.spec+"\n");
+ this.logger.log(5, "UNTAGGED WINDOW2!!!!!!!!! "+contentLocation.spec);
return block;
}
@@ -191,7 +190,7 @@
if(browser.__tb_js_state == torTag)
return ok;
else {
- this.log("Blocking: "+contentLocation.spec+"\n");
+ this.logger.log(3, "Blocking: "+contentLocation.spec);
return block;
}
Deleted: torbutton/trunk/src/components/ghetto-logger.js
===================================================================
--- torbutton/trunk/src/components/ghetto-logger.js 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/components/ghetto-logger.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -1,128 +0,0 @@
-/*************************************************************************
- * GhettoLogger (JavaScript XPCOM component)
- *
- * Allows loglevel-based logging to the console (via dump)
- *
- *************************************************************************/
-
-// Module specific constants
-const kMODULE_NAME = "Ghetto Logger";
-const kMODULE_CONTRACTID = "@torproject.org/ghetto-logger;1";
-const kMODULE_CID = Components.ID("f36d72c9-9718-4134-b550-e109638331d7");
-
-const Cr = Components.results;
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-
-function GhettoLogger() {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- this._loglevel = prefs.getIntPref("extensions.torbutton.loglevel");
-
- this.log = function(level, str) {
- // TODO: This could be done better/unified with the main log system..
- if(this._loglevel <= level) {
- dump(str);
- }
- },
-
- // This JSObject is exported directly to chrome
- this.wrappedJSObject = this;
-}
-
-/**
- * JS XPCOM component registration goop:
- *
- * Everything below is boring boilerplate and can probably be ignored.
- */
-
-const nsISupports = Components.interfaces.nsISupports;
-const nsIClassInfo = Components.interfaces.nsIClassInfo;
-const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
-const nsIObserverService = Components.interfaces.nsIObserverService;
-
-GhettoLogger.prototype =
-{
- QueryInterface: function(iid)
- {
- if (!iid.equals(nsIClassInfo) &&
- !iid.equals(nsISupports)) {
- Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
- return null;
- }
- return this;
- },
-
- wrappedJSObject: null, // Initialized by constructor
-
- // make this an nsIClassInfo object
- flags: nsIClassInfo.DOM_OBJECT,
-
- // method of nsIClassInfo
- classDescription: "GhettoLogger",
-
- // method of nsIClassInfo
- getInterfaces: function(count) {
- var interfaceList = [nsIClassInfo];
- count.value = interfaceList.length;
- return interfaceList;
- },
-
- // method of nsIClassInfo
- getHelperForLanguage: function(count) { return null; },
-
-}
-
-var GhettoLoggerInstance = null;
-var GhettoLoggerFactory = new Object();
-
-GhettoLoggerFactory.createInstance = function (outer, iid)
-{
- if (outer != null) {
- Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
- return null;
- }
- if (!iid.equals(nsIClassInfo) &&
- !iid.equals(nsISupports)) {
- Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
- return null;
- }
- if(GhettoLoggerInstance == null)
- GhettoLoggerInstance = new GhettoLogger();
-
- return GhettoLoggerInstance;
-}
-
-var GhettoLoggerModule = new Object();
-
-GhettoLoggerModule.registerSelf =
-function (compMgr, fileSpec, location, type)
-{
- compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
- compMgr.registerFactoryLocation(kMODULE_CID,
- kMODULE_NAME,
- kMODULE_CONTRACTID,
- fileSpec,
- location,
- type);
-}
-
-GhettoLoggerModule.getClassObject = function (compMgr, cid, iid)
-{
- if (cid.equals(kMODULE_CID))
- return GhettoLoggerFactory;
-
-
- Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
- return null;
-}
-
-GhettoLoggerModule.canUnload = function (compMgr)
-{
- return true;
-}
-
-function NSGetModule(compMgr, fileSpec)
-{
- return GhettoLoggerModule;
-}
Added: torbutton/trunk/src/components/torbutton-logger.js
===================================================================
--- torbutton/trunk/src/components/torbutton-logger.js (rev 0)
+++ torbutton/trunk/src/components/torbutton-logger.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -0,0 +1,195 @@
+/*************************************************************************
+ * TBLogger (JavaScript XPCOM component)
+ *
+ * Allows loglevel-based logging to different logging mechanisms.
+ *
+ *************************************************************************/
+
+// Module specific constants
+const kMODULE_NAME = "Torbutton Logger";
+const kMODULE_CONTRACTID = "@torproject.org/torbutton-logger;1";
+const kMODULE_CID = Components.ID("f36d72c9-9718-4134-b550-e109638331d7");
+
+const Cr = Components.results;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+function TorbuttonLogger() {
+ this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch);
+ this.loglevel = this.prefs.getIntPref("extensions.torbutton.loglevel");
+ this.logmethod = this.prefs.getIntPref("extensions.torbutton.logmethod");
+
+ try {
+ var logMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"]
+ .getService(Components.interfaces.nsIDebugLoggerManager);
+ this._debuglog = logMngr.registerLogger("torbutton");
+ } catch (exErr) {
+ this._debuglog = false;
+ }
+ this._console = Components.classes["@mozilla.org/consoleservice;1"]
+ .getService(Components.interfaces.nsIConsoleService);
+
+ // Register observer
+ var pref_service = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranchInternal);
+ this._branch = pref_service.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
+ this._branch.addObserver("", this, false);
+
+ // This JSObject is exported directly to chrome
+ this.wrappedJSObject = this;
+ dump("Torbutton Logger component initialized\n");
+}
+
+/**
+ * JS XPCOM component registration goop:
+ *
+ * Everything below is boring boilerplate and can probably be ignored.
+ */
+
+const nsISupports = Components.interfaces.nsISupports;
+const nsIClassInfo = Components.interfaces.nsIClassInfo;
+const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
+const nsIObserverService = Components.interfaces.nsIObserverService;
+
+TorbuttonLogger.prototype =
+{
+ QueryInterface: function(iid)
+ {
+ if (!iid.equals(nsIClassInfo) &&
+ !iid.equals(nsISupports)) {
+ Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
+ return null;
+ }
+ return this;
+ },
+
+ wrappedJSObject: null, // Initialized by constructor
+
+ // make this an nsIClassInfo object
+ flags: nsIClassInfo.DOM_OBJECT,
+
+ // method of nsIClassInfo
+ classDescription: "TorbuttonLogger",
+
+ // method of nsIClassInfo
+ getInterfaces: function(count) {
+ var interfaceList = [nsIClassInfo];
+ count.value = interfaceList.length;
+ return interfaceList;
+ },
+
+ // method of nsIClassInfo
+ getHelperForLanguage: function(count) { return null; },
+
+ // error console log
+ eclog: function(level, str) {
+ var now = Date.now();
+ str = "["+now+"] ("+level+"): "+str;
+ switch(this.logmethod) {
+ case 0: // stderr
+ if(this.loglevel <= level)
+ dump(str+"\n");
+ break;
+ default: // errorconsole
+ if(this.loglevel <= level)
+ this._console.logStringMessage(str);
+ break;
+ }
+ },
+
+ log: function(level, str) {
+ var now = Date.now();
+ str = "["+now+"] ("+level+"): "+str;
+ switch(this.logmethod) {
+ case 2: // debuglogger
+ if(this._debuglog) {
+ this._debuglog.log((6-level), str);
+ break;
+ }
+ // fallthrough
+ case 0: // stderr
+ if(this.loglevel <= level)
+ dump(str+"\n");
+ break;
+ default:
+ dump("Bad log method: "+this.logmethod);
+ case 1: // errorconsole
+ if(this.loglevel <= level)
+ this._console.logStringMessage(str);
+ break;
+ }
+ },
+
+ // Pref observer interface implementation
+
+ // topic: what event occurred
+ // subject: what nsIPrefBranch we're observing
+ // data: which pref has been changed (relative to subject)
+ observe: function(subject, topic, data)
+ {
+ if (topic != "nsPref:changed") return;
+ switch (data) {
+ case "extensions.torbutton.logmethod":
+ this.logmethod = this.prefs.getIntPref("extensions.torbutton.logmethod");
+ break;
+ case "extensions.torbutton.loglevel":
+ this.loglevel = this.prefs.getIntPref("extensions.torbutton.loglevel");
+ break;
+ }
+ }
+}
+
+var TorbuttonLoggerInstance = null;
+var TorbuttonLoggerFactory = new Object();
+
+TorbuttonLoggerFactory.createInstance = function (outer, iid)
+{
+ if (outer != null) {
+ Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
+ return null;
+ }
+ if (!iid.equals(nsIClassInfo) &&
+ !iid.equals(nsISupports)) {
+ Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
+ return null;
+ }
+ if(TorbuttonLoggerInstance == null)
+ TorbuttonLoggerInstance = new TorbuttonLogger();
+
+ return TorbuttonLoggerInstance;
+}
+
+var TorbuttonLoggerModule = new Object();
+
+TorbuttonLoggerModule.registerSelf =
+function (compMgr, fileSpec, location, type)
+{
+ compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
+ compMgr.registerFactoryLocation(kMODULE_CID,
+ kMODULE_NAME,
+ kMODULE_CONTRACTID,
+ fileSpec,
+ location,
+ type);
+}
+
+TorbuttonLoggerModule.getClassObject = function (compMgr, cid, iid)
+{
+ if (cid.equals(kMODULE_CID))
+ return TorbuttonLoggerFactory;
+
+
+ Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
+ return null;
+}
+
+TorbuttonLoggerModule.canUnload = function (compMgr)
+{
+ return true;
+}
+
+function NSGetModule(compMgr, fileSpec)
+{
+ return TorbuttonLoggerModule;
+}
Modified: torbutton/trunk/src/components/window-mapper.js
===================================================================
--- torbutton/trunk/src/components/window-mapper.js 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/components/window-mapper.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -21,18 +21,14 @@
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
- this._loglevel = prefs.getIntPref("extensions.torbutton.loglevel");
- this.log = function(str) {
- // TODO: This could be done better/unified with the main log system..
- if(this._loglevel <= 2) {
- dump(str);
- }
- },
+ this.logger = Components.classes["@torproject.org/torbutton-logger;1"]
+ .getService(Components.interfaces.nsISupports).wrappedJSObject;
+
this.checkCache = function(topContentWindow) {
if(typeof(this.cache[topContentWindow]) != "undefined") {
- this.log("Found cached element\n");
+ this.logger.log(1, "Found cached element");
return this.cache[topContentWindow].browser;
}
@@ -44,7 +40,7 @@
insertion.browser = browser;
insertion.time = Date.now();
this.cache[topContentWindow] = insertion;
- this.log("Cached element\n");
+ this.loggger.log(2, "Cached element: "+topContentWindow.location);
};
this.expireOldCache = function() {
@@ -52,10 +48,16 @@
for(var elem in this.cache) {
if((now - this.cache[elem].time) > EXPIRATION_TIME) {
- this.log("Deleting expired entry\n");
+ this.loggger.log(2, "Deleting cached element: "+elem.location);
delete this.cache[elem];
}
}
+ for(var elem in this.cache) {
+ if((now - this.cache[elem].time) > EXPIRATION_TIME) {
+ this.loggger.log(4, "ELEMENT STILL REMAINS: "+elem.location);
+ delete this.cache[elem];
+ }
+ }
};
this.getBrowserForContentWindow = function(topContentWindow) {
@@ -77,17 +79,18 @@
}
}
- if(topContentWindow && topContentWindow.document && topContentWindow.document.location)
- this.log("No browser found: "+topContentWindow.document.location+"\n");
+ if(topContentWindow && topContentWindow.location)
+ this.logger.log(3, "No browser found: "+topContentWindow.location);
else
- this.log("No browser found!\n");
+ this.logger.log(3, "No browser found!");
return null;
};
-
// This JSObject is exported directly to chrome
this.wrappedJSObject = this;
+
+ dump("Window mapper component initialized\n");
}
/**
Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/defaults/preferences/preferences.js 2007-11-01 08:37:56 UTC (rev 12312)
@@ -1,6 +1,7 @@
// pref("extensions.torbutton.prompt_before_visiting_excluded_sites",true);
pref("extensions.torbutton.debug",true);
pref("extensions.torbutton.loglevel",4);
+pref("extensions.torbutton.logmethod",2); // 0=stdout, 1=errorconsole, 2=debuglog
pref("extensions.torbutton.display_panel",true);
pref("extensions.torbutton.panel_style",'text');
pref("extensions.torbutton.settings_method",'recommended');
Modified: torbutton/trunk/src/install.rdf
===================================================================
--- torbutton/trunk/src/install.rdf 2007-11-01 05:18:17 UTC (rev 12311)
+++ torbutton/trunk/src/install.rdf 2007-11-01 08:37:56 UTC (rev 12312)
@@ -6,7 +6,7 @@
<em:name>Torbutton</em:name>
<em:creator>Scott Squires & Mike Perry</em:creator>
<em:id>{e0204bd5-9d31-402b-a99d-a6aa8ffebdca}</em:id>
- <em:version>1.1.9.1-alpha</em:version>
+ <em:version>1.1.9.1-alpha-dev</em:version>
<em:homepageURL>https://torbutton.torproject.org/dev/</em:homepageURL>
<em:optionsURL>chrome://torbutton/content/preferences.xul</em:optionsURL>
<em:iconURL>chrome://torbutton/skin/tor.png</em:iconURL>