summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@gnu.org>2015-11-28 15:24:36 -0600
committerRuben Rodriguez <ruben@gnu.org>2015-11-28 16:27:06 -0600
commite4a3586a14996bbece3b26c9e3b7704ea6af8615 (patch)
tree499bdd16b3a90c30b01e4b47a5882d13b4800f50 /data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme
parent4dbc2fae927bb02ef243c87938e638af9afee8fa (diff)
LibreJS upgraded to 6.0.10
Diffstat (limited to 'data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme')
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/about.js84
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/resource.js43
2 files changed, 127 insertions, 0 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/about.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/about.js
new file mode 100644
index 0000000..7d94b78
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/about.js
@@ -0,0 +1,84 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { Cr, Cu, Ci, Cc, Cm } = require('chrome');
+const { when: unload } = require('sdk/system/unload');
+const { validateOptions : validate } = require('sdk/deprecated/api-utils');
+const { uuid } = require('sdk/util/uuid');
+const { URL, isValidURI } = require('sdk/url');
+const tabs = require('sdk/tabs');
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const validOptions = {
+ what: {
+ is: ['string'],
+ ok: function(what) {
+ if (what.match(/^[a-z0-9-]+$/i))
+ return true;
+ return false;
+ },
+ map: function(url) url.toLowerCase()
+ },
+ url: {
+ map: function(url) url.toString(),
+ ok: isValidURI
+ },
+ useChrome: {
+ is: ['undefined', 'null', 'boolean'],
+ map: function(use) !!use
+ }
+};
+
+function add(options) {
+ let { what, url, useChrome } = validate(options, validOptions);
+ let classID = uuid();
+
+ let aboutModule = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
+ newChannel: function (aURI) {
+ let chan = Services.io.newChannel(url, null, null);
+ if (useChrome)
+ chan.owner = Services.scriptSecurityManager.getSystemPrincipal();
+ return chan;
+ },
+ getURIFlags: function () Ci.nsIAboutModule.ALLOW_SCRIPT
+ };
+
+ let factory = {
+ createInstance: function(aOuter, aIID) {
+ if (aOuter)
+ throw Cr.NS_ERROR_NO_AGGREGATION;
+ return aboutModule.QueryInterface(aIID);
+ },
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
+ };
+
+ // register about:what
+ Cm.QueryInterface(Ci.nsIComponentRegistrar).
+ registerFactory(classID, '', '@mozilla.org/network/protocol/about;1?what='+what, factory);
+
+ let remover = unloader.bind(null, what, factory, classID);
+ unload(remover);
+
+ return undefined;
+}
+exports.add = add;
+
+function unloader(what, factory, classID) {
+ // unregister about:what
+ Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory(classID, factory);
+ let regEx = new RegExp('^' + what, 'i');
+
+ // AMO policy, see http://maglione-k.users.sourceforge.net/bootstrapped.xhtml
+ // close about:what tabs
+ for each (let tab in tabs) {
+ let url = URL(tab.url);
+ if (url.scheme === 'about' && url.path.match(regEx)) {
+ tab.close();
+ }
+ }
+}
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/resource.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/resource.js
new file mode 100644
index 0000000..81a4061
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scheme/resource.js
@@ -0,0 +1,43 @@
+/*jshint asi:true globalstrict:true*/
+'use strict';
+
+const { Cc, Ci } = require('chrome')
+const ioService = Cc['@mozilla.org/network/io-service;1'].
+ getService(Ci.nsIIOService);
+const resourceHandler = ioService.getProtocolHandler('resource').
+ QueryInterface(Ci.nsIResProtocolHandler)
+
+function get(root) {
+ /**
+ Gets the substitution for the `root` key.
+ **/
+ try {
+ return resourceHandler.getSubstitution(root).spec;
+ }
+ catch (error) {}
+ return null;
+}
+exports.get = get;
+
+function has(root) {
+ /**
+ Returns `true` if the substitution exists and `false` otherwise.
+ **/
+ return resourceHandler.hasSubstitution(root);
+}
+exports.has = has;
+
+function set(root, uri) {
+ /**
+ Sets the substitution for the root key:
+
+ resource://root/path ==> baseURI.resolve(path)
+
+ A `null` `uri` removes substitution. A root key should
+ always be lowercase. However, this may not be enforced.
+ **/
+ uri = !uri ? null :
+ uri instanceof Ci.nsIURI ? uri : ioService.newURI(uri, null, null);
+ resourceHandler.setSubstitution(root, uri);
+}
+exports.set = set;