Bug 1387902: Don't attempt to localize browserAction widget properties. r?Gijs draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 06 Aug 2017 16:34:31 -0700
changeset 641403 2640f61d885fee9bed60e8c15b4df1b2cd4c6a31
parent 641402 78851ac803c7a1924c96a2b9764f1fbbe7e01a70
child 641429 36e0186dbae57187eae72c844e21ddf4ea8758e5
push id72508
push usermaglione.k@gmail.com
push dateSun, 06 Aug 2017 23:35:14 +0000
reviewersGijs
bugs1387902
milestone57.0a1
Bug 1387902: Don't attempt to localize browserAction widget properties. r?Gijs We spend a lot of time at startup generating exception objects while trying to retrieve nonexistent localized properties from string bundles. Since extension widget values will never be localized this way, we should skip the string bundle lookup entirely. MozReview-Commit-ID: L9r59bf2Dgf
browser/components/customizableui/CustomizableUI.jsm
browser/components/extensions/ext-browserAction.js
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -1441,16 +1441,19 @@ var CustomizableUIInternal = {
       // By using this as the default, if a widget provides a full string rather
       // than a string ID for localization, we will fall back to that string
       // and return that.
       def = aDef || name;
     } else {
       name = aWidget.id + "." + aProp;
       def = aDef || "";
     }
+    if (aWidget.localized === false) {
+      return def;
+    }
     try {
       if (Array.isArray(aFormatArgs) && aFormatArgs.length) {
         return gWidgetsBundle.formatStringFromName(name, aFormatArgs,
           aFormatArgs.length) || def;
       }
       return gWidgetsBundle.GetStringFromName(name) || def;
     } catch (ex) {
       // If an empty string was explicitly passed, treat it as an actual
@@ -2313,16 +2316,17 @@ var CustomizableUIInternal = {
 
   // XXXunf Log some warnings here, when the data provided isn't up to scratch.
   normalizeWidget(aData, aSource) {
     let widget = {
       implementation: aData,
       source: aSource || CustomizableUI.SOURCE_EXTERNAL,
       instances: new Map(),
       currentArea: null,
+      localized: true,
       removable: true,
       overflows: true,
       defaultArea: null,
       shortcutId: null,
       tabSpecific: false,
       tooltiptext: null,
       showInPrivateBrowsing: true,
       _introducedInVersion: -1,
@@ -2348,17 +2352,18 @@ var CustomizableUIInternal = {
 
     const kOptStringProps = ["label", "tooltiptext", "shortcutId"];
     for (let prop of kOptStringProps) {
       if (typeof aData[prop] == "string") {
         widget[prop] = aData[prop];
       }
     }
 
-    const kOptBoolProps = ["removable", "showInPrivateBrowsing", "overflows", "tabSpecific"];
+    const kOptBoolProps = ["removable", "showInPrivateBrowsing", "overflows", "tabSpecific",
+                           "localized"];
     for (let prop of kOptBoolProps) {
       if (typeof aData[prop] == "boolean") {
         widget[prop] = aData[prop];
       }
     }
 
     // When we normalize builtin widgets, areas have not yet been registered:
     if (aData.defaultArea &&
@@ -3291,16 +3296,19 @@ this.CustomizableUI = {
    *                  shown may pass this method a Promise, which will
    *                  prevent the view from showing until it resolves.
    *                  Additionally, if the promise resolves to the exact
    *                  value `false`, the view will not be shown.
    * - onViewHiding(aEvt): Only useful for views; a function that will be
    *                  invoked when a user hides your view.
    * - tooltiptext:   string to use for the tooltip of the widget
    * - label:         string to use for the label of the widget
+   * - localized:     If true, or undefined, attempt to retrieve the
+   *                  widget's string properties from the customizable
+   *                  widgets string bundle.
    * - removable:     whether the widget is removable (optional, default: true)
    *                  NB: if you specify false here, you must provide a
    *                  defaultArea, too.
    * - overflows:     whether widget can overflow when in an overflowable
    *                  toolbar (optional, default: true)
    * - defaultArea:   default area to add the widget to
    *                  (optional, default: none; required if non-removable)
    * - shortcutId:    id of an element that has a shortcut for this widget
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -134,16 +134,20 @@ this.browserAction = class extends Exten
       id: this.id,
       viewId: this.viewId,
       type: "view",
       removable: true,
       label: this.defaults.title || this.extension.name,
       tooltiptext: this.defaults.title || "",
       defaultArea: this.defaults.area,
 
+      // Don't attempt to load properties from the built-in widget string
+      // bundle.
+      localized: false,
+
       onBeforeCreated: document => {
         let view = document.createElementNS(XUL_NS, "panelview");
         view.id = this.viewId;
         view.setAttribute("flex", "1");
         view.setAttribute("extension", true);
 
         document.getElementById("PanelUI-multiView").appendChild(view);
         document.addEventListener("popupshowing", this);