[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torbutton/master] Bug 2843: Update preferences window to support env var.



commit 8ba1b90bd4b0d4309b96288239fded1e4bd099ee
Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date:   Wed Jun 22 15:40:58 2011 -0700

    Bug 2843: Update preferences window to support env var.
    
    These changes only make the preferences window sane wrt to the TOR_SOCKS_PORT
    environment var. We still need some code to set the pref during startup.
---
 src/chrome/content/preferences.js    |   47 ++++++++++++++++++++++++---------
 src/chrome/content/torbutton_util.js |   21 +++++++++++++++
 2 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index c18d40a..d72509a 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -14,26 +14,34 @@ function torbutton_prefs_set_field_attributes(doc)
     doc.getElementById('torbutton_panelStyle').setAttribute("disabled", !doc.getElementById('torbutton_displayStatusPanel').checked);
     doc.getElementById('torbutton_panelStyleText').setAttribute("disabled", !doc.getElementById('torbutton_displayStatusPanel').checked);
     doc.getElementById('torbutton_panelStyleIcon').setAttribute("disabled", !doc.getElementById('torbutton_displayStatusPanel').checked);
+
     // Privoxy is always recommended for Firefoxes not supporting socks_remote_dns
     if (doc.getElementById('torbutton_transparentTor').selected) {
         doc.getElementById('torbutton_settingsMethod').value = 'transparent';
-    }
-      else if (!torbutton_check_socks_remote_dns()) {
+    } else if (!torbutton_check_socks_remote_dns()) {
       doc.getElementById('torbutton_usePrivoxy').setAttribute("disabled", true);
     } else {
       doc.getElementById('torbutton_usePrivoxy').setAttribute("disabled", doc.getElementById('torbutton_settingsMethod').value != 'recommended');
     }
-    var proxy_port;
-    var proxy_host;
-    if (doc.getElementById('torbutton_usePrivoxy').checked) {
-        proxy_host = '127.0.0.1';
-        proxy_port = 8118;
-    } else {
-        proxy_host = '';
-        proxy_port = 0;
-    }
 
     if (doc.getElementById('torbutton_settingsMethod').value == 'recommended') {
+        var proxy_port;
+        var proxy_host;
+        if (torbutton_has_good_socks()) {
+          doc.getElementById('torbutton_usePrivoxy').checked = false;
+          doc.getElementById('torbutton_usePrivoxy').setAttribute("disabled", true);
+          proxy_host = '';
+          proxy_port = 0;
+        } else {
+          if (doc.getElementById('torbutton_usePrivoxy').checked) {
+            proxy_host = '127.0.0.1';
+            proxy_port = 8118;
+          } else {
+            proxy_host = '';
+            proxy_port = 0;
+          }
+        }
+
         torbutton_log(2, "using recommended settings");
         if (!torbutton_check_socks_remote_dns()) {
             doc.getElementById('torbutton_httpProxy').value = proxy_host;
@@ -55,8 +63,21 @@ function torbutton_prefs_set_field_attributes(doc)
             doc.getElementById('torbutton_gopherProxy').value = '';
             doc.getElementById('torbutton_gopherPort').value = 0;
         }
-        doc.getElementById('torbutton_socksHost').value = '127.0.0.1';
-        doc.getElementById('torbutton_socksPort').value = 9050;
+
+        var environ = Components.classes["@mozilla.org/process/environment;1"]
+                   .getService(Components.interfaces.nsIEnvironment);
+
+        if (environ.exists("TOR_SOCKS_PORT")) {
+          doc.getElementById('torbutton_socksPort').value = parseInt(environ.get("TOR_SOCKS_PORT"));
+        } else {
+          doc.getElementById('torbutton_socksPort').value = 9050;
+        }
+
+        if (environ.exists("TOR_SOCKS_HOST")) {
+          doc.getElementById('torbutton_socksHost').value = environ.get("TOR_SOCKS_HOST");
+        } else {
+          doc.getElementById('torbutton_socksHost').value = '127.0.0.1';
+        }
 
         doc.getElementById('torbutton_httpProxy').disabled = true;
         doc.getElementById('torbutton_httpPort').disabled = true;
diff --git a/src/chrome/content/torbutton_util.js b/src/chrome/content/torbutton_util.js
index fb17932..808c826 100644
--- a/src/chrome/content/torbutton_util.js
+++ b/src/chrome/content/torbutton_util.js
@@ -6,6 +6,7 @@ var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
     .getService(Components.interfaces.nsIXULAppInfo);
 var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
     .getService(Components.interfaces.nsIVersionComparator);
+var m_tb_ff5 = false;
 var m_tb_ff4 = false;
 
 if(versionChecker.compare(appInfo.version, "4.0a1") >= 0) {
@@ -13,6 +14,11 @@ if(versionChecker.compare(appInfo.version, "4.0a1") >= 0) {
 } else {
     m_tb_ff4 = false;
 }
+if(versionChecker.compare(appInfo.version, "5.0a1") >= 0) {
+    m_tb_ff5 = true;
+} else {
+    m_tb_ff5 = false;
+}
 
 
 function torbutton_eclog(nLevel, sMsg) {
@@ -97,6 +103,21 @@ function torbutton_check_socks_remote_dns()
     }
 }
 
+function torbutton_has_good_socks() {
+  if(m_tb_ff5) {
+    return true;
+  }
+
+  // TBB will set this pref if it has the SOCKS timeout patch applied
+  var environ = Components.classes["@mozilla.org/process/environment;1"]
+      .getService(Components.interfaces.nsIEnvironment);
+
+  if (environ.exists("TOR_SOCKS_PORT"))
+    return true;
+
+  return false;
+}
+
 function torbutton_check_status() {
     var liveprefs = false;
     var torprefs = false;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits