[tbb-commits] [tor-browser] 06/10: fixup! Bug 40597: Implement TorSettings module

gitolite role git at cupani.torproject.org
Mon Oct 10 20:17:20 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-102.3.0esr-12.0-2
in repository tor-browser.

commit 2df6696ded66b62ca03109d3db7ab8f9b56e1cff
Author: Pier Angelo Vendrame <pierov at torproject.org>
AuthorDate: Mon Oct 10 15:17:46 2022 +0200

    fixup! Bug 40597: Implement TorSettings module
    
    Bug 40933: Move tor-launcher to tor-browser.git
---
 browser/components/sessionstore/SessionStore.jsm   |   5 -
 browser/modules/BridgeDB.jsm                       |   2 +-
 browser/modules/Moat.jsm                           |   4 +-
 browser/modules/TorConnect.jsm                     |  73 ++-
 browser/modules/TorProcessService.jsm              |  12 -
 browser/modules/TorProtocolService.jsm             | 510 ---------------------
 browser/modules/TorSettings.jsm                    |  25 +-
 browser/modules/moz.build                          |   2 -
 .../processsingleton/MainProcessSingleton.jsm      |   2 -
 .../components/tor-launcher/TorStartupService.jsm  |  14 +
 10 files changed, 57 insertions(+), 592 deletions(-)

diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm
index 5f9f6aab2e54..58c5a4fed6ca 100644
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -234,11 +234,6 @@ ChromeUtils.defineModuleGetter(
   "resource://gre/modules/sessionstore/SessionHistory.jsm"
 );
 
-// FIXME: Is this really necessary?
-const { TorProtocolService } = ChromeUtils.import(
-  "resource:///modules/TorProtocolService.jsm"
-);
-
 const { OnionAuthUtil } = ChromeUtils.import(
   "chrome://browser/content/onionservices/authUtil.jsm"
 );
diff --git a/browser/modules/BridgeDB.jsm b/browser/modules/BridgeDB.jsm
index 50665710ebf4..3110dfbbf20f 100644
--- a/browser/modules/BridgeDB.jsm
+++ b/browser/modules/BridgeDB.jsm
@@ -46,7 +46,7 @@ var BridgeDB = {
       this._image =
         "data:image/jpeg;base64," + encodeURIComponent(response.image);
     } catch (err) {
-      console.log(`error : ${err}`);
+      console.error("Could not request a captcha image", err);
     }
     return this._image;
   },
