Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit process 'loaded' event in sandboxed renderers #17807

Merged
merged 1 commit into from Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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