Bug 943262 - Use CharsetMenu.jsm instead of charsetTitles.properties for Character Encoding menu items. r=bnicholson

This commit is contained in:
Margaret Leibovic 2014-03-14 11:41:47 -07:00
parent a9933dccf8
commit 1718215200
4 changed files with 23 additions and 36 deletions

View File

@ -234,7 +234,6 @@ 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");

View File

@ -82,6 +82,9 @@ 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"],
@ -253,8 +256,7 @@ function shouldShowProgress(url) {
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() {
@ -6398,40 +6400,31 @@ var CharacterEncoding = {
},
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)
};
});
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);
}
// if document charset is not in charset options, add it
let docCharset = normalizeCharsetCode(BrowserApp.selectedBrowser.contentDocument.characterSet);
let selected = 0;
// 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({

View File

@ -152,10 +152,6 @@ password.dontSave=Don't save
# 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

View File

@ -86,7 +86,6 @@ relativesrcdir toolkit/locales:
# 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)