From 8d6ea20cc4cd6f0ac0ba9cf8ede77518c5cdaa7f Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 18 Feb 2014 22:38:58 -0800 Subject: [PATCH] Move magical-non-bootstrappable manifest directives to config.json. --- common/bootstrap.js | 47 +++++++++++++++++++---------------------- common/chrome.manifest | 16 -------------- pentadactyl/config.json | 21 ++++++++++++++++++ 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/common/bootstrap.js b/common/bootstrap.js index 29810c0d..664aa14d 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -215,32 +215,28 @@ let JSMLoader = { function init() { debug("bootstrap: init"); - let manifestURI = getURI("chrome.manifest"); - let manifest = httpGet(manifestURI) - .responseText - .replace(/#(resource)#/g, "$1") - .replace(/^\s*|\s*$|#.*/g, "") - .replace(/^\s*\n/gm, ""); + let manifest = JSON.parse(httpGet(getURI("config.json")) + .responseText); - for each (let line in manifest.split("\n")) { - let fields = line.split(/\s+/); - switch (fields[0]) { - case "category": - categoryManager.addCategoryEntry(fields[1], fields[2], fields[3], false, true); - categories.push([fields[1], fields[2]]); - break; - case "component": - components[fields[1]] = new FactoryProxy(getURI(fields[2]).spec, fields[1]); - break; - case "contract": - components[fields[2]].contractID = fields[1]; - break; + if (!manifest.categories) + manifest.categories = []; - case "resource": - moduleName = moduleName || fields[1]; - resources.push(fields[1]); - resourceProto.setSubstitution(fields[1], getURI(fields[2])); - } + for (let [classID, { contract, path, category }] of Iterator(manifest.components || {})) { + components[classID] = new FactoryProxy(getURI(path).spec, classID, contract); + if (category) + manifest.categories.push([category[0], category[1], contract]); + } + + for (let [category, id, value] of manifest.categories) { + categoryManager.addCategoryEntry(category, id, value, + false, true); + categories.push([category, id]); + } + + for (let [pkg, path] in Iterator(manifest.resources || {})) { + moduleName = moduleName || pkg; + resources.push(pkg); + resourceProto.setSubstitution(pkg, getURI(path)); } JSMLoader.config = JSON.parse(httpGet("resource://dactyl-local/config.json").responseText); @@ -381,9 +377,10 @@ function startup(data, reason) { * @param {string} url The URL of the module housing the real factory. * @param {string} classID The CID of the class this factory represents. */ -function FactoryProxy(url, classID) { +function FactoryProxy(url, classID, contractID) { this.url = url; this.classID = Components.ID(classID); + this.contractID = contractID; } FactoryProxy.prototype = { QueryInterface: XPCOMUtils.generateQI(Ci.nsIFactory), diff --git a/common/chrome.manifest b/common/chrome.manifest index fbf90962..b24abc9b 100644 --- a/common/chrome.manifest +++ b/common/chrome.manifest @@ -1,17 +1 @@ -resource dactyl ../common/modules/ -resource dactyl-common ../common/ -resource dactyl-content ../common/content/ -resource dactyl-skin ../common/skin/ -resource dactyl-locale ../common/locale/ - -resource dactyl-local ./ -resource dactyl-local-content content/ -resource dactyl-local-skin skin/ -resource dactyl-local-locale locale/ - content dactyl ../common/content/ - -component {16dc34f7-6d22-4aa4-a67f-2921fb5dcb69} components/commandline-handler.js -contract @mozilla.org/commandlinehandler/general-startup;1?type=dactyl {16dc34f7-6d22-4aa4-a67f-2921fb5dcb69} -category command-line-handler m-dactyl @mozilla.org/commandlinehandler/general-startup;1?type=dactyl - diff --git a/pentadactyl/config.json b/pentadactyl/config.json index 5ba3bdd9..a5850ec3 100644 --- a/pentadactyl/config.json +++ b/pentadactyl/config.json @@ -9,6 +9,27 @@ "resource://dactyl/" ], + "resources": { + "dactyl": "../common/modules/", + "dactyl-common": "../common/", + "dactyl-content": "../common/content/", + "dactyl-skin": "../common/skin/", + "dactyl-locale": "../common/locale/", + + "dactyl-local": "./", + "dactyl-local-content": "content/", + "dactyl-local-skin": "skin/", + "dactyl-local-locale": "locale/" + }, + + "components": { + "{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}": { + "path": "components/commandline-handler.js", + "contract": "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl", + "category": ["command-line-handler", "m-dactyl"] + } + }, + "autocommands": { "BookmarkAdd": "Triggered after a page is bookmarked", "BookmarkChange": "Triggered after a page's bookmark is changed",