[tbb-commits] [Git][tpo/applications/tor-browser][tor-browser-115.10.0esr-13.5-1] 4 commits: fixup! Bug 40701: Add security warning when downloading a file

richard (@richard) git at gitlab.torproject.org
Mon Apr 15 18:16:47 UTC 2024



richard pushed to branch tor-browser-115.10.0esr-13.5-1 at The Tor Project / Applications / Tor Browser


Commits:
49db61d8 by Henry Wilkes at 2024-04-15T18:16:31+00:00
fixup! Bug 40701: Add security warning when downloading a file

Bug 42221: Migrate downloads warning strings to Fluent.

- - - - -
93684ca3 by Henry Wilkes at 2024-04-15T18:16:31+00:00
fixup! Tor Browser strings

Bug 42221: Migrate downloads warning strings to Fluent.

- - - - -
4e772ce6 by Henry Wilkes at 2024-04-15T18:16:31+00:00
fixup! Add TorStrings module for localization

Bug 42221: Migrate downloads warning strings to Fluent.

- - - - -
e7445294 by Henry Wilkes at 2024-04-15T18:16:31+00:00
fixup! Tor Browser localization migration scripts.

Bug 42221: Migrate downloads warning strings to Fluent.

- - - - -


9 changed files:

- browser/components/downloads/content/contentAreaDownloadsView.js
- browser/components/downloads/content/contentAreaDownloadsView.xhtml
- browser/components/downloads/content/downloads.js
- browser/components/downloads/content/downloadsPanel.inc.xhtml
- browser/components/places/content/places.js
- browser/components/places/content/places.xhtml
- browser/locales/en-US/browser/tor-browser.ftl
- toolkit/torbutton/chrome/locale/en-US/torbutton.properties
- + tools/torbrowser/l10n/migrations/bug-42210-download-warning.py


Changes:

=====================================
browser/components/downloads/content/contentAreaDownloadsView.js
=====================================
@@ -62,53 +62,6 @@ var ContentAreaDownloadsView = {
     if (!PrivateBrowsingUtils.isContentWindowPrivate(window)) {
       view.place = "place:transition=7&sort=4";
     }
-
-    torWarningMessage.querySelector(
-      ".downloads-tor-warning-title"
-    ).textContent = this._getTorString("torbutton.download.warning.title");
-
-    const tailsLink = document.createElement("a");
-    tailsLink.href = "https://tails.net/";
-    tailsLink.target = "_blank";
-    tailsLink.textContent = this._getTorString(
-      "torbutton.download.warning.tails_brand_name"
-    );
-
-    const [beforeLink, afterLink] = this._getTorString(
-      "torbutton.download.warning.description"
-    ).split("%S");
-
-    torWarningMessage
-      .querySelector(".downloads-tor-warning-description")
-      .append(beforeLink, tailsLink, afterLink);
-
-    torWarningMessage.querySelector(
-      ".downloads-tor-warning-dismiss-button"
-    ).textContent = this._getTorString("torbutton.download.warning.dismiss");
-  },
-
-  /**
-   * Get a string from the properties bundle.
-   *
-   * @param {string} name - The string name.
-   *
-   * @return {string} The string.
-   */
-  _getTorString(name) {
-    if (!this._stringBundle) {
-      this._stringBundle = Services.strings.createBundle(
-        "chrome://torbutton/locale/torbutton.properties"
-      );
-    }
-    try {
-      return this._stringBundle.GetStringFromName(name);
-    } catch {}
-    if (!this._fallbackStringBundle) {
-      this._fallbackStringBundle = Services.strings.createBundle(
-        "resource://torbutton/locale/en-US/torbutton.properties"
-      );
-    }
-    return this._fallbackStringBundle.GetStringFromName(name);
   },
 };
 


=====================================
browser/components/downloads/content/contentAreaDownloadsView.xhtml
=====================================
@@ -21,6 +21,7 @@
   <linkset>
     <html:link rel="localization" href="toolkit/global/textActions.ftl"/>
     <html:link rel="localization" href="browser/downloads.ftl" />
+    <html:link rel="localization" href="browser/tor-browser.ftl" />
   </linkset>
 
   <script src="chrome://global/content/globalOverlay.js"/>
@@ -36,20 +37,34 @@
   </keyset>
 #endif
 
-  <html:message-bar id="aboutDownloadsTorWarning"
-                    class="downloads-tor-warning-message-bar"
-                    role="alert"
-                    aria-labelledby="aboutDownloadsTorWarningTitle"
-                    aria-describedby="aboutDownloadsTorWarningDescription">
+  <html:message-bar
+    id="aboutDownloadsTorWarning"
+    class="downloads-tor-warning-message-bar"
+    role="alert"
+    aria-labelledby="aboutDownloadsTorWarningTitle"
+    aria-describedby="aboutDownloadsTorWarningDescription"
+  >
     <html:div class="downloads-tor-warning-grid">
-      <html:p id="aboutDownloadsTorWarningTitle"
-              class="downloads-tor-warning-title">
+      <html:p
+        id="aboutDownloadsTorWarningTitle"
+        class="downloads-tor-warning-title"
+        data-l10n-id="downloads-tor-warning-title"
+      ></html:p>
+      <html:p
+        id="aboutDownloadsTorWarningDescription"
+        class="downloads-tor-warning-description"
+        data-l10n-id="downloads-tor-warning-description"
+      >
+        <html:a
+          href="https://tails.net/"
+          target="_blank"
+          data-l10n-name="tails-link"
+        ></html:a>
       </html:p>
-      <html:p id="aboutDownloadsTorWarningDescription"
-              class="downloads-tor-warning-description">
-      </html:p>
-      <html:button class="downloads-tor-warning-dismiss-button">
-      </html:button>
+      <html:button
+        class="downloads-tor-warning-dismiss-button"
+        data-l10n-id="downloads-tor-warning-dismiss-button"
+      ></html:button>
     </html:div>
   </html:message-bar>
 


=====================================
browser/components/downloads/content/downloads.js
=====================================
@@ -167,38 +167,29 @@ var DownloadsPanel = {
     );
 
     if (!this._torWarningInitialized) {
-      torWarningMessage.querySelector(
-        ".downloads-tor-warning-title"
-      ).textContent = this._getTorString("torbutton.download.warning.title");
-
-      const tailsLink = document.createElement("a");
-      tailsLink.href = "https://tails.net";
-      tailsLink.textContent = this._getTorString(
-        "torbutton.download.warning.tails_brand_name"
-      );
-      tailsLink.addEventListener("click", event => {
-        event.preventDefault();
-        this.hidePanel();
-        openWebLinkIn(tailsLink.href, "tab");
-      });
-
-      const [beforeLink, afterLink] = this._getTorString(
-        "torbutton.download.warning.description"
-      ).split("%S");
-
+      // Intercept clicks on the tails link.
+      // NOTE: We listen for clicks on the parent instead of the
+      // <a data-l10n-name="tails-link"> element because the latter may be
+      // swapped for a new instance by Fluent when refreshing the parent.
       torWarningMessage
         .querySelector(".downloads-tor-warning-description")
-        .append(beforeLink, tailsLink, afterLink);
+        .addEventListener("click", event => {
+          const tailsLink = event.target.closest(
+            ".downloads-tor-warning-tails-link"
+          );
+          if (!tailsLink) {
+            return;
+          }
+          event.preventDefault();
+          this.hidePanel();
+          openWebLinkIn(tailsLink.href, "tab");
+        });
 
-      let dismissButton = torWarningMessage.querySelector(
-        ".downloads-tor-warning-dismiss-button"
-      );
-      dismissButton.textContent = this._getTorString(
-        "torbutton.download.warning.dismiss"
-      );
-      dismissButton.addEventListener("click", event => {
-        Services.prefs.setBoolPref(PREF_SHOW_DOWNLOAD_WARNING, false);
-      });
+      torWarningMessage
+        .querySelector(".downloads-tor-warning-dismiss-button")
+        .addEventListener("click", event => {
+          Services.prefs.setBoolPref(PREF_SHOW_DOWNLOAD_WARNING, false);
+        });
       this._torWarningInitialized = true;
     }
 
