1 # This file loads the user config file: config.js and frame.js.
3 createConfigAPI = require('./api')
4 messageManager = require('./message-manager')
5 utils = require('./utils')
6 prefs = require('./prefs')
8 {FileUtils} = ChromeUtils.import('resource://gre/modules/FileUtils.jsm')
10 load = (vimfx, options = null, callback = ->) ->
11 configDir = vimfx.options.config_file_directory
17 scope = {vimfx: createConfigAPI(vimfx, options)}
19 # Calling `vimfx.createKeyTrees()` after each `vimfx.set()` that modifies a
20 # shortcut is absolutely redundant and may make Firefox start slower. Do it
22 vimfx.skipCreateKeyTrees = true
23 error = loadFile(configDir, 'config.js', scope)
24 vimfx.skipCreateKeyTrees = false
25 vimfx.createKeyTrees()
31 messageManager.send('loadConfig', null, callback)
33 sandboxPreventsAccess = (dir) ->
34 expandedDir = utils.expandPath(dir)
36 prefix = 'security.sandbox.content'
37 if prefs.root.get("#{prefix}.level") <= 2
40 if Services.appinfo.OS == 'Darwin'
42 prefs.root.get("#{prefix}.mac.testing_read_path1"),
43 prefs.root.get("#{prefix}.mac.testing_read_path2")
46 whitelisted = prefs.root.get("#{prefix}.read_path_whitelist").split(',')
48 return not whitelisted.some((e) -> e.startsWith(expandedDir))
50 loadFile = (dir, file, scope) ->
51 expandedPath = new FileUtils.File(utils.expandPath(dir))
52 dirUri = Services.io.newFileURI(expandedPath).spec
53 expandedPath.append(file)
54 uri = Services.io.newFileURI(expandedPath).spec
56 Services.scriptloader.loadSubScriptWithOptions(uri, {
57 target: Object.assign({
66 # in e10s Firefox / Firefox Quantum the content process sandbox might
67 # prevent us from accessing frame.js. The error message is incomprehensible
68 # without explanation.
69 if typeof error == 'string' and
70 error.startsWith('Error opening input stream (invalid filename?)') and
71 sandboxPreventsAccess(dir)
72 console.error("VimFx: Error loading #{file} likely due to e10s sandbox")
73 console.info("Please consult VimFx' documentation on config files.")
75 console.error("VimFx: Error loading #{file}", uri, error)