tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 985df247e26de13e1ca9517b3146144e6db22568
parent dea39cffc946bc006df7308b8d8338e3914f2c91
Author: Henry Wilkes <henry@torproject.org>
Date:   Wed, 13 Sep 2023 14:09:59 +0100

TB 42110: Add TorUIUtils module for common tor component methods.

Diffstat:
Mbrowser/base/content/browser.js | 1+
Mbrowser/base/content/browser.js.globals | 3++-
Abrowser/modules/TorUIUtils.sys.mjs | 26++++++++++++++++++++++++++
Mbrowser/modules/moz.build | 1+
4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js @@ -103,6 +103,7 @@ ChromeUtils.defineESModuleGetters(this, { ToolbarDropHandler: "moz-src:///browser/components/customizableui/ToolbarDropHandler.sys.mjs", ToolbarIconColor: "moz-src:///browser/themes/ToolbarIconColor.sys.mjs", + TorUIUtils: "resource:///modules/TorUIUtils.sys.mjs", TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs", UITour: "moz-src:///browser/components/uitour/UITour.sys.mjs", UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs", diff --git a/browser/base/content/browser.js.globals b/browser/base/content/browser.js.globals @@ -240,5 +240,6 @@ "ProfilesDatastoreService", "gTrustPanelHandler", "SecurityLevelButton", - "NewIdentityButton" + "NewIdentityButton", + "TorUIUtils" ] diff --git a/browser/modules/TorUIUtils.sys.mjs b/browser/modules/TorUIUtils.sys.mjs @@ -0,0 +1,26 @@ +/** + * Common methods for tor UI components. + */ +export const TorUIUtils = { + /** + * Shorten the given address if it is an onion address. + * + * @param {string} address - The address to shorten. + * + * @returns {string} The shortened form of the address, or the address itself + * if it was not shortened. + */ + shortenOnionAddress(address) { + if ( + // Only shorten ".onion" addresses. + !address.endsWith(".onion") || + // That are not "onion" aliases. + address.endsWith(".tor.onion") || + // And are long. + address.length <= 21 + ) { + return address; + } + return `${address.slice(0, 6)}…${address.slice(-12)}`; + }, +}; diff --git a/browser/modules/moz.build b/browser/modules/moz.build @@ -140,6 +140,7 @@ EXTRA_JS_MODULES += [ "SharingUtils.sys.mjs", "SiteDataManager.sys.mjs", "SitePermissions.sys.mjs", + "TorUIUtils.sys.mjs", "TransientPrefs.sys.mjs", "URILoadingHelper.sys.mjs", "webrtcUI.sys.mjs",