Skip to content

Commit

Permalink
fix: <webview> not working in scriptable popups
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored and Milan Burda committed Jul 11, 2019
1 parent 8e68e6e commit 7164824
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions atom/browser/web_contents_preferences.cc
Expand Up @@ -146,8 +146,6 @@ WebContentsPreferences::WebContentsPreferences(
SetDefaultBoolIfUndefined(options::kOffscreen, false);

SetDefaults();

last_preference_ = preference_.Clone();
}

WebContentsPreferences::~WebContentsPreferences() {
Expand All @@ -159,6 +157,8 @@ void WebContentsPreferences::SetDefaults() {
if (IsEnabled(options::kSandbox)) {
SetBool(options::kNativeWindowOpen, true);
}

last_preference_ = preference_.Clone();
}

bool WebContentsPreferences::SetDefaultBoolIfUndefined(
Expand Down
21 changes: 21 additions & 0 deletions spec/api-browser-window-spec.js
Expand Up @@ -2034,6 +2034,27 @@ describe('BrowserWindow module', () => {
})
w.loadFile(path.join(fixtures, 'api', 'native-window-open-native-addon.html'))
})
it('<webview> works in a scriptable popup', (done) => {
const preload = path.join(fixtures, 'api', 'new-window-webview-preload.js')

w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegrationInSubFrames: true,
nativeWindowOpen: true,
webviewTag: true,
preload
}
})

ipcRenderer.send('set-options-on-next-new-window', w.webContents.id, 'show', false)

ipcMain.once('webview-loaded', () => {
done()
})
w.loadFile(path.join(fixtures, 'api', 'new-window-webview.html'))
})
it('should inherit the nativeWindowOpen setting in opened windows', (done) => {
w.destroy()
w = new BrowserWindow({
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/api/new-window-webview-preload.js
@@ -0,0 +1,3 @@
const { ipcRenderer } = require('electron')

window.ipcRenderer = ipcRenderer
20 changes: 20 additions & 0 deletions spec/fixtures/api/new-window-webview.html
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
const code = `
var webview = document.createElement('webview')
webview.src = 'about:blank'
webview.addEventListener('did-finish-load', () => {
ipcRenderer.send('webview-loaded')
}, {once: true})
document.body.appendChild(webview)
`
open('about:blank').eval(code)
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions spec/static/main.js
Expand Up @@ -340,6 +340,12 @@ ipcMain.on('prevent-next-new-window', (event, id) => {
webContents.fromId(id).once('new-window', event => event.preventDefault())
})

ipcMain.on('set-options-on-next-new-window', (event, id, key, value) => {
webContents.fromId(id).once('new-window', (event, url, frameName, disposition, options) => {
options[key] = value
})
})

ipcMain.on('set-web-preferences-on-next-new-window', (event, id, key, value) => {
webContents.fromId(id).once('new-window', (event, url, frameName, disposition, options) => {
options.webPreferences[key] = value
Expand Down

0 comments on commit 7164824

Please sign in to comment.