Merge pull request #8377 from electron/sandbox-open-crash
Destroy web contents if new-window event is prevented
This commit is contained in:
commit
9ff1f6bbde
3 changed files with 25 additions and 2 deletions
|
@ -419,9 +419,11 @@ void WebContents::AddNewContents(content::WebContents* source,
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
auto api_web_contents = CreateFrom(isolate(), new_contents);
|
auto api_web_contents = CreateFrom(isolate(), new_contents);
|
||||||
Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
|
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
|
||||||
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
||||||
initial_rect.height());
|
initial_rect.height())) {
|
||||||
|
api_web_contents->DestroyWebContents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* WebContents::OpenURLFromTab(
|
content::WebContents* WebContents::OpenURLFromTab(
|
||||||
|
|
|
@ -1012,6 +1012,23 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('supports calling preventDefault on new-window events', (done) => {
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
sandbox: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const initialWebContents = webContents.getAllWebContents()
|
||||||
|
ipcRenderer.send('prevent-next-new-window', w.webContents.id)
|
||||||
|
w.webContents.once('new-window', () => {
|
||||||
|
assert.deepEqual(webContents.getAllWebContents(), initialWebContents)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'window-open.html'))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -245,3 +245,7 @@ ipcMain.on('create-window-with-options-cycle', (event) => {
|
||||||
const window = new BrowserWindow({show: false, foo: foo})
|
const window = new BrowserWindow({show: false, foo: foo})
|
||||||
event.returnValue = window.id
|
event.returnValue = window.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('prevent-next-new-window', (event, id) => {
|
||||||
|
webContents.fromId(id).once('new-window', event => event.preventDefault())
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue