feat: emit process 'loaded' event in sandboxed renderers (#17680)
This commit is contained in:
parent
127b87c713
commit
77d59e99b6
4 changed files with 25 additions and 4 deletions
|
@ -226,6 +226,10 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
|
|||
node::per_process::native_module_loader.CompileAndCall(
|
||||
isolate->GetCurrentContext(), "electron/js2c/preload_bundle",
|
||||
&preload_bundle_params, &preload_bundle_args, nullptr);
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Context::Scope context_scope(context);
|
||||
InvokeHiddenCallback(context, kLifecycleKey, "onLoaded");
|
||||
}
|
||||
|
||||
void AtomSandboxedRendererClient::SetupMainWorldOverrides(
|
||||
|
|
|
@ -56,6 +56,9 @@ v8Util.setHiddenValue(global, 'ipcNative', {
|
|||
|
||||
// AtomSandboxedRendererClient will look for the "lifecycle" hidden object when
|
||||
v8Util.setHiddenValue(global, 'lifecycle', {
|
||||
onLoaded () {
|
||||
process.emit('loaded')
|
||||
},
|
||||
onExit () {
|
||||
process.emit('exit')
|
||||
},
|
||||
|
@ -89,6 +92,7 @@ Object.defineProperty(preloadProcess, 'noDeprecation', {
|
|||
}
|
||||
})
|
||||
|
||||
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
|
||||
|
|
|
@ -1568,7 +1568,6 @@ describe('BrowserWindow module', () => {
|
|||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
sandbox: true,
|
||||
preload
|
||||
}
|
||||
|
@ -1586,7 +1585,6 @@ describe('BrowserWindow module', () => {
|
|||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
sandbox: true,
|
||||
preload: preloadSpecialChars
|
||||
}
|
||||
|
@ -1594,12 +1592,24 @@ 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({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
sandbox: true,
|
||||
preload
|
||||
}
|
||||
|
@ -1622,7 +1632,6 @@ describe('BrowserWindow module', () => {
|
|||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
sandbox: true,
|
||||
preload
|
||||
}
|
||||
|
|
4
spec/fixtures/module/preload-sandbox.js
vendored
4
spec/fixtures/module/preload-sandbox.js
vendored
|
@ -13,6 +13,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
process.once('loaded', () => {
|
||||
ipcRenderer.send('process-loaded')
|
||||
})
|
||||
|
||||
if (location.protocol === 'file:') {
|
||||
window.test = 'preload'
|
||||
window.process = process
|
||||
|
|
Loading…
Reference in a new issue