OLD | NEW |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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/NavigationScheduler.h" | 46 #include "core/loader/NavigationScheduler.h" |
47 #include "platform/SharedBuffer.h" | 47 #include "platform/SharedBuffer.h" |
48 #include "platform/ThreadSafeFunctional.h" | 48 #include "platform/ThreadSafeFunctional.h" |
49 #include "platform/ThreadedDataReceiver.h" | 49 #include "platform/ThreadedDataReceiver.h" |
50 #include "platform/TraceEvent.h" | 50 #include "platform/TraceEvent.h" |
51 #include "platform/heap/Handle.h" | 51 #include "platform/heap/Handle.h" |
52 #include "public/platform/Platform.h" | 52 #include "public/platform/Platform.h" |
53 #include "public/platform/WebFrameScheduler.h" | |
54 #include "public/platform/WebScheduler.h" | 53 #include "public/platform/WebScheduler.h" |
55 #include "public/platform/WebThread.h" | 54 #include "public/platform/WebThread.h" |
56 #include "wtf/RefCounted.h" | 55 #include "wtf/RefCounted.h" |
57 #include "wtf/TemporaryChange.h" | 56 #include "wtf/TemporaryChange.h" |
58 | 57 |
59 namespace blink { | 58 namespace blink { |
60 | 59 |
61 using namespace HTMLNames; | 60 using namespace HTMLNames; |
62 | 61 |
63 // This is a direct transcription of step 4 from: | 62 // This is a direct transcription of step 4 from: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 136 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
138 }; | 137 }; |
139 | 138 |
140 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
, ParserSynchronizationPolicy syncPolicy) | 139 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
, ParserSynchronizationPolicy syncPolicy) |
141 : ScriptableDocumentParser(document) | 140 : ScriptableDocumentParser(document) |
142 , m_options(&document) | 141 , m_options(&document) |
143 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) :
nullptr) | 142 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) :
nullptr) |
144 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) | 143 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) |
145 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) | 144 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) |
146 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) | 145 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) |
147 , m_loadingTaskRunner(adoptPtr(document.loadingTaskRunner()->clone())) | 146 , m_parserScheduler(HTMLParserScheduler::create(this)) |
148 , m_parserScheduler(HTMLParserScheduler::create(this, m_loadingTaskRunner.ge
t())) | |
149 , m_xssAuditorDelegate(&document) | 147 , m_xssAuditorDelegate(&document) |
150 , m_weakFactory(this) | 148 , m_weakFactory(this) |
151 , m_preloader(HTMLResourcePreloader::create(document)) | 149 , m_preloader(HTMLResourcePreloader::create(document)) |
152 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) | 150 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) |
153 , m_endWasDelayed(false) | 151 , m_endWasDelayed(false) |
154 , m_haveBackgroundParser(false) | 152 , m_haveBackgroundParser(false) |
155 , m_tasksWereSuspended(false) | 153 , m_tasksWereSuspended(false) |
156 , m_pumpSessionNestingLevel(0) | 154 , m_pumpSessionNestingLevel(0) |
157 , m_pumpSpeculationsSessionNestingLevel(0) | 155 , m_pumpSpeculationsSessionNestingLevel(0) |
158 , m_isParsingAtLineNumber(false) | 156 , m_isParsingAtLineNumber(false) |
159 { | 157 { |
160 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); | 158 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); |
161 } | 159 } |
162 | 160 |
163 // FIXME: Member variables should be grouped into self-initializing structs to | 161 // FIXME: Member variables should be grouped into self-initializing structs to |
164 // minimize code duplication between these constructors. | 162 // minimize code duplication between these constructors. |
165 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) | 163 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) |
166 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) | 164 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) |
167 , m_options(&fragment->document()) | 165 , m_options(&fragment->document()) |
168 , m_token(adoptPtr(new HTMLToken)) | 166 , m_token(adoptPtr(new HTMLToken)) |
169 , m_tokenizer(HTMLTokenizer::create(m_options)) | 167 , m_tokenizer(HTMLTokenizer::create(m_options)) |
170 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this
->parserContentPolicy(), m_options)) | 168 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this
->parserContentPolicy(), m_options)) |
171 , m_loadingTaskRunner(adoptPtr(fragment->document().loadingTaskRunner()->clo
ne())) | |
172 , m_xssAuditorDelegate(&fragment->document()) | 169 , m_xssAuditorDelegate(&fragment->document()) |
173 , m_weakFactory(this) | 170 , m_weakFactory(this) |
174 , m_shouldUseThreading(false) | 171 , m_shouldUseThreading(false) |
175 , m_endWasDelayed(false) | 172 , m_endWasDelayed(false) |
176 , m_haveBackgroundParser(false) | 173 , m_haveBackgroundParser(false) |
177 , m_tasksWereSuspended(false) | 174 , m_tasksWereSuspended(false) |
178 , m_pumpSessionNestingLevel(0) | 175 , m_pumpSessionNestingLevel(0) |
179 , m_pumpSpeculationsSessionNestingLevel(0) | 176 , m_pumpSpeculationsSessionNestingLevel(0) |
180 { | 177 { |
181 bool reportErrors = false; // For now document fragment parsing never report
s errors. | 178 bool reportErrors = false; // For now document fragment parsing never report
s errors. |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 if (document()->settings()) { | 794 if (document()->settings()) { |
798 if (document()->settings()->backgroundHtmlParserOutstandingTokenLimit()) | 795 if (document()->settings()->backgroundHtmlParserOutstandingTokenLimit()) |
799 config->outstandingTokenLimit = document()->settings()->backgroundHt
mlParserOutstandingTokenLimit(); | 796 config->outstandingTokenLimit = document()->settings()->backgroundHt
mlParserOutstandingTokenLimit(); |
800 if (document()->settings()->backgroundHtmlParserPendingTokenLimit()) | 797 if (document()->settings()->backgroundHtmlParserPendingTokenLimit()) |
801 config->pendingTokenLimit = document()->settings()->backgroundHtmlPa
rserPendingTokenLimit(); | 798 config->pendingTokenLimit = document()->settings()->backgroundHtmlPa
rserPendingTokenLimit(); |
802 } | 799 } |
803 | 800 |
804 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); | 801 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); |
805 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); | 802 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); |
806 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s
tart, reference.release(), config.release(), | 803 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s
tart, reference.release(), config.release(), |
807 adoptPtr(m_loadingTaskRunner->clone()))); | 804 AllowCrossThreadAccess(Platform::current()->currentThread()->scheduler()
))); |
808 } | 805 } |
809 | 806 |
810 void HTMLDocumentParser::stopBackgroundParser() | 807 void HTMLDocumentParser::stopBackgroundParser() |
811 { | 808 { |
812 ASSERT(shouldUseThreading()); | 809 ASSERT(shouldUseThreading()); |
813 ASSERT(m_haveBackgroundParser); | 810 ASSERT(m_haveBackgroundParser); |
814 m_haveBackgroundParser = false; | 811 m_haveBackgroundParser = false; |
815 | 812 |
816 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s
top, AllowCrossThreadAccess(m_backgroundParser))); | 813 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s
top, AllowCrossThreadAccess(m_backgroundParser))); |
817 m_weakFactory.revokeAll(); | 814 m_weakFactory.revokeAll(); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1133 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
1137 { | 1134 { |
1138 ASSERT(decoder); | 1135 ASSERT(decoder); |
1139 DecodedDataDocumentParser::setDecoder(decoder); | 1136 DecodedDataDocumentParser::setDecoder(decoder); |
1140 | 1137 |
1141 if (m_haveBackgroundParser) | 1138 if (m_haveBackgroundParser) |
1142 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); | 1139 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); |
1143 } | 1140 } |
1144 | 1141 |
1145 } | 1142 } |
OLD | NEW |