Bug 611580 - Allow chaning character encoding in Fennec. [r=mfinkle, a=blocking]

This commit is contained in:
Wes Johnston 2011-02-18 11:48:50 -08:00
Родитель 295b22a3ca
Коммит 6cf8484043
13 изменённых файлов: 170 добавлений и 7 удалений

Просмотреть файл

@ -243,6 +243,11 @@ pref("accessibility.browsewithcaret_shortcut.enabled", false);
// successfully applied.
pref("app.update.showInstalledUI", 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

Просмотреть файл

@ -38,12 +38,15 @@ let WebProgressListener = {
let spec = aLocationURI ? aLocationURI.spec : "";
let location = spec.split("#")[0];
let charset = content.document.characterSet;
let json = {
contentWindowId: content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID,
documentURI: aWebProgress.DOMWindow.document.documentURIObject.spec,
location: spec,
canGoBack: docShell.canGoBack,
canGoForward: docShell.canGoForward
documentURI: aWebProgress.DOMWindow.document.documentURIObject.spec,
location: spec,
canGoBack: docShell.canGoBack,
canGoForward: docShell.canGoForward,
charset: charset.toString()
};
sendAsyncMessage("Content:LocationChange", json);

Просмотреть файл

@ -219,6 +219,7 @@
this._browser._webNavigation._currentURI = locationURI;
this._browser._webNavigation.canGoBack = json.canGoBack;
this._browser._webNavigation.canGoForward = json.canGoForward;
this._browser._charset = json.charset;
} catch(e) {}
if (this._browser.updateWindowId(json.contentWindowId)) {
@ -722,8 +723,18 @@
readonly="true"/>
<property name="documentCharsetInfo"
onget="return null"
readonly="true"/>
readonly="true">
<getter><![CDATA[
return {
forcedCharset : this._charset,
forcedDetector : false,
parentCharset : "",
parentCharsetSource : 0
}
]]></getter>
</property>
<field name="_charset"></field>
<constructor>
<![CDATA[

Просмотреть файл

@ -238,6 +238,33 @@
</implementation>
</binding>
<binding id="setting-localized-bool" extends="chrome://browser/content/bindings/setting.xml#setting-bool">
<implementation>
<method name="valueFromPreference">
<body>
<![CDATA[
let val = Services.prefs.getComplexValue(this.pref, Components.interfaces.nsIPrefLocalizedString).data;
if(this.inverted) val = !val;
this.value = (val == "true");
]]>
</body>
</method>
<method name="valueToPreference">
<body>
<![CDATA[
let val = this.value;
if(this.inverted) val = !val;
let pref = Components.classes["@mozilla.org/pref-localizedstring;1"].createInstance(Components.interfaces.nsIPrefLocalizedString);
pref.data = this.inverted ? (!val).toString() : val.toString();
Services.prefs.setComplexValue(this.pref, Components.interfaces.nsIPrefLocalizedString, pref);
]]>
</body>
</method>
</implementation>
</binding>
<binding id="setting-integer" extends="chrome://browser/content/bindings/setting.xml#setting-base">
<content>
<xul:box flex="1" class="prefbox setting-integer">

Просмотреть файл

@ -75,7 +75,8 @@ XPCOMUtils.defineLazyGetter(this, "CommonUI", function() {
["FindHelperUI"],
["NewTabPopup"],
["PageActions"],
["BrowserSearch"]
["BrowserSearch"],
["CharsetMenu"]
].forEach(function (aObject) {
XPCOMUtils.defineLazyGetter(window, aObject, function() {
return CommonUI[aObject];

Просмотреть файл

@ -526,6 +526,7 @@ var BrowserUI = {
PageActions.init();
FullScreenVideo.init();
NewTabPopup.init();
CharsetMenu.init();
#ifdef MOZ_UPDATER
// Check for updates in progress

Просмотреть файл

@ -30,6 +30,10 @@ setting[type="bool"] {
-moz-binding: url("chrome://browser/content/bindings/setting.xml#setting-bool");
}
setting[type="bool"][localized="true"] {
-moz-binding: url("chrome://browser/content/bindings/setting.xml#setting-localized-bool");
}
setting[type="boolint"] {
-moz-binding: url("chrome://browser/content/bindings/setting.xml#setting-boolint");
}

Просмотреть файл

@ -343,6 +343,7 @@
<pageaction id="pageaction-reset" title="&pageactions.reset;"
onclick="PageActions.clearPagePermissions(event);"/>
<pageaction id="pageaction-search" title="&pageactions.search.addNew;"/>
<pageaction id="pageaction-charset" title="&pageactions.charEncoding;" onclick="CharsetMenu.show();"/>
</hbox>
</arrowbox>
@ -466,6 +467,7 @@
<setting pref="browser.ui.zoom.reflow" title="&reflowZoom.title;" type="bool"/>
<setting pref="permissions.default.image" title="&showImages.title;" type="boolint" on="1" off="2"/>
<setting pref="javascript.enabled" type="bool" title="&enableJavaScript.title;"/>
<setting pref="browser.menu.showCharacterEncoding" type="bool" localized="true" title="&showCharset.title;"/>
</settings>
</richlistbox>
</notificationbox>

Просмотреть файл

@ -1225,3 +1225,88 @@ var FullScreenVideo = {
});
}
};
var CharsetMenu = {
_strings: null,
_charsets: null,
get strings() {
if (!this._strings)
this._strings = Services.strings.createBundle("chrome://global/locale/charsetTitles.properties");
return this._strings;
},
init: function() {
PageActions.register("pageaction-charset", this.updatePageAction, this);
},
updatePageAction: function(aNode) {
let pref = Services.prefs.getComplexValue("browser.menu.showCharacterEncoding", Ci.nsIPrefLocalizedString).data;
if (pref == "true") {
let charset = getBrowser().documentCharsetInfo.forcedCharset;
if (charset) {
charset = charset.trim().toLowerCase();
aNode.setAttribute("description", this.strings.GetStringFromName(charset + ".title"));
} else if (aNode.hasAttribute("description")) {
aNode.removeAttribute("description");
}
}
return ("true" == pref)
},
_toMenuItems: function(aCharsets, aCurrent) {
let ret = [];
aCharsets.forEach(function (aSet) {
try {
let string = aSet.trim().toLowerCase();
ret.push({
label: this.strings.GetStringFromName(string + ".title"),
value: string,
selected: (string == aCurrent)
});
} catch(ex) { }
}, this);
return ret;
},
menu : {
dispatchEvent: function(aEvent) {
if (aEvent.type == "command")
CharsetMenu.setCharset(this.menupopup.children[this.selectedIndex].value);
},
menupopup: {
hasAttribute: function(aAttr) { return false; },
},
selectedIndex: -1
},
get charsets() {
if (!this._charsets) {
this._charsets = Services.prefs.getComplexValue("intl.charsetmenu.browser.static", Ci.nsIPrefLocalizedString).data.split(",");
}
let charsets = this._charsets;
let currentCharset = getBrowser().documentCharsetInfo.forcedCharset;
if (currentCharset) {
currentCharset = currentCharset.trim().toLowerCase();
if (charsets.indexOf(currentCharset) == -1)
charsets.splice(0, 0, currentCharset);
}
return this._toMenuItems(charsets, currentCharset);
},
show: function showCharsetMenu() {
this.menu.menupopup.children = this.charsets;
MenuListHelperUI.show(this.menu);
},
setCharset: function setCharset(aCharset) {
let browser = getBrowser();
browser.messageManager.sendAsyncMessage("Browser:SetCharset", {
charset: aCharset
});
let history = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
history.setCharsetForURI(browser.documentURI, aCharset);
}
};

Просмотреть файл

@ -266,6 +266,7 @@ let Content = {
addMessageListener("Browser:SaveAs", this);
addMessageListener("Browser:ZoomToPoint", this);
addMessageListener("Browser:MozApplicationCache:Fetch", this);
addMessageListener("Browser:SetCharset", this);
if (Util.isParentProcess())
addEventListener("DOMActivate", this, true);
@ -524,6 +525,15 @@ let Content = {
updateService.scheduleUpdate(manifestURI, currentURI, content);
break;
}
case "Browser:SetCharset": {
let docCharset = docShell.QueryInterface(Ci.nsIDocCharset);
docCharset.charset = json.charset;
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
webNav.reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
break;
}
}
},

Просмотреть файл

@ -109,5 +109,6 @@
<!ENTITY pageactions.reset "Clear Site Preferences">
<!ENTITY pageactions.findInPage "Find In Page">
<!ENTITY pageactions.search.addNew "Add Search Engine">
<!ENTITY pageactions.charEncoding "Character Encoding">
<!ENTITY appMenu.siteOptions "Site Options">

Просмотреть файл

@ -210,3 +210,15 @@ openinapp.general=Open in Another App
# Clear Private Data
clearPrivateData.title=Clear Private Data
clearPrivateData.message=Delete your browsing history and settings, including passwords and cookies?
# 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,x-gbk,big5,iso-2022-jp,shift_jis,euc-jp

Просмотреть файл

@ -19,3 +19,4 @@
<!ENTITY homepage.none "Blank Page">
<!ENTITY homepage.default "&brandShortName; Start">
<!ENTITY homepage.currentpage "Use Current Page">
<!ENTITY showCharset.title "Show Character Encoding">