Changeset 229308 in webkit


Ignore:
Timestamp:
Mar 5, 2018 10:59:34 PM (6 years ago)
Author:
yoav@yoav.ws
Message:

Support for preconnect Link headers
https://bugs.webkit.org/show_bug.cgi?id=181657

Reviewed by Darin Adler.

Source/WebCore:

Move the preconnect functionality into its own function, and
also call this function when Link headers are processed.

Test: http/tests/preconnect/link-header-rel-preconnect-http.php

  • loader/LinkLoader.cpp:

(WebCore::LinkLoader::loadLinksFromHeader): Call preconnectIfNeeded.
(WebCore::LinkLoader::preconnectIfNeeded): Preconnect to a host functionality moved here.
(WebCore::LinkLoader::loadLink): Call preconnectIfNeeded.

  • loader/LinkLoader.h:

LayoutTests:

Add test to see Link preconnect headers trigger a connection.

  • http/tests/preconnect/link-header-rel-preconnect-http-expected.txt: Added.
  • http/tests/preconnect/link-header-rel-preconnect-http.html: Added.
  • http/tests/preconnect/resources/header-preconnect.php: Added.
  • platform/win/TestExpectations: Skipped the preconnect test directory, rather than the individual files in it.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r229306 r229308  
     12018-03-05  Yoav Weiss  <yoav@yoav.ws>
     2
     3        Support for preconnect Link headers
     4        https://bugs.webkit.org/show_bug.cgi?id=181657
     5
     6        Reviewed by Darin Adler.
     7
     8        Add test to see Link preconnect headers trigger a connection.
     9
     10        * http/tests/preconnect/link-header-rel-preconnect-http-expected.txt: Added.
     11        * http/tests/preconnect/link-header-rel-preconnect-http.html: Added.
     12        * http/tests/preconnect/resources/header-preconnect.php: Added.
     13        * platform/win/TestExpectations: Skipped the preconnect test directory, rather than the individual files in it.
     14
    1152018-03-05  Ryan Haddad  <ryanhaddad@apple.com>
    216
  • trunk/LayoutTests/platform/win/TestExpectations

    r229297 r229308  
    37963796# preconnect tests are failing on Windows.
    37973797webkit.org/b/177626 fast/dom/HTMLLinkElement/preconnect-support.html  [ Skip ]
    3798 webkit.org/b/177626 http/tests/preconnect/link-rel-preconnect-http.html [ Skip ]
    3799 webkit.org/b/177626 http/tests/preconnect/link-rel-preconnect-https.html [ Skip ]
     3798webkit.org/b/177626 http/tests/preconnect/ [ Skip ]
    38003799
    38013800webkit.org/b/177964 fast/text/font-display/block-nofinish.html [ Pass ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r229307 r229308  
     12018-03-05  Yoav Weiss  <yoav@yoav.ws>
     2
     3        Support for preconnect Link headers
     4        https://bugs.webkit.org/show_bug.cgi?id=181657
     5
     6        Reviewed by Darin Adler.
     7
     8        Move the preconnect functionality into its own function, and
     9        also call this function when Link headers are processed.
     10
     11        Test: http/tests/preconnect/link-header-rel-preconnect-http.php
     12
     13        * loader/LinkLoader.cpp:
     14        (WebCore::LinkLoader::loadLinksFromHeader): Call preconnectIfNeeded.
     15        (WebCore::LinkLoader::preconnectIfNeeded): Preconnect to a host functionality moved here.
     16        (WebCore::LinkLoader::loadLink): Call preconnectIfNeeded.
     17        * loader/LinkLoader.h:
     18
    1192018-03-05  Antti Koivisto  <antti@apple.com>
    220
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r229196 r229308  
    108108        if (equalIgnoringFragmentIdentifier(url, baseURL))
    109109            continue;
     110        preconnectIfNeeded(relAttribute, url, document, header.crossOrigin());
    110111        preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
    111112    }
     
    209210}
    210211
     212void LinkLoader::preconnectIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& crossOrigin)
     213{
     214    if (!relAttribute.isLinkPreconnect || !href.isValid() || !href.protocolIsInHTTPFamily() || !document.frame())
     215        return;
     216    ASSERT(document.settings().linkPreconnectEnabled());
     217    StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
     218    if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
     219        storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
     220    ASSERT(document.frame()->loader().networkingContext());
     221    platformStrategies()->loaderStrategy()->preconnectTo(document.frame()->loader(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
     222        if (!weakDocument)
     223            return;
     224
     225        if (!error.isNull())
     226            weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Error, makeString(ASCIILiteral("Failed to preconnect to "), href.string(), ASCIILiteral(". Error: "), error.localizedDescription()));
     227        else
     228            weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Info, makeString(ASCIILiteral("Successfuly preconnected to "), href.string()));
     229    });
     230}
     231
    211232std::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)
    212233{
     
    260281    }
    261282
    262     if (relAttribute.isLinkPreconnect && href.isValid() && href.protocolIsInHTTPFamily() && document.frame()) {
    263         ASSERT(document.settings().linkPreconnectEnabled());
    264         StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
    265         if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
    266             storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
    267         ASSERT(document.frame()->loader().networkingContext());
    268         platformStrategies()->loaderStrategy()->preconnectTo(document.frame()->loader(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
    269             if (!weakDocument)
    270                 return;
    271 
    272             if (!error.isNull())
    273                 weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Error, makeString(ASCIILiteral("Failed to preconnect to "), href.string(), ASCIILiteral(". Error: "), error.localizedDescription()));
    274             else
    275                 weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Info, makeString(ASCIILiteral("Successfuly preconnected to "), href.string()));
    276         });
    277     }
     283    preconnectIfNeeded(relAttribute, href, document, crossOrigin);
    278284
    279285    if (m_client.shouldLoadLink()) {
  • trunk/Source/WebCore/loader/LinkLoader.h

    r229196 r229308  
    6565private:
    6666    void notifyFinished(CachedResource&) override;
     67    static void preconnectIfNeeded(const LinkRelAttribute&, const URL& href, Document&, const String& crossOrigin);
    6768    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*);
    6869
Note: See TracChangeset for help on using the changeset viewer.