Changeset 214365 in webkit


Ignore:
Timestamp:
Mar 24, 2017 12:34:11 PM (7 years ago)
Author:
dbates@webkit.org
Message:

Prevent new navigations during document unload
https://bugs.webkit.org/show_bug.cgi?id=169934
<rdar://problem/31247584>

Reviewed by Chris Dumez.

Source/WebCore:

Similar to our policy of preventing new navigations from onbeforeunload handlers
we should prevent new navigations that are initiated during the document unload
process.

The significant part of this change is the instantiation of the RAII object NavigationDisabler
in Document::prepareForDestruction(). The rest of this change just renames class
NavigationDisablerForBeforeUnload to NavigationDisabler now that this RAII class is
used to prevent navigation from both onbeforeunload event handlers and when unloading
a document.

Test: fast/frames/frame-unload-navigate-and-setTimeout-assert-fail.html

  • dom/Document.cpp:

(WebCore::Document::prepareForDestruction): Disable new navigations when disconnecting
subframes. Also assert that the document is not in the page cache before we fall off
the end of the function.

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::isNavigationAllowed): Update for renaming below.
(WebCore::FrameLoader::shouldClose): Ditto.

  • loader/NavigationScheduler.cpp:

(WebCore::NavigationScheduler::shouldScheduleNavigation): Ditto.

  • loader/NavigationScheduler.h:

(WebCore::NavigationDisabler::NavigationDisabler): Renamed class; formerly named NavigationDisablerForBeforeUnload.
(WebCore::NavigationDisabler::~NavigationDisabler): Ditto.
(WebCore::NavigationDisabler::isNavigationAllowed): Ditto.
(WebCore::NavigationDisablerForBeforeUnload::NavigationDisablerForBeforeUnload): Deleted.
(WebCore::NavigationDisablerForBeforeUnload::~NavigationDisablerForBeforeUnload): Deleted.
(WebCore::NavigationDisablerForBeforeUnload::isNavigationAllowed): Deleted.

LayoutTests:

Add a test to ensure that we do not cause an assertion fail when calling setTimeout
after starting a navigation from an onunload event handler.

  • fast/frames/frame-unload-navigate-and-setTimeout-assert-fail-expected.txt: Added.
  • fast/frames/frame-unload-navigate-and-setTimeout-assert-fail.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r214364 r214365  
     12017-03-24  Daniel Bates  <dabates@apple.com>
     2
     3        Prevent new navigations during document unload
     4        https://bugs.webkit.org/show_bug.cgi?id=169934
     5        <rdar://problem/31247584>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Add a test to ensure that we do not cause an assertion fail when calling setTimeout
     10        after starting a navigation from an onunload event handler.
     11
     12        * fast/frames/frame-unload-navigate-and-setTimeout-assert-fail-expected.txt: Added.
     13        * fast/frames/frame-unload-navigate-and-setTimeout-assert-fail.html: Added.
     14
    1152017-03-24  Myles C. Maxfield  <mmaxfield@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r214364 r214365  
     12017-03-24  Daniel Bates  <dabates@apple.com>
     2
     3        Prevent new navigations during document unload
     4        https://bugs.webkit.org/show_bug.cgi?id=169934
     5        <rdar://problem/31247584>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Similar to our policy of preventing new navigations from onbeforeunload handlers
     10        we should prevent new navigations that are initiated during the document unload
     11        process.
     12
     13        The significant part of this change is the instantiation of the RAII object NavigationDisabler
     14        in Document::prepareForDestruction(). The rest of this change just renames class
     15        NavigationDisablerForBeforeUnload to NavigationDisabler now that this RAII class is
     16        used to prevent navigation from both onbeforeunload event handlers and when unloading
     17        a document.
     18
     19        Test: fast/frames/frame-unload-navigate-and-setTimeout-assert-fail.html
     20
     21        * dom/Document.cpp:
     22        (WebCore::Document::prepareForDestruction): Disable new navigations when disconnecting
     23        subframes. Also assert that the document is not in the page cache before we fall off
     24        the end of the function.
     25        * loader/FrameLoader.cpp:
     26        (WebCore::FrameLoader::isNavigationAllowed): Update for renaming below.
     27        (WebCore::FrameLoader::shouldClose): Ditto.
     28        * loader/NavigationScheduler.cpp:
     29        (WebCore::NavigationScheduler::shouldScheduleNavigation): Ditto.
     30        * loader/NavigationScheduler.h:
     31        (WebCore::NavigationDisabler::NavigationDisabler): Renamed class; formerly named NavigationDisablerForBeforeUnload.
     32        (WebCore::NavigationDisabler::~NavigationDisabler): Ditto.
     33        (WebCore::NavigationDisabler::isNavigationAllowed): Ditto.
     34        (WebCore::NavigationDisablerForBeforeUnload::NavigationDisablerForBeforeUnload): Deleted.
     35        (WebCore::NavigationDisablerForBeforeUnload::~NavigationDisablerForBeforeUnload): Deleted.
     36        (WebCore::NavigationDisablerForBeforeUnload::isNavigationAllowed): Deleted.
     37
    1382017-03-24  Myles C. Maxfield  <mmaxfield@apple.com>
    239
  • trunk/Source/WebCore/dom/Document.cpp

    r214361 r214365  
    22252225    }
    22262226#endif
    2227    
    2228     disconnectDescendantFrames();
     2227
     2228    {
     2229        NavigationDisabler navigationDisabler;
     2230        disconnectDescendantFrames();
     2231    }
     2232
    22292233    if (m_domWindow && m_frame)
    22302234        m_domWindow->willDetachDocumentFromFrame();
     
    22822286
    22832287    m_hasPreparedForDestruction = true;
     2288
     2289    // Note that m_pageCacheState can be Document::AboutToEnterPageCache if our frame
     2290    // was removed in an onpagehide event handler fired when the top-level frame is
     2291    // about to enter the page cache.
     2292    ASSERT_WITH_SECURITY_IMPLICATION(m_pageCacheState != Document::InPageCache);
    22842293}
    22852294
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r214277 r214365  
    12131213bool FrameLoader::isNavigationAllowed() const
    12141214{
    1215     return m_pageDismissalEventBeingDispatched == PageDismissalType::None && NavigationDisablerForBeforeUnload::isNavigationAllowed();
     1215    return m_pageDismissalEventBeingDispatched == PageDismissalType::None && NavigationDisabler::isNavigationAllowed();
    12161216}
    12171217
     
    29912991    bool shouldClose = false;
    29922992    {
    2993         NavigationDisablerForBeforeUnload navigationDisabler;
     2993        NavigationDisabler navigationDisabler;
    29942994        size_t i;
    29952995
  • trunk/Source/WebCore/loader/NavigationScheduler.cpp

    r212250 r214365  
    5656namespace WebCore {
    5757
    58 unsigned NavigationDisablerForBeforeUnload::s_navigationDisableCount = 0;
     58unsigned NavigationDisabler::s_navigationDisableCount = 0;
    5959
    6060class ScheduledNavigation {
     
    365365    if (protocolIsJavaScript(url))
    366366        return true;
    367     return NavigationDisablerForBeforeUnload::isNavigationAllowed();
     367    return NavigationDisabler::isNavigationAllowed();
    368368}
    369369
  • trunk/Source/WebCore/loader/NavigationScheduler.h

    r210859 r214365  
    4444class URL;
    4545
    46 class NavigationDisablerForBeforeUnload {
     46class NavigationDisabler {
    4747public:
    48     NavigationDisablerForBeforeUnload()
     48    NavigationDisabler()
    4949    {
    5050        s_navigationDisableCount++;
    5151    }
    52     ~NavigationDisablerForBeforeUnload()
     52    ~NavigationDisabler()
    5353    {
    5454        ASSERT(s_navigationDisableCount);
Note: See TracChangeset for help on using the changeset viewer.