OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/parser/CSSSelectorParser.h" | 5 #include "core/css/parser/CSSSelectorParser.h" |
6 | 6 |
7 #include "core/css/CSSSelectorList.h" | 7 #include "core/css/CSSSelectorList.h" |
8 #include "core/css/StyleSheetContents.h" | 8 #include "core/css/StyleSheetContents.h" |
9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 range.consumeWhitespace(); | 71 range.consumeWhitespace(); |
72 CSSSelectorList result = parser.consumeComplexSelectorList(range); | 72 CSSSelectorList result = parser.consumeComplexSelectorList(range); |
73 if (!range.atEnd()) | 73 if (!range.atEnd()) |
74 return CSSSelectorList(); | 74 return CSSSelectorList(); |
75 | 75 |
76 recordSelectorStats(context, result); | 76 recordSelectorStats(context, result); |
77 return result; | 77 return result; |
78 } | 78 } |
79 | 79 |
80 CSSSelectorParser::CSSSelectorParser(const CSSParserContext& context, StyleSheet
Contents* styleSheet) | 80 CSSSelectorParser::CSSSelectorParser(const CSSParserContext& context, StyleSheet
Contents* styleSheet) |
81 : m_context(context) | 81 : m_context(context) |
82 , m_styleSheet(styleSheet) | 82 , m_styleSheet(styleSheet) |
83 , m_failedParsing(false) | |
84 { | 83 { |
85 } | 84 } |
86 | 85 |
87 CSSSelectorList CSSSelectorParser::consumeComplexSelectorList(CSSParserTokenRang
e& range) | 86 CSSSelectorList CSSSelectorParser::consumeComplexSelectorList(CSSParserTokenRang
e& range) |
88 { | 87 { |
89 Vector<OwnPtr<CSSParserSelector>> selectorList; | 88 Vector<OwnPtr<CSSParserSelector>> selectorList; |
90 OwnPtr<CSSParserSelector> selector = consumeComplexSelector(range); | 89 OwnPtr<CSSParserSelector> selector = consumeComplexSelector(range); |
91 if (!selector) | 90 if (!selector) |
92 return CSSSelectorList(); | 91 return CSSSelectorList(); |
93 selectorList.append(selector.release()); | 92 selectorList.append(selector.release()); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (token.type() != IdentToken && token.type() != FunctionToken) | 326 if (token.type() != IdentToken && token.type() != FunctionToken) |
328 return nullptr; | 327 return nullptr; |
329 | 328 |
330 OwnPtr<CSSParserSelector> selector = CSSParserSelector::create(); | 329 OwnPtr<CSSParserSelector> selector = CSSParserSelector::create(); |
331 selector->setMatch(colons == 1 ? CSSSelector::PseudoClass : CSSSelector::Pse
udoElement); | 330 selector->setMatch(colons == 1 ? CSSSelector::PseudoClass : CSSSelector::Pse
udoElement); |
332 | 331 |
333 String value = token.value(); | 332 String value = token.value(); |
334 bool hasArguments = token.type() == FunctionToken; | 333 bool hasArguments = token.type() == FunctionToken; |
335 selector->updatePseudoType(AtomicString(value.is8Bit() ? value.lower() : val
ue), hasArguments); | 334 selector->updatePseudoType(AtomicString(value.is8Bit() ? value.lower() : val
ue), hasArguments); |
336 | 335 |
| 336 if (selector->match() == CSSSelector::PseudoElement && m_disallowPseudoEleme
nts) |
| 337 return nullptr; |
| 338 |
337 if (token.type() == IdentToken) { | 339 if (token.type() == IdentToken) { |
338 range.consume(); | 340 range.consume(); |
339 if (selector->pseudoType() == CSSSelector::PseudoUnknown) | 341 if (selector->pseudoType() == CSSSelector::PseudoUnknown) |
340 return nullptr; | 342 return nullptr; |
341 return selector.release(); | 343 return selector.release(); |
342 } | 344 } |
343 | 345 |
344 CSSParserTokenRange block = range.consumeBlock(); | 346 CSSParserTokenRange block = range.consumeBlock(); |
345 block.consumeWhitespace(); | 347 block.consumeWhitespace(); |
346 if (selector->pseudoType() == CSSSelector::PseudoUnknown) | 348 if (selector->pseudoType() == CSSSelector::PseudoUnknown) |
347 return nullptr; | 349 return nullptr; |
348 | 350 |
349 switch (selector->pseudoType()) { | 351 switch (selector->pseudoType()) { |
350 case CSSSelector::PseudoHost: | 352 case CSSSelector::PseudoHost: |
351 case CSSSelector::PseudoHostContext: | 353 case CSSSelector::PseudoHostContext: |
352 case CSSSelector::PseudoAny: | 354 case CSSSelector::PseudoAny: |
353 case CSSSelector::PseudoCue: | 355 case CSSSelector::PseudoCue: |
354 { | 356 { |
| 357 DisallowPseudoElementsScope scope(this); |
| 358 |
355 OwnPtr<CSSSelectorList> selectorList = adoptPtr(new CSSSelectorList(
)); | 359 OwnPtr<CSSSelectorList> selectorList = adoptPtr(new CSSSelectorList(
)); |
356 *selectorList = consumeCompoundSelectorList(block); | 360 *selectorList = consumeCompoundSelectorList(block); |
357 if (!selectorList->isValid() || !block.atEnd()) | 361 if (!selectorList->isValid() || !block.atEnd()) |
358 return nullptr; | 362 return nullptr; |
359 selector->setSelectorList(selectorList.release()); | 363 selector->setSelectorList(selectorList.release()); |
360 return selector.release(); | 364 return selector.release(); |
361 } | 365 } |
362 case CSSSelector::PseudoNot: | 366 case CSSSelector::PseudoNot: |
363 { | 367 { |
364 OwnPtr<CSSParserSelector> innerSelector = consumeCompoundSelector(bl
ock); | 368 OwnPtr<CSSParserSelector> innerSelector = consumeCompoundSelector(bl
ock); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); | 678 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); |
675 return compoundSelector; | 679 return compoundSelector; |
676 } | 680 } |
677 | 681 |
678 // All other simple selectors are added to the end of the compound. | 682 // All other simple selectors are added to the end of the compound. |
679 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; | 683 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; |
680 return compoundSelector; | 684 return compoundSelector; |
681 } | 685 } |
682 | 686 |
683 } // namespace blink | 687 } // namespace blink |
OLD | NEW |