Inherit enabled-sandbox in opened windows

This commit is contained in:
Kevin Sawicki 2017-07-10 16:23:04 -07:00
parent c71b0a5441
commit 86b1deedfa
3 changed files with 25 additions and 6 deletions

View file

@ -13,6 +13,7 @@ const inheritedWebPreferences = new Map([
['javascript', false], ['javascript', false],
['nativeWindowOpen', true], ['nativeWindowOpen', true],
['nodeIntegration', false], ['nodeIntegration', false],
['sandbox', true],
['webviewTag', false] ['webviewTag', false]
]) ])

View file

@ -1066,6 +1066,24 @@ describe('BrowserWindow module', function () {
}) })
}) })
it('should inherit the sandbox setting in opened windows', function (done) {
w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
})
const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js')
ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath)
ipcMain.once('answer', (event, args) => {
assert.equal(args.includes('--enable-sandbox'), true)
done()
})
w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`)
})
it('should open windows with the options configured via new-window event listeners', function (done) { it('should open windows with the options configured via new-window event listeners', function (done) {
w.destroy() w.destroy()
w = new BrowserWindow({ w = new BrowserWindow({
@ -1077,10 +1095,10 @@ describe('BrowserWindow module', function () {
const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js') const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js')
ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath) ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath)
ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'sandbox', true) ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'foo', 'bar')
ipcMain.once('answer', (event, args) => { ipcMain.once('answer', (event, args, webPreferences) => {
assert.ok(args.includes('--enable-sandbox')) assert.equal(args.includes('--enable-sandbox'), true)
assert.ok(args.includes(`--preload=${path.join(fixtures, 'api', 'new-window-preload.js')}`)) assert.equal(webPreferences.foo, 'bar')
done() done()
}) })
w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`) w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`)

View file

@ -1,4 +1,4 @@
const {ipcRenderer} = require('electron') const {ipcRenderer, remote} = require('electron')
ipcRenderer.send('answer', process.argv) ipcRenderer.send('answer', process.argv, remote.getCurrentWindow().webContents.getWebPreferences())
window.close() window.close()