[or-cvs] r10553: Turns out the Date hooks do not need to persist in the DOM - (in torbutton/trunk/src: chrome/content chrome/locale/en-US defaults/preferences)

mikeperry at seul.org mikeperry at seul.org
Mon Jun 11 05:07:59 UTC 2007


Author: mikeperry
Date: 2007-06-11 01:07:59 -0400 (Mon, 11 Jun 2007)
New Revision: 10553

Modified:
   torbutton/trunk/src/chrome/content/jshooks.js
   torbutton/trunk/src/chrome/content/preferences.js
   torbutton/trunk/src/chrome/content/preferences.xul
   torbutton/trunk/src/chrome/content/torbutton.js
   torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd
   torbutton/trunk/src/defaults/preferences/preferences.js
Log:
Turns out the Date hooks do not need to persist in the DOM - they can be
inserted and immediately removed, which should fix rendering issues of
text-only pages and some pages that depend on a specific unaltered DOM
structure.

Also, add a bit of code to clear cache every time Tor is toggled.



Modified: torbutton/trunk/src/chrome/content/jshooks.js
===================================================================
--- torbutton/trunk/src/chrome/content/jshooks.js	2007-06-10 20:10:41 UTC (rev 10552)
+++ torbutton/trunk/src/chrome/content/jshooks.js	2007-06-11 05:07:59 UTC (rev 10553)
@@ -1,98 +1,46 @@
-dump("Loading torbutton/jshooks.js\n");
+/* dump("Loading torbutton/jshooks.js\n"); */
 
 function __HookObjects() {
-  // TODO: It might be a good idea to hook window sizes also..
-  // But that will almost certainly fuck with rendering
+  /* TODO: It might be a good idea to hook window sizes also..
+     But that will almost certainly fuck with rendering */
 
-  // XXX: Is it possible this breaks plugin install or other weird shit
-  // for non-windows OS's?
+  /* XXX: Is it possible this breaks plugin install or other weird shit
+     for non-windows OS's? */
   navigator.__defineGetter__("platform", 
         function() { return "Windows";});
   
   navigator.__defineGetter__("oscpu", 
         function() { return "Win32 i686";});
 
-  // CSS hack fix for http://gemal.dk/browserspy/css.html
-  // Must be a var, not a function (to avoid hooking via prototype)
-  /*
-  var removeAllAttributes = function(e) {
-    var atts = e.attributes;
-    if(e.nodeName.toLowerCase() == "a") {
-      for(var i = atts.length; i != 0; --i) {
-        if(atts[0].name.toLowerCase() != "href") {
-          e.removeAttribute(atts[0].name);
-        } else if(atts.length > 1){
-          e.removeAttribute(atts[1].name);
-        }
-      }
-      if(e.attributes.length>1) dump("FUCK\n");
-    }
-  }
-
-  var gEID = document.getElementById;
-  document.getElementById = function(id) {
-    var ret = gEID.call(document, id);
-    if (ret) removeAllAttributes(ret);
-    return ret;
-  }
-
-  var gEN = document.getElementsByName;
-  document.getElementsByName = function(name) {
-    var ret = gEN.call(document, name);
-    for(var i=0; i < ret.length; ++i)  removeAllAttributes(ret[i]); 
-    return ret;
-  }
-
-  var gENS = document.getElementsByNameNS;
-  document.getElementsByNameNS = function(name,ns) {
-    var ret = gENS.call(document, name,ns);
-    for(var i=0; i < ret.length; ++i)  removeAllAttributes(ret[i]); 
-    return ret;
-  }
-
-  var gETN = document.getElementsByTagName;
-  document.getElementsByTagName = function(name) {
-    var ret = gETN.call(document, name);
-    for(var i=0; i < ret.length; ++i) removeAllAttributes(ret[i]);
-    return ret;
-  }
-
-  var gETNS = document.getElementsByTagNameNS;
-  document.getElementsByTagNameNS = function(name,ns) {
-    var ret = gETNS.call(document, name, ns);
-    for(var i=0; i < ret.length; ++i)  removeAllAttributes(ret[i]);
-    return ret;
-  }
-  */
-  
-
-  // Timezone fix for http://gemal.dk/browserspy/css.html
+  /* Timezone fix for http://gemal.dk/browserspy/css.html */
   var reparseDate = function(d, str) {
-    // Rules:
-    //   - If they specify a timezone, it is converted to local
-    //     time. All getter fucntions then convert properly to
-    //     UTC. No mod needed.
-    //   - If they specify UTC timezone, then it is converted
-    //     to local time. All getter functions then convert back.
-    //     No mod needed.
-    //   - If they specify NO timezone, it is local time. 
-    //     The UTC conversion then reveals the offset. Fix.
+    /* Rules:
+     *   - If they specify a timezone, it is converted to local
+     *     time. All getter fucntions then convert properly to
+     *     UTC. No mod needed.
+     *   - If they specify UTC timezone, then it is converted
+     *     to local time. All getter functions then convert back.
+     *     No mod needed.
+     *   - If they specify NO timezone, it is local time. 
+     *     The UTC conversion then reveals the offset. Fix.
+     */
     
-    // Step 1: Remove everything inside ()'s (they are "comments")
+    /* Step 1: Remove everything inside ()'s (they are "comments") */
     var s = str.toLowerCase();
     var re = new RegExp('\\(.*\\)', "gm");
     s = s.replace(re, "");
     dump(s);
-    // Step 2: Look for +/-. If found, do nothing
+    /* Step 2: Look for +/-. If found, do nothing */
     if(s.indexOf("+") == -1 && s.indexOf("-") == -1) {
-      // Step 3: Look for timezone string from
-      // http://lxr.mozilla.org/seamonkey/source/js/src/jsdate.c 
+      /* Step 3: Look for timezone string from
+       * http://lxr.mozilla.org/seamonkey/source/js/src/jsdate.c
+       */
       if(s.indexOf(" gmt") == -1 && s.indexOf(" ut") == -1 &&
          s.indexOf(" est") == -1 && s.indexOf(" edt") == -1 &&
          s.indexOf(" cst") == -1 && s.indexOf(" cdt") == -1 &&
          s.indexOf(" mst") == -1 && s.indexOf(" mdt") == -1 &&
          s.indexOf(" pst") == -1 && s.indexOf(" pdt")) {
-        // No timezone specified. Adjust.
+        /* No timezone specified. Adjust. */
         d.setTime(d.getTime()-(d.getTimezoneOffset()*60000));
       }
     } 
@@ -100,10 +48,10 @@
 
   var tmp = Date;
   Date = function() {
-    // DO NOT make 'd' a member! EvilCode will use it!
+    /* DO NOT make 'd' a member! EvilCode will use it! */
     var d;
     var a = arguments;
-    // apply doesn't seem to work for constructors :(
+    /* apply doesn't seem to work for constructors :( */
     if(arguments.length == 0) d=new tmp();
     if(arguments.length == 1) d=new tmp(a[0]);
     if(arguments.length == 3) d=new tmp(a[0],a[1],a[2]);
@@ -117,12 +65,12 @@
       if((arguments.length == 1) && typeof(a[0]) == "string") {
         reparseDate(d,a[0]);
       } else if(arguments.length > 1) { 
-        // Numerical value. No timezone given, adjust.
+        /* Numerical value. No timezone given, adjust. */
         d.setTime(d.getTime()-(d.getTimezoneOffset()*60000));
       }
     }
 
-    Date.prototype.valueOf=Date.prototype.getTime = // UTC already
+    Date.prototype.valueOf=Date.prototype.getTime = /* UTC already */
          function(){return d.getTime();}
     Date.prototype.getFullYear=function(){return d.getUTCFullYear();}  
     Date.prototype.getYear=function() {return d.getUTCYear();}
@@ -175,16 +123,17 @@
     Date.prototype.toString=function(){return d.toUTCString();}
     Date.prototype.toLocaleString=function(){return d.toUTCString();}
     
-    // XXX: Fuck 'em if they can't take a joke:
+    /* Fuck 'em if they can't take a joke: */
     Date.prototype.toLocaleTimeString=function(){return d.toUTCString();}
     Date.prototype.toLocaleDateString=function(){return d.toUTCString();}
     Date.prototype.toDateString=function(){return d.toUTCString();}
     Date.prototype.toTimeString=function(){return d.toUTCString();}
 
-     // Hack to solve the problem of multiple date objects
-    // all sharing the same lexically scoped d every time a new one is
-    // created. This hack creates a fresh new prototype reference for 
-    // the next object to use with a different d binding.
+    /* Hack to solve the problem of multiple date objects
+     * all sharing the same lexically scoped d every time a new one is
+     * created. This hack creates a fresh new prototype reference for 
+     * the next object to use with a different d binding.
+     */
     Date.prototype = new Object.prototype.toSource();
     return d.toUTCString();
   }

Modified: torbutton/trunk/src/chrome/content/preferences.js
===================================================================
--- torbutton/trunk/src/chrome/content/preferences.js	2007-06-10 20:10:41 UTC (rev 10552)
+++ torbutton/trunk/src/chrome/content/preferences.js	2007-06-11 05:07:59 UTC (rev 10553)
@@ -139,6 +139,7 @@
 	// XXX: work this in with recommended settigns stuff?
     doc.getElementById('torbutton_disablePlugins').checked = o_torprefs.getBoolPref('no_tor_plugins');
     doc.getElementById('torbutton_clearHistory').checked = o_torprefs.getBoolPref('clear_history');
+    doc.getElementById('torbutton_clearCache').checked = o_torprefs.getBoolPref('clear_cache');
     doc.getElementById('torbutton_clearCookies').checked = o_torprefs.getBoolPref('clear_cookies'); 
     doc.getElementById('torbutton_killBadJS').checked = o_torprefs.getBoolPref('kill_bad_js');
     torbutton_prefs_set_field_attributes(doc);
@@ -182,6 +183,7 @@
 	// XXX: work this in with recommended settigns stuff?
     o_torprefs.setBoolPref('no_tor_plugins', doc.getElementById('torbutton_disablePlugins').checked);
     o_torprefs.setBoolPref('clear_history', doc.getElementById('torbutton_clearHistory').checked);
+    o_torprefs.setBoolPref('clear_cache', doc.getElementById('torbutton_clearCache').checked);
     o_torprefs.setBoolPref('clear_cookies', doc.getElementById('torbutton_clearCookies').checked);
     o_torprefs.setBoolPref('kill_bad_js', doc.getElementById('torbutton_killBadJS').checked);
 

Modified: torbutton/trunk/src/chrome/content/preferences.xul
===================================================================
--- torbutton/trunk/src/chrome/content/preferences.xul	2007-06-10 20:10:41 UTC (rev 10552)
+++ torbutton/trunk/src/chrome/content/preferences.xul	2007-06-11 05:07:59 UTC (rev 10553)
@@ -118,6 +118,8 @@
                   oncommand="torbutton_prefs_set_field_attributes(document)"/>
         <checkbox id="torbutton_clearCookies" label="&torbutton.prefs.clear_cookies;" 
                   oncommand="torbutton_prefs_set_field_attributes(document)"/>
+        <checkbox id="torbutton_clearCache" label="&torbutton.prefs.clear_cache;" 
+                  oncommand="torbutton_prefs_set_field_attributes(document)"/>
         <checkbox id="torbutton_clearHistory" label="&torbutton.prefs.clear_history;" 
                   oncommand="torbutton_prefs_set_field_attributes(document)"/>
     </groupbox>

Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2007-06-10 20:10:41 UTC (rev 10552)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2007-06-11 05:07:59 UTC (rev 10553)
@@ -398,6 +398,7 @@
     var label;
     var tooltip;
     
+
     var torprefs = torbutton_get_prefbranch('extensions.torbutton.');
     torprefs.setBoolPref('tor_enabled', mode);
 
@@ -406,6 +407,9 @@
     torbutton_update_statusbar(mode);
     torbutton_update_plugin_status(!mode);
 
+    // TODO: Investigate Firefox privacy clear-data settings.. 
+    // Form data, download history, passwords?
+    // Can these items be excluded from being recorded during tor usage?
     if (torprefs.getBoolPref('clear_history')) {
         ClearHistory();
     }
@@ -415,6 +419,21 @@
     if (torprefs.getBoolPref('clear_cookies')) {
         ClearCookies(mode);
     }
+    /* XXX: Offer option for this? Ugh, so many options..
+
+19:09 < coderman> mikeperry : to disable CSS history hacks and such (regarding 
+                  browser cache) i had to set browser.cache.memory.enable off, 
+                  browser.cache.disk.enable off , and network.http.use-cache 
+                  off.  as for clearing at switch, or leaving off, i don't 
+                  know.  depends on what you're doing i suppose...
+
+    */
+
+    if (torprefs.getBoolPref('clear_cache')) {
+        var cache = Components.classes["@mozilla.org/network/cache-service;1"].
+        getService(Components.interfaces.nsICacheService);
+        cache.evictEntries(0);
+    }
 }
 
 function torbutton_open_prefs_dialog() {
@@ -540,7 +559,8 @@
     torbutton_log(2, 'called ClearCookies');
     var cm = Components.classes["@mozilla.org/cookiemanager;1"]
                     .getService(Components.interfaces.nsICookieManager);
-    
+   
+ 
     // XXX: Check pref to fully clear or not
     //cm.removeAll();
 
@@ -563,7 +583,6 @@
 
 function TagDocshellForJS(browser, allowed) {
     if (typeof(browser.__tb_js_state) == 'undefined') {
-        //@JSD_BREAK
         torbutton_log(5, "UNTAGGED WINDOW!!!!!!!!!");
     }
 
@@ -572,6 +591,8 @@
         browser.docShell.allowJavascript = 
             m_prefs.getBoolPref("javascript.enabled");
     } else {
+        // XXX: hrmm.. way to check for navigator windows? 
+        // non-navigator windows are not tagged..
         // States differ or undefined, js not ok 
         browser.docShell.allowJavascript = false;
     }
@@ -589,6 +610,7 @@
         var b = browser.browsers[i];
         if (b) {
             b.docShell.allowPlugins = allowed;
+            b.webNavigation.stop(b.webNavigation.STOP_ALL);
             TagDocshellForJS(b, allowed);
         }
     }
