-
rniwa@webkit.org authored
Reviewed by Adam Barth. onbeforeunload is broken for framesets https://bugs.webkit.org/show_bug.cgi?id=19418 Added beforeunload event support for sub frames. WebKit's implementation tries to match that of Internet Explorer as much as possible. beforeunload event is fired for each and every descendent of a frame that is about to navigate. When a value other than null is returned by a beforeunload handler, a confirmation dialog is shown for each handler (calls chrome's runBeforeUnloadConfirmPanel) just like it is done for main frames. In addition, navigation is forbidden while beforeunload handlers are being called. Setting values to location.href, location.reload, and other means of navigations are thus ignored while beforeunload event handler is being ran, matching Internet Explorer's behavior. Because navigation needs to prevented globally, NavigationDisablerForBeforeUnload is added to NavigationScheduler.h, which is instantiated as a RAII object in FrameLoader::shouldClose. Tests: fast/events/before-unload-adopt-subframe-to-outside.html fast/events/before-unload-adopt-within-subframes.html fast/events/before-unload-forbidden-navigation.html fast/events/before-unload-in-multiple-subframes.html fast/events/before-unload-in-subframe.html fast/events/before-unload-javascript-navigation.html fast/events/before-unload-remove-and-add-subframe.html fact/events/before-unload-remove-itself.html fast/events/before-unload-with-subframes.html * loader/FrameLoader.cpp: (WebCore::FrameLoader::shouldClose): Calls fireBeforeUnloadEvent on m_frame and m_frame's descendents. Returns true only if every call to fireBeforeUnloadEvent returned true. (WebCore::FrameLoader::fireBeforeUnloadEvent): Fires a beforeunload event and calls chrome's runBeforeUnloadConfirmPanel as needed. (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): Calls shouldClose for all frames. * loader/FrameLoader.h: * loader/NavigationScheduler.cpp: (WebCore::NavigationScheduler::shouldScheduleNavigation): Checks the nullity of Page and calls NavigationDisablerForBeforeUnload::isNavigationAllowed when url is not javascript scheme. (WebCore::NavigationScheduler::scheduleRedirect): Calls shouldScheduleNavigation. (WebCore::NavigationScheduler::scheduleLocationChange): Ditto. (WebCore::NavigationScheduler::scheduleRefresh): Ditto. (WebCore::NavigationScheduler::scheduleHistoryNavigation): Ditto. * loader/NavigationScheduler.h: (WebCore::NavigationDisablerForBeforeUnload::NavigationDisablerForBeforeUnload): Disables navigation. (WebCore::NavigationDisablerForBeforeUnload::~NavigationDisablerForBeforeUnload): Enables navigation when called on the last instance of NavigationDisablerForBeforeUnload. (WebCore::NavigationDisablerForBeforeUnload::isNavigationAllowed): Returns true if there are no instance of NavigationDisablerForBeforeUnload left on the stack. 2011-01-06 Ryosuke Niwa <rniwa@webkit.org> Reviewed by Adam Barth. onbeforeunload is broken for framesets https://bugs.webkit.org/show_bug.cgi?id=19418 Added tests to ensure WebKit fires beforeunload events for subframes, and disallows navigation except that of javascript scheme while beforeunload event handlers are being called. Also added a test to ensure WebKit fires beforeunload event for subframes exactly once even if a subframe was moved around within a beforeunload event handler. A test that ensures beforeunload event is not fired for an iframe if the iframe was added or removed within a beforeunload event handler is also added. Furthermore, a test to ensure WebKit does not fire a beforeunload event to an iframe that has been adopted by a document outside of the unloading document is added. * fast/events/before-unload-adopt-subframe-to-outside-expected.txt: Added. * fast/events/before-unload-adopt-subframe-to-outside.html: Added. * fast/events/before-unload-adopt-within-subframes-expected.txt: Added. * fast/events/before-unload-adopt-within-subframes.html: Added. * fast/events/before-unload-forbidden-navigation-expected.txt: Added. * fast/events/before-unload-forbidden-navigation.html: Added. * fast/events/before-unload-in-multiple-subframes-expected.txt: Added. * fast/events/before-unload-in-multiple-subframes.html: Added. * fast/events/before-unload-in-subframe-expected.txt: Added. * fast/events/before-unload-in-subframe.html: Added. * fast/events/before-unload-javascript-navigation-expected.txt: Added. * fast/events/before-unload-javascript-navigation.html: Added. * fast/events/before-unload-remove-and-add-subframe-expected.txt: Added. * fast/events/before-unload-remove-and-add-subframe.html: Added. * fact/events/before-unload-remove-itself-expected.txt: Added. * fact/events/before-unload-remove-itself.html: Added. * fast/events/before-unload-with-subframes-expected.txt: Added. * fast/events/before-unload-with-subframes.html: Added. * fast/events/resources/before-unload-in-subframe-child.html: Added. * fast/events/resources/before-unload-in-subframe-destination.html: Added. * fast/events/resources/before-unload-in-subframe-fail.html: Added. * fast/events/resources/before-unload-with-subframes-parent.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75305 268f45cc-cd09-0410-ab3c-d52691b4dbfc
cf46007a