Changeset 216143 in webkit
- Timestamp:
- May 3, 2017 2:55:25 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r216142 r216143 1 2017-05-03 Yoav Weiss <yoav@yoav.ws> 2 3 Link preload HTMLPreloadScanner support 4 https://bugs.webkit.org/show_bug.cgi?id=170747 5 6 Reviewed by Youenn Fablet. 7 8 * http/tests/preload/preloadscanner_download_resources-expected.txt: Added. 9 * http/tests/preload/preloadscanner_download_resources.html: Added. 10 1 11 2017-05-03 Ryan Haddad <ryanhaddad@apple.com> 2 12 -
trunk/Source/WebCore/ChangeLog
r216139 r216143 1 2017-05-03 Yoav Weiss <yoav@yoav.ws> 2 3 Link preload HTMLPreloadScanner support 4 https://bugs.webkit.org/show_bug.cgi?id=170747 5 6 Reviewed by Youenn Fablet. 7 8 Test: http/tests/preload/preloadscanner_download_resources.html 9 10 * html/parser/HTMLPreloadScanner.cpp: 11 (WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner): Initialize link preload flag. 12 (WebCore::TokenPreloadScanner::StartTagScanner::createPreloadRequest): Create a request only if the type is known (so ignore 13 preloads with unknown type). 14 (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): Add handling for link preload and the `as` attribute. 15 (WebCore::TokenPreloadScanner::StartTagScanner::relAttributeIsStyleSheet): Get LinkRelAttribute as input. 16 (WebCore::TokenPreloadScanner::StartTagScanner::resourceType): Return an std::optional, in case the preload type is unknown. 17 (WebCore::TokenPreloadScanner::StartTagScanner::shouldPreload): Return true for the link preload case. 18 * loader/cache/CachedResourceLoader.cpp: 19 (WebCore::CachedResourceLoader::preload): Return the resource rather than a nullptr if it's already in m_preloads. 20 1 21 2017-05-03 Michael Catanzaro <mcatanzaro@igalia.com> 2 22 -
trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp
r210828 r216143 34 34 #include "HTMLTokenizer.h" 35 35 #include "InputTypeNames.h" 36 #include "LinkLoader.h" 36 37 #include "LinkRelAttribute.h" 37 38 #include "MediaList.h" … … 101 102 : m_tagId(tagId) 102 103 , m_linkIsStyleSheet(false) 104 , m_linkIsPreload(false) 103 105 , m_metaIsViewport(false) 104 106 , m_inputIsImage(false) … … 145 147 return nullptr; 146 148 147 auto request = std::make_unique<PreloadRequest>(initiatorFor(m_tagId), m_urlToLoad, predictedBaseURL, resourceType(), m_mediaAttribute, m_moduleScript); 149 auto type = resourceType(); 150 if (!type) 151 return nullptr; 152 auto request = std::make_unique<PreloadRequest>(initiatorFor(m_tagId), m_urlToLoad, predictedBaseURL, type.value(), m_mediaAttribute, m_moduleScript); 148 153 request->setCrossOriginMode(m_crossOriginMode); 149 154 request->setNonce(m_nonceAttribute); … … 221 226 if (match(attributeName, hrefAttr)) 222 227 setUrlToLoad(attributeValue); 223 else if (match(attributeName, relAttr)) 224 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); 225 else if (match(attributeName, mediaAttr)) 228 else if (match(attributeName, relAttr)) { 229 LinkRelAttribute parsedAttribute { attributeValue }; 230 m_linkIsStyleSheet = relAttributeIsStyleSheet(parsedAttribute); 231 m_linkIsPreload = parsedAttribute.isLinkPreload; 232 } else if (match(attributeName, mediaAttr)) 226 233 m_mediaAttribute = attributeValue; 227 234 else if (match(attributeName, charsetAttr)) … … 231 238 else if (match(attributeName, nonceAttr)) 232 239 m_nonceAttribute = attributeValue; 240 else if (match(attributeName, asAttr)) 241 m_asAttribute = attributeValue; 233 242 break; 234 243 case TagId::Input: … … 253 262 } 254 263 255 static bool relAttributeIsStyleSheet(const String& attributeValue) 256 { 257 LinkRelAttribute parsedAttribute { attributeValue }; 264 static bool relAttributeIsStyleSheet(const LinkRelAttribute& parsedAttribute) 265 { 258 266 return parsedAttribute.isStyleSheet && !parsedAttribute.isAlternate && !parsedAttribute.iconType && !parsedAttribute.isDNSPrefetch; 259 267 } … … 276 284 } 277 285 278 CachedResource::TyperesourceType() const286 std::optional<CachedResource::Type> resourceType() const 279 287 { 280 288 switch (m_tagId) { … … 287 295 return CachedResource::ImageResource; 288 296 case TagId::Link: 289 ASSERT(m_linkIsStyleSheet); 290 return CachedResource::CSSStyleSheet; 297 if (m_linkIsStyleSheet) 298 return CachedResource::CSSStyleSheet; 299 if (m_linkIsPreload) 300 return LinkLoader::resourceTypeFromAsAttribute(m_asAttribute); 301 break; 291 302 case TagId::Meta: 292 303 case TagId::Unknown: … … 309 320 return false; 310 321 311 if (m_tagId == TagId::Link && !m_linkIsStyleSheet )322 if (m_tagId == TagId::Link && !m_linkIsStyleSheet && !m_linkIsPreload) 312 323 return false; 313 324 … … 326 337 String m_crossOriginMode; 327 338 bool m_linkIsStyleSheet; 339 bool m_linkIsPreload; 328 340 String m_mediaAttribute; 329 341 String m_nonceAttribute; 330 342 String m_metaContent; 343 String m_asAttribute; 331 344 bool m_metaIsViewport; 332 345 bool m_inputIsImage; -
trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp
r216051 r216143 1223 1223 1224 1224 CachedResourceHandle<CachedResource> resource = requestResource(type, WTFMove(request), ForPreload::Yes); 1225 if (!resource || (m_preloads && m_preloads->contains(resource.get()))) 1226 return nullptr; 1227 // Fonts need special treatment since just creating the resource doesn't trigger a load. 1228 if (type == CachedResource::FontResource) 1229 downcast<CachedFont>(resource.get())->beginLoadIfNeeded(*this); 1230 resource->increasePreloadCount(); 1231 1232 if (!m_preloads) 1233 m_preloads = std::make_unique<ListHashSet<CachedResource*>>(); 1234 m_preloads->add(resource.get()); 1235 1225 if (resource && (!m_preloads || !m_preloads->contains(resource.get()))) { 1226 // Fonts need special treatment since just creating the resource doesn't trigger a load. 1227 if (type == CachedResource::FontResource) 1228 downcast<CachedFont>(resource.get())->beginLoadIfNeeded(*this); 1229 resource->increasePreloadCount(); 1230 1231 if (!m_preloads) 1232 m_preloads = std::make_unique<ListHashSet<CachedResource*>>(); 1233 m_preloads->add(resource.get()); 1234 } 1236 1235 return resource; 1237 1236 }
Note: See TracChangeset
for help on using the changeset viewer.