chore: remove disable_user_gesture... patch (#23066)
This commit is contained in:
parent
e4c82fdf2d
commit
2541d62486
6 changed files with 125 additions and 93 deletions
|
@ -12,7 +12,6 @@ render_widget_host_view_base.patch
|
||||||
render_widget_host_view_mac.patch
|
render_widget_host_view_mac.patch
|
||||||
thread_capabilities.patch
|
thread_capabilities.patch
|
||||||
webview_cross_drag.patch
|
webview_cross_drag.patch
|
||||||
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
|
|
||||||
gin_enable_disable_v8_platform.patch
|
gin_enable_disable_v8_platform.patch
|
||||||
blink-worker-enable-csp-in-file-scheme.patch
|
blink-worker-enable-csp-in-file-scheme.patch
|
||||||
disable-redraw-lock.patch
|
disable-redraw-lock.patch
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Aleksei Kuzmin <alkuzmin@microsoft.com>
|
|
||||||
Date: Thu, 20 Sep 2018 17:47:33 -0700
|
|
||||||
Subject: disable_user_gesture_requirement_for_beforeunload_dialogs.patch
|
|
||||||
|
|
||||||
See https://github.com/electron/electron/issues/10754
|
|
||||||
|
|
||||||
diff --git a/third_party/blink/renderer/core/dom/document.cc b/third_party/blink/renderer/core/dom/document.cc
|
|
||||||
index 002633988171955abfa7418dddbaea10dcd99981..4be5be505bd658666f0189e4ec2ab132fc0dde32 100644
|
|
||||||
--- a/third_party/blink/renderer/core/dom/document.cc
|
|
||||||
+++ b/third_party/blink/renderer/core/dom/document.cc
|
|
||||||
@@ -4157,7 +4157,9 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
|
|
||||||
"frame that never had a user gesture since its load. "
|
|
||||||
"https://www.chromestatus.com/feature/5082396709879808";
|
|
||||||
Intervention::GenerateReport(frame_, "BeforeUnloadNoGesture", message);
|
|
||||||
- return true;
|
|
||||||
+ // TODO(alexeykuzmin): Uncomment `return true` when Electron tests are fixed.
|
|
||||||
+ // See https://github.com/electron/electron/issues/10754
|
|
||||||
+ // return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (did_allow_navigation) {
|
|
|
@ -185,7 +185,8 @@ describe('BrowserWindow module', () => {
|
||||||
expect(content).to.equal('close');
|
expect(content).to.equal('close');
|
||||||
});
|
});
|
||||||
it('should emit beforeunload event', async () => {
|
it('should emit beforeunload event', async () => {
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
||||||
|
w.webContents.executeJavaScript('run()', true);
|
||||||
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
e.returnValue = null;
|
e.returnValue = null;
|
||||||
});
|
});
|
||||||
|
@ -2590,7 +2591,8 @@ describe('BrowserWindow module', () => {
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-undefined.html'));
|
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-undefined.html'));
|
||||||
});
|
});
|
||||||
it('returning false would prevent close', async () => {
|
it('returning false would prevent close', async () => {
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
||||||
|
w.webContents.executeJavaScript('run()', true);
|
||||||
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
e.returnValue = null;
|
e.returnValue = null;
|
||||||
});
|
});
|
||||||
|
@ -2598,57 +2600,103 @@ describe('BrowserWindow module', () => {
|
||||||
ipcMain.once('onbeforeunload', (e) => { e.returnValue = null; done(); });
|
ipcMain.once('onbeforeunload', (e) => { e.returnValue = null; done(); });
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-empty-string.html'));
|
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-empty-string.html'));
|
||||||
});
|
});
|
||||||
it('emits for each close attempt', (done) => {
|
|
||||||
let beforeUnloadCount = 0;
|
it('emits for each close attempt', async () => {
|
||||||
ipcMain.on('onbeforeunload', (e) => {
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||||
e.returnValue = null;
|
|
||||||
beforeUnloadCount += 1;
|
const destroyListener = () => { expect.fail('Close was not prevented'); };
|
||||||
if (beforeUnloadCount < 3) {
|
w.webContents.once('destroyed', destroyListener);
|
||||||
|
|
||||||
|
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||||
|
{
|
||||||
|
const p = emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
w.close();
|
w.close();
|
||||||
} else if (beforeUnloadCount === 3) {
|
const [e] = await p;
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
w.webContents.once('did-finish-load', () => { w.webContents.executeJavaScript('window.close()', true); });
|
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
|
||||||
});
|
|
||||||
it('emits for each reload attempt', (done) => {
|
|
||||||
let beforeUnloadCount = 0;
|
|
||||||
ipcMain.on('onbeforeunload', (e) => {
|
|
||||||
e.returnValue = null;
|
e.returnValue = null;
|
||||||
beforeUnloadCount += 1;
|
|
||||||
if (beforeUnloadCount < 3) {
|
|
||||||
w.reload();
|
|
||||||
} else if (beforeUnloadCount === 3) {
|
|
||||||
done();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
w.webContents.once('did-finish-load', () => {
|
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||||
w.webContents.once('did-finish-load', () => {
|
|
||||||
expect.fail('Reload was not prevented');
|
// Hi future test refactorer! I don't know what event this timeout allows
|
||||||
});
|
// to occur, but without it, this test becomes flaky at this point and
|
||||||
w.reload();
|
// sometimes the window gets closed even though a `beforeunload` handler
|
||||||
});
|
// has been installed. I looked for events being emitted by the
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
// `webContents` during this timeout period and found nothing, so it
|
||||||
});
|
// might be some sort of internal timeout being applied by the content/
|
||||||
it('emits for each navigation attempt', (done) => {
|
// layer, or blink?
|
||||||
let beforeUnloadCount = 0;
|
//
|
||||||
ipcMain.on('onbeforeunload', (e) => {
|
// In any case, this incantation reduces flakiness. I'm going to add a
|
||||||
|
// summoning circle for good measure.
|
||||||
|
//
|
||||||
|
// 🕯 🕯
|
||||||
|
// 🕯 🕯
|
||||||
|
// 🕯 🕯
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
// 🕯 🕯
|
||||||
|
// 🕯 🕯
|
||||||
|
// 🕯 🕯
|
||||||
|
|
||||||
|
{
|
||||||
|
const p = emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
|
w.close();
|
||||||
|
const [e] = await p;
|
||||||
e.returnValue = null;
|
e.returnValue = null;
|
||||||
beforeUnloadCount += 1;
|
|
||||||
if (beforeUnloadCount < 3) {
|
|
||||||
w.loadURL('about:blank');
|
|
||||||
} else if (beforeUnloadCount === 3) {
|
|
||||||
done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.webContents.removeListener('destroyed', destroyListener);
|
||||||
|
const p = emittedOnce(w.webContents, 'destroyed');
|
||||||
|
w.close();
|
||||||
|
await p;
|
||||||
});
|
});
|
||||||
w.webContents.once('did-finish-load', () => {
|
|
||||||
w.webContents.once('did-finish-load', () => {
|
it('emits for each reload attempt', async () => {
|
||||||
expect.fail('Navigation was not prevented');
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||||
|
|
||||||
|
const navigationListener = () => { expect.fail('Reload was not prevented'); };
|
||||||
|
w.webContents.once('did-start-navigation', navigationListener);
|
||||||
|
|
||||||
|
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||||
|
w.reload();
|
||||||
|
{
|
||||||
|
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
|
e.returnValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||||
|
w.reload();
|
||||||
|
{
|
||||||
|
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
|
e.returnValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
w.webContents.removeListener('did-start-navigation', navigationListener);
|
||||||
|
w.reload();
|
||||||
|
await emittedOnce(w.webContents, 'did-finish-load');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('emits for each navigation attempt', async () => {
|
||||||
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||||
|
|
||||||
|
const navigationListener = () => { expect.fail('Reload was not prevented'); };
|
||||||
|
w.webContents.once('did-start-navigation', navigationListener);
|
||||||
|
|
||||||
|
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||||
w.loadURL('about:blank');
|
w.loadURL('about:blank');
|
||||||
});
|
{
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
|
e.returnValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||||
|
w.loadURL('about:blank');
|
||||||
|
{
|
||||||
|
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||||
|
e.returnValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
w.webContents.removeListener('did-start-navigation', navigationListener);
|
||||||
|
w.loadURL('about:blank');
|
||||||
|
await emittedOnce(w.webContents, 'did-finish-load');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,16 @@ describe('webContents module', () => {
|
||||||
|
|
||||||
it('emits if beforeunload returns false', async () => {
|
it('emits if beforeunload returns false', async () => {
|
||||||
const w = new BrowserWindow({ show: false });
|
const w = new BrowserWindow({ show: false });
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
||||||
|
w.webContents.executeJavaScript('run()', true);
|
||||||
await emittedOnce(w.webContents, 'will-prevent-unload');
|
await emittedOnce(w.webContents, 'will-prevent-unload');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports calling preventDefault on will-prevent-unload events', async () => {
|
it('supports calling preventDefault on will-prevent-unload events', async () => {
|
||||||
const w = new BrowserWindow({ show: false });
|
const w = new BrowserWindow({ show: false });
|
||||||
w.webContents.once('will-prevent-unload', event => event.preventDefault());
|
w.webContents.once('will-prevent-unload', event => event.preventDefault());
|
||||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
|
||||||
|
w.webContents.executeJavaScript('run()', true);
|
||||||
await emittedOnce(w, 'closed');
|
await emittedOnce(w, 'closed');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
// Only prevent unload on the first three window closes
|
function preventNextBeforeUnload() {
|
||||||
var unloadPreventedCount = 0;
|
window.addEventListener('beforeunload', function handler(e) {
|
||||||
window.onbeforeunload = function() {
|
e.preventDefault();
|
||||||
|
e.returnValue = '';
|
||||||
|
window.removeEventListener('beforeunload', handler)
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
require('electron').ipcRenderer.sendSync('onbeforeunload')
|
require('electron').ipcRenderer.sendSync('onbeforeunload')
|
||||||
}, 0);
|
}, 0);
|
||||||
if (unloadPreventedCount < 3) {
|
|
||||||
unloadPreventedCount++;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
function run() {
|
||||||
// Only prevent unload on the first window close
|
// Only prevent unload on the first window close
|
||||||
var unloadPrevented = false;
|
var unloadPrevented = false;
|
||||||
window.onbeforeunload = function() {
|
window.onbeforeunload = function() {
|
||||||
|
@ -13,7 +14,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// unload events don't get run unless load events have run.
|
// unload events don't get run unless load events have run.
|
||||||
|
if (document.readyState === 'complete')
|
||||||
|
window.close()
|
||||||
|
else
|
||||||
window.onload = () => window.close()
|
window.onload = () => window.close()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue