From c9bdbe33912efdef4bac3b32f68ec3ab6a76ac27 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 2 Feb 2011 11:14:10 -0500 Subject: [PATCH] Replace horrible chrome-data URLs with somewhat more comprehensible dactyl://style/ URLs. --- common/components/protocols.js | 11 ++++++++++- common/modules/config.jsm | 30 ++++++++++++++++-------------- common/modules/styles.jsm | 27 +++++++++++++++++++-------- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/common/components/protocols.js b/common/components/protocols.js index 87914ac1..8400e238 100644 --- a/common/components/protocols.js +++ b/common/components/protocols.js @@ -37,6 +37,9 @@ function makeChannel(url, orig) { if (typeof url === "function") return let ([type, data] = url()) StringChannel(data, type, orig); + if (isArray(url)) + return let ([type, data] = url) StringChannel(data, type, orig); + let uri = ioService.newURI(url, null, null); return (new XMLChannel(uri)).channel; } @@ -114,6 +117,7 @@ function Dactyl() { this.OVERLAY_MAP = {}; this.pages = {}; + this.providers = {}; Cu.import("resource://dactyl/bootstrap.jsm"); if (!JSMLoader.initialized) @@ -162,6 +166,9 @@ Dactyl.prototype = { if (/^help/.test(uri.host) && !("all" in this.FILE_MAP)) return redirect(uri.spec, uri, 1); + if (uri.host in this.providers) + return makeChannel(this.providers[uri.host](uri), uri); + let path = decodeURIComponent(uri.path.replace(/^\/|#.*/g, "")); switch(uri.host) { case "content": @@ -182,7 +189,9 @@ Dactyl.prototype = { return makeChannel(["resource://dactyl-local-locale", config.locale, path].join("/"), uri); } } - catch (e) {} + catch (e) { + util.reportError(e); + } return fakeChannel(uri); }, diff --git a/common/modules/config.jsm b/common/modules/config.jsm index f0db5d5e..5175c92b 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -13,7 +13,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("config", { exports: ["ConfigBase", "Config", "config"], require: ["highlight", "services", "storage", "util", "template"], - use: ["io"] + use: ["highlight", "io"] }, this); var ConfigBase = Class("ConfigBase", { @@ -23,19 +23,21 @@ var ConfigBase = Class("ConfigBase", { */ init: function init() { - highlight.styleableChrome = this.styleableChrome; - highlight.loadCSS(this.CSS); - highlight.loadCSS(this.helpCSS); - if (!util.haveGecko("2b")) - highlight.loadCSS(); + this.timeout(function () { + highlight.styleableChrome = this.styleableChrome; + highlight.loadCSS(this.CSS); + highlight.loadCSS(this.helpCSS); + if (!util.haveGecko("2b")) + highlight.loadCSS(); + }); this.features.push = deprecated("set.add", function push(feature) set.add(this, feature)); if (util.haveGecko("2b")) diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 91864533..252c36ef 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -38,23 +38,22 @@ update(Sheet.prototype, { remove: function () { this.hive.remove(this); }, - get uri() cssUri(this.fullCSS), + get uri() "dactyl://style/" + this.id + "/" + this.hive.name + "/" + (this.name || ""), get enabled() this._enabled, set enabled(on) { - if (on != this._enabled || this.uri != this._uri) { + if (on != this._enabled || this.fullCSS != this._fullCSS) { if (on) this.enabled = false; else if (!this._uri) return; let meth = on ? "registerSheet" : "unregisterSheet"; - styles[meth](on ? this.uri : this._uri, - on ? this.agent : this._agent); + styles[meth](this.uri, on ? this.agent : this._agent); this._agent = this.agent; this._enabled = Boolean(on); - this._uri = this.uri; + this._fullCSS = this.fullCSS; } }, @@ -82,7 +81,8 @@ update(Sheet.prototype, { }); var Hive = Class("Hive", { - init: function () { + init: function (name) { + this.name = name; this.sheets = []; this.names = {}; }, @@ -125,6 +125,8 @@ var Hive = Class("Hive", { this.sheets.push(sheet); } + styles.allSheets[sheet.id] = sheet; + if (!lazy) sheet.enabled = true; @@ -208,6 +210,7 @@ var Hive = Class("Hive", { sheet.enabled = false; if (sheet.name) delete this.names[sheet.name]; + delete styles.allSheets[sheet.id]; } this.sheets = this.sheets.filter(function (s) matches.indexOf(s) == -1); return matches.length; @@ -224,8 +227,16 @@ try { var Styles = Module("Styles", { init: function () { this._id = 0; - this.user = Hive(); - this.system = Hive(); + this.user = Hive("user"); + this.system = Hive("system"); + this.allSheets = {}; + + services["dactyl:"].providers["style"] = function styleProvider(uri) { + let id = /^\/(\d*)/.exec(uri.path)[1]; + if (set.has(styles.allSheets, id)) + return ["text/css", styles.allSheets[id].fullCSS]; + return null; + }; }, cleanup: function cleanup() {