Changeset 246786 in webkit


Ignore:
Timestamp:
Jun 25, 2019 1:42:30 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Introduce LinkLoadParameters
https://bugs.webkit.org/show_bug.cgi?id=198960

Patch by Rob Buis <rbuis@igalia.com> on 2019-06-25
Reviewed by Frédéric Wang.

Avoid the long parameters lists in LinkLoader by moving them
to LinkLoadParameters.

No new tests because there is no behavior change.

  • html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::process):

  • loader/LinkLoader.cpp:

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

  • loader/LinkLoader.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246781 r246786  
     12019-06-25  Rob Buis  <rbuis@igalia.com>
     2
     3        Introduce LinkLoadParameters
     4        https://bugs.webkit.org/show_bug.cgi?id=198960
     5
     6        Reviewed by Frédéric Wang.
     7
     8        Avoid the long parameters lists in LinkLoader by moving them
     9        to LinkLoadParameters.
     10
     11        No new tests because there is no behavior change.
     12
     13        * html/HTMLLinkElement.cpp:
     14        (WebCore::HTMLLinkElement::process):
     15        * loader/LinkLoader.cpp:
     16        (WebCore::LinkLoader::loadLinksFromHeader):
     17        (WebCore::LinkLoader::preconnectIfNeeded):
     18        (WebCore::LinkLoader::preloadIfNeeded):
     19        (WebCore::LinkLoader::prefetchIfNeeded):
     20        (WebCore::LinkLoader::loadLink):
     21        * loader/LinkLoader.h:
     22
    1232019-06-24  Wenson Hsieh  <wenson_hsieh@apple.com>
    224
  • trunk/Source/WebCore/html/HTMLLinkElement.cpp

    r246490 r246786  
    263263    URL url = getNonEmptyURLAttribute(hrefAttr);
    264264
    265     if (!m_linkLoader.loadLink(m_relAttribute, url, attributeWithoutSynchronization(asAttr), attributeWithoutSynchronization(mediaAttr), attributeWithoutSynchronization(typeAttr), attributeWithoutSynchronization(crossoriginAttr), attributeWithoutSynchronization(imagesrcsetAttr),  attributeWithoutSynchronization(imagesizesAttr), document()))
     265    LinkLoadParameters params {
     266        m_relAttribute,
     267        url,
     268        attributeWithoutSynchronization(asAttr),
     269        attributeWithoutSynchronization(mediaAttr),
     270        attributeWithoutSynchronization(typeAttr),
     271        attributeWithoutSynchronization(crossoriginAttr),
     272        attributeWithoutSynchronization(imagesrcsetAttr),
     273        attributeWithoutSynchronization(imagesizesAttr)
     274    };
     275
     276    if (!m_linkLoader.loadLink(params, document()))
    266277        return;
    267278
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r246045 r246786  
    111111        if (equalIgnoringFragmentIdentifier(url, baseURL))
    112112            continue;
    113         preconnectIfNeeded(relAttribute, url, document, header.crossOrigin());
    114         preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), header.imageSrcSet(), header.imageSizes(), nullptr);
     113
     114        LinkLoadParameters params { relAttribute, url, header.as(), header.media(), header.mimeType(), header.crossOrigin(), header.imageSrcSet(), header.imageSizes() };
     115        preconnectIfNeeded(params, document);
     116        preloadIfNeeded(params, document, nullptr);
    115117    }
    116118}
     
    211213}
    212214
    213 void LinkLoader::preconnectIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& crossOrigin)
    214 {
    215     if (!relAttribute.isLinkPreconnect || !href.isValid() || !href.protocolIsInHTTPFamily() || !document.frame())
     215void LinkLoader::preconnectIfNeeded(const LinkLoadParameters& params, Document& document)
     216{
     217    const URL href = params.href;
     218    if (!params.relAttribute.isLinkPreconnect || !href.isValid() || !params.href.protocolIsInHTTPFamily() || !document.frame())
    216219        return;
    217220    ASSERT(document.settings().linkPreconnectEnabled());
    218221    StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
    219     if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
     222    if (equalIgnoringASCIICase(params.crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
    220223        storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
    221224    ASSERT(document.frame()->loader().networkingContext());
     
    231234}
    232235
    233 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, const String& imageSrcSet, const String& imageSizes, LinkLoader* loader)
    234 {
    235     if (!document.loader() || !relAttribute.isLinkPreload)
     236std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const LinkLoadParameters& params, Document& document, LinkLoader* loader)
     237{
     238    if (!document.loader() || !params.relAttribute.isLinkPreload)
    236239        return nullptr;
    237240
    238241    ASSERT(RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled());
    239     auto type = LinkLoader::resourceTypeFromAsAttribute(as);
     242    auto type = LinkLoader::resourceTypeFromAsAttribute(params.as);
    240243    if (!type) {
    241244        document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> must have a valid `as` value"_s);
     
    243246    }
    244247    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    if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadResponsiveImagesEnabled() && type == CachedResource::Type::ImageResource && !params.imageSrcSet.isEmpty()) {
     249        auto sourceSize = SizesAttributeParser(params.imageSizes, document).length();
     250        auto candidate = bestFitSourceForImageAttributes(document.deviceScaleFactor(), params.href.string(), params.imageSrcSet, sourceSize);
    248251        url = document.completeURL(URL({ }, candidate.string.toString()));
    249252    } else
    250         url = document.completeURL(href);
     253        url = document.completeURL(params.href);
    251254
    252255    if (!url.isValid()) {
    253         if (imageSrcSet.isEmpty())
     256        if (params.imageSrcSet.isEmpty())
    254257            document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `href` value"_s);
    255258        else
     
    257260        return nullptr;
    258261    }
    259     if (!MediaQueryEvaluator::mediaAttributeMatches(document, media))
    260         return nullptr;
    261     if (!isSupportedType(type.value(), mimeType))
     262    if (!MediaQueryEvaluator::mediaAttributeMatches(document, params.media))
     263        return nullptr;
     264    if (!isSupportedType(type.value(), params.mimeType))
    262265        return nullptr;
    263266
    264267    auto options = CachedResourceLoader::defaultCachedResourceOptions();
    265     auto linkRequest = createPotentialAccessControlRequest(url, document, crossOriginMode, WTFMove(options));
     268    auto linkRequest = createPotentialAccessControlRequest(url, document, params.crossOrigin, WTFMove(options));
    266269    linkRequest.setPriority(CachedResource::defaultPriorityForResourceType(type.value()));
    267270    linkRequest.setInitiator("link");
     
    279282}
    280283
    281 void LinkLoader::prefetchIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document)
    282 {
    283     if (!relAttribute.isLinkPrefetch || !href.isValid() || !document.frame() || !m_client.shouldLoadLink())
     284void LinkLoader::prefetchIfNeeded(const LinkLoadParameters& params, Document& document)
     285{
     286    if (!params.relAttribute.isLinkPrefetch || !params.href.isValid() || !document.frame() || !m_client.shouldLoadLink())
    284287        return;
    285288
     
    303306    options.serviceWorkersMode = ServiceWorkersMode::None;
    304307    options.cachingPolicy = CachingPolicy::DisallowCaching;
    305     m_cachedLinkResource = document.cachedResourceLoader().requestLinkResource(type, CachedResourceRequest(ResourceRequest(document.completeURL(href)), options, priority)).value_or(nullptr);
     308    m_cachedLinkResource = document.cachedResourceLoader().requestLinkResource(type, CachedResourceRequest(ResourceRequest { document.completeURL(params.href) }, options, priority)).value_or(nullptr);
    306309    if (m_cachedLinkResource)
    307310        m_cachedLinkResource->addClient(*this);
     
    314317}
    315318
    316 bool 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)
    317 {
    318     if (relAttribute.isDNSPrefetch) {
     319bool LinkLoader::loadLink(const LinkLoadParameters& params, Document& document)
     320{
     321    if (params.relAttribute.isDNSPrefetch) {
    319322        // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
    320323        // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>.
    321         if (document.settings().dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty() && document.frame())
    322             document.frame()->loader().client().prefetchDNS(href.host().toString());
    323     }
    324 
    325     preconnectIfNeeded(relAttribute, href, document, crossOrigin);
     324        if (document.settings().dnsPrefetchingEnabled() && params.href.isValid() && !params.href.isEmpty() && document.frame())
     325            document.frame()->loader().client().prefetchDNS(params.href.host().toString());
     326    }
     327
     328    preconnectIfNeeded(params, document);
    326329
    327330    if (m_client.shouldLoadLink()) {
    328         auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, imageSrcSet, imageSizes, this);
     331        auto resourceClient = preloadIfNeeded(params, document, this);
    329332        if (m_preloadResourceClient)
    330333            m_preloadResourceClient->clear();
     
    333336    }
    334337
    335     prefetchIfNeeded(relAttribute, href, document);
     338    prefetchIfNeeded(params, document);
    336339
    337340    return true;
  • trunk/Source/WebCore/loader/LinkLoader.h

    r246045 r246786  
    3636#include "CachedResourceHandle.h"
    3737#include "LinkLoaderClient.h"
     38#include "LinkRelAttribute.h"
    3839
    3940#include <wtf/WeakPtr.h>
     
    4445class LinkPreloadResourceClient;
    4546
    46 struct LinkRelAttribute;
     47struct LinkLoadParameters {
     48    LinkRelAttribute relAttribute;
     49    URL href;
     50    String as;
     51    String media;
     52    String mimeType;
     53    String crossOrigin;
     54    String imageSrcSet;
     55    String imageSizes;
     56};
    4757
    4858class LinkLoader : private CachedResourceClient, public CanMakeWeakPtr<LinkLoader> {
     
    5161    virtual ~LinkLoader();
    5262
    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&);
     63    bool loadLink(const LinkLoadParameters&, Document&);
    5464    static Optional<CachedResource::Type> resourceTypeFromAsAttribute(const String& as);
    5565
     
    6373private:
    6474    void notifyFinished(CachedResource&) override;
    65     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, const String& imageSrcSet, const String& imageSizes, LinkLoader*);
    67     void prefetchIfNeeded(const LinkRelAttribute&, const URL& href, Document&);
     75    static void preconnectIfNeeded(const LinkLoadParameters&, Document&);
     76    static std::unique_ptr<LinkPreloadResourceClient> preloadIfNeeded(const LinkLoadParameters&, Document&, LinkLoader*);
     77    void prefetchIfNeeded(const LinkLoadParameters&, Document&);
    6878
    6979    LinkLoaderClient& m_client;
Note: See TracChangeset for help on using the changeset viewer.