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

[or-cvs] r15424: Make toggling a multi-step process marked by 3 prefs. May he (in torbutton/trunk/src: chrome/content components defaults/preferences)



Author: mikeperry
Date: 2008-06-23 02:22:06 -0400 (Mon, 23 Jun 2008)
New Revision: 15424

Modified:
   torbutton/trunk/src/chrome/content/preferences.js
   torbutton/trunk/src/chrome/content/torbutton.js
   torbutton/trunk/src/chrome/content/torbutton_util.js
   torbutton/trunk/src/components/cssblocker.js
   torbutton/trunk/src/defaults/preferences/preferences.js
Log:

Make toggling a multi-step process marked by 3 prefs. May
help fix/track some odd bugs with toggles not applying
immediately, and help protect against potential race
conditions that may exist due to Firefox Bug 409737. Also
some fixes to "Restore Defaults".



Modified: torbutton/trunk/src/chrome/content/preferences.js
===================================================================
--- torbutton/trunk/src/chrome/content/preferences.js	2008-06-23 05:02:34 UTC (rev 15423)
+++ torbutton/trunk/src/chrome/content/preferences.js	2008-06-23 06:22:06 UTC (rev 15424)
@@ -365,6 +365,8 @@
     var children;
     var i;
     var was_enabled = false;
+    var loglevel = o_torprefs.getIntPref("loglevel");
+    var loglmthd = o_torprefs.getIntPref("logmethod");
     
     torbutton_log(3, "Starting Pref reset");
 
@@ -398,6 +400,10 @@
             o_torprefs.clearUserPref(children[i]);
     }
 
+    // Keep logging the same.
+    o_torprefs.setIntPref("loglevel", loglevel);
+    o_torprefs.setIntPref("logmethod", logmthd);
+
     children = o_proxyprefs.getChildList("" , tmpcnt);
     for(i = 0; i < children.length; i++) {
         if(o_proxyprefs.prefHasUserValue(children[i]))
@@ -413,10 +419,18 @@
     // It's the non-technical ones we should make it easy for
     torbutton_reset_browser_prefs();
 
+    chrome.torbutton_init_prefs();
     torbutton_log(3, "Prefs reset");
 
     if(was_enabled) {
-        chrome.torbutton_enable_tor();
+        // Hack for torbrowser/others where tor proxies are the same
+        // as non-tor.
+        if(chrome.torbutton_check_status()) {
+            torbutton_log(4, "Tor still enabled after reset. Attempting to restore sanity");
+            chrome.torbutton_set_status();
+        } else {
+            chrome.torbutton_enable_tor();
+        }
     }
 
     torbutton_log(4, "Preferences reset to defaults");

Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2008-06-23 05:02:34 UTC (rev 15423)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2008-06-23 06:22:06 UTC (rev 15424)
@@ -45,8 +45,11 @@
             case "extensions.torbutton.panel_style":
                 torbutton_set_panel_style();
                 break;
-            case "extensions.torbutton.tor_enabled":
-                var mode = m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
+
+            // FIXME: Maybe make a intermediate state with a yellow 
+            // icon?
+            case "extensions.torbutton.settings_applied":
+                var mode = m_tb_prefs.getBoolPref("extensions.torbutton.settings_applied");
                 torbutton_update_toolbutton(mode);
                 torbutton_update_statusbar(mode);
                 break;
@@ -246,12 +249,41 @@
 }
 
 function torbutton_set_status() {
+    var state = false;
     if (torbutton_check_status()) {
-        torbutton_log(3,'status: tor is enabled');
-        torbutton_update_status(true, false);
+        state = true;
+        try {
+            torbutton_update_status(true, false);
+        } catch(e) {
+            // This should never happen.. 
+            // FIXME: Do we need to translate it? I'm guessing not.
+            window.alert("Please file bug report! Error applying Tor settings: "+e);
+            torbutton_log(5,'Error applying tor settings: '+e);
+            // Setting these prefs should avoid ininite recursion
+            // because torbutton_update_status should return immediately
+            // on the next call.
+            m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", false);
+            m_tb_prefs.setBoolPref("extensions.torbutton.proxies_applied", false);
+            m_tb_prefs.setBoolPref("extensions.torbutton.settings_applied", false);
+            torbutton_disable_tor();
+        }
     } else {
-        torbutton_log(3,'status: tor is disabled');
-        torbutton_update_status(false, false);
+        state = false;
+        try {
+            torbutton_update_status(false, false);
+        } catch(e) {
+            // This should never happen.. 
+            // FIXME: Do we need to translate it? I'm guessing not.
+            window.alert("Please file bug report! Error applying Non-Tor settings: "+e);
+            torbutton_log(5,'Error applying nontor settings: '+e);
+            // Setting these prefs should avoid ininite recursion
+            // because torbutton_update_status should return immediately
+            // on the next call.
+            m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", true);
+            m_tb_prefs.setBoolPref("extensions.torbutton.proxies_applied", true);
+            m_tb_prefs.setBoolPref("extensions.torbutton.settings_applied", true);
+            torbutton_enable_tor();
+        }
     }
 }
 