@@ -665,10 +687,10 @@
 // XXX: Does this get the first window?
 function NewWindowEvent(event)
 {
+    torbutton_log(1, "New window");
     if (!m_wasinited) {
         torbutton_init();
     }
-    torbutton_log(1, "New window");
 
     if (torbutton_check_status()) {
         if(m_prefs.getBoolPref("extensions.torbutton.no_tor_plugins")) {
@@ -715,6 +737,9 @@
 
 function hookDoc(win, doc) {
     torbutton_log(1, "Hooking document");
+    if(doc.doctype) {
+        torbutton_log(1, "Hooking document: "+doc.doctype.name);
+    }
     if (!m_wasinited) {
         torbutton_init();
     }
@@ -729,6 +754,11 @@
     var tor_tag = !m_prefs.getBoolPref("extensions.torbutton.tor_enabled");
     var js_enabled = m_prefs.getBoolPref("javascript.enabled");
 
+    if (browser.contentDocument == doc) {
+        browser.__tb_js_state = tor_tag;
+        browser.docShell.allowJavascript = js_enabled;
+    } 
+
     // Find proper browser for this document.. ugh.
     for (var i = 0; i < browser.browsers.length; ++i) {
         var b = browser.browsers[i];
@@ -746,14 +776,28 @@
             || !m_prefs.getBoolPref('extensions.torbutton.kill_bad_js'))
         return;
 
+    // Date Hooking:
+
+    /* Q: Do this better with XPCOM?
+     *    http://www.mozilla.org/projects/xpcom/nsIClassInfo.html
+     * A: Negatory.. Date() is not an XPCOM component :(
+     */
+
     var str = "<"+"script>";
     str += m_jshooks; 
-//    str +="alert(\"hi\");";
     str += "</"+"script>";
     var d = doc.createElement("div");
     d.style.visibility = 'hidden';
     d.innerHTML = str;
-    getBody(doc).insertBefore(d, getBody(doc).firstChild);
+    var di = getBody(doc).insertBefore(d, getBody(doc).firstChild);
+    if(di != d) {
+        torbutton_log(5, "Inserted and return not equal");
+    }
+
+    // Remove javascript code for rendering issues/DOM traversals
+    if(!getBody(doc).removeChild(di)) {
+        torbutton_log(5, "Failed to remove js!");
+    } 
 }
 
 const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START;
@@ -779,8 +823,6 @@
    // or when the user switches tabs
     if(aProgress) {
         torbutton_log(1, "location progress");
-        // XXX: Check mimetype or DOM to not fuck with .txt files and other
-        // formats..
         var doc = aProgress.DOMWindow.document;
         if(doc) hookDoc(aProgress.DOMWindow, doc);        
         else torbutton_log(3, "No DOM at location event!");

Modified: torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd
===================================================================
--- torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd	2007-06-10 20:10:41 UTC (rev 10552)
+++ torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd	2007-06-11 05:07:59 UTC (rev 10553)
@@ -16,6 +16,7 @@
 <!ENTITY torbutton.prefs.proxy.port                     "Port:">
 <!ENTITY torbutton.prefs.sec_settings		"Security Settings">
 <!ENTITY torbutton.prefs.clear_history		"Clear history on Tor toggle (optional)">
+<!ENTITY torbutton.prefs.clear_cache		"Clear cache on Tor toggle (recommended)">
 <!ENTITY torbutton.prefs.clear_cookies		"Clear cookies on Tor toggle (recommended)">
 <!ENTITY torbutton.prefs.disable_plugins	"Disable plugins during Tor usage (recommended)">
 <!ENTITY torbutton.prefs.kill_bad_js	    "Block dangerous javascript (recommended)">

Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js	2007-06-10 20:10:41 UTC (rev 10552)
+++ torbutton/trunk/src/defaults/preferences/preferences.js	2007-06-11 05:07:59 UTC (rev 10553)
@@ -41,6 +41,7 @@
 pref("extensions.torbutton.tor_enabled",false);
 pref("extensions.torbutton.no_tor_plugins",true);
 pref("extensions.torbutton.clear_cookies",true);
+pref("extensions.torbutton.clear_cache",true);
 pref("extensions.torbutton.clear_history",false);
 pref("extensions.torbutton.kill_bad_js",true);
 



More information about the tor-commits mailing list