| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 float m_sourceSize; | 435 float m_sourceSize; |
| 436 bool m_sourceSizeSet; | 436 bool m_sourceSizeSet; |
| 437 FetchRequest::DeferOption m_defer; | 437 FetchRequest::DeferOption m_defer; |
| 438 CrossOriginAttributeValue m_crossOrigin; | 438 CrossOriginAttributeValue m_crossOrigin; |
| 439 RefPtrWillBeMember<MediaValuesCached> m_mediaValues; | 439 RefPtrWillBeMember<MediaValuesCached> m_mediaValues; |
| 440 bool m_referrerPolicySet; | 440 bool m_referrerPolicySet; |
| 441 ReferrerPolicy m_referrerPolicy; | 441 ReferrerPolicy m_referrerPolicy; |
| 442 IntegrityMetadataSet m_integrityMetadata; | 442 IntegrityMetadataSet m_integrityMetadata; |
| 443 }; | 443 }; |
| 444 | 444 |
| 445 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters) | 445 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters, const MediaValuesCached::MediaValuesC
achedData& mediaValuesCachedData) |
| 446 : m_documentURL(documentURL) | 446 : m_documentURL(documentURL) |
| 447 , m_inStyle(false) | 447 , m_inStyle(false) |
| 448 , m_inPicture(false) | 448 , m_inPicture(false) |
| 449 , m_isAppCacheEnabled(false) | 449 , m_isAppCacheEnabled(false) |
| 450 , m_isCSPEnabled(false) | 450 , m_isCSPEnabled(false) |
| 451 , m_templateCount(0) | 451 , m_templateCount(0) |
| 452 , m_documentParameters(documentParameters) | 452 , m_documentParameters(documentParameters) |
| 453 , m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)) |
| 453 { | 454 { |
| 454 ASSERT(m_documentParameters.get()); | 455 ASSERT(m_documentParameters.get()); |
| 455 ASSERT(m_documentParameters->mediaValues.get()); | 456 ASSERT(m_mediaValues.get()); |
| 456 } | 457 } |
| 457 | 458 |
| 458 TokenPreloadScanner::~TokenPreloadScanner() | 459 TokenPreloadScanner::~TokenPreloadScanner() |
| 459 { | 460 { |
| 460 } | 461 } |
| 461 | 462 |
| 462 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() | 463 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() |
| 463 { | 464 { |
| 464 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); | 465 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); |
| 465 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isAp
pCacheEnabled, m_isCSPEnabled, m_templateCount)); | 466 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isAp
pCacheEnabled, m_isCSPEnabled, m_templateCount)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 482 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) | 483 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) |
| 483 { | 484 { |
| 484 scanCommon(token, source, requests); | 485 scanCommon(token, source, requests); |
| 485 } | 486 } |
| 486 | 487 |
| 487 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) | 488 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) |
| 488 { | 489 { |
| 489 scanCommon(token, source, requests); | 490 scanCommon(token, source, requests); |
| 490 } | 491 } |
| 491 | 492 |
| 492 static void handleMetaViewport(const String& attributeValue, CachedDocumentParam
eters* documentParameters) | 493 static void handleMetaViewport(const String& attributeValue, const CachedDocumen
tParameters* documentParameters, MediaValuesCached* mediaValues) |
| 493 { | 494 { |
| 494 if (!documentParameters->viewportMetaEnabled) | 495 if (!documentParameters->viewportMetaEnabled) |
| 495 return; | 496 return; |
| 496 ViewportDescription description(ViewportDescription::ViewportMeta); | 497 ViewportDescription description(ViewportDescription::ViewportMeta); |
| 497 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); | 498 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); |
| 498 FloatSize initialViewport(documentParameters->mediaValues->deviceWidth(), do
cumentParameters->mediaValues->deviceHeight()); | 499 FloatSize initialViewport(mediaValues->deviceWidth(), mediaValues->deviceHei
ght()); |
| 499 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); | 500 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); |
| 500 documentParameters->mediaValues->setViewportHeight(constraints.layoutSize.he
ight()); | 501 mediaValues->setViewportHeight(constraints.layoutSize.height()); |
| 501 documentParameters->mediaValues->setViewportWidth(constraints.layoutSize.wid
th()); | 502 mediaValues->setViewportWidth(constraints.layoutSize.width()); |
| 502 } | 503 } |
| 503 | 504 |
| 504 static void handleMetaReferrer(const String& attributeValue, CachedDocumentParam
eters* documentParameters, CSSPreloadScanner* cssScanner) | 505 static void handleMetaReferrer(const String& attributeValue, CachedDocumentParam
eters* documentParameters, CSSPreloadScanner* cssScanner) |
| 505 { | 506 { |
| 506 if (attributeValue.isEmpty() || attributeValue.isNull() || !SecurityPolicy::
referrerPolicyFromString(attributeValue, &documentParameters->referrerPolicy)) { | 507 if (attributeValue.isEmpty() || attributeValue.isNull() || !SecurityPolicy::
referrerPolicyFromString(attributeValue, &documentParameters->referrerPolicy)) { |
| 507 documentParameters->referrerPolicy = ReferrerPolicyDefault; | 508 documentParameters->referrerPolicy = ReferrerPolicyDefault; |
| 508 } | 509 } |
| 509 cssScanner->setReferrerPolicy(documentParameters->referrerPolicy); | 510 cssScanner->setReferrerPolicy(documentParameters->referrerPolicy); |
| 510 } | 511 } |
| 511 | 512 |
| 512 template <typename Token> | 513 template <typename Token> |
| 513 static void handleMetaNameAttribute(const Token& token, CachedDocumentParameters
* documentParameters, CSSPreloadScanner* cssScanner) | 514 static void handleMetaNameAttribute(const Token& token, CachedDocumentParameters
* documentParameters, MediaValuesCached* mediaValues, CSSPreloadScanner* cssScan
ner) |
| 514 { | 515 { |
| 515 const typename Token::Attribute* nameAttribute = token.getAttributeItem(name
Attr); | 516 const typename Token::Attribute* nameAttribute = token.getAttributeItem(name
Attr); |
| 516 if (!nameAttribute) | 517 if (!nameAttribute) |
| 517 return; | 518 return; |
| 518 | 519 |
| 519 String nameAttributeValue(nameAttribute->value); | 520 String nameAttributeValue(nameAttribute->value); |
| 520 const typename Token::Attribute* contentAttribute = token.getAttributeItem(c
ontentAttr); | 521 const typename Token::Attribute* contentAttribute = token.getAttributeItem(c
ontentAttr); |
| 521 if (!contentAttribute) | 522 if (!contentAttribute) |
| 522 return; | 523 return; |
| 523 | 524 |
| 524 String contentAttributeValue(contentAttribute->value); | 525 String contentAttributeValue(contentAttribute->value); |
| 525 if (equalIgnoringCase(nameAttributeValue, "viewport")) { | 526 if (equalIgnoringCase(nameAttributeValue, "viewport")) { |
| 526 handleMetaViewport(contentAttributeValue, documentParameters); | 527 handleMetaViewport(contentAttributeValue, documentParameters, mediaValue
s); |
| 527 return; | 528 return; |
| 528 } | 529 } |
| 529 | 530 |
| 530 if (equalIgnoringCase(nameAttributeValue, "referrer")) { | 531 if (equalIgnoringCase(nameAttributeValue, "referrer")) { |
| 531 handleMetaReferrer(contentAttributeValue, documentParameters, cssScanner
); | 532 handleMetaReferrer(contentAttributeValue, documentParameters, cssScanner
); |
| 532 } | 533 } |
| 533 } | 534 } |
| 534 | 535 |
| 535 template <typename Token> | 536 template <typename Token> |
| 536 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) | 537 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { | 601 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { |
| 601 m_isCSPEnabled = true; | 602 m_isCSPEnabled = true; |
| 602 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ | 603 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ |
| 603 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); | 604 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); |
| 604 if (contentAttribute) | 605 if (contentAttribute) |
| 605 m_clientHintsPreferences.updateFromAcceptClientHintsHead
er(String(contentAttribute->value), nullptr); | 606 m_clientHintsPreferences.updateFromAcceptClientHintsHead
er(String(contentAttribute->value), nullptr); |
| 606 } | 607 } |
| 607 return; | 608 return; |
| 608 } | 609 } |
| 609 | 610 |
| 610 handleMetaNameAttribute(token, m_documentParameters.get(), &m_cssSca
nner); | 611 handleMetaNameAttribute(token, m_documentParameters.get(), m_mediaVa
lues.get(), &m_cssScanner); |
| 611 } | 612 } |
| 612 | 613 |
| 613 if (match(tagImpl, pictureTag)) { | 614 if (match(tagImpl, pictureTag)) { |
| 614 m_inPicture = true; | 615 m_inPicture = true; |
| 615 m_pictureData = PictureData(); | 616 m_pictureData = PictureData(); |
| 616 return; | 617 return; |
| 617 } | 618 } |
| 618 | 619 |
| 619 StartTagScanner scanner(tagImpl, m_documentParameters->mediaValues); | 620 StartTagScanner scanner(tagImpl, m_mediaValues); |
| 620 scanner.processAttributes(token.attributes()); | 621 scanner.processAttributes(token.attributes()); |
| 621 if (m_inPicture) | 622 if (m_inPicture) |
| 622 scanner.handlePictureSourceURL(m_pictureData); | 623 scanner.handlePictureSourceURL(m_pictureData); |
| 623 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source, m_clientHintsPreferences, m_pictureData, m_documentPara
meters->referrerPolicy); | 624 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source, m_clientHintsPreferences, m_pictureData, m_documentPara
meters->referrerPolicy); |
| 624 if (request) | 625 if (request) |
| 625 requests.append(request.release()); | 626 requests.append(request.release()); |
| 626 return; | 627 return; |
| 627 } | 628 } |
| 628 default: { | 629 default: { |
| 629 return; | 630 return; |
| 630 } | 631 } |
| 631 } | 632 } |
| 632 } | 633 } |
| 633 | 634 |
| 634 template<typename Token> | 635 template<typename Token> |
| 635 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) | 636 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) |
| 636 { | 637 { |
| 637 ASSERT(m_predictedBaseElementURL.isEmpty()); | 638 ASSERT(m_predictedBaseElementURL.isEmpty()); |
| 638 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem(
hrefAttr)) { | 639 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem(
hrefAttr)) { |
| 639 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute-
>value)); | 640 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute-
>value)); |
| 640 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL(); | 641 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL(); |
| 641 } | 642 } |
| 642 } | 643 } |
| 643 | 644 |
| 644 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K
URL& documentURL, PassOwnPtr<CachedDocumentParameters> documentParameters) | 645 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K
URL& documentURL, PassOwnPtr<CachedDocumentParameters> documentParameters, const
MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) |
| 645 : m_scanner(documentURL, documentParameters) | 646 : m_scanner(documentURL, documentParameters, mediaValuesCachedData) |
| 646 , m_tokenizer(HTMLTokenizer::create(options)) | 647 , m_tokenizer(HTMLTokenizer::create(options)) |
| 647 { | 648 { |
| 648 } | 649 } |
| 649 | 650 |
| 650 HTMLPreloadScanner::~HTMLPreloadScanner() | 651 HTMLPreloadScanner::~HTMLPreloadScanner() |
| 651 { | 652 { |
| 652 } | 653 } |
| 653 | 654 |
| 654 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) | 655 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) |
| 655 { | 656 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 671 while (m_tokenizer->nextToken(m_source, m_token)) { | 672 while (m_tokenizer->nextToken(m_source, m_token)) { |
| 672 if (m_token.type() == HTMLToken::StartTag) | 673 if (m_token.type() == HTMLToken::StartTag) |
| 673 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 674 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
| 674 m_scanner.scan(m_token, m_source, requests); | 675 m_scanner.scan(m_token, m_source, requests); |
| 675 m_token.clear(); | 676 m_token.clear(); |
| 676 } | 677 } |
| 677 | 678 |
| 678 preloader->takeAndPreload(requests); | 679 preloader->takeAndPreload(requests); |
| 679 } | 680 } |
| 680 | 681 |
| 681 CachedDocumentParameters::CachedDocumentParameters(Document* document, PassRefPt
rWillBeRawPtr<MediaValuesCached> givenMediaValues) | 682 CachedDocumentParameters::CachedDocumentParameters(Document* document) |
| 682 { | 683 { |
| 683 ASSERT(isMainThread()); | 684 ASSERT(isMainThread()); |
| 684 ASSERT(document); | 685 ASSERT(document); |
| 685 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); | 686 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); |
| 686 if (givenMediaValues) | |
| 687 mediaValues = givenMediaValues; | |
| 688 else | |
| 689 mediaValues = MediaValuesCached::create(*document); | |
| 690 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | |
| 691 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 687 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 692 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 688 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
| 693 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 689 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
| 694 referrerPolicy = ReferrerPolicyDefault; | 690 referrerPolicy = ReferrerPolicyDefault; |
| 695 } | 691 } |
| 696 | 692 |
| 697 } // namespace blink | 693 } // namespace blink |
| OLD | NEW |