[tbb-commits] [tor-launcher/master] Bug 11879: Stop bootstrap if Cancel or Open Settings is clicked.

mikeperry at torproject.org mikeperry at torproject.org
Fri Apr 17 02:00:56 UTC 2015


commit 81fd61c79e77e8dcbcfa42559a727ac384583f03
Author: Kathy Brade <brade at pearlcrescent.com>
Date:   Thu Apr 16 11:49:00 2015 -0400

    Bug 11879: Stop bootstrap if Cancel or Open Settings is clicked.
    
    Fix a related problem where the progress dialog immediately closed
    itself if an error had previously been reported.
    Send SETCONF DisableNetwork=0 instead of SETCONF DisableNetwork (this
    makes it easier to interpret debug logs).
---
 src/chrome/content/progress.js |   29 ++++++++++++++++++++++++++++-
 src/components/tl-process.js   |    1 +
 src/components/tl-protocol.js  |    4 +++-
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/chrome/content/progress.js b/src/chrome/content/progress.js
index 8208398..b44dca5 100644
--- a/src/chrome/content/progress.js
+++ b/src/chrome/content/progress.js
@@ -15,6 +15,9 @@ const kTorLogHasWarnOrErrTopic = "TorLogHasWarnOrErr";
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherUtil",
                           "resource://torlauncher/modules/tl-util.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherLogger",
+                          "resource://torlauncher/modules/tl-logger.jsm");
+
 
 var gObsSvc;
 var gOpenerCallbackFunc; // Set when opened from network settings.
@@ -110,7 +113,7 @@ function onCancel()
 
   if (gOpenerCallbackFunc)
   {
-    // TODO: stop the bootstrapping process?
+    stopTorBootstrap();
     gOpenerCallbackFunc(false);
   }
   else try
@@ -126,11 +129,35 @@ function onCancel()
 
 function onOpenSettings()
 {
+  stopTorBootstrap();
   cleanup();
   window.close();
 }
 
 
+function stopTorBootstrap()
+{
+  // Tell tor to disable use of the network; this should stop the bootstrap
+  // process.
+  const kErrorPrefix = "Setting DisableNetwork=1 failed: ";
+  try
+  {
+    var svc = Cc["@torproject.org/torlauncher-protocol-service;1"]
+                 .getService(Ci.nsISupports);
+    svc = svc.wrappedJSObject;
+    var settings = {};
+    settings["DisableNetwork"] = true;
+    var errObj = {};
+    if (!svc.TorSetConfWithReply(settings, errObj))
+      TorLauncherLogger.log(5, kErrorPrefix + errObj.details);
+  }
+  catch(e)
+  {
+    TorLauncherLogger.log(5, kErrorPrefix + e);
+  }
+}
+
+
 var gObserver = {
   // nsIObserver implementation.
   observe: function(aSubject, aTopic, aParam)
diff --git a/src/components/tl-process.js b/src/components/tl-process.js
index ef2b12c..80cd7ea 100644
--- a/src/components/tl-process.js
+++ b/src/components/tl-process.js
@@ -275,6 +275,7 @@ TorProcessService.prototype =
 
   TorClearBootstrapError: function()
   {
+    this.mBootstrapErrorOccurred = false;
     this.mLastTorWarningPhase = null;
     this.mLastTorWarningReason = null;
   },
diff --git a/src/components/tl-protocol.js b/src/components/tl-protocol.js
index 559bb37..fdc2394 100644
--- a/src/components/tl-protocol.js
+++ b/src/components/tl-protocol.js
@@ -206,6 +206,8 @@ TorProtocolService.prototype =
   // aSettingsObj should be a JavaScript object with keys (property values)
   // that correspond to tor config. keys.  The value associated with each
   // key should be a simple string, a string array, or a Boolean value.
+  // If an associated value is undefined or null, a key with no value is
+  // passed in the SETCONF command.
   // If a fatal error occurs, null is returned.  Otherwise, a reply object is
   // returned.
   TorSetConf: function(aSettingsObj)
@@ -221,7 +223,7 @@ TorProtocolService.prototype =
       else
         cmdArgs += ' ' + key;
       var val = aSettingsObj[key];
-      if (val)
+      if ((val !== undefined) && (val !== null))
       {
         var valType = (typeof val);
         if ("boolean" == valType)





More information about the tbb-commits mailing list