Title: [247314] trunk
Revision
247314
Author
[email protected]
Date
2019-07-10 11:17:59 -0700 (Wed, 10 Jul 2019)

Log Message

Disable speculative loading if cache is not to be used for the load
https://bugs.webkit.org/show_bug.cgi?id=199644

Reviewed by Chris Dumez.

Source/WebKit:

When the page is reloaded, loads are instructed to not use the cache.
It is therefore unneeded to do speculative revalidation.
Allow speculative revalidation if the cache policy is either the default HTTP policy or
if policy is to refresh all cache data.
Covered by added test.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::cachePolicyValidForSpeculativeRevalidation):
(WebKit::NetworkCache::canRequestUseSpeculativeRevalidation):

LayoutTests:

* http/wpt/fetch/disable-speculative-for-reload-expected.txt: Added.
* http/wpt/fetch/disable-speculative-for-reload.html: Added.
* http/wpt/fetch/resources/iframe-with-image.py: Added.
(main):
* http/wpt/fetch/resources/image-load-count.py: Added.
(main):
* http/wpt/fetch/resources/image-load.py: Added.
(main):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (247313 => 247314)


--- trunk/LayoutTests/ChangeLog	2019-07-10 18:09:27 UTC (rev 247313)
+++ trunk/LayoutTests/ChangeLog	2019-07-10 18:17:59 UTC (rev 247314)
@@ -1,5 +1,21 @@
 2019-07-10  Youenn Fablet  <[email protected]>
 
+        Disable speculative loading if cache is not to be used for the load
+        https://bugs.webkit.org/show_bug.cgi?id=199644
+
+        Reviewed by Chris Dumez.
+
+        * http/wpt/fetch/disable-speculative-for-reload-expected.txt: Added.
+        * http/wpt/fetch/disable-speculative-for-reload.html: Added.
+        * http/wpt/fetch/resources/iframe-with-image.py: Added.
+        (main):
+        * http/wpt/fetch/resources/image-load-count.py: Added.
+        (main):
+        * http/wpt/fetch/resources/image-load.py: Added.
+        (main):
+
+2019-07-10  Youenn Fablet  <[email protected]>
+
         openDatabase property should not be enumerable on DOMWindow
         https://bugs.webkit.org/show_bug.cgi?id=199672
         <rdar://problem/52809000>

Added: trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload-expected.txt (0 => 247314)


--- trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload-expected.txt	2019-07-10 18:17:59 UTC (rev 247314)
@@ -0,0 +1,3 @@
+
+PASS Ensure image is not speculatively loaded after a reload 
+

Added: trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload.html (0 => 247314)


--- trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload.html	2019-07-10 18:17:59 UTC (rev 247314)
@@ -0,0 +1,61 @@
+<!doctype html>
+<script src=""
+<script src=""
+<script src=""
+<script>
+function loadIFrame(src) {
+    return new Promise(function(resolve, reject) {
+        var iframe = document.createElement('iframe');
+        iframe._onload_ = function() { resolve(iframe); };
+
+        iframe.src = ""
+
+        document.documentElement.appendChild(iframe);
+    });
+}
+
+async function imageLoadCount(uuid)
+{
+    const response = await fetch('resources/image-load.py?uuid=' + uuid, { method: 'POST' });
+    return response.text();
+}
+
+async function navigateIFrame(iframe, uuid)
+{
+    const promise = new Promise(resolve => iframe._onload_ = resolve);
+    iframe.src = "" + uuid;
+    await promise;
+    return imageLoadCount(uuid);
+}
+
+async function reloadIFrame(iframe, uuid)
+{
+    const promise = new Promise(resolve => iframe._onload_ = resolve);
+    iframe.contentWindow.location.reload();
+    await promise;
+    return imageLoadCount(uuid);
+}
+
+function resetIFrame(iframe)
+{
+    const promise = new Promise(resolve => { iframe._onload_ = resolve; });
+    iframe.src = ""
+    return promise;
+}
+
+promise_test(async (test) => {
+    const uuid = token();
+    const iframe = await loadIFrame("about:blank");
+
+    const token1 = await navigateIFrame(iframe, uuid);
+    await resetIFrame(iframe);
+    const token2 = await navigateIFrame(iframe, uuid);
+    const token3 = await reloadIFrame(iframe, uuid);
+
+    assert_equals(token1, "1", "navigating to");
+    assert_equals(token2, "2", "after new navigation");
+    assert_equals(token3, "3", "after reload");
+
+    iframe.remove();
+}, "Ensure image is not speculatively loaded after a reload");
+</script>

Added: trunk/LayoutTests/http/wpt/fetch/resources/iframe-with-image.py (0 => 247314)


--- trunk/LayoutTests/http/wpt/fetch/resources/iframe-with-image.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/iframe-with-image.py	2019-07-10 18:17:59 UTC (rev 247314)
@@ -0,0 +1,8 @@
+ETAG = '"123abc"'
+
+
+def main(request, response):
+    test_id = request.GET.first("uuid")
+    response.status = (200, "OK")
+    response.headers.set("Content-Type", 'text/html')
+    return "<!doctype html><image src=''></image>"

