Merge pull request #8939 from electron/expose-remote-to-sandbox
Expose remote module to sandbox
This commit is contained in:
commit
f71353a4c5
4 changed files with 29 additions and 16 deletions
|
@ -25,13 +25,16 @@ const preloadModules = new Map([
|
|||
['electron', electron]
|
||||
])
|
||||
|
||||
// Fetch the preload script. This needs to be done through the browser process
|
||||
// since we may not have filesystem access in a sandboxed renderer.
|
||||
let preloadSrc = electron.ipcRenderer.sendSync('ELECTRON_BROWSER_READ_FILE', preloadPath)
|
||||
if (preloadSrc.err) {
|
||||
throw new Error(preloadSrc.err)
|
||||
const extraModules = [
|
||||
'fs'
|
||||
]
|
||||
for (let extraModule of extraModules) {
|
||||
preloadModules.set(extraModule, electron.remote.require(extraModule))
|
||||
}
|
||||
|
||||
// Fetch the preload script using the "fs" module proxy.
|
||||
let preloadSrc = preloadModules.get('fs').readFileSync(preloadPath).toString()
|
||||
|
||||
// Pass different process object to the preload script(which should not have
|
||||
// access to things like `process.atomBinding`).
|
||||
const preloadProcess = new events.EventEmitter()
|
||||
|
@ -65,7 +68,7 @@ function preloadRequire (module) {
|
|||
// since browserify won't try to include `electron` in the bundle, falling back
|
||||
// to the `preloadRequire` function above.
|
||||
let preloadWrapperSrc = `(function(require, process, Buffer, global) {
|
||||
${preloadSrc.data}
|
||||
${preloadSrc}
|
||||
})`
|
||||
|
||||
// eval in window scope:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue