From 4a477a198be86a165a6748a967238f5c3e56d87c Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Sat, 5 Jul 2008 20:53:48 -0400 Subject: [PATCH] Bug 441876: remove UTF-7 option from browser Character Encoding menus, r=smontagu, sr=bzbarsky --- browser/base/content/browser.js | 20 +++++++--------- intl/uconv/src/charsetData.properties | 1 + toolkit/content/charsetOverlay.js | 20 +++++++--------- .../en-US/chrome/global/intl.properties | 2 +- xpfe/components/intl/nsCharsetMenu.cpp | 24 +++++++++++++++---- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 1894f22dd0cf..6ca76e21ade6 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -5066,21 +5066,19 @@ function BrowserSetForcedDetector(doReload) function UpdateCurrentCharset() { - var menuitem = null; - - // exctract the charset from DOM + // extract the charset from DOM var wnd = document.commandDispatcher.focusedWindow; if ((window == wnd) || (wnd == null)) wnd = window.content; - menuitem = document.getElementById('charset.' + wnd.document.characterSet); + // Uncheck previous item + if (gPrevCharset) { + var pref_item = document.getElementById('charset.' + gPrevCharset); + if (pref_item) + pref_item.setAttribute('checked', 'false'); + } + + var menuitem = document.getElementById('charset.' + wnd.document.characterSet); if (menuitem) { - // uncheck previously checked item to workaround Mac checkmark problem - // bug 98625 - if (gPrevCharset) { - var pref_item = document.getElementById('charset.' + gPrevCharset); - if (pref_item) - pref_item.setAttribute('checked', 'false'); - } menuitem.setAttribute('checked', 'true'); } } diff --git a/intl/uconv/src/charsetData.properties b/intl/uconv/src/charsetData.properties index 249039e7f4f7..853b3fa5aa8d 100644 --- a/intl/uconv/src/charsetData.properties +++ b/intl/uconv/src/charsetData.properties @@ -66,6 +66,7 @@ ibm1125.notForBrowser = true ibm1131.notForBrowser = true x-ibm1046.notForBrowser = true iso-8859-8-e.notForBrowser = true +utf-7.notForBrowser = true t.61-8bit.notForOutgoing = true utf-7.notForOutgoing = true diff --git a/toolkit/content/charsetOverlay.js b/toolkit/content/charsetOverlay.js index f20ac5a8aa9f..8b286d1430bb 100644 --- a/toolkit/content/charsetOverlay.js +++ b/toolkit/content/charsetOverlay.js @@ -118,21 +118,19 @@ function SetForcedCharset(charset) var gPrevCharset = null; function UpdateCurrentCharset() { - var menuitem = null; - - // exctract the charset from DOM + // extract the charset from DOM var wnd = document.commandDispatcher.focusedWindow; if ((window == wnd) || (wnd == null)) wnd = window.content; - menuitem = document.getElementById('charset.' + wnd.document.characterSet); + // Uncheck previous item + if (gPrevCharset) { + var pref_item = document.getElementById('charset.' + gPrevCharset); + if (pref_item) + pref_item.setAttribute('checked', 'false'); + } + + var menuitem = document.getElementById('charset.' + wnd.document.characterSet); if (menuitem) { - // uncheck previously checked item to workaround Mac checkmark problem - // bug 98625 - if (gPrevCharset) { - var pref_item = document.getElementById('charset.' + gPrevCharset); - if (pref_item) - pref_item.setAttribute('checked', 'false'); - } menuitem.setAttribute('checked', 'true'); } } diff --git a/toolkit/locales/en-US/chrome/global/intl.properties b/toolkit/locales/en-US/chrome/global/intl.properties index 8afc0f37363e..dba12e393317 100644 --- a/toolkit/locales/en-US/chrome/global/intl.properties +++ b/toolkit/locales/en-US/chrome/global/intl.properties @@ -29,7 +29,7 @@ intl.charsetmenu.browser.more3=GB2312, x-gbk, gb18030, HZ-GB-2312, ISO-2022-CN, intl.charsetmenu.browser.more4=armscii-8, GEOSTD8, TIS-620, ISO-8859-11, windows-874, IBM857, ISO-8859-9, x-mac-turkish, windows-1254, x-viet-tcvn5712, VISCII, x-viet-vps, windows-1258, x-mac-devanagari, x-mac-gujarati, x-mac-gurmukhi intl.charsetmenu.browser.more5=ISO-8859-6, windows-1256, IBM864, x-mac-arabic, x-mac-farsi, ISO-8859-8-I, windows-1255, ISO-8859-8, IBM862, x-mac-hebrew # Localization Note: Never change the following entry. -intl.charsetmenu.browser.unicode=UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, UTF-7 +intl.charsetmenu.browser.unicode=UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE intl.charset.default=ISO-8859-1 intl.charset.detector= intl.charsetmenu.mailedit=ISO-8859-1, ISO-8859-15, ISO-8859-6, armscii-8, geostd8, ISO-8859-13, ISO-8859-14, ISO-8859-2, GB2312, GB18030, Big5, KOI8-R, windows-1251, KOI8-U, ISO-8859-7, ISO-8859-8-I, windows-1255, ISO-2022-JP, EUC-KR, ISO-8859-10, ISO-8859-3, TIS-620, ISO-8859-9, UTF-8, VISCII diff --git a/xpfe/components/intl/nsCharsetMenu.cpp b/xpfe/components/intl/nsCharsetMenu.cpp index a03e95687f49..4cde09d0ef05 100644 --- a/xpfe/components/intl/nsCharsetMenu.cpp +++ b/xpfe/components/intl/nsCharsetMenu.cpp @@ -282,7 +282,7 @@ private: nsresult RemoveLastMenuItem(nsIRDFContainer * aContainer, nsVoidArray * aArray); - nsresult RemoveFlaggedCharsets(nsCStringArray& aList, nsString * aProp); + nsresult RemoveFlaggedCharsets(nsCStringArray& aList, const nsString& aProp); nsresult NewRDFContainer(nsIRDFDataSource * aDataSource, nsIRDFResource * aResource, nsIRDFContainer ** aResult); void FreeMenuItemArray(nsVoidArray * aArray); @@ -593,6 +593,10 @@ nsresult nsCharsetMenu::RefreshBrowserMenu() // mark the end of the static area, the rest is cache mBrowserCacheStart = mBrowserMenu.Count(); + // Remove "notForBrowser" entries before populating cache menu + res = RemoveFlaggedCharsets(decs, NS_LITERAL_STRING(".notForBrowser")); + NS_ASSERTION(NS_SUCCEEDED(res), "error removing flagged charsets"); + res = InitCacheMenu(decs, kNC_BrowserCharsetMenuRoot, kBrowserCachePrefKey, &mBrowserMenu); NS_ASSERTION(NS_SUCCEEDED(res), "error initializing browser cache charset menu"); @@ -903,6 +907,10 @@ nsresult nsCharsetMenu::InitBrowserMenu() // elements are numbered from 1 (why god, WHY?!?!?!) mBrowserMenuRDFPosition -= mBrowserCacheStart - 1; + // Remove "notForBrowser" entries before populating cache menu + res = RemoveFlaggedCharsets(browserDecoderList, NS_LITERAL_STRING(".notForBrowser")); + NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs"); + res = InitCacheMenu(browserDecoderList, kNC_BrowserCharsetMenuRoot, kBrowserCachePrefKey, &mBrowserMenu); NS_ASSERTION(NS_SUCCEEDED(res), "error initializing browser cache charset menu"); @@ -1210,13 +1218,12 @@ nsresult nsCharsetMenu::InitMoreMenu(nsCStringArray& aDecs, nsresult res = NS_OK; nsCOMPtr container; nsVoidArray moreMenu; - nsAutoString prop; prop.AssignWithConversion(aFlag); res = NewRDFContainer(mInner, aResource, getter_AddRefs(container)); if (NS_FAILED(res)) goto done; // remove charsets "not for browser" - res = RemoveFlaggedCharsets(aDecs, &prop); + res = RemoveFlaggedCharsets(aDecs, NS_ConvertASCIItoUTF16(aFlag)); if (NS_FAILED(res)) goto done; res = AddCharsetArrayToItemArray(moreMenu, aDecs); @@ -1698,7 +1705,7 @@ nsresult nsCharsetMenu::RemoveLastMenuItem(nsIRDFContainer * aContainer, } nsresult nsCharsetMenu::RemoveFlaggedCharsets(nsCStringArray& aList, - nsString * aProp) + const nsString& aProp) { nsresult res = NS_OK; PRUint32 count; @@ -1713,7 +1720,7 @@ nsresult nsCharsetMenu::RemoveFlaggedCharsets(nsCStringArray& aList, charset = aList.CStringAt(i); if (!charset) continue; - res = mCCManager->GetCharsetData(charset->get(), aProp->get(), str); + res = mCCManager->GetCharsetData(charset->get(), aProp.get(), str); if (NS_FAILED(res)) continue; aList.RemoveCStringAt(i); @@ -1841,6 +1848,13 @@ NS_IMETHODIMP nsCharsetMenu::SetCurrentCharset(const PRUnichar * aCharset) nsresult res = NS_OK; if (mBrowserMenuInitialized) { + // Don't add item to the cache if it's marked "notForBrowser" + nsAutoString str; + res = mCCManager->GetCharsetData(NS_LossyConvertUTF16toASCII(aCharset).get(), + NS_LITERAL_STRING(".notForBrowser").get(), str); + if (NS_SUCCEEDED(res)) // succeeded means attribute exists + return res; // don't throw + res = AddCharsetToCache(NS_LossyConvertUTF16toASCII(aCharset), &mBrowserMenu, kNC_BrowserCharsetMenuRoot, mBrowserCacheStart, mBrowserCacheSize,