richard pushed to branch tor-browser-115.9.0esr-13.5-1 at The Tor Project / Applications / Tor Browser
Commits: 3ddbe28a by Henry Wilkes at 2024-04-08T18:58:55+00:00 fixup! Bug 40209: Implement Basic Crypto Safety
Bug 42202: Migrate crypto safety strings to Fluent.
- - - - - 58d32687 by Henry Wilkes at 2024-04-08T18:58:55+00:00 fixup! Tor Browser strings
Bug 42202: Migrate crypto safety strings to Fluent.
- - - - - bb6f56ad by Henry Wilkes at 2024-04-08T18:58:55+00:00 fixup! Tor Browser localization migration scripts.
Bug 42202: Migrate crypto safety strings to Fluent.
- - - - -
5 changed files:
- browser/actors/CryptoSafetyParent.jsm - browser/locales/en-US/browser/tor-browser.ftl - − browser/locales/en-US/chrome/browser/cryptoSafetyPrompt.properties - browser/locales/jar.mn - + tools/torbrowser/l10n/migrations/bug-42202-crypto-safety.py
Changes:
===================================== browser/actors/CryptoSafetyParent.jsm ===================================== @@ -20,17 +20,8 @@ ChromeUtils.defineModuleGetter( "resource://gre/modules/TorDomainIsolator.jsm" );
-XPCOMUtils.defineLazyGetter(lazy, "cryptoSafetyBundle", () => { - return Services.strings.createBundle( - "chrome://browser/locale/cryptoSafetyPrompt.properties" - ); -}); - -// en-US fallback in case a locale is missing a string. -XPCOMUtils.defineLazyGetter(lazy, "fallbackCryptoSafetyBundle", () => { - return Services.strings.createBundle( - "resource:///chrome/en-US/locale/browser/cryptoSafetyPrompt.properties" - ); +ChromeUtils.defineLazyGetter(lazy, "CryptoStrings", function () { + return new Localization(["browser/tor-browser.ftl"]); });
XPCOMUtils.defineLazyPreferenceGetter( @@ -40,26 +31,8 @@ XPCOMUtils.defineLazyPreferenceGetter( true // Defaults to true. );
-/** - * Get a formatted string from the locale's bundle, or the en-US bundle if the - * string is missing. - * - * @param {string} name - The string's name. - * @param {string[]} [args] - Positional arguments to pass to the format string, - * or leave empty if none are needed. - * - * @returns {string} - The formatted string. - */ -function getString(name, args = []) { - try { - return lazy.cryptoSafetyBundle.formatStringFromName(name, args); - } catch { - return lazy.fallbackCryptoSafetyBundle.formatStringFromName(name, args); - } -} - class CryptoSafetyParent extends JSWindowActorParent { - receiveMessage(aMessage) { + async receiveMessage(aMessage) { if ( !lazy.isCryptoSafetyEnabled || aMessage.name !== "CryptoSafety:CopiedText" @@ -72,14 +45,25 @@ class CryptoSafetyParent extends JSWindowActorParent { address = `${address.substring(0, 32)}…`; }
+ const [titleText, bodyText, reloadText, dismissText] = + await lazy.CryptoStrings.formatValues([ + { id: "crypto-safety-prompt-title" }, + { + id: "crypto-safety-prompt-body", + args: { address, host: aMessage.data.host }, + }, + { id: "crypto-safety-prompt-reload-button" }, + { id: "crypto-safety-prompt-dismiss-button" }, + ]); + const buttonPressed = Services.prompt.confirmEx( this.browsingContext.topChromeWindow, - getString("cryptoSafetyPrompt.cryptoTitle"), - getString("cryptoSafetyPrompt.cryptoBody", [address, aMessage.data.host]), + titleText, + bodyText, Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 + Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_1, - getString("cryptoSafetyPrompt.primaryAction"), - getString("cryptoSafetyPrompt.secondaryAction"), + reloadText, + dismissText, null, null, {}
===================================== browser/locales/en-US/browser/tor-browser.ftl ===================================== @@ -382,3 +382,12 @@ tor-circuit-panel-new-button = New Tor circuit for this site tor-circuit-panel-new-button-description-guard = Your guard node may not change # Shown when the first node in the circuit is a bridge node. tor-circuit-panel-new-button-description-bridge = Your bridge may not change + +## This dialog is shown when copying a suspected cryptocurrency address from a plain HTTP website. + +crypto-safety-prompt-title = Cryptocurrency address copied from an insecure website +# $address (String) - The cryptocurrency address, possibly truncated. +# $host (String) - The website host the address was copied from. +crypto-safety-prompt-body = The copied text ({ $address }) appears to be a cryptocurrency address. Since the connection to { $host } is not secure, the address may have been modified and should not be trusted. You can try establishing a secure connection by reconnecting with a new circuit. +crypto-safety-prompt-reload-button = Reload Tab with a New Circuit +crypto-safety-prompt-dismiss-button = Dismiss Warning
===================================== browser/locales/en-US/chrome/browser/cryptoSafetyPrompt.properties deleted ===================================== @@ -1,19 +0,0 @@ -# Copyright (c) 2022, The Tor Project, Inc. -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -cryptoSafetyPrompt.cryptoTitle=Cryptocurrency address copied from an insecure website -# LOCALIZATION NOTE: -# %1$S is the copied cryptocurrency address. -# %2$S is the website host. -cryptoSafetyPrompt.cryptoBody=The copied text (%1$S) appears to be a cryptocurrency address. Since the connection to %2$S is not secure, the address may have been modified and should not be trusted. You can try establishing a secure connection by reconnecting with a new circuit. -# LOCALIZATION NOTE: %S will be replaced with the cryptocurrency address. -cryptoSafetyPrompt.cryptoWarning=A cryptocurrency address (%S) has been copied from an insecure website. It could have been modified. -cryptoSafetyPrompt.whatCanHeading=What can you do about it? -cryptoSafetyPrompt.whatCanBody=You can try reconnecting with a new circuit to establish a secure connection, or accept the risk and dismiss this warning. -cryptoSafetyPrompt.learnMore=Learn more -cryptoSafetyPrompt.primaryAction=Reload Tab with a New Circuit -cryptoSafetyPrompt.primaryActionAccessKey=R -cryptoSafetyPrompt.secondaryAction=Dismiss Warning -cryptoSafetyPrompt.secondaryActionAccessKey=B
===================================== browser/locales/jar.mn ===================================== @@ -33,5 +33,4 @@ locale/browser/safebrowsing/safebrowsing.properties (%chrome/browser/safebrowsing/safebrowsing.properties) locale/browser/feeds/subscribe.properties (%chrome/browser/feeds/subscribe.properties) locale/browser/syncSetup.properties (%chrome/browser/syncSetup.properties) - locale/browser/cryptoSafetyPrompt.properties (%chrome/browser/cryptoSafetyPrompt.properties) % locale browser-region @AB_CD@ %locale/browser-region/
===================================== tools/torbrowser/l10n/migrations/bug-42202-crypto-safety.py ===================================== @@ -0,0 +1,34 @@ +import fluent.syntax.ast as FTL +from fluent.migrate.helpers import VARIABLE_REFERENCE, transforms_from +from fluent.migrate.transforms import REPLACE + + +def migrate(ctx): + legacy_path = "cryptoSafetyPrompt.properties" + + ctx.add_transforms( + "tor-browser.ftl", + "tor-browser.ftl", + transforms_from( + """ +crypto-safety-prompt-title = { COPY(path, "cryptoSafetyPrompt.cryptoTitle") } +crypto-safety-prompt-reload-button = { COPY(path, "cryptoSafetyPrompt.primaryAction") } +crypto-safety-prompt-dismiss-button = { COPY(path, "cryptoSafetyPrompt.secondaryAction") } +""", + path=legacy_path, + ) + + [ + # Replace "%1$S" and "%2$S" with "{ $address }" and "{ $host }" + FTL.Message( + id=FTL.Identifier("crypto-safety-prompt-body"), + value=REPLACE( + legacy_path, + "cryptoSafetyPrompt.cryptoBody", + { + "%1$S": VARIABLE_REFERENCE("address"), + "%2$S": VARIABLE_REFERENCE("host"), + }, + ), + ), + ], + )
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/27fee80...
tbb-commits@lists.torproject.org