blob: 81a4061e725ce6a8fe3b92a9bfa30a47a8c95793 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
|