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

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

Issue 1104103002: Add <meta viewport> support to the preloader (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: moved CachedDocumentParameters constructor to private Created 5 years, 7 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 14 matching lines...) Expand all
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "config.h" 28 #include "config.h"
29 #include "core/html/parser/HTMLPreloadScanner.h" 29 #include "core/html/parser/HTMLPreloadScanner.h"
30 30
31 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
32 #include "core/InputTypeNames.h" 32 #include "core/InputTypeNames.h"
33 #include "core/css/MediaList.h" 33 #include "core/css/MediaList.h"
34 #include "core/css/MediaQueryEvaluator.h" 34 #include "core/css/MediaQueryEvaluator.h"
35 #include "core/css/MediaValuesCached.h"
35 #include "core/css/parser/SizesAttributeParser.h" 36 #include "core/css/parser/SizesAttributeParser.h"
37 #include "core/dom/Document.h"
38 #include "core/frame/Settings.h"
39 #include "core/html/HTMLMetaElement.h"
36 #include "core/html/LinkRelAttribute.h" 40 #include "core/html/LinkRelAttribute.h"
37 #include "core/html/parser/HTMLParserIdioms.h" 41 #include "core/html/parser/HTMLParserIdioms.h"
38 #include "core/html/parser/HTMLSrcsetParser.h" 42 #include "core/html/parser/HTMLSrcsetParser.h"
39 #include "core/html/parser/HTMLTokenizer.h" 43 #include "core/html/parser/HTMLTokenizer.h"
40 #include "platform/RuntimeEnabledFeatures.h" 44 #include "platform/RuntimeEnabledFeatures.h"
41 #include "platform/TraceEvent.h" 45 #include "platform/TraceEvent.h"
42 #include "wtf/MainThread.h" 46 #include "wtf/MainThread.h"
43 47
44 namespace blink { 48 namespace blink {
45 49
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 , m_linkIsStyleSheet(false) 113 , m_linkIsStyleSheet(false)
110 , m_matchedMediaAttribute(true) 114 , m_matchedMediaAttribute(true)
111 , m_inputIsImage(false) 115 , m_inputIsImage(false)
112 , m_sourceSize(0) 116 , m_sourceSize(0)
113 , m_sourceSizeSet(false) 117 , m_sourceSizeSet(false)
114 , m_isCORSEnabled(false) 118 , m_isCORSEnabled(false)
115 , m_defer(FetchRequest::NoDefer) 119 , m_defer(FetchRequest::NoDefer)
116 , m_allowCredentials(DoNotAllowStoredCredentials) 120 , m_allowCredentials(DoNotAllowStoredCredentials)
117 , m_mediaValues(mediaValues) 121 , m_mediaValues(mediaValues)
118 { 122 {
123 ASSERT(m_mediaValues->isCached());
119 if (match(m_tagImpl, imgTag) 124 if (match(m_tagImpl, imgTag)
120 || match(m_tagImpl, sourceTag)) { 125 || match(m_tagImpl, sourceTag)) {
121 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length( ); 126 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length( );
122 return; 127 return;
123 } 128 }
124 if ( !match(m_tagImpl, inputTag) 129 if ( !match(m_tagImpl, inputTag)
125 && !match(m_tagImpl, linkTag) 130 && !match(m_tagImpl, linkTag)
126 && !match(m_tagImpl, scriptTag) 131 && !match(m_tagImpl, scriptTag)
127 && !match(m_tagImpl, videoTag)) 132 && !match(m_tagImpl, videoTag))
128 m_tagImpl = 0; 133 m_tagImpl = 0;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 String m_imgSrcUrl; 381 String m_imgSrcUrl;
377 String m_srcsetAttributeValue; 382 String m_srcsetAttributeValue;
378 float m_sourceSize; 383 float m_sourceSize;
379 bool m_sourceSizeSet; 384 bool m_sourceSizeSet;
380 bool m_isCORSEnabled; 385 bool m_isCORSEnabled;
381 FetchRequest::DeferOption m_defer; 386 FetchRequest::DeferOption m_defer;
382 StoredCredentials m_allowCredentials; 387 StoredCredentials m_allowCredentials;
383 RefPtr<MediaValues> m_mediaValues; 388 RefPtr<MediaValues> m_mediaValues;
384 }; 389 };
385 390
386 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues) 391 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac hedDocumentParameters> documentParameters)
387 : m_documentURL(documentURL) 392 : m_documentURL(documentURL)
388 , m_inStyle(false) 393 , m_inStyle(false)
389 , m_inPicture(false) 394 , m_inPicture(false)
390 , m_isAppCacheEnabled(false) 395 , m_isAppCacheEnabled(false)
391 , m_isCSPEnabled(false) 396 , m_isCSPEnabled(false)
392 , m_templateCount(0) 397 , m_templateCount(0)
393 , m_mediaValues(mediaValues) 398 , m_documentParameters(documentParameters)
394 { 399 {
400 ASSERT(m_documentParameters.get());
401 ASSERT(m_documentParameters->mediaValues.get());
402 ASSERT(m_documentParameters->mediaValues->isCached());
395 } 403 }
396 404
397 TokenPreloadScanner::~TokenPreloadScanner() 405 TokenPreloadScanner::~TokenPreloadScanner()
398 { 406 {
399 } 407 }
400 408
401 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() 409 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint()
402 { 410 {
403 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); 411 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size();
404 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isAp pCacheEnabled, m_isCSPEnabled, m_templateCount)); 412 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isAp pCacheEnabled, m_isCSPEnabled, m_templateCount));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) { 493 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) {
486 m_isAppCacheEnabled = true; 494 m_isAppCacheEnabled = true;
487 return; 495 return;
488 } 496 }
489 if (match(tagImpl, metaTag)) { 497 if (match(tagImpl, metaTag)) {
490 const typename Token::Attribute* equivAttribute = token.getAttribute Item(http_equivAttr); 498 const typename Token::Attribute* equivAttribute = token.getAttribute Item(http_equivAttr);
491 if (equivAttribute && equalIgnoringCase(String(equivAttribute->value ), "content-security-policy")) { 499 if (equivAttribute && equalIgnoringCase(String(equivAttribute->value ), "content-security-policy")) {
492 m_isCSPEnabled = true; 500 m_isCSPEnabled = true;
493 return; 501 return;
494 } 502 }
503 const typename Token::Attribute* nameAttribute = token.getAttributeI tem(nameAttr);
504 if (nameAttribute && equalIgnoringCase(String(nameAttribute->value), "viewport")) {
505 const typename Token::Attribute* contentAttribute = token.getAtt ributeItem(contentAttr);
506
507 if (contentAttribute) {
508 ViewportDescription description(ViewportDescription::Viewpor tMeta);
509 HTMLMetaElement::getViewportDescriptionFromContentAttribute( String(contentAttribute->value), description, nullptr, m_documentParameters->vie wportMetaZeroValuesQuirk);
510 FloatSize initialViewport(m_documentParameters->mediaValues- >viewportHeight(), m_documentParameters->mediaValues->viewportWidth());
511 PageScaleConstraints constraints = description.resolve(initi alViewport, m_documentParameters->defaultViewportMinWidth);
512 MediaValuesCached* cachedMediaValues = static_cast<MediaValu esCached*>(m_documentParameters->mediaValues.get());
513 cachedMediaValues->setViewportHeight(constraints.layoutSize. height());
514 cachedMediaValues->setViewportWidth(constraints.layoutSize.w idth());
515 }
516 }
495 } 517 }
496 518
497 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT ag))) { 519 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT ag))) {
498 m_inPicture = true; 520 m_inPicture = true;
499 m_pictureSourceURL = String(); 521 m_pictureSourceURL = String();
500 return; 522 return;
501 } 523 }
502 524
503 StartTagScanner scanner(tagImpl, m_mediaValues); 525 StartTagScanner scanner(tagImpl, m_documentParameters->mediaValues);
504 scanner.processAttributes(token.attributes()); 526 scanner.processAttributes(token.attributes());
505 if (m_inPicture) 527 if (m_inPicture)
506 scanner.handlePictureSourceURL(m_pictureSourceURL); 528 scanner.handlePictureSourceURL(m_pictureSourceURL);
507 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte dBaseElementURL, source); 529 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte dBaseElementURL, source);
508 if (request) 530 if (request)
509 requests.append(request.release()); 531 requests.append(request.release());
510 return; 532 return;
511 } 533 }
512 default: { 534 default: {
513 return; 535 return;
514 } 536 }
515 } 537 }
516 } 538 }
517 539
518 template<typename Token> 540 template<typename Token>
519 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) 541 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token)
520 { 542 {
521 ASSERT(m_predictedBaseElementURL.isEmpty()); 543 ASSERT(m_predictedBaseElementURL.isEmpty());
522 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem( hrefAttr)) { 544 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem( hrefAttr)) {
523 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute- >value)); 545 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute- >value));
524 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL(); 546 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL();
525 } 547 }
526 } 548 }
527 549
528 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K URL& documentURL, PassRefPtr<MediaValues> mediaValues) 550 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K URL& documentURL, PassOwnPtr<CachedDocumentParameters> documentParameters)
529 : m_scanner(documentURL, mediaValues) 551 : m_scanner(documentURL, documentParameters)
530 , m_tokenizer(HTMLTokenizer::create(options)) 552 , m_tokenizer(HTMLTokenizer::create(options))
531 { 553 {
532 } 554 }
533 555
534 HTMLPreloadScanner::~HTMLPreloadScanner() 556 HTMLPreloadScanner::~HTMLPreloadScanner()
535 { 557 {
536 } 558 }
537 559
538 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) 560 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source)
539 { 561 {
(...skipping 15 matching lines...) Expand all
555 while (m_tokenizer->nextToken(m_source, m_token)) { 577 while (m_tokenizer->nextToken(m_source, m_token)) {
556 if (m_token.type() == HTMLToken::StartTag) 578 if (m_token.type() == HTMLToken::StartTag)
557 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit)); 579 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit));
558 m_scanner.scan(m_token, m_source, requests); 580 m_scanner.scan(m_token, m_source, requests);
559 m_token.clear(); 581 m_token.clear();
560 } 582 }
561 583
562 preloader->takeAndPreload(requests); 584 preloader->takeAndPreload(requests);
563 } 585 }
564 586
587 CachedDocumentParameters::CachedDocumentParameters(Document* document, PassRefPt r<MediaValues> givenMediaValues)
588 {
589 ASSERT(isMainThread());
590 ASSERT(document);
591 if (givenMediaValues)
592 mediaValues = givenMediaValues;
593 else
594 mediaValues = MediaValuesCached::create(*document);
595 ASSERT(mediaValues->isSafeToSendToAnotherThread());
596 defaultViewportMinWidth = document->viewportDefaultMinWidth();
597 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk();
565 } 598 }
599
600 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLPreloadScanner.h ('k') | Source/core/html/parser/HTMLPreloadScannerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698