[or-cvs] [torbutton/master] 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.
mikeperry at seul.org
mikeperry at seul.org
Wed Sep 23 23:49:11 UTC 2009
Author: Kory Kork <kory at korykirk.com>
Date: Wed, 2 Sep 2009 00:10:58 +0000
Subject: Auto-protect cookies works (finally)
Commit: 35ad67b94a30813f2dfc724b2623e029b5a24c2d
svn:r20457
---
src/chrome/content/torbutton.js | 7 ++++-
src/chrome/content/torcookie.js | 5 +--
src/components/cookie-jar-selector.js | 32 +++++++++++++++++++++++++++++-
src/defaults/preferences/preferences.js | 1 +
4 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 1ed1e79..27192c6 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1563,17 +1563,20 @@ function torbutton_jar_cookies(mode) {
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);
diff --git a/src/chrome/content/torcookie.js b/src/chrome/content/torcookie.js
index 4a017fd..dcb420b 100644
--- a/src/chrome/content/torcookie.js
+++ b/src/chrome/content/torcookie.js
@@ -79,9 +79,7 @@ function initDialog() {
//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 @@ function acceptDialog() {
}
selector.protectCookies(protcookies);
//output protected cookies
+ prefs.setBoolPref("extensions.torbutton.cookie_auto_protect",document.getElementById('saveAllCookies').selected);
}
function CookieColumnSort(column) {
lastCookieSortAscending =
diff --git a/src/components/cookie-jar-selector.js b/src/components/cookie-jar-selector.js
index 4426d78..d8d4401 100644
--- a/src/components/cookie-jar-selector.js
+++ b/src/components/cookie-jar-selector.js
@@ -170,10 +170,36 @@ function CookieJarSelector() {
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 @@ CookieJarSelector.prototype =
}
return this;
},
-
wrappedJSObject: null, // Initialized by constructor
// make this an nsIClassInfo object
@@ -524,7 +549,10 @@ CookieJarSelector.prototype =
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);
diff --git a/src/defaults/preferences/preferences.js b/src/defaults/preferences/preferences.js
index 5a29048..f3b588c 100644
--- a/src/defaults/preferences/preferences.js
+++ b/src/defaults/preferences/preferences.js
@@ -98,6 +98,7 @@ pref("extensions.torbutton.no_tor_plugins",true);
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);
--
1.5.6.5
More information about the tor-commits
mailing list