[or-cvs] r12119: Add a ghetto console logger. Also fix bug 519 (infinite loop (in torbutton/trunk/src: chrome/content components)
mikeperry at seul.org
mikeperry at seul.org
Tue Oct 23 01:03:25 UTC 2007
Author: mikeperry
Date: 2007-10-22 21:03:25 -0400 (Mon, 22 Oct 2007)
New Revision: 12119
Added:
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/window-mapper.js
Log:
Add a ghetto console logger. Also fix bug 519 (infinite loop
on ubuntu). Fix an exception as well.
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2007-10-23 00:59:55 UTC (rev 12118)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2007-10-23 01:03:25 UTC (rev 12119)
@@ -37,6 +37,10 @@
case "extensions.torbutton.panel_style":
torbutton_set_panel_style();
break;
+ /* XXX: Why was this here? Gotta ask Scott.
+ * It causes an inf loop on ubuntu. The
+ * real question is why doesn't it cause this
+ * loop everywhere? it seems like it should
case "extensions.torbutton.http_proxy":
case "extensions.torbutton.http_port":
case "extensions.torbutton.https_proxy":
@@ -48,6 +52,7 @@
case "extensions.torbutton.socks_host":
case "extensions.torbutton.socks_port":
torbutton_init_prefs();
+ */
case "network.proxy.http":
case "network.proxy.http_port":
case "network.proxy.ssl":
@@ -1176,11 +1181,11 @@
function torbutton_check_progress(aProgress, aRequest) {
// This noise is a workaround for the fact that docShell.allowPlugins
// is ignored when you directly click on a link
- if(aRequest instanceof Components.interfaces.nsIChannel
- && aRequest.isPending()
- && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
- && m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins")) {
- try {
+ try {
+ if(aRequest instanceof Components.interfaces.nsIChannel
+ && aRequest.isPending()
+ && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
+ && m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins")) {
torbutton_eclog(2, 'LocChange: '+aRequest.contentType);
if (aRequest.contentType in m_tb_plugin_mimetypes) {
@@ -1188,9 +1193,9 @@
window.alert("Torbutton blocked direct Tor load of plugin content.\n\nUse Save-As instead.\n\n");
return 0;
}
- } catch(e) {
- torbutton_eclog(3, 'Exception on request cancel');
}
+ } catch(e) {
+ torbutton_eclog(3, 'Exception on request cancel');
}
if(aProgress) {
Modified: torbutton/trunk/src/chrome/content/torbutton_util.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton_util.js 2007-10-23 00:59:55 UTC (rev 12118)
+++ torbutton/trunk/src/chrome/content/torbutton_util.js 2007-10-23 01:03:25 UTC (rev 12119)
@@ -1,5 +1,6 @@
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");
@@ -18,14 +19,18 @@
m_tb_console = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
+m_tb_ghetto = Components.classes["@torproject.org/ghetto-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) {
- dump(rDate.getTime()+': '+sMsg+"\n");
+ m_tb_ghetto.log(nLevel, rDate.getTime()+': '+sMsg+"\n");
}
return true;
}
@@ -34,12 +39,13 @@
if(!m_tb_debug) return true;
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) {
- dump(rDate.getTime()+': '+sMsg+"\n");
+ m_tb_ghetto.log(nLevel, rDate.getTime()+': '+sMsg+"\n");
}
// So we can use it in boolean expressions to determine where the
Added: torbutton/trunk/src/components/ghetto-logger.js
===================================================================
--- torbutton/trunk/src/components/ghetto-logger.js (rev 0)
+++ torbutton/trunk/src/components/ghetto-logger.js 2007-10-23 01:03:25 UTC (rev 12119)
@@ -0,0 +1,128 @@
+/*************************************************************************
+ * 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;
+}
Modified: torbutton/trunk/src/components/window-mapper.js
===================================================================
--- torbutton/trunk/src/components/window-mapper.js 2007-10-23 00:59:55 UTC (rev 12118)
+++ torbutton/trunk/src/components/window-mapper.js 2007-10-23 01:03:25 UTC (rev 12119)
@@ -3,9 +3,6 @@
*
* Allows you to find a tabbrowser tab for a top level content window.
*
- * TODO: Implement a local cache+timer expiration so this isn't ass-slow
- * with lots of windows open.
- *
*************************************************************************/
// Module specific constants
More information about the tor-commits
mailing list