8000 fix: emit IPC event in correct context if isolation and sandbox enabled (backport: 4-0-x) by trop[bot] · Pull Request #16376 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: emit IPC event in correct context if isolation and sandbox enabled (backport: 4-0-x) #16376

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion atom/renderer/atom_sandboxed_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be creating Cannot get property 'TMPDIR' on missing remote object 59 when trying to access object through electron.remote now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsabanin This change only landed 12 days ago and has only been released in 5.0. The error you quote there wouldn't be caused by this PR afaik

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look!

v8::Context::Scope context_scope(context);

v8::Local<v8::Value> argv[] = {mate::ConvertToV8(isolate, channel),
mate::ConvertToV8(isolate, args),
mate::ConvertToV8(isolate, sender_id)};
Expand Down
83 changes: 37 additions & 46 deletions spec/api-ipc-renderer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,63 +139,54 @@ describe('ipc renderer module', () => {
contents = null
})

it('sends message to WebContents', done => {
contents = webContents.create({
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js')
})

const payload = 'Hello World!'

ipcRenderer.once('pong', (event, data) => {
expect(payload).to.equal(data)
done()
})

contents.once('did-finish-load', () => {
ipcRenderer.sendTo(contents.id, 'ping', payload)
})

contents.loadFile(path.join(fixtures, 'pages', 'ping-pong.html'))
})
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
})

it('sends message to WebContents (sanboxed renderer)', done => {
contents = webContents.create({
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js'),
sandbox: true
})
const payload = 'Hello World!'

const payload = 'Hello World!'
ipcRenderer.once('pong', (event, data) => {
expect(payload).to.equal(data)
done()
})

ipcRenderer.once('pong', (event, data) => {
expect(payload).to.equal(data)
done()
})
contents.once('did-finish-load', () => {
ipcRenderer.sendTo(contents.id, 'ping', payload)
})

contents.once('did-finish-load', () => {
ipcRenderer.sendTo(contents.id, 'ping', payload)
})
contents.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
})

contents.loadFile(path.join(fixtures, 'pages', 'ping-pong.html'))
})
it('sends message to WebContents (channel has special chars)', done => {
contents = webContents.create({
preload: path.join(fixtures, 'module', 'preload-ipc-ping-pong.js'),
...webPreferences
})

it('sends message to WebContents (channel has special chars)', done => {
contents = webContents.create({
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js')
})
const payload = 'Hello World!'

const payload = 'Hello World!'
ipcRenderer.once('pong-æøåü', (event, data) => {
expect(payload).to.equal(data)
done()
})

ipcRenderer.once('pong-æøåü', (event, data) => {
expect(payload).to.equal(data)
done()
})
contents.once('did-finish-load', () => {
ipcRenderer.sendTo(contents.id, 'ping-æøåü', payload)
})

contents.once('did-finish-load', () => {
ipcRenderer.sendTo(contents.id, 'ping-æøåü', payload)
contents.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
})
})
}

contents.loadFile(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', () => {
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/module/preload-inject-ipc.js

This file was deleted.

9 changes: 9 additions & 0 deletions spec/fixtures/module/preload-ipc-ping-pong.js
7A0B
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { ipcRenderer } = require('electron')

ipcRenderer.on('ping', function (event, payload) {
ipcRenderer.sendTo(event.senderId, 'pong', payload)
})

ipcRenderer.on('ping-æøåü', function (event, payload) {
ipcRenderer.sendTo(event.senderId, 'pong-æøåü', payload)
})
12 changes: 0 additions & 12 deletions spec/fixtures/pages/ping-pong.html

This file was deleted.

0