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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } else if (as == "script") { | 179 } else if (as == "script") { |
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 if (as == "document") { |
| 190 type = Resource::MainResource; |
189 } else { | 191 } else { |
190 type = Resource::Raw; | 192 type = Resource::Raw; |
191 if (!as.isEmpty()) | 193 if (!as.isEmpty()) |
192 return false; | 194 return false; |
193 } | 195 } |
194 return true; | 196 return true; |
195 } | 197 } |
196 | 198 |
197 void LinkLoader::createLinkPreloadResourceClient(Resource* resource) | 199 void LinkLoader::createLinkPreloadResourceClient(Resource* resource) |
198 { | 200 { |
199 if (!resource) | 201 if (!resource) |
200 return; | 202 return; |
201 switch (resource->getType()) { | 203 switch (resource->getType()) { |
202 case Resource::Image: | 204 case Resource::Image: |
203 m_linkPreloadResourceClient = LinkPreloadImageResourceClient::create(thi
s, toImageResource(resource)); | 205 m_linkPreloadResourceClient = LinkPreloadImageResourceClient::create(thi
s, toImageResource(resource)); |
204 break; | 206 break; |
205 case Resource::Script: | 207 case Resource::Script: |
206 m_linkPreloadResourceClient = LinkPreloadScriptResourceClient::create(th
is, toScriptResource(resource)); | 208 m_linkPreloadResourceClient = LinkPreloadScriptResourceClient::create(th
is, toScriptResource(resource)); |
207 break; | 209 break; |
208 case Resource::CSSStyleSheet: | 210 case Resource::CSSStyleSheet: |
209 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi
s, toCSSStyleSheetResource(resource)); | 211 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi
s, toCSSStyleSheetResource(resource)); |
210 break; | 212 break; |
211 case Resource::Font: | 213 case Resource::Font: |
212 m_linkPreloadResourceClient = LinkPreloadFontResourceClient::create(this
, toFontResource(resource)); | 214 m_linkPreloadResourceClient = LinkPreloadFontResourceClient::create(this
, toFontResource(resource)); |
213 break; | 215 break; |
| 216 case Resource::MainResource: |
| 217 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource)); |
| 218 break; |
214 case Resource::Media: | 219 case Resource::Media: |
215 case Resource::TextTrack: | 220 case Resource::TextTrack: |
216 case Resource::Raw: | 221 case Resource::Raw: |
217 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource)); | 222 m_linkPreloadResourceClient = LinkPreloadRawResourceClient::create(this,
toRawResource(resource)); |
218 break; | 223 break; |
219 default: | 224 default: |
220 ASSERT_NOT_REACHED(); | 225 ASSERT_NOT_REACHED(); |
221 } | 226 } |
222 } | 227 } |
223 | 228 |
224 static bool isSupportedType(Resource::Type resourceType, const String& mimeType) | 229 static bool isSupportedType(Resource::Type resourceType, const String& mimeType) |
225 { | 230 { |
226 if (mimeType.isEmpty()) | 231 if (mimeType.isEmpty()) |
227 return true; | 232 return true; |
228 switch (resourceType) { | 233 switch (resourceType) { |
229 case Resource::Image: | 234 case Resource::Image: |
230 return MIMETypeRegistry::isSupportedImagePrefixedMIMEType(mimeType); | 235 return MIMETypeRegistry::isSupportedImagePrefixedMIMEType(mimeType); |
231 case Resource::Script: | 236 case Resource::Script: |
232 return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType); | 237 return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType); |
233 case Resource::CSSStyleSheet: | 238 case Resource::CSSStyleSheet: |
234 return MIMETypeRegistry::isSupportedStyleSheetMIMEType(mimeType); | 239 return MIMETypeRegistry::isSupportedStyleSheetMIMEType(mimeType); |
235 case Resource::Font: | 240 case Resource::Font: |
236 return MIMETypeRegistry::isSupportedFontMIMEType(mimeType); | 241 return MIMETypeRegistry::isSupportedFontMIMEType(mimeType); |
237 case Resource::Media: | 242 case Resource::Media: |
238 return MIMETypeRegistry::isSupportedMediaSourceMIMEType(mimeType, String
()); | 243 return MIMETypeRegistry::isSupportedMediaSourceMIMEType(mimeType, String
()); |
239 case Resource::TextTrack: | 244 case Resource::TextTrack: |
240 return MIMETypeRegistry::isSupportedTextTrackMIMEType(mimeType); | 245 return MIMETypeRegistry::isSupportedTextTrackMIMEType(mimeType); |
241 case Resource::Raw: | 246 case Resource::Raw: |
| 247 case Resource::MainResource: |
242 return true; | 248 return true; |
243 default: | 249 default: |
244 ASSERT_NOT_REACHED(); | 250 ASSERT_NOT_REACHED(); |
245 } | 251 } |
246 return false; | 252 return false; |
247 } | 253 } |
248 | 254 |
249 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
L& href, Document& document, const String& as, const String& mimeType, | 255 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
L& href, Document& document, const String& as, const String& mimeType, |
250 const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller calle
r, bool& errorOccurred, ViewportDescription* viewportDescription) | 256 const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller calle
r, bool& errorOccurred, ViewportDescription* viewportDescription) |
251 { | 257 { |
(...skipping 24 matching lines...) Expand all Loading... |
276 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa
rningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); | 282 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa
rningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); |
277 errorOccurred = true; | 283 errorOccurred = true; |
278 return nullptr; | 284 return nullptr; |
279 } | 285 } |
280 | 286 |
281 if (!isSupportedType(resourceType, mimeType)) { | 287 if (!isSupportedType(resourceType, mimeType)) { |
282 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa
rningMessageLevel, String("<link rel=preload> has an unsupported `type` value"))
); | 288 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa
rningMessageLevel, String("<link rel=preload> has an unsupported `type` value"))
); |
283 return nullptr; | 289 return nullptr; |
284 } | 290 } |
285 ResourceRequest resourceRequest(document.completeURL(href)); | 291 ResourceRequest resourceRequest(document.completeURL(href)); |
| 292 if (resourceType == Resource::MainResource) |
| 293 resourceRequest.setFrameType(WebURLRequest::FrameTypePreload); |
286 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, fals
e); | 294 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, fals
e); |
287 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, doc
ument.encodingName()); | 295 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, doc
ument.encodingName()); |
288 | 296 |
289 if (crossOrigin != CrossOriginAttributeNotSet) | 297 if (crossOrigin != CrossOriginAttributeNotSet) |
290 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), cr
ossOrigin); | 298 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), cr
ossOrigin); |
291 Settings* settings = document.settings(); | 299 Settings* settings = document.settings(); |
292 if (settings && settings->logPreload()) | 300 if (settings && settings->logPreload()) |
293 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De
bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); | 301 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De
bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); |
294 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); | 302 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); |
295 linkRequest.setLinkPreload(true); | 303 linkRequest.setLinkPreload(true); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 DEFINE_TRACE(LinkLoader) | 400 DEFINE_TRACE(LinkLoader) |
393 { | 401 { |
394 visitor->trace(m_client); | 402 visitor->trace(m_client); |
395 visitor->trace(m_prerender); | 403 visitor->trace(m_prerender); |
396 visitor->trace(m_linkPreloadResourceClient); | 404 visitor->trace(m_linkPreloadResourceClient); |
397 ResourceOwner<Resource, ResourceClient>::trace(visitor); | 405 ResourceOwner<Resource, ResourceClient>::trace(visitor); |
398 PrerenderClient::trace(visitor); | 406 PrerenderClient::trace(visitor); |
399 } | 407 } |
400 | 408 |
401 } // namespace blink | 409 } // namespace blink |
OLD | NEW |