[or-cvs] [torbutton/master] All of cookie protection's functionality except for the automatically protect/unprotect new cookies. There are a few bugs I need to work out too.

mikeperry at seul.org mikeperry at seul.org
Wed Sep 23 23:49:11 UTC 2009


Author: Kory Kork <kory at korykirk.com>
Date: Sun, 16 Aug 2009 22:00:19 +0000
Subject: All of cookie protection's functionality except for the automatically protect/unprotect new cookies. There are a few bugs I need to work out too.
Commit: b782554684cb79c2dbf20160131808228f69f9e1

svn:r20324
---
 src/chrome/content/popup.xul          |   10 ++++----
 src/chrome/content/preferences.js     |   31 +++++++++++++++++++++++----
 src/chrome/content/preferences.xul    |    4 ++-
 src/chrome/content/torbutton.js       |   21 ++++++++++++++++--
 src/components/cookie-jar-selector.js |   36 ++++++++++++++++++++++++++++++++-
 5 files changed, 87 insertions(+), 15 deletions(-)

diff --git a/src/chrome/content/popup.xul b/src/chrome/content/popup.xul
index db576ca..685bb32 100644
--- a/src/chrome/content/popup.xul
+++ b/src/chrome/content/popup.xul
@@ -9,8 +9,9 @@
     <stringbundleset id="torbutton-stringbundleset">
         <stringbundle id="torbutton-bundle" src="chrome://torbutton/locale/torbutton.properties"/>
     </stringbundleset>
+    <script src="chrome://torbutton/content/torbutton.js" type="application/x-javascript"/>
 
-    <popup id="torbutton-context-menu">
+    <popup id="torbutton-context-menu" onpopupshowing="checkProtections();">
         <menuitem id="torbutton-toggle"
                   label="&torbutton.context_menu.toggle;"
                   accesskey="&torbutton.context_menu.toggle.key;"
@@ -22,12 +23,11 @@
                   accesskey="&torbutton.context_menu.preferences.key;"
                   insertafter="context-stop"
                   oncommand="torbutton_open_prefs_dialog()"/>
-        <menuitem  id="torbutton-cookies" 
+        <menuitem  id="torbutton-cookie-protector"
                   label="Cookie Protections"
                   accesskey="C"
-                  insertafter="context-stop"
-                  oncommand="window.openDialog('chrome://torbutton/content/torcookiedialog.xul','Cookie Protections',
-                                   'centerscreen,chrome,dialog,modal,resizable')"/>
+                  insertafter="context-stop"                  
+                  oncommand="torbutton_open_cookie_dialog()"/>
         <menuitem id="torbutton-about"
                   label="&torbutton.context_menu.about;"
                   accesskey="&torbutton.context_menu.about.key;"
diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index ee1a843..e73f94b 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -166,7 +166,7 @@ function torbutton_prefs_init(doc) {
         o_torprefs.setBoolPref('cookie_jars', false);
         o_torprefs.setBoolPref('dual_cookie_jars', false);
         o_torprefs.setBoolPref('clear_cookies', true); 
-
+        o_torprefs.setBoolPref('cookie_protections',false);
         o_torprefs.setBoolPref('tor_memory_jar', true);
         o_torprefs.setBoolPref('nontor_memory_jar', true);
         doc.getElementById('torbutton_torMemoryJar').disabled = true;
@@ -177,26 +177,35 @@ function torbutton_prefs_init(doc) {
         o_torprefs.setBoolPref('cookie_jars', true);
         o_torprefs.setBoolPref('dual_cookie_jars', false);
         o_torprefs.setBoolPref('clear_cookies', false);
-
+        o_torprefs.setBoolPref('cookie_protections',false);        
         o_torprefs.setBoolPref('tor_memory_jar', true);
         doc.getElementById('torbutton_torMemoryJar').disabled = true;
-        doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;
+        doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;        
     } else if(o_torprefs.getBoolPref('dual_cookie_jars')) {
         doc.getElementById('torbutton_cookieGroup').selectedItem =
             doc.getElementById('torbutton_dualCookieJars');
         o_torprefs.setBoolPref('cookie_jars', false);
         o_torprefs.setBoolPref('dual_cookie_jars', true);
         o_torprefs.setBoolPref('clear_cookies', false); 
-
+        o_torprefs.setBoolPref('cookie_protections',false);
         doc.getElementById('torbutton_torMemoryJar').disabled = false;
         doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;
+    } else if(o_torprefs.getBoolPref('cookie_protections')) {
+        doc.getElementById('torbutton_cookieGroup').selectedItem =
+            doc.getElementById('torbutton_cookieProtections');
+        o_torprefs.setBoolPref('cookie_jars', false);
+        o_torprefs.setBoolPref('dual_cookie_jars', false);
+        o_torprefs.setBoolPref('clear_cookies', false); 
+        o_torprefs.setBoolPref('tor_memory_jar', false);
+        o_torprefs.setBoolPref('nontor_memory_jar', false);
+        doc.getElementById('torbutton_torMemoryJar').disabled = true;
+        doc.getElementById('torbutton_nonTorMemoryJar').disabled = true;
     } else {
         doc.getElementById('torbutton_cookieGroup').selectedItem =
             doc.getElementById('torbutton_mmmCookies');
         o_torprefs.setBoolPref('cookie_jars', false);
         o_torprefs.setBoolPref('dual_cookie_jars', false);
         o_torprefs.setBoolPref('clear_cookies', false); 
-
         o_torprefs.setBoolPref('tor_memory_jar', false);
         o_torprefs.setBoolPref('nontor_memory_jar', false);
         doc.getElementById('torbutton_torMemoryJar').disabled = true;
@@ -291,21 +300,32 @@ function torbutton_cookie_update(doc) {
         doc.getElementById('torbutton_nonTorMemoryJar').checked = true;
         doc.getElementById('torbutton_torMemoryJar').disabled = true;
         doc.getElementById('torbutton_nonTorMemoryJar').disabled = true;
+
     } else if(doc.getElementById('torbutton_cookieGroup').selectedItem
             == doc.getElementById('torbutton_cookieJars')) {
         doc.getElementById('torbutton_torMemoryJar').checked = true;
         doc.getElementById('torbutton_torMemoryJar').disabled = true;
         doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;
+
     } else if(doc.getElementById('torbutton_cookieGroup').selectedItem
             == doc.getElementById('torbutton_dualCookieJars')) {
         doc.getElementById('torbutton_torMemoryJar').disabled = false;
         doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;
+
     } else if(doc.getElementById('torbutton_cookieGroup').selectedItem
             == doc.getElementById('torbutton_mmmCookies')) {
         doc.getElementById('torbutton_torMemoryJar').checked = false;
         doc.getElementById('torbutton_nonTorMemoryJar').checked = false;
         doc.getElementById('torbutton_torMemoryJar').disabled = true;
         doc.getElementById('torbutton_nonTorMemoryJar').disabled = true;
+
+    } else if(doc.getElementById('torbutton_cookieGroup').selectedItem
+            == doc.getElementById('torbutton_cookieProtections')) {
+        doc.getElementById('torbutton_torMemoryJar').checked = false;
+        doc.getElementById('torbutton_nonTorMemoryJar').checked = false;
+        doc.getElementById('torbutton_torMemoryJar').disabled = true;
+        doc.getElementById('torbutton_nonTorMemoryJar').disabled = true;
+
     }
 }
 
@@ -374,6 +394,7 @@ function torbutton_prefs_save(doc) {
     o_torprefs.setBoolPref('clear_cookies', doc.getElementById('torbutton_clearCookies').selected);
     o_torprefs.setBoolPref('cookie_jars', doc.getElementById('torbutton_cookieJars').selected);
     o_torprefs.setBoolPref('dual_cookie_jars', doc.getElementById('torbutton_dualCookieJars').selected);
+    o_torprefs.setBoolPref('cookie_protections', doc.getElementById('torbutton_cookieProtections').selected);
     o_torprefs.setBoolPref('disable_domstorage', doc.getElementById('torbutton_noDomStorage').checked);
     o_torprefs.setBoolPref('clear_http_auth', doc.getElementById('torbutton_clearHttpAuth').checked);
     o_torprefs.setBoolPref('block_js_history', doc.getElementById('torbutton_blockJSHistory').checked);
diff --git a/src/chrome/content/preferences.xul b/src/chrome/content/preferences.xul
index 5fa6989..38e4c09 100644
--- a/src/chrome/content/preferences.xul
+++ b/src/chrome/content/preferences.xul
@@ -239,7 +239,9 @@
             <radio id="torbutton_dualCookieJars"
                     label="&torbutton.prefs.dual_cookie_jars;" 
                     oncommand="torbutton_prefs_set_field_attributes(document)"/>
-
+            <radio id="torbutton_cookieProtections"
+                    label="Use the Cookie Protections dialog to choose which cookies are protected"
+                    oncommand="torbutton_prefs_set_field_attributes(document)"/>
             <radio id="torbutton_mmmCookies"
                     label="&torbutton.prefs.mmm_cookies;" 
                     oncommand="torbutton_prefs_set_field_attributes(document)"/> 
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 1a35c65..b7e9e23 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1408,7 +1408,17 @@ function torbutton_close_on_toggle(mode) {
     }
 }
 
+function checkProtections()
+{
+  var pref = m_tb_prefs.getBoolPref("extensions.torbutton.cookie_protections");
+  document.getElementById("torbutton-cookie-protector").disabled = !pref; 
+}
+
+function torbutton_open_cookie_dialog() {
 
+  window.openDialog('chrome://torbutton/content/torcookiedialog.xul','Cookie Protections',
+                                   'centerscreen,chrome,dialog,modal,resizable');
+}
 function torbutton_open_prefs_dialog() {
     window.openDialog("chrome://torbutton/content/preferences.xul","torbutton-preferences","centerscreen, chrome");
     torbutton_log(2, 'opened preferences window');
@@ -1539,6 +1549,7 @@ function torbutton_clear_cookies() {
     cm.removeAll();
 }
 
+
 function torbutton_jar_cookies(mode) {
     var selector =
           Components.classes["@stanford.edu/cookie-jar-selector;1"]
@@ -1552,14 +1563,18 @@ function torbutton_jar_cookies(mode) {
         window.alert(warning);
         return;
     }*/
-
+    var protectcookies = m_tb_prefs.getBoolPref('extensions.torbutton.cookie_protections');
     if(mode) {
+        if (protectcookies)
+          selector.clearUnprotectedCookies("nontor");        
         selector.saveCookies("nontor");
         selector.clearCookies();
-        if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars'))
+        if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars') || protectcookies)
             selector.loadCookies("tor", false);
     } else {
-        if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars'))
+        if (protectcookies)
+          selector.clearUnprotectedCookies("tor");          
+        if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars') || protectcookies)
             selector.saveCookies("tor");
         selector.clearCookies();
         selector.loadCookies("nontor", false);
diff --git a/src/components/cookie-jar-selector.js b/src/components/cookie-jar-selector.js
index 8ffe895..c506ca7 100644
--- a/src/components/cookie-jar-selector.js
+++ b/src/components/cookie-jar-selector.js
@@ -239,7 +239,7 @@ function CookieJarSelector() {
         cookiesAsXml.appendChild(xml);
     }
     this["protected-" + name] = cookiesAsXml;
-  }
+  };
   this._cookiesFromFile = function(name) {
       var file = getProfileFile("cookies-" + name + ".xml");
       if (!file.exists())
@@ -306,7 +306,41 @@ function CookieJarSelector() {
     // ok, everything's fine
     this.logger.log(2, "Cookies saved");
   };
-
+  this.clearUnprotectedCookies = function(name) {
+  var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                        .getService(Components.interfaces.nsIPromptService);
+
+    var cookiesAsXml = this.getProtectedCookies(name);
+    if (cookiesAsXml == null)
+      return;//file does not exist - no protected cookies
+    var cookiemanager =
+      Cc["@mozilla.org/cookiemanager;1"]
+      .getService(Ci.nsICookieManager);
+    
+    var enumerator = cookiemanager.enumerator;
+    var count = 0;
+    var protcookie = false;
+    prompts.alert(null, "hey", cookiesAsXml.cookie.length());
+
+    while (enumerator.hasMoreElements()) {
+    var nextCookie = enumerator.getNext();
+    for (var i = 0; i < cookiesAsXml.cookie.length(); i++) {
+      var xml = cookiesAsXml.cookie[i];
+      var cvalue = xml.toString();
+      var cname = xml. at name; 
+      var chost = xml. at host;
+      var cpath = xml. at path;
+      protcookie = (nextCookie.host == chost && nextCookie.name == cname && nextCookie.path == cpath)        
+    }
+      if (!protcookie)
+       cookiemanager.remove(nextCookie.host,
+                         nextCookie.name,
+                         nextCookie.path,
+                         false);
+      protcookie = false;
+    }                     
+  }
+  
   this._oldLoadCookies = function(name, deleteSavedCookieJar) {
     var cookieManager =
       Cc["@mozilla.org/cookiemanager;1"]
-- 
1.5.6.5




More information about the tor-commits mailing list