Skip to content

Commit

Permalink
fix: emit process 'loaded' event in sandboxed renderers (#17807)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored and codebytere committed Apr 16, 2019
1 parent d6ba142 commit 66c5a83
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions atom/renderer/atom_sandboxed_renderer_client.cc
Expand Up @@ -232,6 +232,8 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
// Execute the function with proper arguments
ignore_result(
func->Call(context, v8::Null(isolate), node::arraysize(args), args));

InvokeIpcCallback(context, "onLoaded", std::vector<v8::Local<v8::Value>>());
}

void AtomSandboxedRendererClient::WillReleaseScriptContext(
Expand Down
5 changes: 5 additions & 0 deletions lib/sandboxed_renderer/init.js
Expand Up @@ -58,6 +58,10 @@ ipcNative.onMessage = function (channel, args, senderId) {
electron.ipcRenderer.emit(channel, { sender: electron.ipcRenderer, senderId }, ...args)
}

ipcNative.onLoaded = function () {
process.emit('loaded')
}

ipcNative.onExit = function () {
process.emit('exit')
}
Expand Down Expand Up @@ -90,6 +94,7 @@ Object.assign(preloadProcess, processProps)
Object.assign(process, binding.process)
Object.assign(process, processProps)

process.on('loaded', () => preloadProcess.emit('loaded'))
process.on('exit', () => preloadProcess.emit('exit'))

// This is the `require` function that will be visible to the preload script
Expand Down
13 changes: 13 additions & 0 deletions spec/api-browser-window-spec.js
Expand Up @@ -1527,6 +1527,19 @@ describe('BrowserWindow module', () => {
w.loadFile(path.join(fixtures, 'api', 'preload.html'))
})

it('exposes "loaded" event to preload script', function (done) {
w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload
}
})
ipcMain.once('process-loaded', () => done())
w.loadURL('about:blank')
})

it('exposes "exit" event to preload script', function (done) {
w.destroy()
w = new BrowserWindow({
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/module/preload-sandbox.js
Expand Up @@ -4,6 +4,11 @@
window.ipcRenderer = ipcRenderer
window.setImmediate = setImmediate
window.require = require

process.once('loaded', () => {
ipcRenderer.send('process-loaded')
})

if (location.protocol === 'file:') {
window.test = 'preload'
window.process = process
Expand Down

0 comments on commit 66c5a83

Please sign in to comment.