@@ -725,30 +716,6 @@ var DownloadsPanel = {
       }
     }, 0);
   },
-
-  /**
-   * Get a string from the properties bundle.
-   *
-   * @param {string} name - The string name.
-   *
-   * @return {string} The string.
-   */
-  _getTorString(name) {
-    if (!this._stringBundle) {
-      this._stringBundle = Services.strings.createBundle(
-        "chrome://torbutton/locale/torbutton.properties"
-      );
-    }
-    try {
-      return this._stringBundle.GetStringFromName(name);
-    } catch {}
-    if (!this._fallbackStringBundle) {
-      this._fallbackStringBundle = Services.strings.createBundle(
-        "resource://torbutton/locale/en-US/torbutton.properties"
-      );
-    }
-    return this._fallbackStringBundle.GetStringFromName(name);
-  },
 };
 
 XPCOMUtils.defineConstant(this, "DownloadsPanel", DownloadsPanel);


=====================================
browser/components/downloads/content/downloadsPanel.inc.xhtml
=====================================
@@ -125,19 +125,32 @@
 
     <panelview id="downloadsPanel-mainView">
       <vbox id="downloadsPanelTorWarning">
-        <vbox role="alert"
-              aria-labelledby="downloadsPanelTorWarningTitle"
-              aria-describedby="downloadsPanelTorWarningDescription">
-          <html:p id="downloadsPanelTorWarningTitle"
-                  class="downloads-tor-warning-title">
+        <vbox
+          role="alert"
+          aria-labelledby="downloadsPanelTorWarningTitle"
+          aria-describedby="downloadsPanelTorWarningDescription"
+        >
+          <html:p
+            id="downloadsPanelTorWarningTitle"
+            class="downloads-tor-warning-title"
+            data-l10n-id="downloads-tor-warning-title"
+          ></html:p>
+          <html:p
+            id="downloadsPanelTorWarningDescription"
+            class="downloads-tor-warning-description"
+            data-l10n-id="downloads-tor-warning-description"
+          >
+            <html:a
+              href="https://tails.net/"
+              data-l10n-name="tails-link"
+              class="downloads-tor-warning-tails-link"
+            ></html:a>
           </html:p>
-          <html:p id="downloadsPanelTorWarningDescription"
-                  class="downloads-tor-warning-description">
-          </html:p>
-
           <html:div class="panel-footer">
-            <html:button class="downloads-tor-warning-dismiss-button">
-            </html:button>
+            <html:button
+              class="downloads-tor-warning-dismiss-button"
+              data-l10n-id="downloads-tor-warning-dismiss-button"
+            ></html:button>
           </html:div>
         </vbox>
         <toolbarseparator />


=====================================
browser/components/places/content/places.js
=====================================
@@ -176,32 +176,22 @@ var PlacesOrganizer = {
       }
     );
 
-    // Initialize tor warning text content.
-    torWarningMessage.querySelector(
-      ".downloads-tor-warning-title"
-    ).textContent = this._getTorString("torbutton.download.warning.title");
-
-    const tailsLink = document.createElement("a");
-    tailsLink.href = "https://tails.net/";
-    tailsLink.textContent = this._getTorString(
-      "torbutton.download.warning.tails_brand_name"
-    );
-    tailsLink.addEventListener("click", event => {
-      event.preventDefault();
-      openWebLinkIn(tailsLink.href, "tab");
-    });
-
-    const [beforeLink, afterLink] = this._getTorString(
-      "torbutton.download.warning.description"
-    ).split("%S");
-
-    torWarningMessage
+    // Intercept clicks on the tor warning tails link.
+    // NOTE: We listen for clicks on the parent instead of the
+    // <a data-l10n-name="tails-link"> element because the latter may be
+    // swapped for a new instance by Fluent when refreshing the parent.
+    document
       .querySelector(".downloads-tor-warning-description")