@@ -474,6 +506,8 @@
   }
 
   torbutton_log(2, 'restoring nontor settings');
+
+  m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", false);
   liveprefs.setIntPref('type',          savprefs.getIntPref('type'));
   liveprefs.setCharPref('http',         savprefs.getCharPref('http_proxy'));
   liveprefs.setIntPref('http_port',     savprefs.getIntPref('http_port'));
@@ -494,6 +528,13 @@
   torbutton_log(1, 'almost there');
   if (torbutton_check_socks_remote_dns())
     liveprefs.setBoolPref('socks_remote_dns',     savprefs.getBoolPref('socks_remote_dns'));
+
+  // This is needed for torbrowser and other cases where the 
+  // proxy prefs are actually the same..
+  if(torbutton_check_status()) {
+      m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", true);
+  }
+
   torbutton_log(2, 'settings restored');
 }
 
@@ -620,19 +661,23 @@
     var sPrefix;
     var label;
     var tooltip;
-    
+   
     var torprefs = torbutton_get_prefbranch('extensions.torbutton.');
-    var changed = (torprefs.getBoolPref('tor_enabled') != mode);
-    torprefs.setBoolPref('tor_enabled', mode);
+    var changed = (torprefs.getBoolPref('proxies_applied') != mode);
 
-    torbutton_log(2, 'called update_status: '+mode);
-    torbutton_log(2, 'Changed: '+changed);
+    torbutton_log(2, 'called update_status: '+mode+","+changed);
 
     // this function is called every time there is a new window! Alot of this
     // stuff expects to be called on toggle only.. like the cookie jars and
     // history/cookie clearing
     if(!changed && !force_update) return;
 
