Title: [246786] trunk/Source/WebCore
Revision
246786
Author
[email protected]
Date
2019-06-25 01:42:30 -0700 (Tue, 25 Jun 2019)

Log Message

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

Patch by Rob Buis <[email protected]> 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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (246785 => 246786)


--- trunk/Source/WebCore/ChangeLog	2019-06-25 07:25:59 UTC (rev 246785)
+++ trunk/Source/WebCore/ChangeLog	2019-06-25 08:42:30 UTC (rev 246786)
@@ -1,3 +1,25 @@
+2019-06-25  Rob Buis  <[email protected]>
+
+        Introduce LinkLoadParameters
+        https://bugs.webkit.org/show_bug.cgi?id=198960
+
+        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:
+
 2019-06-24  Wenson Hsieh  <[email protected]>
 
         [Text autosizing] [iPadOS] Revise our heuristics to determine idempotent text autosizing candidates

Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (246785 => 246786)


--- trunk/Source/WebCore/html/HTMLLinkElement.cpp	2019-06-25 07:25:59 UTC (rev 246785)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp	2019-06-25 08:42:30 UTC (rev 246786)
@@ -262,7 +262,18 @@
 
     URL url = ""
 
-    if (!m_linkLoader.loadLink(m_relAttribute, url, attributeWithoutSynchronization(asAttr), attributeWithoutSynchronization(mediaAttr), attributeWithoutSynchronization(typeAttr), attributeWithoutSynchronization(crossoriginAttr), attributeWithoutSynchronization(imagesrcsetAttr),  attributeWithoutSynchronization(imagesizesAttr), document()))
+    LinkLoadParameters params {
+        m_relAttribute,
+        url,
+        attributeWithoutSynchronization(asAttr),
+        attributeWithoutSynchronization(mediaAttr),
+        attributeWithoutSynchronization(typeAttr),
+        attributeWithoutSynchronization(crossoriginAttr),
+        attributeWithoutSynchronization(imagesrcsetAttr),
+        attributeWithoutSynchronization(imagesizesAttr)
+    };
+
+    if (!m_linkLoader.loadLink(params, document()))
         return;
 
     bool treatAsStyleSheet = m_relAttribute.isStyleSheet

Modified: trunk/Source/WebCore/loader/LinkLoader.cpp (246785 => 246786)


--- trunk/Source/WebCore/loader/LinkLoader.cpp	2019-06-25 07:25:59 UTC (rev 246785)
+++ trunk/Source/WebCore/loader/LinkLoader.cpp	2019-06-25 08:42:30 UTC (rev 246786)
@@ -110,8 +110,10 @@
         // Sanity check to avoid re-entrancy here.
         if (equalIgnoringFragmentIdentifier(url, baseURL))
             continue;
-        preconnectIfNeeded(relAttribute, url, document, header.crossOrigin());
-        preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), header.imageSrcSet(), header.imageSizes(), nullptr);
+
+        LinkLoadParameters params { relAttribute, url, header.as(), header.media(), header.mimeType(), header.crossOrigin(), header.imageSrcSet(), header.imageSizes() };
+        preconnectIfNeeded(params, document);
+        preloadIfNeeded(params, document, nullptr);
     }
 }
 
@@ -210,13 +212,14 @@
     return false;
 }
 
