commit
8c856922f3
4 changed files with 81 additions and 0 deletions
|
@ -872,6 +872,15 @@ void WebContents::Observe(int type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::BeforeUnloadDialogCancelled() {
|
||||||
|
if (deferred_load_url_.id) {
|
||||||
|
auto& controller = web_contents()->GetController();
|
||||||
|
if (!controller.GetPendingEntry()) {
|
||||||
|
deferred_load_url_.id = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::DevToolsReloadPage() {
|
void WebContents::DevToolsReloadPage() {
|
||||||
Emit("devtools-reload-page");
|
Emit("devtools-reload-page");
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,6 +340,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
void Observe(int type,
|
void Observe(int type,
|
||||||
const content::NotificationSource& source,
|
const content::NotificationSource& source,
|
||||||
const content::NotificationDetails& details) override;
|
const content::NotificationDetails& details) override;
|
||||||
|
void BeforeUnloadDialogCancelled() override;
|
||||||
|
|
||||||
// brightray::InspectableWebContentsDelegate:
|
// brightray::InspectableWebContentsDelegate:
|
||||||
void DevToolsReloadPage() override;
|
void DevToolsReloadPage() override;
|
||||||
|
|
|
@ -1197,6 +1197,60 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('emits for each close attempt', function (done) {
|
||||||
|
var beforeUnloadCount = 0
|
||||||
|
w.on('onbeforeunload', function () {
|
||||||
|
beforeUnloadCount++
|
||||||
|
if (beforeUnloadCount < 3) {
|
||||||
|
w.close()
|
||||||
|
} else if (beforeUnloadCount === 3) {
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.webContents.once('did-finish-load', function () {
|
||||||
|
w.close()
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('emits for each reload attempt', function (done) {
|
||||||
|
var beforeUnloadCount = 0
|
||||||
|
w.on('onbeforeunload', function () {
|
||||||
|
beforeUnloadCount++
|
||||||
|
if (beforeUnloadCount < 3) {
|
||||||
|
w.reload()
|
||||||
|
} else if (beforeUnloadCount === 3) {
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.webContents.once('did-finish-load', function () {
|
||||||
|
w.webContents.once('did-finish-load', function () {
|
||||||
|
assert.fail('Reload was not prevented')
|
||||||
|
})
|
||||||
|
w.reload()
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('emits for each navigation attempt', function (done) {
|
||||||
|
var beforeUnloadCount = 0
|
||||||
|
w.on('onbeforeunload', function () {
|
||||||
|
beforeUnloadCount++
|
||||||
|
if (beforeUnloadCount < 3) {
|
||||||
|
w.loadURL('about:blank')
|
||||||
|
} else if (beforeUnloadCount === 3) {
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.webContents.once('did-finish-load', function () {
|
||||||
|
w.webContents.once('did-finish-load', function () {
|
||||||
|
assert.fail('Navigation was not prevented')
|
||||||
|
})
|
||||||
|
w.loadURL('about:blank')
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html'))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('new-window event', function () {
|
describe('new-window event', function () {
|
||||||
|
|
17
spec/fixtures/api/beforeunload-false-prevent3.html
vendored
Normal file
17
spec/fixtures/api/beforeunload-false-prevent3.html
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<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').remote.getCurrentWindow().emit('onbeforeunload');
|
||||||
|
}, 0);
|
||||||
|
if (unloadPreventedCount < 3) {
|
||||||
|
unloadPreventedCount++;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue