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

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

Issue 2172613002: Renderer-side changes for NoState Prefetch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests Created 4 years, 4 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 || (contextTag.matches(noscriptTag) && options.scriptEnabled) 82 || (contextTag.matches(noscriptTag) && options.scriptEnabled)
83 || contextTag.matches(noframesTag)) 83 || contextTag.matches(noframesTag))
84 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN TEXTState; 84 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN TEXTState;
85 if (contextTag.matches(scriptTag)) 85 if (contextTag.matches(scriptTag))
86 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL AINTEXTState; 86 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL AINTEXTState;
87 if (contextTag.matches(plaintextTag)) 87 if (contextTag.matches(plaintextTag))
88 return HTMLTokenizer::PLAINTEXTState; 88 return HTMLTokenizer::PLAINTEXTState;
89 return HTMLTokenizer::DataState; 89 return HTMLTokenizer::DataState;
90 } 90 }
91 91
92 // static
93 HTMLDocumentParser* HTMLDocumentParser::create(
Charlie Harrison 2016/08/03 14:40:03 I have a slight preference for passing the sync po
droger 2016/08/03 16:45:50 Done.
94 HTMLDocument& document,
95 ParserSynchronizationPolicy backgroundParsingPolicy)
96 {
97 return new HTMLDocumentParser(
98 document,
99 threadingAllowedForDocument(document)
100 ? backgroundParsingPolicy : ForceSynchronousParsing);
101 }
102
92 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, ParserSynchroniza tionPolicy syncPolicy) 103 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, ParserSynchroniza tionPolicy syncPolicy)
93 : HTMLDocumentParser(document, AllowScriptingContent, syncPolicy) 104 : HTMLDocumentParser(document, AllowScriptingContent, syncPolicy)
94 { 105 {
95 m_scriptRunner = HTMLScriptRunner::create(&document, this); 106 m_scriptRunner = HTMLScriptRunner::create(&document, this);
96 m_treeBuilder = HTMLTreeBuilder::create(this, document, AllowScriptingConten t, m_options); 107 m_treeBuilder = HTMLTreeBuilder::create(this, document, AllowScriptingConten t, m_options);
97 } 108 }
98 109
99 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy) 110 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy)
100 : HTMLDocumentParser(fragment->document(), parserContentPolicy, ForceSynchro nousParsing) 111 : HTMLDocumentParser(fragment->document(), parserContentPolicy, ForceSynchro nousParsing)
101 { 112 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 { 154 {
144 visitor->trace(m_treeBuilder); 155 visitor->trace(m_treeBuilder);
145 visitor->trace(m_parserScheduler); 156 visitor->trace(m_parserScheduler);
146 visitor->trace(m_xssAuditorDelegate); 157 visitor->trace(m_xssAuditorDelegate);
147 visitor->trace(m_scriptRunner); 158 visitor->trace(m_scriptRunner);
148 visitor->trace(m_preloader); 159 visitor->trace(m_preloader);
149 ScriptableDocumentParser::trace(visitor); 160 ScriptableDocumentParser::trace(visitor);
150 HTMLScriptRunnerHost::trace(visitor); 161 HTMLScriptRunnerHost::trace(visitor);
151 } 162 }
152 163
164 // static
165 bool HTMLDocumentParser::threadingAllowedForDocument(HTMLDocument& document)
166 {
167 return !document.isPrefetchOnly();
168 }
169
153 void HTMLDocumentParser::detach() 170 void HTMLDocumentParser::detach()
154 { 171 {
155 if (!isParsingFragment() && m_tokenizedChunkQueue.get() && m_tokenizedChunkQ ueue->peakPendingChunkCount()) { 172 if (!isParsingFragment() && m_tokenizedChunkQueue.get() && m_tokenizedChunkQ ueue->peakPendingChunkCount()) {
156 DEFINE_STATIC_LOCAL(CustomCountHistogram, peakPendingChunkHistogram, ("P arser.PeakPendingChunkCount", 1, 1000, 50)); 173 DEFINE_STATIC_LOCAL(CustomCountHistogram, peakPendingChunkHistogram, ("P arser.PeakPendingChunkCount", 1, 1000, 50));
157 peakPendingChunkHistogram.count(m_tokenizedChunkQueue->peakPendingChunkC ount()); 174 peakPendingChunkHistogram.count(m_tokenizedChunkQueue->peakPendingChunkC ount());
158 DEFINE_STATIC_LOCAL(CustomCountHistogram, peakPendingTokenHistogram, ("P arser.PeakPendingTokenCount", 1, 100000, 50)); 175 DEFINE_STATIC_LOCAL(CustomCountHistogram, peakPendingTokenHistogram, ("P arser.PeakPendingTokenCount", 1, 100000, 50));
159 peakPendingTokenHistogram.count(m_tokenizedChunkQueue->peakPendingTokenC ount()); 176 peakPendingTokenHistogram.count(m_tokenizedChunkQueue->peakPendingTokenC ount());
160 } 177 }
161 178
162 if (m_haveBackgroundParser) 179 if (m_haveBackgroundParser)
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 excludedLineNumberSource.setExcludeLineNumbers(); 717 excludedLineNumberSource.setExcludeLineNumbers();
701 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource); 718 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource);
702 pumpTokenizerIfPossible(); 719 pumpTokenizerIfPossible();
703 720
704 if (isWaitingForScripts()) { 721 if (isWaitingForScripts()) {
705 // Check the document.write() output with a separate preload scanner as 722 // Check the document.write() output with a separate preload scanner as
706 // the main scanner can't deal with insertions. 723 // the main scanner can't deal with insertions.
707 if (!m_insertionPreloadScanner) 724 if (!m_insertionPreloadScanner)
708 m_insertionPreloadScanner = createPreloadScanner(); 725 m_insertionPreloadScanner = createPreloadScanner();
709 m_insertionPreloadScanner->appendToEnd(source); 726 m_insertionPreloadScanner->appendToEnd(source);
710 m_insertionPreloadScanner->scanAndPreload(m_preloader.get(), document()- >validBaseElementURL(), nullptr); 727 m_insertionPreloadScanner->scanAndPreload(
Charlie Harrison 2016/08/03 14:40:03 nit: Unnecessary line break.
droger 2016/08/03 16:45:50 Done.
728 m_preloader.get(), document()->validBaseElementURL(), nullptr);
711 } 729 }
712 730
713 endIfDelayed(); 731 endIfDelayed();
714 } 732 }
715 733
716 void HTMLDocumentParser::startBackgroundParser() 734 void HTMLDocumentParser::startBackgroundParser()
717 { 735 {
718 ASSERT(!isStopped()); 736 ASSERT(!isStopped());
719 ASSERT(shouldUseThreading()); 737 ASSERT(shouldUseThreading());
720 ASSERT(!m_haveBackgroundParser); 738 ASSERT(!m_haveBackgroundParser);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (isStopped()) 799 if (isStopped())
782 return; 800 return;
783 801
784 // We should never reach this point if we're using a parser thread, 802 // We should never reach this point if we're using a parser thread,
785 // as appendBytes() will directly ship the data to the thread. 803 // as appendBytes() will directly ship the data to the thread.
786 ASSERT(!shouldUseThreading()); 804 ASSERT(!shouldUseThreading());
787 805
788 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentParser:: append", "size", inputSource.length()); 806 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentParser:: append", "size", inputSource.length());
789 const SegmentedString source(inputSource); 807 const SegmentedString source(inputSource);
790 808
809 if (document()->isPrefetchOnly()) {
810 if (!m_preloadScanner)
811 m_preloadScanner = createPreloadScanner();
812
813 m_preloadScanner->appendToEnd(source);
814 m_preloadScanner->scanAndPreload(m_preloader.get(), document()->validBas eElementURL(), nullptr);
Charlie Harrison 2016/08/03 14:40:03 This just preloads the tokens normally. Do we want
droger 2016/08/03 16:45:50 This uses the same code as the standard preload sc
Charlie Harrison 2016/08/03 17:15:14 Nope, LOAD_PREFETCH afaik is only used for the lin
pasko 2016/08/04 12:23:08 csharrison: thank you for investigation and the in
815
816 // Return after the preload scanner, do not actually parse the document.
817 return;
818 }
819
791 if (m_preloadScanner) { 820 if (m_preloadScanner) {
792 if (m_input.current().isEmpty() && !isWaitingForScripts()) { 821 if (m_input.current().isEmpty() && !isWaitingForScripts()) {
793 // We have parsed until the end of the current input and so are now moving ahead of the preload scanner. 822 // We have parsed until the end of the current input and so are now moving ahead of the preload scanner.
794 // Clear the scanner so we know to scan starting from the current in put point if we block again. 823 // Clear the scanner so we know to scan starting from the current in put point if we block again.
795 m_preloadScanner.reset(); 824 m_preloadScanner.reset();
796 } else { 825 } else {
797 m_preloadScanner->appendToEnd(source); 826 m_preloadScanner->appendToEnd(source);
798 if (isWaitingForScripts()) 827 if (isWaitingForScripts())
799 m_preloadScanner->scanAndPreload(m_preloader.get(), document()-> validBaseElementURL(), nullptr); 828 m_preloadScanner->scanAndPreload(m_preloader.get(), document()-> validBaseElementURL(), nullptr);
800 } 829 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 void HTMLDocumentParser::resumeScheduledTasks() 1056 void HTMLDocumentParser::resumeScheduledTasks()
1028 { 1057 {
1029 ASSERT(m_tasksWereSuspended); 1058 ASSERT(m_tasksWereSuspended);
1030 m_tasksWereSuspended = false; 1059 m_tasksWereSuspended = false;
1031 if (m_parserScheduler) 1060 if (m_parserScheduler)
1032 m_parserScheduler->resume(); 1061 m_parserScheduler->resume();
1033 } 1062 }
1034 1063
1035 void HTMLDocumentParser::appendBytes(const char* data, size_t length) 1064 void HTMLDocumentParser::appendBytes(const char* data, size_t length)
1036 { 1065 {
1037 if (!length || isStopped()) 1066 if (!length || isStopped())
Charlie Harrison 2016/08/03 14:40:03 Can you DCHECK(!document()->isPrefetchOnly()) here
droger 2016/08/03 16:45:50 Why? Is this because isStopped() should never be t
Charlie Harrison 2016/08/03 17:15:14 This method should not run in the non-threaded mod
droger 2016/08/04 12:42:29 Is "This method" appendBytes()? Or isStopped()? a
Charlie Harrison 2016/08/04 12:44:41 Ah you're right, I was misremember the control flo
1038 return; 1067 return;
1039 1068
1040 if (shouldUseThreading()) { 1069 if (shouldUseThreading()) {
1041 double bytesReceivedTime = monotonicallyIncreasingTimeMS(); 1070 double bytesReceivedTime = monotonicallyIncreasingTimeMS();
1042 if (!m_haveBackgroundParser) 1071 if (!m_haveBackgroundParser)
1043 startBackgroundParser(); 1072 startBackgroundParser();
1044 1073
1045 std::unique_ptr<Vector<char>> buffer = wrapUnique(new Vector<char>(lengt h)); 1074 std::unique_ptr<Vector<char>> buffer = wrapUnique(new Vector<char>(lengt h));
1046 memcpy(buffer->data(), data, length); 1075 memcpy(buffer->data(), data, length);
1047 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentPars er::appendBytes", "size", (unsigned)length); 1076 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentPars er::appendBytes", "size", (unsigned)length);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); 1192 (*WTF::bind(function, std::forward<Ps>(parameters)...))();
1164 return; 1193 return;
1165 case Asynchronous: 1194 case Asynchronous:
1166 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std:: forward<Ps>(parameters)...)); 1195 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std:: forward<Ps>(parameters)...));
1167 return; 1196 return;
1168 } 1197 }
1169 NOTREACHED(); 1198 NOTREACHED();
1170 } 1199 }
1171 1200
1172 } // namespace blink 1201 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698