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

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

Issue 1738133002: Add support for media attribute on link (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 25 matching lines...) Expand all
36 #include "core/html/HTMLDocument.h" 36 #include "core/html/HTMLDocument.h"
37 #include "core/html/parser/AtomicHTMLToken.h" 37 #include "core/html/parser/AtomicHTMLToken.h"
38 #include "core/html/parser/BackgroundHTMLParser.h" 38 #include "core/html/parser/BackgroundHTMLParser.h"
39 #include "core/html/parser/HTMLParserScheduler.h" 39 #include "core/html/parser/HTMLParserScheduler.h"
40 #include "core/html/parser/HTMLParserThread.h" 40 #include "core/html/parser/HTMLParserThread.h"
41 #include "core/html/parser/HTMLScriptRunner.h" 41 #include "core/html/parser/HTMLScriptRunner.h"
42 #include "core/html/parser/HTMLTreeBuilder.h" 42 #include "core/html/parser/HTMLTreeBuilder.h"
43 #include "core/inspector/InspectorInstrumentation.h" 43 #include "core/inspector/InspectorInstrumentation.h"
44 #include "core/inspector/InspectorTraceEvents.h" 44 #include "core/inspector/InspectorTraceEvents.h"
45 #include "core/loader/DocumentLoader.h" 45 #include "core/loader/DocumentLoader.h"
46 #include "core/loader/LinkLoader.h"
46 #include "core/loader/NavigationScheduler.h" 47 #include "core/loader/NavigationScheduler.h"
47 #include "platform/SharedBuffer.h" 48 #include "platform/SharedBuffer.h"
48 #include "platform/ThreadSafeFunctional.h" 49 #include "platform/ThreadSafeFunctional.h"
49 #include "platform/TraceEvent.h" 50 #include "platform/TraceEvent.h"
50 #include "platform/heap/Handle.h" 51 #include "platform/heap/Handle.h"
51 #include "public/platform/Platform.h" 52 #include "public/platform/Platform.h"
52 #include "public/platform/WebFrameScheduler.h" 53 #include "public/platform/WebFrameScheduler.h"
53 #include "public/platform/WebScheduler.h" 54 #include "public/platform/WebScheduler.h"
54 #include "public/platform/WebThread.h" 55 #include "public/platform/WebThread.h"
55 #include "wtf/RefCounted.h" 56 #include "wtf/RefCounted.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 , m_weakFactory(this) 121 , m_weakFactory(this)
121 , m_preloader(HTMLResourcePreloader::create(document)) 122 , m_preloader(HTMLResourcePreloader::create(document))
122 , m_parsedChunkQueue(ParsedChunkQueue::create()) 123 , m_parsedChunkQueue(ParsedChunkQueue::create())
123 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) 124 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing)
124 , m_endWasDelayed(false) 125 , m_endWasDelayed(false)
125 , m_haveBackgroundParser(false) 126 , m_haveBackgroundParser(false)
126 , m_tasksWereSuspended(false) 127 , m_tasksWereSuspended(false)
127 , m_pumpSessionNestingLevel(0) 128 , m_pumpSessionNestingLevel(0)
128 , m_pumpSpeculationsSessionNestingLevel(0) 129 , m_pumpSpeculationsSessionNestingLevel(0)
129 , m_isParsingAtLineNumber(false) 130 , m_isParsingAtLineNumber(false)
131 , m_isLoadedLinkHeaders(false)
130 { 132 {
131 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); 133 ASSERT(shouldUseThreading() || (m_token && m_tokenizer));
132 } 134 }
133 135
134 // FIXME: Member variables should be grouped into self-initializing structs to 136 // FIXME: Member variables should be grouped into self-initializing structs to
135 // minimize code duplication between these constructors. 137 // minimize code duplication between these constructors.
136 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy) 138 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy)
137 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) 139 : ScriptableDocumentParser(fragment->document(), parserContentPolicy)
138 , m_options(&fragment->document()) 140 , m_options(&fragment->document())
139 , m_token(adoptPtr(new HTMLToken)) 141 , m_token(adoptPtr(new HTMLToken))
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 m_textPosition = it->textPosition(); 485 m_textPosition = it->textPosition();
484 486
485 constructTreeFromCompactHTMLToken(*it); 487 constructTreeFromCompactHTMLToken(*it);
486 488
487 if (isStopped()) 489 if (isStopped())
488 break; 490 break;
489 491
490 if (!m_queuedPreloads.isEmpty() && document()->documentElement()) 492 if (!m_queuedPreloads.isEmpty() && document()->documentElement())
491 m_preloader->takeAndPreload(m_queuedPreloads); 493 m_preloader->takeAndPreload(m_queuedPreloads);
492 494
495 if (!m_isLoadedLinkHeaders) {
496 ViewportDescription oldDescription;
497 String linkHeader = document()->loader()->response().httpHeaderField (HTTPNames::Link);
498 if (!linkHeader.isEmpty()) {
499 ASSERT(chunk);
500 LinkLoader::loadLinkFromHeader(linkHeader, document()->loader()- >response().url(),
501 document(), NetworkHintsInterfaceImpl(), LinkLoader::OnlyLoa dResources, &(chunk->viewport));
502 m_isLoadedLinkHeaders = true;
503 }
504 }
505
493 if (isWaitingForScripts()) { 506 if (isWaitingForScripts()) {
494 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch. 507 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch.
495 runScriptsForPausedTreeBuilder(); 508 runScriptsForPausedTreeBuilder();
496 validateSpeculations(chunk.release()); 509 validateSpeculations(chunk.release());
497 break; 510 break;
498 } 511 }
499 512
500 if (it->type() == HTMLToken::EndOfFile) { 513 if (it->type() == HTMLToken::EndOfFile) {
501 ASSERT(it + 1 == tokens->end()); // The EOF is assumed to be the las t token of this bunch. 514 ASSERT(it + 1 == tokens->end()); // The EOF is assumed to be the las t token of this bunch.
502 ASSERT(m_speculations.isEmpty()); // There should never be any chunk s after the EOF. 515 ASSERT(m_speculations.isEmpty()); // There should never be any chunk s after the EOF.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // adding paranoia if for speculative crash fix for crbug.com/465478 670 // adding paranoia if for speculative crash fix for crbug.com/465478
658 if (m_preloader) { 671 if (m_preloader) {
659 if (!m_preloadScanner) { 672 if (!m_preloadScanner) {
660 m_preloadScanner = HTMLPreloadScanner::create( 673 m_preloadScanner = HTMLPreloadScanner::create(
661 m_options, 674 m_options,
662 document()->url(), 675 document()->url(),
663 CachedDocumentParameters::create(document()), 676 CachedDocumentParameters::create(document()),
664 MediaValuesCached::MediaValuesCachedData(*document())); 677 MediaValuesCached::MediaValuesCachedData(*document()));
665 m_preloadScanner->appendToEnd(m_input.current()); 678 m_preloadScanner->appendToEnd(m_input.current());
666 } 679 }
667 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL ()); 680 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL (), nullptr);
668 } 681 }
669 } 682 }
670 683
671 TRACE_EVENT_END1("devtools.timeline", "ParseHTML", "endData", InspectorParse HtmlEvent::endData(m_input.current().currentLine().zeroBasedInt() - 1)); 684 TRACE_EVENT_END1("devtools.timeline", "ParseHTML", "endData", InspectorParse HtmlEvent::endData(m_input.current().currentLine().zeroBasedInt() - 1));
672 } 685 }
673 686
674 void HTMLDocumentParser::constructTreeFromHTMLToken() 687 void HTMLDocumentParser::constructTreeFromHTMLToken()
675 { 688 {
676 AtomicHTMLToken atomicToken(token()); 689 AtomicHTMLToken atomicToken(token());
677 690
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // the main scanner can't deal with insertions. 757 // the main scanner can't deal with insertions.
745 if (!m_insertionPreloadScanner) { 758 if (!m_insertionPreloadScanner) {
746 m_insertionPreloadScanner = HTMLPreloadScanner::create( 759 m_insertionPreloadScanner = HTMLPreloadScanner::create(
747 m_options, 760 m_options,
748 document()->url(), 761 document()->url(),
749 CachedDocumentParameters::create(document()), 762 CachedDocumentParameters::create(document()),
750 MediaValuesCached::MediaValuesCachedData(*document())); 763 MediaValuesCached::MediaValuesCachedData(*document()));
751 } 764 }
752 765
753 m_insertionPreloadScanner->appendToEnd(source); 766 m_insertionPreloadScanner->appendToEnd(source);
754 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme ntURL()); 767 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme ntURL(), nullptr);
755 } 768 }
756 769
757 endIfDelayed(); 770 endIfDelayed();
758 } 771 }
759 772
760 void HTMLDocumentParser::startBackgroundParser() 773 void HTMLDocumentParser::startBackgroundParser()
761 { 774 {
762 ASSERT(!isStopped()); 775 ASSERT(!isStopped());
763 ASSERT(shouldUseThreading()); 776 ASSERT(shouldUseThreading());
764 ASSERT(!m_haveBackgroundParser); 777 ASSERT(!m_haveBackgroundParser);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 const SegmentedString source(inputSource); 837 const SegmentedString source(inputSource);
825 838
826 if (m_preloadScanner) { 839 if (m_preloadScanner) {
827 if (m_input.current().isEmpty() && !isWaitingForScripts()) { 840 if (m_input.current().isEmpty() && !isWaitingForScripts()) {
828 // We have parsed until the end of the current input and so are now moving ahead of the preload scanner. 841 // We have parsed until the end of the current input and so are now moving ahead of the preload scanner.
829 // Clear the scanner so we know to scan starting from the current in put point if we block again. 842 // Clear the scanner so we know to scan starting from the current in put point if we block again.
830 m_preloadScanner.clear(); 843 m_preloadScanner.clear();
831 } else { 844 } else {
832 m_preloadScanner->appendToEnd(source); 845 m_preloadScanner->appendToEnd(source);
833 if (isWaitingForScripts()) 846 if (isWaitingForScripts())
834 m_preloadScanner->scan(m_preloader.get(), document()->baseElemen tURL()); 847 m_preloadScanner->scan(m_preloader.get(), document()->baseElemen tURL(), nullptr);
835 } 848 }
836 } 849 }
837 850
838 m_input.appendToEnd(source); 851 m_input.appendToEnd(source);
839 852
840 if (inPumpSession()) { 853 if (inPumpSession()) {
841 // We've gotten data off the network in a nested write. 854 // We've gotten data off the network in a nested write.
842 // We don't want to consume any more of the input stream now. Do 855 // We don't want to consume any more of the input stream now. Do
843 // not worry. We'll consume this data in a less-nested write(). 856 // not worry. We'll consume this data in a less-nested write().
844 return; 857 return;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 1017
1005 m_insertionPreloadScanner.clear(); 1018 m_insertionPreloadScanner.clear();
1006 pumpTokenizerIfPossible(); 1019 pumpTokenizerIfPossible();
1007 endIfDelayed(); 1020 endIfDelayed();
1008 } 1021 }
1009 1022
1010 void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan() 1023 void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan()
1011 { 1024 {
1012 ASSERT(m_preloadScanner); 1025 ASSERT(m_preloadScanner);
1013 m_preloadScanner->appendToEnd(m_input.current()); 1026 m_preloadScanner->appendToEnd(m_input.current());
1014 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); 1027 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL(), null ptr);
1015 } 1028 }
1016 1029
1017 void HTMLDocumentParser::notifyScriptLoaded(Resource* cachedResource) 1030 void HTMLDocumentParser::notifyScriptLoaded(Resource* cachedResource)
1018 { 1031 {
1019 // pumpTokenizer can cause this parser to be detached from the Document, 1032 // pumpTokenizer can cause this parser to be detached from the Document,
1020 // but we need to ensure it isn't deleted yet. 1033 // but we need to ensure it isn't deleted yet.
1021 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); 1034 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this);
1022 1035
1023 ASSERT(m_scriptRunner); 1036 ASSERT(m_scriptRunner);
1024 ASSERT(!isExecutingScript()); 1037 ASSERT(!isExecutingScript());
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1140 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1128 { 1141 {
1129 ASSERT(decoder); 1142 ASSERT(decoder);
1130 DecodedDataDocumentParser::setDecoder(decoder); 1143 DecodedDataDocumentParser::setDecoder(decoder);
1131 1144
1132 if (m_haveBackgroundParser) 1145 if (m_haveBackgroundParser)
1133 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); 1146 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder()));
1134 } 1147 }
1135 1148
1136 } // namespace blink 1149 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698