diff --git a/browser/modules/Moat.jsm b/browser/modules/Moat.jsm
index 90a6ae4e521c..28f177e27b3b 100644
--- a/browser/modules/Moat.jsm
+++ b/browser/modules/Moat.jsm
@@ -9,11 +9,11 @@ const { Subprocess } = ChromeUtils.import(
 );
 
 const { TorLauncherUtil } = ChromeUtils.import(
-  "resource://torlauncher/modules/tl-util.jsm"
+  "resource://gre/modules/TorLauncherUtil.jsm"
 );
 
 const { TorProtocolService } = ChromeUtils.import(
-  "resource:///modules/TorProtocolService.jsm"
+  "resource://gre/modules/TorProtocolService.jsm"
 );
 
 const { TorSettings, TorBridgeSource } = ChromeUtils.import(
diff --git a/browser/modules/TorConnect.jsm b/browser/modules/TorConnect.jsm
index cc0eeb2b1eba..34a3a9ee7d33 100644
--- a/browser/modules/TorConnect.jsm
+++ b/browser/modules/TorConnect.jsm
@@ -17,14 +17,14 @@ const { BrowserWindowTracker } = ChromeUtils.import(
   "resource:///modules/BrowserWindowTracker.jsm"
 );
 
-const {
-  TorProtocolService,
-  TorTopics,
-  TorBootstrapRequest,
-} = ChromeUtils.import("resource:///modules/TorProtocolService.jsm");
-
+const { TorMonitorService } = ChromeUtils.import(
+  "resource://gre/modules/TorMonitorService.jsm"
+);
+const { TorBootstrapRequest } = ChromeUtils.import(
+  "resource://gre/modules/TorBootstrapRequest.jsm"
+);
 const { TorLauncherUtil } = ChromeUtils.import(
-  "resource://torlauncher/modules/tl-util.jsm"
+  "resource://gre/modules/TorLauncherUtil.jsm"
 );
 
 const {
@@ -37,9 +37,9 @@ const { TorStrings } = ChromeUtils.import("resource:///modules/TorStrings.jsm");
 
 const { MoatRPC } = ChromeUtils.import("resource:///modules/Moat.jsm");
 
-/* Browser observer topis */
-const BrowserTopics = Object.freeze({
-  ProfileAfterChange: "profile-after-change",
+const TorTopics = Object.freeze({
+  LogHasWarnOrErr: "TorLogHasWarnOrErr",
+  ProcessExited: "TorProcessExited",
 });
 
 /* Relevant prefs used by tor-launcher */
@@ -445,7 +445,7 @@ const TorConnect = (() => {
                   "Error: Censorship simulation",
                   true
                 );
-                TorProtocolService._torBootstrapDebugSetError();
+                TorMonitorService.setBootstrapError();
                 return;
               }
 
@@ -567,7 +567,7 @@ const TorConnect = (() => {
                     );
                     return;
                   }
-                  TorProtocolService._torBootstrapDebugSetError();
+                  TorMonitorService.setBootstrapError();
                 }
               }
 
@@ -817,42 +817,31 @@ const TorConnect = (() => {
       );
     },
 
-    // init should be called on app-startup in MainProcessingSingleton.jsm
+    // init should be called by TorStartupService
     init() {
       console.log("TorConnect: init()");
-
-      // delay remaining init until after profile-after-change
-      Services.obs.addObserver(this, BrowserTopics.ProfileAfterChange);
-
       this._callback(TorConnectState.Initial).begin();
+
+      if (!TorMonitorService.ownsTorDaemon) {
+        // Disabled
+        this._changeState(TorConnectState.Disabled);
+      } else {
+        let observeTopic = addTopic => {
+          Services.obs.addObserver(this, addTopic);
+          console.log(`TorConnect: Observing topic '${addTopic}'`);
+        };
+
+        // register the Tor topics we always care about
+        observeTopic(TorTopics.ProcessExited);
+        observeTopic(TorTopics.LogHasWarnOrErr);
+        observeTopic(TorSettingsTopics.Ready);
+      }
     },
 
     async observe(subject, topic, data) {
       console.log(`TorConnect: Observed ${topic}`);
 
       switch (topic) {
-        /* Determine which state to move to from Initial */
-        case BrowserTopics.ProfileAfterChange: {
-          if (
-            TorLauncherUtil.useLegacyLauncher ||
-            !TorProtocolService.ownsTorDaemon
-          ) {
-            // Disabled
-            this._changeState(TorConnectState.Disabled);
-          } else {
-            let observeTopic = addTopic => {
-              Services.obs.addObserver(this, addTopic);
-              console.log(`TorConnect: Observing topic '${addTopic}'`);
-            };
-
-            // register the Tor topics we always care about
-            observeTopic(TorTopics.ProcessExited);
-            observeTopic(TorTopics.LogHasWarnOrErr);
-            observeTopic(TorSettingsTopics.Ready);
-          }
-          Services.obs.removeObserver(this, topic);
-          break;
-        }
         /* We need to wait until TorSettings have been loaded and applied before we can Quickstart */
         case TorSettingsTopics.Ready: {
           if (this.shouldQuickStart) {
@@ -881,11 +870,9 @@ const TorConnect = (() => {
     get shouldShowTorConnect() {
       // TorBrowser must control the daemon
       return (
-        TorProtocolService.ownsTorDaemon &&
-        // and we're not using the legacy launcher
-        !TorLauncherUtil.useLegacyLauncher &&
+        TorMonitorService.ownsTorDaemon &&
         // if we have succesfully bootstraped, then no need to show TorConnect
-        this.state != TorConnectState.Bootstrapped
+        this.state !== TorConnectState.Bootstrapped
       );
     },
 
diff --git a/browser/modules/TorProcessService.jsm b/browser/modules/TorProcessService.jsm
deleted file mode 100644
index 201e331b2806..000000000000
--- a/browser/modules/TorProcessService.jsm
+++ /dev/null
@@ -1,12 +0,0 @@
-"use strict";
-
-var EXPORTED_SYMBOLS = ["TorProcessService"];
-
-var TorProcessService = {
-  get isBootstrapDone() {
-    const svc = Cc["@torproject.org/torlauncher-process-service;1"].getService(
-      Ci.nsISupports
-    ).wrappedJSObject;
-    return svc.mIsBootstrapDone;
-  },
-};
diff --git a/browser/modules/TorProtocolService.jsm b/browser/modules/TorProtocolService.jsm
deleted file mode 100644
index 6a1d6b94fff7..000000000000
--- a/browser/modules/TorProtocolService.jsm
+++ /dev/null
@@ -1,510 +0,0 @@
-// Copyright (c) 2021, The Tor Project, Inc.
-
-"use strict";
-
-var EXPORTED_SYMBOLS = [
-  "TorProtocolService",
-  "TorProcessStatus",
-  "TorTopics",
-  "TorBootstrapRequest",
-];
-
-const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
-
-const { setTimeout, clearTimeout } = ChromeUtils.import(
-  "resource://gre/modules/Timer.jsm"
-);
-
-const { TorLauncherUtil } = ChromeUtils.import(
-  "resource://torlauncher/modules/tl-util.jsm"
-);
-
-// see tl-process.js
-const TorProcessStatus = Object.freeze({
-  Unknown: 0,
-  Starting: 1,
-  Running: 2,
-  Exited: 3,
-});
-
-/* tor-launcher observer topics */
-const TorTopics = Object.freeze({
-  BootstrapStatus: "TorBootstrapStatus",
-  BootstrapError: "TorBootstrapError",
-  ProcessExited: "TorProcessExited",
-  LogHasWarnOrErr: "TorLogHasWarnOrErr",
-});
-
-/* Browser observer topis */
-const BrowserTopics = Object.freeze({
-  ProfileAfterChange: "profile-after-change",
-});
-
-var TorProtocolService = {
-  _TorLauncherProtocolService: null,
-  _TorProcessService: null,
-
-  // maintain a map of tor settings set by Tor Browser so that we don't
-  // repeatedly set the same key/values over and over
-  // this map contains string keys to primitive or array values
-  _settingsCache: new Map(),
-
-  init() {
-    Services.obs.addObserver(this, BrowserTopics.ProfileAfterChange);
-  },
-
-  observe(subject, topic, data) {
-    if (topic === BrowserTopics.ProfileAfterChange) {
-      // we have to delay init'ing this or else the crypto service inits too early without a profile
-      // which breaks the password manager
-      this._TorLauncherProtocolService = Cc[
-        "@torproject.org/torlauncher-protocol-service;1"
-      ].getService(Ci.nsISupports).wrappedJSObject;
-      this._TorProcessService = Cc[
-        "@torproject.org/torlauncher-process-service;1"
-      ].getService(Ci.nsISupports).wrappedJSObject;
-      Services.obs.removeObserver(this, topic);
-    }
-  },
-
-  _typeof(aValue) {
-    switch (typeof aValue) {
-      case "boolean":
-        return "boolean";
-      case "string":
-        return "string";
-      case "object":
-        if (aValue == null) {
-          return "null";
-        } else if (Array.isArray(aValue)) {
-          return "array";
-        }
-        return "object";
-    }
-    return "unknown";
-  },
-
-  _assertValidSettingKey(aSetting) {
-    // ensure the 'key' is a string
-    if (typeof aSetting != "string") {
-      throw new Error(
-        `Expected setting of type string but received ${typeof aSetting}`
-      );
-    }
-  },
-
-  _assertValidSetting(aSetting, aValue) {
-    this._assertValidSettingKey(aSetting);
-
-    const valueType = this._typeof(aValue);
-    switch (valueType) {
-      case "boolean":
-      case "string":
-      case "null":
-        return;
-      case "array":
-        for (const element of aValue) {
-          if (typeof element != "string") {
-            throw new Error(
-              `Setting '${aSetting}' array contains value of invalid type '${typeof element}'`
-            );
-          }
-        }
-        return;
-      default:
-        throw new Error(
-          `Invalid object type received for setting '${aSetting}'`
-        );
-    }
-  },
-
-  // takes a Map containing tor settings
-  // throws on error
-  async writeSettings(aSettingsObj) {
-    // only write settings that have changed
-    let newSettings = new Map();
-    for (const [setting, value] of aSettingsObj) {
-      let saveSetting = false;
-
-      // make sure we have valid data here
-      this._assertValidSetting(setting, value);
-
-      if (!this._settingsCache.has(setting)) {
-        // no cached setting, so write
-        saveSetting = true;
-      } else {
-        const cachedValue = this._settingsCache.get(setting);
-        if (value != cachedValue) {
-          // compare arrays member-wise
-          if (Array.isArray(value) && Array.isArray(cachedValue)) {
-            if (value.length != cachedValue.length) {
-              saveSetting = true;
-            } else {
-              const arrayLength = value.length;
-              for (let i = 0; i < arrayLength; ++i) {
-                if (value[i] != cachedValue[i]) {
-                  saveSetting = true;
-                  break;
-                }
-              }
-            }
-          } else {
-            // some other different values
-            saveSetting = true;
-          }
-        }
-      }
-
-      if (saveSetting) {
-        newSettings.set(setting, value);
-      }
-    }
-
-    // only write if new setting to save
-    if (newSettings.size > 0) {
-      // convert settingsObject map to js object for torlauncher-protocol-service
-      let settingsObject = {};
-      for (const [setting, value] of newSettings) {
-        settingsObject[setting] = value;
-      }
-
-      let errorObject = {};
-      if (
-        !(await this._TorLauncherProtocolService.TorSetConfWithReply(
-          settingsObject,
-          errorObject
-        ))
-      ) {
-        throw new Error(errorObject.details);
-      }
-
-      // save settings to cache after successfully writing to Tor
-      for (const [setting, value] of newSettings) {
-        this._settingsCache.set(setting, value);
-      }
-    }
-  },
-
-  async _readSetting(aSetting) {
-    this._assertValidSettingKey(aSetting);
-    let reply = await this._TorLauncherProtocolService.TorGetConf(aSetting);
-    if (this._TorLauncherProtocolService.TorCommandSucceeded(reply)) {
-      return reply.lineArray;
-    }
-    throw new Error(reply.lineArray.join("\n"));
-  },
-
-  async _readBoolSetting(aSetting) {
-    let lineArray = await this._readSetting(aSetting);
-    if (lineArray.length != 1) {
-      throw new Error(
-        `Expected an array with length 1 but received array of length ${lineArray.length}`
-      );
-    }
-
-    let retval = lineArray[0];
-    switch (retval) {
-      case "0":
-        return false;
-      case "1":
-        return true;
-      default:
-        throw new Error(`Expected boolean (1 or 0) but received '${retval}'`);
-    }
-  },
-
-  async _readStringSetting(aSetting) {
-    let lineArray = await this._readSetting(aSetting);
-    if (lineArray.length != 1) {
-      throw new Error(
-        `Expected an array with length 1 but received array of length ${lineArray.length}`
-      );
-    }
-    return lineArray[0];
-  },
-
-  async _readStringArraySetting(aSetting) {
-    let lineArray = await this._readSetting(aSetting);
-    return lineArray;
-  },
-
-  async readBoolSetting(aSetting) {
-    let value = await this._readBoolSetting(aSetting);
-    this._settingsCache.set(aSetting, value);
-    return value;
-  },
-
-  async readStringSetting(aSetting) {
-    let value = await this._readStringSetting(aSetting);
-    this._settingsCache.set(aSetting, value);
-    return value;
-  },
-
-  async readStringArraySetting(aSetting) {
-    let value = await this._readStringArraySetting(aSetting);
-    this._settingsCache.set(aSetting, value);
-    return value;
-  },
-
-  // writes current tor settings to disk
-  async flushSettings() {
-    await this.sendCommand("SAVECONF");
-  },
-
-  getLog(countObj) {
-    countObj = countObj || { value: 0 };
-    let torLog = this._TorLauncherProtocolService.TorGetLog(countObj);
-    return torLog;
-  },
-
-  // true if we launched and control tor, false if using system tor
-  get ownsTorDaemon() {
-    return TorLauncherUtil.shouldStartAndOwnTor;
-  },
-
-  // Assumes `ownsTorDaemon` is true
-  isNetworkDisabled() {
-    const reply = TorProtocolService._TorLauncherProtocolService.TorGetConfBool(
-      "DisableNetwork",
-      true
-    );
-    if (
-      TorProtocolService._TorLauncherProtocolService.TorCommandSucceeded(reply)
-    ) {
-      return reply.retVal;
-    }
-    return true;
-  },
-
-  async enableNetwork() {
-    let settings = {};
-    settings.DisableNetwork = false;
-    let errorObject = {};
-    if (
-      !(await this._TorLauncherProtocolService.TorSetConfWithReply(
-        settings,
-        errorObject
-      ))
-    ) {
-      throw new Error(errorObject.details);
-    }
-  },
-
-  async sendCommand(cmd) {
-    return this._TorLauncherProtocolService.TorSendCommand(cmd);
-  },
-
-  retrieveBootstrapStatus() {
-    return this._TorLauncherProtocolService.TorRetrieveBootstrapStatus();
-  },
-
-  _GetSaveSettingsErrorMessage(aDetails) {
-    try {
-      return TorLauncherUtil.getSaveSettingsErrorMessage(aDetails);
-    } catch (e) {
-      console.log("GetSaveSettingsErrorMessage error", e);
-      return "Unexpected Error";
-    }
-  },
-
-  async setConfWithReply(settings) {
-    let result = false;
-    const error = {};
-    try {
-      result = await this._TorLauncherProtocolService.TorSetConfWithReply(
-        settings,
-        error
-      );
-    } catch (e) {
-      console.log("TorSetConfWithReply error", e);
-      error.details = this._GetSaveSettingsErrorMessage(e.message);
-    }
-    return { result, error };
-  },
-
-  isBootstrapDone() {
-    return this._TorProcessService.mIsBootstrapDone;
-  },
-
-  clearBootstrapError() {
-    return this._TorProcessService.TorClearBootstrapError();
-  },
-
-  torBootstrapErrorOccurred() {
-    return this._TorProcessService.TorBootstrapErrorOccurred;
-  },
-
-  _torBootstrapDebugSetError() {
-    this._TorProcessService._TorSetBootstrapErrorForDebug();
-  },
-
-  // Resolves to null if ok, or an error otherwise
-  async connect() {
-    const kTorConfKeyDisableNetwork = "DisableNetwork";
-    const settings = {};
-    settings[kTorConfKeyDisableNetwork] = false;
-    const { result, error } = await this.setConfWithReply(settings);
-    if (!result) {
-      return error;
-    }
-    try {
-      await this.sendCommand("SAVECONF");
-      this.clearBootstrapError();
-      this.retrieveBootstrapStatus();
-    } catch (e) {
-      return error;
-    }
-    return null;
-  },
-
-  torLogHasWarnOrErr() {
-    return this._TorLauncherProtocolService.TorLogHasWarnOrErr;
-  },
-
-  async torStopBootstrap() {
-    // Tell tor to disable use of the network; this should stop the bootstrap
-    // process.
-    const kErrorPrefix = "Setting DisableNetwork=1 failed: ";
-    try {
-      let settings = {};
-      settings.DisableNetwork = true;
-      const { result, error } = await this.setConfWithReply(settings);
-      if (!result) {
-        console.log(
-          `Error stopping bootstrap ${kErrorPrefix} ${error.details}`
-        );
-      }
-    } catch (e) {
-      console.log(`Error stopping bootstrap ${kErrorPrefix} ${e}`);
-    }
-    this.retrieveBootstrapStatus();
-  },
-
-  get torProcessStatus() {
-    if (this._TorProcessService) {
-      return this._TorProcessService.TorProcessStatus;
-    }
-    return TorProcessStatus.Unknown;
-  },
-};
-TorProtocolService.init();
-
-// modeled after XMLHttpRequest
-// nicely encapsulates the observer register/unregister logic
-class TorBootstrapRequest {
-  constructor() {
-    // number of ms to wait before we abandon the bootstrap attempt
-    // a value of 0 implies we never wait
-    this.timeout = 0;
-    // callbacks for bootstrap process status updates
-    this.onbootstrapstatus = (progress, status) => {};
-    this.onbootstrapcomplete = () => {};
-    this.onbootstraperror = (message, details) => {};
-
-    // internal resolve() method for bootstrap
-    this._bootstrapPromiseResolve = null;
-    this._bootstrapPromise = null;
-    this._timeoutID = null;
-  }
-
-  async observe(subject, topic, data) {
-    const obj = subject?.wrappedJSObject;
-    switch (topic) {
-      case TorTopics.BootstrapStatus: {
-        const progress = obj.PROGRESS;
-        const status = TorLauncherUtil.getLocalizedBootstrapStatus(obj, "TAG");
-        if (this.onbootstrapstatus) {
-          this.onbootstrapstatus(progress, status);
-        }
-        if (progress === 100) {
-          if (this.onbootstrapcomplete) {
-            this.onbootstrapcomplete();
-          }
-          this._bootstrapPromiseResolve(true);
-          clearTimeout(this._timeoutID);
-        }
-
-        break;
-      }
-      case TorTopics.BootstrapError: {
-        // first stop our bootstrap timeout before handling the error
-        clearTimeout(this._timeoutID);
-
-        await TorProtocolService.torStopBootstrap();
-
-        const message = obj.message;
-        const details = obj.details;
-        if (this.onbootstraperror) {
-          this.onbootstraperror(message, details);
-        }
-        this._bootstrapPromiseResolve(false);
-        break;
-      }
-    }
-  }
-
-  // resolves 'true' if bootstrap succeeds, false otherwise
-  bootstrap() {
-    if (this._bootstrapPromise) {
-      return this._bootstrapPromise;
-    }
-
-    this._bootstrapPromise = new Promise((resolve, reject) => {
-      this._bootstrapPromiseResolve = resolve;
-
-      // register ourselves to listen for bootstrap events
-      Services.obs.addObserver(this, TorTopics.BootstrapStatus);
-      Services.obs.addObserver(this, TorTopics.BootstrapError);
-
-      // optionally cancel bootstrap after a given timeout
-      if (this.timeout > 0) {
-        this._timeoutID = setTimeout(async () => {
-          await TorProtocolService.torStopBootstrap();
-          if (this.onbootstraperror) {
-            this.onbootstraperror(
-              "Tor Bootstrap process timed out",
-              `Bootstrap attempt abandoned after waiting ${this.timeout} ms`
-            );
-          }
-          this._bootstrapPromiseResolve(false);
-        }, this.timeout);
-      }
-
-      // wait for bootstrapping to begin and maybe handle error
-      TorProtocolService.connect()
-        .then(async err => {
-          if (!err) {
-            return;
-          }
-
-          clearTimeout(this._timeoutID);
-          await TorProtocolService.torStopBootstrap();
-
-          const message = err.message;
-          const details = err.details;
-          if (this.onbootstraperror) {
-            this.onbootstraperror(message, details);
-          }
-          this._bootstrapPromiseResolve(false);
-        })
-        .catch(err => {
-          // Currently, TorProtocolService.connect() should never throw
-          reject(err);
-        });
-    }).finally(() => {
-      // and remove ourselves once bootstrap is resolved
-      Services.obs.removeObserver(this, TorTopics.BootstrapStatus);
-      Services.obs.removeObserver(this, TorTopics.BootstrapError);
-    });
-
-    return this._bootstrapPromise;
-  }
-
-  async cancel() {
-    clearTimeout(this._timeoutID);
-
-    await TorProtocolService.torStopBootstrap();
-
-    this._bootstrapPromiseResolve(false);
-  }
-}
diff --git a/browser/modules/TorSettings.jsm b/browser/modules/TorSettings.jsm
index 57a2a80c7d3f..4084ee71a1ce 100644
--- a/browser/modules/TorSettings.jsm
+++ b/browser/modules/TorSettings.jsm
@@ -11,14 +11,12 @@ var EXPORTED_SYMBOLS = [
 
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-const { TorProtocolService, TorProcessStatus } = ChromeUtils.import(
-  "resource:///modules/TorProtocolService.jsm"
+const { TorMonitorService } = ChromeUtils.import(
+  "resource://gre/modules/TorMonitorService.jsm"
+);
+const { TorProtocolService } = ChromeUtils.import(
+  "resource://gre/modules/TorProtocolService.jsm"
 );
-
-/* Browser observer topics */
-const BrowserTopics = Object.freeze({
-  ProfileAfterChange: "profile-after-change",
-});
 
 /* tor-launcher observer topics */
 const TorTopics = Object.freeze({
@@ -290,7 +288,7 @@ const TorSettings = (() => {
 
     /* load or init our settings, and register observers */
     init() {
-      if (TorProtocolService.ownsTorDaemon) {
+      if (TorMonitorService.ownsTorDaemon) {
         // if the settings branch exists, load settings from prefs
         if (Services.prefs.getBoolPref(TorSettingsPrefs.enabled, false)) {
           this.loadFromPrefs();
@@ -298,8 +296,11 @@ const TorSettings = (() => {
           // otherwise load defaults
           this._settings = this.defaultSettings();
         }
-        Services.obs.addObserver(this, BrowserTopics.ProfileAfterChange);
         Services.obs.addObserver(this, TorTopics.ProcessIsReady);
+
+        if (TorMonitorService.isRunning) {
+          handleProcessReady();
+        }
       }
     },
 
@@ -316,12 +317,6 @@ const TorSettings = (() => {
       };
 
       switch (topic) {
-        case BrowserTopics.ProfileAfterChange:
-          Services.obs.removeObserver(this, BrowserTopics.ProfileAfterChange);
-          if (TorProtocolService.torProcessStatus == TorProcessStatus.Running) {
-            await handleProcessReady();
-          }
-          break;
         case TorTopics.ProcessIsReady:
           Services.obs.removeObserver(this, TorTopics.ProcessIsReady);
           await handleProcessReady();
diff --git a/browser/modules/moz.build b/browser/modules/moz.build
index 98caa91ee6f4..b9158588b812 100644
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -147,8 +147,6 @@ EXTRA_JS_MODULES += [
     "TabsList.jsm",
     "TabUnloader.jsm",
     "TorConnect.jsm",
-    "TorProcessService.jsm",
-    "TorProtocolService.jsm",
     "TorSettings.jsm",
     "TorStrings.jsm",
     "TransientPrefs.jsm",
diff --git a/toolkit/components/processsingleton/MainProcessSingleton.jsm b/toolkit/components/processsingleton/MainProcessSingleton.jsm
index 4afa7f118a72..f99dd538ec7c 100644
--- a/toolkit/components/processsingleton/MainProcessSingleton.jsm
+++ b/toolkit/components/processsingleton/MainProcessSingleton.jsm
@@ -20,8 +20,6 @@ MainProcessSingleton.prototype = {
         // Imported for side-effects.
         ChromeUtils.import("resource://gre/modules/CustomElementsListener.jsm");
 
-        // FIXME: Is this import really necessary?
-        ChromeUtils.import("resource:///modules/TorSettings.jsm");
         ChromeUtils.import("resource:///modules/TorConnect.jsm");
 
         Services.ppmm.loadProcessScript(
diff --git a/toolkit/components/tor-launcher/TorStartupService.jsm b/toolkit/components/tor-launcher/TorStartupService.jsm
index 9c27b34b2f6f..539c599aec62 100644
--- a/toolkit/components/tor-launcher/TorStartupService.jsm
+++ b/toolkit/components/tor-launcher/TorStartupService.jsm
@@ -22,6 +22,17 @@ ChromeUtils.defineModuleGetter(
   "resource://gre/modules/TorProtocolService.jsm"
 );
 
+ChromeUtils.defineModuleGetter(
+  this,
+  "TorConnect",
+  "resource:///modules/TorConnect.jsm"
+);
+ChromeUtils.defineModuleGetter(
+  this,
+  "TorSettings",
+  "resource:///modules/TorSettings.jsm"
+);
+
 /* Browser observer topis */
 const BrowserTopics = Object.freeze({
   ProfileAfterChange: "profile-after-change",
@@ -53,6 +64,9 @@ class TorStartupService {
     await TorProtocolService.init();
     TorMonitorService.init();
 
+    TorSettings.init();
+    TorConnect.init();
+
     try {
       TorLauncherUtil.removeMeekAndMoatHelperProfiles();
     } catch (e) {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list