Bug 940907 - Re-introduce the Character Encoding menu to the View Source window. r=Unfocused, a=lsblakk
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Tue, 28 Jan 2014 21:22:13 -0500
changeset 176059 79cbd6fb82054dbf34ef637ce37a9753df011900
parent 176058 27d4e681c33f430887de5ead598ec95a1e49f4d5
child 176060 354c393518fb5a5e00aa9bf5399209e8c7866c4b
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused, lsblakk
bugs940907
milestone28.0a2
Bug 940907 - Re-introduce the Character Encoding menu to the View Source window. r=Unfocused, a=lsblakk
browser/base/content/browser-charsetmenu.inc
browser/base/content/browser-doctype.inc
browser/base/content/browser.js
browser/locales/jar.mn
browser/modules/CharsetMenu.jsm
browser/modules/moz.build
toolkit/components/viewsource/content/viewSource.js
toolkit/components/viewsource/content/viewSource.xul
toolkit/locales/jar.mn
toolkit/modules/CharsetMenu.jsm
toolkit/modules/moz.build
--- a/browser/base/content/browser-charsetmenu.inc
+++ b/browser/base/content/browser-charsetmenu.inc
@@ -6,19 +6,19 @@
 
 #expand <menu id="__ID_PREFIX__charsetMenu"
     label="&charsetMenu.label;"
 #ifndef OMIT_ACCESSKEYS
     accesskey="&charsetMenu.accesskey;"
 #endif
     oncommand="MultiplexHandler(event)"
 #ifdef OMIT_ACCESSKEYS
-#expand    onpopupshowing="CharsetMenu.build(event, '__ID_PREFIX__');"
+#expand    onpopupshowing="CharsetMenu.build(event, '__ID_PREFIX__', false);"
 #else
-#expand    onpopupshowing="CharsetMenu.build(event, '__ID_PREFIX__', true);"
+#expand    onpopupshowing="CharsetMenu.build(event, '__ID_PREFIX__');"
 #endif
     onpopupshown="UpdateMenus(event);">
   <menupopup>
     <menu label="&charsetMenuAutodet.label;"
 #ifndef OMIT_ACCESSKEYS
           accesskey="&charsetMenuAutodet.accesskey;"
 #endif
         >
--- a/browser/base/content/browser-doctype.inc
+++ b/browser/base/content/browser-doctype.inc
@@ -1,16 +1,16 @@
 <!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
 %brandDTD;
 <!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd" >
 %browserDTD;
 <!ENTITY % baseMenuDTD SYSTEM "chrome://browser/locale/baseMenuOverlay.dtd" >
 %baseMenuDTD;
-<!ENTITY % charsetDTD SYSTEM "chrome://browser/locale/charsetMenu.dtd" >
+<!ENTITY % charsetDTD SYSTEM "chrome://global/locale/charsetMenu.dtd" >
 %charsetDTD;
 <!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
 %textcontextDTD;
 <!ENTITY % customizeToolbarDTD SYSTEM "chrome://global/locale/customizeToolbar.dtd">
   %customizeToolbarDTD;
 <!ENTITY % placesDTD SYSTEM "chrome://browser/locale/places/places.dtd">
 %placesDTD;
 #ifdef MOZ_SAFE_BROWSING
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -9,17 +9,17 @@ let Cu = Components.utils;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/NotificationDB.jsm");
 Cu.import("resource:///modules/RecentWindow.jsm");
 Cu.import("resource://gre/modules/WindowsPrefSync.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "CharsetMenu",
-                                  "resource:///modules/CharsetMenu.jsm");
+                                  "resource://gre/modules/CharsetMenu.jsm");
 
 const nsIWebNavigation = Ci.nsIWebNavigation;
 
 var gLastBrowserCharset = null;
 var gPrevCharset = null;
 var gProxyFavIcon = null;
 var gLastValidURLStr = "";
 var gInPrintPreviewMode = false;
--- a/browser/locales/jar.mn
+++ b/browser/locales/jar.mn
@@ -17,18 +17,16 @@
     locale/browser/aboutSessionRestore.dtd         (%chrome/browser/aboutSessionRestore.dtd)
 #ifdef MOZ_SERVICES_SYNC
     locale/browser/syncProgress.dtd                (%chrome/browser/syncProgress.dtd)
     locale/browser/aboutSyncTabs.dtd               (%chrome/browser/aboutSyncTabs.dtd)
 #endif
     locale/browser/browser.dtd                     (%chrome/browser/browser.dtd)
     locale/browser/baseMenuOverlay.dtd             (%chrome/browser/baseMenuOverlay.dtd)
     locale/browser/browser.properties              (%chrome/browser/browser.properties)
