зеркало из https://github.com/electron/electron.git
fix: <webview> not working in scriptable popups (#19198)
This commit is contained in:
Родитель
e26f366405
Коммит
35294891ae
|
@ -147,8 +147,6 @@ WebContentsPreferences::WebContentsPreferences(
|
||||||
#endif
|
#endif
|
||||||
SetDefaultBoolIfUndefined(options::kOffscreen, false);
|
SetDefaultBoolIfUndefined(options::kOffscreen, false);
|
||||||
|
|
||||||
SetDefaults();
|
|
||||||
|
|
||||||
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
||||||
// this WebContents is also offscreen-rendered.
|
// this WebContents is also offscreen-rendered.
|
||||||
int guest_instance_id = 0;
|
int guest_instance_id = 0;
|
||||||
|
@ -166,7 +164,7 @@ WebContentsPreferences::WebContentsPreferences(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
last_preference_ = preference_.Clone();
|
SetDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContentsPreferences::~WebContentsPreferences() {
|
WebContentsPreferences::~WebContentsPreferences() {
|
||||||
|
@ -178,6 +176,8 @@ void WebContentsPreferences::SetDefaults() {
|
||||||
if (IsEnabled(options::kSandbox)) {
|
if (IsEnabled(options::kSandbox)) {
|
||||||
SetBool(options::kNativeWindowOpen, true);
|
SetBool(options::kNativeWindowOpen, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_preference_ = preference_.Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContentsPreferences::SetDefaultBoolIfUndefined(
|
bool WebContentsPreferences::SetDefaultBoolIfUndefined(
|
||||||
|
|
|
@ -836,6 +836,27 @@ describe('BrowserWindow module', () => {
|
||||||
})
|
})
|
||||||
w.loadFile(path.join(fixtures, 'api', 'native-window-open-native-addon.html'))
|
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) => {
|
it('should inherit the nativeWindowOpen setting in opened windows', (done) => {
|
||||||
w.destroy()
|
w.destroy()
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
const { ipcRenderer } = require('electron')
|
||||||
|
|
||||||
|
window.ipcRenderer = ipcRenderer
|
|
@ -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>
|
|
@ -231,6 +231,12 @@ ipcMain.on('prevent-next-new-window', (event, id) => {
|
||||||
webContents.fromId(id).once('new-window', event => event.preventDefault())
|
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) => {
|
ipcMain.on('set-web-preferences-on-next-new-window', (event, id, key, value) => {
|
||||||
webContents.fromId(id).once('new-window', (event, url, frameName, disposition, options) => {
|
webContents.fromId(id).once('new-window', (event, url, frameName, disposition, options) => {
|
||||||
options.webPreferences[key] = value
|
options.webPreferences[key] = value
|
||||||
|
|
Загрузка…
Ссылка в новой задаче