mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
prevent overwriting of salvageable state in later prompt/unload steps
This commit is contained in:
parent
a297e8f288
commit
57c0d82944
5 changed files with 101 additions and 5 deletions
|
@ -1654,7 +1654,9 @@ impl Document {
|
||||||
);
|
);
|
||||||
// TODO: Step 6, decrease the event loop's termination nesting level by 1.
|
// TODO: Step 6, decrease the event loop's termination nesting level by 1.
|
||||||
// Step 7
|
// Step 7
|
||||||
self.salvageable.set(!has_listeners);
|
if has_listeners {
|
||||||
|
self.salvageable.set(false);
|
||||||
|
}
|
||||||
let mut can_unload = true;
|
let mut can_unload = true;
|
||||||
// TODO: Step 8 send a message to embedder to prompt user.
|
// TODO: Step 8 send a message to embedder to prompt user.
|
||||||
// Step 9
|
// Step 9
|
||||||
|
@ -1662,9 +1664,11 @@ impl Document {
|
||||||
for iframe in self.iter_iframes() {
|
for iframe in self.iter_iframes() {
|
||||||
// TODO: handle the case of cross origin iframes.
|
// TODO: handle the case of cross origin iframes.
|
||||||
let document = document_from_node(&*iframe);
|
let document = document_from_node(&*iframe);
|
||||||
if !document.prompt_to_unload(true) {
|
can_unload = document.prompt_to_unload(true);
|
||||||
self.salvageable.set(document.salvageable());
|
if !document.salvageable() {
|
||||||
can_unload = false;
|
self.salvageable.set(false);
|
||||||
|
}
|
||||||
|
if !can_unload {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1715,7 +1719,9 @@ impl Document {
|
||||||
);
|
);
|
||||||
self.fired_unload.set(true);
|
self.fired_unload.set(true);
|
||||||
// Step 9
|
// Step 9
|
||||||
self.salvageable.set(!has_listeners);
|
if has_listeners {
|
||||||
|
self.salvageable.set(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: Step 8, decrease the event loop's termination nesting level by 1.
|
// TODO: Step 8, decrease the event loop's termination nesting level by 1.
|
||||||
|
|
||||||
|
|
|
@ -277161,6 +277161,16 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"html/browsers/browsing-the-web/unloading-documents/prompt/004-1.html": [
|
||||||
|
[
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"html/browsers/browsing-the-web/unloading-documents/prompt/004-2.html": [
|
||||||
|
[
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html": [
|
"html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html": [
|
||||||
[
|
[
|
||||||
{}
|
{}
|
||||||
|
@ -333024,6 +333034,12 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"html/browsers/browsing-the-web/unloading-documents/prompt/004.html": [
|
||||||
|
[
|
||||||
|
"/html/browsers/browsing-the-web/unloading-documents/prompt/004.html",
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"html/browsers/browsing-the-web/unloading-documents/unload/001.html": [
|
"html/browsers/browsing-the-web/unloading-documents/unload/001.html": [
|
||||||
[
|
[
|
||||||
"/html/browsers/browsing-the-web/unloading-documents/unload/001.html",
|
"/html/browsers/browsing-the-web/unloading-documents/unload/001.html",
|
||||||
|
@ -564777,6 +564793,18 @@
|
||||||
"c37ad1ea3a1c8e389f6066c95c7b2745648e9e7e",
|
"c37ad1ea3a1c8e389f6066c95c7b2745648e9e7e",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
|
"html/browsers/browsing-the-web/unloading-documents/prompt/004-1.html": [
|
||||||
|
"3530a94754361d436b6c20496bea07eb0bec4893",
|
||||||
|
"support"
|
||||||
|
],
|
||||||
|
"html/browsers/browsing-the-web/unloading-documents/prompt/004-2.html": [
|
||||||
|
"01dc2c7f9c673781291a5afbdb40ca0f0919e797",
|
||||||
|
"support"
|
||||||
|
],
|
||||||
|
"html/browsers/browsing-the-web/unloading-documents/prompt/004.html": [
|
||||||
|
"4c8485a929926005115dd0f8e2d2a2d8e1673c6f",
|
||||||
|
"testharness"
|
||||||
|
],
|
||||||
"html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html": [
|
"html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html": [
|
||||||
"895580cf70904918397da755527c5dda3f227b8a",
|
"895580cf70904918397da755527c5dda3f227b8a",
|
||||||
"support"
|
"support"
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<!doctype html>
|
||||||
|
004-1
|
||||||
|
<script>
|
||||||
|
var handleBeforeUnload = function() {
|
||||||
|
parent.beforeunload_fired = true;
|
||||||
|
removeListener();
|
||||||
|
setTimeout(function() {
|
||||||
|
parent.timeout_fired = true;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
var removeListener = function() {
|
||||||
|
assert_true(window.removeEventListener('beforeunload', handleBeforeUnload, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload, false);
|
||||||
|
|
||||||
|
onload = function() {
|
||||||
|
if (!parent.loaded) {
|
||||||
|
parent.loaded = true;
|
||||||
|
location="004-2.html?" + Math.random();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
// child frame with no onbeforeunload listener. Should leave the parent as unsalvageable.
|
||||||
|
// Adding the iframe prevents potential implementation bugs where the the recursive steps of #prompt-to-unload-a-document
|
||||||
|
// would overwrite the salvageable state of the parent.
|
||||||
|
<iframe></iframe>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<!doctype html>
|
||||||
|
004-2
|
||||||
|
<script>
|
||||||
|
onload = function() {setTimeout(parent.t.step_func(function() {parent.start_test(); history.go(-1)}), 100)}
|
||||||
|
</script>
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!doctype html>
|
||||||
|
<title>salvagable state of document after setting beforeunload listener</title>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<div id="log"></div>
|
||||||
|
<script>
|
||||||
|
var t = async_test();
|
||||||
|
|
||||||
|
var loaded = false;
|
||||||
|
var beforeunload_fired = false;
|
||||||
|
var timeout_fired = false;
|
||||||
|
|
||||||
|
function start_test() {
|
||||||
|
step_timeout(
|
||||||
|
t.step_func(function() {
|
||||||
|
assert_true(beforeunload_fired);
|
||||||
|
assert_false(timeout_fired);
|
||||||
|
t.done()
|
||||||
|
}), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
onload = function() {
|
||||||
|
var iframe = document.getElementsByTagName("iframe")[0]
|
||||||
|
onload = null;
|
||||||
|
iframe.src="004-1.html?" + Math.random();
|
||||||
|
};
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<iframe></iframe>
|
Loading…
Add table
Add a link
Reference in a new issue