Bug 943262 - Use CharsetMenu.jsm instead of charsetTitles.properties for Character Encoding menu items. r=bnicholson
☠☠ backed out by 2569cd05832a ☠ ☠
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 14 Mar 2014 11:41:47 -0700
changeset 191805 e7f7cc81c10333623a345b77450b7b98824fdfbc
parent 191804 c25710dd68fface0dabbe0e3b473d309d9e7c488
child 191806 0e2a2db3af5cf889e7d5eaff83362d3780be00f1
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs943262
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 943262 - Use CharsetMenu.jsm instead of charsetTitles.properties for Character Encoding menu items. r=bnicholson
mobile/android/app/mobile.js
mobile/android/chrome/content/browser.js
mobile/android/locales/en-US/chrome/browser.properties
mobile/android/locales/jar.mn
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -229,17 +229,16 @@ pref("accessibility.typeaheadfind.timeou
 pref("accessibility.typeaheadfind.flashBar", 1);
 pref("accessibility.typeaheadfind.linksonly", false);
 pref("accessibility.typeaheadfind.casesensitive", 0);
 pref("accessibility.browsewithcaret_shortcut.enabled", false);
 
 // Whether the character encoding menu is under the main Firefox button. This
 // preference is a string so that localizers can alter it.
 pref("browser.menu.showCharacterEncoding", "chrome://browser/locale/browser.properties");
-pref("intl.charsetmenu.browser.static", "chrome://browser/locale/browser.properties");
 
 // pointer to the default engine name
 pref("browser.search.defaultenginename", "chrome://browser/locale/region.properties");
 // SSL error page behaviour
 pref("browser.ssl_override_behavior", 2);
 pref("browser.xul.error_pages.expert_bad_cert", false);
 
 // disable logging for the search service by default
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -77,16 +77,19 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://shumway/ShumwayUtils.jsm");
 #endif
 
 #ifdef MOZ_ANDROID_SYNTHAPKS
 XPCOMUtils.defineLazyModuleGetter(this, "WebappManager",
                                   "resource://gre/modules/WebappManager.jsm");
 #endif
 
+XPCOMUtils.defineLazyModuleGetter(this, "CharsetMenu",
+                                  "resource://gre/modules/CharsetMenu.jsm");
+
 // Lazily-loaded browser scripts:
 [
   ["SelectHelper", "chrome://browser/content/SelectHelper.js"],
   ["InputWidgetHelper", "chrome://browser/content/InputWidgetHelper.js"],
   ["AboutReader", "chrome://browser/content/aboutReader.js"],
   ["MasterPassword", "chrome://browser/content/MasterPassword.js"],
   ["PluginHelper", "chrome://browser/content/PluginHelper.js"],
   ["OfflineApps", "chrome://browser/content/OfflineApps.js"],
@@ -248,18 +251,17 @@ function shouldShowProgress(url) {
 }
 
 /**
  * Cache of commonly used string bundles.
  */
 var Strings = {};
 [
   ["brand",      "chrome://branding/locale/brand.properties"],
-  ["browser",    "chrome://browser/locale/browser.properties"],
-  ["charset",    "chrome://global/locale/charsetTitles.properties"]
+  ["browser",    "chrome://browser/locale/browser.properties"]
 ].forEach(function (aStringBundle) {
   let [name, bundle] = aStringBundle;
   XPCOMUtils.defineLazyGetter(Strings, name, function() {
     return Services.strings.createBundle(bundle);
   });
 });
 
 const kFormHelperModeDisabled = 0;
@@ -6393,50 +6395,41 @@ var CharacterEncoding = {
 
     sendMessageToJava({
       type: "CharEncoding:State",
       visible: showCharEncoding
     });
   },
 
   getEncoding: function getEncoding() {
-    function normalizeCharsetCode(charsetCode) {
-      return charsetCode.trim().toLowerCase();
-    }
-
-    function getTitle(charsetCode) {
-      let charsetTitle = charsetCode;
-      try {
-        charsetTitle = Strings.charset.GetStringFromName(charsetCode + ".title");
-      } catch (e) {
-        dump("error: title not found for " + charsetCode);
-      }
-      return charsetTitle;
+    function infoToCharset(info) {
+      return { code: info.value, title: info.label };
     }
 
     if (!this._charsets.length) {
-      let charsets = Services.prefs.getComplexValue("intl.charsetmenu.browser.static", Ci.nsIPrefLocalizedString).data;
-      this._charsets = charsets.split(",").map(function (charset) {
-        return {
-          code: normalizeCharsetCode(charset),
-          title: getTitle(charset)
-        };
-      });
-    }
-
-    // if document charset is not in charset options, add it
-    let docCharset = normalizeCharsetCode(BrowserApp.selectedBrowser.contentDocument.characterSet);
-    let selected = 0;
+      let data = CharsetMenu.getData();
+
+      // In the desktop UI, the pinned charsets are shown above the rest.
+      let pinnedCharsets = data.pinnedCharsets.map(infoToCharset);
+      let otherCharsets = data.otherCharsets.map(infoToCharset)
+
+      this._charsets = pinnedCharsets.concat(otherCharsets);
+    }
+
+    // Look for the index of the selected charset. Default to -1 if the
+    // doc charset isn't found in the list of available charsets.
+    let docCharset = BrowserApp.selectedBrowser.contentDocument.characterSet;
+    let selected = -1;
     let charsetCount = this._charsets.length;
-    for (; selected < charsetCount && this._charsets[selected].code != docCharset; selected++);
-    if (selected == charsetCount) {
-      this._charsets.push({
-        code: docCharset,
-        title: getTitle(docCharset)
-      });
+
+    for (let i = 0; i < charsetCount; i++) {
+      if (this._charsets[i].code === docCharset) {
+        selected = i;
+        break;
+      }
     }
 
     sendMessageToJava({
       type: "CharEncoding:Data",
       charsets: this._charsets,
       selected: selected
     });
   },
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -147,20 +147,16 @@ password.dontSave=Don't save
 # LOCALIZATION NOTE (browser.menu.showCharacterEncoding): Set to the string
 # "true" (spelled and capitalized exactly that way) to show the "Character
 # Encoding" menu in the site menu. Any other value will hide it. Without this
 # setting, the "Character Encoding" menu must be enabled via Preferences.
 # This is not a string to translate. If users frequently use the "Character Encoding"
 # menu, set this to "true". Otherwise, you can leave it as "false".
 browser.menu.showCharacterEncoding=false
 
-# LOCALIZATION NOTE (intl.charsetmenu.browser.static): Set to a series of comma separated
-# values for charsets that the user can select from in the Character Encoding menu.
-intl.charsetmenu.browser.static=iso-8859-1,utf-8,big5,iso-2022-jp,shift_jis,euc-jp
-
 # Text Selection
 selectionHelper.textCopied=Text copied to clipboard
 
 # Casting
 casting.prompt=Cast to Device
 
 # Context menu
 contextmenu.openInNewTab=Open Link in New Tab
--- a/mobile/android/locales/jar.mn
+++ b/mobile/android/locales/jar.mn
@@ -81,17 +81,16 @@ relativesrcdir toolkit/locales:
 % override chrome://global/locale/crashes.dtd chrome://browser/locale/overrides/crashreporter/crashes.dtd
 % override chrome://global/locale/crashes.properties chrome://browser/locale/overrides/crashreporter/crashes.properties
 % override chrome://global/locale/mozilla.dtd chrome://browser/locale/overrides/global/mozilla.dtd
 % override chrome://global/locale/aboutTelemetry.dtd chrome://browser/locale/overrides/global/aboutTelemetry.dtd
 % override chrome://global/locale/aboutTelemetry.properties chrome://browser/locale/overrides/global/aboutTelemetry.properties
 
 # overrides for dom l10n, also for en-US
 relativesrcdir dom/locales:
-  locale/@AB_CD@/browser/overrides/charsetTitles.properties    (%chrome/charsetTitles.properties)
   locale/@AB_CD@/browser/overrides/global.dtd                  (%chrome/global.dtd)
   locale/@AB_CD@/browser/overrides/AccessFu.properties         (%chrome/accessibility/AccessFu.properties)
   locale/@AB_CD@/browser/overrides/dom/dom.properties          (%chrome/dom/dom.properties)
 #about:plugins
   locale/@AB_CD@/browser/overrides/plugins.properties          (%chrome/plugins.properties)
 
 % override chrome://global/locale/charsetTitles.properties chrome://browser/locale/overrides/charsetTitles.properties
 % override chrome://global/locale/global.dtd chrome://browser/locale/overrides/global.dtd