Added: trunk/LayoutTests/http/wpt/fetch/resources/image-load-count.py (0 => 247314)


--- trunk/LayoutTests/http/wpt/fetch/resources/image-load-count.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/image-load-count.py	2019-07-10 18:17:59 UTC (rev 247314)
@@ -0,0 +1,11 @@
+def main(request, response):
+    test_id = request.GET.first("uuid")
+    stashed_count = request.server.stash.take(test_id)
+    if stashed_count is None:
+        stashed_count = test_id + " none"
+
+    request.server.stash.put(test_id, stashed_count)
+
+    response.status = (200, "OK")
+    response.headers.set("Content-Type", 'text/plain')
+    return str(stashed_count)

Added: trunk/LayoutTests/http/wpt/fetch/resources/image-load.py (0 => 247314)


--- trunk/LayoutTests/http/wpt/fetch/resources/image-load.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/image-load.py	2019-07-10 18:17:59 UTC (rev 247314)
@@ -0,0 +1,36 @@
+ETAG = '"123abc"'
+
+
+def main(request, response):
+    test_id = request.GET.first("uuid")
+
+    if request.method == "POST":
+        stashed_count = request.server.stash.take(test_id)
+        if stashed_count is None:
+            stashed_count = 0
+
+        request.server.stash.put(test_id, stashed_count)
+
+        response.status = (200, "OK")
+        response.headers.set("Content-Type", 'text/plain')
+        return str(stashed_count)
+
+    stashed_count = request.server.stash.take(test_id)
+    if stashed_count is not None:
+        stashed_count = stashed_count + 1
+    else:
+        stashed_count = 1
+    request.server.stash.put(test_id, stashed_count)
+
+    etag = request.headers.get("If-None-Match", None)
+    if etag == ETAG:
+        response.headers.set("X-HTTP-STATUS", 304)
+        response.status = (304, "Not Modified")
+        return ""
+
+    # cache miss, so respond with the actual content
+    response.status = (200, "OK")
+    response.headers.set("ETag", ETAG)
+    response.headers.set("Content-Type", 'image/png')
+    response.headers.set("Cache-Control", "max-age=0");
+    return 'myimagecontent'

Modified: trunk/Source/WebKit/ChangeLog (247313 => 247314)


--- trunk/Source/WebKit/ChangeLog	2019-07-10 18:09:27 UTC (rev 247313)
+++ trunk/Source/WebKit/ChangeLog	2019-07-10 18:17:59 UTC (rev 247314)
@@ -1,3 +1,20 @@
+2019-07-10  Youenn Fablet  <[email protected]>
+
+        Disable speculative loading if cache is not to be used for the load
+        https://bugs.webkit.org/show_bug.cgi?id=199644
+
+        Reviewed by Chris Dumez.
+
+        When the page is reloaded, loads are instructed to not use the cache.
+        It is therefore unneeded to do speculative revalidation.
+        Allow speculative revalidation if the cache policy is either the default HTTP policy or
+        if policy is to refresh all cache data.
+        Covered by added test.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::cachePolicyValidForSpeculativeRevalidation):
+        (WebKit::NetworkCache::canRequestUseSpeculativeRevalidation):
+
 2019-07-10  Alex Christensen  <[email protected]>
 
         Fix build after Foundation changes UIEdgeInsets definition

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp (247313 => 247314)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2019-07-10 18:09:27 UTC (rev 247313)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2019-07-10 18:17:59 UTC (rev 247314)
@@ -270,12 +270,29 @@
 }
 
 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
+static bool cachePolicyValidForSpeculativeRevalidation(WebCore::ResourceRequestCachePolicy policy)
+{
+    switch (policy) {
+    case WebCore::ResourceRequestCachePolicy::ReturnCacheDataElseLoad:
+    case WebCore::ResourceRequestCachePolicy::ReturnCacheDataDontLoad:
+    case WebCore::ResourceRequestCachePolicy::ReloadIgnoringCacheData:
+        return false;
+    case WebCore::ResourceRequestCachePolicy::UseProtocolCachePolicy:
+    case WebCore::ResourceRequestCachePolicy::RefreshAnyCacheData:
+        return true;
+    case WebCore::ResourceRequestCachePolicy::DoNotUseAnyCache:
+        ASSERT_NOT_REACHED();
+        return false;
+    }
+    return false;
+}
+
 static bool inline canRequestUseSpeculativeRevalidation(const ResourceRequest& request)
 {
     if (request.isConditional())
         return false;
 
-    if (cachePolicyAllowsExpired(request.cachePolicy()))
+    if (cachePolicyValidForSpeculativeRevalidation(request.cachePolicy()))
         return false;
 
     return request.requester() != ResourceRequest::Requester::XHR && request.requester() != ResourceRequest::Requester::Fetch;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to