Changeset 246045 in webkit


Ignore:
Timestamp:
Jun 3, 2019 1:49:53 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Implement imagesrcset and imagesizes attributes on link rel=preload
https://bugs.webkit.org/show_bug.cgi?id=192950

Patch by Rob Buis <rbuis@igalia.com> on 2019-06-03
Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Import relevant tests for this feature.

  • web-platform-tests/preload/dynamic-adding-preload-imagesrcset-expected.txt: Added.
  • web-platform-tests/preload/dynamic-adding-preload-imagesrcset.html: Added.
  • web-platform-tests/preload/link-header-preload-expected.txt: Added.
  • web-platform-tests/preload/link-header-preload-imagesrcset-expected.txt: Added.
  • web-platform-tests/preload/link-header-preload-imagesrcset.html: Added.
  • web-platform-tests/preload/link-header-preload-imagesrcset.html.headers: Added.
  • web-platform-tests/preload/link-header-preload-nonce-expected.txt: Added.
  • web-platform-tests/preload/link-header-preload-nonce.html: Added.
  • web-platform-tests/preload/link-header-preload-nonce.html.headers: Added.
  • web-platform-tests/preload/link-header-preload.html: Added.
  • web-platform-tests/preload/link-header-preload.html.headers: Added.
  • web-platform-tests/preload/onload-event-expected.txt: Added.
  • web-platform-tests/preload/onload-event.html: Added.
  • web-platform-tests/preload/preload-csp.sub-expected.txt:
  • web-platform-tests/preload/preload-csp.sub.html:
  • web-platform-tests/preload/preload-default-csp.sub-expected.txt:
  • web-platform-tests/preload/preload-default-csp.sub.html:
  • web-platform-tests/preload/preload-with-type-expected.txt: Added.
  • web-platform-tests/preload/preload-with-type.html: Added.
  • web-platform-tests/preload/resources/A4.ogv: Added.
  • web-platform-tests/preload/resources/A4.ogv.sub.headers: Added.
  • web-platform-tests/preload/resources/cross-origin-module.py: Added.

(main):

  • web-platform-tests/preload/resources/dummy-preloads-subresource.css: Added.
  • web-platform-tests/preload/resources/dummy-preloads-subresource.css.sub.headers: Added.
  • web-platform-tests/preload/resources/empty.html: Added.
  • web-platform-tests/preload/resources/empty.html.sub.headers: Added.
  • web-platform-tests/preload/resources/foo.vtt.sub.headers: Added.
  • web-platform-tests/preload/resources/module1.js: Added.
  • web-platform-tests/preload/resources/module2.js: Added.
  • web-platform-tests/preload/resources/preload_helper.js:

(verifyNumberOfResourceTimingEntries):
(numberOfResourceTimingEntries):

Source/WebCore:

Implement imagesrcset and imagesizes attributes for both Link header
and link element.

Tests: imported/w3c/web-platform-tests/preload/dynamic-adding-preload-imagesrcset.html

imported/w3c/web-platform-tests/preload/link-header-preload-imagesrcset.html
imported/w3c/web-platform-tests/preload/link-header-preload-nonce.html
imported/w3c/web-platform-tests/preload/link-header-preload.html
imported/w3c/web-platform-tests/preload/onload-event.html
imported/w3c/web-platform-tests/preload/preload-with-type.html

  • html/HTMLAttributeNames.in:
  • html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::process):

  • html/HTMLLinkElement.idl:
  • loader/LinkHeader.cpp:

(WebCore::paramterNameFromString):
(WebCore::LinkHeader::setValue):
(WebCore::LinkHeader::LinkHeader):

  • loader/LinkHeader.h:

(WebCore::LinkHeader::imageSrcSet const):
(WebCore::LinkHeader::imageSizes const):
(WebCore::LinkHeader::isViewportDependent const):

  • loader/LinkLoader.cpp:

(WebCore::LinkLoader::loadLinksFromHeader):
(WebCore::LinkLoader::preloadIfNeeded):
(WebCore::LinkLoader::loadLink):

  • loader/LinkLoader.h:
  • page/RuntimeEnabledFeatures.h:

(WebCore::RuntimeEnabledFeatures::linkPreloadResponsiveImagesEnabled const):
(WebCore::RuntimeEnabledFeatures::setLinkPreloadResponsiveImagesEnabled):

Source/WebKit:

