diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index e60fbbe1..b4d728dd 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -529,7 +529,7 @@ var Bookmarks = Module("bookmarks", { description: "The character encoding of the bookmark", type: CommandOption.STRING, completer: function (context) completion.charset(context), - validator: Option.validateCompleter + validator: io.bound.validateCharset }, { names: ["-id"], diff --git a/common/modules/base.jsm b/common/modules/base.jsm index e368811c..7d34390b 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -17,7 +17,7 @@ function module(url) { } var { XPCOMUtils } = module("resource://gre/modules/XPCOMUtils.jsm"); -var { OS, TextDecoder, TextEncoder } = module("resource://gre/modules/osfile.jsm"); +var { OS } = module("resource://gre/modules/osfile.jsm"); try { var { ctypes } = module("resource://gre/modules/ctypes.jsm"); } @@ -748,9 +748,13 @@ function memoize(obj, key, getter) { } } -let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].createInstance()); + +let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].createInstance(), + { wantGlobalProperties: ["TextDecoder", "TextEncoder"] }); sandbox.__proto__ = this; +var { TextEncoder, TextDecoder } = sandbox; + /** * Updates an object with the properties of another object. Getters * and setters are copied as expected. Moreover, any function diff --git a/common/modules/io.jsm b/common/modules/io.jsm index b0466dc2..c1a28320 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -216,6 +216,28 @@ var IO = Module("io", { } }), + charsets: Class.Memoize(function () { + const BASE = "@mozilla.org/intl/unicode/decoder;1?charset="; + return [k.slice(BASE.length) + for (k of Object.keys(Cc)) + if (k.startsWith(BASE))]; + }), + + charsetBundle: Class.Memoize( + () => services.stringBundle.createBundle("chrome://global/locale/charsetTitles.properties")), + + charsetTitle: function charsetTitle(charset, default_=charset) { + try { + return this.charsetBundle.GetStringFromName(charset + ".title"); + } + catch (e) {} + return default_; + }, + + validateCharset: function validateCharset(charset) { + new TextDecoder(charset); + }, + // TODO: there seems to be no way, short of a new component, to change // the process's CWD - see https://bugzilla.mozilla.org/show_bug.cgi?id=280953 /** @@ -942,16 +964,9 @@ unlet s:cpo_save context.anchored = false; context.keys = { text: util.identity, - description: function (charset) { - try { - return services.charset.getCharsetTitle(charset); - } - catch (e) { - return charset; - } - } + description: charset => io.charsetTitle(charset), }; - context.generate = () => iter(services.charset.getDecoderList()); + context.completions = io.charsets; }; completion.directory = function directory(context, full) {