commit 1f5639da4297ac20fd21223d2004a7cfeef72e21
parent 68b5ac456f3f8153675c0bf2f9feb56b37b2223a
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 9 Oct 2017 23:03:37 -0400
Fix #1335, Item drag and drop is unreliable
Regression from e62433edfb
Load a locale file once via nsIConverterInputStream and cache it for
subsequent retrieveLocale() calls. I'm not sure if using a stream
instead of synchronous XHR is actually necessary now that there's
caching, but it can't hurt.
Diffstat:
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js
@@ -556,12 +556,40 @@ Zotero.Cite.System.prototype = {
* @return {String|Boolean} The locale as a string if it exists, or false if it doesn't
*/
"retrieveLocale":function retrieveLocale(lang) {
+ return Zotero.Cite.Locale.get(lang);
+ }
+};
+
+Zotero.Cite.Locale = {
+ _cache: new Map(),
+
+ get: function (locale) {
+ var str = this._cache.get(locale);
+ if (str) {
+ return str;
+ }
+ var uri = `chrome://zotero/content/locale/csl/locales-${locale}.xml`;
try {
- return Zotero.File.getContentsFromURL(
- `chrome://zotero/content/locale/csl/locales-${lang}.xml`
- );
+ let protHandler = Components.classes["@mozilla.org/network/protocol;1?name=chrome"]
+ .createInstance(Components.interfaces.nsIProtocolHandler);
+ let channel = protHandler.newChannel(protHandler.newURI(uri));
+ let cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
+ .createInstance(Components.interfaces.nsIConverterInputStream);
+ cstream.init(channel.open(), "UTF-8", 0, 0);
+ let obj = {};
+ let read = 0;
+ let str = "";
+ do {
+ // Read as much as we can and put it in obj.value
+ read = cstream.readString(0xffffffff, obj);
+ str += obj.value;
+ } while (read != 0);
+ cstream.close();
+ this._cache.set(locale, str);
+ return str;
}
catch (e) {
+ //Zotero.debug(e);
return false;
}
}