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

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

Issue 2625103002: Teach the background parser to ignore certain elements inside '<select>'. (Closed)
Patch Set: Test. 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.push_back(HTML); 106 m_namespaceStack.push_back(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.back() == SVG && tokenExitsSVG(token)) || 142 if ((m_namespaceStack.back() == SVG && tokenExitsSVG(token)) ||
135 (m_namespaceStack.back() == MathML && tokenExitsMath(token))) 143 (m_namespaceStack.back() == MathML && tokenExitsMath(token)))
136 m_namespaceStack.push_back(HTML); 144 m_namespaceStack.push_back(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) {
Yoav Weiss 2017/01/12 13:45:44 I'm most probably missing something, but I don't s
Mike West 2017/01/12 14:44:51 Sure. However, we have no idea what mode we're in
Yoav Weiss 2017/01/13 14:13:19 makes sense :)
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)) {
Yoav Weiss 2017/01/12 13:45:44 Here we're basically blocking anything not mention
Mike West 2017/01/12 14:44:51 No? This basically just moves the existing code (f
Yoav Weiss 2017/01/13 14:13:19 fair enough :)
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 (token.type() == HTMLToken::StartTag && token.selfClosing() && 188 (token.type() == HTMLToken::StartTag && token.selfClosing() &&
163 inForeignContent())) { 189 inForeignContent())) {
164 const String& tagName = token.data(); 190 const String& tagName = token.data();
165 if ((m_namespaceStack.back() == SVG && 191 if ((m_namespaceStack.back() == SVG &&
166 threadSafeMatch(tagName, SVGNames::svgTag)) || 192 threadSafeMatch(tagName, SVGNames::svgTag)) ||
167 (m_namespaceStack.back() == MathML && 193 (m_namespaceStack.back() == MathML &&
168 threadSafeMatch(tagName, MathMLNames::mathTag)) || 194 threadSafeMatch(tagName, MathMLNames::mathTag)) ||
169 (m_namespaceStack.contains(SVG) && m_namespaceStack.back() == HTML && 195 (m_namespaceStack.contains(SVG) && m_namespaceStack.back() == HTML &&
170 tokenExitsSVG(token)) || 196 tokenExitsSVG(token)) ||
171 (m_namespaceStack.contains(MathML) && m_namespaceStack.back() == HTML && 197 (m_namespaceStack.contains(MathML) && m_namespaceStack.back() == HTML &&
172 tokenExitsMath(token))) 198 tokenExitsMath(token))) {
173 m_namespaceStack.pop_back(); 199 m_namespaceStack.pop_back();
200 }
174 if (threadSafeMatch(tagName, scriptTag)) { 201 if (threadSafeMatch(tagName, scriptTag)) {
175 if (!inForeignContent()) 202 if (!inForeignContent())
176 tokenizer->setState(HTMLTokenizer::DataState); 203 tokenizer->setState(HTMLTokenizer::DataState);
177 return ScriptEnd; 204 return ScriptEnd;
205 } else if (threadSafeMatch(tagName, selectTag)) {
206 m_inSelectInsertionMode = false;
178 } 207 }
179 } 208 }
180 209
181 // FIXME: Also setForceNullCharacterReplacement when in text mode. 210 // FIXME: Also setForceNullCharacterReplacement when in text mode.
182 tokenizer->setForceNullCharacterReplacement(inForeignContent()); 211 tokenizer->setForceNullCharacterReplacement(inForeignContent());
183 tokenizer->setShouldAllowCDATA(inForeignContent()); 212 tokenizer->setShouldAllowCDATA(inForeignContent());
184 return simulatedToken; 213 return simulatedToken;
185 } 214 }
186 215
187 } // namespace blink 216 } // 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