Changeset 246786 in webkit
- Timestamp:
- Jun 25, 2019 1:42:30 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r246781 r246786 1 2019-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 1 23 2019-06-24 Wenson Hsieh <wenson_hsieh@apple.com> 2 24 -
trunk/Source/WebCore/html/HTMLLinkElement.cpp
r246490 r246786 263 263 URL url = getNonEmptyURLAttribute(hrefAttr); 264 264 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())) 266 277 return; 267 278 -
trunk/Source/WebCore/loader/LinkLoader.cpp
r246045 r246786 111 111 if (equalIgnoringFragmentIdentifier(url, baseURL)) 112 112 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); 115 117 } 116 118 } … … 211 213 } 212 214 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()) 215 void 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()) 216 219 return; 217 220 ASSERT(document.settings().linkPreconnectEnabled()); 218 221 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))) 220 223 storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse; 221 224 ASSERT(document.frame()->loader().networkingContext()); … … 231 234 } 232 235 233 std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const Link RelAttribute& 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)236 std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const LinkLoadParameters& params, Document& document, LinkLoader* loader) 237 { 238 if (!document.loader() || !params.relAttribute.isLinkPreload) 236 239 return nullptr; 237 240 238 241 ASSERT(RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled()); 239 auto type = LinkLoader::resourceTypeFromAsAttribute( as);242 auto type = LinkLoader::resourceTypeFromAsAttribute(params.as); 240 243 if (!type) { 241 244 document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> must have a valid `as` value"_s); … … 243 246 } 244 247 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); 248 251 url = document.completeURL(URL({ }, candidate.string.toString())); 249 252 } else 250 url = document.completeURL( href);253 url = document.completeURL(params.href); 251 254 252 255 if (!url.isValid()) { 253 if ( imageSrcSet.isEmpty())256 if (params.imageSrcSet.isEmpty()) 254 257 document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, "<link rel=preload> has an invalid `href` value"_s); 255 258 else … … 257 260 return nullptr; 258 261 } 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)) 262 265 return nullptr; 263 266 264 267 auto options = CachedResourceLoader::defaultCachedResourceOptions(); 265 auto linkRequest = createPotentialAccessControlRequest(url, document, crossOriginMode, WTFMove(options));268 auto linkRequest = createPotentialAccessControlRequest(url, document, params.crossOrigin, WTFMove(options)); 266 269 linkRequest.setPriority(CachedResource::defaultPriorityForResourceType(type.value())); 267 270 linkRequest.setInitiator("link"); … … 279 282 } 280 283 281 void LinkLoader::prefetchIfNeeded(const Link RelAttribute& relAttribute, const URL& href, Document& document)282 { 283 if (! relAttribute.isLinkPrefetch || !href.isValid() || !document.frame() || !m_client.shouldLoadLink())284 void LinkLoader::prefetchIfNeeded(const LinkLoadParameters& params, Document& document) 285 { 286 if (!params.relAttribute.isLinkPrefetch || !params.href.isValid() || !document.frame() || !m_client.shouldLoadLink()) 284 287 return; 285 288 … … 303 306 options.serviceWorkersMode = ServiceWorkersMode::None; 304 307 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); 306 309 if (m_cachedLinkResource) 307 310 m_cachedLinkResource->addClient(*this); … … 314 317 } 315 318 316 bool LinkLoader::loadLink(const Link RelAttribute& 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) {319 bool LinkLoader::loadLink(const LinkLoadParameters& params, Document& document) 320 { 321 if (params.relAttribute.isDNSPrefetch) { 319 322 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt 320 323 // 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); 326 329 327 330 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); 329 332 if (m_preloadResourceClient) 330 333 m_preloadResourceClient->clear(); … … 333 336 } 334 337 335 prefetchIfNeeded( relAttribute, href, document);338 prefetchIfNeeded(params, document); 336 339 337 340 return true; -
trunk/Source/WebCore/loader/LinkLoader.h
r246045 r246786 36 36 #include "CachedResourceHandle.h" 37 37 #include "LinkLoaderClient.h" 38 #include "LinkRelAttribute.h" 38 39 39 40 #include <wtf/WeakPtr.h> … … 44 45 class LinkPreloadResourceClient; 45 46 46 struct LinkRelAttribute; 47 struct 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 }; 47 57 48 58 class LinkLoader : private CachedResourceClient, public CanMakeWeakPtr<LinkLoader> { … … 51 61 virtual ~LinkLoader(); 52 62 53 bool loadLink(const Link RelAttribute&, 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&); 54 64 static Optional<CachedResource::Type> resourceTypeFromAsAttribute(const String& as); 55 65 … … 63 73 private: 64 74 void notifyFinished(CachedResource&) override; 65 static void preconnectIfNeeded(const Link RelAttribute&, const URL& href, Document&, const String& crossOrigin);66 static std::unique_ptr<LinkPreloadResourceClient> preloadIfNeeded(const Link RelAttribute&, 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 Link RelAttribute&, 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&); 68 78 69 79 LinkLoaderClient& m_client;
Note: See TracChangeset
for help on using the changeset viewer.