| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, ParserSynchroniza
tionPolicy syncPolicy) | 92 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, ParserSynchroniza
tionPolicy syncPolicy) |
| 93 : HTMLDocumentParser(document, AllowScriptingContent, syncPolicy) | 93 : HTMLDocumentParser(document, AllowScriptingContent, syncPolicy) |
| 94 { | 94 { |
| 95 m_scriptRunner = HTMLScriptRunner::create(&document, this); | 95 m_scriptRunner = HTMLScriptRunner::create(m_reentryPermit, &document, this); |
| 96 m_treeBuilder = HTMLTreeBuilder::create(this, document, AllowScriptingConten
t, m_options); | 96 m_treeBuilder = HTMLTreeBuilder::create(this, document, AllowScriptingConten
t, m_options); |
| 97 } | 97 } |
| 98 | 98 |
| 99 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) | 99 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) |
| 100 : HTMLDocumentParser(fragment->document(), parserContentPolicy, ForceSynchro
nousParsing) | 100 : HTMLDocumentParser(fragment->document(), parserContentPolicy, ForceSynchro
nousParsing) |
| 101 { | 101 { |
| 102 // No m_scriptRunner in fragment parser. | 102 // No m_scriptRunner in fragment parser. |
| 103 m_treeBuilder = HTMLTreeBuilder::create(this, fragment, contextElement, pars
erContentPolicy, m_options); | 103 m_treeBuilder = HTMLTreeBuilder::create(this, fragment, contextElement, pars
erContentPolicy, m_options); |
| 104 | 104 |
| 105 bool reportErrors = false; // For now document fragment parsing never report
s errors. | 105 bool reportErrors = false; // For now document fragment parsing never report
s errors. |
| 106 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report
Errors, m_options)); | 106 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report
Errors, m_options)); |
| 107 m_xssAuditor.initForFragment(); | 107 m_xssAuditor.initForFragment(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 HTMLDocumentParser::HTMLDocumentParser(Document& document, ParserContentPolicy c
ontentPolicy, ParserSynchronizationPolicy syncPolicy) | 110 HTMLDocumentParser::HTMLDocumentParser(Document& document, ParserContentPolicy c
ontentPolicy, ParserSynchronizationPolicy syncPolicy) |
| 111 : ScriptableDocumentParser(document, contentPolicy) | 111 : ScriptableDocumentParser(document, contentPolicy) |
| 112 , m_options(&document) | 112 , m_options(&document) |
| 113 , m_reentryPermit(new HTMLParserReentryPermit()) |
| 113 , m_token(syncPolicy == ForceSynchronousParsing ? wrapUnique(new HTMLToken)
: nullptr) | 114 , m_token(syncPolicy == ForceSynchronousParsing ? wrapUnique(new HTMLToken)
: nullptr) |
| 114 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) | 115 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) |
| 115 , m_loadingTaskRunner(TaskRunnerHelper::getLoadingTaskRunner(&document)->clo
ne()) | 116 , m_loadingTaskRunner(TaskRunnerHelper::getLoadingTaskRunner(&document)->clo
ne()) |
| 116 , m_parserScheduler(syncPolicy == AllowAsynchronousParsing ? HTMLParserSched
uler::create(this, m_loadingTaskRunner.get()) : nullptr) | 117 , m_parserScheduler(syncPolicy == AllowAsynchronousParsing ? HTMLParserSched
uler::create(this, m_loadingTaskRunner.get()) : nullptr) |
| 117 , m_xssAuditorDelegate(&document) | 118 , m_xssAuditorDelegate(&document) |
| 118 , m_weakFactory(this) | 119 , m_weakFactory(this) |
| 119 , m_preloader(HTMLResourcePreloader::create(document)) | 120 , m_preloader(HTMLResourcePreloader::create(document)) |
| 120 , m_tokenizedChunkQueue(TokenizedChunkQueue::create()) | 121 , m_tokenizedChunkQueue(TokenizedChunkQueue::create()) |
| 121 , m_evaluator(DocumentWriteEvaluator::create(document)) | 122 , m_evaluator(DocumentWriteEvaluator::create(document)) |
| 122 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) | 123 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 139 void HTMLDocumentParser::dispose() | 140 void HTMLDocumentParser::dispose() |
| 140 { | 141 { |
| 141 // In Oilpan, HTMLDocumentParser can die together with Document, and | 142 // In Oilpan, HTMLDocumentParser can die together with Document, and |
| 142 // detach() is not called in this case. | 143 // detach() is not called in this case. |
| 143 if (m_haveBackgroundParser) | 144 if (m_haveBackgroundParser) |
| 144 stopBackgroundParser(); | 145 stopBackgroundParser(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 DEFINE_TRACE(HTMLDocumentParser) | 148 DEFINE_TRACE(HTMLDocumentParser) |
| 148 { | 149 { |
| 150 visitor->trace(m_reentryPermit); |
| 149 visitor->trace(m_treeBuilder); | 151 visitor->trace(m_treeBuilder); |
| 150 visitor->trace(m_parserScheduler); | 152 visitor->trace(m_parserScheduler); |
| 151 visitor->trace(m_xssAuditorDelegate); | 153 visitor->trace(m_xssAuditorDelegate); |
| 152 visitor->trace(m_scriptRunner); | 154 visitor->trace(m_scriptRunner); |
| 153 visitor->trace(m_preloader); | 155 visitor->trace(m_preloader); |
| 154 ScriptableDocumentParser::trace(visitor); | 156 ScriptableDocumentParser::trace(visitor); |
| 155 HTMLScriptRunnerHost::trace(visitor); | 157 HTMLScriptRunnerHost::trace(visitor); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void HTMLDocumentParser::detach() | 160 void HTMLDocumentParser::detach() |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 // where the script is transfered from the treebuilder to the script runner. | 948 // where the script is transfered from the treebuilder to the script runner. |
| 947 // The script runner will hold the script until its loaded and run. During | 949 // The script runner will hold the script until its loaded and run. During |
| 948 // any of this time, we want to count ourselves as "waiting for a script" an
d thus | 950 // any of this time, we want to count ourselves as "waiting for a script" an
d thus |
| 949 // run the preload scanner, as well as delay completion of parsing. | 951 // run the preload scanner, as well as delay completion of parsing. |
| 950 bool treeBuilderHasBlockingScript = m_treeBuilder->hasParserBlockingScript()
; | 952 bool treeBuilderHasBlockingScript = m_treeBuilder->hasParserBlockingScript()
; |
| 951 bool scriptRunnerHasBlockingScript = m_scriptRunner && m_scriptRunner->hasPa
rserBlockingScript(); | 953 bool scriptRunnerHasBlockingScript = m_scriptRunner && m_scriptRunner->hasPa
rserBlockingScript(); |
| 952 // Since the parser is paused while a script runner has a blocking script, i
t should | 954 // Since the parser is paused while a script runner has a blocking script, i
t should |
| 953 // never be possible to end up with both objects holding a blocking script. | 955 // never be possible to end up with both objects holding a blocking script. |
| 954 ASSERT(!(treeBuilderHasBlockingScript && scriptRunnerHasBlockingScript)); | 956 ASSERT(!(treeBuilderHasBlockingScript && scriptRunnerHasBlockingScript)); |
| 955 // If either object has a blocking script, the parser should be paused. | 957 // If either object has a blocking script, the parser should be paused. |
| 956 return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript; | 958 return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript || m_re
entryPermit->parserPauseFlag(); |
| 957 } | 959 } |
| 958 | 960 |
| 959 void HTMLDocumentParser::resumeParsingAfterScriptExecution() | 961 void HTMLDocumentParser::resumeParsingAfterScriptExecution() |
| 960 { | 962 { |
| 961 ASSERT(!isExecutingScript()); | 963 ASSERT(!isExecutingScript()); |
| 962 ASSERT(!isWaitingForScripts()); | 964 ASSERT(!isWaitingForScripts()); |
| 963 | 965 |
| 964 if (m_haveBackgroundParser) { | 966 if (m_haveBackgroundParser) { |
| 965 validateSpeculations(std::move(m_lastChunkBeforeScript)); | 967 validateSpeculations(std::move(m_lastChunkBeforeScript)); |
| 966 ASSERT(!m_lastChunkBeforeScript); | 968 ASSERT(!m_lastChunkBeforeScript); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 1171 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
| 1170 return; | 1172 return; |
| 1171 case Asynchronous: | 1173 case Asynchronous: |
| 1172 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::
forward<Ps>(parameters)...)); | 1174 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::
forward<Ps>(parameters)...)); |
| 1173 return; | 1175 return; |
| 1174 } | 1176 } |
| 1175 NOTREACHED(); | 1177 NOTREACHED(); |
| 1176 } | 1178 } |
| 1177 | 1179 |
| 1178 } // namespace blink | 1180 } // namespace blink |
| OLD | NEW |