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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp

Issue 2474483002: [LazyParseCSS] Ensure UseCounting has parity with strict parsing (Closed)
Patch Set: Add StyleSheetContents::anyOwnerDocument() Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/CSSLazyParsingState.h" 5 #include "core/css/parser/CSSLazyParsingState.h"
6 #include "core/css/parser/CSSParserTokenRange.h" 6 #include "core/css/parser/CSSParserTokenRange.h"
7 #include "core/dom/Document.h"
7 #include "core/frame/UseCounter.h" 8 #include "core/frame/UseCounter.h"
8 9
9 namespace blink { 10 namespace blink {
10 11
11 CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext& context, 12 CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext& context,
12 Vector<String> escapedStrings, 13 Vector<String> escapedStrings,
13 const String& sheetText, 14 const String& sheetText,
14 StyleSheetContents* contents) 15 StyleSheetContents* contents)
15 : m_context(context), 16 : m_context(context),
16 m_escapedStrings(std::move(escapedStrings)), 17 m_escapedStrings(std::move(escapedStrings)),
17 m_sheetText(sheetText), 18 m_sheetText(sheetText),
18 m_owningContents(contents) {} 19 m_owningContents(contents) {}
19 20
20 const CSSParserContext& CSSLazyParsingState::context() { 21 const CSSParserContext& CSSLazyParsingState::context() {
21 DCHECK(m_owningContents); 22 DCHECK(m_owningContents);
22 UseCounter* sheetCounter = UseCounter::getFrom(m_owningContents); 23 Document* document = m_owningContents->anyOwnerDocument();
23 if (sheetCounter != m_context.useCounter()) 24 if (document != m_document) {
rune 2016/12/02 22:18:09 Couldn't you check if m_document is nullptr before
Charlie Harrison 2016/12/02 22:38:46 Yes I think we can do this. My reason for doing it
24 m_context = CSSParserContext(m_context, sheetCounter); 25 // Since all StyleSheetContents are parsed with a single owner document, try
26 // as best as possible to grab a valid UseCounter if the underlying document
27 // has gone away.
28 m_document = document;
29 m_context = CSSParserContext(m_context, UseCounter::getFrom(m_document));
30 }
25 return m_context; 31 return m_context;
26 } 32 }
27 33
28 bool CSSLazyParsingState::shouldLazilyParseProperties( 34 bool CSSLazyParsingState::shouldLazilyParseProperties(
29 const CSSSelectorList& selectors, 35 const CSSSelectorList& selectors,
30 const CSSParserTokenRange& block) { 36 const CSSParserTokenRange& block) {
31 // Simple heuristic for an empty block. Note that |block| here does not 37 // Simple heuristic for an empty block. Note that |block| here does not
32 // include {} brackets. We avoid lazy parsing empty blocks so we can avoid 38 // include {} brackets. We avoid lazy parsing empty blocks so we can avoid
33 // considering them when possible for matching. Lazy blocks must always be 39 // considering them when possible for matching. Lazy blocks must always be
34 // considered. Three tokens is a reasonable minimum for a block: 40 // considered. Three tokens is a reasonable minimum for a block:
(...skipping 11 matching lines...) Expand all
46 const CSSSelector::PseudoType type(current->getPseudoType()); 52 const CSSSelector::PseudoType type(current->getPseudoType());
47 if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter) 53 if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter)
48 return false; 54 return false;
49 if (current->relation() != CSSSelector::SubSelector) 55 if (current->relation() != CSSSelector::SubSelector)
50 break; 56 break;
51 } 57 }
52 } 58 }
53 return true; 59 return true;
54 } 60 }
55 61
62 DEFINE_TRACE(CSSLazyParsingState) {
63 visitor->trace(m_owningContents);
64 visitor->trace(m_document);
65 }
66
56 } // namespace blink 67 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698