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

[tor-commits] [tor-launcher/master] Added hidden pref. to control whether Tor Launcher starts the tor process.



commit 3daaee7e03793efeaf3775d7f6bbb7128758db3c
Author: Kathy Brade <brade@xxxxxxxxxxxxxx>
Date:   Tue Apr 9 13:01:54 2013 -0400

    Added hidden pref. to control whether Tor Launcher starts the tor process.
---
 src/chrome/content/network-settings.js |    4 +---
 src/components/tl-process.js           |   24 ++++++++++++++++++------
 src/components/tl-protocol.js          |   21 +++++++++++++--------
 src/defaults/preferences/prefs.js      |    1 +
 4 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/chrome/content/network-settings.js b/src/chrome/content/network-settings.js
index 98d4ed7..a2f57ad 100644
--- a/src/chrome/content/network-settings.js
+++ b/src/chrome/content/network-settings.js
@@ -15,8 +15,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherUtil",
 XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherLogger",
                           "resource://torlauncher/modules/tl-logger.jsm");
 
-const kPrefPromptAtStartup = "extensions.torlauncher.prompt_at_startup";
-
 const kUseProxyCheckbox = "useProxy";
 const kProxyTypeMenulist = "proxyType";
 const kProxyAddr = "proxyAddr";
@@ -48,7 +46,7 @@ var gIsBootstrapComplete = false;
 function initDialog()
 {
   var okBtn = document.documentElement.getButton("accept");
-  gIsInitialBootstrap = TorLauncherUtil.getBoolPref(kPrefPromptAtStartup);
+  gIsInitialBootstrap = window.arguments[0];
   if (gIsInitialBootstrap)
   {
     document.documentElement.setAttribute("class", "initialBootstrap");
diff --git a/src/components/tl-process.js b/src/components/tl-process.js
index 4067232..4d77d21 100644
--- a/src/components/tl-process.js
+++ b/src/components/tl-process.js
@@ -30,6 +30,7 @@ TorProcessService.prototype =
   kServiceName : "Tor Launcher Process Service",
   kClassID: Components.ID("{FE7B4CAF-BCF4-4848-8BFF-EFA66C9AFDA1}"),
 
+  kPrefStartTor: "extensions.torlauncher.start_tor",
   kPrefPromptAtStartup: "extensions.torlauncher.prompt_at_startup",
   kInitialMonitorDelayMS: 1000, // TODO: how can we avoid this delay?
   kMonitorDelayMS: 200,
@@ -76,7 +77,9 @@ TorProcessService.prototype =
       this.mObsSvc.addObserver(this, "quit-application-granted", false);
       this.mObsSvc.addObserver(this, kOpenNetworkSettingsTopic, false);
       this.mObsSvc.addObserver(this, kUserQuitTopic, false);
-      this._startTor();
+
+      if (TorLauncherUtil.getBoolPref(this.kPrefStartTor))
+        this._startTor();
     }
     else if ("quit-application-granted" == aTopic)
     {
@@ -118,7 +121,7 @@ TorProcessService.prototype =
         this.mTimer.init(this, this.kMonitorDelayMS, this.mTimer.TYPE_ONE_SHOT);
     }
     else if (kOpenNetworkSettingsTopic == aTopic)
-      this._openNetworkSettings();
+      this._openNetworkSettings(false);
     else if (kUserQuitTopic == aTopic)
       this.mQuitSoon = true;
   },
@@ -267,7 +270,7 @@ TorProcessService.prototype =
         //       to delay before retry inside TorSendCommand()... which is
         //       difficult b/c that is a synchronous API.
         if (this.mProtocolSvc)
-          this._openNetworkSettings(); // Blocks until dialog is closed.
+          this._openNetworkSettings(true); // Blocks until dialog is closed.
       }
       else
       {
@@ -332,13 +335,22 @@ TorProcessService.prototype =
   }, // _checkBootstrapStatus()
 
   // Blocks until network settings dialog is closed.
-  _openNetworkSettings: function()
+  _openNetworkSettings: function(aIsInitialBootstrap)
   {
-    var chromeURL = "chrome://torlauncher/content/network-settings.xul";
+    const kChromeURL = "chrome://torlauncher/content/network-settings.xul";
+
     var wwSvc = Cc["@mozilla.org/embedcomp/window-watcher;1"]
                   .getService(Ci.nsIWindowWatcher);
     var winFeatures = "chrome,dialog=yes,modal,all";
-    wwSvc.openWindow(null, chromeURL, "_blank", winFeatures, null);
+
+    var argsArray = Cc["@mozilla.org/array;1"]
+                      .createInstance(Ci.nsIMutableArray);
+    var variant = Cc["@mozilla.org/variant;1"]
+                    .createInstance(Ci.nsIWritableVariant);
+    variant.setFromVariant(aIsInitialBootstrap);
+    argsArray.appendElement(variant, false);
+
+    wwSvc.openWindow(null, kChromeURL, "_blank", winFeatures, argsArray);
   },
 
   _openProgressDialog: function()
diff --git a/src/components/tl-protocol.js b/src/components/tl-protocol.js
index 26cd983..f589472 100644
--- a/src/components/tl-protocol.js
+++ b/src/components/tl-protocol.js
@@ -71,6 +71,8 @@ TorProtocolService.prototype =
   kServiceName : "Tor Launcher Protocol Service",
   kClassID: Components.ID("{4F476361-23FB-43EF-A427-B36A14D3208E}"),
 
+  kPrefStartTor: "extensions.torlauncher.start_tor",
+
   // nsISupports implementation.
   QueryInterface: function(aIID)
   {
@@ -429,16 +431,19 @@ TorProtocolService.prototype =
         return null;
       }
 
-      // Try to become the primary controller (TAKEOWNERSHIP).
-      reply = this._sendCommand(conn, "TAKEOWNERSHIP", null);
-      if (!this.TorCommandSucceeded(reply))
-        TorLauncherLogger.log(4, "take ownership failed");
-      else
+      if (TorLauncherUtil.getBoolPref(this.kPrefStartTor))
       {
-        reply = this._sendCommand(conn, "RESETCONF",
-                                  "__OwningControllerProcess");
+        // Try to become the primary controller (TAKEOWNERSHIP).
+        reply = this._sendCommand(conn, "TAKEOWNERSHIP", null);
         if (!this.TorCommandSucceeded(reply))
-          TorLauncherLogger.log(4, "clear owning controller process failed");
+          TorLauncherLogger.log(4, "take ownership failed");
+        else
+        {
+          reply = this._sendCommand(conn, "RESETCONF",
+                                    "__OwningControllerProcess");
+          if (!this.TorCommandSucceeded(reply))
+            TorLauncherLogger.log(4, "clear owning controller process failed");
+        }
       }
     }
     catch(e)
diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js
index 68613b5..d9ea4d1 100644
--- a/src/defaults/preferences/prefs.js
+++ b/src/defaults/preferences/prefs.js
@@ -4,6 +4,7 @@ pref("extensions.torlauncher.logmethod", 1);  // 0=stdout, 1=errorconsole, 2=deb
 pref("extensions.torlauncher.control_host", "127.0.0.1");
 pref("extensions.torlauncher.control_port", 9151);
 
+pref("extensions.torlauncher.start_tor", true);
 pref("extensions.torlauncher.prompt_at_startup", true);
 
 // All path prefs. are relative to the firefox executable's directory

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