Title: [194077] branches/safari-601-branch
Revision
194077
Author
[email protected]
Date
2015-12-14 16:35:35 -0800 (Mon, 14 Dec 2015)

Log Message

Merge r192270. rdar://problem/23435543

Modified Paths

Added Paths

Diff

Modified: branches/safari-601-branch/LayoutTests/ChangeLog (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/ChangeLog	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/ChangeLog	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,3 +1,56 @@
+2015-12-14  Harris Papadopoulos  <[email protected]>
+
+        Merge r192270. rdar://problem/23435543
+
+    2015-11-10  Geoffrey Garen  <[email protected]>
+
+            alert, confirm, prompt, showModalDialog should be forbidden during page close and navigation
+            https://bugs.webkit.org/show_bug.cgi?id=150980
+
+            Reviewed by Chris Dumez.
+
+            Added tests to cover the matrix of [ alert, confirm, prompt, showModalDialog ] x [ beforeunload, unload, pagehide ].
+
+            * fast/events/beforeunload-alert-expected.txt: Added.
+            * fast/events/beforeunload-alert.html: Added.
+            * fast/events/beforeunload-confirm-expected.txt: Added.
+            * fast/events/beforeunload-confirm.html: Added.
+            * fast/events/beforeunload-prompt-expected.txt: Added.
+            * fast/events/beforeunload-prompt.html: Added.
+            * fast/events/beforeunload-showModalDialog-expected.txt: Added.
+            * fast/events/beforeunload-showModalDialog.html: Added.
+            * fast/events/onunload-expected.txt:
+            * fast/events/onunload-not-on-body-expected.txt:
+            * fast/events/onunload-window-property-expected.txt:
+            * fast/events/pagehide-alert-expected.txt: Added.
+            * fast/events/pagehide-alert.html: Added.
+            * fast/events/pagehide-confirm-expected.txt: Added.
+            * fast/events/pagehide-confirm.html: Added.
+            * fast/events/pagehide-prompt-expected.txt: Added.
+            * fast/events/pagehide-prompt.html: Added.
+            * fast/events/pagehide-showModalDialog-expected.txt: Added.
+            * fast/events/pagehide-showModalDialog.html: Added.
+            * fast/events/pageshow-pagehide-on-back-cached-expected.txt:
+            * fast/events/pageshow-pagehide-on-back-uncached-expected.txt:
+            * fast/events/resources/prompt-landing-page.html: Added.
+            * fast/events/unload-alert-expected.txt: Added.
+            * fast/events/unload-alert.html: Added.
+            * fast/events/unload-confirm-expected.txt: Added.
+            * fast/events/unload-confirm.html: Added.
+            * fast/events/unload-prompt-expected.txt: Added.
+            * fast/events/unload-prompt.html: Added.
+            * fast/events/unload-showModalDialog-expected.txt: Added.
+            * fast/events/unload-showModalDialog.html: Added.
+
+            * platform/wk2/TestExpectations: WebKit2 can't handle showModalDialog tests.
+
+            * compositing/iframes/page-cache-layer-tree-expected.txt:
+            * fast/dom/Geolocation/notimer-after-unload-expected.txt:
+            * fast/history/timed-refresh-in-cached-frame-expected.txt:
+            * fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt:
+            * fast/loader/page-dismissal-modal-dialogs-expected.txt: These were
+            pre-existing tests that tried to alert during unload.
+
 2015-12-14  Matthew Hanson  <[email protected]>
 
         Merge r194001. rdar://problem/23581577

Modified: branches/safari-601-branch/LayoutTests/compositing/iframes/page-cache-layer-tree-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/compositing/iframes/page-cache-layer-tree-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/compositing/iframes/page-cache-layer-tree-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,5 +1,5 @@
 ALERT: pageshow - not from cache
-ALERT: pagehide - entering cache
+CONSOLE MESSAGE: line 70: Use of window.alert is not allowed while unloading a page.
 ALERT: pageshow - from cache
 This tests that layers are rebuilt properly after the page is restored from the page cache.
 

Modified: branches/safari-601-branch/LayoutTests/fast/dom/Geolocation/notimer-after-unload-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/dom/Geolocation/notimer-after-unload-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/dom/Geolocation/notimer-after-unload-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,3 +1,3 @@
 main frame - has 1 onunload handler(s)
-ALERT: unload-called
+CONSOLE MESSAGE: line 15: Use of window.alert is not allowed while unloading a page.
 You should have seen one unload alert appear.

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-alert-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-alert-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-alert-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-alert.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-alert.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-alert.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onbeforeunload_ = function() {
+	alert("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-confirm-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-confirm-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-confirm-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 8: Use of window.confirm is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-confirm.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-confirm.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-confirm.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onbeforeunload_ = function() {
+	confirm("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-prompt-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-prompt-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-prompt-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 8: Use of window.prompt is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-prompt.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-prompt.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-prompt.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onbeforeunload_ = function() {
+	prompt("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-showModalDialog-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-showModalDialog-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-showModalDialog-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 14: Use of window.showModalDialog is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/beforeunload-showModalDialog.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/beforeunload-showModalDialog.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/beforeunload-showModalDialog.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,18 @@
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows();
+    testRunner.waitUntilDone();
+}
+
+function log()
+{
+	alert("FAIL: This prompt should have been ignored.");
+}
+
+window._onbeforeunload_ = function() {
+	showModalDialog("resources/modal-dialog.html");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Modified: branches/safari-601-branch/LayoutTests/fast/events/onunload-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/onunload-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/events/onunload-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,3 +1,3 @@
 main frame - has 1 onunload handler(s)
-ALERT: unload
+CONSOLE MESSAGE: line 16: Use of window.alert is not allowed while unloading a page.
 You should have seen an unload alert appear.

Modified: branches/safari-601-branch/LayoutTests/fast/events/onunload-not-on-body-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/onunload-not-on-body-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/events/onunload-not-on-body-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,3 +1,3 @@
 frame "<!--framePath //<!--frame2-->-->" - has 1 onunload handler(s)
-ALERT: unload
+CONSOLE MESSAGE: line 1: Use of window.alert is not allowed while unloading a page.
 you should only see one unload alert appear.

Modified: branches/safari-601-branch/LayoutTests/fast/events/onunload-window-property-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/onunload-window-property-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/events/onunload-window-property-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,2 +1,2 @@
-ALERT: unload
+CONSOLE MESSAGE: line 13: Use of window.alert is not allowed while unloading a page.
 You should have seen an unload alert appear.

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-alert-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-alert-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-alert-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-alert.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-alert.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-alert.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onpagehide_ = function() {
+	alert("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-confirm-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-confirm-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-confirm-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 8: Use of window.confirm is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-confirm.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-confirm.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-confirm.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onpagehide_ = function() {
+	confirm("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-prompt-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-prompt-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-prompt-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 8: Use of window.prompt is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-prompt.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-prompt.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-prompt.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onpagehide_ = function() {
+	prompt("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-showModalDialog-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-showModalDialog-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-showModalDialog-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 14: Use of window.showModalDialog is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/pagehide-showModalDialog.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pagehide-showModalDialog.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/pagehide-showModalDialog.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,18 @@
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows();
+    testRunner.waitUntilDone();
+}
+
+function log()
+{
+	alert("FAIL: This prompt should have been ignored.");
+}
+
+window._onpagehide_ = function() {
+	showModalDialog("resources/modal-dialog.html");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Modified: branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-cached-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-cached-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-cached-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,5 +1,5 @@
 ALERT: window.onload
 ALERT: window.onpageshow, target = [object HTMLDocument], persisted = false
-ALERT: window.onpagehide, target = [object HTMLDocument], persisted = true
+CONSOLE MESSAGE: line 25: Use of window.alert is not allowed while unloading a page.
 ALERT: window.onpageshow, target = [object HTMLDocument], persisted = true
 Test pageshow/pagehide event behavior when navigating back to an cached page.

Modified: branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-uncached-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-uncached-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-uncached-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,7 +1,7 @@
 main frame - has 1 onunload handler(s)
 ALERT: window.onload
 ALERT: window.onpageshow, target = [object HTMLDocument], persisted = false
-ALERT: window.onpagehide, target = [object HTMLDocument], persisted = false
+CONSOLE MESSAGE: line 28: Use of window.alert is not allowed while unloading a page.
 main frame "pageshow/pagehide" - has 1 onunload handler(s)
 ALERT: window.onload
 ALERT: window.onpageshow, target = [object HTMLDocument], persisted = false

Added: branches/safari-601-branch/LayoutTests/fast/events/resources/prompt-landing-page.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/resources/prompt-landing-page.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/resources/prompt-landing-page.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<p>This test verifies that prompts are forbidden when leaving a webpage.</p>
+
+<p>Prompts include alert, confirm, prompt, and showModalDialog.</p>
+
+<p>If there is no prompt, the test passed.</p>
+
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.notifyDone();
+}
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-alert-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-alert-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-alert-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,7 @@
+main frame - has 1 onunload handler(s)
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-alert.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-alert.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-alert.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onunload_ = function() {
+	alert("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-confirm-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-confirm-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-confirm-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,7 @@
+main frame - has 1 onunload handler(s)
+CONSOLE MESSAGE: line 8: Use of window.confirm is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-confirm.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-confirm.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-confirm.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onunload_ = function() {
+	confirm("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-prompt-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-prompt-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-prompt-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,7 @@
+main frame - has 1 onunload handler(s)
+CONSOLE MESSAGE: line 8: Use of window.prompt is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-prompt.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-prompt.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-prompt.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,12 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+window._onunload_ = function() {
+	prompt("FAIL: This prompt should have been ignored.");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-showModalDialog-expected.txt (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-showModalDialog-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-showModalDialog-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,7 @@
+main frame - has 1 onunload handler(s)
+CONSOLE MESSAGE: line 14: Use of window.showModalDialog is not allowed while unloading a page.
+This test verifies that prompts are forbidden when leaving a webpage.
+
+Prompts include alert, confirm, prompt, and showModalDialog.
+
+If there is no prompt, the test passed.

Added: branches/safari-601-branch/LayoutTests/fast/events/unload-showModalDialog.html (0 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/events/unload-showModalDialog.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/events/unload-showModalDialog.html	2015-12-15 00:35:35 UTC (rev 194077)
@@ -0,0 +1,18 @@
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows();
+    testRunner.waitUntilDone();
+}
+
+function log()
+{
+	alert("FAIL: This prompt should have been ignored.");
+}
+
+window._onunload_ = function() {
+	showModalDialog("resources/modal-dialog.html");
+}
+
+setTimeout(function() { window.location = "resources/prompt-landing-page.html" }, 0);
+</script>

Modified: branches/safari-601-branch/LayoutTests/fast/history/timed-refresh-in-cached-frame-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/history/timed-refresh-in-cached-frame-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/history/timed-refresh-in-cached-frame-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,2 +1,2 @@
-ALERT: pagehide true
+CONSOLE MESSAGE: line 1: Use of window.alert is not allowed while unloading a page.
 PASSED if didn't crash in two seconds.

Modified: branches/safari-601-branch/LayoutTests/fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,7 +1,7 @@
 frame "<!--framePath //<!--frame0-->/<!--frame0-->-->" - has 1 onunload handler(s)
 ALERT: Subframe onload
 ALERT: Subframe onpageshow
-ALERT: Main frame window.onpagehide called
-ALERT: Subframe onpagehide
-ALERT: Subframe onunload
+CONSOLE MESSAGE: line 16: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 18: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.alert is not allowed while unloading a page.
 

Modified: branches/safari-601-branch/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,32 +1,32 @@
 frame "<!--framePath //<!--frame0-->-->" - has 1 onunload handler(s)
-CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
-CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
-ALERT: mainFrame pagehide PASS
-CONFIRM: mainFrame pagehide PASS
-PROMPT: mainFrame pagehide PASS, default text: PASS
-ALERT: iFrame click PASS
-CONFIRM: iFrame click PASS
-PROMPT: iFrame click PASS, default text: PASS
-ALERT: mainFrame unload PASS
-CONFIRM: mainFrame unload PASS
-PROMPT: mainFrame unload PASS, default text: PASS
-ALERT: iFrame click PASS
-CONFIRM: iFrame click PASS
-PROMPT: iFrame click PASS, default text: PASS
-ALERT: iFrame pagehide PASS
-CONFIRM: iFrame pagehide PASS
-PROMPT: iFrame pagehide PASS, default text: PASS
-ALERT: iFrame unload PASS
-CONFIRM: iFrame unload PASS
-PROMPT: iFrame unload PASS, default text: PASS
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
+CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
+CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
+CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
 PASS

Modified: branches/safari-601-branch/LayoutTests/platform/wk2/TestExpectations (194076 => 194077)


--- branches/safari-601-branch/LayoutTests/platform/wk2/TestExpectations	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/LayoutTests/platform/wk2/TestExpectations	2015-12-15 00:35:35 UTC (rev 194077)
@@ -141,6 +141,9 @@
 # WebKitTestRunner needs testRunner.abortModal
 # <https://bugs.webkit.org/show_bug.cgi?id=69548>
 fast/events/show-modal-dialog-onblur-onfocus.html
+fast/events/beforeunload-showModalDialog.html
+fast/events/pagehide-showModalDialog.html
+fast/events/unload-showModalDialog.html
 
 # WebKitTestRunner needs testRunner.setWillSendRequestClearHeader
 # <https://bugs.webkit.org/show_bug.cgi?id=42699>

Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (194076 => 194077)


--- branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1,3 +1,62 @@
+2015-12-14  Harris Papadopoulos  <[email protected]>
+
+        Merge r192270. rdar://problem/23435543
+
+    2015-11-10  Geoffrey Garen  <[email protected]>
+
+            alert, confirm, prompt, showModalDialog should be forbidden during page close and navigation
+            https://bugs.webkit.org/show_bug.cgi?id=150980
+
+            Reviewed by Chris Dumez.
+
+            Tests: fast/events/beforeunload-alert.html
+                   fast/events/beforeunload-confirm.html
+                   fast/events/beforeunload-prompt.html
+                   fast/events/beforeunload-showModalDialog.html
+                   fast/events/pagehide-alert.html
+                   fast/events/pagehide-confirm.html
+                   fast/events/pagehide-prompt.html
+                   fast/events/pagehide-showModalDialog.html
+                   fast/events/unload-alert.html
+                   fast/events/unload-confirm.html
+                   fast/events/unload-prompt.html
+                   fast/events/unload-showModalDialog.html
+
+            * loader/FrameLoader.cpp:
+            (WebCore::FrameLoader::stopLoading): Factored out a helper function for
+            unload event processing.
+            (WebCore::FrameLoader::handleUnloadEvents): Forbid prompts in unload
+            events just like we do in beforeunload events, and for the same reasons.
+
+            (WebCore::FrameLoader::handleBeforeUnloadEvent): Updated for renames.
+
+            * loader/FrameLoader.h:
+
+            * page/DOMWindow.cpp:
+            (WebCore::DOMWindow::print):
+            (WebCore::DOMWindow::alert):
+            (WebCore::DOMWindow::confirm):
+            (WebCore::DOMWindow::prompt):
+            (WebCore::DOMWindow::showModalDialog): Updated for renames. Refactored
+            some of this code to handle null pages more cleanly. In particular, we
+            sometimes used to treat null page as "everything is permitted" -- but it
+            is best practice in a permissions context to treat lack of information
+            as no permission granted rather than all permissions granted. (I don't
+            know of a way to trigger this condition in practice.)
+
+            * page/Page.cpp:
+            (WebCore::Page::Page):
+            (WebCore::Page::forbidPrompts):
+            (WebCore::Page::allowPrompts):
+            (WebCore::Page::arePromptsAllowed): Renamed to make these functions
+            reflect their new, broader context.
+
+            (WebCore::Page::incrementFrameHandlingBeforeUnloadEventCount): Deleted.
+            (WebCore::Page::decrementFrameHandlingBeforeUnloadEventCount): Deleted.
+            (WebCore::Page::isAnyFrameHandlingBeforeUnloadEvent): Deleted.
+
+            * page/Page.h:
+
 2015-12-08  Harris Papadopoulos  <[email protected]>
 
         Merge r188386. rdar://problem/23816165

Modified: branches/safari-601-branch/Source/WebCore/loader/FrameLoader.cpp (194076 => 194077)


--- branches/safari-601-branch/Source/WebCore/loader/FrameLoader.cpp	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/Source/WebCore/loader/FrameLoader.cpp	2015-12-15 00:35:35 UTC (rev 194077)
@@ -175,6 +175,24 @@
     return frame.document() && frame.document()->isSandboxed(mask);
 }
 
+struct ForbidPromptsScope {
+    ForbidPromptsScope(Page* page) : m_page(page)
+    {
+        if (!m_page)
+            return;
+        m_page->forbidPrompts();
+    }
+
+    ~ForbidPromptsScope()
+    {
+        if (!m_page)
+            return;
+        m_page->allowPrompts();
+    }
+
+    Page* m_page;
+};
+
 class FrameLoader::FrameProgressTracker {
 public:
     explicit FrameProgressTracker(Frame& frame)
@@ -419,56 +437,9 @@
     if (m_frame.document() && m_frame.document()->parser())
         m_frame.document()->parser()->stopParsing();
 
-    if (unloadEventPolicy != UnloadEventPolicyNone) {
-        if (m_frame.document()) {
-            if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) {
-                Element* currentFocusedElement = m_frame.document()->focusedElement();
-                if (currentFocusedElement && currentFocusedElement->toInputElement())
-                    currentFocusedElement->toInputElement()->endEditing();
-                if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) {
-                    if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) {
-                        m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide;
-                        m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->inPageCache()), m_frame.document());
-                    }
+    if (unloadEventPolicy != UnloadEventPolicyNone)
+        handleUnloadEvents(unloadEventPolicy);
 
-                    // FIXME: update Page Visibility state here.
-                    // https://bugs.webkit.org/show_bug.cgi?id=116770
-
-                    if (!m_frame.document()->inPageCache()) {
-                        RefPtr<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false));
-                        // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed
-                        // while dispatching the event, so protect it to prevent writing the end
-                        // time into freed memory.
-                        RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader;
-                        m_pageDismissalEventBeingDispatched = PageDismissalType::Unload;
-                        if (documentLoader && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) {
-                            DocumentLoadTiming& timing = documentLoader->timing();
-                            ASSERT(timing.navigationStart());
-                            timing.markUnloadEventStart();
-                            m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
-                            timing.markUnloadEventEnd();
-                        } else
-                            m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
-                    }
-                }
-                m_pageDismissalEventBeingDispatched = PageDismissalType::None;
-                if (m_frame.document())
-                    m_frame.document()->updateStyleIfNeeded();
-                m_wasUnloadEventEmitted = true;
-            }
-        }
-
-        // Dispatching the unload event could have made m_frame.document() null.
-        if (m_frame.document() && !m_frame.document()->inPageCache()) {
-            // Don't remove event listeners from a transitional empty document (see bug 28716 for more information).
-            bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader
-                && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url());
-
-            if (!keepEventListeners)
-                m_frame.document()->removeAllEventListeners();
-        }
-    }
-
     m_isComplete = true; // to avoid calling completed() in finishedParsing()
     m_didCallImplicitClose = true; // don't want that one either
 
@@ -2869,6 +2840,64 @@
     return shouldClose;
 }
 
+void FrameLoader::handleUnloadEvents(UnloadEventPolicy unloadEventPolicy)
+{
+    if (!m_frame.document())
+        return;
+
+    // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent.
+    ForbidPromptsScope forbidPrompts(m_frame.page());
+
+    if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) {
+        auto* currentFocusedElement = m_frame.document()->focusedElement();
+        if (is<HTMLInputElement>(currentFocusedElement))
+            downcast<HTMLInputElement>(*currentFocusedElement).endEditing();
+        if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) {
+            if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) {
+                m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide;
+                m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->inPageCache()), m_frame.document());
+            }
+
+            // FIXME: update Page Visibility state here.
+            // https://bugs.webkit.org/show_bug.cgi?id=116770
+
+            if (!m_frame.document()->inPageCache()) {
+                RefPtr<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false));
+                // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed
+                // while dispatching the event, so protect it to prevent writing the end
+                // time into freed memory.
+                RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader;
+                m_pageDismissalEventBeingDispatched = PageDismissalType::Unload;
+                if (documentLoader && documentLoader->timing().navigationStart() && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) {
+                    auto& timing = documentLoader->timing();
+                    timing.markUnloadEventStart();
+                    m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
+                    timing.markUnloadEventEnd();
+                } else
+                    m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
+            }
+        }
+        m_pageDismissalEventBeingDispatched = PageDismissalType::None;
+        if (m_frame.document())
+            m_frame.document()->updateStyleIfNeeded();
+        m_wasUnloadEventEmitted = true;
+    }
+
+    // Dispatching the unload event could have made m_frame.document() null.
+    if (!m_frame.document())
+        return;
+
+    if (m_frame.document()->inPageCache())
+        return;
+
+    // Don't remove event listeners from a transitional empty document (see bug 28716 for more information).
+    bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader
+        && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url());
+
+    if (!keepEventListeners)
+        m_frame.document()->removeAllEventListeners();
+}
+
 bool FrameLoader::handleBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLoaderBeingNavigated)
 {
     DOMWindow* domWindow = m_frame.document()->domWindow();
@@ -2882,11 +2911,10 @@
     RefPtr<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create();
     m_pageDismissalEventBeingDispatched = PageDismissalType::BeforeUnload;
 
-    // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent.
-    Page* page = m_frame.page();
-    page->incrementFrameHandlingBeforeUnloadEventCount();
-    domWindow->dispatchEvent(beforeUnloadEvent.get(), domWindow->document());
-    page->decrementFrameHandlingBeforeUnloadEventCount();
+    {
+        ForbidPromptsScope forbidPrompts(m_frame.page());
+        domWindow->dispatchEvent(beforeUnloadEvent.get(), domWindow->document());
+    }
 
     m_pageDismissalEventBeingDispatched = PageDismissalType::None;
 

Modified: branches/safari-601-branch/Source/WebCore/loader/FrameLoader.h (194076 => 194077)


--- branches/safari-601-branch/Source/WebCore/loader/FrameLoader.h	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/Source/WebCore/loader/FrameLoader.h	2015-12-15 00:35:35 UTC (rev 194077)
@@ -317,6 +317,7 @@
     SubstituteData defaultSubstituteDataForURL(const URL&);
 
     bool handleBeforeUnloadEvent(Chrome&, FrameLoader* frameLoaderBeingNavigated);
+    void handleUnloadEvents(UnloadEventPolicy);
 
     void continueLoadAfterNavigationPolicy(const ResourceRequest&, PassRefPtr<FormState>, bool shouldContinue, AllowNavigationToInvalidURL);
     void continueLoadAfterNewWindowPolicy(const ResourceRequest&, PassRefPtr<FormState>, const String& frameName, const NavigationAction&, bool shouldContinue, AllowNavigationToInvalidURL, NewFrameOpenerPolicy);

Modified: branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp (194076 => 194077)


--- branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp	2015-12-15 00:35:35 UTC (rev 194077)
@@ -1048,13 +1048,12 @@
     if (!m_frame)
         return;
 
-    Page* page = m_frame->page();
+    auto* page = m_frame->page();
     if (!page)
         return;
 
-    // Pages are not allowed to bring up a modal print dialog during BeforeUnload dispatch.
-    if (page->isAnyFrameHandlingBeforeUnloadEvent()) {
-        printErrorMessage("Use of window.print is not allowed during beforeunload event dispatch.");
+    if (!page->arePromptsAllowed()) {
+        printErrorMessage("Use of window.print is not allowed while unloading a page.");
         return;
     }
 
@@ -1081,18 +1080,17 @@
     if (!m_frame)
         return;
 
-    // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
-    if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
-        printErrorMessage("Use of window.alert is not allowed during beforeunload event dispatch.");
+    auto* page = m_frame->page();
+    if (!page)
         return;
+
+    if (!page->arePromptsAllowed()) {
+        printErrorMessage("Use of window.alert is not allowed while unloading a page.");
+        return;
     }
 
     m_frame->document()->updateStyleIfNeeded();
 
-    Page* page = m_frame->page();
-    if (!page)
-        return;
-
     page->chrome().runJavaScriptAlert(m_frame, message);
 }
 
@@ -1101,18 +1099,17 @@
     if (!m_frame)
         return false;
     
-    // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
-    if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
-        printErrorMessage("Use of window.confirm is not allowed during beforeunload event dispatch.");
+    auto* page = m_frame->page();
+    if (!page)
         return false;
+
+    if (!page->arePromptsAllowed()) {
+        printErrorMessage("Use of window.confirm is not allowed while unloading a page.");
+        return false;
     }
 
     m_frame->document()->updateStyleIfNeeded();
 
-    Page* page = m_frame->page();
-    if (!page)
-        return false;
-
     return page->chrome().runJavaScriptConfirm(m_frame, message);
 }
 
