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

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: Fix a crash Created 5 years, 8 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 15 matching lines...) Expand all
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/MediaValues.h" 35 #include "core/css/MediaValues.h"
36 #include "core/css/MediaValuesCached.h"
36 #include "core/css/parser/SizesAttributeParser.h" 37 #include "core/css/parser/SizesAttributeParser.h"
38 #include "core/html/HTMLMetaElement.h"
37 #include "core/html/LinkRelAttribute.h" 39 #include "core/html/LinkRelAttribute.h"
38 #include "core/html/parser/HTMLParserIdioms.h" 40 #include "core/html/parser/HTMLParserIdioms.h"
39 #include "core/html/parser/HTMLSrcsetParser.h" 41 #include "core/html/parser/HTMLSrcsetParser.h"
40 #include "core/html/parser/HTMLTokenizer.h" 42 #include "core/html/parser/HTMLTokenizer.h"
41 #include "platform/RuntimeEnabledFeatures.h" 43 #include "platform/RuntimeEnabledFeatures.h"
42 #include "platform/TraceEvent.h" 44 #include "platform/TraceEvent.h"
43 #include "wtf/MainThread.h" 45 #include "wtf/MainThread.h"
44 46
45 namespace blink { 47 namespace blink {
46 48
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 , m_linkIsStyleSheet(false) 112 , m_linkIsStyleSheet(false)
111 , m_matchedMediaAttribute(true) 113 , m_matchedMediaAttribute(true)
112 , m_inputIsImage(false) 114 , m_inputIsImage(false)
113 , m_sourceSize(0) 115 , m_sourceSize(0)
114 , m_sourceSizeSet(false) 116 , m_sourceSizeSet(false)
115 , m_isCORSEnabled(false) 117 , m_isCORSEnabled(false)
116 , m_defer(FetchRequest::NoDefer) 118 , m_defer(FetchRequest::NoDefer)
117 , m_allowCredentials(DoNotAllowStoredCredentials) 119 , m_allowCredentials(DoNotAllowStoredCredentials)
118 , m_mediaValues(mediaValues) 120 , m_mediaValues(mediaValues)
119 { 121 {
122 ASSERT(m_mediaValues->isCached());
120 if (match(m_tagImpl, imgTag) 123 if (match(m_tagImpl, imgTag)
121 || match(m_tagImpl, sourceTag)) { 124 || match(m_tagImpl, sourceTag)) {
122 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length( ); 125 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length( );
123 return; 126 return;
124 } 127 }
125 if ( !match(m_tagImpl, inputTag) 128 if ( !match(m_tagImpl, inputTag)
126 && !match(m_tagImpl, linkTag) 129 && !match(m_tagImpl, linkTag)
127 && !match(m_tagImpl, scriptTag) 130 && !match(m_tagImpl, scriptTag)
128 && !match(m_tagImpl, videoTag)) 131 && !match(m_tagImpl, videoTag))
129 m_tagImpl = 0; 132 m_tagImpl = 0;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 String m_imgSrcUrl; 380 String m_imgSrcUrl;
378 String m_srcsetAttributeValue; 381 String m_srcsetAttributeValue;
379 float m_sourceSize; 382 float m_sourceSize;
380 bool m_sourceSizeSet; 383 bool m_sourceSizeSet;
381 bool m_isCORSEnabled; 384 bool m_isCORSEnabled;
382 FetchRequest::DeferOption m_defer; 385 FetchRequest::DeferOption m_defer;
383 StoredCredentials m_allowCredentials; 386 StoredCredentials m_allowCredentials;
384 RefPtr<MediaValues> m_mediaValues; 387 RefPtr<MediaValues> m_mediaValues;
385 }; 388 };
386 389
387 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues) 390 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues, const Length& defaultViewportMinWidth, bool viewportMetaZ eroValuesQuirk)
388 : m_documentURL(documentURL) 391 : m_documentURL(documentURL)
389 , m_inStyle(false) 392 , m_inStyle(false)
390 , m_inPicture(false) 393 , m_inPicture(false)
391 , m_isAppCacheEnabled(false) 394 , m_isAppCacheEnabled(false)
392 , m_isCSPEnabled(false) 395 , m_isCSPEnabled(false)
393 , m_templateCount(0) 396 , m_templateCount(0)
394 , m_mediaValues(mediaValues) 397 , m_mediaValues(mediaValues)
398 , m_defaultViewportMinWidth(defaultViewportMinWidth)
399 , m_viewportZeroMetaQuirk(viewportMetaZeroValuesQuirk)
395 { 400 {
396 } 401 }
397 402
398 TokenPreloadScanner::~TokenPreloadScanner() 403 TokenPreloadScanner::~TokenPreloadScanner()
399 { 404 {
400 } 405 }
401 406
402 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() 407 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint()
403 { 408 {
404 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); 409 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) { 491 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) {
487 m_isAppCacheEnabled = true; 492 m_isAppCacheEnabled = true;
488 return; 493 return;
489 } 494 }
490 if (match(tagImpl, metaTag)) { 495 if (match(tagImpl, metaTag)) {
491 const typename Token::Attribute* equivAttribute = token.getAttribute Item(http_equivAttr); 496 const typename Token::Attribute* equivAttribute = token.getAttribute Item(http_equivAttr);
492 if (equivAttribute && equalIgnoringCase(String(equivAttribute->value ), "content-security-policy")) { 497 if (equivAttribute && equalIgnoringCase(String(equivAttribute->value ), "content-security-policy")) {
493 m_isCSPEnabled = true; 498 m_isCSPEnabled = true;
494 return; 499 return;
495 } 500 }
501 const typename Token::Attribute* nameAttribute = token.getAttributeI tem(nameAttr);
502 if (nameAttribute && equalIgnoringCase(String(nameAttribute->value), "viewport")) {
503 const typename Token::Attribute* contentAttribute = token.getAtt ributeItem(contentAttr);
504
505 if (contentAttribute) {
506 ViewportDescription description(ViewportDescription::Viewpor tMeta);
507 HTMLMetaElement::getViewportDescriptionFromContentAttribute( String(contentAttribute->value), description, nullptr, m_viewportZeroMetaQuirk);
508 FloatSize initialViewport(m_mediaValues->viewportHeight(), m _mediaValues->viewportWidth());
509 PageScaleConstraints constraints = description.resolve(initi alViewport, m_defaultViewportMinWidth);
510 MediaValuesCached* cachedMediaValues = static_cast<MediaValu esCached*>(m_mediaValues.get());
511 cachedMediaValues->setViewportHeight(constraints.layoutSize. height());
512 cachedMediaValues->setViewportWidth(constraints.layoutSize.w idth());
513 }
514 }
496 } 515 }
497 516
498 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT ag))) { 517 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT ag))) {
499 m_inPicture = true; 518 m_inPicture = true;
500 m_pictureSourceURL = String(); 519 m_pictureSourceURL = String();
501 return; 520 return;
502 } 521 }
503 522
504 StartTagScanner scanner(tagImpl, m_mediaValues); 523 StartTagScanner scanner(tagImpl, m_mediaValues);
505 scanner.processAttributes(token.attributes()); 524 scanner.processAttributes(token.attributes());
(...skipping 13 matching lines...) Expand all
519 template<typename Token> 538 template<typename Token>
520 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) 539 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token)
521 { 540 {
522 ASSERT(m_predictedBaseElementURL.isEmpty()); 541 ASSERT(m_predictedBaseElementURL.isEmpty());
523 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem( hrefAttr)) { 542 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem( hrefAttr)) {
524 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute- >value)); 543 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute- >value));
525 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL(); 544 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL();
526 } 545 }
527 } 546 }
528 547
529 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K URL& documentURL, PassRefPtr<MediaValues> mediaValues) 548 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K URL& documentURL, PassRefPtr<MediaValues> mediaValues, const Length& defaultView portMinWidth, bool viewportMetaZeroValuesQuirk)
530 : m_scanner(documentURL, mediaValues) 549 : m_scanner(documentURL, mediaValues, defaultViewportMinWidth, viewportMetaZ eroValuesQuirk)
531 , m_tokenizer(HTMLTokenizer::create(options)) 550 , m_tokenizer(HTMLTokenizer::create(options))
532 { 551 {
533 } 552 }
534 553
535 HTMLPreloadScanner::~HTMLPreloadScanner() 554 HTMLPreloadScanner::~HTMLPreloadScanner()
536 { 555 {
537 } 556 }
538 557
539 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) 558 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source)
540 { 559 {
(...skipping 16 matching lines...) Expand all
557 if (m_token.type() == HTMLToken::StartTag) 576 if (m_token.type() == HTMLToken::StartTag)
558 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit)); 577 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit));
559 m_scanner.scan(m_token, m_source, requests); 578 m_scanner.scan(m_token, m_source, requests);
560 m_token.clear(); 579 m_token.clear();
561 } 580 }
562 581
563 preloader->takeAndPreload(requests); 582 preloader->takeAndPreload(requests);
564 } 583 }
565 584
566 } 585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698