Loading toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs +20 −19 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", TorProvider: "resource://gre/modules/TorProvider.sys.mjs", TorProviderNone: "resource://gre/modules/TorProviderNone.sys.mjs", }); ChromeUtils.defineLazyGetter(lazy, "logger", () => { Loading Loading @@ -198,23 +199,11 @@ export class TorProviderBuilder { }; Services.obs.addObserver(this.#logObserver, TorProviderTopics.TorLog); switch (this.providerType) { case TorProviders.tor: // Even though initialization of the initial TorProvider is // asynchronous, we do not expect the caller to await it. The reason is // that any call to build() will wait the initialization anyway (and // re-throw any initialization error). // Even though initialization of the initial provider is asynchronous, we do // not expect the caller to await it. The reason is that any call to build() // will wait the initialization anyway (and re-throw any initialization // error). this.#replaceProvider(); break; case TorProviders.none: lazy.TorLauncherUtil.setProxyConfiguration( lazy.TorLauncherUtil.getPreferredSocksConfiguration() ); break; default: console.error(`Unknown tor provider ${this.providerType}.`); break; } } /** Loading Loading @@ -247,10 +236,22 @@ export class TorProviderBuilder { lazy.logger.info(`Creating the initial "${this.providerType}" provider.`); } let providerClass; switch (this.providerType) { case TorProviders.tor: providerClass = lazy.TorProvider; break; case TorProviders.none: providerClass = lazy.TorProviderNone; break; default: lazy.logger.error(`Unknown tor provider ${this.providerType}.`); break; } // NOTE: It should be safe to create another provider instance whilst the // existing one is still active. However, we will wait until the other is // uninitialized before we initialize the new one. const provider = new lazy.TorProvider(() => { const provider = new providerClass(() => { this.#notifyStateChanged(provider); }); const prevProviderData = this.#providerData; Loading Loading @@ -370,7 +371,7 @@ export class TorProviderBuilder { */ static async build() { this.#checkActive(); if (!this.#providerData && this.providerType === TorProviders.none) { if (this.#providerData.provider instanceof lazy.TorProviderNone) { throw new Error( "Tor Browser has been configured to use only the proxy functionalities." ); Loading toolkit/components/tor-launcher/TorProviderNone.sys.mjs 0 → 100644 +19 −0 Original line number Diff line number Diff line import { TorProviderBase } from "resource://gre/modules/TorProviderBase.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", }); /** * A provider that only sets the proxy settings. */ export class TorProviderNone extends TorProviderBase { async _initInternal() { lazy.TorLauncherUtil.setProxyConfiguration( lazy.TorLauncherUtil.getPreferredSocksConfiguration() ); } async _uninitInternal() {} } toolkit/components/tor-launcher/moz.build +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ EXTRA_JS_MODULES += [ "TorProvider.sys.mjs", "TorProviderBase.sys.mjs", "TorProviderBuilder.sys.mjs", "TorProviderNone.sys.mjs", "TorStartupService.sys.mjs", ] Loading Loading
toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs +20 −19 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", TorProvider: "resource://gre/modules/TorProvider.sys.mjs", TorProviderNone: "resource://gre/modules/TorProviderNone.sys.mjs", }); ChromeUtils.defineLazyGetter(lazy, "logger", () => { Loading Loading @@ -198,23 +199,11 @@ export class TorProviderBuilder { }; Services.obs.addObserver(this.#logObserver, TorProviderTopics.TorLog); switch (this.providerType) { case TorProviders.tor: // Even though initialization of the initial TorProvider is // asynchronous, we do not expect the caller to await it. The reason is // that any call to build() will wait the initialization anyway (and // re-throw any initialization error). // Even though initialization of the initial provider is asynchronous, we do // not expect the caller to await it. The reason is that any call to build() // will wait the initialization anyway (and re-throw any initialization // error). this.#replaceProvider(); break; case TorProviders.none: lazy.TorLauncherUtil.setProxyConfiguration( lazy.TorLauncherUtil.getPreferredSocksConfiguration() ); break; default: console.error(`Unknown tor provider ${this.providerType}.`); break; } } /** Loading Loading @@ -247,10 +236,22 @@ export class TorProviderBuilder { lazy.logger.info(`Creating the initial "${this.providerType}" provider.`); } let providerClass; switch (this.providerType) { case TorProviders.tor: providerClass = lazy.TorProvider; break; case TorProviders.none: providerClass = lazy.TorProviderNone; break; default: lazy.logger.error(`Unknown tor provider ${this.providerType}.`); break; } // NOTE: It should be safe to create another provider instance whilst the // existing one is still active. However, we will wait until the other is // uninitialized before we initialize the new one. const provider = new lazy.TorProvider(() => { const provider = new providerClass(() => { this.#notifyStateChanged(provider); }); const prevProviderData = this.#providerData; Loading Loading @@ -370,7 +371,7 @@ export class TorProviderBuilder { */ static async build() { this.#checkActive(); if (!this.#providerData && this.providerType === TorProviders.none) { if (this.#providerData.provider instanceof lazy.TorProviderNone) { throw new Error( "Tor Browser has been configured to use only the proxy functionalities." ); Loading
toolkit/components/tor-launcher/TorProviderNone.sys.mjs 0 → 100644 +19 −0 Original line number Diff line number Diff line import { TorProviderBase } from "resource://gre/modules/TorProviderBase.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", }); /** * A provider that only sets the proxy settings. */ export class TorProviderNone extends TorProviderBase { async _initInternal() { lazy.TorLauncherUtil.setProxyConfiguration( lazy.TorLauncherUtil.getPreferredSocksConfiguration() ); } async _uninitInternal() {} }
toolkit/components/tor-launcher/moz.build +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ EXTRA_JS_MODULES += [ "TorProvider.sys.mjs", "TorProviderBase.sys.mjs", "TorProviderBuilder.sys.mjs", "TorProviderNone.sys.mjs", "TorStartupService.sys.mjs", ] Loading