| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 bool m_referrerPolicySet; | 490 bool m_referrerPolicySet; |
| 491 ReferrerPolicy m_referrerPolicy; | 491 ReferrerPolicy m_referrerPolicy; |
| 492 IntegrityMetadataSet m_integrityMetadata; | 492 IntegrityMetadataSet m_integrityMetadata; |
| 493 }; | 493 }; |
| 494 | 494 |
| 495 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, std::unique_pt
r<CachedDocumentParameters> documentParameters, const MediaValuesCached::MediaVa
luesCachedData& mediaValuesCachedData) | 495 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, std::unique_pt
r<CachedDocumentParameters> documentParameters, const MediaValuesCached::MediaVa
luesCachedData& mediaValuesCachedData) |
| 496 : m_documentURL(documentURL) | 496 : m_documentURL(documentURL) |
| 497 , m_inStyle(false) | 497 , m_inStyle(false) |
| 498 , m_inPicture(false) | 498 , m_inPicture(false) |
| 499 , m_inScript(false) | 499 , m_inScript(false) |
| 500 , m_isCSPEnabled(false) | |
| 501 , m_templateCount(0) | 500 , m_templateCount(0) |
| 502 , m_documentParameters(std::move(documentParameters)) | 501 , m_documentParameters(std::move(documentParameters)) |
| 503 , m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)) | 502 , m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)) |
| 504 , m_didRewind(false) | 503 , m_didRewind(false) |
| 505 { | 504 { |
| 506 ASSERT(m_documentParameters.get()); | 505 ASSERT(m_documentParameters.get()); |
| 507 ASSERT(m_mediaValues.get()); | 506 ASSERT(m_mediaValues.get()); |
| 508 m_cssScanner.setReferrerPolicy(m_documentParameters->referrerPolicy); | 507 m_cssScanner.setReferrerPolicy(m_documentParameters->referrerPolicy); |
| 509 } | 508 } |
| 510 | 509 |
| 511 TokenPreloadScanner::~TokenPreloadScanner() | 510 TokenPreloadScanner::~TokenPreloadScanner() |
| 512 { | 511 { |
| 513 } | 512 } |
| 514 | 513 |
| 515 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() | 514 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() |
| 516 { | 515 { |
| 517 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); | 516 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); |
| 518 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_inSc
ript, m_isCSPEnabled, m_templateCount)); | 517 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_inSc
ript, m_templateCount)); |
| 519 return checkpoint; | 518 return checkpoint; |
| 520 } | 519 } |
| 521 | 520 |
| 522 void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex
) | 521 void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex
) |
| 523 { | 522 { |
| 524 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, che
ckpointIndex is invalid. | 523 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, che
ckpointIndex is invalid. |
| 525 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; | 524 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; |
| 526 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; | 525 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; |
| 527 m_inStyle = checkpoint.inStyle; | 526 m_inStyle = checkpoint.inStyle; |
| 528 m_isCSPEnabled = checkpoint.isCSPEnabled; | |
| 529 m_templateCount = checkpoint.templateCount; | 527 m_templateCount = checkpoint.templateCount; |
| 530 | 528 |
| 531 m_didRewind = true; | 529 m_didRewind = true; |
| 532 m_inScript = checkpoint.inScript; | 530 m_inScript = checkpoint.inScript; |
| 533 | 531 |
| 534 m_cssScanner.reset(); | 532 m_cssScanner.reset(); |
| 535 m_checkpoints.clear(); | 533 m_checkpoints.clear(); |
| 536 } | 534 } |
| 537 | 535 |
| 538 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewport) | 536 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewport, bool
* isCSPMetaTag) |
| 539 { | 537 { |
| 540 scanCommon(token, source, requests, viewport, nullptr); | 538 scanCommon(token, source, requests, viewport, isCSPMetaTag, nullptr); |
| 541 } | 539 } |
| 542 | 540 |
| 543 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewpor
t, bool* likelyDocumentWriteScript) | 541 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewpor
t, bool* isCSPMetaTag, bool* likelyDocumentWriteScript) |
| 544 { | 542 { |
| 545 scanCommon(token, source, requests, viewport, likelyDocumentWriteScript); | 543 scanCommon(token, source, requests, viewport, isCSPMetaTag, likelyDocumentWr
iteScript); |
| 546 } | 544 } |
| 547 | 545 |
| 548 static void handleMetaViewport(const String& attributeValue, const CachedDocumen
tParameters* documentParameters, MediaValuesCached* mediaValues, ViewportDescrip
tionWrapper* viewport) | 546 static void handleMetaViewport(const String& attributeValue, const CachedDocumen
tParameters* documentParameters, MediaValuesCached* mediaValues, ViewportDescrip
tionWrapper* viewport) |
| 549 { | 547 { |
| 550 if (!documentParameters->viewportMetaEnabled) | 548 if (!documentParameters->viewportMetaEnabled) |
| 551 return; | 549 return; |
| 552 ViewportDescription description(ViewportDescription::ViewportMeta); | 550 ViewportDescription description(ViewportDescription::ViewportMeta); |
| 553 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); | 551 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); |
| 554 if (viewport) { | 552 if (viewport) { |
| 555 viewport->description = description; | 553 viewport->description = description; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 } | 642 } |
| 645 if (source.find("Math.random") != WTF::kNotFound | 643 if (source.find("Math.random") != WTF::kNotFound |
| 646 || source.find("Date") != WTF::kNotFound) { | 644 || source.find("Date") != WTF::kNotFound) { |
| 647 LogGatedEvaluation(GatedEvaluationNondeterminism); | 645 LogGatedEvaluation(GatedEvaluationNondeterminism); |
| 648 return false; | 646 return false; |
| 649 } | 647 } |
| 650 return true; | 648 return true; |
| 651 } | 649 } |
| 652 | 650 |
| 653 template <typename Token> | 651 template <typename Token> |
| 654 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewport, bo
ol* likelyDocumentWriteScript) | 652 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewport, bo
ol* isCSPMetaTag, bool* likelyDocumentWriteScript) |
| 655 { | 653 { |
| 656 if (!m_documentParameters->doHtmlPreloadScanning) | 654 if (!m_documentParameters->doHtmlPreloadScanning) |
| 657 return; | 655 return; |
| 658 | 656 |
| 659 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s | |
| 660 if (m_isCSPEnabled) | |
| 661 return; | |
| 662 | |
| 663 switch (token.type()) { | 657 switch (token.type()) { |
| 664 case HTMLToken::Character: { | 658 case HTMLToken::Character: { |
| 665 if (m_inStyle) { | 659 if (m_inStyle) { |
| 666 m_cssScanner.scan(token.data(), source, requests, m_predictedBaseEle
mentURL); | 660 m_cssScanner.scan(token.data(), source, requests, m_predictedBaseEle
mentURL); |
| 667 } else if (m_inScript && likelyDocumentWriteScript && !m_didRewind) { | 661 } else if (m_inScript && likelyDocumentWriteScript && !m_didRewind) { |
| 668 // Don't mark scripts for evaluation if the preloader rewound to a | 662 // Don't mark scripts for evaluation if the preloader rewound to a |
| 669 // previous checkpoint. This could cause re-evaluation of scripts if | 663 // previous checkpoint. This could cause re-evaluation of scripts if |
| 670 // care isn't given. | 664 // care isn't given. |
| 671 // TODO(csharrison): Revisit this if rewinds are low hanging fruit f
or the | 665 // TODO(csharrison): Revisit this if rewinds are low hanging fruit f
or the |
| 672 // document.write evaluator. | 666 // document.write evaluator. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 if (!m_predictedBaseElementURL.isEmpty()) | 711 if (!m_predictedBaseElementURL.isEmpty()) |
| 718 return; | 712 return; |
| 719 updatePredictedBaseURL(token); | 713 updatePredictedBaseURL(token); |
| 720 return; | 714 return; |
| 721 } | 715 } |
| 722 if (match(tagImpl, metaTag)) { | 716 if (match(tagImpl, metaTag)) { |
| 723 const typename Token::Attribute* equivAttribute = token.getAttribute
Item(http_equivAttr); | 717 const typename Token::Attribute* equivAttribute = token.getAttribute
Item(http_equivAttr); |
| 724 if (equivAttribute) { | 718 if (equivAttribute) { |
| 725 String equivAttributeValue(equivAttribute->value()); | 719 String equivAttributeValue(equivAttribute->value()); |
| 726 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { | 720 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { |
| 727 m_isCSPEnabled = true; | 721 *isCSPMetaTag = true; |
| 728 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ | 722 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ |
| 729 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); | 723 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); |
| 730 if (contentAttribute) | 724 if (contentAttribute) |
| 731 m_clientHintsPreferences.updateFromAcceptClientHintsHead
er(contentAttribute->value(), nullptr); | 725 m_clientHintsPreferences.updateFromAcceptClientHintsHead
er(contentAttribute->value(), nullptr); |
| 732 } | 726 } |
| 733 return; | 727 return; |
| 734 } | 728 } |
| 735 | 729 |
| 736 handleMetaNameAttribute(token, m_documentParameters.get(), m_mediaVa
lues.get(), &m_cssScanner, viewport); | 730 handleMetaNameAttribute(token, m_documentParameters.get(), m_mediaVa
lues.get(), &m_cssScanner, viewport); |
| 737 } | 731 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 | 784 |
| 791 // When we start scanning, our best prediction of the baseElementURL is the
real one! | 785 // When we start scanning, our best prediction of the baseElementURL is the
real one! |
| 792 if (!startingBaseElementURL.isEmpty()) | 786 if (!startingBaseElementURL.isEmpty()) |
| 793 m_scanner.setPredictedBaseElementURL(startingBaseElementURL); | 787 m_scanner.setPredictedBaseElementURL(startingBaseElementURL); |
| 794 | 788 |
| 795 PreloadRequestStream requests; | 789 PreloadRequestStream requests; |
| 796 | 790 |
| 797 while (m_tokenizer->nextToken(m_source, m_token)) { | 791 while (m_tokenizer->nextToken(m_source, m_token)) { |
| 798 if (m_token.type() == HTMLToken::StartTag) | 792 if (m_token.type() == HTMLToken::StartTag) |
| 799 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 793 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
| 800 m_scanner.scan(m_token, m_source, requests, viewport); | 794 bool isCSPMetaTag = false; |
| 795 m_scanner.scan(m_token, m_source, requests, viewport, &isCSPMetaTag); |
| 801 m_token.clear(); | 796 m_token.clear(); |
| 797 // Don't preload anything if a CSP meta tag is found. We should never |
| 798 // really find them here because the HTMLPreloadScanner is only used for |
| 799 // dynamically added markup. |
| 800 if (isCSPMetaTag) |
| 801 return; |
| 802 } | 802 } |
| 803 | 803 |
| 804 preloader->takeAndPreload(requests); | 804 preloader->takeAndPreload(requests); |
| 805 } | 805 } |
| 806 | 806 |
| 807 CachedDocumentParameters::CachedDocumentParameters(Document* document) | 807 CachedDocumentParameters::CachedDocumentParameters(Document* document) |
| 808 { | 808 { |
| 809 ASSERT(isMainThread()); | 809 ASSERT(isMainThread()); |
| 810 ASSERT(document); | 810 ASSERT(document); |
| 811 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); | 811 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); |
| 812 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame()
&& document->frame()->isMainFrame(); | 812 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame()
&& document->frame()->isMainFrame(); |
| 813 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 813 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 814 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 814 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
| 815 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 815 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
| 816 referrerPolicy = document->getReferrerPolicy(); | 816 referrerPolicy = document->getReferrerPolicy(); |
| 817 } | 817 } |
| 818 | 818 |
| 819 } // namespace blink | 819 } // namespace blink |
| OLD | NEW |