Commit 10bb83df authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Defer preloads with imagesrcset/imagesizes until the first chunk is parsed

Preloads from link headers with the media attribute are deferred until
the first chunk of the document is parsed, so that ViewportDescription
from the preload scanner can be taken into account. Preloads with
imagesrcset or imagesizes depend on the viewport, so such preloads
should be deferred as well.

Note: This applies to only preloads dispatched by DocumentLoader. Link
rel=preload headers from subresources (e.g. prefetch) are not deferred
even if they have media/imagesrcset/imagesizes attributes.

Bug: 813452
Change-Id: Iccc6ec12cf5bd53b71824463378c854cbd23a5ba
Reviewed-on: https://chromium-review.googlesource.com/c/1360193Reviewed-by: default avatarDominic Farolino <domfarolino@gmail.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614253}
parent 19876327
...@@ -603,9 +603,9 @@ void LinkLoader::LoadLinksFromHeader( ...@@ -603,9 +603,9 @@ void LinkLoader::LoadLinksFromHeader(
if (!header.Valid() || header.Url().IsEmpty() || header.Rel().IsEmpty()) if (!header.Valid() || header.Url().IsEmpty() || header.Rel().IsEmpty())
continue; continue;
if (media_policy == kOnlyLoadMedia && header.Media().IsEmpty()) if (media_policy == kOnlyLoadMedia && !header.IsViewportDependent())
continue; continue;
if (media_policy == kOnlyLoadNonMedia && !header.Media().IsEmpty()) if (media_policy == kOnlyLoadNonMedia && header.IsViewportDependent())
continue; continue;
const LinkLoadParameters params(header, base_url); const LinkLoadParameters params(header, base_url);
......
...@@ -26,6 +26,10 @@ class LinkHeader { ...@@ -26,6 +26,10 @@ class LinkHeader {
const String& ImageSrcset() const { return image_srcset_; } const String& ImageSrcset() const { return image_srcset_; }
const String& ImageSizes() const { return image_sizes_; } const String& ImageSizes() const { return image_sizes_; }
bool Valid() const { return is_valid_; } bool Valid() const { return is_valid_; }
bool IsViewportDependent() const {
return !Media().IsEmpty() || !ImageSrcset().IsEmpty() ||
!ImageSizes().IsEmpty();
}
enum LinkParameterName { enum LinkParameterName {
kLinkParameterRel, kLinkParameterRel,
......
<!DOCTYPE html>
<script>
if (window.internals) {
internals.settings.setViewportEnabled(true);
internals.settings.setViewportMetaEnabled(true);
}
if (window.testRunner) {
testRunner.setCanOpenWindows(true);
testRunner.setCloseRemainingWindowsWhenComplete(true);
}
</script>
<meta name="viewport" content="width=160">
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var t = async_test('Makes sure that Link headers support the imagesrcset and imagesizes attributes and respond to <meta content=viewport>');
addEventListener("message", t.step_func(function(event) {
if (event.data == "largeloaded")
assert_unreached("FAIL: large resource was loaded");
if (event.data == "smallnotloaded")
assert_unreached("FAIL: small resource was not loaded");
t.done();
}, false));
window.open("resources/enable-viewport-and-refresh.html?media-link-headers-imagesrcset.php");
</script>
<?php
header('Link: <http://127.0.0.1:8000/resources/square.png?large>; rel=preload; as=image; imagesrcset="http://127.0.0.1:8000/resources/square.png?small 150w, http://127.0.0.1:8000/resources/square.png?large 300w"; imagesizes="(min-width: 150px) and (max-width: 150px) 150px, 300px"', false);
?>
<!DOCTYPE html>
<meta name="viewport" content="width=150">
<script>
window.addEventListener("load", function() {
var entries = performance.getEntriesByType("resource");
var smallLoaded = false;
for (var i = 0; i < entries.length; ++i) {
if (entries[i].name.indexOf("large") != -1)
window.opener.postMessage("largeloaded", "*");
if (entries[i].name.indexOf("small") != -1)
smallLoaded = true;
}
if (smallLoaded)
window.opener.postMessage("success", "*")
window.opener.postMessage("smallnotloaded", "*");
});
</script>
<script src="../resources/slow-script.pl?delay=200"></script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment