⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 281147 in webkit


Ignore:
Timestamp:
Aug 17, 2021, 10:30:54 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Document load events should update timing in PerformanceNavigationTiming even after its instantiation
​https://bugs.webkit.org/show_bug.cgi?id=229181

Patch by Alex Christensen <​achristensen@webkit.org> on 2021-08-17
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

  • web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt:

Source/WebCore:

When we make a PerformanceNavigationTiming object, we copy the DocumentLoadTiming and DocumentEventTiming values.
If PerformanceNavigationTiming is accessed before the document has finished loading, we still need to update the timing values.

Covered by a newly passing WPT test, which Chrome and Firefox already pass.

  • dom/Document.cpp:

(WebCore::Document::documentEventTimingFromNavigationTiming):
(WebCore::Document::setReadyState):
(WebCore::Document::finishedParsing):

  • dom/Document.h:
  • loader/DocumentLoadTiming.h:

(WebCore::DocumentLoadTiming::setLoadEventStart):
(WebCore::DocumentLoadTiming::setLoadEventEnd):
(WebCore::DocumentLoadTiming::markLoadEventStart): Deleted.
(WebCore::DocumentLoadTiming::markLoadEventEnd): Deleted.

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::dispatchLoadEvent):

  • page/Performance.h:
  • page/PerformanceNavigationTiming.h:

LayoutTests:

