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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; | 479 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; |
480 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; | 480 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; |
481 m_inStyle = checkpoint.inStyle; | 481 m_inStyle = checkpoint.inStyle; |
482 m_isAppCacheEnabled = checkpoint.isAppCacheEnabled; | 482 m_isAppCacheEnabled = checkpoint.isAppCacheEnabled; |
483 m_isCSPEnabled = checkpoint.isCSPEnabled; | 483 m_isCSPEnabled = checkpoint.isCSPEnabled; |
484 m_templateCount = checkpoint.templateCount; | 484 m_templateCount = checkpoint.templateCount; |
485 m_cssScanner.reset(); | 485 m_cssScanner.reset(); |
486 m_checkpoints.clear(); | 486 m_checkpoints.clear(); |
487 } | 487 } |
488 | 488 |
489 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) | 489 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewport) |
490 { | 490 { |
491 scanCommon(token, source, requests); | 491 scanCommon(token, source, requests, viewport); |
492 } | 492 } |
493 | 493 |
494 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) | 494 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewpor
t) |
495 { | 495 { |
496 scanCommon(token, source, requests); | 496 scanCommon(token, source, requests, viewport); |
497 } | 497 } |
498 | 498 |
499 static void handleMetaViewport(const String& attributeValue, const CachedDocumen
tParameters* documentParameters, MediaValuesCached* mediaValues) | 499 static void handleMetaViewport(const String& attributeValue, const CachedDocumen
tParameters* documentParameters, MediaValuesCached* mediaValues, ViewportDescrip
tionWrapper* viewport) |
500 { | 500 { |
501 if (!documentParameters->viewportMetaEnabled) | 501 if (!documentParameters->viewportMetaEnabled) |
502 return; | 502 return; |
503 ViewportDescription description(ViewportDescription::ViewportMeta); | 503 ViewportDescription description(ViewportDescription::ViewportMeta); |
504 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); | 504 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); |
| 505 if (viewport) { |
| 506 viewport->description = description; |
| 507 viewport->set = true; |
| 508 } |
505 FloatSize initialViewport(mediaValues->deviceWidth(), mediaValues->deviceHei
ght()); | 509 FloatSize initialViewport(mediaValues->deviceWidth(), mediaValues->deviceHei
ght()); |
506 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); | 510 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); |
507 mediaValues->setViewportHeight(constraints.layoutSize.height()); | 511 mediaValues->overrideViewportDimensions(constraints.layoutSize.width(), cons
traints.layoutSize.height()); |
508 mediaValues->setViewportWidth(constraints.layoutSize.width()); | |
509 } | 512 } |
510 | 513 |
511 static void handleMetaReferrer(const String& attributeValue, CachedDocumentParam
eters* documentParameters, CSSPreloadScanner* cssScanner) | 514 static void handleMetaReferrer(const String& attributeValue, CachedDocumentParam
eters* documentParameters, CSSPreloadScanner* cssScanner) |
512 { | 515 { |
513 if (attributeValue.isEmpty() || attributeValue.isNull() || !SecurityPolicy::
referrerPolicyFromString(attributeValue, &documentParameters->referrerPolicy)) { | 516 if (attributeValue.isEmpty() || attributeValue.isNull() || !SecurityPolicy::
referrerPolicyFromString(attributeValue, &documentParameters->referrerPolicy)) { |
514 documentParameters->referrerPolicy = ReferrerPolicyDefault; | 517 documentParameters->referrerPolicy = ReferrerPolicyDefault; |
515 } | 518 } |
516 cssScanner->setReferrerPolicy(documentParameters->referrerPolicy); | 519 cssScanner->setReferrerPolicy(documentParameters->referrerPolicy); |
517 } | 520 } |
518 | 521 |
519 template <typename Token> | 522 template <typename Token> |
520 static void handleMetaNameAttribute(const Token& token, CachedDocumentParameters
* documentParameters, MediaValuesCached* mediaValues, CSSPreloadScanner* cssScan
ner) | 523 static void handleMetaNameAttribute(const Token& token, CachedDocumentParameters
* documentParameters, MediaValuesCached* mediaValues, CSSPreloadScanner* cssScan
ner, ViewportDescriptionWrapper* viewport) |
521 { | 524 { |
522 const typename Token::Attribute* nameAttribute = token.getAttributeItem(name
Attr); | 525 const typename Token::Attribute* nameAttribute = token.getAttributeItem(name
Attr); |
523 if (!nameAttribute) | 526 if (!nameAttribute) |
524 return; | 527 return; |
525 | 528 |
526 String nameAttributeValue(nameAttribute->value()); | 529 String nameAttributeValue(nameAttribute->value()); |
527 const typename Token::Attribute* contentAttribute = token.getAttributeItem(c
ontentAttr); | 530 const typename Token::Attribute* contentAttribute = token.getAttributeItem(c
ontentAttr); |
528 if (!contentAttribute) | 531 if (!contentAttribute) |
529 return; | 532 return; |
530 | 533 |
531 String contentAttributeValue(contentAttribute->value()); | 534 String contentAttributeValue(contentAttribute->value()); |
532 if (equalIgnoringCase(nameAttributeValue, "viewport")) { | 535 if (equalIgnoringCase(nameAttributeValue, "viewport")) { |
533 handleMetaViewport(contentAttributeValue, documentParameters, mediaValue
s); | 536 handleMetaViewport(contentAttributeValue, documentParameters, mediaValue
s, viewport); |
534 return; | 537 return; |
535 } | 538 } |
536 | 539 |
537 if (equalIgnoringCase(nameAttributeValue, "referrer")) { | 540 if (equalIgnoringCase(nameAttributeValue, "referrer")) { |
538 handleMetaReferrer(contentAttributeValue, documentParameters, cssScanner
); | 541 handleMetaReferrer(contentAttributeValue, documentParameters, cssScanner
); |
539 } | 542 } |
540 } | 543 } |
541 | 544 |
542 template <typename Token> | 545 template <typename Token> |
543 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) | 546 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests, ViewportDescriptionWrapper* viewport) |
544 { | 547 { |
545 if (!m_documentParameters->doHtmlPreloadScanning) | 548 if (!m_documentParameters->doHtmlPreloadScanning) |
546 return; | 549 return; |
547 | 550 |
548 // Disable preload for documents with AppCache. | 551 // Disable preload for documents with AppCache. |
549 if (m_isAppCacheEnabled) | 552 if (m_isAppCacheEnabled) |
550 return; | 553 return; |
551 | 554 |
552 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s | 555 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s |
553 if (m_isCSPEnabled) | 556 if (m_isCSPEnabled) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { | 610 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { |
608 m_isCSPEnabled = true; | 611 m_isCSPEnabled = true; |
609 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ | 612 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ |
610 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); | 613 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); |
611 if (contentAttribute) | 614 if (contentAttribute) |
612 m_clientHintsPreferences.updateFromAcceptClientHintsHead
er(contentAttribute->value(), nullptr); | 615 m_clientHintsPreferences.updateFromAcceptClientHintsHead
er(contentAttribute->value(), nullptr); |
613 } | 616 } |
614 return; | 617 return; |
615 } | 618 } |
616 | 619 |
617 handleMetaNameAttribute(token, m_documentParameters.get(), m_mediaVa
lues.get(), &m_cssScanner); | 620 handleMetaNameAttribute(token, m_documentParameters.get(), m_mediaVa
lues.get(), &m_cssScanner, viewport); |
618 } | 621 } |
619 | 622 |
620 if (match(tagImpl, pictureTag)) { | 623 if (match(tagImpl, pictureTag)) { |
621 m_inPicture = true; | 624 m_inPicture = true; |
622 m_pictureData = PictureData(); | 625 m_pictureData = PictureData(); |
623 return; | 626 return; |
624 } | 627 } |
625 | 628 |
626 StartTagScanner scanner(tagImpl, m_mediaValues); | 629 StartTagScanner scanner(tagImpl, m_mediaValues); |
627 scanner.processAttributes(token.attributes()); | 630 scanner.processAttributes(token.attributes()); |
(...skipping 28 matching lines...) Expand all Loading... |
656 | 659 |
657 HTMLPreloadScanner::~HTMLPreloadScanner() | 660 HTMLPreloadScanner::~HTMLPreloadScanner() |
658 { | 661 { |
659 } | 662 } |
660 | 663 |
661 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) | 664 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) |
662 { | 665 { |
663 m_source.append(source); | 666 m_source.append(source); |
664 } | 667 } |
665 | 668 |
666 void HTMLPreloadScanner::scan(ResourcePreloader* preloader, const KURL& starting
BaseElementURL) | 669 void HTMLPreloadScanner::scan(ResourcePreloader* preloader, const KURL& starting
BaseElementURL, ViewportDescriptionWrapper* viewport) |
667 { | 670 { |
668 ASSERT(isMainThread()); // HTMLTokenizer::updateStateFor only works on the m
ain thread. | 671 ASSERT(isMainThread()); // HTMLTokenizer::updateStateFor only works on the m
ain thread. |
669 | 672 |
670 TRACE_EVENT1("blink", "HTMLPreloadScanner::scan", "source_length", m_source.
length()); | 673 TRACE_EVENT1("blink", "HTMLPreloadScanner::scan", "source_length", m_source.
length()); |
671 | 674 |
672 // When we start scanning, our best prediction of the baseElementURL is the
real one! | 675 // When we start scanning, our best prediction of the baseElementURL is the
real one! |
673 if (!startingBaseElementURL.isEmpty()) | 676 if (!startingBaseElementURL.isEmpty()) |
674 m_scanner.setPredictedBaseElementURL(startingBaseElementURL); | 677 m_scanner.setPredictedBaseElementURL(startingBaseElementURL); |
675 | 678 |
676 PreloadRequestStream requests; | 679 PreloadRequestStream requests; |
677 | 680 |
678 while (m_tokenizer->nextToken(m_source, m_token)) { | 681 while (m_tokenizer->nextToken(m_source, m_token)) { |
679 if (m_token.type() == HTMLToken::StartTag) | 682 if (m_token.type() == HTMLToken::StartTag) |
680 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 683 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
681 m_scanner.scan(m_token, m_source, requests); | 684 m_scanner.scan(m_token, m_source, requests, viewport); |
682 m_token.clear(); | 685 m_token.clear(); |
683 } | 686 } |
684 | 687 |
685 preloader->takeAndPreload(requests); | 688 preloader->takeAndPreload(requests); |
686 } | 689 } |
687 | 690 |
688 CachedDocumentParameters::CachedDocumentParameters(Document* document) | 691 CachedDocumentParameters::CachedDocumentParameters(Document* document) |
689 { | 692 { |
690 ASSERT(isMainThread()); | 693 ASSERT(isMainThread()); |
691 ASSERT(document); | 694 ASSERT(document); |
692 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); | 695 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); |
693 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 696 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
694 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 697 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
695 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 698 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
696 referrerPolicy = ReferrerPolicyDefault; | 699 referrerPolicy = ReferrerPolicyDefault; |
697 } | 700 } |
698 | 701 |
699 } // namespace blink | 702 } // namespace blink |
OLD | NEW |