-      .append(beforeLink, tailsLink, afterLink);
-
-    torWarningMessage.querySelector(
-      ".downloads-tor-warning-dismiss-button"
-    ).textContent = this._getTorString("torbutton.download.warning.dismiss");
+      .addEventListener("click", event => {
+        const tailsLink = event.target.closest(
+          ".downloads-tor-warning-tails-link"
+        );
+        if (!tailsLink) {
+          return;
+        }
+        event.preventDefault();
+        openWebLinkIn(tailsLink.href, "tab");
+      });
 
     ContentArea.init();
 
@@ -274,30 +264,6 @@ var PlacesOrganizer = {
     ContentArea.focus();
   },
 
-  /**
-   * Get a string from the properties bundle.
-   *
-   * @param {string} name - The string name.
-   *
-   * @returns {string} The string.
-   */
-  _getTorString(name) {
-    if (!this._stringBundle) {
-      this._stringBundle = Services.strings.createBundle(
-        "chrome://torbutton/locale/torbutton.properties"
-      );
-    }
-    try {
-      return this._stringBundle.GetStringFromName(name);
-    } catch {}
-    if (!this._fallbackStringBundle) {
-      this._fallbackStringBundle = Services.strings.createBundle(
-        "resource://torbutton/locale/en-US/torbutton.properties"
-      );
-    }
-    return this._fallbackStringBundle.GetStringFromName(name);
-  },
-
   QueryInterface: ChromeUtils.generateQI([]),
 
   handleEvent: function PO_handleEvent(aEvent) {


=====================================
browser/components/places/content/places.xhtml
=====================================
@@ -40,6 +40,7 @@
     <html:link rel="localization" href="browser/places.ftl"/>
     <html:link rel="localization" href="browser/downloads.ftl"/>
     <html:link rel="localization" href="browser/editBookmarkOverlay.ftl"/>
+    <html:link rel="localization" href="browser/tor-browser.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/places/places.js"/>
@@ -338,19 +339,33 @@
     </tree>
     <splitter collapse="none" persist="state"></splitter>
     <vbox id="contentView">
-      <html:message-bar id="placesDownloadsTorWarning"
-                        role="alert"
-                        aria-labelledby="placesDownloadsTorWarningTitle"
-                        aria-describedby="placesDownloadsTorWarningDescription">
+      <html:message-bar
+        id="placesDownloadsTorWarning"
+        role="alert"
+        aria-labelledby="placesDownloadsTorWarningTitle"
+        aria-describedby="placesDownloadsTorWarningDescription"
+      >
         <html:div class="downloads-tor-warning-grid">
-          <html:p id="placesDownloadsTorWarningTitle"
-                  class="downloads-tor-warning-title">
+          <html:p
+            id="placesDownloadsTorWarningTitle"
+            class="downloads-tor-warning-title"
+            data-l10n-id="downloads-tor-warning-title"
+          ></html:p>
+          <html:p
+            id="placesDownloadsTorWarningDescription"
+            class="downloads-tor-warning-description"
+            data-l10n-id="downloads-tor-warning-description"
+          >
+            <html:a
+              href="https://tails.net/"
+              class="downloads-tor-warning-tails-link"
+              data-l10n-name="tails-link"
+            ></html:a>
           </html:p>
-          <html:p id="placesDownloadsTorWarningDescription"
-                  class="downloads-tor-warning-description">
-          </html:p>
-          <html:button class="downloads-tor-warning-dismiss-button">
-          </html:button>
+          <html:button
+            class="downloads-tor-warning-dismiss-button"
+            data-l10n-id="downloads-tor-warning-dismiss-button"
+          ></html:button>
         </html:div>
       </html:message-bar>
       <vbox id="placesViewsBox" flex="1">


=====================================
browser/locales/en-US/browser/tor-browser.ftl
=====================================
@@ -548,3 +548,12 @@ crypto-safety-prompt-title = Cryptocurrency address copied from an insecure webs
 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
+
+## Downloads warning.
+## Shown in downloads panel, about:downloads and Library window.
+
+downloads-tor-warning-title = Be careful opening downloads
+# "Tails" is the brand name for the Tails operating system and should be localized appropriately, and will be a link to its website. The name should be wrapped in '<a data-l10n-name="tails-link">' and '</a>'.
+downloads-tor-warning-description = Some files may connect to the internet when opened without using Tor. To be safe, open the files while offline or use a portable operating system like <a data-l10n-name="tails-link">Tails</a>.
+# Button to dismiss the warning forever.
+downloads-tor-warning-dismiss-button = Got it


=====================================
toolkit/torbutton/chrome/locale/en-US/torbutton.properties
=====================================
@@ -3,14 +3,6 @@
 # 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/.
 
-# Download pane warning
-torbutton.download.warning.title = Be careful opening downloads
-# %S will be a link to the Tails operating system website. With the content given by torbutton.download.warning.tails_brand_name
-torbutton.download.warning.description = Some files may connect to the internet when opened without using Tor. To be safe, open the files while offline or use a portable operating system like %S.
-# Locale name for Tails operating system.
-torbutton.download.warning.tails_brand_name = Tails
-torbutton.download.warning.dismiss = Got it
-
 # .Onion Page Info prompt.
 pageInfo_OnionEncryptionWithBitsAndProtocol=Connection Encrypted (Onion Service, %1$S, %2$S bit keys, %3$S)
 pageInfo_OnionEncryption=Connection Encrypted (Onion Service)


=====================================
tools/torbrowser/l10n/migrations/bug-42210-download-warning.py
=====================================
@@ -0,0 +1,39 @@
+import fluent.syntax.ast as FTL
+from fluent.migrate.helpers import transforms_from
+from fluent.migrate.transforms import CONCAT, COPY, REPLACE
+
+
+def migrate(ctx):
+    legacy_path = "torbutton.properties"
+
+    ctx.add_transforms(
+        "tor-browser.ftl",
+        "tor-browser.ftl",
+        transforms_from(
+            """
+downloads-tor-warning-title = { COPY(path, "torbutton.download.warning.title") }
+downloads-tor-warning-dismiss-button = { COPY(path, "torbutton.download.warning.dismiss") }
+""",
+            path=legacy_path,
+        )
+        + [
+            # Replace "%S" with link to Tails website.
+            FTL.Message(
+                id=FTL.Identifier("downloads-tor-warning-description"),
+                value=REPLACE(
+                    legacy_path,
+                    "torbutton.download.warning.description",
+                    {
+                        "%1$S": CONCAT(
+                            FTL.TextElement('<a data-l10n-name="tails-link">'),
+                            COPY(
+                                legacy_path,
+                                "torbutton.download.warning.tails_brand_name",
+                            ),
+                            FTL.TextElement("</a>"),
+                        )
+                    },
+                ),
+            ),
+        ],
+    )



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/a5b9b03b01162f4b5dc5c52d7b3301238778af88...e7445294dd49959ea7c14171177cb64cada8a16c

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/a5b9b03b01162f4b5dc5c52d7b3301238778af88...e7445294dd49959ea7c14171177cb64cada8a16c
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20240415/8eae584d/attachment-0001.htm>


More information about the tbb-commits mailing list