-void LinkLoader::preconnectIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& crossOrigin)
+void LinkLoader::preconnectIfNeeded(const LinkLoadParameters& params, Document& document)
 {
-    if (!relAttribute.isLinkPreconnect || !href.isValid() || !href.protocolIsInHTTPFamily() || !document.frame())
+    const URL href = ""
+    if (!params.relAttribute.isLinkPreconnect || !href.isValid() || !params.href.protocolIsInHTTPFamily() || !document.frame())
         return;
     ASSERT(document.settings().linkPreconnectEnabled());
     StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
-    if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
+    if (equalIgnoringASCIICase(params.crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
         storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
     ASSERT(document.frame()->loader().networkingContext());
     platformStrategies()->loaderStrategy()->preconnectTo(document.frame()->loader(), href, storageCredentialsPolicy, [weakDocument = makeWeakPtr(document), href](ResourceError error) {
@@ -230,39 +233,39 @@
     });
 }
 
-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)
+std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const LinkLoadParameters& params, Document& document, LinkLoader* loader)
 {
-    if (!document.loader() || !relAttribute.isLinkPreload)
+    if (!document.loader() || !params.relAttribute.isLinkPreload)
         return nullptr;
 
     ASSERT(RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled());
-    auto type = LinkLoader::resourceTypeFromAsAttribute(as);
+    auto type = LinkLoader::resourceTypeFromAsAttribute(params.as);
     if (!type) {
         document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> must have a valid `as` value"_s);
         return nullptr;
     }
     URL url;
-    if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadResponsiveImagesEnabled() && type == CachedResource::Type::ImageResource && !imageSrcSet.isEmpty()) {
-        auto sourceSize = SizesAttributeParser(imageSizes, document).length();
-        auto candidate = bestFitSourceForImageAttributes(document.deviceScaleFactor(), href.string(), imageSrcSet, sourceSize);
+    if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadResponsiveImagesEnabled() && type == CachedResource::Type::ImageResource && !params.imageSrcSet.isEmpty()) {
+        auto sourceSize = SizesAttributeParser(params.imageSizes, document).length();
+        auto candidate = bestFitSourceForImageAttributes(document.deviceScaleFactor(), params.href.string(), params.imageSrcSet, sourceSize);
         url = "" }, candidate.string.toString()));
     } else
-        url = ""
+        url = ""
 
     if (!url.isValid()) {
-        if (imageSrcSet.isEmpty())
+        if (params.imageSrcSet.isEmpty())
             document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `href` value"_s);
         else
             document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `imagesrcset` value"_s);
         return nullptr;
     }
-    if (!MediaQueryEvaluator::mediaAttributeMatches(document, media))
+    if (!MediaQueryEvaluator::mediaAttributeMatches(document, params.media))
         return nullptr;
-    if (!isSupportedType(type.value(), mimeType))
+    if (!isSupportedType(type.value(), params.mimeType))
         return nullptr;
 
     auto options = CachedResourceLoader::defaultCachedResourceOptions();
-    auto linkRequest = createPotentialAccessControlRequest(url, document, crossOriginMode, WTFMove(options));
+    auto linkRequest = createPotentialAccessControlRequest(url, document, params.crossOrigin, WTFMove(options));
     linkRequest.setPriority(CachedResource::defaultPriorityForResourceType(type.value()));
     linkRequest.setInitiator("link");
     linkRequest.setIgnoreForRequestCount(true);
@@ -278,9 +281,9 @@
     return nullptr;
 }
 
-void LinkLoader::prefetchIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document)
+void LinkLoader::prefetchIfNeeded(const LinkLoadParameters& params, Document& document)
 {
-    if (!relAttribute.isLinkPrefetch || !href.isValid() || !document.frame() || !m_client.shouldLoadLink())
+    if (!params.relAttribute.isLinkPrefetch || !params.href.isValid() || !document.frame() || !m_client.shouldLoadLink())
         return;
 
     ASSERT(RuntimeEnabledFeatures::sharedFeatures().linkPrefetchEnabled());
@@ -302,7 +305,7 @@
     options.mode = FetchOptions::Mode::Navigate;
     options.serviceWorkersMode = ServiceWorkersMode::None;
     options.cachingPolicy = CachingPolicy::DisallowCaching;
-    m_cachedLinkResource = document.cachedResourceLoader().requestLinkResource(type, CachedResourceRequest(ResourceRequest(document.completeURL(href)), options, priority)).value_or(nullptr);
+    m_cachedLinkResource = document.cachedResourceLoader().requestLinkResource(type, CachedResourceRequest(ResourceRequest { document.completeURL(params.href) }, options, priority)).value_or(nullptr);
     if (m_cachedLinkResource)
         m_cachedLinkResource->addClient(*this);
 }