This test now always passes in WK2.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r281146 r281147  
     12021-08-17  Alex Christensen  <achristensen@webkit.org>
     2
     3        Document load events should update timing in PerformanceNavigationTiming even after its instantiation
     4        https://bugs.webkit.org/show_bug.cgi?id=229181
     5
     6        Reviewed by Chris Dumez.
     7
     8        * TestExpectations:
     9        * platform/mac-wk1/TestExpectations:
     10        This test now always passes in WK2.
     11
    1122021-08-17  Eric Hutchison  <ehutchison@apple.com>
    213
  • trunk/LayoutTests/TestExpectations

    r281125 r281147  
    11331133imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub.html [ Pass Failure ]
    11341134imported/w3c/web-platform-tests/navigation-timing/secure_connection_start_non_zero.https.html [ Pass Failure ]
    1135 imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values.html [ Pass Failure ]
    11361135imported/w3c/web-platform-tests/resource-timing/TAO-match.html [ Pass Failure ]
    11371136imported/w3c/web-platform-tests/resource-timing/iframe-failed-commit.html [ Pass Failure ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r281140 r281147  
     12021-08-17  Alex Christensen  <achristensen@webkit.org>
     2
     3        Document load events should update timing in PerformanceNavigationTiming even after its instantiation
     4        https://bugs.webkit.org/show_bug.cgi?id=229181
     5
     6        Reviewed by Chris Dumez.
     7
     8        * web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt:
     9
    1102021-08-17  Alex Christensen  <achristensen@webkit.org>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt

    r278477 r281147  
    44
    55
    6 FAIL Performance navigation timing instance's value is reasonable. assert_greater_than: Expected domInteractive to be greater than 0 expected a number greater than 0 but got 0
     6PASS Performance navigation timing instance's value is reasonable.
    77
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r281108 r281147  
    582582# NSURLConnection doesn't have an API to give us good timing for redirects. We do what we can with MonotonicTime::now() but this still fails sometimes.
    583583imported/w3c/web-platform-tests/navigation-timing/nav2_test_redirect_server.html [ Pass Failure ]
     584imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values.html [ Pass Failure ]
    584585
    585586webkit.org/b/160101 userscripts/window-onerror-for-isolated-world-3.html [ Pass Failure ]
  • trunk/Source/WebCore/ChangeLog

    r281136 r281147  
     12021-08-17  Alex Christensen  <achristensen@webkit.org>
     2
     3        Document load events should update timing in PerformanceNavigationTiming even after its instantiation
     4        https://bugs.webkit.org/show_bug.cgi?id=229181
     5
     6        Reviewed by Chris Dumez.
     7
     8        When we make a PerformanceNavigationTiming object, we copy the DocumentLoadTiming and DocumentEventTiming values.
     9        If PerformanceNavigationTiming is accessed before the document has finished loading, we still need to update the timing values.
     10
     11        Covered by a newly passing WPT test, which Chrome and Firefox already pass.
     12
     13        * dom/Document.cpp:
     14        (WebCore::Document::documentEventTimingFromNavigationTiming):
     15        (WebCore::Document::setReadyState):
     16        (WebCore::Document::finishedParsing):
     17        * dom/Document.h:
     18        * loader/DocumentLoadTiming.h:
     19        (WebCore::DocumentLoadTiming::setLoadEventStart):
     20        (WebCore::DocumentLoadTiming::setLoadEventEnd):
     21        (WebCore::DocumentLoadTiming::markLoadEventStart): Deleted.
     22        (WebCore::DocumentLoadTiming::markLoadEventEnd): Deleted.
     23        * page/DOMWindow.cpp:
     24        (WebCore::DOMWindow::dispatchLoadEvent):
     25        * page/Performance.h:
     26        * page/PerformanceNavigationTiming.h:
     27
    1282021-08-17  Antti Koivisto  <antti@apple.com>
    229
  • trunk/Source/WebCore/dom/Document.cpp

    r280953 r281147  
    162162#include "PaintWorkletGlobalScope.h"
    163163#include "Performance.h"
     164#include "PerformanceNavigationTiming.h"
    164165#include "PlatformLocale.h"
    165166#include "PlatformMediaSessionManager.h"
    … …  
    13751376}
    13761377
     1378DocumentEventTiming* Document::documentEventTimingFromNavigationTiming()
     1379{
     1380    auto* window = domWindow();
     1381    if (!window)
     1382        return nullptr;
     1383    auto* navigationTiming = window->performance().navigationTiming();
     1384    if (!navigationTiming)
     1385        return nullptr;
     1386    return &navigationTiming->documentEventTiming();
     1387}
     1388
    13771389void Document::setReadyState(ReadyState readyState)
    13781390{
    … …  
    13821394    switch (readyState) {
    13831395    case Loading:
    1384         if (!m_eventTiming.domLoading)
    1385             m_eventTiming.domLoading = MonotonicTime::now();
     1396        if (!m_eventTiming.domLoading) {
     1397            auto now = MonotonicTime::now();
     1398            m_eventTiming.domLoading = now;
     1399            if (auto* eventTiming = documentEventTimingFromNavigationTiming())
     1400                eventTiming->domLoading = now;
     1401        }
    13861402        break;
    13871403    case Complete:
    1388         if (!m_eventTiming.domComplete)
    1389             m_eventTiming.domComplete = MonotonicTime::now();
     1404        if (!m_eventTiming.domComplete) {
     1405            auto now = MonotonicTime::now();
     1406            m_eventTiming.domComplete = now;
     1407            if (auto* eventTiming = documentEventTimingFromNavigationTiming())
     1408                eventTiming->domComplete = now;
     1409        }
    13901410        FALLTHROUGH;
    13911411    case Interactive:
    1392         if (!m_eventTiming.domInteractive)
    1393             m_eventTiming.domInteractive = MonotonicTime::now();
     1412        if (!m_eventTiming.domInteractive) {
     1413            auto now = MonotonicTime::now();
     1414            m_eventTiming.domInteractive = now;
     1415            if (auto* eventTiming = documentEventTimingFromNavigationTiming())
     1416                eventTiming->domInteractive = now;
     1417        }
    13941418        break;
    13951419    }
    … …  
    60716095    scriptRunner().documentFinishedParsing();
    60726096
    6073     if (!m_eventTiming.domContentLoadedEventStart)
    6074         m_eventTiming.domContentLoadedEventStart = MonotonicTime::now();
     6097    if (!m_eventTiming.domContentLoadedEventStart) {
     6098        auto now = MonotonicTime::now();
     6099        m_eventTiming.domContentLoadedEventStart = now;
     6100        if (auto* eventTiming = documentEventTimingFromNavigationTiming())
     6101            eventTiming->domContentLoadedEventStart = now;
     6102    }
    60756103
    60766104    // FIXME: Schedule a task to fire DOMContentLoaded event instead. See webkit.org/b/82931
    … …  
    60786106    dispatchEvent(Event::create(eventNames().DOMContentLoadedEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
    60796107
    6080     if (!m_eventTiming.domContentLoadedEventEnd)
    6081         m_eventTiming.domContentLoadedEventEnd = MonotonicTime::now();
     6108    if (!m_eventTiming.domContentLoadedEventEnd) {
     6109        auto now = MonotonicTime::now();
     6110        m_eventTiming.domContentLoadedEventEnd = now;
     6111        if (auto* eventTiming = documentEventTimingFromNavigationTiming())
     6112            eventTiming->domContentLoadedEventEnd = now;
     6113    }
    60826114
    60836115    if (RefPtr<Frame> frame = this->frame()) {
  • trunk/Source/WebCore/dom/Document.h

    r280881 r281147  
    16601660    void detachParser();
    16611661
     1662    DocumentEventTiming* documentEventTimingFromNavigationTiming();
     1663
    16621664    // ScriptExecutionContext
    16631665    CSSFontSelector* cssFontSelector() final { return m_fontSelector.ptr(); }
  • trunk/Source/WebCore/loader/DocumentLoadTiming.h

    r278391 r281147  
    3838    void markUnloadEventStart() { m_unloadEventStart = MonotonicTime::now(); }
    3939    void markUnloadEventEnd() { m_unloadEventEnd = MonotonicTime::now(); }
    40     void markLoadEventStart() { m_loadEventStart = MonotonicTime::now(); }
    41     void markLoadEventEnd() { m_loadEventEnd = MonotonicTime::now(); }
     40    void setLoadEventStart(MonotonicTime time) { m_loadEventStart = time; }
     41    void setLoadEventEnd(MonotonicTime time) { m_loadEventEnd = time; }
    4242
    4343    void setHasSameOriginAsPreviousDocument(bool value) { m_hasSameOriginAsPreviousDocument = value; }
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r280861 r281147  
    8787#include "PageTransitionEvent.h"
    8888#include "Performance.h"
     89#include "PerformanceNavigationTiming.h"
    8990#include "RequestAnimationFrameCallback.h"
    9091#include "ResourceLoadInfo.h"
    … …  
    22602261    bool shouldMarkLoadEventTimes = protectedLoader && !protectedLoader->timing().loadEventStart();
    22612262
    2262     if (shouldMarkLoadEventTimes)
    2263         protectedLoader->timing().markLoadEventStart();
     2263    if (shouldMarkLoadEventTimes) {
     2264        auto now = MonotonicTime::now();
     2265        protectedLoader->timing().setLoadEventStart(now);
     2266        if (auto* navigationTiming = performance().navigationTiming())
     2267            navigationTiming->documentLoadTiming().setLoadEventStart(now);
     2268    }
    22642269
    22652270    dispatchEvent(Event::create(eventNames().loadEvent, Event::CanBubble::No, Event::IsCancelable::No), document());
    22662271
    2267     if (shouldMarkLoadEventTimes)
    2268         protectedLoader->timing().markLoadEventEnd();
     2272    if (shouldMarkLoadEventTimes) {
     2273        auto now = MonotonicTime::now();
     2274        protectedLoader->timing().setLoadEventEnd(now);
     2275        if (auto* navigationTiming = performance().navigationTiming())
     2276            navigationTiming->documentLoadTiming().setLoadEventEnd(now);
     2277    }
    22692278
    22702279    // Send a separate load event to the element that owns this frame.
  • trunk/Source/WebCore/page/Performance.h

    r280988 r281147  
    117117    void scheduleNavigationObservationTaskIfNeeded();
    118118
     119    PerformanceNavigationTiming* navigationTiming() { return m_navigationTiming.get(); }
     120
    119121private:
    120122    Performance(ScriptExecutionContext*, MonotonicTime timeOrigin);
  • trunk/Source/WebCore/page/PerformanceNavigationTiming.h

    r278391 r281147  
    6969    double duration() const final;
    7070
     71    DocumentEventTiming& documentEventTiming() { return m_documentEventTiming; }
     72    DocumentLoadTiming& documentLoadTiming() { return m_documentLoadTiming; }
     73
    7174private:
    7275    PerformanceNavigationTiming(MonotonicTime timeOrigin, CachedResource&, const DocumentLoadTiming&, const NetworkLoadMetrics&, const DocumentEventTiming&, const SecurityOrigin&, WebCore::NavigationType);
Note: See TracChangeset for help on using the changeset viewer.