Bug 441876: remove UTF-7 option from browser Character Encoding menus, r=smontagu, sr=bzbarsky
authorGavin Sharp <gavin@mozilla.com>
Sat, 05 Jul 2008 20:53:48 -0400
changeset 15673 e64a979ed64ca82d8ad98f32ec0ad92b01e180eb
parent 15672 5024aedbb16db85443010febda827f67eff74296
child 15674 d4f93c4a8a8a1280aa9261f6db00a53ccf349194
push idunknown
push userunknown
push dateunknown
reviewerssmontagu, bzbarsky
bugs441876
milestone1.9.1a1pre
Bug 441876: remove UTF-7 option from browser Character Encoding menus, r=smontagu, sr=bzbarsky
browser/base/content/browser.js
intl/uconv/src/charsetData.properties
toolkit/content/charsetOverlay.js
toolkit/locales/en-US/chrome/global/intl.properties
xpfe/components/intl/nsCharsetMenu.cpp
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5061,31 +5061,29 @@ function BrowserSetForcedDetector(doRelo
 {
   getBrowser().documentCharsetInfo.forcedDetector = true;
   if (doReload)
     BrowserReloadWithFlags(nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
 }
 
 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');
     }
 }
 
 function UpdateCharsetDetector()
 {
     var prefvalue;
 
--- a/intl/uconv/src/charsetData.properties
+++ b/intl/uconv/src/charsetData.properties
@@ -61,16 +61,17 @@ x-obsoleted-shift_jis.notForBrowser     
 iso-8859-6-e.notForBrowser              = true
 iso-8859-6-i.notForBrowser              = true
 ibm864i.notForBrowser                   = true
 ibm869.notForBrowser                    = true
 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
 x-imap4-modified-utf7.notForOutgoing = true
 windows-936.notForOutgoing           = true
 us-ascii.notForOutgoing                  = true
 x-obsoleted-euc-jp.notForOutgoing        = true
 x-obsoleted-iso-2022-jp.notForOutgoing   = true
--- a/toolkit/content/charsetOverlay.js
+++ b/toolkit/content/charsetOverlay.js
@@ -113,31 +113,29 @@ function SetForcedDetector(doReload)
 function SetForcedCharset(charset)
 {
     BrowserSetForcedCharacterSet(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');
     }
 }
 
 function UpdateCurrentMailCharset()
 {
     var charset = msgWindow.mailCharacterSet;
     var menuitem = document.getElementById('charset.' + charset);
--- a/toolkit/locales/en-US/chrome/global/intl.properties
+++ b/toolkit/locales/en-US/chrome/global/intl.properties
@@ -24,16 +24,16 @@ font.language.group=x-western
 intl.accept_languages=en-us, en
 intl.charsetmenu.browser.static=ISO-8859-1, UTF-8
 intl.charsetmenu.browser.more1=ISO-8859-1, ISO-8859-15, IBM850, x-mac-roman, windows-1252, ISO-8859-14, ISO-8859-7, x-mac-greek, windows-1253, x-mac-icelandic, ISO-8859-10, ISO-8859-3
 intl.charsetmenu.browser.more2=ISO-8859-4, ISO-8859-13, windows-1257, IBM852, ISO-8859-2, x-mac-ce, windows-1250, x-mac-croatian, IBM855, ISO-8859-5, ISO-IR-111, KOI8-R, x-mac-cyrillic, windows-1251, IBM866, KOI8-U, x-mac-ukrainian, ISO-8859-16, x-mac-romanian
 intl.charsetmenu.browser.more3=GB2312, x-gbk, gb18030, HZ-GB-2312, ISO-2022-CN, Big5, Big5-HKSCS, x-euc-tw, EUC-JP, ISO-2022-JP, Shift_JIS, EUC-KR, x-windows-949, x-johab, ISO-2022-KR
 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
 # valid intl.menuitems.appendedacceskeys are: true or false, <empty string> (missing or empty preference equals false)
 intl.menuitems.alwaysappendaccesskeys=
 # valid intl.menuitems.insertseparatorbeforeaccesskeys are: true or false, <empty string> (missing or empty preference equals false)
 intl.menuitems.insertseparatorbeforeaccesskeys=true
--- a/xpfe/components/intl/nsCharsetMenu.cpp
+++ b/xpfe/components/intl/nsCharsetMenu.cpp
@@ -277,17 +277,17 @@ private:
     const char * aKey);
   nsresult UpdateCachePrefs(const char * aCacheKey, const char * aCacheSizeKey, 
     const char * aStaticKey, const PRUnichar * aCharset);
 
   nsresult ClearMenu(nsIRDFContainer * aContainer, nsVoidArray * aArray);
   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);
   PRInt32 FindMenuItemInArray(const nsVoidArray* aArray,
                               const nsAFlatCString& aCharset, 
                               nsMenuEntry ** aResult);
   nsresult ReorderMenuItemArray(nsVoidArray * aArray);
   nsresult GetCollation(nsICollation ** aCollation);
