[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r20324: {torbutton} All of cookie protection's functionality except for the auto (in torbutton/branches/gsoc2009-koryk/src: chrome/content components)
Author: koryk
Date: 2009-08-16 18:00:19 -0400 (Sun, 16 Aug 2009)
New Revision: 20324
Modified:
torbutton/branches/gsoc2009-koryk/src/chrome/content/popup.xul
torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.js
torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.xul
torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js
torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js
Log:
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.
Modified: torbutton/branches/gsoc2009-koryk/src/chrome/content/popup.xul
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/chrome/content/popup.xul 2009-08-16 12:28:51 UTC (rev 20323)
+++ torbutton/branches/gsoc2009-koryk/src/chrome/content/popup.xul 2009-08-16 22:00:19 UTC (rev 20324)
@@ -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;"
Modified: torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.js 2009-08-16 12:28:51 UTC (rev 20323)
+++ torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.js 2009-08-16 22:00:19 UTC (rev 20324)
@@ -162,7 +162,7 @@
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;
@@ -173,26 +173,35 @@
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;
@@ -287,21 +296,32 @@
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;
+
}
}
@@ -368,6 +388,7 @@
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);
Modified: torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.xul
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.xul 2009-08-16 12:28:51 UTC (rev 20323)
+++ torbutton/branches/gsoc2009-koryk/src/chrome/content/preferences.xul 2009-08-16 22:00:19 UTC (rev 20324)
@@ -221,7 +221,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)"/>
Modified: torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js 2009-08-16 12:28:51 UTC (rev 20323)
+++ torbutton/branches/gsoc2009-koryk/src/chrome/content/torbutton.js 2009-08-16 22:00:19 UTC (rev 20324)
@@ -1374,7 +1374,17 @@
}
}
+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');
@@ -1505,6 +1515,7 @@
cm.removeAll();
}
+
function torbutton_jar_cookies(mode) {
var selector =
Components.classes["@stanford.edu/cookie-jar-selector;1"]
@@ -1518,14 +1529,18 @@
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);
Modified: torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js
===================================================================
--- torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js 2009-08-16 12:28:51 UTC (rev 20323)
+++ torbutton/branches/gsoc2009-koryk/src/components/cookie-jar-selector.js 2009-08-16 22:00:19 UTC (rev 20324)
@@ -239,7 +239,7 @@
cookiesAsXml.appendChild(xml);
}
this["protected-" + name] = cookiesAsXml;
- }
+ };
this._cookiesFromFile = function(name) {
var file = getProfileFile("cookies-" + name + ".xml");
if (!file.exists())
@@ -306,7 +306,41 @@
// 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.@name;
+ var chost = xml.@host;
+ var cpath = xml.@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"]