| 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 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 * | 29 * |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "core/loader/LinkLoader.h" | 33 #include "core/loader/LinkLoader.h" |
| 34 | 34 |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/fetch/FetchInitiatorTypeNames.h" | 36 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 37 #include "core/fetch/FetchRequest.h" | 37 #include "core/fetch/FetchRequest.h" |
| 38 #include "core/fetch/LinkFetchResource.h" |
| 38 #include "core/fetch/ResourceFetcher.h" | 39 #include "core/fetch/ResourceFetcher.h" |
| 39 #include "core/frame/Settings.h" | 40 #include "core/frame/Settings.h" |
| 40 #include "core/html/CrossOriginAttribute.h" | 41 #include "core/html/CrossOriginAttribute.h" |
| 41 #include "core/html/LinkRelAttribute.h" | 42 #include "core/html/LinkRelAttribute.h" |
| 42 #include "core/inspector/ConsoleMessage.h" | 43 #include "core/inspector/ConsoleMessage.h" |
| 43 #include "core/loader/LinkHeader.h" | 44 #include "core/loader/LinkHeader.h" |
| 44 #include "core/loader/PrerenderHandle.h" | 45 #include "core/loader/PrerenderHandle.h" |
| 45 #include "platform/Prerender.h" | 46 #include "platform/Prerender.h" |
| 46 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
| 47 #include "platform/network/NetworkHints.h" | 48 #include "platform/network/NetworkHints.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 Resource::Type priorityType; | 175 Resource::Type priorityType; |
| 175 if (!getPriorityTypeFromAsAttribute(as, priorityType)) { | 176 if (!getPriorityTypeFromAsAttribute(as, priorityType)) { |
| 176 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value")
)); | 177 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value")
)); |
| 177 return; | 178 return; |
| 178 } | 179 } |
| 179 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 180 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
| 180 linkRequest.setPriority(ResourceFetcher::loadPriority(priorityType, link
Request)); | 181 linkRequest.setPriority(ResourceFetcher::loadPriority(priorityType, link
Request)); |
| 181 Settings* settings = document.settings(); | 182 Settings* settings = document.settings(); |
| 182 if (settings && settings->logPreload()) | 183 if (settings && settings->logPreload()) |
| 183 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); | 184 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); |
| 184 setResource(document.fetcher()->fetchLinkPreloadResource(Resource::LinkP
reload, linkRequest)); | 185 setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest,
document.fetcher())); |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t) | 189 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t) |
| 189 { | 190 { |
| 190 if (!document) | 191 if (!document) |
| 191 return false; | 192 return false; |
| 192 LinkHeaderSet headerSet(headerValue); | 193 LinkHeaderSet headerSet(headerValue); |
| 193 for (auto& header : headerSet) { | 194 for (auto& header : headerSet) { |
| 194 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 195 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 220 preloadIfNeeded(relAttribute, href, document, as); | 221 preloadIfNeeded(relAttribute, href, document, as); |
| 221 | 222 |
| 222 // FIXME(crbug.com/323096): Should take care of import. | 223 // FIXME(crbug.com/323096): Should take care of import. |
| 223 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { | 224 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { |
| 224 if (!m_client->shouldLoadLink()) | 225 if (!m_client->shouldLoadLink()) |
| 225 return false; | 226 return false; |
| 226 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; | 227 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; |
| 227 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 228 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
| 228 if (!crossOriginMode.isNull()) | 229 if (!crossOriginMode.isNull()) |
| 229 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c
rossOriginMode); | 230 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c
rossOriginMode); |
| 230 setResource(document.fetcher()->fetchLinkResource(type, linkRequest)); | 231 setResource(LinkFetchResource::fetch(type, linkRequest, document.fetcher
())); |
| 231 } | 232 } |
| 232 | 233 |
| 233 if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(rel
Attribute)) { | 234 if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(rel
Attribute)) { |
| 234 if (!m_prerender) { | 235 if (!m_prerender) { |
| 235 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); | 236 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); |
| 236 } else if (m_prerender->url() != href) { | 237 } else if (m_prerender->url() != href) { |
| 237 m_prerender->cancel(); | 238 m_prerender->cancel(); |
| 238 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); | 239 m_prerender = PrerenderHandle::create(document, this, href, prerende
rRelTypes); |
| 239 } | 240 } |
| 240 // TODO(gavinp): Handle changes to rel types of existing prerenders. | 241 // TODO(gavinp): Handle changes to rel types of existing prerenders. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 254 m_prerender.clear(); | 255 m_prerender.clear(); |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 | 258 |
| 258 DEFINE_TRACE(LinkLoader) | 259 DEFINE_TRACE(LinkLoader) |
| 259 { | 260 { |
| 260 visitor->trace(m_prerender); | 261 visitor->trace(m_prerender); |
| 261 } | 262 } |
| 262 | 263 |
| 263 } | 264 } |
| OLD | NEW |