]> git.gir.st - VimFx.git/blob - extension/lib/workarounds.coffee
wip workarounds 2
[VimFx.git] / extension / lib / workarounds.coffee
1 # coffeelint: disable=colon_assignment_spacing
2 # coffeelint: disable=no_implicit_braces
3
4 config = require('./config')
5 help = require('./help')
6 prefs = require('./prefs')
7 utils = require('./utils')
8 vimfx = require('./vimfx')
9
10 sandbox = 'security.sandbox.content'
11
12 workarounds = [
13 {
14 name: 'Devtools stuck in normal mode'
15 desc: 'When blurring and refocusing the devtools, VimFx will not enter
16 ignore mode when focusing an input element. This workarounds sets
17 devtools.toolbox.content-frame to false.'
18 regressed_by: [1539979]
19 more_info: ['http://bugzil.la/1585747'] # bug we rely on to be open
20 is_applied: -> prefs.root.get('devtools.toolbox.content-frame') == false
21 is_required: ->
22 Cu.importGlobalProperties(['XMLHttpRequest'])
23 xhr = new XMLHttpRequest() # using XHR, as we need result synchronously
24 xhr.open(
25 'GET', 'resource://devtools/client/framework/toolbox-hosts.js', false
26 )
27 xhr.overrideMimeType('text/plain') # prevent non-fatal 'XML Parsing Error'
28 xhr.send()
29 return xhr.response.includes('devtools.toolbox.content-frame')
30 apply: -> prefs.root.set('devtools.toolbox.content-frame', false)
31 undo: -> prefs.root.set('devtools.toolbox.content-frame', null)
32 restart: false
33 },
34 {
35 name: 'frame.js needs sandbox whitelisting'
36 desc: 'The browser is preventing access to the config script. This
37 workaround will add it to the read-only whitelist
38 (security.sandbox.content.read_path_whitelist on non-OSX systems or
39 security.sandbox.content.mac.testing_read_path1 or 2 on OSX).'
40 regressed_by: [1288874]
41 # coffeelint: disable=max_line_length
42 more_info: ["#{vimfx.info?.homepageURL}/tree/master/documentation/config-file.md#on-process-sandboxing"]
43 # coffeelint: enable=max_line_length
44 is_applied: ->
45 dir = prefs.get('config_file_directory')
46 return true unless dir
47 dir = utils.expandPath(dir)
48 return not config.checkSandbox(dir)
49 is_required: ->
50 prefs.get('config_file_directory') != '' and
51 prefs.root.get("#{sandbox}.level") > 2
52 apply: ->
53 dir = prefs.get('config_file_directory')
54 return unless dir
55 seperator = if Services.appinfo.OS == 'WINNT' then '\\' else '/'
56 dir = utils.expandPath(dir) + seperator
57 if Services.appinfo.OS == 'Darwin'
58 if not prefs.root.get("#{sandbox}.mac.testing_read_path1")?
59 prefs.root.set("#{sandbox}.mac.testing_read_path1", dir)
60 else if not prefs.root.get("#{sandbox}.mac.testing_read_path2")?
61 prefs.root.set("#{sandbox}.mac.testing_read_path2", dir)
62 else
63 console.error('all whitelist prefs occupied, refusing to overwrite.')
64 else
65 val = prefs.root.get("#{sandbox}.read_path_whitelist").split(',')
66 val = val.filter((e) -> e != '')
67 val.push(dir)
68 prefs.root.set("#{sandbox}.read_path_whitelist", val.join(','))
69 undo: ->
70 dir = prefs.get('config_file_directory')
71 return unless dir
72 dir = utils.expandPath(dir)
73 if Services.appinfo.OS == 'Darwin'
74 if prefs.root.get("#{sandbox}.mac.testing_read_path1")?.startsWith(dir)
75 prefs.root.set("#{sandbox}.mac.testing_read_path1", null)
76 if prefs.root.get("#{sandbox}.mac.testing_read_path2")?.startsWith(dir)
77 prefs.root.set("#{sandbox}.mac.testing_read_path2", null)
78 else
79 val = prefs.root.get("#{sandbox}.read_path_whitelist").split(',')
80 val = val.filter((e) -> not e.startsWith(dir))
81 prefs.root.set("#{sandbox}.read_path_whitelist", val.join(','))
82 restart: true
83 },
84 {
85 name: 'Fission is enabled'
86 desc: 'VimFx is not fission compatible. This workaround flips the
87 fission.autostart pref off.'
88 regressed_by: []
89 more_info: ['http://bugzil.la/fission']
90 is_applied: -> prefs.root.get('fission.autostart') == false
91 is_required: -> prefs.root.get('fission.autostart') == true
92 apply: -> prefs.root.set('fission.autostart', false)
93 undo: -> prefs.root.set('fission.autostart', null)
94 restart: true
95 },
96 ]
97
98 askUser = ->
99 utils.showPopupNotification(
100 'vimfx-require-workaround',
101 'VimFx needs to apply some about:config changes to function properly',
102 {
103 'label':'Apply automatically',
104 'accessKey': 'A',
105 'callback': ()=>{}
106 }, [{
107 'label':'See details',
108 'accessKey': 'S',
109 'callback': ()->
110 window = Services.wm.getMostRecentWindow('navigator:browser')
111 help.goToCommandSetting(window, vimfx, 'category.workaround')
112 }, {
113 'label':'Ignore',
114 'accessKey': 'I',
115 'callback': ()=>{}
116 }]
117 )
118
119 module.exports = {
120 askUser
121 workarounds
122 }
Imprint / Impressum