@@ -588,16 +588,20 @@ nsresult nsCharsetMenu::RefreshBrowserMe
   
   res = AddFromPrefsToMenu(&mBrowserMenu, container, kBrowserStaticPrefKey, 
                            decs, "charset.");
   NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs");
 
   // 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");
 
   return res;
 }
 
 nsresult nsCharsetMenu::RefreshMailviewMenu()
@@ -898,16 +902,20 @@ nsresult nsCharsetMenu::InitBrowserMenu(
 
     // compute the position of the menu in the RDF container
     res = container->GetCount(&mBrowserMenuRDFPosition);
     if (NS_FAILED(res)) return res;
     // this "1" here is a correction necessary because the RDF container 
     // 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");
 
     // register prefs callback
     nsCOMPtr<nsIPrefBranch2> pbi = do_QueryInterface(mPrefs);
     if (pbi)
       res = pbi->AddObserver(kBrowserStaticPrefKey, mCharsetMenuObserver, PR_FALSE);
@@ -1205,23 +1213,22 @@ nsresult nsCharsetMenu::InitMoreMenu(nsC
                                      nsIRDFResource * aResource, 
                                      const char * aFlag)
 {
   NS_TIMELINE_START_TIMER("nsCharsetMenu::InitMoreMenu");
 
   nsresult res = NS_OK;
   nsCOMPtr<nsIRDFContainer> 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);
   if (NS_FAILED(res)) goto done;
 
   // reorder the array
   res = ReorderMenuItemArray(&moreMenu);
   if (NS_FAILED(res)) goto done;
@@ -1693,32 +1700,32 @@ nsresult nsCharsetMenu::RemoveLastMenuIt
       if (NS_FAILED(res)) return res;
     }
   }
 
   return res;
 }
 
 nsresult nsCharsetMenu::RemoveFlaggedCharsets(nsCStringArray& aList, 
-                                              nsString * aProp)
+                                              const nsString& aProp)
 {
   nsresult res = NS_OK;
   PRUint32 count;
 
   count = aList.Count();
   if (NS_FAILED(res)) return res;
 
   nsCString* charset;
   nsAutoString str;
   for (PRUint32 i = 0; i < count; i++) {
 
     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);
 
     i--; 
     count--;
   }
 
@@ -1836,16 +1843,23 @@ nsresult nsCharsetMenu::GetCollation(nsI
 // Interface nsICurrentCharsetListener [implementation]
 
 NS_IMETHODIMP nsCharsetMenu::SetCurrentCharset(const PRUnichar * aCharset)
 {
   NS_TIMELINE_START_TIMER("nsCharsetMenu:SetCurrentCharset");
   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,
                             mBrowserMenuRDFPosition);
     if (NS_FAILED(res)) {
         NS_TIMELINE_LEAVE("nsCharsetMenu:SetCurrentCharset");
         return res;
     }