-    locale/browser/charsetMenu.properties          (%chrome/browser/charsetMenu.properties)
-    locale/browser/charsetMenu.dtd                 (%chrome/browser/charsetMenu.dtd)
     locale/browser/devtools/appcacheutils.properties  (%chrome/browser/devtools/appcacheutils.properties)
     locale/browser/devtools/debugger.dtd              (%chrome/browser/devtools/debugger.dtd)
     locale/browser/devtools/debugger.properties       (%chrome/browser/devtools/debugger.properties)
     locale/browser/devtools/netmonitor.dtd            (%chrome/browser/devtools/netmonitor.dtd)
     locale/browser/devtools/netmonitor.properties     (%chrome/browser/devtools/netmonitor.properties)
     locale/browser/devtools/shadereditor.dtd          (%chrome/browser/devtools/shadereditor.dtd)
     locale/browser/devtools/shadereditor.properties   (%chrome/browser/devtools/shadereditor.properties)
     locale/browser/devtools/gcli.properties           (%chrome/browser/devtools/gcli.properties)
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -3,17 +3,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 TEST_DIRS += ['test']
 
 EXTRA_JS_MODULES += [
     'BrowserNewTabPreloader.jsm',
-    'CharsetMenu.jsm',
     'ContentClick.jsm',
     'NetworkPrioritizer.jsm',
     'offlineAppCache.jsm',
     'openLocationLastURL.jsm',
     'SharedFrame.jsm',
     'SignInToWebsite.jsm',
     'SitePermissions.jsm',
     'Social.jsm',
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -1,15 +1,16 @@
 // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/CharsetMenu.jsm");
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 var gLastLineFound = '';
 var gGoToLine = 0;
 
 [
@@ -661,16 +662,77 @@ function BrowserCharsetReload()
 }
 
 function BrowserSetForcedCharacterSet(aCharset)
 {
   gBrowser.docShell.charset = aCharset;
   BrowserCharsetReload();
 }
 
+function MultiplexHandler(event)
+{
+  var node = event.target;
+  var name = node.getAttribute("name");
+
+  if (name == "detectorGroup") {
+    SelectDetector(event);
+    BrowserCharsetReload();
+  } else if (name == "charsetGroup") {
+    var charset = node.getAttribute("id");
+    charset = charset.substring(charset.indexOf("charset.") + "charset.".length);
+    BrowserSetForcedCharacterSet(charset);
+  }
+}
+
+function SelectDetector(event)
+{
+  var uri =  event.target.getAttribute("id");
+  var prefvalue = uri.substring(uri.indexOf("chardet.") + "chardet.".length);
+  if ("off" == prefvalue) { // "off" is special value to turn off the detectors
+    prefvalue = "";
+  }
+
+  try {
+    var str = Cc["@mozilla.org/supports-string;1"].
+              createInstance(Ci.nsISupportsString);
+    str.data = prefvalue;
+    gPrefService.setComplexValue("intl.charset.detector", Ci.nsISupportsString, str);
+  }
+  catch (ex) {
+    dump("Failed to set the intl.charset.detector preference.\n");
+  }
+}
+
+function UpdateCurrentCharset() {
+  var menuitem = document.getElementById("charset." + content.document.characterSet);
+  if (menuitem)
+    menuitem.setAttribute("checked", "true");
+}
+
+function UpdateCharsetDetector() {
+  var prefvalue;
+
+  try {
+    prefvalue = gPrefService.getComplexValue("intl.charset.detector", Ci.nsIPrefLocalizedString).data;
+  }
+  catch (ex) {}
+
+  if (!prefvalue)
+    prefvalue = "off";
+
+  var menuitem = document.getElementById("chardet." + prefvalue);
+  if (menuitem)
+    menuitem.setAttribute("checked", "true");
+}
+
+function UpdateMenus() {
+  UpdateCurrentCharset();
+  UpdateCharsetDetector();
+}
+
 function BrowserForward(aEvent) {
   try {
     gBrowser.goForward();
   }
   catch(ex) {
   }
 }
 
--- a/toolkit/components/viewsource/content/viewSource.xul
+++ b/toolkit/components/viewsource/content/viewSource.xul
@@ -9,16 +9,18 @@
 <?xml-stylesheet href="chrome://mozapps/skin/viewsource/viewsource.css" type="text/css"?>
 <?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
 
 <!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
 %brandDTD;
 <!ENTITY % sourceDTD SYSTEM "chrome://global/locale/viewSource.dtd" >
 %sourceDTD;
+<!ENTITY % charsetDTD SYSTEM "chrome://global/locale/charsetMenu.dtd" >
+%charsetDTD;
 ]>
 
 <window id="viewSource"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="onLoadViewSource();"
         contenttitlesetting="true"
         title="&mainWindow.title;" 
         titlemodifier="&mainWindow.titlemodifier;" 
@@ -189,16 +191,53 @@
                         label="&menu_textReduce.label;" accesskey="&menu_textReduce.accesskey;"
                         key="key_textZoomReduce"/>
               <menuseparator/>
               <menuitem id="menu_textReset" command="cmd_textZoomReset"
                         label="&menu_textReset.label;" accesskey="&menu_textReset.accesskey;"
                         key="key_textZoomReset"/>
             </menupopup>
           </menu>
+
+          <!-- Charset Menu -->
+          <menu id="charsetMenu"
+                label="&charsetMenu.label;"
+                accesskey="&charsetMenu.accesskey;"
+                oncommand="MultiplexHandler(event);"
+                onpopupshowing="CharsetMenu.build(event);"
+                onpopupshown="UpdateMenus();">
+            <menupopup>
+              <menu label="&charsetMenuAutodet.label;"
+                    accesskey="&charsetMenuAutodet.accesskey;">
+                <menupopup>
+                  <menuitem type="radio"
+                            name="detectorGroup"
+                            id="chardet.off"
+                            label="&charsetMenuAutodet.off.label;"
+                            accesskey="&charsetMenuAutodet.off.accesskey;"/>
+                  <menuitem type="radio"
+                            name="detectorGroup"
+                            id="chardet.ja_parallel_state_machine"
+                            label="&charsetMenuAutodet.ja.label;"
+                            accesskey="&charsetMenuAutodet.ja.accesskey;"/>
+                  <menuitem type="radio"
+                            name="detectorGroup"
+                            id="chardet.ruprob"
+                            label="&charsetMenuAutodet.ru.label;"
+                            accesskey="&charsetMenuAutodet.ru.accesskey;"/>
+                  <menuitem type="radio"
+                            name="detectorGroup"
+                            id="chardet.ukprob"
+                            label="&charsetMenuAutodet.uk.label;"
+                            accesskey="&charsetMenuAutodet.uk.accesskey;"/>
+                </menupopup>
+              </menu>
+              <menuseparator/>
+            </menupopup>
+          </menu>
           <menuseparator/>
           <menuitem id="menu_wrapLongLines" type="checkbox" command="cmd_wrapLongLines"
                     label="&menu_wrapLongLines.title;" accesskey="&menu_wrapLongLines.accesskey;"/>
           <menuitem type="checkbox" id="menu_highlightSyntax" command="cmd_highlightSyntax"
                     label="&menu_highlightSyntax.label;" accesskey="&menu_highlightSyntax.accesskey;"/>
         </menupopup>
       </menu>
     </menubar>  
--- a/toolkit/locales/jar.mn
+++ b/toolkit/locales/jar.mn
@@ -130,8 +130,12 @@
   locale/@AB_CD@/help/help.properties                     (%chrome/mozapps/help/help.properties)
   locale/@AB_CD@/help/help.dtd                            (%chrome/mozapps/help/help.dtd)
   locale/@AB_CD@/help/help-toc.rdf                        (%chrome/mozapps/help/help-toc.rdf)
   locale/@AB_CD@/help/welcome.xhtml                       (%chrome/mozapps/help/welcome.xhtml)
 #endif
 % locale places @AB_CD@ %locale/@AB_CD@/places/
   locale/@AB_CD@/places/places.properties                 (%chrome/places/places.properties)
   locale/@AB_CD@/global/search/search.properties          (%chrome/search/search.properties)
+
+relativesrcdir browser/locales:
+  locale/@AB_CD@/global/charsetMenu.dtd                 (%chrome/browser/charsetMenu.dtd)
+  locale/@AB_CD@/global/charsetMenu.properties          (%chrome/browser/charsetMenu.properties)
rename from browser/modules/CharsetMenu.jsm
rename to toolkit/modules/CharsetMenu.jsm
--- a/browser/modules/CharsetMenu.jsm
+++ b/toolkit/modules/CharsetMenu.jsm
@@ -4,17 +4,17 @@
 
 this.EXPORTED_SYMBOLS = [ "CharsetMenu" ];
 
 const { classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyGetter(this, "gBundle", function() {
-  const kUrl = "chrome://browser/locale/charsetMenu.properties";
+  const kUrl = "chrome://global/locale/charsetMenu.properties";
   return Services.strings.createBundle(kUrl);
 });
 /**
  * This set contains encodings that are in the Encoding Standard, except:
  *  - XSS-dangerous encodings (except ISO-2022-JP which is assumed to be
  *    too common not to be included).
  *  - x-user-defined, which practically never makes sense as an end-user-chosen
  *    override.
@@ -76,17 +76,17 @@ const kEncodings = new Set([
 
 // Always at the start of the menu, in this order, followed by a separator.
 const kPinned = [
   "UTF-8",
   "windows-1252"
 ];
 
 this.CharsetMenu = Object.freeze({
-  build: function BuildCharsetMenu(event, idPrefix="", showAccessKeys=false) {
+  build: function BuildCharsetMenu(event, idPrefix="", showAccessKeys=true) {
     let parent = event.target;
     if (parent.lastChild.localName != "menuseparator") {
       // Detector menu or charset menu already built
       return;
     }
     let doc = parent.ownerDocument;
 
     function createItem(encoding) {
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -3,16 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 TEST_DIRS += ['tests']
 
 EXTRA_JS_MODULES += [
     'AsyncShutdown.jsm',
+    'CharsetMenu.jsm',
     'debug.js',
     'DeferredTask.jsm',
     'Deprecated.jsm',
     'Dict.jsm',
     'FileUtils.jsm',
     'Finder.jsm',
     'Geometry.jsm',
     'Http.jsm',