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

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

Issue 2630253002: Teach the background parser to ignore certain elements inside '<select>'. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2013 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
85 // FIXME: This is copied from HTMLElementStack::isMathMLTextIntegrationPoint 85 // FIXME: This is copied from HTMLElementStack::isMathMLTextIntegrationPoint
86 // and changed to use threadSafeMatch. 86 // and changed to use threadSafeMatch.
87 const String& tagName = token.data(); 87 const String& tagName = token.data();
88 return threadSafeMatch(tagName, MathMLNames::miTag) || 88 return threadSafeMatch(tagName, MathMLNames::miTag) ||
89 threadSafeMatch(tagName, MathMLNames::moTag) || 89 threadSafeMatch(tagName, MathMLNames::moTag) ||
90 threadSafeMatch(tagName, MathMLNames::mnTag) || 90 threadSafeMatch(tagName, MathMLNames::mnTag) ||
91 threadSafeMatch(tagName, MathMLNames::msTag) || 91 threadSafeMatch(tagName, MathMLNames::msTag) ||
92 threadSafeMatch(tagName, MathMLNames::mtextTag); 92 threadSafeMatch(tagName, MathMLNames::mtextTag);
93 } 93 }
94 94
95 static bool tokenExitsInSelect(const CompactHTMLToken& token) {
96 // https://html.spec.whatwg.org/#parsing-main-inselect
97 const String& tagName = token.data();
98 return threadSafeMatch(tagName, inputTag) ||
99 threadSafeMatch(tagName, keygenTag) ||
100 threadSafeMatch(tagName, textareaTag);
101 }
102
95 HTMLTreeBuilderSimulator::HTMLTreeBuilderSimulator( 103 HTMLTreeBuilderSimulator::HTMLTreeBuilderSimulator(
96 const HTMLParserOptions& options) 104 const HTMLParserOptions& options)
97 : m_options(options) { 105 : m_options(options), m_inSelectInsertionMode(false) {
98 m_namespaceStack.append(HTML); 106 m_namespaceStack.append(HTML);
99 } 107 }
100 108
101 HTMLTreeBuilderSimulator::State HTMLTreeBuilderSimulator::stateFor( 109 HTMLTreeBuilderSimulator::State HTMLTreeBuilderSimulator::stateFor(
102 HTMLTreeBuilder* treeBuilder) { 110 HTMLTreeBuilder* treeBuilder) {
103 ASSERT(isMainThread()); 111 ASSERT(isMainThread());
104 State namespaceStack; 112 State namespaceStack;
105 for (HTMLElementStack::ElementRecord* record = 113 for (HTMLElementStack::ElementRecord* record =
106 treeBuilder->openElements()->topRecord(); 114 treeBuilder->openElements()->topRecord();
107 record; record = record->next()) { 115 record; record = record->next()) {
(...skipping 25 matching lines...) Expand all
133 m_namespaceStack.pop_back(); 141 m_namespaceStack.pop_back();
134 if ((m_namespaceStack.last() == SVG && tokenExitsSVG(token)) || 142 if ((m_namespaceStack.last() == SVG && tokenExitsSVG(token)) ||
135 (m_namespaceStack.last() == MathML && tokenExitsMath(token))) 143 (m_namespaceStack.last() == MathML && tokenExitsMath(token)))
136 m_namespaceStack.append(HTML); 144 m_namespaceStack.append(HTML);
137 if (!inForeignContent()) { 145 if (!inForeignContent()) {
138 // FIXME: This is just a copy of Tokenizer::updateStateFor which uses 146 // FIXME: This is just a copy of Tokenizer::updateStateFor which uses
139 // threadSafeMatches. 147 // threadSafeMatches.
140 if (threadSafeMatch(tagName, textareaTag) || 148 if (threadSafeMatch(tagName, textareaTag) ||
141 threadSafeMatch(tagName, titleTag)) { 149 threadSafeMatch(tagName, titleTag)) {
142 tokenizer->setState(HTMLTokenizer::RCDATAState); 150 tokenizer->setState(HTMLTokenizer::RCDATAState);
143 } else if (threadSafeMatch(tagName, plaintextTag)) {
144 tokenizer->setState(HTMLTokenizer::PLAINTEXTState);
145 } else if (threadSafeMatch(tagName, scriptTag)) { 151 } else if (threadSafeMatch(tagName, scriptTag)) {
146 tokenizer->setState(HTMLTokenizer::ScriptDataState); 152 tokenizer->setState(HTMLTokenizer::ScriptDataState);
147 simulatedToken = ScriptStart; 153 simulatedToken = ScriptStart;
148 } else if (threadSafeMatch(tagName, styleTag) || 154 } else if (!m_inSelectInsertionMode) {
149 threadSafeMatch(tagName, iframeTag) || 155 // If we're in the "in select" insertion mode, all of these tags are
150 threadSafeMatch(tagName, xmpTag) || 156 // ignored, so we shouldn't change the tokenizer state:
151 (threadSafeMatch(tagName, noembedTag) && 157 // https://html.spec.whatwg.org/#parsing-main-inselect
152 m_options.pluginsEnabled) || 158 if (threadSafeMatch(tagName, plaintextTag) &&
153 threadSafeMatch(tagName, noframesTag) || 159 !m_inSelectInsertionMode) {
154 (threadSafeMatch(tagName, noscriptTag) && 160 tokenizer->setState(HTMLTokenizer::PLAINTEXTState);
155 m_options.scriptEnabled)) { 161 } else if (threadSafeMatch(tagName, styleTag) ||
156 tokenizer->setState(HTMLTokenizer::RAWTEXTState); 162 threadSafeMatch(tagName, iframeTag) ||
163 threadSafeMatch(tagName, xmpTag) ||
164 (threadSafeMatch(tagName, noembedTag) &&
165 m_options.pluginsEnabled) ||
166 threadSafeMatch(tagName, noframesTag) ||
167 (threadSafeMatch(tagName, noscriptTag) &&
168 m_options.scriptEnabled)) {
169 tokenizer->setState(HTMLTokenizer::RAWTEXTState);
170 }
171 }
172
173 // We need to track whether we're in the "in select" insertion mode
174 // in order to determine whether '<plaintext>' will put the tokenizer
175 // into PLAINTEXTState, and whether '<xmp>' and others will consume
176 // textual content.
177 //
178 // https://html.spec.whatwg.org/#parsing-main-inselect
179 if (threadSafeMatch(tagName, selectTag)) {
180 m_inSelectInsertionMode = true;
181 } else if (m_inSelectInsertionMode && tokenExitsInSelect(token)) {
182 m_inSelectInsertionMode = false;
157 } 183 }
158 } 184 }
159 } 185 }
160 186
161 if (token.type() == HTMLToken::EndTag) { 187 if (token.type() == HTMLToken::EndTag) {
162 const String& tagName = token.data(); 188 const String& tagName = token.data();
163 if ((m_namespaceStack.last() == SVG && 189 if ((m_namespaceStack.last() == SVG &&
164 threadSafeMatch(tagName, SVGNames::svgTag)) || 190 threadSafeMatch(tagName, SVGNames::svgTag)) ||
165 (m_namespaceStack.last() == MathML && 191 (m_namespaceStack.last() == MathML &&
166 threadSafeMatch(tagName, MathMLNames::mathTag)) || 192 threadSafeMatch(tagName, MathMLNames::mathTag)) ||
167 (m_namespaceStack.contains(SVG) && m_namespaceStack.last() == HTML && 193 (m_namespaceStack.contains(SVG) && m_namespaceStack.last() == HTML &&
168 tokenExitsSVG(token)) || 194 tokenExitsSVG(token)) ||
169 (m_namespaceStack.contains(MathML) && m_namespaceStack.last() == HTML && 195 (m_namespaceStack.contains(MathML) && m_namespaceStack.last() == HTML &&
170 tokenExitsMath(token))) 196 tokenExitsMath(token))) {
171 m_namespaceStack.pop_back(); 197 m_namespaceStack.pop_back();
198 }
172 if (threadSafeMatch(tagName, scriptTag)) { 199 if (threadSafeMatch(tagName, scriptTag)) {
173 if (!inForeignContent()) 200 if (!inForeignContent())
174 tokenizer->setState(HTMLTokenizer::DataState); 201 tokenizer->setState(HTMLTokenizer::DataState);
175 return ScriptEnd; 202 return ScriptEnd;
203 } else if (threadSafeMatch(tagName, selectTag)) {
204 m_inSelectInsertionMode = false;
176 } 205 }
177 } 206 }
178 207
179 // FIXME: Also setForceNullCharacterReplacement when in text mode. 208 // FIXME: Also setForceNullCharacterReplacement when in text mode.
180 tokenizer->setForceNullCharacterReplacement(inForeignContent()); 209 tokenizer->setForceNullCharacterReplacement(inForeignContent());
181 tokenizer->setShouldAllowCDATA(inForeignContent()); 210 tokenizer->setShouldAllowCDATA(inForeignContent());
182 return simulatedToken; 211 return simulatedToken;
183 } 212 }
184 213
185 } // namespace blink 214 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698