+    torprefs.setBoolPref('proxies_applied', mode);
+    if(torprefs.getBoolPref("tor_enabled") != mode) {
+        torbutton_log(3, 'Got external update for: '+mode);
+        torprefs.setBoolPref("tor_enabled", mode);
+    }
+
     if(m_tb_ff3 
             && !m_tb_prefs.getBoolPref("extensions.torbutton.warned_ff3")
             && mode && changed) {
@@ -958,6 +1003,9 @@
     if (m_tb_prefs.getBoolPref('extensions.torbutton.jar_certs')) {
         torbutton_jar_certs(mode);
     }
+
+    m_tb_prefs.setBoolPref("extensions.torbutton.settings_applied", mode);
+    torbutton_log(3, "Settings applied for mode: "+mode);
 }
 
 function torbutton_close_on_toggle(mode) {
@@ -1581,7 +1629,9 @@
     var warning = o_stringbundle.GetStringFromName("torbutton.popup.history.warning");
 
     this.f1 = function() {
-        if(this.browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
+        // Block everything unless we've reached steady state
+        if((this.browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled"))
+                || (this.browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.settings_applied"))
                 && m_tb_prefs.getBoolPref("extensions.torbutton.block_js_history")) {
             torbutton_log(3, "Blocking history manipulation");
             window.alert(warning);
@@ -1707,8 +1757,26 @@
     // Crash detection code (works w/ components/crash-observer.js)
     if(m_tb_prefs.getBoolPref("extensions.torbutton.crashed")) {
         torbutton_log(4, "Crash detected, attempting recovery");
-        m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", 
-                torbutton_check_status());
+        var state = torbutton_check_status();
+        if(state != m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
+                || state != m_tb_prefs.getBoolPref("extensions.torbutton.proxies_applied")
+                || state != m_tb_prefs.getBoolPref("extensions.torbutton.settings_applied")) {
+            var te = m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
+            var pa = m_tb_prefs.getBoolPref("extensions.torbutton.proxies_applied");
+            var sa = m_tb_prefs.getBoolPref("extensions.torbutton.settings_applied");
+            // XXX: It is likely this will happen.. prefs may get out of 
+            // sync if not written to disk properly.. Needs testing
+            window.alert("Crash state conflict! Please file bug report with these four values: "
+                    +state+","+te+","+pa+","+sa);
+            torbutton_log(5, "Crash state conflict: "+state+","
+                    +te+","+pa+","+sa);
+        }
+
+        // FIXME: consider trying to check these to see what work we may 
+        // need to redo?
+        m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", state);
+        m_tb_prefs.setBoolPref("extensions.torbutton.proxies_applied", state);
+        m_tb_prefs.setBoolPref("extensions.torbutton.settings_applied", state);
        
         // Do the restore cookies first because we potentially save
         // cookies by toggling tor state in the next pref. If we
@@ -1751,8 +1819,6 @@
   } else if (topic == "quit-application-granted") {
     if (this._uninstall) {
         torbutton_disable_tor();
-        // Still called by pref observer:
-        // torbutton_update_status(false, false);
 
         // Reset all browser prefs that torbutton touches just in case
         // they get horked. Better everything gets set back to default
@@ -1835,9 +1901,11 @@
                   if(wind.browserDOMWindow) {
                       var browser = wind.getBrowser().selectedTab.linkedBrowser;
                       // This can happen in the first request of a new state.
+                      // block favicons till we've reach steady state
                       if((typeof(browser.__tb_tor_fetched) != "undefined")
-                        && browser.__tb_tor_fetched != 
-                              m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")) {
+                        && (browser.__tb_tor_fetched != 
+                              m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
+                              || browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.settings_applied"))) {
                           subject.cancel(0x804b0002); // NS_BINDING_ABORTED
                           torbutton_eclog(3, 'Cancelling opposing (favicon?) request: '+subject.name);
                       }
@@ -1958,6 +2026,7 @@
 { 
     // listening for new tabs
     torbutton_log(2, "New tab");
+
     var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
     var no_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");
     var browser = event.currentTarget;
@@ -2168,7 +2237,9 @@
     torbutton_log(2, "Got browser "+browser.contentWindow.location+" for: " 
             + win.location + ", under: "+win.top.location);
 
-    var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
+    // Base this tag off of proxies_applied, since we want to go
+    // by whatever the actual load proxy was
+    var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.proxies_applied");
     var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");
     var kill_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");
 
@@ -2373,7 +2444,9 @@
                         torbutton_eclog(3, 'Got browser for request: ' + (browser != null));
 
                         // XXX: This may block ssl popups in the first tab
-                        if(browser && browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")) {
+                        if(browser && 
+                                (browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
+                                 || browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.settings_applied"))) {
                             try {
                                 torbutton_eclog(3, 'Stopping document: '+DOMWindow.location);
                                 aRequest.cancel(0x804b0002); // NS_BINDING_ABORTED

Modified: torbutton/trunk/src/chrome/content/torbutton_util.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton_util.js	2008-06-23 05:02:34 UTC (rev 15423)
+++ torbutton/trunk/src/chrome/content/torbutton_util.js	2008-06-23 06:22:06 UTC (rev 15424)
@@ -146,6 +146,7 @@
   }
 
   torbutton_log(2, 'Activate tor settings');
+  torprefs.setBoolPref("tor_enabled", true);
   liveprefs.setCharPref('http',         torprefs.getCharPref('http_proxy'));
   liveprefs.setIntPref('http_port',     torprefs.getIntPref('http_port'));
   liveprefs.setCharPref('ssl',          torprefs.getCharPref('https_proxy'));

Modified: torbutton/trunk/src/components/cssblocker.js
===================================================================
--- torbutton/trunk/src/components/cssblocker.js	2008-06-23 05:02:34 UTC (rev 15423)
+++ torbutton/trunk/src/components/cssblocker.js	2008-06-23 06:22:06 UTC (rev 15424)
@@ -119,6 +119,8 @@
 
     this.isolate_content = this._prefs.getBoolPref("extensions.torbutton.isolate_content");
     this.tor_enabled = this._prefs.getBoolPref("extensions.torbutton.tor_enabled");
+    this.settings_applied = this._prefs.getBoolPref("extensions.torbutton.settings_applied");
+    this.tor_enabling = this.tor_enabled || this.settings_applied; // Catch transition edge cases
     this.block_tor_file_net = this._prefs.getBoolPref("extensions.torbutton.block_tor_file_net");
     this.block_nontor_file_net = this._prefs.getBoolPref("extensions.torbutton.block_nontor_file_net");
     this.no_tor_plugins = this._prefs.getBoolPref("extensions.torbutton.no_tor_plugins");
@@ -165,7 +167,7 @@
         }
 
         if (!requestOrigin || !requestOrigin.scheme) {
-            if (this.tor_enabled) {
+            if (this.tor_enabling) {
                 // in FF3, at startup requestOrigin is not set
                 if (("chrome" == contentLocation.scheme) && (contentLocation.host in browserSources)) {
                     this.logger.eclog(1, "Allowing browser chrome request from: " +
@@ -213,8 +215,8 @@
                                       contentLocation.spec);
                     return ok;
                 } else {
-                    if (this.block_tor_file_net && this.tor_enabled ||
-                            this.block_nontor_file_net && !this.tor_enabled) {
+                    if (this.block_tor_file_net && this.tor_enabling ||
+                            this.block_nontor_file_net && !this.tor_enabling) {
                         this.logger.eclog(4, "Blocking remote request from: " +
                                           requestOrigin.spec + " for: " +
                                           contentLocation.spec);
@@ -224,9 +226,8 @@
                 break;
             case "moz-nullprincipal":
                 // forbidden
-                // XXX: 
-                if (this.tor_enabled) {
-                    this.logger.eclog(3, "Blocking request from: " +
+                if (this.tor_enabling) {
+                    this.logger.eclog(4, "Blocking request from: " +
                                       requestOrigin.spec + " for: " +
                                       contentLocation.spec);
                     return block;
@@ -254,8 +255,8 @@
                                           contentLocation.spec);
                         return ok;
                     } else {
-                        if (this.tor_enabled || ("torbutton" == targetHost)) {
-                            this.logger.eclog(3, "Blocking local request from: "
+                        if (this.tor_enabling || ("torbutton" == targetHost)) {
+                            this.logger.eclog(4, "Blocking local request from: "
                                               +requestOrigin.spec+" ("
                                               +requestOrigin.scheme+") for: "+
                                               contentLocation.spec);
@@ -275,13 +276,11 @@
 			wind = node;
 		}
 
-        var tor_state = this.tor_enabled;
-
         if (contentType == 5) { // Object
             // Never seems to happen.. But it would be nice if we 
             // could handle it either here or shouldProcess, instead of in 
             // the webprogresslistener
-            if(this.tor_enabled && this.no_tor_plugins) {
+            if(this.tor_enabling && this.no_tor_plugins) {
                 this.logger.log(4, "Blocking object at "+contentLocation.spec);
                 return block;
             }
@@ -316,7 +315,7 @@
 
         // For javascript links (and others?) the normal http events
         // for the weblistener in torbutton.js are suppressed
-        if(tor_state && node instanceof Ci.nsIDOMWindow) {
+        if(this.tor_enabling && node instanceof Ci.nsIDOMWindow) {
             var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
                          .getService(Components.interfaces.nsIWindowMediator);
             var chrome = wm.getMostRecentWindow("navigator:browser");
@@ -350,7 +349,8 @@
                             this.logger.log(3, "Untagged window for redirect "+contentLocation.spec);
                             return ok;
                         }
-                        if(browser.__tb_tor_fetched == tor_state) {
+                        if(browser.__tb_tor_fetched == this.tor_enabled
+                                && browser.__tb_tor_fetched == this.settings_applied) {
                             return ok;
                         } else {
                             this.logger.log(4, "Blocking redirect: "+contentLocation.spec);
@@ -362,7 +362,8 @@
             }
         }
 
-        if(browser.__tb_tor_fetched == tor_state) {
+        if(browser.__tb_tor_fetched == this.tor_enabled
+                && browser.__tb_tor_fetched == this.settings_applied) {
             return ok;
         } else {
             this.logger.log(4, "Blocking cross state load of: "+contentLocation.spec);
@@ -395,7 +396,12 @@
                 break;
             case "extensions.torbutton.tor_enabled":
                 this.tor_enabled = this._prefs.getBoolPref("extensions.torbutton.tor_enabled");
+                this.tor_enabling = this.tor_enabled || this.settings_applied; // Catch transition edge cases
                 break;
+            case "extensions.torbutton.settings_applied":
+                this.settings_applied = this._prefs.getBoolPref("extensions.torbutton.settings_applied");
+                this.tor_enabling = this.tor_enabled || this.settings_applied; // Catch transition edge cases
+                break;
             case "extensions.torbutton.block_tor_file_net":
                 this.block_tor_file_net = this._prefs.getBoolPref("extensions.torbutton.block_tor_file_net");
                 break;

Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js	2008-06-23 05:02:34 UTC (rev 15423)
+++ torbutton/trunk/src/defaults/preferences/preferences.js	2008-06-23 06:22:06 UTC (rev 15424)
@@ -73,6 +73,8 @@
 
 // State prefs:
 pref("extensions.torbutton.tor_enabled",false);
+pref("extensions.torbutton.proxies_applied",false);
+pref("extensions.torbutton.settings_applied",false);
 pref("extensions.torbutton.startup",false);
 pref("extensions.torbutton.crashed",false);
 pref("extensions.torbutton.noncrashed",false);