Add a runtime flag for link preload responsive images.

  • Shared/WebPreferences.yaml:

Source/WebKitLegacy/mac:

Add a runtime flag for link preload responsive images.

  • WebView/WebPreferenceKeysPrivate.h:
  • WebView/WebPreferences.mm:

(+[WebPreferences initialize]):
(-[WebPreferences linkPreloadResponsiveImagesEnabled]):
(-[WebPreferences setLinkPreloadResponsiveImagesEnabled:]):

  • WebView/WebPreferencesPrivate.h:
  • WebView/WebView.mm:

(-[WebView _preferencesChanged:]):

Tools:

Add a runtime flag for link preload responsive images.

  • DumpRenderTree/mac/DumpRenderTree.mm:

(enableExperimentalFeatures):

LayoutTests:

Write special expectation for link-header-preload-imagesrcset.html because test runner
uses different dimensions on iOS.

  • platform/ios-simulator-12-wk2/imported/w3c/web-platform-tests/preload/dynamic-adding-preload-imagesrcset-expected.txt: Added.
  • platform/ios-simulator-12-wk2/imported/w3c/web-platform-tests/preload/link-header-preload-imagesrcset-expected.txt: Added.
Location:
trunk
Files:
32 added
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246040 r246045  
     12019-06-03  Rob Buis  <rbuis@igalia.com>
     2
     3        Implement imagesrcset and imagesizes attributes on link rel=preload
     4        https://bugs.webkit.org/show_bug.cgi?id=192950
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Write special expectation for link-header-preload-imagesrcset.html because test runner
     9        uses different dimensions on iOS.
     10
     11        * platform/ios-simulator-12-wk2/imported/w3c/web-platform-tests/preload/dynamic-adding-preload-imagesrcset-expected.txt: Added.
     12        * platform/ios-simulator-12-wk2/imported/w3c/web-platform-tests/preload/link-header-preload-imagesrcset-expected.txt: Added.
     13
    1142019-06-03  Yusuke Suzuki  <ysuzuki@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r245966 r246045  
     12019-06-03  Rob Buis  <rbuis@igalia.com>
     2
     3        Implement imagesrcset and imagesizes attributes on link rel=preload
     4        https://bugs.webkit.org/show_bug.cgi?id=192950
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Import relevant tests for this feature.
     9
     10        * web-platform-tests/preload/dynamic-adding-preload-imagesrcset-expected.txt: Added.
     11        * web-platform-tests/preload/dynamic-adding-preload-imagesrcset.html: Added.
     12        * web-platform-tests/preload/link-header-preload-expected.txt: Added.
     13        * web-platform-tests/preload/link-header-preload-imagesrcset-expected.txt: Added.
     14        * web-platform-tests/preload/link-header-preload-imagesrcset.html: Added.
     15        * web-platform-tests/preload/link-header-preload-imagesrcset.html.headers: Added.
     16        * web-platform-tests/preload/link-header-preload-nonce-expected.txt: Added.
     17        * web-platform-tests/preload/link-header-preload-nonce.html: Added.
     18        * web-platform-tests/preload/link-header-preload-nonce.html.headers: Added.
     19        * web-platform-tests/preload/link-header-preload.html: Added.
     20        * web-platform-tests/preload/link-header-preload.html.headers: Added.
     21        * web-platform-tests/preload/onload-event-expected.txt: Added.
     22        * web-platform-tests/preload/onload-event.html: Added.
     23        * web-platform-tests/preload/preload-csp.sub-expected.txt:
     24        * web-platform-tests/preload/preload-csp.sub.html:
     25        * web-platform-tests/preload/preload-default-csp.sub-expected.txt:
     26        * web-platform-tests/preload/preload-default-csp.sub.html:
     27        * web-platform-tests/preload/preload-with-type-expected.txt: Added.
     28        * web-platform-tests/preload/preload-with-type.html: Added.
     29        * web-platform-tests/preload/resources/A4.ogv: Added.
     30        * web-platform-tests/preload/resources/A4.ogv.sub.headers: Added.
     31        * web-platform-tests/preload/resources/cross-origin-module.py: Added.
     32        (main):
     33        * web-platform-tests/preload/resources/dummy-preloads-subresource.css: Added.
     34        * web-platform-tests/preload/resources/dummy-preloads-subresource.css.sub.headers: Added.
     35        * web-platform-tests/preload/resources/empty.html: Added.
     36        * web-platform-tests/preload/resources/empty.html.sub.headers: Added.
     37        * web-platform-tests/preload/resources/foo.vtt.sub.headers: Added.
     38        * web-platform-tests/preload/resources/module1.js: Added.
     39        * web-platform-tests/preload/resources/module2.js: Added.
     40        * web-platform-tests/preload/resources/preload_helper.js:
     41        (verifyNumberOfResourceTimingEntries):
     42        (numberOfResourceTimingEntries):
     43
    1442019-05-31  Joonghun Park  <jh718.park@samsung.com>
    245
  • trunk/LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub-expected.txt

    r245825 r246045  
    1313CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/sound_5.oga because it does not appear in the media-src directive of the Content Security Policy.
    1414CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/foo.vtt because it does not appear in the media-src directive of the Content Security Policy.
    15 CONSOLE MESSAGE: line 16: <link rel=preload> must have a valid `as` value
    16 CONSOLE MESSAGE: line 17: <link rel=preload> must have a valid `as` value
     15CONSOLE MESSAGE: line 14: <link rel=preload> must have a valid `as` value
     16CONSOLE MESSAGE: line 15: <link rel=preload> must have a valid `as` value
    1717
    1818PASS Makes sure that preload requests respect CSP
  • trunk/LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub.html

    r245825 r246045  
    11<!DOCTYPE html>
    22<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; font-src 'none'; style-src 'none'; img-src 'none'; media-src 'none'; connect-src 'none'">
     3<title>Makes sure that preload requests respect CSP</title>
    34<script src="/resources/testharness.js"></script>
    45<script src="/resources/testharnessreport.js"></script>
    56<script src="/preload/resources/preload_helper.js"></script>
    6 <script>
    7     var t = async_test('Makes sure that preload requests respect CSP');
    8 </script>
    97<link rel=preload href="{{host}}:{{ports[http][1]}}/preload/resources/dummy.js" as=style>
    108<link rel=preload href="resources/dummy.css" as=style>
     
    1816<body>
    1917<script>
    20     window.onload = t.step_func(function() {
    21         t.step_timeout(function() {
    22             verifyPreloadAndRTSupport();
     18    setup({explicit_done: true});
     19
     20    var iterations = 0;
     21
     22    function check_finished() {
     23        if (numberOfResourceTimingEntries("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js") == 0 &&
     24            numberOfResourceTimingEntries("resources/dummy.css") == 0 &&
     25            numberOfResourceTimingEntries("resources/square.png") == 0 &&
     26            numberOfResourceTimingEntries("/fonts/CanvasTest.ttf") == 0 &&
     27            numberOfResourceTimingEntries("resources/white.mp4") == 0 &&
     28            numberOfResourceTimingEntries("resources/sound_5.oga") == 0 &&
     29            numberOfResourceTimingEntries("resources/foo.vtt") == 0 &&
     30            numberOfResourceTimingEntries("resources/dummy.xml") == 0) {
     31            done();
     32        }
     33        iterations++;
     34        if (iterations == 10) {
     35            // At least one is expected to fail, but this should give details to the exact failure(s).
    2336            verifyNumberOfResourceTimingEntries("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js", 0);
    2437            verifyNumberOfResourceTimingEntries("resources/dummy.css", 0);
     
    2942            verifyNumberOfResourceTimingEntries("resources/foo.vtt", 0);
    3043            verifyNumberOfResourceTimingEntries("resources/dummy.xml", 0);
    31             t.done();
    32         }, 5000);
     44            done();
     45        } else {
     46            step_timeout(check_finished, 500);
     47        }
     48    }
     49
     50    window.addEventListener("load", function() {
     51        verifyPreloadAndRTSupport();
     52        step_timeout(check_finished, 500);
    3353    });
    3454</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub-expected.txt

    r245825 r246045  
    1313CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/sound_5.oga because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
    1414CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/foo.vtt because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
    15 CONSOLE MESSAGE: line 16: <link rel=preload> must have a valid `as` value
    16 CONSOLE MESSAGE: line 17: <link rel=preload> must have a valid `as` value
     15CONSOLE MESSAGE: line 14: <link rel=preload> must have a valid `as` value
     16CONSOLE MESSAGE: line 15: <link rel=preload> must have a valid `as` value
    1717
    1818PASS Makes sure that preload requests respect CSP
  • trunk/LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub.html

    r245825 r246045  
    11<!DOCTYPE html>
    22<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; default-src 'none'">
     3<title>Makes sure that preload requests respect CSP</title>
    34<script src="/resources/testharness.js"></script>
    45<script src="/resources/testharnessreport.js"></script>
    56<script src="/preload/resources/preload_helper.js"></script>
    6 <script>
    7     var t = async_test('Makes sure that preload requests respect CSP');
    8 </script>
    97<link rel=preload href="{{host}}:{{ports[http][1]}}/preload/resources/dummy.js" as=style>
    108<link rel=preload href="resources/dummy.css" as=style>
     
    1816<body>
    1917<script>
    20     window.onload = t.step_func(function() {
    21         t.step_timeout(function() {
    22             verifyPreloadAndRTSupport();
     18    setup({explicit_done: true});
     19
     20    var iterations = 0;
     21
     22    function check_finished() {
     23        if (numberOfResourceTimingEntries("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js") == 0 &&
     24            numberOfResourceTimingEntries("resources/dummy.css") == 0 &&
     25            numberOfResourceTimingEntries("resources/square.png") == 0 &&
     26            numberOfResourceTimingEntries("/fonts/CanvasTest.ttf") == 0 &&
     27            numberOfResourceTimingEntries("resources/white.mp4") == 0 &&
     28            numberOfResourceTimingEntries("resources/sound_5.oga") == 0 &&
     29            numberOfResourceTimingEntries("resources/foo.vtt") == 0 &&
     30            numberOfResourceTimingEntries("resources/dummy.xml") == 0) {
     31            done();
     32        }
     33        iterations++;
     34        if (iterations == 10) {
     35            // At least one is expected to fail, but this should give details to the exact failure(s).
    2336            verifyNumberOfResourceTimingEntries("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js", 0);
    2437            verifyNumberOfResourceTimingEntries("resources/dummy.css", 0);
     
    2942            verifyNumberOfResourceTimingEntries("resources/foo.vtt", 0);
    3043            verifyNumberOfResourceTimingEntries("resources/dummy.xml", 0);
    31             t.done();
    32         }, 5000);
     44            done();
     45        } else {
     46            step_timeout(check_finished, 500);
     47        }
     48    }
     49
     50    window.addEventListener("load", function() {
     51        verifyPreloadAndRTSupport();
     52        step_timeout(check_finished, 500);
    3353    });
    3454</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/preload/resources/preload_helper.js

    r245825 r246045  
    1313function verifyNumberOfResourceTimingEntries(url, number)
    1414{
    15     var numEntries = performance.getEntriesByName(getAbsoluteURL(url)).length;
    16     assert_equals(numEntries, number, url);
     15    assert_equals(numberOfResourceTimingEntries(url), number, url);
     16}
     17
     18function numberOfResourceTimingEntries(url)
     19{
     20    return performance.getEntriesByName(getAbsoluteURL(url)).length;
    1721}
    1822
  • trunk/Source/WebCore/ChangeLog

    r246043 r246045  
     12019-06-03  Rob Buis  <rbuis@igalia.com>
     2
     3        Implement imagesrcset and imagesizes attributes on link rel=preload
     4        https://bugs.webkit.org/show_bug.cgi?id=192950
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Implement imagesrcset and imagesizes attributes for both Link header
     9        and link element.
     10
     11        Tests: imported/w3c/web-platform-tests/preload/dynamic-adding-preload-imagesrcset.html
     12               imported/w3c/web-platform-tests/preload/link-header-preload-imagesrcset.html
     13               imported/w3c/web-platform-tests/preload/link-header-preload-nonce.html
     14               imported/w3c/web-platform-tests/preload/link-header-preload.html
     15               imported/w3c/web-platform-tests/preload/onload-event.html
     16               imported/w3c/web-platform-tests/preload/preload-with-type.html
     17
     18        * html/HTMLAttributeNames.in:
     19        * html/HTMLLinkElement.cpp:
     20        (WebCore::HTMLLinkElement::process):
     21        * html/HTMLLinkElement.idl:
     22        * loader/LinkHeader.cpp:
     23        (WebCore::paramterNameFromString):
     24        (WebCore::LinkHeader::setValue):
     25        (WebCore::LinkHeader::LinkHeader):
     26        * loader/LinkHeader.h:
     27        (WebCore::LinkHeader::imageSrcSet const):
     28        (WebCore::LinkHeader::imageSizes const):
     29        (WebCore::LinkHeader::isViewportDependent const):
     30        * loader/LinkLoader.cpp:
     31        (WebCore::LinkLoader::loadLinksFromHeader):
     32        (WebCore::LinkLoader::preloadIfNeeded):
     33        (WebCore::LinkLoader::loadLink):
     34        * loader/LinkLoader.h:
     35        * page/RuntimeEnabledFeatures.h:
     36        (WebCore::RuntimeEnabledFeatures::linkPreloadResponsiveImagesEnabled const):
     37        (WebCore::RuntimeEnabledFeatures::setLinkPreloadResponsiveImagesEnabled):
     38
    1392019-06-02  Andy Estes  <aestes@apple.com>
    240
  • trunk/Source/WebCore/html/HTMLAttributeNames.in

    r245825 r246045  
    145145http_equiv
    146146id
     147imagesizes
     148imagesrcset
    147149incremental
    148150indeterminate
  • trunk/Source/WebCore/html/HTMLLinkElement.cpp

    r245825 r246045  
    263263    URL url = getNonEmptyURLAttribute(hrefAttr);
    264264
    265     if (!m_linkLoader.loadLink(m_relAttribute, url, attributeWithoutSynchronization(asAttr), attributeWithoutSynchronization(mediaAttr), attributeWithoutSynchronization(typeAttr), attributeWithoutSynchronization(crossoriginAttr), document()))
     265    if (!m_linkLoader.loadLink(m_relAttribute, url, attributeWithoutSynchronization(asAttr), attributeWithoutSynchronization(mediaAttr), attributeWithoutSynchronization(typeAttr), attributeWithoutSynchronization(crossoriginAttr), attributeWithoutSynchronization(imagesrcsetAttr),  attributeWithoutSynchronization(imagesizesAttr), document()))
    266266        return;
    267267
  • trunk/Source/WebCore/html/HTMLLinkElement.idl

    r245825 r246045  
    3636    [CEReactions=NotNeeded] attribute DOMString as;
    3737    [CEReactions=NotNeeded] attribute DOMString? crossOrigin;
     38    [CEReactions=NotNeeded, Reflect, EnabledAtRuntime=LinkPreloadResponsiveImages] attribute DOMString imageSrcset;
     39    [CEReactions=NotNeeded, Reflect, EnabledAtRuntime=LinkPreloadResponsiveImages] attribute DOMString imageSizes;
    3840
    3941    // DOM Level 2 Style
  • trunk/Source/WebCore/loader/LinkHeader.cpp

    r245825 r246045  
    166166    if (equalLettersIgnoringASCIICase(name, "as"))
    167167        return LinkHeader::LinkParameterAs;
     168    if (equalLettersIgnoringASCIICase(name, "imagesrcset"))
     169        return LinkHeader::LinkParameterImageSrcSet;
     170    if (equalLettersIgnoringASCIICase(name, "imagesizes"))
     171        return LinkHeader::LinkParameterImageSizes;
    168172    return LinkHeader::LinkParameterUnknown;
    169173}
     
    265269}
    266270
    267 void LinkHeader::setValue(LinkParameterName name, String value)
     271void LinkHeader::setValue(LinkParameterName name, String&& value)
    268272{
    269273    switch (name) {
    270274    case LinkParameterRel:
    271275        if (!m_rel)
    272             m_rel = value;
     276            m_rel = WTFMove(value);
    273277        break;
    274278    case LinkParameterAnchor:
     
    276280        break;
    277281    case LinkParameterCrossOrigin:
    278         m_crossOrigin = value;
     282        m_crossOrigin = WTFMove(value);
    279283        break;
    280284    case LinkParameterAs:
    281         m_as = value;
     285        m_as = WTFMove(value);
    282286        break;
    283287    case LinkParameterType:
    284         m_mimeType = value;
     288        m_mimeType = WTFMove(value);
    285289        break;
    286290    case LinkParameterMedia:
    287         m_media = value;
     291        m_media = WTFMove(value);
     292        break;
     293    case LinkParameterImageSrcSet:
     294        m_imageSrcSet = WTFMove(value);
     295        break;
     296    case LinkParameterImageSizes:
     297        m_imageSizes = WTFMove(value);
    288298        break;
    289299    case LinkParameterTitle:
     
    337347        }
    338348
    339         setValue(parameterName, parameterValue);
     349        setValue(parameterName, WTFMove(parameterValue));
    340350    }
    341351    findNextHeader(position, end);
  • trunk/Source/WebCore/loader/LinkHeader.h

    r245825 r246045  
    4242    const String& media() const { return m_media; }
    4343    const String& crossOrigin() const { return m_crossOrigin; }
     44    const String& imageSrcSet() const { return m_imageSrcSet; }
     45    const String& imageSizes() const { return m_imageSizes; }
    4446    bool valid() const { return m_isValid; }
     47    bool isViewportDependent() const { return !media().isEmpty() || !imageSrcSet().isEmpty() || !imageSizes().isEmpty(); }
    4548
    4649    enum LinkParameterName {
     
    5659        LinkParameterCrossOrigin,
    5760        LinkParameterAs,
     61        LinkParameterImageSrcSet,
     62        LinkParameterImageSizes,
    5863    };
    5964
    6065private:
    61     void setValue(LinkParameterName, String value);
     66    void setValue(LinkParameterName, String&& value);
    6267
    6368    String m_url;
     
    6772    String m_media;
    6873    String m_crossOrigin;
     74    String m_imageSrcSet;
     75    String m_imageSizes;
    6976    bool m_isValid { true };
    7077};
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r245825 r246045  
    4545#include "FrameLoaderClient.h"
    4646#include "FrameView.h"
     47#include "HTMLSrcsetParser.h"
    4748#include "LinkHeader.h"
    4849#include "LinkPreloadResourceClients.h"
     
    5051#include "LoaderStrategy.h"
    5152#include "MIMETypeRegistry.h"
     53#include "MediaList.h"
    5254#include "MediaQueryEvaluator.h"
    5355#include "PlatformStrategies.h"
     
    5557#include "RuntimeEnabledFeatures.h"
    5658#include "Settings.h"
     59#include "SizesAttributeParser.h"
    5760#include "StyleResolver.h"
    5861
     
    98101        if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty())
    99102            continue;
    100         if ((mediaAttributeCheck == MediaAttributeCheck::MediaAttributeNotEmpty && header.media().isEmpty())
    101             || (mediaAttributeCheck == MediaAttributeCheck::MediaAttributeEmpty && !header.media().isEmpty())) {
     103        if ((mediaAttributeCheck == MediaAttributeCheck::MediaAttributeNotEmpty && !header.isViewportDependent())
     104            || (mediaAttributeCheck == MediaAttributeCheck::MediaAttributeEmpty && header.isViewportDependent())) {
    102105                continue;
    103106        }
     
    109112            continue;
    110113        preconnectIfNeeded(relAttribute, url, document, header.crossOrigin());
    111         preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
     114        preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), header.imageSrcSet(), header.imageSizes(), nullptr);
    112115    }
    113116}
     
    228231}
    229232
    230 std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& as, const String& media, const String& mimeType, const String& crossOriginMode, LinkLoader* loader)
     233std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& as, const String& media, const String& mimeType, const String& crossOriginMode, const String& imageSrcSet, const String& imageSizes, LinkLoader* loader)
    231234{
    232235    if (!document.loader() || !relAttribute.isLinkPreload)
     
    234237
    235238    ASSERT(RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled());
    236     if (!href.isValid()) {
    237         document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `href` value"_s);
    238         return nullptr;
    239     }
    240239    auto type = LinkLoader::resourceTypeFromAsAttribute(as);
    241240    if (!type) {
     
    243242        return nullptr;
    244243    }
     244    URL url;
     245    if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadResponsiveImagesEnabled() && type == CachedResource::Type::ImageResource && !imageSrcSet.isEmpty()) {
     246        auto sourceSize = SizesAttributeParser(imageSizes, document).length();
     247        auto candidate = bestFitSourceForImageAttributes(document.deviceScaleFactor(), href.string(), imageSrcSet, sourceSize);
     248        url = document.completeURL(URL({ }, candidate.string.toString()));
     249    } else
     250        url = document.completeURL(href);
     251
     252    if (!url.isValid()) {
     253        if (imageSrcSet.isEmpty())
     254            document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `href` value"_s);
     255        else
     256            document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `imagesrcset` value"_s);
     257        return nullptr;
     258    }
    245259    if (!MediaQueryEvaluator::mediaAttributeMatches(document, media))
    246260        return nullptr;
     
    249263
    250264    auto options = CachedResourceLoader::defaultCachedResourceOptions();
    251     auto linkRequest = createPotentialAccessControlRequest(document.completeURL(href), document, crossOriginMode, WTFMove(options));
     265    auto linkRequest = createPotentialAccessControlRequest(url, document, crossOriginMode, WTFMove(options));
    252266    linkRequest.setPriority(CachedResource::defaultPriorityForResourceType(type.value()));
    253267    linkRequest.setInitiator("link");
     
    300314}
    301315
    302 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href, const String& as, const String& media, const String& mimeType, const String& crossOrigin, Document& document)
     316bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href, const String& as, const String& media, const String& mimeType, const String& crossOrigin, const String& imageSrcSet, const String& imageSizes, Document& document)
    303317{
    304318    if (relAttribute.isDNSPrefetch) {
     
    312326
    313327    if (m_client.shouldLoadLink()) {
    314         auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
     328        auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, imageSrcSet, imageSizes, this);
    315329        if (m_preloadResourceClient)
    316330            m_preloadResourceClient->clear();
  • trunk/Source/WebCore/loader/LinkLoader.h

    r245825 r246045  
    5151    virtual ~LinkLoader();
    5252
    53     bool loadLink(const LinkRelAttribute&, const URL&, const String& as, const String& media, const String& type, const String& crossOrigin, Document&);
     53    bool loadLink(const LinkRelAttribute&, const URL&, const String& as, const String& media, const String& type, const String& crossOrigin, const String& imageSrcSet, const String& imageSizes, Document&);
    5454    static Optional<CachedResource::Type> resourceTypeFromAsAttribute(const String& as);
    5555
     
    6464    void notifyFinished(CachedResource&) override;
    6565    static void preconnectIfNeeded(const LinkRelAttribute&, const URL& href, Document&, const String& crossOrigin);
    66     static std::unique_ptr<LinkPreloadResourceClient> preloadIfNeeded(const LinkRelAttribute&, const URL& href, Document&, const String& as, const String& media, const String& type, const String& crossOriginMode, LinkLoader*);
     66    static std::unique_ptr<LinkPreloadResourceClient> preloadIfNeeded(const LinkRelAttribute&, const URL& href, Document&, const String& as, const String& media, const String& type, const String& crossOriginMode, const String& imageSrcSet, const String& imageSizes, LinkLoader*);
    6767    void prefetchIfNeeded(const LinkRelAttribute&, const URL& href, Document&);
    6868
  • trunk/Source/WebCore/page/RuntimeEnabledFeatures.h

    r246002 r246045  
    360360    bool interruptAudioOnPageVisibilityChangeEnabled() const { return m_interruptAudioOnPageVisibilityChangeEnabled; }
    361361    void setInterruptAudioOnPageVisibilityChangeEnabled(bool enabled) { m_interruptAudioOnPageVisibilityChangeEnabled = enabled; }
     362
     363    bool linkPreloadResponsiveImagesEnabled() const { return m_linkPreloadResponsiveImagesEnabled; }
     364    void setLinkPreloadResponsiveImagesEnabled(bool isEnabled) { m_linkPreloadResponsiveImagesEnabled = isEnabled; }
    362365
    363366    WEBCORE_EXPORT static RuntimeEnabledFeatures& sharedFeatures();
     
    546549    bool m_interruptAudioOnPageVisibilityChangeEnabled { false };
    547550
     551    bool m_linkPreloadResponsiveImagesEnabled { false };
     552
    548553    friend class WTF::NeverDestroyed<RuntimeEnabledFeatures>;
    549554};
  • trunk/Source/WebKit/ChangeLog

    r246034 r246045  
     12019-06-03  Rob Buis  <rbuis@igalia.com>
     2
     3        Implement imagesrcset and imagesizes attributes on link rel=preload
     4        https://bugs.webkit.org/show_bug.cgi?id=192950
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Add a runtime flag for link preload responsive images.
     9
     10        * Shared/WebPreferences.yaml:
     11
    1122019-06-03  Darin Adler  <darin@apple.com>
    213
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r246002 r246045  
    16801680  category: experimental
    16811681
     1682LinkPreloadResponsiveImagesEnabled:
     1683  type: bool
     1684  defaultValue: false
     1685  humanReadableName: "Link preload responsive images"
     1686  humanReadableDescription: "Enable link preload responsive images"
     1687  webcoreBinding: RuntimeEnabledFeatures
     1688  category: experimental
     1689
    16821690# Deprecated
    16831691
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r246014 r246045  
     12019-06-03  Rob Buis  <rbuis@igalia.com>
     2
     3        Implement imagesrcset and imagesizes attributes on link rel=preload
     4        https://bugs.webkit.org/show_bug.cgi?id=192950
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Add a runtime flag for link preload responsive images.
     9
     10        * WebView/WebPreferenceKeysPrivate.h:
     11        * WebView/WebPreferences.mm:
     12        (+[WebPreferences initialize]):
     13        (-[WebPreferences linkPreloadResponsiveImagesEnabled]):
     14        (-[WebPreferences setLinkPreloadResponsiveImagesEnabled:]):
     15        * WebView/WebPreferencesPrivate.h:
     16        * WebView/WebView.mm:
     17        (-[WebView _preferencesChanged:]):
     18
    1192019-06-01  Andy Estes  <aestes@apple.com>
    220
  • trunk/Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h

    r244869 r246045  
    270270#define WebKitResizeObserverEnabledPreferenceKey @"WebKitResizeObserverEnabled"
    271271#define WebKitCoreMathMLEnabledPreferenceKey @"WebKitCoreMathMLEnabled"
    272 
     272#define WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey @"WebKitLinkPreloadResponsiveImagesEnabled"
     273
  • trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm

    r244869 r246045  
    693693#endif
    694694        @NO, WebKitCoreMathMLEnabledPreferenceKey,
     695        @NO, WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey,
    695696        nil];
    696697
     
    34693470}
    34703471
     3472- (BOOL)linkPreloadResponsiveImagesEnabled
     3473{
     3474    return [self _boolValueForKey:WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey];
     3475}
     3476
     3477- (void)setLinkPreloadResponsiveImagesEnabled:(BOOL)flag
     3478{
     3479    [self _setBoolValue:flag forKey:WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey];
     3480}
     3481
    34713482@end
    34723483
  • trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h

    r244869 r246045  
    606606- (void)setCoreMathMLEnabled:(BOOL)flag;
    607607- (BOOL)coreMathMLEnabled;
     608
     609- (void)setLinkPreloadResponsiveImagesEnabled:(BOOL)flag;
     610- (BOOL)linkPreloadResponsiveImagesEnabled;
    608611
    609612@property (nonatomic) BOOL visualViewportAPIEnabled;
     
    640643@property (nonatomic) BOOL resizeObserverEnabled;
    641644@property (nonatomic) BOOL coreMathMLEnabled;
     645@property (nonatomic) BOOL linkPreloadResponsiveImagesEnabled;
    642646
    643647#if TARGET_OS_IPHONE
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r245072 r246045  
    31913191    RuntimeEnabledFeatures::sharedFeatures().setFetchAPIKeepAliveEnabled([preferences fetchAPIKeepAliveEnabled]);
    31923192    RuntimeEnabledFeatures::sharedFeatures().setReferrerPolicyAttributeEnabled([preferences referrerPolicyAttributeEnabled]);
     3193    RuntimeEnabledFeatures::sharedFeatures().setLinkPreloadResponsiveImagesEnabled([preferences linkPreloadResponsiveImagesEnabled]);
    31933194
    31943195#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
  • trunk/Tools/ChangeLog

    r246044 r246045  
     12019-06-03  Rob Buis  <rbuis@igalia.com>
     2
     3        Implement imagesrcset and imagesizes attributes on link rel=preload
     4        https://bugs.webkit.org/show_bug.cgi?id=192950
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Add a runtime flag for link preload responsive images.
     9
     10        * DumpRenderTree/mac/DumpRenderTree.mm:
     11        (enableExperimentalFeatures):
     12
    1132019-06-03  Don Olmstead  <don.olmstead@sony.com>
    214
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r245280 r246045  
    876876    [preferences setMediaRecorderEnabled:YES];
    877877    [preferences setReferrerPolicyAttributeEnabled:YES];
     878    [preferences setReferrerPolicyAttributeEnabled:YES];
     879    [preferences setLinkPreloadResponsiveImagesEnabled:YES];
    878880}
    879881
Note: See TracChangeset for help on using the changeset viewer.