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

Changeset 248359 in webkit


Ignore:
Timestamp:
Aug 6, 2019, 11:53:05 PM (7 years ago)
Author:
Kocsen Chung
Message:

Cherry-pick r248265. rdar://problem/54017843

Ping loads should not prevent page caching
https://bugs.webkit.org/show_bug.cgi?id=200418
<rdar://problem/53901632>

Reviewed by Darin Adler.

Source/WebCore:

We normally prevent page caching if there were any pending subresource loads when navigating,
to avoid caching partial / broken content. However, this should not apply to Ping / Beacon
loads since those do not impact page rendering and can outlive the page.

Tests: http/tests/navigation/page-cache-pending-ping-load-cross-origin.html

http/tests/navigation/page-cache-pending-ping-load-same-origin.html

  • history/PageCache.cpp: (WebCore::PageCache::addIfCacheable): After we've fired the 'pagehide' event in each frame, stop all the loads again. This is needed since pages are allowed to start ping / beacon loads in their 'pagehide' handlers. If we do not stop those loads, then the next call to canCachePage() would fail because the DocumentLoader is still loading. Note that we're not actually preventing these ping loads from hitting the server since we never cancel page loads and those can outlive their page.
  • loader/DocumentLoader.cpp: (WebCore::shouldPendingCachedResourceLoadPreventPageCache): (WebCore::areAllLoadersPageCacheAcceptable): Make sure that Ping / Beacon / Prefetches / Icon loads do not prevent page caching.

(WebCore::DocumentLoader::addSubresourceLoader):
Tweak assertion that was incorrect since we actually allow ping / beacon loads when the
document is about to enter PageCache (while firing pagehide event).

Tools:

Add TestOption to enable PageCache at UIProcess-level so that we can test
page caching when navigating cross-origin with PSON enabled.

  • WebKitTestRunner/TestController.cpp: (WTR::TestController::resetPreferencesToConsistentValues): (WTR::updateTestOptionsFromTestHeader):
  • WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const):

LayoutTests:

