diff --git a/components/chrome-data.js b/components/chrome-data.js new file mode 100644 index 00000000..23389c85 --- /dev/null +++ b/components/chrome-data.js @@ -0,0 +1,82 @@ +/* Adds support for data: URIs with chrome privileges + * and fragment identifiers. + * + * "chrome-data:" [; ]* "," [] + * + * By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler. + * + * Licenced under the MIT License, which allows for sublicensing + * under any compatible license, includeing the GNU GPL and the MPL. + */ + +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +const NS_BINDING_ABORTED = 0x804b0002; +const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler; + +const ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + +let channel = Components.classesByID["{61ba33c0-3031-11d3-8cd0-0060b0fc14a3}"] + .getService(Components.interfaces.nsIProtocolHandler) + .newChannel(ioService.newURI("chrome://liberator/content/data", null, null)) + .QueryInterface(Components.interfaces.nsIRequest); +const systemPrincipal = channel.owner; +channel.cancel(NS_BINDING_ABORTED); +delete channel; + +var instance; +function ChromeData() { +} +ChromeData.prototype = { + contractID: "@mozilla.org/network/protocol;1?name=chrome-data", + classID: Components.ID("{c1b67a07-18f7-4e13-b361-2edcc35a5a0d}"), + classDescription: "Data URIs with chrome privileges", + QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProtocolHandler]), + _xpcom_factory: { + createInstance: function(outer, iid) { + if(!instance) + instance = new ChromeData(); + if(outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + return instance.QueryInterface(iid); + } + }, + + scheme: "chrome-data", + defaultPort: -1, + allowPort: function(port, scheme) false, + protocolFlags: nsIProtocolHandler.URI_NORELATIVE + | nsIProtocolHandler.URI_NOAUTH + | nsIProtocolHandler.URI_IS_UI_RESOURCE, + + newURI: function(spec, charset, baseURI) { + var uri = Components.classes["@mozilla.org/network/standard-url;1"] + .createInstance(Components.interfaces.nsIStandardURL) + .QueryInterface(Components.interfaces.nsIURI); + uri.init(1, -1, spec, charset, null); + return uri; + }, + + newChannel: function(uri) { + try + { + if (uri.scheme == this.scheme) { + let newURI = ioService.newURI(uri.spec.replace(/^.*?:\/*(.*)(?:#.*)?/, "data:$1"), null, null); + let channel = ioService.newChannelFromURI(newURI); + channel.owner = systemPrincipal; + channel.originalURI = uri; + return channel; + } + } + catch (e) {} + throw Components.results.NS_ERROR_FAILURE; + } +}; + +var components = [ChromeData]; + +function NSGetModule(compMgr, fileSpec) { + return XPCOMUtils.generateModule(components); +} + diff --git a/content/buffer.js b/content/buffer.js index de559cad..3d338335 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -73,7 +73,7 @@ function Buffer() //{{{ "@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);\n"; const Sheet = new Struct("name", "sites", "css", "ref"); - let cssUri = function (css) "data:text/css," + encodeURI(css); + let cssUri = function (css) "chrome-data:text/css," + encodeURI(css); let userSheets = []; let systemSheets = []; @@ -259,7 +259,7 @@ function Buffer() //{{{ } if (errors.length) { - let err = new Error("", errors[0].sourceName.replace(/^(data:text\/css,).*/, "$1..."), errors[0].lineNumber); + let err = new Error("", errors[0].sourceName.replace(/^(chrome-data:text\/css,).*/, "$1..."), errors[0].lineNumber); err.name = "CSSError" err.message = errors.reduce(function (msg, e) msg + "; " + e.lineNumber + ": " + e.errorMessage, errors.shift().errorMessage); err.echoerr = err.fileName + ":" + err.lineNumber + ": " + err.message; diff --git a/content/completion.js b/content/completion.js index 9d5f8681..5be0c073 100644 --- a/content/completion.js +++ b/content/completion.js @@ -410,7 +410,7 @@ function Completion() //{{{ let end = (frame == -1 ? lastIdx : get(frame + 1)[OFFSET]); cacheKey = null; - let obj = [liberator, window]; // Default objects; + let obj = [modules, window]; // Default objects; /* Is this an object dereference? */ if (dot < statement) // No. dot = statement - 1; diff --git a/content/io.js b/content/io.js index 62b5fcf9..45f1f4d7 100644 --- a/content/io.js +++ b/content/io.js @@ -798,8 +798,11 @@ lookup: } catch (e) { - e.echoerr = file.path + ":" + e.lineNumber + ": " + e; - throw e; + let err = new Error(); + for (let [k, v] in Iterator(e)) + err[k] = v; + err.echoerr = file.path + ":" + e.lineNumber + ": " + e; + throw err; } } else if (/\.css$/.test(filename)) diff --git a/content/ui.js b/content/ui.js index 551245b6..e49447a6 100644 --- a/content/ui.js +++ b/content/ui.js @@ -621,6 +621,8 @@ function CommandLine() //{{{ var focused = document.commandDispatcher.focusedElement; if (focused && focused == commandWidget.inputField || focused == multilineInputWidget.inputField) return false; + if (silent) + return false; highlightGroup = highlightGroup || this.HL_NORMAL;