Changeset 226962 in webkit


Ignore:
Timestamp:
Jan 15, 2018 10:44:41 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 preconnect.
(WebCore::LinkLoader::preconnect): Preconnect to a host functionality moved here.
(WebCore::LinkLoader::preload): Renamed preloadIfNeeded to preload.
(WebCore::LinkLoader::loadLink): Call preconnect.

  • 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.php: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r226961 r226962  
     12018-01-15  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.php: Added.
     12
    1132018-01-15  Michael Catanzaro  <mcatanzaro@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r226958 r226962  
     12018-01-15  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 preconnect.
     15        (WebCore::LinkLoader::preconnect): Preconnect to a host functionality moved here.
     16        (WebCore::LinkLoader::preload): Renamed `preloadIfNeeded` to `preload`.
     17        (WebCore::LinkLoader::loadLink): Call preconnect.
     18        * loader/LinkLoader.h:
     19
    1202018-01-15  Michael Catanzaro  <mcatanzaro@igalia.com>
    221
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r225747 r226962  
    111111        if (equalIgnoringFragmentIdentifier(url, baseURL))
    112112            continue;
    113         preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
     113        preconnect(relAttribute, url, document, header.crossOrigin());
     114        preload(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
    114115    }
    115116}
     
    212213}
    213214
    214 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)
     215void LinkLoader::preconnect(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& crossOrigin)
     216{
     217    if (!relAttribute.isLinkPreconnect || !href.isValid() || !href.protocolIsInHTTPFamily() || !document.frame())
     218        return;
     219    ASSERT(document.settings().linkPreconnectEnabled());
     220    StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
     221    if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
     222        storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
     223    ASSERT(document.frame()->loader().networkingContext());
     224    platformStrategies()->loaderStrategy()->preconnectTo(*document.frame()->loader().networkingContext(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
     225        if (!weakDocument)
     226            return;
     227
     228        if (!error.isNull())
     229            weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Error, makeString(ASCIILiteral("Failed to preconnect to "), href.string(), ASCIILiteral(". Error: "), error.localizedDescription()));
     230        else
     231            weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Info, makeString(ASCIILiteral("Successfuly preconnected to "), href.string()));
     232    });
     233}
     234
     235std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preload(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& as, const String& media, const String& mimeType, const String& crossOriginMode, LinkLoader* loader)
    215236{
    216237    if (!document.loader() || !relAttribute.isLinkPreload)
     
    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().networkingContext(), 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    preconnect(relAttribute, href, document, crossOrigin);
    278284
    279285    if (m_client.shouldLoadLink()) {
    280         auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
     286        auto resourceClient = preload(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
    281287        if (resourceClient)
    282288            m_preloadResourceClient = WTFMove(resourceClient);
  • trunk/Source/WebCore/loader/LinkLoader.h

    r222422 r226962  
    6565private:
    6666    void notifyFinished(CachedResource&) override;
    67     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*);
     67    static void preconnect(const LinkRelAttribute&, const URL& href, Document&, const String& crossOrigin);
     68    static std::unique_ptr<LinkPreloadResourceClient> preload(const LinkRelAttribute&, const URL& href, Document&, const String& as, const String& media, const String& type, const String& crossOriginMode, LinkLoader*);
    6869
    6970    LinkLoaderClient& m_client;
Note: See TracChangeset for help on using the changeset viewer.