Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 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 "core/loader/LinkLoader.h" |
| 48 #include "platform/ContentType.h" | |
| 49 #include "platform/MIMETypeRegistry.h" | |
| 48 #include "platform/RuntimeEnabledFeatures.h" | 50 #include "platform/RuntimeEnabledFeatures.h" |
| 49 #include "platform/TraceEvent.h" | 51 #include "platform/TraceEvent.h" |
| 50 #include "wtf/MainThread.h" | 52 #include "wtf/MainThread.h" |
| 51 | 53 |
| 52 namespace blink { | 54 namespace blink { |
| 53 | 55 |
| 54 using namespace HTMLNames; | 56 using namespace HTMLNames; |
| 55 | 57 |
| 56 static bool match(const StringImpl* impl, const QualifiedName& qName) | 58 static bool match(const StringImpl* impl, const QualifiedName& qName) |
| 57 { | 59 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 MediaQueryEvaluator mediaQueryEvaluator(mediaValues); | 111 MediaQueryEvaluator mediaQueryEvaluator(mediaValues); |
| 110 return mediaQueryEvaluator.eval(mediaQueries.get()); | 112 return mediaQueryEvaluator.eval(mediaQueries.get()); |
| 111 } | 113 } |
| 112 | 114 |
| 113 class TokenPreloadScanner::StartTagScanner { | 115 class TokenPreloadScanner::StartTagScanner { |
| 114 STACK_ALLOCATED(); | 116 STACK_ALLOCATED(); |
| 115 public: | 117 public: |
| 116 StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValue s> mediaValues) | 118 StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValue s> mediaValues) |
| 117 : m_tagImpl(tagImpl) | 119 : m_tagImpl(tagImpl) |
| 118 , m_linkIsStyleSheet(false) | 120 , m_linkIsStyleSheet(false) |
| 121 , m_linkHasType(false) | |
| 122 , m_linkTypeIsSupportedStyleSheet(false) | |
| 119 , m_linkIsPreconnect(false) | 123 , m_linkIsPreconnect(false) |
| 120 , m_linkIsPreload(false) | 124 , m_linkIsPreload(false) |
| 121 , m_linkIsImport(false) | 125 , m_linkIsImport(false) |
| 122 , m_matchedMediaAttribute(true) | 126 , m_matchedMediaAttribute(true) |
| 123 , m_inputIsImage(false) | 127 , m_inputIsImage(false) |
| 124 , m_sourceSize(0) | 128 , m_sourceSize(0) |
| 125 , m_sourceSizeSet(false) | 129 , m_sourceSizeSet(false) |
| 126 , m_defer(FetchRequest::NoDefer) | 130 , m_defer(FetchRequest::NoDefer) |
| 127 , m_crossOrigin(CrossOriginAttributeNotSet) | 131 , m_crossOrigin(CrossOriginAttributeNotSet) |
| 128 , m_mediaValues(mediaValues) | 132 , m_mediaValues(mediaValues) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel .iconType() == InvalidIcon && !rel.isDNSPrefetch(); | 277 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel .iconType() == InvalidIcon && !rel.isDNSPrefetch(); |
| 274 m_linkIsPreconnect = rel.isPreconnect(); | 278 m_linkIsPreconnect = rel.isPreconnect(); |
| 275 m_linkIsPreload = rel.isLinkPreload(); | 279 m_linkIsPreload = rel.isLinkPreload(); |
| 276 m_linkIsImport = rel.isImport(); | 280 m_linkIsImport = rel.isImport(); |
| 277 } else if (match(attributeName, mediaAttr)) { | 281 } else if (match(attributeName, mediaAttr)) { |
| 278 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr ibuteValue); | 282 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr ibuteValue); |
| 279 } else if (match(attributeName, crossoriginAttr)) { | 283 } else if (match(attributeName, crossoriginAttr)) { |
| 280 setCrossOrigin(attributeValue); | 284 setCrossOrigin(attributeValue); |
| 281 } else if (match(attributeName, asAttr)) { | 285 } else if (match(attributeName, asAttr)) { |
| 282 m_asAttributeValue = attributeValue; | 286 m_asAttributeValue = attributeValue; |
| 287 } else if (match(attributeName, typeAttr)) { | |
| 288 m_linkHasType = true; | |
| 289 m_linkTypeIsSupportedStyleSheet = MIMETypeRegistry::isSupportedStyle SheetMIMEType(ContentType(attributeValue).type()); | |
|
Yoav Weiss
2016/01/25 09:55:54
I don't think we need two booleans here. You could
suzyh_UTC10 (ex-contributor)
2016/01/27 00:07:53
Done.
| |
| 283 } | 290 } |
| 284 } | 291 } |
| 285 | 292 |
| 286 template<typename NameType> | 293 template<typename NameType> |
| 287 void processInputAttribute(const NameType& attributeName, const String& attr ibuteValue) | 294 void processInputAttribute(const NameType& attributeName, const String& attr ibuteValue) |
| 288 { | 295 { |
| 289 // FIXME - Don't set type multiple times. | 296 // FIXME - Don't set type multiple times. |
| 290 if (match(attributeName, srcAttr)) | 297 if (match(attributeName, srcAttr)) |
| 291 setUrlToLoad(attributeValue, DisallowURLReplacement); | 298 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 292 else if (match(attributeName, typeAttr)) | 299 else if (match(attributeName, typeAttr)) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 { | 392 { |
| 386 return match(m_tagImpl, linkTag) && m_linkIsPreload && !m_urlToLoad.isEm pty(); | 393 return match(m_tagImpl, linkTag) && m_linkIsPreload && !m_urlToLoad.isEm pty(); |
| 387 } | 394 } |
| 388 | 395 |
| 389 bool shouldPreload() const | 396 bool shouldPreload() const |
| 390 { | 397 { |
| 391 if (m_urlToLoad.isEmpty()) | 398 if (m_urlToLoad.isEmpty()) |
| 392 return false; | 399 return false; |
| 393 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport && !m_linkIsPreload) | 400 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport && !m_linkIsPreload) |
| 394 return false; | 401 return false; |
| 402 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet && m_linkHasType && !m_linkTypeIsSupportedStyleSheet) | |
| 403 return false; | |
| 395 if (match(m_tagImpl, inputTag) && !m_inputIsImage) | 404 if (match(m_tagImpl, inputTag) && !m_inputIsImage) |
| 396 return false; | 405 return false; |
| 397 return true; | 406 return true; |
| 398 } | 407 } |
|
Yoav Weiss
2016/01/25 09:55:54
Nit: Could you add a new line here, since you're a
suzyh_UTC10 (ex-contributor)
2016/01/27 00:07:53
Done.
| |
| 399 void setCrossOrigin(const String& corsSetting) | 408 void setCrossOrigin(const String& corsSetting) |
| 400 { | 409 { |
| 401 m_crossOrigin = crossOriginAttributeValue(corsSetting); | 410 m_crossOrigin = crossOriginAttributeValue(corsSetting); |
| 402 } | 411 } |
| 403 | 412 |
| 404 void setDefer(FetchRequest::DeferOption defer) | 413 void setDefer(FetchRequest::DeferOption defer) |
| 405 { | 414 { |
| 406 m_defer = defer; | 415 m_defer = defer; |
| 407 } | 416 } |
| 408 | 417 |
| 409 bool defer() const | 418 bool defer() const |
| 410 { | 419 { |
| 411 return m_defer; | 420 return m_defer; |
| 412 } | 421 } |
| 413 | 422 |
| 414 const StringImpl* m_tagImpl; | 423 const StringImpl* m_tagImpl; |
| 415 String m_urlToLoad; | 424 String m_urlToLoad; |
| 416 ImageCandidate m_srcsetImageCandidate; | 425 ImageCandidate m_srcsetImageCandidate; |
| 417 String m_charset; | 426 String m_charset; |
| 418 bool m_linkIsStyleSheet; | 427 bool m_linkIsStyleSheet; |
| 428 bool m_linkHasType; | |
| 429 bool m_linkTypeIsSupportedStyleSheet; | |
| 419 bool m_linkIsPreconnect; | 430 bool m_linkIsPreconnect; |
| 420 bool m_linkIsPreload; | 431 bool m_linkIsPreload; |
| 421 bool m_linkIsImport; | 432 bool m_linkIsImport; |
| 422 bool m_matchedMediaAttribute; | 433 bool m_matchedMediaAttribute; |
| 423 bool m_inputIsImage; | 434 bool m_inputIsImage; |
| 424 String m_imgSrcUrl; | 435 String m_imgSrcUrl; |
| 425 String m_srcsetAttributeValue; | 436 String m_srcsetAttributeValue; |
| 426 String m_asAttributeValue; | 437 String m_asAttributeValue; |
| 427 float m_sourceSize; | 438 float m_sourceSize; |
| 428 bool m_sourceSizeSet; | 439 bool m_sourceSizeSet; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 else | 693 else |
| 683 mediaValues = MediaValuesCached::create(*document); | 694 mediaValues = MediaValuesCached::create(*document); |
| 684 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 695 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
| 685 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 696 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 686 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk(); | 697 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk(); |
| 687 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled(); | 698 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled(); |
| 688 referrerPolicy = ReferrerPolicyDefault; | 699 referrerPolicy = ReferrerPolicyDefault; |
| 689 } | 700 } |
| 690 | 701 |
| 691 } | 702 } |
| OLD | NEW |