@@ -313,19 +316,19 @@
         m_preloadResourceClient->clear();
 }
 
-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)
+bool LinkLoader::loadLink(const LinkLoadParameters& params, Document& document)
 {
-    if (relAttribute.isDNSPrefetch) {
+    if (params.relAttribute.isDNSPrefetch) {
         // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
         // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>.
-        if (document.settings().dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty() && document.frame())
-            document.frame()->loader().client().prefetchDNS(href.host().toString());
+        if (document.settings().dnsPrefetchingEnabled() && params.href.isValid() && !params.href.isEmpty() && document.frame())
+            document.frame()->loader().client().prefetchDNS(params.href.host().toString());
     }
 
-    preconnectIfNeeded(relAttribute, href, document, crossOrigin);
+    preconnectIfNeeded(params, document);
 
     if (m_client.shouldLoadLink()) {
-        auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, imageSrcSet, imageSizes, this);
+        auto resourceClient = preloadIfNeeded(params, document, this);
         if (m_preloadResourceClient)
             m_preloadResourceClient->clear();
         if (resourceClient)
@@ -332,7 +335,7 @@
             m_preloadResourceClient = WTFMove(resourceClient);
     }
 
-    prefetchIfNeeded(relAttribute, href, document);
+    prefetchIfNeeded(params, document);
 
     return true;
 }

Modified: trunk/Source/WebCore/loader/LinkLoader.h (246785 => 246786)


--- trunk/Source/WebCore/loader/LinkLoader.h	2019-06-25 07:25:59 UTC (rev 246785)
+++ trunk/Source/WebCore/loader/LinkLoader.h	2019-06-25 08:42:30 UTC (rev 246786)
@@ -35,6 +35,7 @@
 #include "CachedResourceClient.h"
 #include "CachedResourceHandle.h"
 #include "LinkLoaderClient.h"
+#include "LinkRelAttribute.h"
 
 #include <wtf/WeakPtr.h>
 
@@ -43,7 +44,16 @@
 class Document;
 class LinkPreloadResourceClient;
 
-struct LinkRelAttribute;
+struct LinkLoadParameters {
+    LinkRelAttribute relAttribute;
+    URL href;
+    String as;
+    String media;
+    String mimeType;
+    String crossOrigin;
+    String imageSrcSet;
+    String imageSizes;
+};
 
 class LinkLoader : private CachedResourceClient, public CanMakeWeakPtr<LinkLoader> {
 public:
@@ -50,7 +60,7 @@
     explicit LinkLoader(LinkLoaderClient&);
     virtual ~LinkLoader();
 
-    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&);
+    bool loadLink(const LinkLoadParameters&, Document&);
     static Optional<CachedResource::Type> resourceTypeFromAsAttribute(const String& as);
 
     enum class MediaAttributeCheck { MediaAttributeEmpty, MediaAttributeNotEmpty, SkipMediaAttributeCheck };
@@ -62,9 +72,9 @@
 
 private:
     void notifyFinished(CachedResource&) override;
-    static void preconnectIfNeeded(const LinkRelAttribute&, const URL& href, Document&, const String& crossOrigin);
-    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*);
-    void prefetchIfNeeded(const LinkRelAttribute&, const URL& href, Document&);
+    static void preconnectIfNeeded(const LinkLoadParameters&, Document&);
+    static std::unique_ptr<LinkPreloadResourceClient> preloadIfNeeded(const LinkLoadParameters&, Document&, LinkLoader*);
+    void prefetchIfNeeded(const LinkLoadParameters&, Document&);
 
     LinkLoaderClient& m_client;
     CachedResourceHandle<CachedResource> m_cachedLinkResource;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to