| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 type = Resource::Script; | 180 type = Resource::Script; |
| 181 } else if (as == "style") { | 181 } else if (as == "style") { |
| 182 type = Resource::CSSStyleSheet; | 182 type = Resource::CSSStyleSheet; |
| 183 } else if (as == "media") { | 183 } else if (as == "media") { |
| 184 type = Resource::Media; | 184 type = Resource::Media; |
| 185 } else if (as == "font") { | 185 } else if (as == "font") { |
| 186 type = Resource::Font; | 186 type = Resource::Font; |
| 187 } else if (as == "track") { | 187 } else if (as == "track") { |
| 188 type = Resource::TextTrack; | 188 type = Resource::TextTrack; |
| 189 } else { | 189 } else { |
| 190 type = Resource::LinkPreload; | 190 type = Resource::Raw; |
| 191 if (!as.isEmpty()) | 191 if (!as.isEmpty()) |
| 192 return false; | 192 return false; |
| 193 } | 193 } |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| 196 | 196 |
| 197 void LinkLoader::createLinkPreloadResourceClient(Resource* resource) | 197 void LinkLoader::createLinkPreloadResourceClient(Resource* resource) |
| 198 { | 198 { |
| 199 if (!resource) | 199 if (!resource) |
| 200 return; | 200 return; |
| 201 switch (resource->getType()) { | 201 switch (resource->getType()) { |
| 202 case Resource::Image: | 202 case Resource::Image: |
| 203 m_linkPreloadResourceClient = LinkPreloadImageResourceClient::create(thi
s, toImageResource(resource)); | 203 m_linkPreloadResourceClient = LinkPreloadImageResourceClient::create(thi
s, toImageResource(resource)); |
| 204 break; | 204 break; |
| 205 case Resource::Script: | 205 case Resource::Script: |
| 206 m_linkPreloadResourceClient = LinkPreloadScriptResourceClient::create(th
is, toScriptResource(resource)); | 206 m_linkPreloadResourceClient = LinkPreloadScriptResourceClient::create(th
is, toScriptResource(resource)); |
| 207 break; | 207 break; |
| 208 case Resource::CSSStyleSheet: | 208 case Resource::CSSStyleSheet: |
| 209 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi
s, toCSSStyleSheetResource(resource)); | 209 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi
s, toCSSStyleSheetResource(resource)); |
| 210 break; | 210 break; |
| 211 case Resource::Font: | 211 case Resource::Font: |
| 212 m_linkPreloadResourceClient = LinkPreloadFontResourceClient::create(this
, toFontResource(resource)); | 212 m_linkPreloadResourceClient = LinkPreloadFontResourceClient::create(this
, toFontResource(resource)); |
| 213 break; | 213 break; |
| 214 case Resource::Media: | 214 case Resource::Media: |
| 215 case Resource::TextTrack: | 215 case Resource::TextTrack: |
| 216 case Resource::Raw: | 216 case Resource::Raw: |
| 217 case Resource::LinkPreload: | |
| 218 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource)); | 217 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource)); |
| 219 break; | 218 break; |
| 220 default: | 219 default: |
| 221 ASSERT_NOT_REACHED(); | 220 ASSERT_NOT_REACHED(); |
| 222 } | 221 } |
| 223 } | 222 } |
| 224 | 223 |
| 225 static bool isSupportedType(Resource::Type resourceType, const String& mimeType) | 224 static bool isSupportedType(Resource::Type resourceType, const String& mimeType) |
| 226 { | 225 { |
| 227 if (mimeType.isEmpty()) | 226 if (mimeType.isEmpty()) |
| 228 return true; | 227 return true; |
| 229 switch (resourceType) { | 228 switch (resourceType) { |
| 230 case Resource::Image: | 229 case Resource::Image: |
| 231 return MIMETypeRegistry::isSupportedImagePrefixedMIMEType(mimeType); | 230 return MIMETypeRegistry::isSupportedImagePrefixedMIMEType(mimeType); |
| 232 case Resource::Script: | 231 case Resource::Script: |
| 233 return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType); | 232 return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType); |
| 234 case Resource::CSSStyleSheet: | 233 case Resource::CSSStyleSheet: |
| 235 return MIMETypeRegistry::isSupportedStyleSheetMIMEType(mimeType); | 234 return MIMETypeRegistry::isSupportedStyleSheetMIMEType(mimeType); |
| 236 case Resource::Font: | 235 case Resource::Font: |
| 237 return MIMETypeRegistry::isSupportedFontMIMEType(mimeType); | 236 return MIMETypeRegistry::isSupportedFontMIMEType(mimeType); |
| 238 case Resource::Media: | 237 case Resource::Media: |
| 239 return MIMETypeRegistry::isSupportedMediaSourceMIMEType(mimeType, String
()); | 238 return MIMETypeRegistry::isSupportedMediaSourceMIMEType(mimeType, String
()); |
| 240 case Resource::TextTrack: | 239 case Resource::TextTrack: |
| 241 return MIMETypeRegistry::isSupportedTextTrackMIMEType(mimeType); | 240 return MIMETypeRegistry::isSupportedTextTrackMIMEType(mimeType); |
| 242 case Resource::Raw: | 241 case Resource::Raw: |
| 243 case Resource::LinkPreload: | |
| 244 return true; | 242 return true; |
| 245 default: | 243 default: |
| 246 ASSERT_NOT_REACHED(); | 244 ASSERT_NOT_REACHED(); |
| 247 } | 245 } |
| 248 return false; | 246 return false; |
| 249 } | 247 } |
| 250 | 248 |
| 251 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
L& href, Document& document, const String& as, const String& mimeType, | 249 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
L& href, Document& document, const String& as, const String& mimeType, |
| 252 const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller calle
r, bool& errorOccurred, ViewportDescription* viewportDescription) | 250 const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller calle
r, bool& errorOccurred, ViewportDescription* viewportDescription) |
| 253 { | 251 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, fals
e); | 287 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, fals
e); |
| 290 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, doc
ument.encodingName()); | 288 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, doc
ument.encodingName()); |
| 291 | 289 |
| 292 if (crossOrigin != CrossOriginAttributeNotSet) | 290 if (crossOrigin != CrossOriginAttributeNotSet) |
| 293 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), cr
ossOrigin); | 291 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), cr
ossOrigin); |
| 294 Settings* settings = document.settings(); | 292 Settings* settings = document.settings(); |
| 295 if (settings && settings->logPreload()) | 293 if (settings && settings->logPreload()) |
| 296 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De
bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); | 294 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De
bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); |
| 297 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); | 295 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); |
| 298 linkRequest.setLinkPreload(true); | 296 linkRequest.setLinkPreload(true); |
| 299 if (resourceType == Resource::LinkPreload) | |
| 300 linkRequest.setDefer(FetchRequest::LazyLoad); | |
| 301 return document.loader()->startPreload(resourceType, linkRequest); | 297 return document.loader()->startPreload(resourceType, linkRequest); |
| 302 } | 298 } |
| 303 | 299 |
| 304 void LinkLoader::loadLinksFromHeader(const String& headerValue, const KURL& base
URL, Document* document, const NetworkHintsInterface& networkHintsInterface, | 300 void LinkLoader::loadLinksFromHeader(const String& headerValue, const KURL& base
URL, Document* document, const NetworkHintsInterface& networkHintsInterface, |
| 305 CanLoadResources canLoadResources, MediaPreloadPolicy mediaPolicy, ViewportD
escriptionWrapper* viewportDescriptionWrapper) | 301 CanLoadResources canLoadResources, MediaPreloadPolicy mediaPolicy, ViewportD
escriptionWrapper* viewportDescriptionWrapper) |
| 306 { | 302 { |
| 307 if (!document || headerValue.isEmpty()) | 303 if (!document || headerValue.isEmpty()) |
| 308 return; | 304 return; |
| 309 LinkHeaderSet headerSet(headerValue); | 305 LinkHeaderSet headerSet(headerValue); |
| 310 for (auto& header : headerSet) { | 306 for (auto& header : headerSet) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 DEFINE_TRACE(LinkLoader) | 395 DEFINE_TRACE(LinkLoader) |
| 400 { | 396 { |
| 401 visitor->trace(m_client); | 397 visitor->trace(m_client); |
| 402 visitor->trace(m_prerender); | 398 visitor->trace(m_prerender); |
| 403 visitor->trace(m_linkPreloadResourceClient); | 399 visitor->trace(m_linkPreloadResourceClient); |
| 404 ResourceOwner<Resource, ResourceClient>::trace(visitor); | 400 ResourceOwner<Resource, ResourceClient>::trace(visitor); |
| 405 PrerenderClient::trace(visitor); | 401 PrerenderClient::trace(visitor); |
| 406 } | 402 } |
| 407 | 403 |
| 408 } // namespace blink | 404 } // namespace blink |
| OLD | NEW |