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

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

Issue 2474483002: [LazyParseCSS] Ensure UseCounting has parity with strict parsing (Closed)
Patch Set: s/!/!!/ 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
index 1a231c6dc85ded6e06f0492cf21242bf60b8b075..b3d2ec5c849fbab7c3acbfb27b276ed83b41b87b 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
@@ -5,6 +5,7 @@
#include "core/css/parser/CSSLazyParsingState.h"
#include "core/css/parser/CSSLazyPropertyParserImpl.h"
#include "core/css/parser/CSSParserTokenRange.h"
+#include "core/dom/Document.h"
#include "core/frame/UseCounter.h"
#include "platform/Histogram.h"
@@ -21,7 +22,8 @@ CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext& context,
m_parsedStyleRules(0),
m_totalStyleRules(0),
m_styleRulesNeededForNextMilestone(0),
- m_usage(UsageGe0) {
+ m_usage(UsageGe0),
+ m_shouldUseCount(!!m_context.useCounter()) {
recordUsageMetrics();
}
@@ -33,9 +35,21 @@ CSSLazyPropertyParserImpl* CSSLazyParsingState::createLazyParser(
const CSSParserContext& CSSLazyParsingState::context() {
DCHECK(m_owningContents);
- UseCounter* sheetCounter = UseCounter::getFrom(m_owningContents);
- if (sheetCounter != m_context.useCounter())
- m_context = CSSParserContext(m_context, sheetCounter);
+ if (!m_shouldUseCount) {
+ DCHECK(!m_context.useCounter());
+ return m_context;
+ }
+
+ // Try as best as possible to grab a valid UseCounter if the underlying
+ // document has gone away.
+ if (!m_document)
+ m_document = m_owningContents->anyOwnerDocument();
+
+ // Always refresh the UseCounter, as the Document can outlive its
+ // underlying frame host causing a use-after-free of m_context's counter.
+ UseCounter* useCounter = UseCounter::getFrom(m_document);
rune 2016/12/05 22:21:05 If we always retrieve the UseCounter, could we sim
Charlie Harrison 2016/12/05 22:27:59 I don't have the trace now, but I remember seeing
rune 2016/12/05 22:31:53 Acknowledged.
+ if (useCounter != m_context.useCounter())
+ m_context = CSSParserContext(m_context, useCounter);
return m_context;
}
@@ -106,4 +120,9 @@ void CSSLazyParsingState::recordUsageMetrics() {
usageHistogram.count(m_usage);
}
+DEFINE_TRACE(CSSLazyParsingState) {
+ visitor->trace(m_owningContents);
+ visitor->trace(m_document);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698