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

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

Issue 673603002: Reland: Make the HTMLDocumentParser yield more aggressively (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years, 1 month 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 FetchRequest::DeferOption m_defer; 367 FetchRequest::DeferOption m_defer;
368 StoredCredentials m_allowCredentials; 368 StoredCredentials m_allowCredentials;
369 RefPtr<MediaValues> m_mediaValues; 369 RefPtr<MediaValues> m_mediaValues;
370 }; 370 };
371 371
372 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues) 372 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues)
373 : m_documentURL(documentURL) 373 : m_documentURL(documentURL)
374 , m_inStyle(false) 374 , m_inStyle(false)
375 , m_inPicture(false) 375 , m_inPicture(false)
376 , m_isAppCacheEnabled(false) 376 , m_isAppCacheEnabled(false)
377 , m_isCSPEnabled(false)
377 , m_templateCount(0) 378 , m_templateCount(0)
378 , m_mediaValues(mediaValues) 379 , m_mediaValues(mediaValues)
379 { 380 {
380 } 381 }
381 382
382 TokenPreloadScanner::~TokenPreloadScanner() 383 TokenPreloadScanner::~TokenPreloadScanner()
383 { 384 {
384 } 385 }
385 386
386 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() 387 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint()
387 { 388 {
388 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); 389 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size();
389 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isAp pCacheEnabled, m_templateCount)); 390 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isAp pCacheEnabled, m_isCSPEnabled, m_templateCount));
390 return checkpoint; 391 return checkpoint;
391 } 392 }
392 393
393 void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex ) 394 void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex )
394 { 395 {
395 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, che ckpointIndex is invalid. 396 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, che ckpointIndex is invalid.
396 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; 397 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex];
397 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; 398 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL;
398 m_inStyle = checkpoint.inStyle; 399 m_inStyle = checkpoint.inStyle;
399 m_isAppCacheEnabled = checkpoint.isAppCacheEnabled; 400 m_isAppCacheEnabled = checkpoint.isAppCacheEnabled;
401 m_isCSPEnabled = checkpoint.isCSPEnabled;
400 m_templateCount = checkpoint.templateCount; 402 m_templateCount = checkpoint.templateCount;
401 m_cssScanner.reset(); 403 m_cssScanner.reset();
402 m_checkpoints.clear(); 404 m_checkpoints.clear();
403 } 405 }
404 406
405 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so urce, PreloadRequestStream& requests) 407 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so urce, PreloadRequestStream& requests)
406 { 408 {
407 scanCommon(token, source, requests); 409 scanCommon(token, source, requests);
408 } 410 }
409 411
410 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr ing& source, PreloadRequestStream& requests) 412 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr ing& source, PreloadRequestStream& requests)
411 { 413 {
412 scanCommon(token, source, requests); 414 scanCommon(token, source, requests);
413 } 415 }
414 416
415 template<typename Token> 417 template<typename Token>
416 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString& source, PreloadRequestStream& requests) 418 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString& source, PreloadRequestStream& requests)
417 { 419 {
418 // Disable preload for documents with AppCache. 420 // Disable preload for documents with AppCache.
419 if (m_isAppCacheEnabled) 421 if (m_isAppCacheEnabled)
420 return; 422 return;
421 423
424 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag s
425 if (m_isCSPEnabled)
426 return;
427
422 switch (token.type()) { 428 switch (token.type()) {
423 case HTMLToken::Character: { 429 case HTMLToken::Character: {
424 if (!m_inStyle) 430 if (!m_inStyle)
425 return; 431 return;
426 m_cssScanner.scan(token.data(), source, requests); 432 m_cssScanner.scan(token.data(), source, requests);
427 return; 433 return;
428 } 434 }
429 case HTMLToken::EndTag: { 435 case HTMLToken::EndTag: {
430 const StringImpl* tagImpl = tagImplFor(token.data()); 436 const StringImpl* tagImpl = tagImplFor(token.data());
431 if (match(tagImpl, templateTag)) { 437 if (match(tagImpl, templateTag)) {
(...skipping 27 matching lines...) Expand all
459 // The first <base> element is the one that wins. 465 // The first <base> element is the one that wins.
460 if (!m_predictedBaseElementURL.isEmpty()) 466 if (!m_predictedBaseElementURL.isEmpty())
461 return; 467 return;
462 updatePredictedBaseURL(token); 468 updatePredictedBaseURL(token);
463 return; 469 return;
464 } 470 }
465 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) { 471 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) {
466 m_isAppCacheEnabled = true; 472 m_isAppCacheEnabled = true;
467 return; 473 return;
468 } 474 }
475 if (match(tagImpl, metaTag)) {
476 const typename Token::Attribute* equivAttribute = token.getAttribute Item(http_equivAttr);
477 if (equivAttribute && equalIgnoringCase(String(equivAttribute->value ), "content-security-policy")) {
478 m_isCSPEnabled = true;
479 return;
480 }
481 }
469 482
470 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT ag))) { 483 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT ag))) {
471 m_inPicture = true; 484 m_inPicture = true;
472 m_pictureSourceURL = String(); 485 m_pictureSourceURL = String();
473 return; 486 return;
474 } 487 }
475 488
476 StartTagScanner scanner(tagImpl, m_mediaValues); 489 StartTagScanner scanner(tagImpl, m_mediaValues);
477 scanner.processAttributes(token.attributes()); 490 scanner.processAttributes(token.attributes());
478 if (m_inPicture) 491 if (m_inPicture)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if (m_token.type() == HTMLToken::StartTag) 540 if (m_token.type() == HTMLToken::StartTag)
528 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit)); 541 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit));
529 m_scanner.scan(m_token, m_source, requests); 542 m_scanner.scan(m_token, m_source, requests);
530 m_token.clear(); 543 m_token.clear();
531 } 544 }
532 545
533 preloader->takeAndPreload(requests); 546 preloader->takeAndPreload(requests);
534 } 547 }
535 548
536 } 549 }
OLDNEW
« Source/core/html/parser/HTMLPreloadScanner.h ('K') | « Source/core/html/parser/HTMLPreloadScanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698