OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ | 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ |
4 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 4 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "core/fetch/IntegrityMetadata.h" | 37 #include "core/fetch/IntegrityMetadata.h" |
38 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
39 #include "core/frame/SubresourceIntegrity.h" | 39 #include "core/frame/SubresourceIntegrity.h" |
40 #include "core/html/CrossOriginAttribute.h" | 40 #include "core/html/CrossOriginAttribute.h" |
41 #include "core/html/HTMLImageElement.h" | 41 #include "core/html/HTMLImageElement.h" |
42 #include "core/html/HTMLMetaElement.h" | 42 #include "core/html/HTMLMetaElement.h" |
43 #include "core/html/LinkRelAttribute.h" | 43 #include "core/html/LinkRelAttribute.h" |
44 #include "core/html/parser/HTMLParserIdioms.h" | 44 #include "core/html/parser/HTMLParserIdioms.h" |
45 #include "core/html/parser/HTMLSrcsetParser.h" | 45 #include "core/html/parser/HTMLSrcsetParser.h" |
46 #include "core/html/parser/HTMLTokenizer.h" | 46 #include "core/html/parser/HTMLTokenizer.h" |
| 47 #include "core/loader/LinkLoader.h" |
47 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
48 #include "platform/TraceEvent.h" | 49 #include "platform/TraceEvent.h" |
49 #include "wtf/MainThread.h" | 50 #include "wtf/MainThread.h" |
50 | 51 |
51 namespace blink { | 52 namespace blink { |
52 | 53 |
53 using namespace HTMLNames; | 54 using namespace HTMLNames; |
54 | 55 |
55 static bool match(const StringImpl* impl, const QualifiedName& qName) | 56 static bool match(const StringImpl* impl, const QualifiedName& qName) |
56 { | 57 { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return mediaQueryEvaluator.eval(mediaQueries.get()); | 110 return mediaQueryEvaluator.eval(mediaQueries.get()); |
110 } | 111 } |
111 | 112 |
112 class TokenPreloadScanner::StartTagScanner { | 113 class TokenPreloadScanner::StartTagScanner { |
113 STACK_ALLOCATED(); | 114 STACK_ALLOCATED(); |
114 public: | 115 public: |
115 StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValue
s> mediaValues) | 116 StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValue
s> mediaValues) |
116 : m_tagImpl(tagImpl) | 117 : m_tagImpl(tagImpl) |
117 , m_linkIsStyleSheet(false) | 118 , m_linkIsStyleSheet(false) |
118 , m_linkIsPreconnect(false) | 119 , m_linkIsPreconnect(false) |
| 120 , m_linkIsPreload(false) |
119 , m_linkIsImport(false) | 121 , m_linkIsImport(false) |
120 , m_matchedMediaAttribute(true) | 122 , m_matchedMediaAttribute(true) |
121 , m_inputIsImage(false) | 123 , m_inputIsImage(false) |
122 , m_sourceSize(0) | 124 , m_sourceSize(0) |
123 , m_sourceSizeSet(false) | 125 , m_sourceSizeSet(false) |
124 , m_defer(FetchRequest::NoDefer) | 126 , m_defer(FetchRequest::NoDefer) |
125 , m_crossOrigin(CrossOriginAttributeNotSet) | 127 , m_crossOrigin(CrossOriginAttributeNotSet) |
126 , m_mediaValues(mediaValues) | 128 , m_mediaValues(mediaValues) |
127 , m_referrerPolicySet(false) | 129 , m_referrerPolicySet(false) |
128 , m_referrerPolicy(ReferrerPolicyDefault) | 130 , m_referrerPolicy(ReferrerPolicyDefault) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ | 177 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ |
176 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); | 178 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); |
177 } | 179 } |
178 } | 180 } |
179 | 181 |
180 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData, const ReferrerPolicy documentReferrerPoli
cy) | 182 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData, const ReferrerPolicy documentReferrerPoli
cy) |
181 { | 183 { |
182 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; | 184 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; |
183 if (shouldPreconnect()) | 185 if (shouldPreconnect()) |
184 requestType = PreloadRequest::RequestTypePreconnect; | 186 requestType = PreloadRequest::RequestTypePreconnect; |
| 187 else if (isLinkRelPreload()) |
| 188 requestType = PreloadRequest::RequestTypeLinkRelPreload; |
185 else if (!shouldPreload() || !m_matchedMediaAttribute) | 189 else if (!shouldPreload() || !m_matchedMediaAttribute) |
186 return nullptr; | 190 return nullptr; |
187 | 191 |
188 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); | 192 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); |
189 FetchRequest::ResourceWidth resourceWidth; | 193 FetchRequest::ResourceWidth resourceWidth; |
190 float sourceSize = m_sourceSize; | 194 float sourceSize = m_sourceSize; |
191 bool sourceSizeSet = m_sourceSizeSet; | 195 bool sourceSizeSet = m_sourceSizeSet; |
192 if (pictureData.picked) { | 196 if (pictureData.picked) { |
193 sourceSizeSet = pictureData.sourceSizeSet; | 197 sourceSizeSet = pictureData.sourceSizeSet; |
194 sourceSize = pictureData.sourceSize; | 198 sourceSize = pictureData.sourceSize; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 template<typename NameType> | 257 template<typename NameType> |
254 void processLinkAttribute(const NameType& attributeName, const String& attri
buteValue) | 258 void processLinkAttribute(const NameType& attributeName, const String& attri
buteValue) |
255 { | 259 { |
256 // FIXME - Don't set rel/media/crossorigin multiple times. | 260 // FIXME - Don't set rel/media/crossorigin multiple times. |
257 if (match(attributeName, hrefAttr)) { | 261 if (match(attributeName, hrefAttr)) { |
258 setUrlToLoad(attributeValue, DisallowURLReplacement); | 262 setUrlToLoad(attributeValue, DisallowURLReplacement); |
259 } else if (match(attributeName, relAttr)) { | 263 } else if (match(attributeName, relAttr)) { |
260 LinkRelAttribute rel(attributeValue); | 264 LinkRelAttribute rel(attributeValue); |
261 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel
.iconType() == InvalidIcon && !rel.isDNSPrefetch(); | 265 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel
.iconType() == InvalidIcon && !rel.isDNSPrefetch(); |
262 m_linkIsPreconnect = rel.isPreconnect(); | 266 m_linkIsPreconnect = rel.isPreconnect(); |
| 267 m_linkIsPreload = rel.isLinkPreload(); |
263 m_linkIsImport = rel.isImport(); | 268 m_linkIsImport = rel.isImport(); |
264 } else if (match(attributeName, mediaAttr)) { | 269 } else if (match(attributeName, mediaAttr)) { |
265 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr
ibuteValue); | 270 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr
ibuteValue); |
266 } else if (match(attributeName, crossoriginAttr)) { | 271 } else if (match(attributeName, crossoriginAttr)) { |
267 setCrossOrigin(attributeValue); | 272 setCrossOrigin(attributeValue); |
| 273 } else if (match(attributeName, asAttr)) { |
| 274 m_asAttributeValue = attributeValue; |
268 } | 275 } |
269 } | 276 } |
270 | 277 |
271 template<typename NameType> | 278 template<typename NameType> |
272 void processInputAttribute(const NameType& attributeName, const String& attr
ibuteValue) | 279 void processInputAttribute(const NameType& attributeName, const String& attr
ibuteValue) |
273 { | 280 { |
274 // FIXME - Don't set type multiple times. | 281 // FIXME - Don't set type multiple times. |
275 if (match(attributeName, srcAttr)) | 282 if (match(attributeName, srcAttr)) |
276 setUrlToLoad(attributeValue, DisallowURLReplacement); | 283 setUrlToLoad(attributeValue, DisallowURLReplacement); |
277 else if (match(attributeName, typeAttr)) | 284 else if (match(attributeName, typeAttr)) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 Resource::Type resourceType() const | 353 Resource::Type resourceType() const |
347 { | 354 { |
348 if (match(m_tagImpl, scriptTag)) | 355 if (match(m_tagImpl, scriptTag)) |
349 return Resource::Script; | 356 return Resource::Script; |
350 if (match(m_tagImpl, imgTag) || match(m_tagImpl, videoTag) || (match(m_t
agImpl, inputTag) && m_inputIsImage)) | 357 if (match(m_tagImpl, imgTag) || match(m_tagImpl, videoTag) || (match(m_t
agImpl, inputTag) && m_inputIsImage)) |
351 return Resource::Image; | 358 return Resource::Image; |
352 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet) | 359 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet) |
353 return Resource::CSSStyleSheet; | 360 return Resource::CSSStyleSheet; |
354 if (m_linkIsPreconnect) | 361 if (m_linkIsPreconnect) |
355 return Resource::Raw; | 362 return Resource::Raw; |
| 363 if (m_linkIsPreload) |
| 364 return LinkLoader::getTypeFromAsAttribute(m_asAttributeValue, nullpt
r); |
356 if (match(m_tagImpl, linkTag) && m_linkIsImport) | 365 if (match(m_tagImpl, linkTag) && m_linkIsImport) |
357 return Resource::ImportResource; | 366 return Resource::ImportResource; |
358 ASSERT_NOT_REACHED(); | 367 ASSERT_NOT_REACHED(); |
359 return Resource::Raw; | 368 return Resource::Raw; |
360 } | 369 } |
361 | 370 |
362 bool shouldPreconnect() const | 371 bool shouldPreconnect() const |
363 { | 372 { |
364 return match(m_tagImpl, linkTag) && m_linkIsPreconnect && !m_urlToLoad.i
sEmpty(); | 373 return match(m_tagImpl, linkTag) && m_linkIsPreconnect && !m_urlToLoad.i
sEmpty(); |
365 } | 374 } |
366 | 375 |
| 376 bool isLinkRelPreload() const |
| 377 { |
| 378 return match(m_tagImpl, linkTag) && m_linkIsPreload && !m_urlToLoad.isEm
pty(); |
| 379 } |
| 380 |
367 bool shouldPreload() const | 381 bool shouldPreload() const |
368 { | 382 { |
369 if (m_urlToLoad.isEmpty()) | 383 if (m_urlToLoad.isEmpty()) |
370 return false; | 384 return false; |
371 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport) | 385 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport
&& !m_linkIsPreload) |
372 return false; | 386 return false; |
373 if (match(m_tagImpl, inputTag) && !m_inputIsImage) | 387 if (match(m_tagImpl, inputTag) && !m_inputIsImage) |
374 return false; | 388 return false; |
375 return true; | 389 return true; |
376 } | 390 } |
377 void setCrossOrigin(const String& corsSetting) | 391 void setCrossOrigin(const String& corsSetting) |
378 { | 392 { |
379 m_crossOrigin = crossOriginAttributeValue(corsSetting); | 393 m_crossOrigin = crossOriginAttributeValue(corsSetting); |
380 } | 394 } |
381 | 395 |
382 void setDefer(FetchRequest::DeferOption defer) | 396 void setDefer(FetchRequest::DeferOption defer) |
383 { | 397 { |
384 m_defer = defer; | 398 m_defer = defer; |
385 | 399 |
386 } | 400 } |
387 | 401 |
388 bool defer() const | 402 bool defer() const |
389 { | 403 { |
390 return m_defer; | 404 return m_defer; |
391 } | 405 } |
392 | 406 |
393 const StringImpl* m_tagImpl; | 407 const StringImpl* m_tagImpl; |
394 String m_urlToLoad; | 408 String m_urlToLoad; |
395 ImageCandidate m_srcsetImageCandidate; | 409 ImageCandidate m_srcsetImageCandidate; |
396 String m_charset; | 410 String m_charset; |
397 bool m_linkIsStyleSheet; | 411 bool m_linkIsStyleSheet; |
398 bool m_linkIsPreconnect; | 412 bool m_linkIsPreconnect; |
| 413 bool m_linkIsPreload; |
399 bool m_linkIsImport; | 414 bool m_linkIsImport; |
400 bool m_matchedMediaAttribute; | 415 bool m_matchedMediaAttribute; |
401 bool m_inputIsImage; | 416 bool m_inputIsImage; |
402 String m_imgSrcUrl; | 417 String m_imgSrcUrl; |
403 String m_srcsetAttributeValue; | 418 String m_srcsetAttributeValue; |
| 419 String m_asAttributeValue; |
404 float m_sourceSize; | 420 float m_sourceSize; |
405 bool m_sourceSizeSet; | 421 bool m_sourceSizeSet; |
406 FetchRequest::DeferOption m_defer; | 422 FetchRequest::DeferOption m_defer; |
407 CrossOriginAttributeValue m_crossOrigin; | 423 CrossOriginAttributeValue m_crossOrigin; |
408 RefPtrWillBeMember<MediaValues> m_mediaValues; | 424 RefPtrWillBeMember<MediaValues> m_mediaValues; |
409 bool m_referrerPolicySet; | 425 bool m_referrerPolicySet; |
410 ReferrerPolicy m_referrerPolicy; | 426 ReferrerPolicy m_referrerPolicy; |
411 IntegrityMetadataSet m_integrityMetadata; | 427 IntegrityMetadataSet m_integrityMetadata; |
412 }; | 428 }; |
413 | 429 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 else | 675 else |
660 mediaValues = MediaValuesCached::create(*document); | 676 mediaValues = MediaValuesCached::create(*document); |
661 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 677 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
662 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 678 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
663 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 679 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
664 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 680 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
665 referrerPolicy = ReferrerPolicyDefault; | 681 referrerPolicy = ReferrerPolicyDefault; |
666 } | 682 } |
667 | 683 |
668 } | 684 } |
OLD | NEW |