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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
href, Document& document) | 131 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
href, Document& document) |
132 { | 132 { |
133 if (relAttribute.isPreconnect() && href.isValid()) { | 133 if (relAttribute.isPreconnect() && href.isValid()) { |
134 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); | 134 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); |
135 if (document.settings()->logDnsPrefetchAndPreconnect()) | 135 if (document.settings()->logDnsPrefetchAndPreconnect()) |
136 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for " + href.host()))); | 136 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for " + href.host()))); |
137 preconnect(href); | 137 preconnect(href); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
| 141 // TODO(yoav): Replace Resource:Type here with some way that conveys priority bu
t not context. |
| 142 static bool getTypeFromAsAttribute(const String& as, Resource::Type& type) |
| 143 { |
| 144 if (as.isEmpty()) |
| 145 return false; |
| 146 // TODO(yoav): Return false also when the `as` value is not a valid one. |
| 147 // TODO(yoav): Add actual types here and make sure priorities work according
ly. |
| 148 type = Resource::Raw; |
| 149 return true; |
| 150 } |
| 151 |
| 152 void LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
L& href, Document& document, const String& as) |
| 153 { |
| 154 if (relAttribute.isLinkPreload()) { |
| 155 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); |
| 156 if (!href.isValid() || href.isEmpty()) { |
| 157 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))
); |
| 158 return; |
| 159 } |
| 160 Resource::Type type; |
| 161 if (!getTypeFromAsAttribute(as, type)) { |
| 162 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value")
)); |
| 163 return; |
| 164 } |
| 165 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
| 166 if (document.settings()->logPreload()) |
| 167 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); |
| 168 setResource(document.fetcher()->fetchLinkPreloadResource(type, linkReque
st)); |
| 169 } |
| 170 } |
| 171 |
141 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t) | 172 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t) |
142 { | 173 { |
143 if (!document) | 174 if (!document) |
144 return false; | 175 return false; |
145 LinkHeaderSet headerSet(headerValue); | 176 LinkHeaderSet headerSet(headerValue); |
146 for (auto& header : headerSet) { | 177 for (auto& header : headerSet) { |
147 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 178 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
148 return false; | 179 return false; |
149 LinkRelAttribute relAttribute(header.rel()); | 180 LinkRelAttribute relAttribute(header.rel()); |
150 KURL url = document->completeURL(header.url()); | 181 KURL url = document->completeURL(header.url()); |
151 if (RuntimeEnabledFeatures::linkHeaderEnabled()) | 182 if (RuntimeEnabledFeatures::linkHeaderEnabled()) |
152 dnsPrefetchIfNeeded(relAttribute, url, *document); | 183 dnsPrefetchIfNeeded(relAttribute, url, *document); |
153 | 184 |
154 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) | 185 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) |
155 preconnectIfNeeded(relAttribute, url, *document); | 186 preconnectIfNeeded(relAttribute, url, *document); |
156 | 187 |
157 // FIXME: Add more supported headers as needed. | 188 // FIXME: Add more supported headers as needed. |
158 } | 189 } |
159 return true; | 190 return true; |
160 } | 191 } |
161 | 192 |
162 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri
ng& crossOriginMode, const String& type, const KURL& href, Document& document) | 193 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri
ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc
ument& document) |
163 { | 194 { |
| 195 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. |
164 dnsPrefetchIfNeeded(relAttribute, href, document); | 196 dnsPrefetchIfNeeded(relAttribute, href, document); |
165 | 197 |
166 preconnectIfNeeded(relAttribute, href, document); | 198 preconnectIfNeeded(relAttribute, href, document); |
167 | 199 |
| 200 preloadIfNeeded(relAttribute, href, document, as); |
| 201 |
168 // FIXME(crbug.com/323096): Should take care of import. | 202 // FIXME(crbug.com/323096): Should take care of import. |
169 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re
lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame(
)) { | 203 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re
lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame(
)) { |
170 if (!m_client->shouldLoadLink()) | 204 if (!m_client->shouldLoadLink()) |
171 return false; | 205 return false; |
172 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; | 206 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; |
173 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 207 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
174 if (!crossOriginMode.isNull()) | 208 if (!crossOriginMode.isNull()) |
175 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c
rossOriginMode); | 209 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c
rossOriginMode); |
176 setResource(document.fetcher()->fetchLinkResource(type, linkRequest)); | 210 setResource(document.fetcher()->fetchLinkResource(type, linkRequest)); |
177 } | 211 } |
(...skipping 22 matching lines...) Expand all Loading... |
200 m_prerender.clear(); | 234 m_prerender.clear(); |
201 } | 235 } |
202 } | 236 } |
203 | 237 |
204 DEFINE_TRACE(LinkLoader) | 238 DEFINE_TRACE(LinkLoader) |
205 { | 239 { |
206 visitor->trace(m_prerender); | 240 visitor->trace(m_prerender); |
207 } | 241 } |
208 | 242 |
209 } | 243 } |
OLD | NEW |