Diff
Modified: trunk/LayoutTests/ChangeLog (152940 => 152941)
--- trunk/LayoutTests/ChangeLog 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/ChangeLog 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,3 +1,31 @@
+2013-07-19 Brady Eidson <[email protected]>
+
+ Pages should not be able to abuse users inside beforeunload handlers.
+ <rdar://problem/14475779> and https://bugs.webkit.org/show_bug.cgi?id=118871.
+
+ Reviewed by Alexey Proskuryakov.
+
+ In addition to the new tests, updated some results of previous tests that were relying on "alert"
+ as a poor man's logging method.
+
+ * fast/events/onbeforeunload-focused-iframe-expected.txt:
+ * fast/events/onbeforeunload-focused-iframe.html:
+ * fast/events/onunload-clears-onbeforeunload-expected.txt:
+ * fast/events/onunload-clears-onbeforeunload.html:
+ * fast/loader/page-dismissal-modal-dialogs-expected.txt:
+ * fast/loader/page-dismissal-modal-dialogs.html:
+ * fast/loader/recursive-before-unload-crash-expected.txt:
+ * fast/loader/recursive-before-unload-crash.html:
+ * fast/loader/resources/iframe-with-beforeunload.html: Added.
+ * fast/loader/show-only-one-beforeunload-dialog-expected.txt: Added.
+ * fast/loader/show-only-one-beforeunload-dialog.html: Added.
+ * http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin-expected.txt: Added.
+ * http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html: Added.
+ * http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin-expected.txt: Added.
+ * http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html: Added.
+ * http/tests/misc/resources/iframe-with-beforeunload.html: Added.
+ * http/tests/misc/resources/notify-done.html: Added.
+
2013-07-19 Stephanie Lewis <[email protected]>
Some compositing tests fail on ML WK2 Debugi
Modified: trunk/LayoutTests/fast/events/onbeforeunload-focused-iframe-expected.txt (152940 => 152941)
--- trunk/LayoutTests/fast/events/onbeforeunload-focused-iframe-expected.txt 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/events/onbeforeunload-focused-iframe-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,6 +1,6 @@
-ALERT: beforeUnload
+CONSOLE MESSAGE: line 16: beforeUnload
New window with beforeUnload handler.
-You should see an alert with "beforeUnload" if you try to close the window.
+You should see "beforeUnload" in the console log if you try to close the window.
--------
Modified: trunk/LayoutTests/fast/events/onbeforeunload-focused-iframe.html (152940 => 152941)
--- trunk/LayoutTests/fast/events/onbeforeunload-focused-iframe.html 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/events/onbeforeunload-focused-iframe.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,7 +1,7 @@
<html>
<body>
New window with beforeUnload handler.<br>
- You should see an alert with "beforeUnload" if you try to close the window.<br>
+ You should see "beforeUnload" in the console log if you try to close the window.<br>
<iframe src="" id="focusedFrame"></iframe>
<script>
if (window.testRunner) {
@@ -13,7 +13,7 @@
window._onbeforeunload_ = beforeUnload;
function beforeUnload()
{
- alert("beforeUnload");
+ console.log("beforeUnload");
window._onbeforeunload_ = null;
}
Modified: trunk/LayoutTests/fast/events/onunload-clears-onbeforeunload-expected.txt (152940 => 152941)
--- trunk/LayoutTests/fast/events/onunload-clears-onbeforeunload-expected.txt 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/events/onunload-clears-onbeforeunload-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,4 +1,4 @@
main frame - has 1 onunload handler(s)
-ALERT: before unload
-ALERT: unload
+CONSOLE MESSAGE: line 16: before unload
+CONSOLE MESSAGE: line 21: unload
If you didn't hit an assert you PASS.
Modified: trunk/LayoutTests/fast/events/onunload-clears-onbeforeunload.html (152940 => 152941)
--- trunk/LayoutTests/fast/events/onunload-clears-onbeforeunload.html 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/events/onunload-clears-onbeforeunload.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -13,12 +13,12 @@
function before()
{
- alert( "before unload");
+ console.log( "before unload");
}
function unload()
{
- alert( "unload" );
+ console.log( "unload" );
window.removeEventListener('beforeunload', before, false);
}
Modified: trunk/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt (152940 => 152941)
--- trunk/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,16 +1,16 @@
frame "<!--framePath //<!--frame0-->-->" - has 1 onunload handler(s)
-ALERT: mainFrame beforeunload PASS
-CONFIRM: mainFrame beforeunload PASS
-PROMPT: mainFrame beforeunload PASS, default text: PASS
-ALERT: iFrame click PASS
-CONFIRM: iFrame click PASS
-PROMPT: iFrame click PASS, default text: PASS
-ALERT: iFrame beforeunload PASS
-CONFIRM: iFrame beforeunload PASS
-PROMPT: iFrame beforeunload PASS, default text: PASS
-ALERT: mainFrame click PASS
-CONFIRM: mainFrame click PASS
-PROMPT: mainFrame click PASS, default text: PASS
+CONSOLE MESSAGE: Use of window.alert is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.confirm is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.prompt is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.alert is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.confirm is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.prompt is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.alert is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.confirm is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.prompt is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.alert is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: Use of window.confirm is not allowed during beforeunload event dispatch.
+CONSOLE MESSAGE: 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
Modified: trunk/LayoutTests/fast/loader/page-dismissal-modal-dialogs.html (152940 => 152941)
--- trunk/LayoutTests/fast/loader/page-dismissal-modal-dialogs.html 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/loader/page-dismissal-modal-dialogs.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,5 +1,9 @@
<!DOCTYPE html>
-<html><head><meta charset=utf-8><title>Page Dismissal Modal Dialogs mainFrame</title><script>
+<html>
+<head>
+<meta charset=utf-8>
+<title>Page Dismissal Modal Dialogs mainFrame</title>
+<script>
function showMessages(event) {
alert(event + " PASS");
confirm(event + " PASS");
@@ -27,13 +31,17 @@
}
location = "resources/pass-and-notify-done.html";
}, false);
-</script></head><body><div>
+</script>
+</head>
+<body>
+<div>
+<span _onclick_="showMessages('mainFrame click');" id=anchor>anchor</span>
+<iframe src=""
-<span _onclick_="showMessages('mainFrame click')" id=anchor>anchor</span>
-<iframe src=""
-
This page registers handlers for various types of unload events and attempts to
popup modal dialogs through various _javascript_ calls in each of them. Also, it
does the same thing in an iframe. In addition, it tries to popup dialogs in the
context of one frame when running a handler in the other frame.
-</div></body></html>
+</div>
+</body>
+</html>
Modified: trunk/LayoutTests/fast/loader/recursive-before-unload-crash-expected.txt (152940 => 152941)
--- trunk/LayoutTests/fast/loader/recursive-before-unload-crash-expected.txt 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/loader/recursive-before-unload-crash-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,5 +1,3 @@
-ALERT: onbeforeunload called, and iframe hasn't been added yet.
-ALERT: Adding iframe
This test demonstrates a problem with our handling of the beforeunload event.
If a script manages to try and navigate the frame from beforeunload - when a navigation is already pending - we end up blowing out the stack by recursively consulting the policy delegate then running onbeforeunload repeatedly.
After this happens, the FrameLoader is in a bogus state where it thinks it is in the middle of a provisional load, but it doesn't have a provisional document loader.
@@ -7,4 +5,6 @@
This was reproducibly identified on sears.com following a bizarre Safari specific code path.
Click here to run the beforeunload test and blow out the stack
Click here to append an iframe and crash
+onbeforeunload called, and iframe hasn't been added yet.
+Adding iframe.
Modified: trunk/LayoutTests/fast/loader/recursive-before-unload-crash.html (152940 => 152941)
--- trunk/LayoutTests/fast/loader/recursive-before-unload-crash.html 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/LayoutTests/fast/loader/recursive-before-unload-crash.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -8,7 +8,7 @@
window._onbeforeunload_ = function() {
if (!haveAddedIFrame)
- alert("onbeforeunload called, and iframe hasn't been added yet.");
+ document.getElementById("logger").innerText += "onbeforeunload called, and iframe hasn't been added yet.\n";
var a = document.createEvent("MouseEvents");
a.initEvent("click", true, true);
var d = document.createElement("a");
@@ -21,7 +21,7 @@
}
function addiframe() {
- alert("Adding iframe");
+ document.getElementById("logger").innerText += "Adding iframe.\n";
var frame = document.createElement("iframe");
frame.src = ""
document.body.appendChild(frame);
@@ -44,4 +44,5 @@
This was reproducibly identified on sears.com following a bizarre Safari specific code path.<br>
<a href="" here to run the beforeunload test and blow out the stack</a><br>
<a href="" here to append an iframe and crash</a><br>
+<div id="logger"></div>
</body>
Added: trunk/LayoutTests/fast/loader/resources/iframe-with-beforeunload.html (0 => 152941)
--- trunk/LayoutTests/fast/loader/resources/iframe-with-beforeunload.html (rev 0)
+++ trunk/LayoutTests/fast/loader/resources/iframe-with-beforeunload.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,7 @@
+<script>
+window._onbeforeunload_ = function()
+{
+ return "This is beforeunload from an iframe.";
+}
+</script>
+This is an iframe with a beforeunload handler.
Added: trunk/LayoutTests/fast/loader/show-only-one-beforeunload-dialog-expected.txt (0 => 152941)
--- trunk/LayoutTests/fast/loader/show-only-one-beforeunload-dialog-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/loader/show-only-one-beforeunload-dialog-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,4 @@
+CONFIRM NAVIGATION: This is beforeunload from the top level frame.
+CONSOLE MESSAGE: Blocked attempt to show multiple beforeunload confirmation dialogs for the same navigation.
+CONSOLE MESSAGE: Blocked attempt to show multiple beforeunload confirmation dialogs for the same navigation.
+
Added: trunk/LayoutTests/fast/loader/show-only-one-beforeunload-dialog.html (0 => 152941)
--- trunk/LayoutTests/fast/loader/show-only-one-beforeunload-dialog.html (rev 0)
+++ trunk/LayoutTests/fast/loader/show-only-one-beforeunload-dialog.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,25 @@
+<script>
+
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+}
+
+window._onload_ = function()
+{
+ window.setTimeout("window.location.href = '';", 0);
+}
+
+window._onbeforeunload_ = function()
+{
+ return "This is beforeunload from the top level frame.";
+}
+
+</script>
+<body>
+This page has multiple iframes, each trying to bring up a beforeunload dialog.<br>
+This page also has a beforeunload dialog, itself.<br>
+Only the dialog from this top-level frame should display, and none of the iframe ones should display.<br>
+<iframe src=""
+<iframe src=""
+</body>
Added: trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin-expected.txt (0 => 152941)
--- trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,2 @@
+CONFIRM NAVIGATION: This is beforeunload from an iframe.
+
Added: trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html (0 => 152941)
--- trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html (rev 0)
+++ trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,18 @@
+<script>
+
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+}
+
+window._onload_ = function()
+{
+ window.setTimeout("window.location.href = '';", 0);
+}
+
+</script>
+<body>
+When viewed using the host 127.0.0.1, this page has an iframe whose security origin matches the main frame.<br>
+The iframe has a beforeunload handler, and that handler should result in the display of the page dismissal dialog.<br>
+<iframe src=""
+</body>
Added: trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin-expected.txt (0 => 152941)
--- trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin-expected.txt 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: Blocked attempt to show beforeunload confirmation dialog on behalf of a frame with different security origin. Protocols, domains, and ports must match.
+
Added: trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html (0 => 152941)
--- trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html (rev 0)
+++ trunk/LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,18 @@
+<script>
+
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+}
+
+window._onload_ = function()
+{
+ window.setTimeout("window.location.href = '';", 0);
+}
+
+</script>
+<body>
+When viewed using the host 127.0.0.1, this page has an iframe whose security origin is different from the main frame.<br>
+The iframe has a beforeunload handler, and that handler should not result in the display of the page dismissal dialog since the security origins differ.<br>
+<iframe src=""
+</body>
Added: trunk/LayoutTests/http/tests/misc/resources/iframe-with-beforeunload.html (0 => 152941)
--- trunk/LayoutTests/http/tests/misc/resources/iframe-with-beforeunload.html (rev 0)
+++ trunk/LayoutTests/http/tests/misc/resources/iframe-with-beforeunload.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,7 @@
+<script>
+window._onbeforeunload_ = function()
+{
+ return "This is beforeunload from an iframe.";
+}
+</script>
+This is an iframe with a beforeunload handler.
Added: trunk/LayoutTests/http/tests/misc/resources/notify-done.html (0 => 152941)
--- trunk/LayoutTests/http/tests/misc/resources/notify-done.html (rev 0)
+++ trunk/LayoutTests/http/tests/misc/resources/notify-done.html 2013-07-20 06:43:51 UTC (rev 152941)
@@ -0,0 +1,4 @@
+<script>
+if (window.testRunner)
+ testRunner.notifyDone();
+</script>
Modified: trunk/Source/WebCore/ChangeLog (152940 => 152941)
--- trunk/Source/WebCore/ChangeLog 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/Source/WebCore/ChangeLog 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1,3 +1,39 @@
+2013-07-19 Brady Eidson <[email protected]>
+
+ Pages should not be able to abuse users inside beforeunload handlers.
+ <rdar://problem/14475779> and https://bugs.webkit.org/show_bug.cgi?id=118871.
+
+ Reviewed by Alexey Proskuryakov.
+
+ Tests: fast/loader/show-only-one-beforeunload-dialog.html
+ http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html
+ http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html
+
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::FrameLoader):
+ (WebCore::FrameLoader::shouldClose):
+ (WebCore::FrameLoader::handleBeforeUnloadEvent):
+ (WebCore::FrameLoader::shouldCloseFiringBeforeUnloadEvent): Renamed from fireBeforeUnloadEvent.
+ Add logic to enforce "1 beforeunload dialog per navigation" as well as "iframes can only show beforeunload
+ dialogs if their entire ancestry's security origins match the navigating frame."
+ * loader/FrameLoader.h:
+ * loader/FrameLoader.h:
+
+ Add the ability for Page to know when any frame is dispatching beforeunload:
+ * page/Page.cpp:
+ (WebCore::Page::Page):
+ (WebCore::Page::incrementFrameHandlingBeforeUnloadEventCount):
+ (WebCore::Page::decrementFrameHandlingBeforeUnloadEventCount):
+ (WebCore::Page::isAnyFrameHandlingBeforeUnloadEvent):
+ * page/Page.h:
+
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::print): Disallow if any frame is in beforeunload dispatch.
+ (WebCore::DOMWindow::alert): Ditto.
+ (WebCore::DOMWindow::confirm): Ditto.
+ (WebCore::DOMWindow::prompt): Ditto.
+ (WebCore::DOMWindow::showModalDialog): Ditto.
+
2013-07-19 Chris Fleizach <[email protected]>
AX: VoiceOver not detecting misspelled words don't work in all cases
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (152940 => 152941)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2013-07-20 06:43:51 UTC (rev 152941)
@@ -237,6 +237,7 @@
, m_didPerformFirstNavigation(false)
, m_loadingFromCachedPage(false)
, m_suppressOpenerInNewFrame(false)
+ , m_currentNavigationHasShownBeforeUnloadConfirmPanel(false)
, m_forcedSandboxFlags(SandboxNone)
{
}
@@ -2740,7 +2741,7 @@
for (i = 0; i < targetFrames.size(); i++) {
if (!targetFrames[i]->tree()->isDescendantOf(m_frame))
continue;
- if (!targetFrames[i]->loader()->fireBeforeUnloadEvent(page->chrome()))
+ if (!targetFrames[i]->loader()->handleBeforeUnloadEvent(page->chrome(), this))
break;
}
@@ -2751,10 +2752,11 @@
if (!shouldClose)
m_submittedFormURL = KURL();
+ m_currentNavigationHasShownBeforeUnloadConfirmPanel = false;
return shouldClose;
}
-bool FrameLoader::fireBeforeUnloadEvent(Chrome& chrome)
+bool FrameLoader::handleBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLoaderBeingNavigated)
{
DOMWindow* domWindow = m_frame->document()->domWindow();
if (!domWindow)
@@ -2763,10 +2765,16 @@
RefPtr<Document> document = m_frame->document();
if (!document->body())
return true;
-
+
RefPtr<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create();
m_pageDismissalEventBeingDispatched = BeforeUnloadDismissal;
+
+ // 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();
+
m_pageDismissalEventBeingDispatched = NoDismissal;
if (!beforeUnloadEvent->defaultPrevented())
@@ -2774,6 +2782,39 @@
if (beforeUnloadEvent->result().isNull())
return true;
+ // If the navigating FrameLoader has already shown a beforeunload confirmation panel for the current navigation attempt,
+ // this frame is not allowed to cause another one to be shown.
+ if (frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel) {
+ document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Blocked attempt to show multiple beforeunload confirmation dialogs for the same navigation.");
+ return true;
+ }
+
+ // We should only display the beforeunload dialog for an iframe if its SecurityOrigin matches all
+ // ancestor frame SecurityOrigins up through the navigating FrameLoader.
+ if (frameLoaderBeingNavigated != this) {
+ Frame* parentFrame = m_frame->tree()->parent();
+ while (parentFrame) {
+ Document* parentDocument = parentFrame->document();
+ if (!parentDocument)
+ return true;
+ if (!m_frame->document() || !m_frame->document()->securityOrigin()->canAccess(parentDocument->securityOrigin())) {
+ document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Blocked attempt to show beforeunload confirmation dialog on behalf of a frame with different security origin. Protocols, domains, and ports must match.");
+ return true;
+ }
+
+ if (parentFrame->loader() == frameLoaderBeingNavigated)
+ break;
+
+ parentFrame = parentFrame->tree()->parent();
+ }
+
+ // The navigatingFrameLoader should always be in our ancestory.
+ ASSERT(parentFrame);
+ ASSERT(parentFrame->loader() == frameLoaderBeingNavigated);
+ }
+
+ frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel = true;
+
String text = document->displayStringModifiedByEncoding(beforeUnloadEvent->result());
return chrome.runBeforeUnloadConfirmPanel(text, m_frame);
}
Modified: trunk/Source/WebCore/loader/FrameLoader.h (152940 => 152941)
--- trunk/Source/WebCore/loader/FrameLoader.h 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/Source/WebCore/loader/FrameLoader.h 2013-07-20 06:43:51 UTC (rev 152941)
@@ -319,7 +319,7 @@
static void callContinueLoadAfterNewWindowPolicy(void*, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName, const NavigationAction&, bool shouldContinue);
static void callContinueFragmentScrollAfterNavigationPolicy(void*, const ResourceRequest&, PassRefPtr<FormState>, bool shouldContinue);
- bool fireBeforeUnloadEvent(Chrome&);
+ bool handleBeforeUnloadEvent(Chrome&, FrameLoader* frameLoaderBeingNavigated);
void continueLoadAfterNavigationPolicy(const ResourceRequest&, PassRefPtr<FormState>, bool shouldContinue);
void continueLoadAfterNewWindowPolicy(const ResourceRequest&, PassRefPtr<FormState>, const String& frameName, const NavigationAction&, bool shouldContinue);
@@ -440,6 +440,8 @@
bool m_didPerformFirstNavigation;
bool m_loadingFromCachedPage;
bool m_suppressOpenerInNewFrame;
+
+ bool m_currentNavigationHasShownBeforeUnloadConfirmPanel;
SandboxFlags m_forcedSandboxFlags;
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (152940 => 152941)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2013-07-20 06:43:51 UTC (rev 152941)
@@ -1011,6 +1011,12 @@
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.");
+ return;
+ }
+
if (m_frame->loader()->activeDocumentLoader()->isLoading()) {
m_shouldPrintWhenFinishedLoading = true;
return;
@@ -1034,6 +1040,12 @@
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.");
+ return;
+ }
+
m_frame->document()->updateStyleIfNeeded();
Page* page = m_frame->page();
@@ -1047,6 +1059,12 @@
{
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.");
+ return false;
+ }
m_frame->document()->updateStyleIfNeeded();
@@ -1062,6 +1080,12 @@
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.");
+ return String();
+ }
+
m_frame->document()->updateStyleIfNeeded();
Page* page = m_frame->page();
@@ -1994,6 +2018,12 @@
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.");
+ return;
+ }
+
if (!canShowModalDialogNow(m_frame) || !firstWindow->allowPopUp())
return;
Modified: trunk/Source/WebCore/page/Page.cpp (152940 => 152941)
--- trunk/Source/WebCore/page/Page.cpp 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/Source/WebCore/page/Page.cpp 2013-07-20 06:43:51 UTC (rev 152941)
@@ -187,6 +187,7 @@
, m_scriptedAnimationsSuspended(false)
, m_pageThrottler(PageThrottler::create(this))
, m_console(PageConsole::create(this))
+ , m_framesHandlingBeforeUnloadEvent(0)
{
ASSERT(m_editorClient);
@@ -1569,6 +1570,22 @@
}
#endif
+void Page::incrementFrameHandlingBeforeUnloadEventCount()
+{
+ ++m_framesHandlingBeforeUnloadEvent;
+}
+
+void Page::decrementFrameHandlingBeforeUnloadEventCount()
+{
+ ASSERT(m_framesHandlingBeforeUnloadEvent);
+ --m_framesHandlingBeforeUnloadEvent;
+}
+
+bool Page::isAnyFrameHandlingBeforeUnloadEvent()
+{
+ return m_framesHandlingBeforeUnloadEvent;
+}
+
Page::PageClients::PageClients()
: alternativeTextClient(0)
, chromeClient(0)
Modified: trunk/Source/WebCore/page/Page.h (152940 => 152941)
--- trunk/Source/WebCore/page/Page.h 2013-07-20 06:42:18 UTC (rev 152940)
+++ trunk/Source/WebCore/page/Page.h 2013-07-20 06:43:51 UTC (rev 152941)
@@ -406,6 +406,10 @@
void captionPreferencesChanged();
#endif
+ void incrementFrameHandlingBeforeUnloadEventCount();
+ void decrementFrameHandlingBeforeUnloadEventCount();
+ bool isAnyFrameHandlingBeforeUnloadEvent();
+
private:
void initGroup();
@@ -542,6 +546,8 @@
HashSet<String> m_seenPlugins;
HashSet<String> m_seenMediaEngines;
+
+ unsigned m_framesHandlingBeforeUnloadEvent;
};
inline PageGroup& Page::group()