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
|
||||
thread_capabilities.patch
|
||||
webview_cross_drag.patch
|
||||
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
|
||||
gin_enable_disable_v8_platform.patch
|
||||
blink-worker-enable-csp-in-file-scheme.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');
|
||||
});
|
||||
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');
|
||||
e.returnValue = null;
|
||||
});
|
||||
|
@ -2590,7 +2591,8 @@ describe('BrowserWindow module', () => {
|
|||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-undefined.html'));
|
||||
});
|
||||
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');
|
||||
e.returnValue = null;
|
||||
});
|
||||
|
@ -2598,57 +2600,103 @@ describe('BrowserWindow module', () => {
|
|||
ipcMain.once('onbeforeunload', (e) => { e.returnValue = null; done(); });
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-empty-string.html'));
|
||||
});
|
||||
it('emits for each close attempt', (done) => {
|
||||
let beforeUnloadCount = 0;
|
||||
ipcMain.on('onbeforeunload', (e) => {
|
||||
|
||||
it('emits for each close attempt', async () => {
|
||||
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||
|
||||
const destroyListener = () => { expect.fail('Close was not prevented'); };
|
||||
w.webContents.once('destroyed', destroyListener);
|
||||
|
||||
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||
{
|
||||
const p = emittedOnce(ipcMain, 'onbeforeunload');
|
||||
w.close();
|
||||
const [e] = await p;
|
||||
e.returnValue = null;
|
||||
beforeUnloadCount += 1;
|
||||
if (beforeUnloadCount < 3) {
|
||||
w.close();
|
||||
} else if (beforeUnloadCount === 3) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
w.webContents.once('did-finish-load', () => { w.webContents.executeJavaScript('window.close()', true); });
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||
}
|
||||
|
||||
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
|
||||
|
||||
// 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
|
||||
// sometimes the window gets closed even though a `beforeunload` handler
|
||||
// has been installed. I looked for events being emitted by the
|
||||
// `webContents` during this timeout period and found nothing, so it
|
||||
// might be some sort of internal timeout being applied by the content/
|
||||
// layer, or blink?
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
w.webContents.removeListener('destroyed', destroyListener);
|
||||
const p = emittedOnce(w.webContents, 'destroyed');
|
||||
w.close();
|
||||
await p;
|
||||
});
|
||||
it('emits for each reload attempt', (done) => {
|
||||
let beforeUnloadCount = 0;
|
||||
ipcMain.on('onbeforeunload', (e) => {
|
||||
|
||||
it('emits for each reload 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.reload();
|
||||
{
|
||||
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||
e.returnValue = null;
|
||||
beforeUnloadCount += 1;
|
||||
if (beforeUnloadCount < 3) {
|
||||
w.reload();
|
||||
} else if (beforeUnloadCount === 3) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
expect.fail('Reload was not prevented');
|
||||
});
|
||||
w.reload();
|
||||
});
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||
}
|
||||
|
||||
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', (done) => {
|
||||
let beforeUnloadCount = 0;
|
||||
ipcMain.on('onbeforeunload', (e) => {
|
||||
|
||||
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');
|
||||
{
|
||||
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
|
||||
e.returnValue = null;
|
||||
beforeUnloadCount += 1;
|
||||
if (beforeUnloadCount < 3) {
|
||||
w.loadURL('about:blank');
|
||||
} else if (beforeUnloadCount === 3) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
expect.fail('Navigation was not prevented');
|
||||
});
|
||||
w.loadURL('about:blank');
|
||||
});
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
|
||||
}
|
||||
|
||||
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 () => {
|
||||
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');
|
||||
});
|
||||
|
||||
it('supports calling preventDefault on will-prevent-unload events', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Only prevent unload on the first three window closes
|
||||
var unloadPreventedCount = 0;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload')
|
||||
}, 0);
|
||||
if (unloadPreventedCount < 3) {
|
||||
unloadPreventedCount++;
|
||||
function preventNextBeforeUnload() {
|
||||
window.addEventListener('beforeunload', function handler(e) {
|
||||
e.preventDefault();
|
||||
e.returnValue = '';
|
||||
window.removeEventListener('beforeunload', handler)
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload')
|
||||
}, 0);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Only prevent unload on the first window close
|
||||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload');
|
||||
}, 0);
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
return false;
|
||||
function run() {
|
||||
// Only prevent unload on the first window close
|
||||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload');
|
||||
}, 0);
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// unload events don't get run unless load events have run.
|
||||
if (document.readyState === 'complete')
|
||||
window.close()
|
||||
else
|
||||
window.onload = () => window.close()
|
||||
}
|
||||
// unload events don't get run unless load events have run.
|
||||
window.onload = () => window.close()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue