Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp

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

Powered by Google App Engine
This is Rietveld 408576698