@@ -1121,18 +1118,17 @@
     if (!m_frame)
         return String();
 
-    // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
-    if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
-        printErrorMessage("Use of window.prompt is not allowed during beforeunload event dispatch.");
+    auto* page = m_frame->page();
+    if (!page)
         return String();
+
+    if (!page->arePromptsAllowed()) {
+        printErrorMessage("Use of window.prompt is not allowed while unloading a page.");
+        return String();
     }
 
     m_frame->document()->updateStyleIfNeeded();
 
-    Page* page = m_frame->page();
-    if (!page)
-        return String();
-
     String returnValue;
     if (page->chrome().runJavaScriptPrompt(m_frame, message, defaultValue, returnValue))
         return returnValue;
@@ -2236,10 +2232,13 @@
     if (!firstFrame)
         return;
 
-    // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
-    if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
-        printErrorMessage("Use of window.showModalDialog is not allowed during beforeunload event dispatch.");
+    auto* page = m_frame->page();
+    if (!page)
         return;
+
+    if (!page->arePromptsAllowed()) {
+        printErrorMessage("Use of window.showModalDialog is not allowed while unloading a page.");
+        return;
     }
 
     if (!canShowModalDialogNow(m_frame) || !firstWindow.allowPopUp())

Modified: branches/safari-601-branch/Source/WebCore/page/Page.cpp (194076 => 194077)


