Changeset 267614 in webkit


Ignore:
Timestamp:
Sep 25, 2020 5:50:00 PM (4 years ago)
Author:
Chris Dumez
Message:

visibilitychange:hidden doesn't fire during page navigations
https://bugs.webkit.org/show_bug.cgi?id=151234
<rdar://problem/23688763>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Import page-visibility WPT tests from upstream.

  • resources/import-expectations.json:
  • web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window-expected.txt:
  • web-platform-tests/page-visibility/*: Added.

Source/WebCore:

Fire a visibilitychange during document unload, as per the specification:

Note that the specification currently says to fire the visibilitychange event before the pagehide event.
However, Both Chrome and Firefox fire the pagehide event then the visibilitychange event. This change
aligns our behavior with both Chrome and Firefox. The following bug has been filed against the
specification:

We also fire a visibilitychange event when coming out of the back/forward cache. This makes sense given
that we fire one when the document enters the back/forward cache. This is also Firefox's behavior.
I have verified that the new fast/history/back-forward-cache-visibility-state.html layout test is passing
in Firefox.

Tests: fast/history/back-forward-cache-visibility-state.html

imported/w3c/web-platform-tests/page-visibility/idlharness.window.html
imported/w3c/web-platform-tests/page-visibility/iframe-unload.html
imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html
imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html
imported/w3c/web-platform-tests/page-visibility/test_child_document.html
imported/w3c/web-platform-tests/page-visibility/test_default_view.html
imported/w3c/web-platform-tests/page-visibility/test_read_only.html
imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html
imported/w3c/web-platform-tests/page-visibility/unload.html

  • dom/Document.cpp:

(WebCore::Document::visibilityState const):
(WebCore::Document::setHiddenDueToDismissal):

  • dom/Document.h:
  • history/CachedPage.cpp:

(WebCore::firePageShowAndPopStateEvents):

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::dispatchUnloadEvents):

LayoutTests:

Add test coverage for the visibilitychange event and document.visibilitystate when entering
and coming out of the back/forward cache.

  • fast/history/back-forward-cache-visibility-state-expected.txt: Added.
  • fast/history/back-forward-cache-visibility-state.html: Added.
Location:
trunk
Files:
32 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r267613 r267614  
     12020-09-25  Chris Dumez  <cdumez@apple.com>
     2
     3        visibilitychange:hidden doesn't fire during page navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=151234
     5        <rdar://problem/23688763>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add test coverage for the visibilitychange event and document.visibilitystate when entering
     10        and coming out of the back/forward cache.
     11
     12        * fast/history/back-forward-cache-visibility-state-expected.txt: Added.
     13        * fast/history/back-forward-cache-visibility-state.html: Added.
     14
    1152020-09-25  James Darpinian  <jdarpinian@chromium.org>
    216
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r267593 r267614  
     12020-09-25  Chris Dumez  <cdumez@apple.com>
     2
     3        visibilitychange:hidden doesn't fire during page navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=151234
     5        <rdar://problem/23688763>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Import page-visibility WPT tests from upstream.
     10
     11        * resources/import-expectations.json:
     12        * web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window-expected.txt:
     13        * web-platform-tests/page-visibility/*: Added.
     14
    1152020-09-25  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/resources/import-expectations.json

    r267593 r267614  
    337337    "web-platform-tests/orientation-event": "skip",
    338338    "web-platform-tests/orientation-sensor": "skip",
    339     "web-platform-tests/page-visibility": "skip",
     339    "web-platform-tests/page-visibility": "import",
    340340    "web-platform-tests/paint-timing": "skip",
    341341    "web-platform-tests/payment-handler": "skip",
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window-expected.txt

    r267593 r267614  
    11CONSOLE MESSAGE: Error: assert_equals: expected no popup during pagehide expected null but got object "[object Window]"
     2CONSOLE MESSAGE: Error: assert_equals: expected no popup during visibilitychange expected null but got object "[object Window]"
    23CONSOLE MESSAGE: Error: assert_equals: expected no popup during unload expected null but got object "[object Window]"
    34
  • trunk/Source/WebCore/ChangeLog

    r267613 r267614  
     12020-09-25  Chris Dumez  <cdumez@apple.com>
     2
     3        visibilitychange:hidden doesn't fire during page navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=151234
     5        <rdar://problem/23688763>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Fire a visibilitychange during document unload, as per the specification:
     10        - https://www.w3.org/TR/page-visibility/#reacting-to-visibilitychange-changes
     11        - https://html.spec.whatwg.org/multipage/browsing-the-web.html#unloading-document-visibility-change-steps
     12
     13        Note that the specification currently says to fire the visibilitychange event before the pagehide event.
     14        However, Both Chrome and Firefox fire the pagehide event then the visibilitychange event. This change
     15        aligns our behavior with both Chrome and Firefox. The following bug has been filed against the
     16        specification:
     17        - https://github.com/w3c/page-visibility/issues/67
     18
     19        We also fire a visibilitychange event when coming out of the back/forward cache. This makes sense given
     20        that we fire one when the document enters the back/forward cache. This is also Firefox's behavior.
     21        I have verified that the new fast/history/back-forward-cache-visibility-state.html layout test is passing
     22        in Firefox.
     23
     24        Tests: fast/history/back-forward-cache-visibility-state.html
     25               imported/w3c/web-platform-tests/page-visibility/idlharness.window.html
     26               imported/w3c/web-platform-tests/page-visibility/iframe-unload.html
     27               imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html
     28               imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html
     29               imported/w3c/web-platform-tests/page-visibility/test_child_document.html
     30               imported/w3c/web-platform-tests/page-visibility/test_default_view.html
     31               imported/w3c/web-platform-tests/page-visibility/test_read_only.html
     32               imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html
     33               imported/w3c/web-platform-tests/page-visibility/unload.html
     34
     35        * dom/Document.cpp:
     36        (WebCore::Document::visibilityState const):
     37        (WebCore::Document::setHiddenDueToDismissal):
     38        * dom/Document.h:
     39        * history/CachedPage.cpp:
     40        (WebCore::firePageShowAndPopStateEvents):
     41        * loader/FrameLoader.cpp:
     42        (WebCore::FrameLoader::dispatchUnloadEvents):
     43
    1442020-09-25  James Darpinian  <jdarpinian@chromium.org>
    245
  • trunk/Source/WebCore/dom/Document.cpp

    r267611 r267614  
    17731773    // that the page is hidden, as specified by the spec:
    17741774    // https://w3c.github.io/page-visibility/#visibilitystate-attribute
    1775     if (!m_frame || !m_frame->page())
     1775    if (!m_frame || !m_frame->page() || m_visibilityHiddenDueToDismissal)
    17761776        return VisibilityState::Hidden;
    17771777    return m_frame->page()->visibilityState();
     
    32583258}
    32593259
     3260void Document::setVisibilityHiddenDueToDismissal(bool hiddenDueToDismissal)
     3261{
     3262    if (m_visibilityHiddenDueToDismissal == hiddenDueToDismissal)
     3263        return;
     3264
     3265    m_visibilityHiddenDueToDismissal = hiddenDueToDismissal;
     3266    dispatchEvent(Event::create(eventNames().visibilitychangeEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
     3267}
     3268
    32603269Seconds Document::domTimerAlignmentInterval(bool hasReachedMaxNestingLevel) const
    32613270{
  • trunk/Source/WebCore/dom/Document.h

    r267593 r267614  
    492492    bool isTimerThrottlingEnabled() const { return m_isTimerThrottlingEnabled; }
    493493
     494    void setVisibilityHiddenDueToDismissal(bool);
     495
    494496    WEBCORE_EXPORT ExceptionOr<Ref<Node>> adoptNode(Node& source);
    495497
     
    21292131    bool m_hasVisuallyNonEmptyCustomContent { false };
    21302132
     2133    bool m_visibilityHiddenDueToDismissal { false };
     2134
    21312135    Ref<UndoManager> m_undoManager;
    21322136#if PLATFORM(IOS_FAMILY)
  • trunk/Source/WebCore/history/CachedPage.cpp

    r266061 r267614  
    9393            continue;
    9494
    95         // FIXME: Update Page Visibility state here.
    96         // https://bugs.webkit.org/show_bug.cgi?id=116770
     95        // This takes care of firing the visibilitychange event and making sure the document is reported as visible.
     96        document->setVisibilityHiddenDueToDismissal(false);
     97
    9798        document->dispatchPageshowEvent(PageshowEventPersisted);
    9899
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r267593 r267614  
    32813281            }
    32823282
    3283             // FIXME: update Page Visibility state here.
    3284             // https://bugs.webkit.org/show_bug.cgi?id=116770
     3283            // This takes care of firing the visibilitychange event and making sure the document is reported as hidden.
     3284            m_frame.document()->setVisibilityHiddenDueToDismissal(true);
    32853285
    32863286            if (m_frame.document()->backForwardCacheState() == Document::NotInBackForwardCache) {
Note: See TracChangeset for help on using the changeset viewer.