Add layout test coverage.

  • http/tests/navigation/page-cache-pending-ping-load-cross-origin-expected.txt: Added.
  • http/tests/navigation/page-cache-pending-ping-load-cross-origin.html: Added.
  • http/tests/navigation/page-cache-pending-ping-load-same-origin-expected.txt: Added.
  • http/tests/navigation/page-cache-pending-ping-load-same-origin.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248265 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-608.1-branch
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608.1-branch/LayoutTests/ChangeLog

    r248358 r248359  
     12019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r248265. rdar://problem/54017843
     4
     5    Ping loads should not prevent page caching
     6    https://bugs.webkit.org/show_bug.cgi?id=200418
     7    <rdar://problem/53901632>
     8   
     9    Reviewed by Darin Adler.
     10   
     11    Source/WebCore:
     12   
     13    We normally prevent page caching if there were any pending subresource loads when navigating,
     14    to avoid caching partial / broken content. However, this should not apply to Ping / Beacon
     15    loads since those do not impact page rendering and can outlive the page.
     16   
     17    Tests: http/tests/navigation/page-cache-pending-ping-load-cross-origin.html
     18           http/tests/navigation/page-cache-pending-ping-load-same-origin.html
     19   
     20    * history/PageCache.cpp:
     21    (WebCore::PageCache::addIfCacheable):
     22    After we've fired the 'pagehide' event in each frame, stop all the loads again. This is needed
     23    since pages are allowed to start ping / beacon loads in their 'pagehide' handlers. If we do not
     24    stop those loads, then the next call to canCachePage() would fail because the DocumentLoader is
     25    still loading. Note that we're not actually preventing these ping loads from hitting the server
     26    since we never cancel page loads and those can outlive their page.
     27   
     28    * loader/DocumentLoader.cpp:
     29    (WebCore::shouldPendingCachedResourceLoadPreventPageCache):
     30    (WebCore::areAllLoadersPageCacheAcceptable):
     31    Make sure that Ping / Beacon / Prefetches / Icon loads do not prevent page caching.
     32   
     33    (WebCore::DocumentLoader::addSubresourceLoader):
     34    Tweak assertion that was incorrect since we actually allow ping / beacon loads when the
     35    document is about to enter PageCache (while firing pagehide event).
     36   
     37    Tools:
     38   
     39    Add TestOption to enable PageCache at UIProcess-level so that we can test
     40    page caching when navigating cross-origin with PSON enabled.
     41   
     42    * WebKitTestRunner/TestController.cpp:
     43    (WTR::TestController::resetPreferencesToConsistentValues):
     44    (WTR::updateTestOptionsFromTestHeader):
     45    * WebKitTestRunner/TestOptions.h:
     46    (WTR::TestOptions::hasSameInitializationOptions const):
     47   
     48    LayoutTests:
     49   
     50    Add layout test coverage.
     51   
     52    * http/tests/navigation/page-cache-pending-ping-load-cross-origin-expected.txt: Added.
     53    * http/tests/navigation/page-cache-pending-ping-load-cross-origin.html: Added.
     54    * http/tests/navigation/page-cache-pending-ping-load-same-origin-expected.txt: Added.
     55    * http/tests/navigation/page-cache-pending-ping-load-same-origin.html: Added.
     56   
     57   
     58    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     59
     60    2019-08-04  Chris Dumez  <cdumez@apple.com>
     61
     62            Ping loads should not prevent page caching
     63            https://bugs.webkit.org/show_bug.cgi?id=200418
     64            <rdar://problem/53901632>
     65
     66            Reviewed by Darin Adler.
     67
     68            Add layout test coverage.
     69
     70            * http/tests/navigation/page-cache-pending-ping-load-cross-origin-expected.txt: Added.
     71            * http/tests/navigation/page-cache-pending-ping-load-cross-origin.html: Added.
     72            * http/tests/navigation/page-cache-pending-ping-load-same-origin-expected.txt: Added.
     73            * http/tests/navigation/page-cache-pending-ping-load-same-origin.html: Added.
     74
    1752019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
    276
  • branches/safari-608.1-branch/Source/WebCore/ChangeLog

    r248358 r248359  
     12019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r248265. rdar://problem/54017843
     4
     5    Ping loads should not prevent page caching
     6    https://bugs.webkit.org/show_bug.cgi?id=200418
     7    <rdar://problem/53901632>
     8   
     9    Reviewed by Darin Adler.
     10   
     11    Source/WebCore:
     12   
     13    We normally prevent page caching if there were any pending subresource loads when navigating,
     14    to avoid caching partial / broken content. However, this should not apply to Ping / Beacon
     15    loads since those do not impact page rendering and can outlive the page.
     16   
     17    Tests: http/tests/navigation/page-cache-pending-ping-load-cross-origin.html
     18           http/tests/navigation/page-cache-pending-ping-load-same-origin.html
     19   
     20    * history/PageCache.cpp:
     21    (WebCore::PageCache::addIfCacheable):
     22    After we've fired the 'pagehide' event in each frame, stop all the loads again. This is needed
     23    since pages are allowed to start ping / beacon loads in their 'pagehide' handlers. If we do not
     24    stop those loads, then the next call to canCachePage() would fail because the DocumentLoader is
     25    still loading. Note that we're not actually preventing these ping loads from hitting the server
     26    since we never cancel page loads and those can outlive their page.
     27   
     28    * loader/DocumentLoader.cpp:
     29    (WebCore::shouldPendingCachedResourceLoadPreventPageCache):
     30    (WebCore::areAllLoadersPageCacheAcceptable):
     31    Make sure that Ping / Beacon / Prefetches / Icon loads do not prevent page caching.
     32   
     33    (WebCore::DocumentLoader::addSubresourceLoader):
     34    Tweak assertion that was incorrect since we actually allow ping / beacon loads when the
     35    document is about to enter PageCache (while firing pagehide event).
     36   
     37    Tools:
     38   
     39    Add TestOption to enable PageCache at UIProcess-level so that we can test
     40    page caching when navigating cross-origin with PSON enabled.
     41   
     42    * WebKitTestRunner/TestController.cpp:
     43    (WTR::TestController::resetPreferencesToConsistentValues):
     44    (WTR::updateTestOptionsFromTestHeader):
     45    * WebKitTestRunner/TestOptions.h:
     46    (WTR::TestOptions::hasSameInitializationOptions const):
     47   
     48    LayoutTests:
     49   
     50    Add layout test coverage.
     51   
     52    * http/tests/navigation/page-cache-pending-ping-load-cross-origin-expected.txt: Added.
     53    * http/tests/navigation/page-cache-pending-ping-load-cross-origin.html: Added.
     54    * http/tests/navigation/page-cache-pending-ping-load-same-origin-expected.txt: Added.
     55    * http/tests/navigation/page-cache-pending-ping-load-same-origin.html: Added.
     56   
     57   
     58    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     59
     60    2019-08-04  Chris Dumez  <cdumez@apple.com>
     61
     62            Ping loads should not prevent page caching
     63            https://bugs.webkit.org/show_bug.cgi?id=200418
     64            <rdar://problem/53901632>
     65
     66            Reviewed by Darin Adler.
     67
     68            We normally prevent page caching if there were any pending subresource loads when navigating,
     69            to avoid caching partial / broken content. However, this should not apply to Ping / Beacon
     70            loads since those do not impact page rendering and can outlive the page.
     71
     72            Tests: http/tests/navigation/page-cache-pending-ping-load-cross-origin.html
     73                   http/tests/navigation/page-cache-pending-ping-load-same-origin.html
     74
     75            * history/PageCache.cpp:
     76            (WebCore::PageCache::addIfCacheable):
     77            After we've fired the 'pagehide' event in each frame, stop all the loads again. This is needed
     78            since pages are allowed to start ping / beacon loads in their 'pagehide' handlers. If we do not
     79            stop those loads, then the next call to canCachePage() would fail because the DocumentLoader is
     80            still loading. Note that we're not actually preventing these ping loads from hitting the server
     81            since we never cancel page loads and those can outlive their page.
     82
     83            * loader/DocumentLoader.cpp:
     84            (WebCore::shouldPendingCachedResourceLoadPreventPageCache):
     85            (WebCore::areAllLoadersPageCacheAcceptable):
     86            Make sure that Ping / Beacon / Prefetches / Icon loads do not prevent page caching.
     87
     88            (WebCore::DocumentLoader::addSubresourceLoader):
     89            Tweak assertion that was incorrect since we actually allow ping / beacon loads when the
     90            document is about to enter PageCache (while firing pagehide event).
     91
    1922019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
    293
  • branches/safari-608.1-branch/Source/WebCore/history/PageCache.cpp

    r246187 r248359  
    459459    destroyRenderTree(page->mainFrame());
    460460
     461    // Stop all loads again before checking if we can still cache the page after firing the pagehide
     462    // event, since the page may have started ping loads in its pagehide event handler.
     463    for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
     464        if (auto* documentLoader = frame->loader().documentLoader())
     465            documentLoader->stopLoading();
     466    }
     467
    461468    // Check that the page is still page-cacheable after firing the pagehide event. The JS event handlers
    462469    // could have altered the page in a way that could prevent caching.
  • branches/safari-608.1-branch/Source/WebCore/loader/DocumentLoader.cpp

    r248358 r248359  
    126126}
    127127
     128static bool shouldPendingCachedResourceLoadPreventPageCache(CachedResource& cachedResource)
     129{
     130    if (!cachedResource.isLoading())
     131        return false;
     132
     133    switch (cachedResource.type()) {
     134    case CachedResource::Type::ImageResource:
     135    case CachedResource::Type::Icon:
     136    case CachedResource::Type::Beacon:
     137    case CachedResource::Type::Ping:
     138    case CachedResource::Type::LinkPrefetch:
     139        return false;
     140    case CachedResource::Type::MainResource:
     141    case CachedResource::Type::CSSStyleSheet:
     142    case CachedResource::Type::Script:
     143    case CachedResource::Type::FontResource:
     144#if ENABLE(SVG_FONTS)
     145    case CachedResource::Type::SVGFontResource:
     146#endif
     147    case CachedResource::Type::MediaResource:
     148    case CachedResource::Type::RawResource:
     149    case CachedResource::Type::SVGDocumentResource:
     150#if ENABLE(XSLT)
     151    case CachedResource::Type::XSLStyleSheet:
     152#endif
     153#if ENABLE(VIDEO_TRACK)
     154    case CachedResource::Type::TextTrackResource:
     155#endif
     156#if ENABLE(APPLICATION_MANIFEST)
     157    case CachedResource::Type::ApplicationManifest:
     158#endif
     159        break;
     160    };
     161    return !cachedResource.areAllClientsXMLHttpRequests();
     162}
     163
    128164static bool areAllLoadersPageCacheAcceptable(const ResourceLoaderMap& loaders)
    129165{
     
    138174        // Only image and XHR loads do not prevent the page from entering the PageCache.
    139175        // All non-image loads will prevent the page from entering the PageCache.
    140         if (cachedResource->isLoading() && !cachedResource->isImage() && !cachedResource->areAllClientsXMLHttpRequests())
     176        if (shouldPendingCachedResourceLoadPreventPageCache(*cachedResource))
    141177            return false;
    142178    }
     
    16831719        return;
    16841720
    1685     // A page in the PageCache or about to enter PageCache should not be able to start loads.
    1686     ASSERT_WITH_SECURITY_IMPLICATION(!document() || document()->pageCacheState() == Document::NotInPageCache);
     1721#if !ASSERT_DISABLED
     1722    if (document()) {
     1723        switch (document()->pageCacheState()) {
     1724        case Document::NotInPageCache:
     1725            break;
     1726        case Document::AboutToEnterPageCache: {
     1727            // A page about to enter PageCache should only be able to start ping loads.
     1728            auto* cachedResource = MemoryCache::singleton().resourceForRequest(loader->request(), loader->frameLoader()->frame().page()->sessionID());
     1729            ASSERT(cachedResource && CachedResource::shouldUsePingLoad(cachedResource->type()));
     1730            break;
     1731        }
     1732        case Document::InPageCache:
     1733            // A page in the PageCache should not be able to start loads.
     1734            ASSERT_NOT_REACHED();
     1735            break;
     1736        }
     1737    }
     1738#endif
    16871739
    16881740    m_subresourceLoaders.add(loader->identifier(), loader);
  • branches/safari-608.1-branch/Tools/ChangeLog

    r248344 r248359  
     12019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r248265. rdar://problem/54017843
     4
     5    Ping loads should not prevent page caching
     6    https://bugs.webkit.org/show_bug.cgi?id=200418
     7    <rdar://problem/53901632>
     8   
     9    Reviewed by Darin Adler.
     10   
     11    Source/WebCore:
     12   
     13    We normally prevent page caching if there were any pending subresource loads when navigating,
     14    to avoid caching partial / broken content. However, this should not apply to Ping / Beacon
     15    loads since those do not impact page rendering and can outlive the page.
     16   
     17    Tests: http/tests/navigation/page-cache-pending-ping-load-cross-origin.html
     18           http/tests/navigation/page-cache-pending-ping-load-same-origin.html
     19   
     20    * history/PageCache.cpp:
     21    (WebCore::PageCache::addIfCacheable):
     22    After we've fired the 'pagehide' event in each frame, stop all the loads again. This is needed
     23    since pages are allowed to start ping / beacon loads in their 'pagehide' handlers. If we do not
     24    stop those loads, then the next call to canCachePage() would fail because the DocumentLoader is
     25    still loading. Note that we're not actually preventing these ping loads from hitting the server
     26    since we never cancel page loads and those can outlive their page.
     27   
     28    * loader/DocumentLoader.cpp:
     29    (WebCore::shouldPendingCachedResourceLoadPreventPageCache):
     30    (WebCore::areAllLoadersPageCacheAcceptable):
     31    Make sure that Ping / Beacon / Prefetches / Icon loads do not prevent page caching.
     32   
     33    (WebCore::DocumentLoader::addSubresourceLoader):
     34    Tweak assertion that was incorrect since we actually allow ping / beacon loads when the
     35    document is about to enter PageCache (while firing pagehide event).
     36   
     37    Tools:
     38   
     39    Add TestOption to enable PageCache at UIProcess-level so that we can test
     40    page caching when navigating cross-origin with PSON enabled.
     41   
     42    * WebKitTestRunner/TestController.cpp:
     43    (WTR::TestController::resetPreferencesToConsistentValues):
     44    (WTR::updateTestOptionsFromTestHeader):
     45    * WebKitTestRunner/TestOptions.h:
     46    (WTR::TestOptions::hasSameInitializationOptions const):
     47   
     48    LayoutTests:
     49   
     50    Add layout test coverage.
     51   
     52    * http/tests/navigation/page-cache-pending-ping-load-cross-origin-expected.txt: Added.
     53    * http/tests/navigation/page-cache-pending-ping-load-cross-origin.html: Added.
     54    * http/tests/navigation/page-cache-pending-ping-load-same-origin-expected.txt: Added.
     55    * http/tests/navigation/page-cache-pending-ping-load-same-origin.html: Added.
     56   
     57   
     58    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     59
     60    2019-08-04  Chris Dumez  <cdumez@apple.com>
     61
     62            Ping loads should not prevent page caching
     63            https://bugs.webkit.org/show_bug.cgi?id=200418
     64            <rdar://problem/53901632>
     65
     66            Reviewed by Darin Adler.
     67
     68            Add TestOption to enable PageCache at UIProcess-level so that we can test
     69            page caching when navigating cross-origin with PSON enabled.
     70
     71            * WebKitTestRunner/TestController.cpp:
     72            (WTR::TestController::resetPreferencesToConsistentValues):
     73            (WTR::updateTestOptionsFromTestHeader):
     74            * WebKitTestRunner/TestOptions.h:
     75            (WTR::TestOptions::hasSameInitializationOptions const):
     76
    1772019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
    278
  • branches/safari-608.1-branch/Tools/WebKitTestRunner/TestController.cpp

    r246856 r248359  
    799799    WKPreferencesSetFullScreenEnabled(preferences, true);
    800800#endif
    801     WKPreferencesSetPageCacheEnabled(preferences, false);
    802801    WKPreferencesSetAsynchronousPluginInitializationEnabled(preferences, false);
    803802    WKPreferencesSetAsynchronousPluginInitializationEnabledForAllPlugins(preferences, false);
     
    819818    WKPreferencesSetColorFilterEnabled(preferences, options.enableColorFilter);
    820819    WKPreferencesSetPunchOutWhiteBackgroundsInDarkMode(preferences, options.punchOutWhiteBackgroundsInDarkMode);
     820    WKPreferencesSetPageCacheEnabled(preferences, options.enablePageCache);
    821821
    822822    static WKStringRef defaultTextEncoding = WKStringCreateWithUTF8CString("ISO-8859-1");
     
    13971397        else if (key == "enableAppNap")
    13981398            testOptions.enableAppNap = parseBooleanTestHeaderValue(value);
     1399        else if (key == "enablePageCache")
     1400            testOptions.enablePageCache = parseBooleanTestHeaderValue(value);
    13991401        pairStart = pairEnd + 1;
    14001402    }
  • branches/safari-608.1-branch/Tools/WebKitTestRunner/TestOptions.h

    r246118 r248359  
    9393    bool shouldPresentPopovers { true };
    9494    bool enableAppNap { false };
     95    bool enablePageCache { false };
    9596
    9697    double contentInsetTop { 0 };
     
    147148            || contentInsetTop != options.contentInsetTop
    148149            || contentMode != options.contentMode
    149             || enableAppNap != options.enableAppNap)
     150            || enableAppNap != options.enableAppNap
     151            || enablePageCache != options.enablePageCache)
    150152            return false;
    151153
Note: See TracChangeset for help on using the changeset viewer.