alert, confirm, prompt, showModalDialog should be forbidden during page close and...
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2015 22:19:44 +0000 (22:19 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2015 22:19:44 +0000 (22:19 +0000)
commitf3e45d08bf0717f5c042c4cbb3ee9b4cb9844192
treef99c2adee8ea26430a79c3496ee0059450155e5f
parent9052079694c0a4fff2dfb61749992680a0f73ebd
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.

Source/WebCore:

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:

LayoutTests:

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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192270 268f45cc-cd09-0410-ab3c-d52691b4dbfc
43 files changed:
LayoutTests/ChangeLog
LayoutTests/compositing/iframes/page-cache-layer-tree-expected.txt
LayoutTests/fast/dom/Geolocation/notimer-after-unload-expected.txt
LayoutTests/fast/events/beforeunload-alert-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-alert.html [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-confirm-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-confirm.html [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-prompt-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-prompt.html [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-showModalDialog-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-showModalDialog.html [new file with mode: 0644]
LayoutTests/fast/events/onunload-expected.txt
LayoutTests/fast/events/onunload-not-on-body-expected.txt
LayoutTests/fast/events/onunload-window-property-expected.txt
LayoutTests/fast/events/pagehide-alert-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/pagehide-alert.html [new file with mode: 0644]
LayoutTests/fast/events/pagehide-confirm-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/pagehide-confirm.html [new file with mode: 0644]
LayoutTests/fast/events/pagehide-prompt-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/pagehide-prompt.html [new file with mode: 0644]
LayoutTests/fast/events/pagehide-showModalDialog-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/pagehide-showModalDialog.html [new file with mode: 0644]
LayoutTests/fast/events/pageshow-pagehide-on-back-cached-expected.txt
LayoutTests/fast/events/pageshow-pagehide-on-back-uncached-expected.txt
LayoutTests/fast/events/resources/prompt-landing-page.html [new file with mode: 0644]
LayoutTests/fast/events/unload-alert-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/unload-alert.html [new file with mode: 0644]
LayoutTests/fast/events/unload-confirm-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/unload-confirm.html [new file with mode: 0644]
LayoutTests/fast/events/unload-prompt-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/unload-prompt.html [new file with mode: 0644]
LayoutTests/fast/events/unload-showModalDialog-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/unload-showModalDialog.html [new file with mode: 0644]
LayoutTests/fast/history/timed-refresh-in-cached-frame-expected.txt
LayoutTests/fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt
LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h