--- branches/safari-601-branch/Source/WebCore/page/Page.cpp	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/Source/WebCore/page/Page.cpp	2015-12-15 00:35:35 UTC (rev 194077)
@@ -209,7 +209,7 @@
     , m_inspectorDebuggable(std::make_unique<PageDebuggable>(*this))
 #endif
     , m_lastSpatialNavigationCandidatesCount(0) // NOTE: Only called from Internals for Spatial Navigation testing.
-    , m_framesHandlingBeforeUnloadEvent(0)
+    , m_forbidPromptsDepth(0)
     , m_applicationCacheStorage(pageConfiguration.applicationCacheStorage ? *WTF::move(pageConfiguration.applicationCacheStorage) : ApplicationCacheStorage::singleton())
     , m_databaseProvider(*WTF::move(pageConfiguration.databaseProvider))
     , m_storageNamespaceProvider(*WTF::move(pageConfiguration.storageNamespaceProvider))
@@ -1597,20 +1597,20 @@
 }
 #endif
 
-void Page::incrementFrameHandlingBeforeUnloadEventCount()
+void Page::forbidPrompts()
 {
-    ++m_framesHandlingBeforeUnloadEvent;
+    ++m_forbidPromptsDepth;
 }
 
-void Page::decrementFrameHandlingBeforeUnloadEventCount()
+void Page::allowPrompts()
 {
-    ASSERT(m_framesHandlingBeforeUnloadEvent);
-    --m_framesHandlingBeforeUnloadEvent;
+    ASSERT(m_forbidPromptsDepth);
+    --m_forbidPromptsDepth;
 }
 
