[or-cvs] r20457: {torbutton} Auto-protect cookies works (finally) Fake refresh feature on (in torbutton/branches/gsoc2009-koryk/src: chrome/content components defaults/preferences)

koryk at seul.org koryk at seul.org
Wed Sep 2 00:10:58 UTC 2009


Author: koryk
Date: 2009-09-01 20:10:58 -0400 (Tue, 01 Sep 2009)
New Revision: 20457

Modified:
   torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js
   torbutton/branches/gsoc2009-koryk/src/chrome/content/torcookie.js
   torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js
   torbutton/branches/gsoc2009-koryk/src/defaults/preferences/preferences.js
Log:
Auto-protect cookies works (finally)
Fake refresh feature only available through about:config
The do not write tor/non-tor cookies to disk options works now.

Modified: torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js	2009-09-01 22:10:13 UTC (rev 20456)
+++ torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js	2009-09-02 00:10:58 UTC (rev 20457)
@@ -1529,17 +1529,20 @@
         return;
     }*/
     var protectcookies = m_tb_prefs.getBoolPref('extensions.torbutton.cookie_protections');
+    var writeTor = !m_tb_prefs.getBoolPref('extensions.torbutton.tor_memory_jar');
+    var writeNontor = !m_tb_prefs.getBoolPref('extensions.torbutton.nontor_memory_jar');
     if(mode) {
         if (protectcookies)
           selector.clearUnprotectedCookies("nontor");        
-        selector.saveCookies("nontor");
+        if (writeNontor)
+          selector.saveCookies("nontor");
         selector.clearCookies();
         if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars'))
             selector.loadCookies("tor", false);
     } else {
         if (protectcookies)
           selector.clearUnprotectedCookies("tor");          
-        if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars'))
+        if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars') && writeTor)
             selector.saveCookies("tor");
         selector.clearCookies();
         selector.loadCookies("nontor", false);

Modified: torbutton/branches/gsoc2009-koryk/src/chrome/content/torcookie.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/chrome/content/torcookie.js	2009-09-01 22:10:13 UTC (rev 20456)
+++ torbutton/branches/gsoc2009-koryk/src/chrome/content/torcookie.js	2009-09-02 00:10:58 UTC (rev 20457)
@@ -79,9 +79,7 @@
   //apply custom view
   cookiesTreeView.rowCount = cookies.length;
   cookiesTree.treeBoxObject.view = cookiesTreeView;    
- 
-  //grab data from xml files
-  //add protected tag
+  document.getElementById('defaultCookieGroup').selectedIndex = prefs.getBoolPref("extensions.torbutton.cookie_auto_protect")? 0 : 1;
 }
 function protectCookie()
 {
@@ -134,6 +132,7 @@
   }
   selector.protectCookies(protcookies);
   //output protected cookies
+  prefs.setBoolPref("extensions.torbutton.cookie_auto_protect",document.getElementById('saveAllCookies').selected);
 }
 function CookieColumnSort(column) {
   lastCookieSortAscending =

Modified: torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js	2009-09-01 22:10:13 UTC (rev 20456)
+++ torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js	2009-09-02 00:10:58 UTC (rev 20457)
@@ -170,10 +170,36 @@
     foStream.write(data, data.length);
     foStream.close();
   }
+  this.addProtectedCookie = function(cookie) {
+    var tor_enabled = this.prefs.getBoolPref("extensions.torbutton.tor_enabled");
+    var name = tor_enabled? "tor" : "nontor";
+    var cookies = this.getProtectedCookies(name);
+    var xml = <cookie>{cookie.value}</cookie>;
+    xml. at name = cookie.name;
+    xml. at host = cookie.host;
+    xml. at path = cookie.path;
+    if (cookie.isSecure)
+      xml. at isSecure = 1;
+    if (cookie.isSession) {
+      xml. at isSession = 1;
+      // session cookies get fucked up expiry. Give it 1yr if
+      // the user wants to save their session cookies
+      xml. at expiry = Date.now()/1000 + 365*24*60*60;
+    } else {
+      xml. at expiry = cookie.expiry; 
+    }
+    if (cookie.isHttpOnly)
+      xml. at isHttpOnly = 1;
+
+    
+    cookies.appendChild(xml);
+    this["protected-" + name] = cookies;
+    this._protectedCookiesToFile(name);
+  }
   this.getProtectedCookies = function(name) {
       var file = getProfileFile("protected-" + name + ".xml");
       if (!file.exists())
-          return null;
+        return null;
       var data = "";
       var fstream = Cc["@mozilla.org/network/file-input-stream;1"]
           .createInstance(Ci.nsIFileInputStream);
@@ -501,7 +527,6 @@
     }
     return this;
   },
-
   wrappedJSObject: null,  // Initialized by constructor
 
   // make this an nsIClassInfo object
@@ -524,7 +549,10 @@
   observe : function(aSubject, aTopic, aData) {
        switch(aTopic) { 
         case "cookie-changed":
+            var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);          
             this.timerCallback.cookie_changed = true;
+            if (aData = "added" && prefs.getBoolPref("extensions.torbutton.cookie_auto_protect"))
+              this.addProtectedCookie(aSubject.QueryInterface(Components.interfaces.nsICookie2));//protect the new cookie!
             break;
         case "app-startup": 
             var obsSvc = Components.classes["@mozilla.org/observer-service;1"].getService(nsIObserverService);

Modified: torbutton/branches/gsoc2009-koryk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/defaults/preferences/preferences.js	2009-09-01 22:10:13 UTC (rev 20456)
+++ torbutton/branches/gsoc2009-koryk/src/defaults/preferences/preferences.js	2009-09-02 00:10:58 UTC (rev 20457)
@@ -96,6 +96,7 @@
 pref("extensions.torbutton.clear_cookies",false);
 pref("extensions.torbutton.cookie_jars",true);
 pref("extensions.torbutton.cookie_protections",false);
+pref("extensions.torbutton.cookie_auto_protect",false);
 pref("extensions.torbutton.dual_cookie_jars",false);
 pref("extensions.torbutton.disable_domstorage",true);
 pref("extensions.torbutton.clear_cache",true);



More information about the tor-commits mailing list