| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 break; | 200 break; |
| 201 case Resource::CSSStyleSheet: | 201 case Resource::CSSStyleSheet: |
| 202 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi
s, toCSSStyleSheetResource(resource.get())); | 202 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi
s, toCSSStyleSheetResource(resource.get())); |
| 203 break; | 203 break; |
| 204 case Resource::Font: | 204 case Resource::Font: |
| 205 m_linkPreloadResourceClient = LinkPreloadFontResourceClient::create(this
, toFontResource(resource.get())); | 205 m_linkPreloadResourceClient = LinkPreloadFontResourceClient::create(this
, toFontResource(resource.get())); |
| 206 break; | 206 break; |
| 207 case Resource::Media: | 207 case Resource::Media: |
| 208 case Resource::TextTrack: | 208 case Resource::TextTrack: |
| 209 case Resource::Raw: | 209 case Resource::Raw: |
| 210 case Resource::LinkSubresource: | 210 case Resource::LinkPreload: |
| 211 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource.get())); | 211 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource.get())); |
| 212 break; | 212 break; |
| 213 default: | 213 default: |
| 214 ASSERT_NOT_REACHED(); | 214 ASSERT_NOT_REACHED(); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 static ResourcePtr<Resource> preloadIfNeeded(const LinkRelAttribute& relAttribut
e, const KURL& href, Document& document, const String& as, LinkCaller caller) | 218 static ResourcePtr<Resource> preloadIfNeeded(const LinkRelAttribute& relAttribut
e, const KURL& href, Document& document, const String& as, LinkCaller caller) |
| 219 { | 219 { |
| 220 if (!document.loader() || !relAttribute.isLinkPreload()) | 220 if (!document.loader() || !relAttribute.isLinkPreload()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn
terface, LinkCalledFromMarkup); | 280 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn
terface, LinkCalledFromMarkup); |
| 281 | 281 |
| 282 if (m_client->shouldLoadLink()) | 282 if (m_client->shouldLoadLink()) |
| 283 createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, docu
ment, as, LinkCalledFromMarkup)); | 283 createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, docu
ment, as, LinkCalledFromMarkup)); |
| 284 | 284 |
| 285 if (href.isEmpty() || !href.isValid()) | 285 if (href.isEmpty() || !href.isValid()) |
| 286 released(); | 286 released(); |
| 287 | 287 |
| 288 // FIXME(crbug.com/323096): Should take care of import. | 288 // FIXME(crbug.com/323096): Should take care of import. |
| 289 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { | 289 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { |
| 290 if (!m_client->shouldLoadLink()) | 290 if (!m_client->shouldLoadLink()) |
| 291 return false; | 291 return false; |
| 292 Resource::Type type = Resource::LinkPrefetch; | 292 UseCounter::count(document, UseCounter::LinkRelPrefetch); |
| 293 if (relAttribute.isLinkSubresource()) { | |
| 294 type = Resource::LinkSubresource; | |
| 295 UseCounter::count(document, UseCounter::LinkRelSubresource); | |
| 296 } else { | |
| 297 UseCounter::count(document, UseCounter::LinkRelPrefetch); | |
| 298 } | |
| 299 | 293 |
| 300 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 294 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
| 301 if (crossOrigin != CrossOriginAttributeNotSet) | 295 if (crossOrigin != CrossOriginAttributeNotSet) |
| 302 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c
rossOrigin); | 296 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c
rossOrigin); |
| 303 setResource(LinkFetchResource::fetch(type, linkRequest, document.fetcher
())); | 297 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest
, document.fetcher())); |
| 304 } | 298 } |
| 305 | 299 |
| 306 if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(rel
Attribute, document)) { | 300 if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(rel
Attribute, document)) { |
| 307 if (!m_prerender) { | 301 if (!m_prerender) { |
| 308 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); | 302 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); |
| 309 } else if (m_prerender->url() != href) { | 303 } else if (m_prerender->url() != href) { |
| 310 m_prerender->cancel(); | 304 m_prerender->cancel(); |
| 311 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); | 305 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); |
| 312 } | 306 } |
| 313 // TODO(gavinp): Handle changes to rel types of existing prerenders. | 307 // TODO(gavinp): Handle changes to rel types of existing prerenders. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 332 | 326 |
| 333 DEFINE_TRACE(LinkLoader) | 327 DEFINE_TRACE(LinkLoader) |
| 334 { | 328 { |
| 335 visitor->trace(m_client); | 329 visitor->trace(m_client); |
| 336 visitor->trace(m_prerender); | 330 visitor->trace(m_prerender); |
| 337 visitor->trace(m_linkPreloadResourceClient); | 331 visitor->trace(m_linkPreloadResourceClient); |
| 338 ResourceOwner<Resource, ResourceClient>::trace(visitor); | 332 ResourceOwner<Resource, ResourceClient>::trace(visitor); |
| 339 } | 333 } |
| 340 | 334 |
| 341 } // namespace blink | 335 } // namespace blink |
| OLD | NEW |