Title: [247806] trunk
Revision
247806
Author
[email protected]
Date
2019-07-24 17:55:16 -0700 (Wed, 24 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 Alex Christensen.

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 (247805 => 247806)


--- trunk/LayoutTests/ChangeLog	2019-07-25 00:52:10 UTC (rev 247805)
+++ trunk/LayoutTests/ChangeLog	2019-07-25 00:55:16 UTC (rev 247806)
@@ -1,3 +1,19 @@
+2019-07-24  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 Alex Christensen.
+
+        * 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-24  Devin Rousso  <[email protected]>
 
         Web Inspector: support `console.screenshot` with subclasses of CanvasRenderingContext

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


--- 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-25 00:55:16 UTC (rev 247806)
@@ -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 => 247806)


--- trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/disable-speculative-for-reload.html	2019-07-25 00:55:16 UTC (rev 247806)
@@ -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 => 247806)


--- trunk/LayoutTests/http/wpt/fetch/resources/iframe-with-image.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/iframe-with-image.py	2019-07-25 00:55:16 UTC (rev 247806)
@@ -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 => 247806)


--- trunk/LayoutTests/http/wpt/fetch/resources/image-load-count.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/image-load-count.py	2019-07-25 00:55:16 UTC (rev 247806)
@@ -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 => 247806)


--- trunk/LayoutTests/http/wpt/fetch/resources/image-load.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/image-load.py	2019-07-25 00:55:16 UTC (rev 247806)
@@ -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 (247805 => 247806)


--- trunk/Source/WebKit/ChangeLog	2019-07-25 00:52:10 UTC (rev 247805)
+++ trunk/Source/WebKit/ChangeLog	2019-07-25 00:55:16 UTC (rev 247806)
@@ -1,3 +1,20 @@
+2019-07-24  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 Alex Christensen.
+
+        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-24  Priyanka Agarwal  <[email protected]>
 
         Allow Clients to Add Fields to the AutoFillContext Dictionary

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp (247805 => 247806)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2019-07-25 00:52:10 UTC (rev 247805)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2019-07-25 00:55:16 UTC (rev 247806)
@@ -275,10 +275,22 @@
     if (request.isConditional())
         return false;
 
-    if (cachePolicyAllowsExpired(request.cachePolicy()))
+    if (request.requester() == ResourceRequest::Requester::XHR || request.requester() != ResourceRequest::Requester::Fetch)
         return false;
 
-    return request.requester() != ResourceRequest::Requester::XHR && request.requester() != ResourceRequest::Requester::Fetch;
+    switch (request.cachePolicy()) {
+    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;
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to