-bool Page::isAnyFrameHandlingBeforeUnloadEvent()
+bool Page::arePromptsAllowed()
 {
-    return m_framesHandlingBeforeUnloadEvent;
+    return !m_forbidPromptsDepth;
 }
 
 void Page::setUserContentController(UserContentController* userContentController)

Modified: branches/safari-601-branch/Source/WebCore/page/Page.h (194076 => 194077)


--- branches/safari-601-branch/Source/WebCore/page/Page.h	2015-12-15 00:35:22 UTC (rev 194076)
+++ branches/safari-601-branch/Source/WebCore/page/Page.h	2015-12-15 00:35:35 UTC (rev 194077)
@@ -409,9 +409,10 @@
     void captionPreferencesChanged();
 #endif
 
-    void incrementFrameHandlingBeforeUnloadEventCount();
-    void decrementFrameHandlingBeforeUnloadEventCount();
-    bool isAnyFrameHandlingBeforeUnloadEvent();
+    void forbidPrompts();
+    void allowPrompts();
+    bool arePromptsAllowed();
+
     void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
     unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
 
@@ -606,7 +607,7 @@
     HashSet<String> m_seenMediaEngines;
 
     unsigned m_lastSpatialNavigationCandidatesCount;
-    unsigned m_framesHandlingBeforeUnloadEvent;
+    unsigned m_forbidPromptsDepth;
 
     Ref<ApplicationCacheStorage> m_applicationCacheStorage;
     Ref<DatabaseProvider> m_databaseProvider;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to