-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
-Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("protocol", {
exports: ["LocaleChannel", "Protocol", "RedirectChannel", "StringChannel", "XMLChannel"],
require: ["services", "util"]
-}, this);
+});
var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
originalURI: orig,
- asyncOpen: function () { throw error || Cr.NS_ERROR_FILE_NOT_FOUND },
+ asyncOpen: function () { throw error || Cr.NS_ERROR_FILE_NOT_FOUND; },
- open: function () { throw error || Cr.NS_ERROR_FILE_NOT_FOUND }
+ open: function () { throw error || Cr.NS_ERROR_FILE_NOT_FOUND; }
}).data.QueryInterface(Ci.nsIChannel);
}
function RedirectChannel(to, orig, time, message) {
- let html = <html><head><meta http-equiv="Refresh" content={(time || 0) + ";" + to}/></head>
- <body><h2 style="text-align: center">{message || ""}</h2></body></html>.toXMLString();
+ let html = DOM.toXML(
+ ["html", {},
+ ["head", {},
+ ["meta", { "http-equiv": "Refresh", content: (time || 0) + ";" + to }]],
+ ["body", {},
+ ["h2", { style: "text-align: center" }, message || ""]]]);
return StringChannel(html, "text/html", services.io.newURI(to, null, null));
}
contentBase: contentBase,
- _xpcom_factory: JSMLoader.Factory(Protocol),
+ _xpcom_factory: JSMLoader.Factory(Protocol)
};
return Protocol;
}
};
function LocaleChannel(pkg, locale, path, orig) {
- for each (let locale in [locale, "en-US"])
- for each (let sep in "-/") {
- var channel = Channel(["resource:/", pkg + sep + locale, path].join("/"), orig, true);
+ for (let locale of [locale, "en-US"])
+ for (let sep of "-/") {
+ var channel = Channel(["resource:/", pkg + sep + locale, path].join("/"), orig, true, true);
if (channel)
return channel;
}
this.channel.contentType = contentType || channel.contentType;
this.channel.contentCharset = "UTF-8";
if (!unprivileged)
- this.channel.owner = systemPrincipal;
-
- let stream = services.InputStream(channelStream);
- let [, pre, doctype, url, extra, open, post] = util.regexp(<![CDATA[
- ^ ([^]*?)
- (?:
- (<!DOCTYPE \s+ \S+ \s+) (?:SYSTEM \s+ "([^"]*)" | ((?:[^[>\s]|\s[^[])*))
- (\s+ \[)?
- ([^]*)
- )?
- $
- ]]>, "x").exec(stream.read(4096));
- this.writes.push(pre);
- if (doctype) {
- this.writes.push(doctype + (extra || "") + " [\n");
- if (url)
- this.addChannel(url);
-
- if (!open)
- this.writes.push("\n]");
-
- for (let [, pre, url] in util.regexp.iterate(/([^]*?)(?:%include\s+"([^"]*)";|$)/gy, post)) {
- this.writes.push(pre);
+ this.channel.owner = systemPrincipal;
+
+ let type = this.channel.contentType;
+ if (/^text\/|[\/+]xml$/.test(type)) {
+ let stream = services.InputStream(channelStream);
+ let [, pre, doctype, url, extra, open, post] = util.regexp(literal(/*
+ ^ ([^]*?)
+ (?:
+ (<!DOCTYPE \s+ \S+ \s+) (?:SYSTEM \s+ "([^"]*)" | ((?:[^[>\s]|\s[^[])*))
+ (\s+ \[)?
+ ([^]*)
+ )?
+ $
+ */), "x").exec(stream.read(4096));
+ this.writes.push(pre);
+ if (doctype) {
+ this.writes.push(doctype + (extra || "") + " [\n");
if (url)
this.addChannel(url);
+
+ if (!open)
+ this.writes.push("\n]");
+
+ for (let [, pre, url] in util.regexp.iterate(/([^]*?)(?:%include\s+"([^"]*)";|$)/gy, post)) {
+ this.writes.push(pre);
+ if (url)
+ this.addChannel(url);
+ }
}
}
this.writes.push(channelStream);
this.writes.push(services.io.newChannel(url, null, this.uri).open());
}
catch (e) {
+ util.dump("addChannel('" + url + "'):");
util.reportError(e);
}
},
endModule();
-// vim: set fdm=marker sw=4 ts=4 et ft=javascript:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: