mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* fix: emit IPC event in correct context if isolation and sandbox enabled IPC events were not being delivered to renderer processes when both `contextIsolation` and `sandbox` were enabled. This is because the `AtomSandboxedRenderFrameObserver` class was incorrectly using the `MainWorldScriptContext`, rather than conditionally selecting the context based on if isolation was enabled. Fixes #11922
This commit is contained in:
committed by
Charles Kerr
parent
93655d67b3
commit
516233c0da
@@ -125,8 +125,10 @@ class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {
|
||||
|
||||
auto* isolate = blink::MainThreadIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto context = frame->MainWorldScriptContext();
|
||||
|
||||
auto context = renderer_client_->GetContext(frame, isolate);
|
||||
v8::Context::Scope context_scope(context);
|
||||
|
||||
v8::Local<v8::Value> argv[] = {mate::ConvertToV8(isolate, channel),
|
||||
mate::ConvertToV8(isolate, args)};
|
||||
renderer_client_->InvokeIpcCallback(
|
||||
|
||||
@@ -140,20 +140,35 @@ describe('ipc renderer module', () => {
|
||||
contents = null
|
||||
})
|
||||
|
||||
it('sends message to WebContents', done => {
|
||||
const webContentsId = remote.getCurrentWebContents().id
|
||||
const generateSpecs = (description, webPreferences) => {
|
||||
describe(description, () => {
|
||||
it('sends message to WebContents', done => {
|
||||
contents = webContents.create({
|
||||
preload: path.join(fixtures, 'module', 'preload-ipc-ping-pong.js'),
|
||||
...webPreferences
|
||||
})
|
||||
|
||||
ipcRenderer.once('pong', (event, id) => {
|
||||
expect(webContentsId).to.equal(id)
|
||||
done()
|
||||
const payload = 'Hello World!'
|
||||
const webContentsId = remote.getCurrentWebContents().id
|
||||
|
||||
ipcRenderer.once('pong', (event, data) => {
|
||||
expect(payload).to.equal(data)
|
||||
done()
|
||||
})
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping', webContentsId, payload)
|
||||
})
|
||||
|
||||
contents.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping', webContentsId)
|
||||
})
|
||||
|
||||
contents.loadURL(`file://${path.join(fixtures, 'pages', 'ping-pong.html')}`)
|
||||
})
|
||||
generateSpecs('without sandbox', {})
|
||||
generateSpecs('with sandbox', { sandbox: true })
|
||||
generateSpecs('with contextIsolation', { contextIsolation: true })
|
||||
generateSpecs('with contextIsolation + sandbox', { contextIsolation: true, sandbox: true })
|
||||
})
|
||||
|
||||
describe('remote listeners', () => {
|
||||
|
||||
2
spec/fixtures/module/preload-inject-ipc.js
vendored
2
spec/fixtures/module/preload-inject-ipc.js
vendored
@@ -1,2 +0,0 @@
|
||||
const {ipcRenderer} = require('electron')
|
||||
window.ipcRenderer = ipcRenderer
|
||||
5
spec/fixtures/module/preload-ipc-ping-pong.js
vendored
Normal file
5
spec/fixtures/module/preload-ipc-ping-pong.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
ipcRenderer.on('ping', function (event, senderId, payload) {
|
||||
ipcRenderer.sendTo(senderId, 'pong', payload)
|
||||
})
|
||||
11
spec/fixtures/pages/ping-pong.html
vendored
11
spec/fixtures/pages/ping-pong.html
vendored
@@ -1,11 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const {ipcRenderer} = require('electron')
|
||||
ipcRenderer.on('ping', function (event, id) {
|
||||
ipcRenderer.sendTo(id, 'pong', id)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user