Bug 1558503 - Preserve the order of the arguments in the localized storageAccess.message string; r=johannh,flod, a=jcristau FIREFOX_ESR_68_0_X_RELBRANCH
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 10 Jul 2019 15:05:47 +0000
branchFIREFOX_ESR_68_0_X_RELBRANCH
changeset 523036 a244194949587eaa74bcf9f9015388214e36a2d7
parent 523035 e76e10494b89a3bd93d06ec53c0f17dbc34062da
child 523037 c7c791d2632d9f80884fd0d5d884de811e1e4dea
push id81
push userryanvm@gmail.com
push dateWed, 17 Jul 2019 19:37:31 +0000
treeherdermozilla-esr68@61219aed2735 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, flod, jcristau
bugs1558503
milestone68.0.1
Bug 1558503 - Preserve the order of the arguments in the localized storageAccess.message string; r=johannh,flod, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D37468
browser/modules/PermissionUI.jsm
toolkit/modules/PopupNotifications.jsm
--- a/browser/modules/PermissionUI.jsm
+++ b/browser/modules/PermissionUI.jsm
@@ -1081,17 +1081,17 @@ StorageAccessPermissionPrompt.prototype 
     return "storage-access";
   },
 
   get anchorID() {
     return "storage-access-notification-icon";
   },
 
   get message() {
-    return gBrowserBundle.formatStringFromName("storageAccess.message", ["<>", "<>"], 2);
+    return gBrowserBundle.formatStringFromName("storageAccess.message", ["<>", "{}"], 2);
   },
 
   get promptActions() {
     let self = this;
 
     let storageAccessHistogram = Services.telemetry.getHistogramById("STORAGE_ACCESS_API_UI");
 
     return [{
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -336,18 +336,19 @@ PopupNotifications.prototype = {
    *        "geolocation"). Only one notification with a given ID can be visible
    *        at a time. If a notification already exists with the given ID, it
    *        will be replaced.
    * @param message
    *        A string containing the text to be displayed as the notification
    *        header.  The string may optionally contain one or two "<>" as a
    *        placeholder which is later replaced by a host name or an addon name
    *        that is formatted to look bold, in which case the options.name
-   *        property (as well as options.secondName if passing two "<>"
-   *        placeholders) needs to be specified.
+   *        property (as well as options.secondName if passing a "<>" and a "{}"
+   *        placeholder) needs to be specified. "<>" will be considered as the
+   *        first and "{}" as the second placeholder.
    * @param anchorID
    *        The ID of the element that should be used as this notification
    *        popup's anchor. May be null, in which case the notification will be
    *        anchored to the iconBox.
    * @param mainAction
    *        A JavaScript object literal describing the notification button's
    *        action. If present, it must have the following properties:
    *          - label (string): the button's label.
@@ -469,17 +470,19 @@ PopupNotifications.prototype = {
    *        name:
    *                     An optional string formatted to look bold and used in the
    *                     notifiation description header text. Usually a host name or
    *                     addon name.
    *        secondName:
    *                     An optional string formatted to look bold and used in the
    *                     notification description header text. Usually a host name or
    *                     addon name. This is similar to name, and only used in case
-   *                     where message contains two "<>" placeholders.
+   *                     where message contains a "<>" and a "{}" placeholder. "<>"
+   *                     is considered the first and "{}" is considered the second
+   *                     placeholder.
    *        escAction:
    *                     An optional string indicating the action to take when the
    *                     Esc key is pressed. This should be set to the name of the
    *                     command to run. If not provided, "secondarybuttoncommand"
    *                     will be used.
    * @returns the Notification object corresponding to the added notification.
    */
   show: function PopupNotifications_show(browser, id, message, anchorID,
@@ -785,23 +788,31 @@ PopupNotifications.prototype = {
    *        file URIs with description messages that don't display hostnames.
    * name:  A string that is formatted to look bold. It replaces the
    *        placeholder with the options.name property from the notification
    *        object which is usually an addon name or a host name.
    * end:   The last part of the description message.
    */
   _formatDescriptionMessage(n) {
     let text = {};
-    let array = n.message.split("<>");
+    let array = n.message.split(/<>|{}/);
     text.start = array[0] || "";
     text.name = n.options.name || "";
     text.end = array[1] || "";
     if (array.length == 3) {
       text.secondName = n.options.secondName || "";
       text.secondEnd = array[2] || "";
+
+      // name and secondName should be in logical positions.  Swap them in case
+      // the second placeholder came before the first one in the original string.
+      if (n.message.indexOf("{}") < n.message.indexOf("<>")) {
+        let tmp = text.name;
+        text.name = text.secondName;
+        text.secondName = tmp;
+      }
     } else if (array.length > 3) {
       Cu.reportError("Unexpected array length encountered in " +
                      "_formatDescriptionMessage: " + array.length);
     }
     return text;
   },
 
   _refreshPanel: function PopupNotifications_refreshPanel(notificationsToShow) {