Make CSSParserContext be garbage collected.

This is a refactor only, no functionality should change. This allocates
CSSParserContext on the heap and wires it up to be garbage collected.
This is necessary so in the future it can have a handle to a Document
(also a GC'ed class) instead of a UseCounter.

Also includes some minor API changes to CSSParserContext that I think
make it more readable, since I'm changing every callsite of the class
already anyway.

TBR=haraken@chromium.org
BUG=668251

Review-Url: https://codereview.chromium.org/2616093003
Cr-Commit-Position: refs/heads/master@{#443792}
diff --git a/third_party/WebKit/Source/build/scripts/templates/CSSPropertyAPIFiles.h.tmpl b/third_party/WebKit/Source/build/scripts/templates/CSSPropertyAPIFiles.h.tmpl
index f008171..fcc9687 100644
--- a/third_party/WebKit/Source/build/scripts/templates/CSSPropertyAPIFiles.h.tmpl
+++ b/third_party/WebKit/Source/build/scripts/templates/CSSPropertyAPIFiles.h.tmpl
@@ -16,7 +16,7 @@
 class {{api_classname}} : public CSSPropertyAPI {
  public:
   static const CSSValue* parseSingleValue(CSSParserTokenRange&,
-                                          const CSSParserContext&);
+                                          const CSSParserContext*);
 };
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/ActiveStyleSheetsTest.cpp b/third_party/WebKit/Source/core/css/ActiveStyleSheetsTest.cpp
index e22465a..1cd52d0 100644
--- a/third_party/WebKit/Source/core/css/ActiveStyleSheetsTest.cpp
+++ b/third_party/WebKit/Source/core/css/ActiveStyleSheetsTest.cpp
@@ -23,7 +23,7 @@
  protected:
   static CSSStyleSheet* createSheet(const String& cssText = String()) {
     StyleSheetContents* contents =
-        StyleSheetContents::create(CSSParserContext(HTMLStandardMode, nullptr));
+        StyleSheetContents::create(CSSParserContext::create(HTMLStandardMode));
     contents->parseString(cssText);
     contents->ensureRuleSet(MediaQueryEvaluator(),
                             RuleHasDocumentSecurityOrigin);
diff --git a/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp b/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp
index 0f628a2..b92e529 100644
--- a/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp
+++ b/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp
@@ -64,7 +64,7 @@
 
 static StyleSheetContents* parseUASheet(const String& str) {
   StyleSheetContents* sheet =
-      StyleSheetContents::create(CSSParserContext(UASheetMode, nullptr));
+      StyleSheetContents::create(CSSParserContext::create(UASheetMode));
   sheet->parseString(str);
   // User Agent stylesheets are parsed once for the lifetime of the renderer
   // process and are intentionally leaked.
diff --git a/third_party/WebKit/Source/core/css/CSSGroupingRule.cpp b/third_party/WebKit/Source/core/css/CSSGroupingRule.cpp
index f9b8541..258cfe3 100644
--- a/third_party/WebKit/Source/core/css/CSSGroupingRule.cpp
+++ b/third_party/WebKit/Source/core/css/CSSGroupingRule.cpp
@@ -62,7 +62,8 @@
   }
 
   CSSStyleSheet* styleSheet = parentStyleSheet();
-  CSSParserContext context(parserContext(), UseCounter::getFrom(styleSheet));
+  CSSParserContext* context =
+      CSSParserContext::createWithStyleSheet(parserContext(), styleSheet);
   StyleRuleBase* newRule = CSSParser::parseRule(
       context, styleSheet ? styleSheet->contents() : nullptr, ruleString);
   if (!newRule) {
diff --git a/third_party/WebKit/Source/core/css/CSSKeyframesRule.cpp b/third_party/WebKit/Source/core/css/CSSKeyframesRule.cpp
index 18fdb4e1..88cae61 100644
--- a/third_party/WebKit/Source/core/css/CSSKeyframesRule.cpp
+++ b/third_party/WebKit/Source/core/css/CSSKeyframesRule.cpp
@@ -99,7 +99,8 @@
          m_keyframesRule->keyframes().size());
 
   CSSStyleSheet* styleSheet = parentStyleSheet();
-  CSSParserContext context(parserContext(), UseCounter::getFrom(styleSheet));
+  CSSParserContext* context =
+      CSSParserContext::createWithStyleSheet(parserContext(), styleSheet);
   StyleRuleKeyframe* keyframe = CSSParser::parseKeyframeRule(context, ruleText);
   if (!keyframe)
     return;
diff --git a/third_party/WebKit/Source/core/css/CSSPageRule.cpp b/third_party/WebKit/Source/core/css/CSSPageRule.cpp
index 8dec885..1ceded32 100644
--- a/third_party/WebKit/Source/core/css/CSSPageRule.cpp
+++ b/third_party/WebKit/Source/core/css/CSSPageRule.cpp
@@ -55,7 +55,8 @@
 }
 
 void CSSPageRule::setSelectorText(const String& selectorText) {
-  CSSParserContext context(parserContext(), nullptr);
+  CSSParserContext* context =
+      CSSParserContext::create(parserContext(), nullptr);
   CSSSelectorList selectorList = CSSParser::parsePageSelector(
       context, parentStyleSheet() ? parentStyleSheet()->contents() : nullptr,
       selectorText);
diff --git a/third_party/WebKit/Source/core/css/CSSRule.cpp b/third_party/WebKit/Source/core/css/CSSRule.cpp
index b6f52d7c..d8089d5 100644
--- a/third_party/WebKit/Source/core/css/CSSRule.cpp
+++ b/third_party/WebKit/Source/core/css/CSSRule.cpp
@@ -38,7 +38,7 @@
 static_assert(sizeof(CSSRule) == sizeof(SameSizeAsCSSRule),
               "CSSRule should stay small");
 
-const CSSParserContext& CSSRule::parserContext() const {
+const CSSParserContext* CSSRule::parserContext() const {
   CSSStyleSheet* styleSheet = parentStyleSheet();
   return styleSheet ? styleSheet->contents()->parserContext()
                     : strictCSSParserContext();
diff --git a/third_party/WebKit/Source/core/css/CSSRule.h b/third_party/WebKit/Source/core/css/CSSRule.h
index 19607b29..6f97d95 100644
--- a/third_party/WebKit/Source/core/css/CSSRule.h
+++ b/third_party/WebKit/Source/core/css/CSSRule.h
@@ -93,7 +93,7 @@
     m_hasCachedSelectorText = hasCachedSelectorText;
   }
 
-  const CSSParserContext& parserContext() const;
+  const CSSParserContext* parserContext() const;
 
  private:
   mutable unsigned char m_hasCachedSelectorText : 1;
diff --git a/third_party/WebKit/Source/core/css/CSSStyleRule.cpp b/third_party/WebKit/Source/core/css/CSSStyleRule.cpp
index 3f1763628..31860a52 100644
--- a/third_party/WebKit/Source/core/css/CSSStyleRule.cpp
+++ b/third_party/WebKit/Source/core/css/CSSStyleRule.cpp
@@ -77,7 +77,8 @@
 }
 
 void CSSStyleRule::setSelectorText(const String& selectorText) {
-  CSSParserContext context(parserContext(), nullptr);
+  const CSSParserContext* context =
+      CSSParserContext::create(parserContext(), nullptr);
   CSSSelectorList selectorList = CSSParser::parseSelector(
       context, parentStyleSheet() ? parentStyleSheet()->contents() : nullptr,
       selectorText);
diff --git a/third_party/WebKit/Source/core/css/CSSStyleSheet.cpp b/third_party/WebKit/Source/core/css/CSSStyleSheet.cpp
index decf312..44201915 100644
--- a/third_party/WebKit/Source/core/css/CSSStyleSheet.cpp
+++ b/third_party/WebKit/Source/core/css/CSSStyleSheet.cpp
@@ -102,8 +102,8 @@
                                            const KURL& baseURL,
                                            const TextPosition& startPosition,
                                            const String& encoding) {
-  CSSParserContext parserContext(ownerNode.document(), nullptr, baseURL,
-                                 encoding);
+  CSSParserContext* parserContext =
+      CSSParserContext::create(ownerNode.document(), baseURL, encoding);
   StyleSheetContents* sheet =
       StyleSheetContents::create(baseURL.getString(), parserContext);
   return new CSSStyleSheet(sheet, ownerNode, true, startPosition);
@@ -264,8 +264,8 @@
                             String::number(length()) + ").");
     return 0;
   }
-  CSSParserContext context(m_contents->parserContext(),
-                           UseCounter::getFrom(this));
+  const CSSParserContext* context =
+      CSSParserContext::createWithStyleSheet(m_contents->parserContext(), this);
   StyleRuleBase* rule =
       CSSParser::parseRule(context, m_contents.get(), ruleString);
 
diff --git a/third_party/WebKit/Source/core/css/DOMWindowCSS.cpp b/third_party/WebKit/Source/core/css/DOMWindowCSS.cpp
index 46c90a4..3b9bbca 100644
--- a/third_party/WebKit/Source/core/css/DOMWindowCSS.cpp
+++ b/third_party/WebKit/Source/core/css/DOMWindowCSS.cpp
@@ -57,7 +57,7 @@
   // This will return false when !important is present
   MutableStylePropertySet* dummyStyle =
       MutableStylePropertySet::create(HTMLStandardMode);
-  return CSSParser::parseValue(dummyStyle, unresolvedProperty, value, false, 0)
+  return CSSParser::parseValue(dummyStyle, unresolvedProperty, value, false)
       .didParse;
 }
 
diff --git a/third_party/WebKit/Source/core/css/FontFace.cpp b/third_party/WebKit/Source/core/css/FontFace.cpp
index 66783b99..1f64d68d 100644
--- a/third_party/WebKit/Source/core/css/FontFace.cpp
+++ b/third_party/WebKit/Source/core/css/FontFace.cpp
@@ -68,7 +68,8 @@
 static const CSSValue* parseCSSValue(const Document* document,
                                      const String& value,
                                      CSSPropertyID propertyID) {
-  CSSParserContext context(*document, UseCounter::getFrom(document));
+  CSSParserContext* context =
+      CSSParserContext::create(*document, UseCounter::getFrom(document));
   return CSSParser::parseFontFaceDescriptor(propertyID, value, context);
 }
 
diff --git a/third_party/WebKit/Source/core/css/FontFaceSet.cpp b/third_party/WebKit/Source/core/css/FontFaceSet.cpp
index 572793d1..d998594 100644
--- a/third_party/WebKit/Source/core/css/FontFaceSet.cpp
+++ b/third_party/WebKit/Source/core/css/FontFaceSet.cpp
@@ -446,7 +446,7 @@
   // CanvasRenderingContext2D.
   MutableStylePropertySet* parsedStyle =
       MutableStylePropertySet::create(HTMLStandardMode);
-  CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true, 0);
+  CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true);
   if (parsedStyle->isEmpty())
     return false;
 
diff --git a/third_party/WebKit/Source/core/css/StylePropertySet.cpp b/third_party/WebKit/Source/core/css/StylePropertySet.cpp
index 2446f3f..3049d035 100644
--- a/third_party/WebKit/Source/core/css/StylePropertySet.cpp
+++ b/third_party/WebKit/Source/core/css/StylePropertySet.cpp
@@ -384,11 +384,13 @@
     StyleSheetContents* contextStyleSheet) {
   m_propertyVector.clear();
 
-  CSSParserContext context(cssParserMode(),
-                           UseCounter::getFrom(contextStyleSheet));
+  CSSParserContext* context;
   if (contextStyleSheet) {
-    context = contextStyleSheet->parserContext();
-    context.setMode(cssParserMode());
+    context = CSSParserContext::createWithStyleSheetContents(
+        contextStyleSheet->parserContext(), contextStyleSheet);
+    context->setMode(cssParserMode());
+  } else {
+    context = CSSParserContext::create(cssParserMode());
   }
 
   CSSParser::parseDeclarationList(context, this, styleDeclaration);
diff --git a/third_party/WebKit/Source/core/css/StyleRuleImport.cpp b/third_party/WebKit/Source/core/css/StyleRuleImport.cpp
index d35a32f2..5d8d808 100644
--- a/third_party/WebKit/Source/core/css/StyleRuleImport.cpp
+++ b/third_party/WebKit/Source/core/css/StyleRuleImport.cpp
@@ -72,17 +72,19 @@
   if (m_styleSheet)
     m_styleSheet->clearOwnerRule();
 
-  CSSParserContext context = m_parentStyleSheet
-                                 ? m_parentStyleSheet->parserContext()
-                                 : strictCSSParserContext();
-  context.setCharset(charset);
+  CSSParserContext* context = CSSParserContext::create(
+      m_parentStyleSheet ? m_parentStyleSheet->parserContext()
+                         : strictCSSParserContext(),
+      nullptr);
+  context->setCharset(charset);
   Document* document =
       m_parentStyleSheet ? m_parentStyleSheet->singleOwnerDocument() : nullptr;
   if (!baseURL.isNull()) {
-    context.setBaseURL(baseURL);
-    if (document)
-      context.setReferrer(Referrer(baseURL.strippedForUseAsReferrer(),
-                                   document->getReferrerPolicy()));
+    context->setBaseURL(baseURL);
+    if (document) {
+      context->setReferrer(Referrer(baseURL.strippedForUseAsReferrer(),
+                                    document->getReferrerPolicy()));
+    }
   }
 
   m_styleSheet = StyleSheetContents::create(this, href, context);
diff --git a/third_party/WebKit/Source/core/css/StyleSheetContents.cpp b/third_party/WebKit/Source/core/css/StyleSheetContents.cpp
index 982ca98..be7b7347 100644
--- a/third_party/WebKit/Source/core/css/StyleSheetContents.cpp
+++ b/third_party/WebKit/Source/core/css/StyleSheetContents.cpp
@@ -59,7 +59,7 @@
 
 StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule,
                                        const String& originalURL,
-                                       const CSSParserContext& context)
+                                       const CSSParserContext* context)
     : m_ownerRule(ownerRule),
       m_originalURL(originalURL),
       m_defaultNamespace(starAtom),
@@ -346,7 +346,7 @@
   }
 
   CSSStyleSheetResource::MIMETypeCheck mimeTypeCheck =
-      isQuirksModeBehavior(m_parserContext.mode()) && isSameOriginRequest
+      isQuirksModeBehavior(m_parserContext->mode()) && isSameOriginRequest
           ? CSSStyleSheetResource::MIMETypeCheck::Lax
           : CSSStyleSheetResource::MIMETypeCheck::Strict;
   String sheetText = cachedStyleSheet->sheetText(mimeTypeCheck);
@@ -358,7 +358,8 @@
     m_sourceMapURL = response.httpHeaderField(HTTPNames::X_SourceMap);
   }
 
-  CSSParserContext context(parserContext(), UseCounter::getFrom(this));
+  const CSSParserContext* context =
+      CSSParserContext::createWithStyleSheetContents(parserContext(), this);
   CSSParser::parseSheet(context, this, sheetText,
                         RuntimeEnabledFeatures::lazyParseCSSEnabled());
 
@@ -379,7 +380,8 @@
 void StyleSheetContents::parseStringAtPosition(
     const String& sheetText,
     const TextPosition& startPosition) {
-  CSSParserContext context(parserContext(), UseCounter::getFrom(this));
+  const CSSParserContext* context =
+      CSSParserContext::createWithStyleSheetContents(parserContext(), this);
   CSSParser::parseSheet(context, this, sheetText);
 }
 
@@ -693,6 +695,7 @@
   visitor->trace(m_completedClients);
   visitor->trace(m_ruleSet);
   visitor->trace(m_referencedFromResource);
+  visitor->trace(m_parserContext);
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/StyleSheetContents.h b/third_party/WebKit/Source/core/css/StyleSheetContents.h
index b54a61b..caf0fcb 100644
--- a/third_party/WebKit/Source/core/css/StyleSheetContents.h
+++ b/third_party/WebKit/Source/core/css/StyleSheetContents.h
@@ -48,22 +48,22 @@
 class CORE_EXPORT StyleSheetContents
     : public GarbageCollectedFinalized<StyleSheetContents> {
  public:
-  static StyleSheetContents* create(const CSSParserContext& context) {
+  static StyleSheetContents* create(const CSSParserContext* context) {
     return new StyleSheetContents(0, String(), context);
   }
   static StyleSheetContents* create(const String& originalURL,
-                                    const CSSParserContext& context) {
+                                    const CSSParserContext* context) {
     return new StyleSheetContents(0, originalURL, context);
   }
   static StyleSheetContents* create(StyleRuleImport* ownerRule,
                                     const String& originalURL,
-                                    const CSSParserContext& context) {
+                                    const CSSParserContext* context) {
     return new StyleSheetContents(ownerRule, originalURL, context);
   }
 
   ~StyleSheetContents();
 
-  const CSSParserContext& parserContext() const { return m_parserContext; }
+  const CSSParserContext* parserContext() const { return m_parserContext; }
 
   const AtomicString& defaultNamespace() { return m_defaultNamespace; }
   const AtomicString& namespaceURIFromPrefix(const AtomicString& prefix);
@@ -91,7 +91,7 @@
   // if there are none.
   Document* anyOwnerDocument() const;
 
-  const String& charset() const { return m_parserContext.charset(); }
+  const String& charset() const { return m_parserContext->charset(); }
 
   bool loadCompleted() const;
   bool hasFailedOrCanceledSubresources() const;
@@ -135,7 +135,7 @@
   // this style sheet. This property probably isn't useful for much except
   // the JavaScript binding (which needs to use this value for security).
   String originalURL() const { return m_originalURL; }
-  const KURL& baseURL() const { return m_parserContext.baseURL(); }
+  const KURL& baseURL() const { return m_parserContext->baseURL(); }
 
   unsigned ruleCount() const;
   StyleRuleBase* ruleAt(unsigned index) const;
@@ -185,7 +185,7 @@
  private:
   StyleSheetContents(StyleRuleImport* ownerRule,
                      const String& originalURL,
-                     const CSSParserContext&);
+                     const CSSParserContext*);
   StyleSheetContents(const StyleSheetContents&);
   StyleSheetContents() = delete;
   StyleSheetContents& operator=(const StyleSheetContents&) = delete;
@@ -215,7 +215,7 @@
   bool m_hasSingleOwnerDocument : 1;
   bool m_isUsedFromTextCache : 1;
 
-  CSSParserContext m_parserContext;
+  Member<const CSSParserContext> m_parserContext;
 
   HeapHashSet<WeakMember<CSSStyleSheet>> m_loadingClients;
   HeapHashSet<WeakMember<CSSStyleSheet>> m_completedClients;
diff --git a/third_party/WebKit/Source/core/css/StyleSheetContentsFuzzer.cpp b/third_party/WebKit/Source/core/css/StyleSheetContentsFuzzer.cpp
index 236089b..38d8ccb8 100644
--- a/third_party/WebKit/Source/core/css/StyleSheetContentsFuzzer.cpp
+++ b/third_party/WebKit/Source/core/css/StyleSheetContentsFuzzer.cpp
@@ -8,7 +8,8 @@
 #include "wtf/text/WTFString.h"
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
-  blink::CSSParserContext context(blink::HTMLStandardMode, nullptr);
+  blink::CSSParserContext* context =
+      blink::CSSParserContext::create(blink::HTMLStandardMode);
   blink::StyleSheetContents* styleSheet =
       blink::StyleSheetContents::create(context);
   styleSheet->parseString(String::fromUTF8WithLatin1Fallback(
diff --git a/third_party/WebKit/Source/core/css/StyleSheetContentsTest.cpp b/third_party/WebKit/Source/core/css/StyleSheetContentsTest.cpp
index 232850d..3ab2ae8 100644
--- a/third_party/WebKit/Source/core/css/StyleSheetContentsTest.cpp
+++ b/third_party/WebKit/Source/core/css/StyleSheetContentsTest.cpp
@@ -11,7 +11,7 @@
 namespace blink {
 
 TEST(StyleSheetContentsTest, InsertMediaRule) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
 
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
   styleSheet->parseString("@namespace ns url(test);");
@@ -34,7 +34,7 @@
 }
 
 TEST(StyleSheetContentsTest, InsertFontFaceRule) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
 
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
   styleSheet->parseString("@namespace ns url(test);");
@@ -57,7 +57,7 @@
 }
 
 TEST(StyleSheetContentsTest, HasViewportRule) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
 
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
   styleSheet->parseString("@viewport { width: 200px}");
@@ -66,7 +66,7 @@
 }
 
 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertion) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
 
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
   styleSheet->parseString("body { color: pink }");
@@ -82,7 +82,7 @@
 }
 
 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertionIntoMediaRule) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
 
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
   styleSheet->parseString("@media {}");
diff --git a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
index b3d2ec5..c5ed81c 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.cpp
@@ -11,7 +11,7 @@
 
 namespace blink {
 
-CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext& context,
+CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext* context,
                                          Vector<String> escapedStrings,
                                          const String& sheetText,
                                          StyleSheetContents* contents)
@@ -23,7 +23,7 @@
       m_totalStyleRules(0),
       m_styleRulesNeededForNextMilestone(0),
       m_usage(UsageGe0),
-      m_shouldUseCount(!!m_context.useCounter()) {
+      m_shouldUseCount(m_context->isUseCounterRecordingEnabled()) {
   recordUsageMetrics();
 }
 
@@ -33,23 +33,21 @@
   return new CSSLazyPropertyParserImpl(std::move(block), this);
 }
 
-const CSSParserContext& CSSLazyParsingState::context() {
+const CSSParserContext* CSSLazyParsingState::context() {
   DCHECK(m_owningContents);
   if (!m_shouldUseCount) {
-    DCHECK(!m_context.useCounter());
+    DCHECK(!m_context->isUseCounterRecordingEnabled());
     return m_context;
   }
 
-  // Try as best as possible to grab a valid UseCounter if the underlying
-  // document has gone away.
+  // Try as best as possible to grab a valid Document if the old Document has
+  // gone away so we can still use UseCounter.
   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);
-  if (useCounter != m_context.useCounter())
-    m_context = CSSParserContext(m_context, useCounter);
+  if (useCounter != m_context->useCounter())
+    m_context = CSSParserContext::create(m_context, useCounter);
   return m_context;
 }
 
@@ -123,6 +121,7 @@
 DEFINE_TRACE(CSSLazyParsingState) {
   visitor->trace(m_owningContents);
   visitor->trace(m_document);
+  visitor->trace(m_context);
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.h b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.h
index 80c846f..2d6eda4 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingState.h
@@ -22,7 +22,7 @@
 class CSSLazyParsingState
     : public GarbageCollectedFinalized<CSSLazyParsingState> {
  public:
-  CSSLazyParsingState(const CSSParserContext&,
+  CSSLazyParsingState(const CSSParserContext*,
                       Vector<String> escapedStrings,
                       const String& sheetText,
                       StyleSheetContents*);
@@ -30,7 +30,7 @@
   // Helper method used to bump m_totalStyleRules.
   CSSLazyPropertyParserImpl* createLazyParser(const CSSParserTokenRange& block);
 
-  const CSSParserContext& context();
+  const CSSParserContext* context();
 
   void countRuleParsed();
 
@@ -57,7 +57,7 @@
  private:
   void recordUsageMetrics();
 
-  CSSParserContext m_context;
+  Member<const CSSParserContext> m_context;
   Vector<String> m_escapedStrings;
   // Also referenced on the css resource.
   String m_sheetText;
diff --git a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingTest.cpp b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingTest.cpp
index 064e172..7d5fbf82 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSLazyParsingTest.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSLazyParsingTest.cpp
@@ -33,7 +33,7 @@
 };
 
 TEST_F(CSSLazyParsingTest, Simple) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
 
   String sheetText = "body { background-color: red; }";
@@ -47,7 +47,7 @@
 // Avoiding lazy parsing for trivially empty blocks helps us perform the
 // shouldConsiderForMatchingRules optimization.
 TEST_F(CSSLazyParsingTest, DontLazyParseEmpty) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
 
   String sheetText = "body {  }";
@@ -61,7 +61,7 @@
 // Avoid parsing rules with ::before or ::after to avoid causing
 // collectFeatures() when we trigger parsing for attr();
 TEST_F(CSSLazyParsingTest, DontLazyParseBeforeAfter) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
 
   String sheetText =
@@ -77,7 +77,7 @@
 // dangerous API because callers will expect the set of matching rules to be
 // identical if the stylesheet is not mutated.
 TEST_F(CSSLazyParsingTest, ShouldConsiderForMatchingRulesDoesntChange1) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
 
   String sheetText = "p::first-letter { ,badness, } ";
@@ -100,7 +100,7 @@
 // Test the same thing as above, with a property that does not get lazy parsed,
 // to ensure that we perform the optimization where possible.
 TEST_F(CSSLazyParsingTest, ShouldConsiderForMatchingRulesSimple) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
 
   String sheetText = "p::before { ,badness, } ";
@@ -118,8 +118,9 @@
 TEST_F(CSSLazyParsingTest, ChangeDocuments) {
   std::unique_ptr<DummyPageHolder> dummyHolder =
       DummyPageHolder::create(IntSize(500, 500));
-  CSSParserContext context(HTMLStandardMode,
-                           UseCounter::getFrom(&dummyHolder->document()));
+  CSSParserContext* context = CSSParserContext::create(
+      HTMLStandardMode, CSSParserContext::DynamicProfile,
+      UseCounter::getFrom(&dummyHolder->document()));
   m_cachedContents = StyleSheetContents::create(context);
   {
     CSSStyleSheet* sheet =
@@ -169,7 +170,7 @@
 }
 
 TEST_F(CSSLazyParsingTest, SimpleRuleUsagePercent) {
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* styleSheet = StyleSheetContents::create(context);
 
   std::string metricName = "Style.LazyUsage.Percent";
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSParser.cpp
index b0c557b..ab4d97bf9 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParser.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSParser.cpp
@@ -21,21 +21,21 @@
 
 namespace blink {
 
-bool CSSParser::parseDeclarationList(const CSSParserContext& context,
+bool CSSParser::parseDeclarationList(const CSSParserContext* context,
                                      MutableStylePropertySet* propertySet,
                                      const String& declaration) {
   return CSSParserImpl::parseDeclarationList(propertySet, declaration, context);
 }
 
 void CSSParser::parseDeclarationListForInspector(
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     const String& declaration,
     CSSParserObserver& observer) {
   CSSParserImpl::parseDeclarationListForInspector(declaration, context,
                                                   observer);
 }
 
-CSSSelectorList CSSParser::parseSelector(const CSSParserContext& context,
+CSSSelectorList CSSParser::parseSelector(const CSSParserContext* context,
                                          StyleSheetContents* styleSheetContents,
                                          const String& selector) {
   CSSTokenizer tokenizer(selector);
@@ -44,7 +44,7 @@
 }
 
 CSSSelectorList CSSParser::parsePageSelector(
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     StyleSheetContents* styleSheetContents,
     const String& selector) {
   CSSTokenizer tokenizer(selector);
@@ -52,14 +52,14 @@
                                           styleSheetContents);
 }
 
-StyleRuleBase* CSSParser::parseRule(const CSSParserContext& context,
+StyleRuleBase* CSSParser::parseRule(const CSSParserContext* context,
                                     StyleSheetContents* styleSheet,
                                     const String& rule) {
   return CSSParserImpl::parseRule(rule, context, styleSheet,
                                   CSSParserImpl::AllowImportRules);
 }
 
-void CSSParser::parseSheet(const CSSParserContext& context,
+void CSSParser::parseSheet(const CSSParserContext* context,
                            StyleSheetContents* styleSheet,
                            const String& text,
                            bool deferPropertyParsing) {
@@ -67,7 +67,7 @@
                                         deferPropertyParsing);
 }
 
-void CSSParser::parseSheetForInspector(const CSSParserContext& context,
+void CSSParser::parseSheetForInspector(const CSSParserContext* context,
                                        StyleSheetContents* styleSheet,
                                        const String& text,
                                        CSSParserObserver& observer) {
@@ -79,6 +79,15 @@
     MutableStylePropertySet* declaration,
     CSSPropertyID unresolvedProperty,
     const String& string,
+    bool important) {
+  return parseValue(declaration, unresolvedProperty, string, important,
+                    static_cast<StyleSheetContents*>(nullptr));
+}
+
+MutableStylePropertySet::SetResult CSSParser::parseValue(
+    MutableStylePropertySet* declaration,
+    CSSPropertyID unresolvedProperty,
+    const String& string,
     bool important,
     StyleSheetContents* styleSheet) {
   if (string.isEmpty()) {
@@ -97,10 +106,12 @@
         CSSProperty(resolvedProperty, *value, important));
     return MutableStylePropertySet::SetResult{didParse, didChange};
   }
-  CSSParserContext context(parserMode, nullptr);
+  CSSParserContext* context;
   if (styleSheet) {
-    context = styleSheet->parserContext();
-    context.setMode(parserMode);
+    context = CSSParserContext::create(styleSheet->parserContext(), nullptr);
+    context->setMode(parserMode);
+  } else {
+    context = CSSParserContext::create(parserMode);
   }
   return parseValue(declaration, unresolvedProperty, string, important,
                     context);
@@ -121,10 +132,12 @@
     return MutableStylePropertySet::SetResult{didParse, didChange};
   }
   CSSParserMode parserMode = declaration->cssParserMode();
-  CSSParserContext context(parserMode, nullptr);
+  CSSParserContext* context;
   if (styleSheet) {
-    context = styleSheet->parserContext();
-    context.setMode(parserMode);
+    context = CSSParserContext::create(styleSheet->parserContext(), nullptr);
+    context->setMode(parserMode);
+  } else {
+    context = CSSParserContext::create(parserMode);
   }
   return CSSParserImpl::parseVariableValue(declaration, propertyName, registry,
                                            value, important, context,
@@ -141,18 +154,18 @@
     CSSPropertyID unresolvedProperty,
     const String& string,
     bool important,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   return CSSParserImpl::parseValue(declaration, unresolvedProperty, string,
                                    important, context);
 }
 
 const CSSValue* CSSParser::parseSingleValue(CSSPropertyID propertyID,
                                             const String& string,
-                                            const CSSParserContext& context) {
+                                            const CSSParserContext* context) {
   if (string.isEmpty())
     return nullptr;
   if (CSSValue* value = CSSParserFastPaths::maybeParseValue(propertyID, string,
-                                                            context.mode()))
+                                                            context->mode()))
     return value;
   CSSTokenizer tokenizer(string);
   return CSSPropertyParser::parseSingleValue(propertyID, tokenizer.tokenRange(),
@@ -170,7 +183,7 @@
   return CSSParserImpl::parseKeyframeKeyList(keyList);
 }
 
-StyleRuleKeyframe* CSSParser::parseKeyframeRule(const CSSParserContext& context,
+StyleRuleKeyframe* CSSParser::parseKeyframeRule(const CSSParserContext* context,
                                                 const String& rule) {
   StyleRuleBase* keyframe = CSSParserImpl::parseRule(
       rule, context, nullptr, CSSParserImpl::KeyframeRules);
@@ -221,7 +234,7 @@
 const CSSValue* CSSParser::parseFontFaceDescriptor(
     CSSPropertyID propertyID,
     const String& propertyValue,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   StringBuilder builder;
   builder.append("@font-face { ");
   builder.append(getPropertyNameString(propertyID));
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParser.h b/third_party/WebKit/Source/core/css/parser/CSSParser.h
index 2c67b87..c9ace334 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParser.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSParser.h
@@ -30,20 +30,20 @@
 
  public:
   // As well as regular rules, allows @import and @namespace but not @charset
-  static StyleRuleBase* parseRule(const CSSParserContext&,
+  static StyleRuleBase* parseRule(const CSSParserContext*,
                                   StyleSheetContents*,
                                   const String&);
-  static void parseSheet(const CSSParserContext&,
+  static void parseSheet(const CSSParserContext*,
                          StyleSheetContents*,
                          const String&,
                          bool deferPropertyParsing = false);
-  static CSSSelectorList parseSelector(const CSSParserContext&,
+  static CSSSelectorList parseSelector(const CSSParserContext*,
                                        StyleSheetContents*,
                                        const String&);
-  static CSSSelectorList parsePageSelector(const CSSParserContext&,
+  static CSSSelectorList parsePageSelector(const CSSParserContext*,
                                            StyleSheetContents*,
                                            const String&);
-  static bool parseDeclarationList(const CSSParserContext&,
+  static bool parseDeclarationList(const CSSParserContext*,
                                    MutableStylePropertySet*,
                                    const String&);
 
@@ -51,6 +51,11 @@
       MutableStylePropertySet*,
       CSSPropertyID unresolvedProperty,
       const String&,
+      bool important);
+  static MutableStylePropertySet::SetResult parseValue(
+      MutableStylePropertySet*,
+      CSSPropertyID unresolvedProperty,
+      const String&,
       bool important,
       StyleSheetContents*);
 
@@ -68,17 +73,17 @@
   static const CSSValue* parseSingleValue(
       CSSPropertyID,
       const String&,
-      const CSSParserContext& = strictCSSParserContext());
+      const CSSParserContext* = strictCSSParserContext());
 
   static const CSSValue* parseFontFaceDescriptor(CSSPropertyID,
                                                  const String&,
-                                                 const CSSParserContext&);
+                                                 const CSSParserContext*);
 
   static ImmutableStylePropertySet* parseInlineStyleDeclaration(const String&,
                                                                 Element*);
 
   static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&);
-  static StyleRuleKeyframe* parseKeyframeRule(const CSSParserContext&,
+  static StyleRuleKeyframe* parseKeyframeRule(const CSSParserContext*,
                                               const String&);
 
   static bool parseSupportsCondition(const String&);
@@ -88,11 +93,11 @@
   static bool parseColor(Color&, const String&, bool strict = false);
   static bool parseSystemColor(Color&, const String&);
 
-  static void parseSheetForInspector(const CSSParserContext&,
+  static void parseSheetForInspector(const CSSParserContext*,
                                      StyleSheetContents*,
                                      const String&,
                                      CSSParserObserver&);
-  static void parseDeclarationListForInspector(const CSSParserContext&,
+  static void parseDeclarationListForInspector(const CSSParserContext*,
                                                const String&,
                                                CSSParserObserver&);
 
@@ -102,7 +107,7 @@
       CSSPropertyID unresolvedProperty,
       const String&,
       bool important,
-      const CSSParserContext&);
+      const CSSParserContext*);
 };
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserContext.cpp b/third_party/WebKit/Source/core/css/parser/CSSParserContext.cpp
index 66e3d2a8..cfd0007 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParserContext.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserContext.cpp
@@ -4,69 +4,115 @@
 
 #include "core/css/parser/CSSParserContext.h"
 
+#include "core/css/CSSStyleSheet.h"
+#include "core/css/StyleSheetContents.h"
 #include "core/frame/Settings.h"
 #include "core/frame/csp/ContentSecurityPolicy.h"
 #include "core/html/imports/HTMLImportsController.h"
 
 namespace blink {
 
-CSSParserContext::CSSParserContext(CSSParserMode mode,
-                                   UseCounter* useCounter,
-                                   SelectorProfile profile)
-    : m_mode(mode),
-      m_matchMode(mode),
-      m_profile(profile),
-      m_isHTMLDocument(false),
-      m_useLegacyBackgroundSizeShorthandBehavior(false),
-      m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy),
-      m_useCounter(useCounter) {}
-
-CSSParserContext::CSSParserContext(const Document& document,
-                                   UseCounter* useCounter,
-                                   const KURL& baseURL,
-                                   const String& charset,
-                                   SelectorProfile profile)
-    : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL),
-      m_charset(charset),
-      m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode),
-      m_profile(profile),
-      m_referrer(m_baseURL.strippedForUseAsReferrer(),
-                 document.getReferrerPolicy()),
-      m_isHTMLDocument(document.isHTMLDocument()),
-      m_useLegacyBackgroundSizeShorthandBehavior(
-          document.settings()
-              ? document.settings()
-                    ->getUseLegacyBackgroundSizeShorthandBehavior()
-              : false),
-      m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy),
-      m_useCounter(useCounter) {
-  if (ContentSecurityPolicy::shouldBypassMainWorld(&document))
-    m_shouldCheckContentSecurityPolicy = DoNotCheckContentSecurityPolicy;
-  else
-    m_shouldCheckContentSecurityPolicy = CheckContentSecurityPolicy;
-
-  if (HTMLImportsController* importsController = document.importsController()) {
-    m_matchMode = importsController->master()->inQuirksMode()
-                      ? HTMLQuirksMode
-                      : HTMLStandardMode;
-  } else {
-    m_matchMode = m_mode;
-  }
+// static
+CSSParserContext* CSSParserContext::createWithStyleSheet(
+    const CSSParserContext* other,
+    const CSSStyleSheet* styleSheet) {
+  return CSSParserContext::create(other, UseCounter::getFrom(styleSheet));
 }
 
-CSSParserContext::CSSParserContext(const CSSParserContext& other,
-                                   UseCounter* useCounter)
-    : m_baseURL(other.m_baseURL),
-      m_charset(other.m_charset),
-      m_mode(other.m_mode),
-      m_matchMode(other.m_matchMode),
-      m_profile(other.m_profile),
-      m_referrer(other.m_referrer),
-      m_isHTMLDocument(other.m_isHTMLDocument),
+// static
+CSSParserContext* CSSParserContext::createWithStyleSheetContents(
+    const CSSParserContext* other,
+    const StyleSheetContents* styleSheetContents) {
+  return CSSParserContext::create(other,
+                                  UseCounter::getFrom(styleSheetContents));
+}
+
+// static
+CSSParserContext* CSSParserContext::create(const CSSParserContext* other,
+                                           UseCounter* useCounter) {
+  return new CSSParserContext(
+      other->m_baseURL, other->m_charset, other->m_mode, other->m_matchMode,
+      other->m_profile, other->m_referrer, other->m_isHTMLDocument,
+      other->m_useLegacyBackgroundSizeShorthandBehavior,
+      other->m_shouldCheckContentSecurityPolicy, useCounter);
+}
+
+// static
+CSSParserContext* CSSParserContext::create(CSSParserMode mode,
+                                           SelectorProfile profile,
+                                           UseCounter* useCounter) {
+  return new CSSParserContext(KURL(), emptyString(), mode, mode, profile,
+                              Referrer(), false, false,
+                              DoNotCheckContentSecurityPolicy, useCounter);
+}
+
+// static
+CSSParserContext* CSSParserContext::create(const Document& document,
+                                           UseCounter* useCounter) {
+  return CSSParserContext::create(document, KURL(), emptyString(),
+                                  DynamicProfile, useCounter);
+}
+
+// static
+CSSParserContext* CSSParserContext::create(const Document& document,
+                                           const KURL& baseURLOverride,
+                                           const String& charset,
+                                           SelectorProfile profile,
+                                           UseCounter* useCounter) {
+  const KURL baseURL =
+      baseURLOverride.isNull() ? document.baseURL() : baseURLOverride;
+
+  CSSParserMode mode =
+      document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode;
+  CSSParserMode matchMode;
+  if (HTMLImportsController* importsController = document.importsController()) {
+    matchMode = importsController->master()->inQuirksMode() ? HTMLQuirksMode
+                                                            : HTMLStandardMode;
+  } else {
+    matchMode = mode;
+  }
+
+  const Referrer referrer(baseURL.strippedForUseAsReferrer(),
+                          document.getReferrerPolicy());
+
+  bool useLegacyBackgroundSizeShorthandBehavior =
+      document.settings()
+          ? document.settings()->getUseLegacyBackgroundSizeShorthandBehavior()
+          : false;
+
+  ContentSecurityPolicyDisposition policyDisposition;
+  if (ContentSecurityPolicy::shouldBypassMainWorld(&document))
+    policyDisposition = DoNotCheckContentSecurityPolicy;
+  else
+    policyDisposition = CheckContentSecurityPolicy;
+
+  return new CSSParserContext(baseURL, charset, mode, matchMode, profile,
+                              referrer, document.isHTMLDocument(),
+                              useLegacyBackgroundSizeShorthandBehavior,
+                              policyDisposition, useCounter);
+}
+
+CSSParserContext::CSSParserContext(
+    const KURL& baseURL,
+    const String& charset,
+    CSSParserMode mode,
+    CSSParserMode matchMode,
+    SelectorProfile profile,
+    const Referrer& referrer,
+    bool isHTMLDocument,
+    bool useLegacyBackgroundSizeShorthandBehavior,
+    ContentSecurityPolicyDisposition policyDisposition,
+    UseCounter* useCounter)
+    : m_baseURL(baseURL),
+      m_charset(charset),
+      m_mode(mode),
+      m_matchMode(matchMode),
+      m_profile(profile),
+      m_referrer(referrer),
+      m_isHTMLDocument(isHTMLDocument),
       m_useLegacyBackgroundSizeShorthandBehavior(
-          other.m_useLegacyBackgroundSizeShorthandBehavior),
-      m_shouldCheckContentSecurityPolicy(
-          other.m_shouldCheckContentSecurityPolicy),
+          useLegacyBackgroundSizeShorthandBehavior),
+      m_shouldCheckContentSecurityPolicy(policyDisposition),
       m_useCounter(useCounter) {}
 
 bool CSSParserContext::operator==(const CSSParserContext& other) const {
@@ -78,10 +124,10 @@
              other.m_useLegacyBackgroundSizeShorthandBehavior;
 }
 
-const CSSParserContext& strictCSSParserContext() {
+const CSSParserContext* strictCSSParserContext() {
   DEFINE_STATIC_LOCAL(CSSParserContext, strictContext,
-                      (HTMLStandardMode, nullptr));
-  return strictContext;
+                      (CSSParserContext::create(HTMLStandardMode)));
+  return &strictContext;
 }
 
 KURL CSSParserContext::completeURL(const String& url) const {
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserContext.h b/third_party/WebKit/Source/core/css/parser/CSSParserContext.h
index b96c3db..fbe7c94 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParserContext.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserContext.h
@@ -13,31 +13,41 @@
 
 namespace blink {
 
+class CSSStyleSheet;
 class Document;
+class StyleSheetContents;
 class UseCounter;
 
-class CORE_EXPORT CSSParserContext {
-  USING_FAST_MALLOC(CSSParserContext);
-
+class CORE_EXPORT CSSParserContext
+    : public GarbageCollectedFinalized<CSSParserContext> {
  public:
   // https://drafts.csswg.org/selectors/#profiles
   enum SelectorProfile { DynamicProfile, StaticProfile };
 
-  CSSParserContext(CSSParserMode,
-                   UseCounter*,
-                   SelectorProfile = DynamicProfile);
-  // FIXME: We shouldn't need the UseCounter argument as we could infer it from
-  // the Document but some callers want to disable use counting (e.g. the
-  // WebInspector).
-  CSSParserContext(const Document&,
-                   UseCounter*,
-                   const KURL& baseURL = KURL(),
-                   const String& charset = emptyString(),
-                   SelectorProfile = DynamicProfile);
+  // All three of these factories copy the context and override the current
+  // UseCounter handle.
+  static CSSParserContext* createWithStyleSheet(const CSSParserContext*,
+                                                const CSSStyleSheet*);
+  static CSSParserContext* createWithStyleSheetContents(
+      const CSSParserContext*,
+      const StyleSheetContents*);
   // FIXME: This constructor shouldn't exist if we properly piped the UseCounter
   // through the CSS subsystem. Currently the UseCounter life time is too crazy
   // and we need a way to override it.
-  CSSParserContext(const CSSParserContext&, UseCounter*);
+  static CSSParserContext* create(const CSSParserContext* other, UseCounter*);
+
+  static CSSParserContext* create(CSSParserMode,
+                                  SelectorProfile = DynamicProfile,
+                                  UseCounter* = nullptr);
+  // FIXME: We shouldn't need the UseCounter argument as we could infer it from
+  // the Document but some callers want to disable use counting (e.g. the
+  // WebInspector).
+  static CSSParserContext* create(const Document&, UseCounter*);
+  static CSSParserContext* create(const Document&,
+                                  const KURL& baseURLOverride = KURL(),
+                                  const String& charset = emptyString(),
+                                  SelectorProfile = DynamicProfile,
+                                  UseCounter* = nullptr);
 
   bool operator==(const CSSParserContext&) const;
   bool operator!=(const CSSParserContext& other) const {
@@ -73,12 +83,26 @@
   // This may return nullptr if counting is disabled.
   // See comments on constructors.
   UseCounter* useCounter() const { return m_useCounter; }
+  bool isUseCounterRecordingEnabled() const { return m_useCounter; }
 
   ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy() const {
     return m_shouldCheckContentSecurityPolicy;
   }
 
+  DEFINE_INLINE_TRACE() {}
+
  private:
+  CSSParserContext(const KURL& baseURL,
+                   const String& charset,
+                   CSSParserMode,
+                   CSSParserMode matchMode,
+                   SelectorProfile,
+                   const Referrer&,
+                   bool isHTMLDocument,
+                   bool useLegacyBackgroundSizeShorthandBehavior,
+                   ContentSecurityPolicyDisposition,
+                   UseCounter*);
+
   KURL m_baseURL;
   String m_charset;
   CSSParserMode m_mode;
@@ -92,8 +116,8 @@
   UseCounter* m_useCounter;
 };
 
-CORE_EXPORT const CSSParserContext& strictCSSParserContext();
+CORE_EXPORT const CSSParserContext* strictCSSParserContext();
 
 }  // namespace blink
 
-#endif  // CSSParserMode_h
+#endif  // CSSParserContext_h
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp
index a6549ff..a7d9ba7 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp
@@ -36,7 +36,7 @@
 
 namespace blink {
 
-CSSParserImpl::CSSParserImpl(const CSSParserContext& context,
+CSSParserImpl::CSSParserImpl(const CSSParserContext* context,
                              StyleSheetContents* styleSheet)
     : m_context(context),
       m_styleSheet(styleSheet),
@@ -47,7 +47,7 @@
     CSSPropertyID unresolvedProperty,
     const String& string,
     bool important,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSParserImpl parser(context);
   StyleRule::RuleType ruleType = StyleRule::Style;
   if (declaration->cssParserMode() == CSSViewportRuleMode)
@@ -72,7 +72,7 @@
     const PropertyRegistry* registry,
     const String& value,
     bool important,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     bool isAnimationTainted) {
   CSSParserImpl parser(context);
   CSSTokenizer tokenizer(value);
@@ -155,13 +155,13 @@
     const String& string,
     Element* element) {
   Document& document = element->document();
-  CSSParserContext context =
-      CSSParserContext(document.elementSheet().contents()->parserContext(),
-                       UseCounter::getFrom(&document));
+  CSSParserContext* context = CSSParserContext::create(
+      document.elementSheet().contents()->parserContext(),
+      UseCounter::getFrom(&document));
   CSSParserMode mode = element->isHTMLElement() && !document.inQuirksMode()
                            ? HTMLStandardMode
                            : HTMLQuirksMode;
-  context.setMode(mode);
+  context->setMode(mode);
   CSSParserImpl parser(context, document.elementSheet().contents());
   CSSTokenizer tokenizer(string);
   parser.consumeDeclarationList(tokenizer.tokenRange(), StyleRule::Style);
@@ -170,7 +170,7 @@
 
 bool CSSParserImpl::parseDeclarationList(MutableStylePropertySet* declaration,
                                          const String& string,
-                                         const CSSParserContext& context) {
+                                         const CSSParserContext* context) {
   CSSParserImpl parser(context);
   StyleRule::RuleType ruleType = StyleRule::Style;
   if (declaration->cssParserMode() == CSSViewportRuleMode)
@@ -194,7 +194,7 @@
 }
 
 StyleRuleBase* CSSParserImpl::parseRule(const String& string,
-                                        const CSSParserContext& context,
+                                        const CSSParserContext* context,
                                         StyleSheetContents* styleSheet,
                                         AllowedRulesType allowedRules) {
   CSSParserImpl parser(context, styleSheet);
@@ -217,12 +217,12 @@
 }
 
 void CSSParserImpl::parseStyleSheet(const String& string,
-                                    const CSSParserContext& context,
+                                    const CSSParserContext* context,
                                     StyleSheetContents* styleSheet,
                                     bool deferPropertyParsing) {
   TRACE_EVENT_BEGIN2("blink,blink_style", "CSSParserImpl::parseStyleSheet",
-                     "baseUrl", context.baseURL().getString().utf8(), "mode",
-                     context.mode());
+                     "baseUrl", context->baseURL().getString().utf8(), "mode",
+                     context->mode());
 
   TRACE_EVENT_BEGIN0("blink,blink_style",
                      "CSSParserImpl::parseStyleSheet.tokenize");
@@ -336,7 +336,7 @@
 
 void CSSParserImpl::parseDeclarationListForInspector(
     const String& declaration,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     CSSParserObserver& observer) {
   CSSParserImpl parser(context);
   CSSParserObserverWrapper wrapper(observer);
@@ -348,7 +348,7 @@
 }
 
 void CSSParserImpl::parseStyleSheetForInspector(const String& string,
-                                                const CSSParserContext& context,
+                                                const CSSParserContext* context,
                                                 StyleSheetContents* styleSheet,
                                                 CSSParserObserver& observer) {
   CSSParserImpl parser(context, styleSheet);
@@ -367,10 +367,10 @@
 
 StylePropertySet* CSSParserImpl::parseDeclarationListForLazyStyle(
     CSSParserTokenRange block,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSParserImpl parser(context);
   parser.consumeDeclarationList(std::move(block), StyleRule::Style);
-  return createStylePropertySet(parser.m_parsedProperties, context.mode());
+  return createStylePropertySet(parser.m_parsedProperties, context->mode());
 }
 
 static CSSParserImpl::AllowedRulesType computeNewAllowedRules(
@@ -452,8 +452,8 @@
 
   CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek());
   CSSAtRuleID id = cssAtRuleID(name);
-  if (id != CSSAtRuleInvalid && m_context.useCounter())
-    countAtRule(m_context.useCounter(), id);
+  if (id != CSSAtRuleInvalid && m_context->isUseCounterRecordingEnabled())
+    countAtRule(m_context->useCounter(), id);
 
   if (range.atEnd() || range.peek().type() == SemicolonToken) {
     range.consume();
@@ -641,7 +641,7 @@
     CSSParserTokenRange block) {
   // Allow @viewport rules from UA stylesheets even if the feature is disabled.
   if (!RuntimeEnabledFeatures::cssViewportEnabled() &&
-      !isUASheetBehavior(m_context.mode()))
+      !isUASheetBehavior(m_context->mode()))
     return nullptr;
 
   if (!prelude.atEnd())
@@ -701,8 +701,8 @@
   if (nameToken.type() == IdentToken) {
     name = nameToken.value().toString();
   } else if (nameToken.type() == StringToken && webkitPrefixed) {
-    if (m_context.useCounter())
-      m_context.useCounter()->count(UseCounter::QuotedKeyframesRule);
+    if (m_context->isUseCounterRecordingEnabled())
+      m_context->useCounter()->count(UseCounter::QuotedKeyframesRule);
     name = nameToken.value().toString();
   } else {
     return nullptr;  // Parse error; expected ident token in @keyframes header
@@ -746,7 +746,7 @@
 
   return StyleRulePage::create(
       std::move(selectorList),
-      createStylePropertySet(m_parsedProperties, m_context.mode()));
+      createStylePropertySet(m_parsedProperties, m_context->mode()));
 }
 
 void CSSParserImpl::consumeApplyRule(CSSParserTokenRange prelude) {
@@ -777,7 +777,7 @@
   consumeDeclarationList(block, StyleRule::Keyframe);
   return StyleRuleKeyframe::create(
       std::move(keyList),
-      createStylePropertySet(m_parsedProperties, m_context.mode()));
+      createStylePropertySet(m_parsedProperties, m_context->mode()));
 }
 
 static void observeSelectors(CSSParserObserverWrapper& wrapper,
@@ -823,7 +823,7 @@
 
   return StyleRule::create(
       std::move(selectorList),
-      createStylePropertySet(m_parsedProperties, m_context.mode()));
+      createStylePropertySet(m_parsedProperties, m_context->mode()));
 }
 
 void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range,
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.h b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.h
index 219ab0d..4310671 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.h
@@ -41,7 +41,7 @@
   WTF_MAKE_NONCOPYABLE(CSSParserImpl);
 
  public:
-  CSSParserImpl(const CSSParserContext&, StyleSheetContents* = nullptr);
+  CSSParserImpl(const CSSParserContext*, StyleSheetContents* = nullptr);
 
   enum AllowedRulesType {
     // As per css-syntax, css-cascade and css-namespaces, @charset rules
@@ -62,26 +62,26 @@
                                                        CSSPropertyID,
                                                        const String&,
                                                        bool important,
-                                                       const CSSParserContext&);
+                                                       const CSSParserContext*);
   static MutableStylePropertySet::SetResult parseVariableValue(
       MutableStylePropertySet*,
       const AtomicString& propertyName,
       const PropertyRegistry*,
       const String&,
       bool important,
-      const CSSParserContext&,
+      const CSSParserContext*,
       bool isAnimationTainted);
   static ImmutableStylePropertySet* parseInlineStyleDeclaration(const String&,
                                                                 Element*);
   static bool parseDeclarationList(MutableStylePropertySet*,
                                    const String&,
-                                   const CSSParserContext&);
+                                   const CSSParserContext*);
   static StyleRuleBase* parseRule(const String&,
-                                  const CSSParserContext&,
+                                  const CSSParserContext*,
                                   StyleSheetContents*,
                                   AllowedRulesType);
   static void parseStyleSheet(const String&,
-                              const CSSParserContext&,
+                              const CSSParserContext*,
                               StyleSheetContents*,
                               bool deferPropertyParsing = false);
   static CSSSelectorList parsePageSelector(CSSParserTokenRange,
@@ -94,16 +94,16 @@
   bool supportsDeclaration(CSSParserTokenRange&);
 
   static void parseDeclarationListForInspector(const String&,
-                                               const CSSParserContext&,
+                                               const CSSParserContext*,
                                                CSSParserObserver&);
   static void parseStyleSheetForInspector(const String&,
-                                          const CSSParserContext&,
+                                          const CSSParserContext*,
                                           StyleSheetContents*,
                                           CSSParserObserver&);
 
   static StylePropertySet* parseDeclarationListForLazyStyle(
       CSSParserTokenRange block,
-      const CSSParserContext&);
+      const CSSParserContext*);
 
  private:
   enum RuleListType { TopLevelRuleList, RegularRuleList, KeyframesRuleList };
@@ -157,8 +157,8 @@
   // FIXME: Can we build StylePropertySets directly?
   // FIXME: Investigate using a smaller inline buffer
   HeapVector<CSSProperty, 256> m_parsedProperties;
-  const CSSParserContext& m_context;
 
+  Member<const CSSParserContext> m_context;
   Member<StyleSheetContents> m_styleSheet;
 
   // For the inspector
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
index d29bce6..b7f9ff35 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
@@ -54,7 +54,7 @@
 
 CSSPropertyParser::CSSPropertyParser(
     const CSSParserTokenRange& range,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     HeapVector<CSSProperty, 256>* parsedProperties)
     : m_range(range), m_context(context), m_parsedProperties(parsedProperties) {
   m_range.consumeWhitespace();
@@ -98,7 +98,7 @@
     CSSPropertyID unresolvedProperty,
     bool important,
     const CSSParserTokenRange& range,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     HeapVector<CSSProperty, 256>& parsedProperties,
     StyleRule::RuleType ruleType) {
   int parsedPropertiesSize = parsedProperties.size();
@@ -109,7 +109,7 @@
 
   if (ruleType == StyleRule::Viewport) {
     parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() ||
-                    isUASheetBehavior(context.mode())) &&
+                    isUASheetBehavior(context->mode())) &&
                    parser.parseViewportDescriptor(resolvedProperty, important);
   } else if (ruleType == StyleRule::FontFace) {
     parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty);
@@ -118,8 +118,8 @@
   }
 
   // This doesn't count UA style sheets
-  if (parseSuccess && context.useCounter())
-    context.useCounter()->count(context.mode(), unresolvedProperty);
+  if (parseSuccess && context->isUseCounterRecordingEnabled())
+    context->useCounter()->count(context->mode(), unresolvedProperty);
 
   if (!parseSuccess)
     parsedProperties.shrink(parsedPropertiesSize);
@@ -130,7 +130,7 @@
 const CSSValue* CSSPropertyParser::parseSingleValue(
     CSSPropertyID property,
     const CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSPropertyParser parser(range, context, nullptr);
   const CSSValue* value = parser.parseSingleValue(property);
   if (!value || !parser.m_range.atEnd())
@@ -756,25 +756,25 @@
 }
 
 static bool validWidthOrHeightKeyword(CSSValueID id,
-                                      const CSSParserContext& context) {
+                                      const CSSParserContext* context) {
   if (id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent ||
       id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent ||
       id == CSSValueMinContent || id == CSSValueMaxContent ||
       id == CSSValueFitContent) {
-    if (context.useCounter()) {
+    if (context->isUseCounterRecordingEnabled()) {
+      UseCounter* useCounter = context->useCounter();
       switch (id) {
         case CSSValueWebkitMinContent:
-          context.useCounter()->count(UseCounter::CSSValuePrefixedMinContent);
+          useCounter->count(UseCounter::CSSValuePrefixedMinContent);
           break;
         case CSSValueWebkitMaxContent:
-          context.useCounter()->count(UseCounter::CSSValuePrefixedMaxContent);
+          useCounter->count(UseCounter::CSSValuePrefixedMaxContent);
           break;
         case CSSValueWebkitFillAvailable:
-          context.useCounter()->count(
-              UseCounter::CSSValuePrefixedFillAvailable);
+          useCounter->count(UseCounter::CSSValuePrefixedFillAvailable);
           break;
         case CSSValueWebkitFitContent:
-          context.useCounter()->count(UseCounter::CSSValuePrefixedFitContent);
+          useCounter->count(UseCounter::CSSValuePrefixedFitContent);
           break;
         default:
           break;
@@ -787,23 +787,23 @@
 
 static CSSValue* consumeMaxWidthOrHeight(
     CSSParserTokenRange& range,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     UnitlessQuirk unitless = UnitlessQuirk::Forbid) {
   if (range.peek().id() == CSSValueNone ||
       validWidthOrHeightKeyword(range.peek().id(), context))
     return consumeIdent(range);
-  return consumeLengthOrPercent(range, context.mode(), ValueRangeNonNegative,
+  return consumeLengthOrPercent(range, context->mode(), ValueRangeNonNegative,
                                 unitless);
 }
 
 static CSSValue* consumeWidthOrHeight(
     CSSParserTokenRange& range,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     UnitlessQuirk unitless = UnitlessQuirk::Forbid) {
   if (range.peek().id() == CSSValueAuto ||
       validWidthOrHeightKeyword(range.peek().id(), context))
     return consumeIdent(range);
-  return consumeLengthOrPercent(range, context.mode(), ValueRangeNonNegative,
+  return consumeLengthOrPercent(range, context->mode(), ValueRangeNonNegative,
                                 unitless);
 }
 
@@ -951,15 +951,15 @@
 }
 
 static CSSValue* consumeAnimationName(CSSParserTokenRange& range,
-                                      const CSSParserContext& context,
+                                      const CSSParserContext* context,
                                       bool allowQuotedName) {
   if (range.peek().id() == CSSValueNone)
     return consumeIdent(range);
 
   if (allowQuotedName && range.peek().type() == StringToken) {
     // Legacy support for strings in prefixed animations.
-    if (context.useCounter())
-      context.useCounter()->count(UseCounter::QuotedAnimationName);
+    if (context->isUseCounterRecordingEnabled())
+      context->useCounter()->count(UseCounter::QuotedAnimationName);
 
     const CSSParserToken& token = range.consumeIncludingWhitespace();
     if (equalIgnoringASCIICase(token.value(), "none"))
@@ -1059,7 +1059,7 @@
 
 static CSSValue* consumeAnimationValue(CSSPropertyID property,
                                        CSSParserTokenRange& range,
-                                       const CSSParserContext& context,
+                                       const CSSParserContext* context,
                                        bool useLegacyParsing) {
   switch (property) {
     case CSSPropertyAnimationDelay:
@@ -1106,7 +1106,7 @@
 static CSSValueList* consumeAnimationPropertyList(
     CSSPropertyID property,
     CSSParserTokenRange& range,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     bool useLegacyParsing) {
   CSSValueList* list = CSSValueList::createCommaSeparated();
   do {
@@ -1242,7 +1242,7 @@
 
 static CSSFunctionValue* consumeFilterFunction(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSValueID filterType = range.peek().functionId();
   if (filterType < CSSValueInvert || filterType > CSSValueDropShadow)
     return nullptr;
@@ -1251,11 +1251,11 @@
   CSSValue* parsedValue = nullptr;
 
   if (filterType == CSSValueDropShadow) {
-    parsedValue = parseSingleShadow(args, context.mode(), false, false);
+    parsedValue = parseSingleShadow(args, context->mode(), false, false);
   } else {
     if (args.atEnd()) {
-      if (context.useCounter())
-        context.useCounter()->count(UseCounter::CSSFilterFunctionNoArguments);
+      if (context->isUseCounterRecordingEnabled())
+        context->useCounter()->count(UseCounter::CSSFilterFunctionNoArguments);
       return filterValue;
     }
     if (filterType == CSSValueBrightness) {
@@ -1292,7 +1292,7 @@
 }
 
 static CSSValue* consumeFilter(CSSParserTokenRange& range,
-                               const CSSParserContext& context) {
+                               const CSSParserContext* context) {
   if (range.peek().id() == CSSValueNone)
     return consumeIdent(range);
 
@@ -1417,26 +1417,27 @@
 }
 
 static CSSValue* consumeOffsetPath(CSSParserTokenRange& range,
-                                   UseCounter* useCounter,
+                                   const CSSParserContext* context,
                                    bool isMotionPath) {
   CSSValue* value = consumePathOrNone(range);
 
   // Count when we receive a valid path other than 'none'.
-  if (useCounter && value && !value->isIdentifierValue()) {
-    if (isMotionPath)
-      useCounter->count(UseCounter::CSSMotionInEffect);
-    else
-      useCounter->count(UseCounter::CSSOffsetInEffect);
+  if (context->isUseCounterRecordingEnabled() && value &&
+      !value->isIdentifierValue()) {
+    if (isMotionPath) {
+      context->useCounter()->count(UseCounter::CSSMotionInEffect);
+    } else {
+      context->useCounter()->count(UseCounter::CSSOffsetInEffect);
+    }
   }
   return value;
 }
 
 // offset: <offset-path> <offset-distance> <offset-rotation>
 bool CSSPropertyParser::consumeOffsetShorthand(bool important) {
-  const CSSValue* offsetPath =
-      consumeOffsetPath(m_range, m_context.useCounter(), false);
+  const CSSValue* offsetPath = consumeOffsetPath(m_range, m_context, false);
   const CSSValue* offsetDistance =
-      consumeLengthOrPercent(m_range, m_context.mode(), ValueRangeAll);
+      consumeLengthOrPercent(m_range, m_context->mode(), ValueRangeAll);
   const CSSValue* offsetRotation = consumeOffsetRotate(m_range);
   if (!offsetPath || !offsetDistance || !offsetRotation || !m_range.atEnd())
     return false;
@@ -1545,17 +1546,17 @@
 }
 
 static bool consumePerspective(CSSParserTokenRange& args,
-                               const CSSParserContext& context,
+                               const CSSParserContext* context,
                                CSSFunctionValue*& transformValue,
                                bool useLegacyParsing) {
   CSSPrimitiveValue* parsedValue =
-      consumeLength(args, context.mode(), ValueRangeNonNegative);
+      consumeLength(args, context->mode(), ValueRangeNonNegative);
   if (!parsedValue && useLegacyParsing) {
     double perspective;
     if (!consumeNumberRaw(args, perspective) || perspective < 0)
       return false;
-    if (context.useCounter()) {
-      context.useCounter()->count(
+    if (context->isUseCounterRecordingEnabled()) {
+      context->useCounter()->count(
           UseCounter::UnitlessPerspectiveInTransformProperty);
     }
     parsedValue = CSSPrimitiveValue::create(
@@ -1568,7 +1569,7 @@
 }
 
 static CSSValue* consumeTransformValue(CSSParserTokenRange& range,
-                                       const CSSParserContext& context,
+                                       const CSSParserContext* context,
                                        bool useLegacyParsing) {
   CSSValueID functionId = range.peek().functionId();
   if (functionId == CSSValueInvalid)
@@ -1618,20 +1619,21 @@
     case CSSValueTranslateX:
     case CSSValueTranslateY:
     case CSSValueTranslate:
-      parsedValue = consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+      parsedValue =
+          consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
       if (!parsedValue)
         return nullptr;
       if (functionId == CSSValueTranslate &&
           consumeCommaIncludingWhitespace(args)) {
         transformValue->append(*parsedValue);
         parsedValue =
-            consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+            consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
         if (!parsedValue)
           return nullptr;
       }
       break;
     case CSSValueTranslateZ:
-      parsedValue = consumeLength(args, context.mode(), ValueRangeAll);
+      parsedValue = consumeLength(args, context->mode(), ValueRangeAll);
       break;
     case CSSValueMatrix:
     case CSSValueMatrix3d:
@@ -1652,7 +1654,7 @@
         return nullptr;
       break;
     case CSSValueTranslate3d:
-      if (!consumeTranslate3d(args, context.mode(), transformValue))
+      if (!consumeTranslate3d(args, context->mode(), transformValue))
         return nullptr;
       break;
     default:
@@ -1666,7 +1668,7 @@
 }
 
 static CSSValue* consumeTransform(CSSParserTokenRange& range,
-                                  const CSSParserContext& context,
+                                  const CSSParserContext* context,
                                   bool useLegacyParsing) {
   if (range.peek().id() == CSSValueNone)
     return consumeIdent(range);
@@ -1775,7 +1777,7 @@
 }
 
 static CSSValue* consumeCursor(CSSParserTokenRange& range,
-                               const CSSParserContext& context,
+                               const CSSParserContext* context,
                                bool inQuirksMode) {
   CSSValueList* list = nullptr;
   while (CSSValue* image = consumeImage(range, context,
@@ -1801,11 +1803,11 @@
   }
 
   CSSValueID id = range.peek().id();
-  if (!range.atEnd() && context.useCounter()) {
+  if (!range.atEnd() && context->isUseCounterRecordingEnabled()) {
     if (id == CSSValueWebkitZoomIn)
-      context.useCounter()->count(UseCounter::PrefixedCursorZoomIn);
+      context->useCounter()->count(UseCounter::PrefixedCursorZoomIn);
     else if (id == CSSValueWebkitZoomOut)
-      context.useCounter()->count(UseCounter::PrefixedCursorZoomOut);
+      context->useCounter()->count(UseCounter::PrefixedCursorZoomOut);
   }
   CSSValue* cursorType = nullptr;
   if (id == CSSValueHand) {
@@ -1827,7 +1829,7 @@
 }
 
 static CSSValue* consumeAttr(CSSParserTokenRange args,
-                             const CSSParserContext& context) {
+                             const CSSParserContext* context) {
   if (args.peek().type() != IdentToken)
     return nullptr;
 
@@ -1837,7 +1839,7 @@
     return nullptr;
 
   // TODO(esprehn): This should be lowerASCII().
-  if (context.isHTMLDocument())
+  if (context->isHTMLDocument())
     attrName = attrName.lower();
 
   CSSFunctionValue* attrValue = CSSFunctionValue::create(CSSValueAttr);
@@ -1879,7 +1881,7 @@
 }
 
 static CSSValue* consumeContent(CSSParserTokenRange& range,
-                                const CSSParserContext& context) {
+                                const CSSParserContext* context) {
   if (identMatches<CSSValueNone, CSSValueNormal>(range.peek().id()))
     return consumeIdent(range);
 
@@ -1910,19 +1912,19 @@
 }
 
 static CSSValue* consumePerspective(CSSParserTokenRange& range,
-                                    const CSSParserContext& context,
+                                    const CSSParserContext* context,
                                     CSSPropertyID unresolvedProperty) {
   if (range.peek().id() == CSSValueNone)
     return consumeIdent(range);
   CSSPrimitiveValue* parsedValue =
-      consumeLength(range, context.mode(), ValueRangeAll);
+      consumeLength(range, context->mode(), ValueRangeAll);
   if (!parsedValue &&
       (unresolvedProperty == CSSPropertyAliasWebkitPerspective)) {
     double perspective;
     if (!consumeNumberRaw(range, perspective))
       return nullptr;
-    if (context.useCounter()) {
-      context.useCounter()->count(
+    if (context->isUseCounterRecordingEnabled()) {
+      context->useCounter()->count(
           UseCounter::UnitlessPerspectiveInPerspectiveProperty);
     }
     parsedValue = CSSPrimitiveValue::create(
@@ -1985,16 +1987,16 @@
 
 static CSSBasicShapeCircleValue* consumeBasicShapeCircle(
     CSSParserTokenRange& args,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   // spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
   // circle( [<shape-radius>]? [at <position>]? )
   CSSBasicShapeCircleValue* shape = CSSBasicShapeCircleValue::create();
-  if (CSSValue* radius = consumeShapeRadius(args, context.mode()))
+  if (CSSValue* radius = consumeShapeRadius(args, context->mode()))
     shape->setRadius(radius);
   if (consumeIdent<CSSValueAt>(args)) {
     CSSValue* centerX = nullptr;
     CSSValue* centerY = nullptr;
-    if (!consumePosition(args, context.mode(), UnitlessQuirk::Forbid, centerX,
+    if (!consumePosition(args, context->mode(), UnitlessQuirk::Forbid, centerX,
                          centerY))
       return nullptr;
     shape->setCenterX(centerX);
@@ -2005,19 +2007,19 @@
 
 static CSSBasicShapeEllipseValue* consumeBasicShapeEllipse(
     CSSParserTokenRange& args,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   // spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
   // ellipse( [<shape-radius>{2}]? [at <position>]? )
   CSSBasicShapeEllipseValue* shape = CSSBasicShapeEllipseValue::create();
-  if (CSSValue* radiusX = consumeShapeRadius(args, context.mode())) {
+  if (CSSValue* radiusX = consumeShapeRadius(args, context->mode())) {
     shape->setRadiusX(radiusX);
-    if (CSSValue* radiusY = consumeShapeRadius(args, context.mode()))
+    if (CSSValue* radiusY = consumeShapeRadius(args, context->mode()))
       shape->setRadiusY(radiusY);
   }
   if (consumeIdent<CSSValueAt>(args)) {
     CSSValue* centerX = nullptr;
     CSSValue* centerY = nullptr;
-    if (!consumePosition(args, context.mode(), UnitlessQuirk::Forbid, centerX,
+    if (!consumePosition(args, context->mode(), UnitlessQuirk::Forbid, centerX,
                          centerY))
       return nullptr;
     shape->setCenterX(centerX);
@@ -2028,7 +2030,7 @@
 
 static CSSBasicShapePolygonValue* consumeBasicShapePolygon(
     CSSParserTokenRange& args,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSBasicShapePolygonValue* shape = CSSBasicShapePolygonValue::create();
   if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
     shape->setWindRule(args.consumeIncludingWhitespace().id() == CSSValueEvenodd
@@ -2040,11 +2042,11 @@
 
   do {
     CSSPrimitiveValue* xLength =
-        consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+        consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
     if (!xLength)
       return nullptr;
     CSSPrimitiveValue* yLength =
-        consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+        consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
     if (!yLength)
       return nullptr;
     shape->appendPoint(xLength, yLength);
@@ -2109,20 +2111,20 @@
 
 static CSSBasicShapeInsetValue* consumeBasicShapeInset(
     CSSParserTokenRange& args,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSBasicShapeInsetValue* shape = CSSBasicShapeInsetValue::create();
   CSSPrimitiveValue* top =
-      consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+      consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
   if (!top)
     return nullptr;
   CSSPrimitiveValue* right =
-      consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+      consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
   CSSPrimitiveValue* bottom = nullptr;
   CSSPrimitiveValue* left = nullptr;
   if (right) {
-    bottom = consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+    bottom = consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
     if (bottom)
-      left = consumeLengthOrPercent(args, context.mode(), ValueRangeAll);
+      left = consumeLengthOrPercent(args, context->mode(), ValueRangeAll);
   }
   if (left)
     shape->updateShapeSize4Values(top, right, bottom, left);
@@ -2136,7 +2138,7 @@
   if (consumeIdent<CSSValueRound>(args)) {
     CSSValue* horizontalRadii[4] = {0};
     CSSValue* verticalRadii[4] = {0};
-    if (!consumeRadii(horizontalRadii, verticalRadii, args, context.mode(),
+    if (!consumeRadii(horizontalRadii, verticalRadii, args, context->mode(),
                       false))
       return nullptr;
     shape->setTopLeftRadius(
@@ -2156,7 +2158,7 @@
 }
 
 static CSSValue* consumeBasicShape(CSSParserTokenRange& range,
-                                   const CSSParserContext& context) {
+                                   const CSSParserContext* context) {
   CSSValue* shape = nullptr;
   if (range.peek().type() != FunctionToken)
     return nullptr;
@@ -2178,7 +2180,7 @@
 }
 
 static CSSValue* consumeClipPath(CSSParserTokenRange& range,
-                                 const CSSParserContext& context) {
+                                 const CSSParserContext* context) {
   if (range.peek().id() == CSSValueNone)
     return consumeIdent(range);
   if (CSSURIValue* url = consumeUrl(range))
@@ -2187,7 +2189,7 @@
 }
 
 static CSSValue* consumeShapeOutside(CSSParserTokenRange& range,
-                                     const CSSParserContext& context) {
+                                     const CSSParserContext* context) {
   if (CSSValue* imageValue = consumeImageOrNone(range, context))
     return imageValue;
   CSSValueList* list = CSSValueList::createSpaceSeparated();
@@ -2349,7 +2351,7 @@
 
 static bool consumeBorderImageComponents(CSSPropertyID property,
                                          CSSParserTokenRange& range,
-                                         const CSSParserContext& context,
+                                         const CSSParserContext* context,
                                          CSSValue*& source,
                                          CSSValue*& slice,
                                          CSSValue*& width,
@@ -2392,7 +2394,7 @@
 
 static CSSValue* consumeWebkitBorderImage(CSSPropertyID property,
                                           CSSParserTokenRange& range,
-                                          const CSSParserContext& context) {
+                                          const CSSParserContext* context) {
   CSSValue* source = nullptr;
   CSSValue* slice = nullptr;
   CSSValue* width = nullptr;
@@ -2405,7 +2407,7 @@
 }
 
 static CSSValue* consumeReflect(CSSParserTokenRange& range,
-                                const CSSParserContext& context) {
+                                const CSSParserContext* context) {
   CSSIdentifierValue* direction =
       consumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>(
           range);
@@ -2416,7 +2418,7 @@
   if (range.atEnd()) {
     offset = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pixels);
   } else {
-    offset = consumeLengthOrPercent(range, context.mode(), ValueRangeAll,
+    offset = consumeLengthOrPercent(range, context->mode(), ValueRangeAll,
                                     UnitlessQuirk::Forbid);
     if (!offset)
       return nullptr;
@@ -2471,7 +2473,7 @@
 
 static CSSValue* consumePrefixedBackgroundBox(CSSPropertyID property,
                                               CSSParserTokenRange& range,
-                                              const CSSParserContext& context) {
+                                              const CSSParserContext* context) {
   // The values 'border', 'padding' and 'content' are deprecated and do not
   // apply to the version of the property that has the -webkit- prefix removed.
   if (CSSValue* value =
@@ -2532,7 +2534,7 @@
 
 static CSSValue* consumeBackgroundComponent(CSSPropertyID unresolvedProperty,
                                             CSSParserTokenRange& range,
-                                            const CSSParserContext& context) {
+                                            const CSSParserContext* context) {
   switch (unresolvedProperty) {
     case CSSPropertyBackgroundClip:
       return consumeBackgroundBox(range);
@@ -2556,16 +2558,16 @@
       return consumeImageOrNone(range, context);
     case CSSPropertyBackgroundPositionX:
     case CSSPropertyWebkitMaskPositionX:
-      return consumePositionX(range, context.mode());
+      return consumePositionX(range, context->mode());
     case CSSPropertyBackgroundPositionY:
     case CSSPropertyWebkitMaskPositionY:
-      return consumePositionY(range, context.mode());
+      return consumePositionY(range, context->mode());
     case CSSPropertyBackgroundSize:
     case CSSPropertyAliasWebkitBackgroundSize:
     case CSSPropertyWebkitMaskSize:
-      return consumeBackgroundSize(unresolvedProperty, range, context.mode());
+      return consumeBackgroundSize(unresolvedProperty, range, context->mode());
     case CSSPropertyBackgroundColor:
-      return consumeColor(range, context.mode());
+      return consumeColor(range, context->mode());
     default:
       break;
   };
@@ -2589,7 +2591,7 @@
 static CSSValue* consumeCommaSeparatedBackgroundComponent(
     CSSPropertyID unresolvedProperty,
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSValue* result = nullptr;
   do {
     CSSValue* value =
@@ -3072,38 +3074,41 @@
 }
 
 static void countKeywordOnlyPropertyUsage(CSSPropertyID property,
-                                          UseCounter* counter,
+                                          const CSSParserContext* context,
                                           CSSValueID valueID) {
-  if (!counter)
+  if (!context->isUseCounterRecordingEnabled())
     return;
   switch (property) {
-    case CSSPropertyWebkitAppearance:
+    case CSSPropertyWebkitAppearance: {
+      UseCounter::Feature feature;
       if (valueID == CSSValueNone) {
-        counter->count(UseCounter::CSSValueAppearanceNone);
+        feature = UseCounter::CSSValueAppearanceNone;
       } else {
-        counter->count(UseCounter::CSSValueAppearanceNotNone);
+        feature = UseCounter::CSSValueAppearanceNotNone;
         if (valueID == CSSValueButton)
-          counter->count(UseCounter::CSSValueAppearanceButton);
+          feature = UseCounter::CSSValueAppearanceButton;
         else if (valueID == CSSValueCaret)
-          counter->count(UseCounter::CSSValueAppearanceCaret);
+          feature = UseCounter::CSSValueAppearanceCaret;
         else if (valueID == CSSValueCheckbox)
-          counter->count(UseCounter::CSSValueAppearanceCheckbox);
+          feature = UseCounter::CSSValueAppearanceCheckbox;
         else if (valueID == CSSValueMenulist)
-          counter->count(UseCounter::CSSValueAppearanceMenulist);
+          feature = UseCounter::CSSValueAppearanceMenulist;
         else if (valueID == CSSValueMenulistButton)
-          counter->count(UseCounter::CSSValueAppearanceMenulistButton);
+          feature = UseCounter::CSSValueAppearanceMenulistButton;
         else if (valueID == CSSValueListbox)
-          counter->count(UseCounter::CSSValueAppearanceListbox);
+          feature = UseCounter::CSSValueAppearanceListbox;
         else if (valueID == CSSValueRadio)
-          counter->count(UseCounter::CSSValueAppearanceRadio);
+          feature = UseCounter::CSSValueAppearanceRadio;
         else if (valueID == CSSValueSearchfield)
-          counter->count(UseCounter::CSSValueAppearanceSearchField);
+          feature = UseCounter::CSSValueAppearanceSearchField;
         else if (valueID == CSSValueTextfield)
-          counter->count(UseCounter::CSSValueAppearanceTextField);
+          feature = UseCounter::CSSValueAppearanceTextField;
         else
-          counter->count(UseCounter::CSSValueAppearanceOthers);
+          feature = UseCounter::CSSValueAppearanceOthers;
       }
+      context->useCounter()->count(feature);
       break;
+    }
 
     default:
       break;
@@ -3116,10 +3121,9 @@
   CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
   if (CSSParserFastPaths::isKeywordPropertyID(property)) {
     if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(
-            property, m_range.peek().id(), m_context.mode()))
+            property, m_range.peek().id(), m_context->mode()))
       return nullptr;
-    countKeywordOnlyPropertyUsage(property, m_context.useCounter(),
-                                  m_range.peek().id());
+    countKeywordOnlyPropertyUsage(property, m_context, m_range.peek().id());
     return consumeIdent(m_range);
   }
 
@@ -3152,28 +3156,28 @@
       return consumeFontWeight(m_range);
     case CSSPropertyLetterSpacing:
     case CSSPropertyWordSpacing:
-      return consumeSpacing(m_range, m_context.mode());
+      return consumeSpacing(m_range, m_context->mode());
     case CSSPropertyTabSize:
-      return consumeTabSize(m_range, m_context.mode());
+      return consumeTabSize(m_range, m_context->mode());
     case CSSPropertyTextSizeAdjust:
-      return consumeTextSizeAdjust(m_range, m_context.mode());
+      return consumeTextSizeAdjust(m_range, m_context->mode());
     case CSSPropertyFontSize:
-      return consumeFontSize(m_range, m_context.mode(), UnitlessQuirk::Allow);
+      return consumeFontSize(m_range, m_context->mode(), UnitlessQuirk::Allow);
     case CSSPropertyLineHeight:
-      return consumeLineHeight(m_range, m_context.mode());
+      return consumeLineHeight(m_range, m_context->mode());
     case CSSPropertyScale:
       return consumeScale(m_range);
     case CSSPropertyWebkitBorderHorizontalSpacing:
     case CSSPropertyWebkitBorderVerticalSpacing:
-      return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative);
+      return consumeLength(m_range, m_context->mode(), ValueRangeNonNegative);
     case CSSPropertyCounterIncrement:
     case CSSPropertyCounterReset:
       return consumeCounter(m_range,
                             property == CSSPropertyCounterIncrement ? 1 : 0);
     case CSSPropertySnapHeight:
-      return consumeSnapHeight(m_range, m_context.mode());
+      return consumeSnapHeight(m_range, m_context->mode());
     case CSSPropertyTextIndent:
-      return consumeTextIndent(m_range, m_context.mode());
+      return consumeTextIndent(m_range, m_context->mode());
     case CSSPropertyMaxWidth:
     case CSSPropertyMaxHeight:
       return consumeMaxWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
@@ -3204,33 +3208,33 @@
     case CSSPropertyLeft:
     case CSSPropertyRight:
     case CSSPropertyTop:
-      return consumeMarginOrOffset(m_range, m_context.mode(),
+      return consumeMarginOrOffset(m_range, m_context->mode(),
                                    UnitlessQuirk::Allow);
     case CSSPropertyWebkitMarginStart:
     case CSSPropertyWebkitMarginEnd:
     case CSSPropertyWebkitMarginBefore:
     case CSSPropertyWebkitMarginAfter:
-      return consumeMarginOrOffset(m_range, m_context.mode(),
+      return consumeMarginOrOffset(m_range, m_context->mode(),
                                    UnitlessQuirk::Forbid);
     case CSSPropertyPaddingTop:
     case CSSPropertyPaddingRight:
     case CSSPropertyPaddingBottom:
     case CSSPropertyPaddingLeft:
-      return consumeLengthOrPercent(m_range, m_context.mode(),
+      return consumeLengthOrPercent(m_range, m_context->mode(),
                                     ValueRangeNonNegative,
                                     UnitlessQuirk::Allow);
     case CSSPropertyClip:
-      return consumeClip(m_range, m_context.mode());
+      return consumeClip(m_range, m_context->mode());
     case CSSPropertyTouchAction:
       return consumeTouchAction(m_range);
     case CSSPropertyScrollSnapDestination:
     case CSSPropertyObjectPosition:
     case CSSPropertyPerspectiveOrigin:
-      return consumePosition(m_range, m_context.mode(), UnitlessQuirk::Forbid);
+      return consumePosition(m_range, m_context->mode(), UnitlessQuirk::Forbid);
     case CSSPropertyWebkitLineClamp:
       return consumeLineClamp(m_range);
     case CSSPropertyWebkitFontSizeDelta:
-      return consumeLength(m_range, m_context.mode(), ValueRangeAll,
+      return consumeLength(m_range, m_context->mode(), ValueRangeAll,
                            UnitlessQuirk::Allow);
     case CSSPropertyWebkitHyphenateCharacter:
     case CSSPropertyWebkitLocale:
@@ -3258,10 +3262,10 @@
           unresolvedProperty == CSSPropertyAliasWebkitAnimationName);
     case CSSPropertyGridColumnGap:
     case CSSPropertyGridRowGap:
-      return consumeLengthOrPercent(m_range, m_context.mode(),
+      return consumeLengthOrPercent(m_range, m_context->mode(),
                                     ValueRangeNonNegative);
     case CSSPropertyShapeMargin:
-      return consumeLengthOrPercent(m_range, m_context.mode(),
+      return consumeLengthOrPercent(m_range, m_context->mode(),
                                     ValueRangeNonNegative);
     case CSSPropertyShapeImageThreshold:
       return consumeNumber(m_range, ValueRangeAll);
@@ -3270,7 +3274,7 @@
     case CSSPropertyWidows:
       return consumePositiveInteger(m_range);
     case CSSPropertyWebkitTextStrokeWidth:
-      return consumeTextStrokeWidth(m_range, m_context.mode());
+      return consumeTextStrokeWidth(m_range, m_context->mode());
     case CSSPropertyWebkitTextFillColor:
     case CSSPropertyWebkitTapHighlightColor:
     case CSSPropertyWebkitTextEmphasisColor:
@@ -3283,15 +3287,15 @@
     case CSSPropertyFloodColor:
     case CSSPropertyLightingColor:
     case CSSPropertyColumnRuleColor:
-      return consumeColor(m_range, m_context.mode());
+      return consumeColor(m_range, m_context->mode());
     case CSSPropertyColor:
     case CSSPropertyBackgroundColor:
-      return consumeColor(m_range, m_context.mode(), inQuirksMode());
+      return consumeColor(m_range, m_context->mode(), inQuirksMode());
     case CSSPropertyWebkitBorderStartWidth:
     case CSSPropertyWebkitBorderEndWidth:
     case CSSPropertyWebkitBorderBeforeWidth:
     case CSSPropertyWebkitBorderAfterWidth:
-      return consumeBorderWidth(m_range, m_context.mode(),
+      return consumeBorderWidth(m_range, m_context->mode(),
                                 UnitlessQuirk::Forbid);
     case CSSPropertyBorderBottomColor:
     case CSSPropertyBorderLeftColor:
@@ -3300,7 +3304,7 @@
       bool allowQuirkyColors =
           inQuirksMode() && (currentShorthand == CSSPropertyInvalid ||
                              currentShorthand == CSSPropertyBorderColor);
-      return consumeColor(m_range, m_context.mode(), allowQuirkyColors);
+      return consumeColor(m_range, m_context->mode(), allowQuirkyColors);
     }
     case CSSPropertyBorderBottomWidth:
     case CSSPropertyBorderLeftWidth:
@@ -3311,11 +3315,11 @@
                              currentShorthand == CSSPropertyBorderWidth);
       UnitlessQuirk unitless =
           allowQuirkyLengths ? UnitlessQuirk::Allow : UnitlessQuirk::Forbid;
-      return consumeBorderWidth(m_range, m_context.mode(), unitless);
+      return consumeBorderWidth(m_range, m_context->mode(), unitless);
     }
     case CSSPropertyTextShadow:
     case CSSPropertyBoxShadow:
-      return consumeShadow(m_range, m_context.mode(),
+      return consumeShadow(m_range, m_context->mode(),
                            property == CSSPropertyBoxShadow);
     case CSSPropertyFilter:
     case CSSPropertyBackdropFilter:
@@ -3327,38 +3331,39 @@
     case CSSPropertyTextDecorationLine:
       return consumeTextDecorationLine(m_range);
     case CSSPropertyOffsetAnchor:
-      return consumeOffsetAnchor(m_range, m_context.mode());
+      return consumeOffsetAnchor(m_range, m_context->mode());
     case CSSPropertyD:
       return consumePathOrNone(m_range);
     case CSSPropertyOffsetPath:
       return consumeOffsetPath(
-          m_range, m_context.useCounter(),
+          m_range, m_context,
           currentShorthand == CSSPropertyMotion ||
               unresolvedProperty == CSSPropertyAliasMotionPath);
     case CSSPropertyOffsetDistance:
-      return consumeLengthOrPercent(m_range, m_context.mode(), ValueRangeAll);
+      return consumeLengthOrPercent(m_range, m_context->mode(), ValueRangeAll);
     case CSSPropertyOffsetRotate:
     case CSSPropertyOffsetRotation:
       return consumeOffsetRotate(m_range);
     case CSSPropertyWebkitTextEmphasisStyle:
       return consumeTextEmphasisStyle(m_range);
     case CSSPropertyOutlineColor:
-      return consumeOutlineColor(m_range, m_context.mode());
+      return consumeOutlineColor(m_range, m_context->mode());
     case CSSPropertyOutlineWidth:
-      return consumeLineWidth(m_range, m_context.mode(), UnitlessQuirk::Forbid);
+      return consumeLineWidth(m_range, m_context->mode(),
+                              UnitlessQuirk::Forbid);
     case CSSPropertyTransform:
       return consumeTransform(
           m_range, m_context,
           unresolvedProperty == CSSPropertyAliasWebkitTransform);
     case CSSPropertyWebkitTransformOriginX:
     case CSSPropertyWebkitPerspectiveOriginX:
-      return consumePositionX(m_range, m_context.mode());
+      return consumePositionX(m_range, m_context->mode());
     case CSSPropertyWebkitTransformOriginY:
     case CSSPropertyWebkitPerspectiveOriginY:
-      return consumePositionY(m_range, m_context.mode());
+      return consumePositionY(m_range, m_context->mode());
     case CSSPropertyFill:
     case CSSPropertyStroke:
-      return consumePaintStroke(m_range, m_context.mode());
+      return consumePaintStroke(m_range, m_context->mode());
     case CSSPropertyMarkerStart:
     case CSSPropertyMarkerMid:
     case CSSPropertyMarkerEnd:
@@ -3370,7 +3375,7 @@
     case CSSPropertyStrokeDasharray:
       return consumeStrokeDasharray(m_range);
     case CSSPropertyColumnRuleWidth:
-      return consumeColumnRuleWidth(m_range, m_context.mode());
+      return consumeColumnRuleWidth(m_range, m_context->mode());
     case CSSPropertyStrokeOpacity:
     case CSSPropertyFillOpacity:
     case CSSPropertyStopOpacity:
@@ -3408,18 +3413,18 @@
       return consumePerspective(m_range, m_context, unresolvedProperty);
     case CSSPropertyScrollSnapPointsX:
     case CSSPropertyScrollSnapPointsY:
-      return consumeScrollSnapPoints(m_range, m_context.mode());
+      return consumeScrollSnapPoints(m_range, m_context->mode());
     case CSSPropertyBorderTopRightRadius:
     case CSSPropertyBorderTopLeftRadius:
     case CSSPropertyBorderBottomLeftRadius:
     case CSSPropertyBorderBottomRightRadius:
-      return consumeBorderRadiusCorner(m_range, m_context.mode());
+      return consumeBorderRadiusCorner(m_range, m_context->mode());
     case CSSPropertyWebkitBoxFlexGroup:
       return consumeInteger(m_range, 0);
     case CSSPropertyOrder:
       return consumeInteger(m_range);
     case CSSPropertyVerticalAlign:
-      return consumeVerticalAlign(m_range, m_context.mode());
+      return consumeVerticalAlign(m_range, m_context->mode());
     case CSSPropertyShapeOutside:
       return consumeShapeOutside(m_range, m_context);
     case CSSPropertyClipPath:
@@ -3489,11 +3494,11 @@
     case CSSPropertyGridAutoColumns:
     case CSSPropertyGridAutoRows:
       ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
-      return consumeGridTrackList(m_range, m_context.mode(), GridAuto);
+      return consumeGridTrackList(m_range, m_context->mode(), GridAuto);
     case CSSPropertyGridTemplateColumns:
     case CSSPropertyGridTemplateRows:
       ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
-      return consumeGridTemplatesRowsOrColumns(m_range, m_context.mode());
+      return consumeGridTemplatesRowsOrColumns(m_range, m_context->mode());
     case CSSPropertyGridTemplateAreas:
       ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
       return consumeGridTemplateAreas(m_range);
@@ -3529,14 +3534,14 @@
 }
 
 static CSSValue* consumeFontFaceSrcURI(CSSParserTokenRange& range,
-                                       const CSSParserContext& context) {
+                                       const CSSParserContext* context) {
   String url = consumeUrlAsStringView(range).toString();
   if (url.isNull())
     return nullptr;
   CSSFontFaceSrcValue* uriValue(
-      CSSFontFaceSrcValue::create(url, context.completeURL(url),
-                                  context.shouldCheckContentSecurityPolicy()));
-  uriValue->setReferrer(context.referrer());
+      CSSFontFaceSrcValue::create(url, context->completeURL(url),
+                                  context->shouldCheckContentSecurityPolicy()));
+  uriValue->setReferrer(context->referrer());
 
   if (range.peek().functionId() != CSSValueFormat)
     return uriValue;
@@ -3553,10 +3558,10 @@
 }
 
 static CSSValue* consumeFontFaceSrcLocal(CSSParserTokenRange& range,
-                                         const CSSParserContext& context) {
+                                         const CSSParserContext* context) {
   CSSParserTokenRange args = consumeFunction(range);
   ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy =
-      context.shouldCheckContentSecurityPolicy();
+      context->shouldCheckContentSecurityPolicy();
   if (args.peek().type() == StringToken) {
     const CSSParserToken& arg = args.consumeIncludingWhitespace();
     if (!args.atEnd())
@@ -3575,7 +3580,7 @@
 }
 
 static CSSValueList* consumeFontFaceSrc(CSSParserTokenRange& range,
-                                        const CSSParserContext& context) {
+                                        const CSSParserContext* context) {
   CSSValueList* values = CSSValueList::createCommaSeparated();
 
   do {
@@ -3612,8 +3617,8 @@
     case CSSPropertyFontStretch:
     case CSSPropertyFontStyle: {
       CSSValueID id = m_range.consumeIncludingWhitespace().id();
-      if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id,
-                                                              m_context.mode()))
+      if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(
+              propId, id, m_context->mode()))
         return false;
       parsedValue = CSSIdentifierValue::create(id);
       break;
@@ -3696,7 +3701,7 @@
   while (!m_range.atEnd()) {
     CSSValueID id = m_range.peek().id();
     if (!fontStyle && CSSParserFastPaths::isValidKeywordPropertyAndValue(
-                          CSSPropertyFontStyle, id, m_context.mode())) {
+                          CSSPropertyFontStyle, id, m_context->mode())) {
       fontStyle = consumeIdent(m_range);
       continue;
     }
@@ -3714,7 +3719,7 @@
         continue;
     }
     if (!fontStretch && CSSParserFastPaths::isValidKeywordPropertyAndValue(
-                            CSSPropertyFontStretch, id, m_context.mode()))
+                            CSSPropertyFontStretch, id, m_context->mode()))
       fontStretch = consumeIdent(m_range);
     else
       break;
@@ -3746,14 +3751,14 @@
       important);
 
   // Now a font size _must_ come.
-  CSSValue* fontSize = consumeFontSize(m_range, m_context.mode());
+  CSSValue* fontSize = consumeFontSize(m_range, m_context->mode());
   if (!fontSize || m_range.atEnd())
     return false;
 
   addProperty(CSSPropertyFontSize, CSSPropertyFont, *fontSize, important);
 
   if (consumeSlashIncludingWhitespace(m_range)) {
-    CSSValue* lineHeight = consumeLineHeight(m_range, m_context.mode());
+    CSSValue* lineHeight = consumeLineHeight(m_range, m_context->mode());
     if (!lineHeight)
       return false;
     addProperty(CSSPropertyLineHeight, CSSPropertyFont, *lineHeight, important);
@@ -3837,13 +3842,15 @@
 
 bool CSSPropertyParser::consumeBorderSpacing(bool important) {
   CSSValue* horizontalSpacing = consumeLength(
-      m_range, m_context.mode(), ValueRangeNonNegative, UnitlessQuirk::Allow);
+      m_range, m_context->mode(), ValueRangeNonNegative, UnitlessQuirk::Allow);
   if (!horizontalSpacing)
     return false;
   CSSValue* verticalSpacing = horizontalSpacing;
-  if (!m_range.atEnd())
-    verticalSpacing = consumeLength(
-        m_range, m_context.mode(), ValueRangeNonNegative, UnitlessQuirk::Allow);
+  if (!m_range.atEnd()) {
+    verticalSpacing =
+        consumeLength(m_range, m_context->mode(), ValueRangeNonNegative,
+                      UnitlessQuirk::Allow);
+  }
   if (!verticalSpacing || !m_range.atEnd())
     return false;
   addProperty(CSSPropertyWebkitBorderHorizontalSpacing,
@@ -3893,18 +3900,19 @@
 bool CSSPropertyParser::parseViewportDescriptor(CSSPropertyID propId,
                                                 bool important) {
   ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() ||
-         isUASheetBehavior(m_context.mode()));
+         isUASheetBehavior(m_context->mode()));
 
   switch (propId) {
     case CSSPropertyWidth: {
       CSSValue* minWidth = consumeSingleViewportDescriptor(
-          m_range, CSSPropertyMinWidth, m_context.mode());
+          m_range, CSSPropertyMinWidth, m_context->mode());
       if (!minWidth)
         return false;
       CSSValue* maxWidth = minWidth;
-      if (!m_range.atEnd())
+      if (!m_range.atEnd()) {
         maxWidth = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxWidth,
-                                                   m_context.mode());
+                                                   m_context->mode());
+      }
       if (!maxWidth || !m_range.atEnd())
         return false;
       addProperty(CSSPropertyMinWidth, CSSPropertyInvalid, *minWidth,
@@ -3915,13 +3923,14 @@
     }
     case CSSPropertyHeight: {
       CSSValue* minHeight = consumeSingleViewportDescriptor(
-          m_range, CSSPropertyMinHeight, m_context.mode());
+          m_range, CSSPropertyMinHeight, m_context->mode());
       if (!minHeight)
         return false;
       CSSValue* maxHeight = minHeight;
-      if (!m_range.atEnd())
+      if (!m_range.atEnd()) {
         maxHeight = consumeSingleViewportDescriptor(
-            m_range, CSSPropertyMaxHeight, m_context.mode());
+            m_range, CSSPropertyMaxHeight, m_context->mode());
+      }
       if (!maxHeight || !m_range.atEnd())
         return false;
       addProperty(CSSPropertyMinHeight, CSSPropertyInvalid, *minHeight,
@@ -3940,7 +3949,7 @@
     case CSSPropertyUserZoom:
     case CSSPropertyOrientation: {
       CSSValue* parsedValue =
-          consumeSingleViewportDescriptor(m_range, propId, m_context.mode());
+          consumeSingleViewportDescriptor(m_range, propId, m_context->mode());
       if (!parsedValue || !m_range.atEnd())
         return false;
       addProperty(propId, CSSPropertyInvalid, *parsedValue, important);
@@ -4052,7 +4061,7 @@
         if (m_range.peek().id() == CSSValueAuto)
           flexBasis = consumeIdent(m_range);
         if (!flexBasis)
-          flexBasis = consumeLengthOrPercent(m_range, m_context.mode(),
+          flexBasis = consumeLengthOrPercent(m_range, m_context->mode(),
                                              ValueRangeNonNegative);
         if (index == 2 && !m_range.atEnd())
           return false;
@@ -4091,7 +4100,7 @@
   while (!width || !style || !color) {
     if (!width) {
       width =
-          consumeLineWidth(m_range, m_context.mode(), UnitlessQuirk::Forbid);
+          consumeLineWidth(m_range, m_context->mode(), UnitlessQuirk::Forbid);
       if (width)
         continue;
     }
@@ -4101,7 +4110,7 @@
         continue;
     }
     if (!color) {
-      color = consumeColor(m_range, m_context.mode());
+      color = consumeColor(m_range, m_context->mode());
       if (color)
         continue;
     }
@@ -4279,14 +4288,15 @@
 }
 
 static bool consumeBackgroundPosition(CSSParserTokenRange& range,
-                                      const CSSParserContext& context,
+                                      const CSSParserContext* context,
                                       UnitlessQuirk unitless,
                                       CSSValue*& resultX,
                                       CSSValue*& resultY) {
   do {
     CSSValue* positionX = nullptr;
     CSSValue* positionY = nullptr;
-    if (!consumePosition(range, context.mode(), unitless, positionX, positionY))
+    if (!consumePosition(range, context->mode(), unitless, positionX,
+                         positionY))
       return false;
     addBackgroundValue(resultX, positionX);
     addBackgroundValue(resultY, positionY);
@@ -4366,14 +4376,14 @@
           consumeRepeatStyleComponent(m_range, value, valueY, implicit);
         } else if (property == CSSPropertyBackgroundPositionX ||
                    property == CSSPropertyWebkitMaskPositionX) {
-          if (!consumePosition(m_range, m_context.mode(), UnitlessQuirk::Forbid,
-                               value, valueY))
+          if (!consumePosition(m_range, m_context->mode(),
+                               UnitlessQuirk::Forbid, value, valueY))
             continue;
         } else if (property == CSSPropertyBackgroundSize ||
                    property == CSSPropertyWebkitMaskSize) {
           if (!consumeSlashIncludingWhitespace(m_range))
             continue;
-          value = consumeBackgroundSize(property, m_range, m_context.mode());
+          value = consumeBackgroundSize(property, m_range, m_context->mode());
           if (!value || !parsedLonghand[i - 1])  // Position must have been
                                                  // parsed in the current layer.
             return false;
@@ -4426,7 +4436,7 @@
   for (size_t i = 0; i < longhandCount; ++i) {
     CSSPropertyID property = shorthand.properties()[i];
     if (property == CSSPropertyBackgroundSize && longhands[i] &&
-        m_context.useLegacyBackgroundSizeShorthandBehavior())
+        m_context->useLegacyBackgroundSizeShorthandBehavior())
       continue;
     addProperty(property, shorthand.id(), *longhands[i], important, implicit);
   }
@@ -4541,7 +4551,7 @@
     ++rowCount;
 
     // Handle template-rows's track-size.
-    CSSValue* value = consumeGridTrackSize(m_range, m_context.mode());
+    CSSValue* value = consumeGridTrackSize(m_range, m_context->mode());
     if (!value)
       value = CSSIdentifierValue::create(CSSValueAuto);
     templateRows->append(*value);
@@ -4559,7 +4569,7 @@
     if (!consumeSlashIncludingWhitespace(m_range))
       return false;
     columnsValue =
-        consumeGridTrackList(m_range, m_context.mode(), GridTemplateNoRepeat);
+        consumeGridTrackList(m_range, m_context->mode(), GridTemplateNoRepeat);
     if (!columnsValue || !m_range.atEnd())
       return false;
   } else {
@@ -4597,13 +4607,13 @@
 
   // 2- <grid-template-rows> / <grid-template-columns>
   if (!rowsValue)
-    rowsValue = consumeGridTrackList(m_range, m_context.mode(), GridTemplate);
+    rowsValue = consumeGridTrackList(m_range, m_context->mode(), GridTemplate);
 
   if (rowsValue) {
     if (!consumeSlashIncludingWhitespace(m_range))
       return false;
     CSSValue* columnsValue =
-        consumeGridTemplatesRowsOrColumns(m_range, m_context.mode());
+        consumeGridTemplatesRowsOrColumns(m_range, m_context->mode());
     if (!columnsValue || !m_range.atEnd())
       return false;
 
@@ -4682,20 +4692,22 @@
     if (consumeSlashIncludingWhitespace(m_range)) {
       autoRowsValue = CSSInitialValue::create();
     } else {
-      autoRowsValue = consumeGridTrackList(m_range, m_context.mode(), GridAuto);
+      autoRowsValue =
+          consumeGridTrackList(m_range, m_context->mode(), GridAuto);
       if (!autoRowsValue)
         return false;
       if (!consumeSlashIncludingWhitespace(m_range))
         return false;
     }
     if (!(templateColumns =
-              consumeGridTemplatesRowsOrColumns(m_range, m_context.mode())))
+              consumeGridTemplatesRowsOrColumns(m_range, m_context->mode())))
       return false;
     templateRows = CSSInitialValue::create();
     autoColumnsValue = CSSInitialValue::create();
   } else {
     // 3- <grid-template-rows> / [ auto-flow && dense? ] <grid-auto-columns>?
-    templateRows = consumeGridTemplatesRowsOrColumns(m_range, m_context.mode());
+    templateRows =
+        consumeGridTemplatesRowsOrColumns(m_range, m_context->mode());
     if (!templateRows)
       return false;
     if (!consumeSlashIncludingWhitespace(m_range))
@@ -4708,7 +4720,7 @@
       autoColumnsValue = CSSInitialValue::create();
     } else {
       autoColumnsValue =
-          consumeGridTrackList(m_range, m_context.mode(), GridAuto);
+          consumeGridTrackList(m_range, m_context->mode(), GridAuto);
       if (!autoColumnsValue)
         return false;
     }
@@ -4749,7 +4761,7 @@
     case CSSPropertyWebkitMarginCollapse: {
       CSSValueID id = m_range.consumeIncludingWhitespace().id();
       if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(
-              CSSPropertyWebkitMarginBeforeCollapse, id, m_context.mode()))
+              CSSPropertyWebkitMarginBeforeCollapse, id, m_context->mode()))
         return false;
       CSSValue* beforeCollapse = CSSIdentifierValue::create(id);
       addProperty(CSSPropertyWebkitMarginBeforeCollapse,
@@ -4762,7 +4774,7 @@
       }
       id = m_range.consumeIncludingWhitespace().id();
       if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(
-              CSSPropertyWebkitMarginAfterCollapse, id, m_context.mode()))
+              CSSPropertyWebkitMarginAfterCollapse, id, m_context->mode()))
         return false;
       addProperty(CSSPropertyWebkitMarginAfterCollapse,
                   CSSPropertyWebkitMarginCollapse,
@@ -4772,7 +4784,7 @@
     case CSSPropertyOverflow: {
       CSSValueID id = m_range.consumeIncludingWhitespace().id();
       if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(
-              CSSPropertyOverflowY, id, m_context.mode()))
+              CSSPropertyOverflowY, id, m_context->mode()))
         return false;
       if (!m_range.atEnd())
         return false;
@@ -4862,7 +4874,7 @@
       CSSValue* horizontalRadii[4] = {0};
       CSSValue* verticalRadii[4] = {0};
       if (!consumeRadii(
-              horizontalRadii, verticalRadii, m_range, m_context.mode(),
+              horizontalRadii, verticalRadii, m_range, m_context->mode(),
               unresolvedProperty == CSSPropertyAliasWebkitBorderRadius))
         return false;
       addProperty(CSSPropertyBorderTopLeftRadius, CSSPropertyBorderRadius,
@@ -4952,9 +4964,9 @@
     case CSSPropertyGridGap: {
       ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled() &&
              shorthandForProperty(CSSPropertyGridGap).length() == 2);
-      CSSValue* rowGap = consumeLengthOrPercent(m_range, m_context.mode(),
+      CSSValue* rowGap = consumeLengthOrPercent(m_range, m_context->mode(),
                                                 ValueRangeNonNegative);
-      CSSValue* columnGap = consumeLengthOrPercent(m_range, m_context.mode(),
+      CSSValue* columnGap = consumeLengthOrPercent(m_range, m_context->mode(),
                                                    ValueRangeNonNegative);
       if (!rowGap || !m_range.atEnd())
         return false;
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h
index d8862666..4f291e7 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h
@@ -47,18 +47,18 @@
   static bool parseValue(CSSPropertyID,
                          bool important,
                          const CSSParserTokenRange&,
-                         const CSSParserContext&,
+                         const CSSParserContext*,
                          HeapVector<CSSProperty, 256>&,
                          StyleRule::RuleType);
 
   // Parses a non-shorthand CSS property
   static const CSSValue* parseSingleValue(CSSPropertyID,
                                           const CSSParserTokenRange&,
-                                          const CSSParserContext&);
+                                          const CSSParserContext*);
 
  private:
   CSSPropertyParser(const CSSParserTokenRange&,
-                    const CSSParserContext&,
+                    const CSSParserContext*,
                     HeapVector<CSSProperty, 256>*);
 
   // TODO(timloh): Rename once the CSSParserValue-based parseValue is removed
@@ -67,7 +67,7 @@
   const CSSValue* parseSingleValue(CSSPropertyID,
                                    CSSPropertyID = CSSPropertyInvalid);
 
-  bool inQuirksMode() const { return isQuirksModeBehavior(m_context.mode()); }
+  bool inQuirksMode() const { return isQuirksModeBehavior(m_context->mode()); }
 
   bool parseViewportDescriptor(CSSPropertyID propId, bool important);
   bool parseFontFaceDescriptor(CSSPropertyID);
@@ -117,7 +117,7 @@
  private:
   // Inputs:
   CSSParserTokenRange m_range;
-  const CSSParserContext& m_context;
+  Member<const CSSParserContext> m_context;
   // Outputs:
   HeapVector<CSSProperty, 256>* m_parsedProperties;
 };
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
index b63c13b..20e37e6 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
@@ -1067,14 +1067,14 @@
 }
 
 CSSValue* consumeImageOrNone(CSSParserTokenRange& range,
-                             const CSSParserContext& context) {
+                             const CSSParserContext* context) {
   if (range.peek().id() == CSSValueNone)
     return consumeIdent(range);
   return consumeImage(range, context);
 }
 
 static CSSValue* consumeCrossFade(CSSParserTokenRange& args,
-                                  const CSSParserContext& context) {
+                                  const CSSParserContext* context) {
   CSSValue* fromImageValue = consumeImageOrNone(args, context);
   if (!fromImageValue || !consumeCommaIncludingWhitespace(args))
     return nullptr;
@@ -1099,7 +1099,7 @@
 }
 
 static CSSValue* consumePaint(CSSParserTokenRange& args,
-                              const CSSParserContext& context) {
+                              const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::cssPaintAPIEnabled());
 
   CSSCustomIdentValue* name = consumeCustomIdent(args);
@@ -1110,50 +1110,52 @@
 }
 
 static CSSValue* consumeGeneratedImage(CSSParserTokenRange& range,
-                                       const CSSParserContext& context) {
+                                       const CSSParserContext* context) {
   CSSValueID id = range.peek().functionId();
   CSSParserTokenRange rangeCopy = range;
   CSSParserTokenRange args = consumeFunction(rangeCopy);
   CSSValue* result = nullptr;
   if (id == CSSValueRadialGradient) {
-    result = consumeRadialGradient(args, context.mode(), NonRepeating);
+    result = consumeRadialGradient(args, context->mode(), NonRepeating);
   } else if (id == CSSValueRepeatingRadialGradient) {
-    result = consumeRadialGradient(args, context.mode(), Repeating);
+    result = consumeRadialGradient(args, context->mode(), Repeating);
   } else if (id == CSSValueWebkitLinearGradient) {
     // FIXME: This should send a deprecation message.
-    if (context.useCounter())
-      context.useCounter()->count(UseCounter::DeprecatedWebKitLinearGradient);
-    result = consumeLinearGradient(args, context.mode(), NonRepeating,
+    if (context->isUseCounterRecordingEnabled())
+      context->useCounter()->count(UseCounter::DeprecatedWebKitLinearGradient);
+    result = consumeLinearGradient(args, context->mode(), NonRepeating,
                                    CSSPrefixedLinearGradient);
   } else if (id == CSSValueWebkitRepeatingLinearGradient) {
     // FIXME: This should send a deprecation message.
-    if (context.useCounter())
-      context.useCounter()->count(
+    if (context->isUseCounterRecordingEnabled()) {
+      context->useCounter()->count(
           UseCounter::DeprecatedWebKitRepeatingLinearGradient);
-    result = consumeLinearGradient(args, context.mode(), Repeating,
+    }
+    result = consumeLinearGradient(args, context->mode(), Repeating,
                                    CSSPrefixedLinearGradient);
   } else if (id == CSSValueRepeatingLinearGradient) {
-    result = consumeLinearGradient(args, context.mode(), Repeating,
+    result = consumeLinearGradient(args, context->mode(), Repeating,
                                    CSSLinearGradient);
   } else if (id == CSSValueLinearGradient) {
-    result = consumeLinearGradient(args, context.mode(), NonRepeating,
+    result = consumeLinearGradient(args, context->mode(), NonRepeating,
                                    CSSLinearGradient);
   } else if (id == CSSValueWebkitGradient) {
     // FIXME: This should send a deprecation message.
-    if (context.useCounter())
-      context.useCounter()->count(UseCounter::DeprecatedWebKitGradient);
-    result = consumeDeprecatedGradient(args, context.mode());
+    if (context->isUseCounterRecordingEnabled())
+      context->useCounter()->count(UseCounter::DeprecatedWebKitGradient);
+    result = consumeDeprecatedGradient(args, context->mode());
   } else if (id == CSSValueWebkitRadialGradient) {
     // FIXME: This should send a deprecation message.
-    if (context.useCounter())
-      context.useCounter()->count(UseCounter::DeprecatedWebKitRadialGradient);
+    if (context->isUseCounterRecordingEnabled())
+      context->useCounter()->count(UseCounter::DeprecatedWebKitRadialGradient);
     result =
-        consumeDeprecatedRadialGradient(args, context.mode(), NonRepeating);
+        consumeDeprecatedRadialGradient(args, context->mode(), NonRepeating);
   } else if (id == CSSValueWebkitRepeatingRadialGradient) {
-    if (context.useCounter())
-      context.useCounter()->count(
+    if (context->isUseCounterRecordingEnabled()) {
+      context->useCounter()->count(
           UseCounter::DeprecatedWebKitRepeatingRadialGradient);
-    result = consumeDeprecatedRadialGradient(args, context.mode(), Repeating);
+    }
+    result = consumeDeprecatedRadialGradient(args, context->mode(), Repeating);
   } else if (id == CSSValueWebkitCrossFade) {
     result = consumeCrossFade(args, context);
   } else if (id == CSSValuePaint) {
@@ -1169,15 +1171,15 @@
 
 static CSSValue* createCSSImageValueWithReferrer(
     const AtomicString& rawValue,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSValue* imageValue =
-      CSSImageValue::create(rawValue, context.completeURL(rawValue));
-  toCSSImageValue(imageValue)->setReferrer(context.referrer());
+      CSSImageValue::create(rawValue, context->completeURL(rawValue));
+  toCSSImageValue(imageValue)->setReferrer(context->referrer());
   return imageValue;
 }
 
 static CSSValue* consumeImageSet(CSSParserTokenRange& range,
-                                 const CSSParserContext& context) {
+                                 const CSSParserContext* context) {
   CSSParserTokenRange rangeCopy = range;
   CSSParserTokenRange args = consumeFunction(rangeCopy);
   CSSImageSetValue* imageSet = CSSImageSetValue::create();
@@ -1220,7 +1222,7 @@
 }
 
 CSSValue* consumeImage(CSSParserTokenRange& range,
-                       const CSSParserContext& context,
+                       const CSSParserContext* context,
                        ConsumeGeneratedImagePolicy generatedImage) {
   AtomicString uri = consumeUrlAsStringView(range).toAtomicString();
   if (!uri.isNull())
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
index 6e78d07..720539a 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
@@ -90,9 +90,9 @@
 
 CSSValue* consumeImage(
     CSSParserTokenRange&,
-    const CSSParserContext&,
+    const CSSParserContext*,
     ConsumeGeneratedImagePolicy = ConsumeGeneratedImagePolicy::Allow);
-CSSValue* consumeImageOrNone(CSSParserTokenRange&, const CSSParserContext&);
+CSSValue* consumeImageOrNone(CSSParserTokenRange&, const CSSParserContext*);
 
 bool isCSSWideKeyword(StringView);
 
diff --git a/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
index 33e69d2..37b6f8f 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
@@ -14,9 +14,9 @@
 
 namespace blink {
 
-static void recordSelectorStats(const CSSParserContext& context,
+static void recordSelectorStats(const CSSParserContext* context,
                                 const CSSSelectorList& selectorList) {
-  if (!context.useCounter())
+  if (!context->isUseCounterRecordingEnabled())
     return;
 
   for (const CSSSelector* selector = selectorList.first(); selector;
@@ -53,11 +53,11 @@
           feature = UseCounter::CSSSelectorPseudoFullScreen;
           break;
         case CSSSelector::PseudoListBox:
-          if (context.mode() != UASheetMode)
+          if (context->mode() != UASheetMode)
             feature = UseCounter::CSSSelectorInternalPseudoListBox;
           break;
         case CSSSelector::PseudoWebKitCustomElement:
-          if (context.mode() != UASheetMode) {
+          if (context->mode() != UASheetMode) {
             if (current->value() == "-internal-media-controls-cast-button")
               feature = UseCounter::CSSSelectorInternalMediaControlsCastButton;
             else if (current->value() ==
@@ -67,25 +67,25 @@
           }
           break;
         case CSSSelector::PseudoSpatialNavigationFocus:
-          if (context.mode() != UASheetMode)
+          if (context->mode() != UASheetMode)
             feature =
                 UseCounter::CSSSelectorInternalPseudoSpatialNavigationFocus;
           break;
         case CSSSelector::PseudoReadOnly:
-          if (context.mode() != UASheetMode)
+          if (context->mode() != UASheetMode)
             feature = UseCounter::CSSSelectorPseudoReadOnly;
           break;
         case CSSSelector::PseudoReadWrite:
-          if (context.mode() != UASheetMode)
+          if (context->mode() != UASheetMode)
             feature = UseCounter::CSSSelectorPseudoReadWrite;
           break;
         default:
           break;
       }
       if (feature != UseCounter::NumberOfFeatures)
-        context.useCounter()->count(feature);
+        context->useCounter()->count(feature);
       if (current->relation() == CSSSelector::IndirectAdjacent)
-        context.useCounter()->count(UseCounter::CSSSelectorIndirectAdjacent);
+        context->useCounter()->count(UseCounter::CSSSelectorIndirectAdjacent);
       if (current->selectorList())
         recordSelectorStats(context, *current->selectorList());
     }
@@ -94,7 +94,7 @@
 
 CSSSelectorList CSSSelectorParser::parseSelector(
     CSSParserTokenRange range,
-    const CSSParserContext& context,
+    const CSSParserContext* context,
     StyleSheetContents* styleSheet) {
   CSSSelectorParser parser(context, styleSheet);
   range.consumeWhitespace();
@@ -106,7 +106,7 @@
   return result;
 }
 
-CSSSelectorParser::CSSSelectorParser(const CSSParserContext& context,
+CSSSelectorParser::CSSSelectorParser(const CSSParserContext* context,
                                      StyleSheetContents* styleSheet)
     : m_context(context), m_styleSheet(styleSheet) {}
 
@@ -191,7 +191,7 @@
 
   for (CSSParserSelector* simple = selector.get();
        simple && !previousCompoundFlags; simple = simple->tagHistory())
-    previousCompoundFlags |= extractCompoundFlags(*simple, m_context.mode());
+    previousCompoundFlags |= extractCompoundFlags(*simple, m_context->mode());
 
   while (CSSSelector::RelationType combinator = consumeCombinator(range)) {
     std::unique_ptr<CSSParserSelector> nextSelector =
@@ -202,10 +202,10 @@
     if (previousCompoundFlags & HasPseudoElementForRightmostCompound)
       return nullptr;
     CSSParserSelector* end = nextSelector.get();
-    unsigned compoundFlags = extractCompoundFlags(*end, m_context.mode());
+    unsigned compoundFlags = extractCompoundFlags(*end, m_context->mode());
     while (end->tagHistory()) {
       end = end->tagHistory();
-      compoundFlags |= extractCompoundFlags(*end, m_context.mode());
+      compoundFlags |= extractCompoundFlags(*end, m_context->mode());
     }
     end->setRelation(combinator);
     if (previousCompoundFlags & HasContentPseudoElement)
@@ -312,7 +312,7 @@
     if (compoundSelector->match() == CSSSelector::PseudoElement)
       compoundPseudoElement = compoundSelector->pseudoType();
   }
-  if (m_context.isHTMLDocument())
+  if (m_context->isHTMLDocument())
     elementName = elementName.lower();
 
   while (std::unique_ptr<CSSParserSelector> simpleSelector =
@@ -321,7 +321,7 @@
     // The UASheetMode check is a work-around to allow this selector in
     // mediaControls(New).css:
     // video::-webkit-media-text-track-region-container.scrolling
-    if (m_context.mode() != UASheetMode &&
+    if (m_context->mode() != UASheetMode &&
         !isSimpleSelectorValidAfterPseudoElement(*simpleSelector.get(),
                                                  compoundPseudoElement)) {
       m_failedParsing = true;
@@ -423,7 +423,7 @@
   std::unique_ptr<CSSParserSelector> selector = CSSParserSelector::create();
   selector->setMatch(CSSSelector::Id);
   AtomicString value = range.consume().value().toAtomicString();
-  selector->setValue(value, isQuirksModeBehavior(m_context.matchMode()));
+  selector->setValue(value, isQuirksModeBehavior(m_context->matchMode()));
   return selector;
 }
 
@@ -437,7 +437,7 @@
   std::unique_ptr<CSSParserSelector> selector = CSSParserSelector::create();
   selector->setMatch(CSSSelector::Class);
   AtomicString value = range.consume().value().toAtomicString();
-  selector->setValue(value, isQuirksModeBehavior(m_context.matchMode()));
+  selector->setValue(value, isQuirksModeBehavior(m_context->matchMode()));
   return selector;
 }
 
@@ -453,7 +453,7 @@
     return nullptr;
   block.consumeWhitespace();
 
-  if (m_context.isHTMLDocument())
+  if (m_context->isHTMLDocument())
     attributeName = attributeName.lower();
 
   AtomicString namespaceURI = determineNamespace(namespacePrefix);
@@ -616,7 +616,7 @@
     case '>':
       if (!RuntimeEnabledFeatures::
               shadowPiercingDescendantCombinatorEnabled() ||
-          m_context.isDynamicProfile() ||
+          m_context->isDynamicProfile() ||
           range.peek(1).type() != DelimiterToken ||
           range.peek(1).delimiter() != '>') {
         range.consumeIncludingWhitespace();
diff --git a/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.h b/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.h
index 8c9c3576..216e262 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.h
@@ -23,13 +23,13 @@
 
  public:
   static CSSSelectorList parseSelector(CSSParserTokenRange,
-                                       const CSSParserContext&,
+                                       const CSSParserContext*,
                                        StyleSheetContents*);
 
   static bool consumeANPlusB(CSSParserTokenRange&, std::pair<int, int>&);
 
  private:
-  CSSSelectorParser(const CSSParserContext&, StyleSheetContents*);
+  CSSSelectorParser(const CSSParserContext*, StyleSheetContents*);
 
   // These will all consume trailing comments if successful
 
@@ -70,7 +70,7 @@
   splitCompoundAtImplicitShadowCrossingCombinator(
       std::unique_ptr<CSSParserSelector> compoundSelector);
 
-  const CSSParserContext& m_context;
+  Member<const CSSParserContext> m_context;
   Member<StyleSheetContents> m_styleSheet;  // FIXME: Should be const
 
   bool m_failedParsing = false;
diff --git a/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp b/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
index 12d63df..4d2f3fb2 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
@@ -119,7 +119,7 @@
     CSSTokenizer tokenizer(testCase[0]);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+        range, CSSParserContext::create(HTMLStandardMode), nullptr);
     EXPECT_STREQ(testCase[1], list.selectorsText().ascii().data());
   }
 }
@@ -142,7 +142,7 @@
     CSSTokenizer tokenizer(testCase);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+        range, CSSParserContext::create(HTMLStandardMode), nullptr);
     EXPECT_FALSE(list.isValid());
   }
 }
@@ -157,7 +157,7 @@
     CSSTokenizer tokenizer(testCase);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+        range, CSSParserContext::create(HTMLStandardMode), nullptr);
     EXPECT_TRUE(list.isValid());
   }
 }
@@ -180,7 +180,7 @@
     CSSTokenizer tokenizer(testCase);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+        range, CSSParserContext::create(HTMLStandardMode), nullptr);
     EXPECT_FALSE(list.isValid());
   }
 }
@@ -195,7 +195,7 @@
     CSSTokenizer tokenizer(testCase);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(UASheetMode, nullptr), nullptr);
+        range, CSSParserContext::create(UASheetMode), nullptr);
     EXPECT_TRUE(list.isValid());
   }
 }
@@ -209,7 +209,7 @@
     CSSTokenizer tokenizer(testCase);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+        range, CSSParserContext::create(HTMLStandardMode), nullptr);
     EXPECT_TRUE(list.isValid());
   }
 }
@@ -223,7 +223,7 @@
     CSSTokenizer tokenizer(testCase);
     CSSParserTokenRange range = tokenizer.tokenRange();
     CSSSelectorList list = CSSSelectorParser::parseSelector(
-        range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+        range, CSSParserContext::create(HTMLStandardMode), nullptr);
     EXPECT_FALSE(list.isValid());
   }
 }
@@ -231,7 +231,7 @@
 TEST(CSSSelectorParserTest, UnresolvedNamespacePrefix) {
   const char* testCases[] = {"ns|div", "div ns|div", "div ns|div "};
 
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* sheet = StyleSheetContents::create(context);
 
   for (auto testCase : testCases) {
@@ -260,7 +260,7 @@
       {"ns|*::cue(i)", "ns|*::cue(i)"},
       {"ns|*::shadow", "ns|*::shadow"}};
 
-  CSSParserContext context(HTMLStandardMode, nullptr);
+  CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* sheet = StyleSheetContents::create(context);
   sheet->parserAddNamespace("ns", "http://ns.org");
 
@@ -278,8 +278,8 @@
 TEST(CSSSelectorParserTest, InvalidDescendantCombinatorInDynamicProfile) {
   const char* testCases[] = {"div >>>> span", "div >>> span", "div >> span"};
 
-  CSSParserContext context(HTMLStandardMode, nullptr,
-                           CSSParserContext::DynamicProfile);
+  CSSParserContext* context = CSSParserContext::create(
+      HTMLStandardMode, CSSParserContext::DynamicProfile);
   StyleSheetContents* sheet = StyleSheetContents::create(context);
 
   for (auto testCase : testCases) {
@@ -296,8 +296,8 @@
   const char* testCases[] = {"div >>>> span", "div >> span", "div >> > span",
                              "div > >> span", "div > > > span"};
 
-  CSSParserContext context(HTMLStandardMode, nullptr,
-                           CSSParserContext::StaticProfile);
+  CSSParserContext* context = CSSParserContext::create(
+      HTMLStandardMode, CSSParserContext::StaticProfile);
   StyleSheetContents* sheet = StyleSheetContents::create(context);
 
   for (auto testCase : testCases) {
@@ -316,8 +316,8 @@
                                 {"div >/**/>> span", "div >>> span"},
                                 {"div >/**/>/**/> span", "div >>> span"}};
 
-  CSSParserContext context(HTMLStandardMode, nullptr,
-                           CSSParserContext::StaticProfile);
+  CSSParserContext* context = CSSParserContext::create(
+      HTMLStandardMode, CSSParserContext::StaticProfile);
   StyleSheetContents* sheet = StyleSheetContents::create(context);
 
   for (auto testCase : testCases) {
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPI.h b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPI.h
index ccafed6..3f73dadf 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPI.h
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPI.h
@@ -37,7 +37,7 @@
   // Parses a single CSS property and returns the corresponding CSSValue. If the
   // input is invalid it returns nullptr.
   static const CSSValue* parseSingleValue(CSSParserTokenRange&,
-                                          const CSSParserContext&);
+                                          const CSSParserContext*);
 };
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPICaretColor.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPICaretColor.cpp
index 4fcb91cc..6dcdcdb8 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPICaretColor.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPICaretColor.cpp
@@ -11,10 +11,10 @@
 
 const CSSValue* CSSPropertyAPICaretColor::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
-  return CSSPropertyParserHelpers::consumeColor(range, context.mode());
+  return CSSPropertyParserHelpers::consumeColor(range, context->mode());
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp
index 77f0bdc..25699b44 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp
@@ -25,7 +25,7 @@
 
 const CSSValue* CSSPropertyAPIClip::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
 
@@ -34,22 +34,22 @@
 
   CSSParserTokenRange args = CSSPropertyParserHelpers::consumeFunction(range);
   // rect(t, r, b, l) || rect(t r b l)
-  CSSValue* top = consumeClipComponent(args, context.mode());
+  CSSValue* top = consumeClipComponent(args, context->mode());
   if (!top)
     return nullptr;
   bool needsComma =
       CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args);
-  CSSValue* right = consumeClipComponent(args, context.mode());
+  CSSValue* right = consumeClipComponent(args, context->mode());
   if (!right ||
       (needsComma &&
        !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args)))
     return nullptr;
-  CSSValue* bottom = consumeClipComponent(args, context.mode());
+  CSSValue* bottom = consumeClipComponent(args, context->mode());
   if (!bottom ||
       (needsComma &&
        !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args)))
     return nullptr;
-  CSSValue* left = consumeClipComponent(args, context.mode());
+  CSSValue* left = consumeClipComponent(args, context->mode());
   if (!left || !args.atEnd())
     return nullptr;
   return CSSQuadValue::create(top, right, bottom, left,
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIColumnGap.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIColumnGap.cpp
index cc3374b..1934b94b 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIColumnGap.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIColumnGap.cpp
@@ -11,10 +11,10 @@
 
 const CSSValue* CSSPropertyAPIColumnGap::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueNormal)
     return CSSPropertyParserHelpers::consumeIdent(range);
-  return CSSPropertyParserHelpers::consumeLength(range, context.mode(),
+  return CSSPropertyParserHelpers::consumeLength(range, context->mode(),
                                                  ValueRangeNonNegative);
 }
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFlexBasis.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFlexBasis.cpp
index 6ed445b..6fd88d592 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFlexBasis.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFlexBasis.cpp
@@ -11,12 +11,12 @@
 
 const CSSValue* CSSPropertyAPIFlexBasis::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   // FIXME: Support intrinsic dimensions too.
   if (range.peek().id() == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
   return CSSPropertyParserHelpers::consumeLengthOrPercent(
-      range, context.mode(), ValueRangeNonNegative);
+      range, context->mode(), ValueRangeNonNegative);
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontSizeAdjust.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontSizeAdjust.cpp
index 4851691..2d0c853 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontSizeAdjust.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontSizeAdjust.cpp
@@ -11,7 +11,7 @@
 
 const CSSValue* CSSPropertyAPIFontSizeAdjust::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled());
   if (range.peek().id() == CSSValueNone)
     return CSSPropertyParserHelpers::consumeIdent(range);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp
index 90974388..f4ed8e96 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp
@@ -43,7 +43,7 @@
 
 const CSSValue* CSSPropertyAPIFontVariationSettings::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::cssVariableFontsEnabled());
   if (range.peek().id() == CSSValueNormal)
     return CSSPropertyParserHelpers::consumeIdent(range);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOffsetPosition.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOffsetPosition.cpp
index 74f2eb7..1fc270d4 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOffsetPosition.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOffsetPosition.cpp
@@ -13,16 +13,16 @@
 
 const CSSValue* CSSPropertyAPIOffsetPosition::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSValueID id = range.peek().id();
   if (id == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
   CSSValue* value = CSSPropertyParserHelpers::consumePosition(
-      range, context.mode(), CSSPropertyParserHelpers::UnitlessQuirk::Forbid);
+      range, context->mode(), CSSPropertyParserHelpers::UnitlessQuirk::Forbid);
 
   // Count when we receive a valid position other than 'auto'.
-  if (context.useCounter() && value && value->isValuePair())
-    context.useCounter()->count(UseCounter::CSSOffsetInEffect);
+  if (context->isUseCounterRecordingEnabled() && value && value->isValuePair())
+    context->useCounter()->count(UseCounter::CSSOffsetInEffect);
   return value;
 }
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOutlineOffset.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOutlineOffset.cpp
index 21d7f16..c33a01a0 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOutlineOffset.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIOutlineOffset.cpp
@@ -11,8 +11,8 @@
 
 const CSSValue* CSSPropertyAPIOutlineOffset::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
-  return CSSPropertyParserHelpers::consumeLength(range, context.mode(),
+    const CSSParserContext* context) {
+  return CSSPropertyParserHelpers::consumeLength(range, context->mode(),
                                                  ValueRangeAll);
 }
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPage.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPage.cpp
index ada74f5..ebe5612 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPage.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPage.cpp
@@ -10,7 +10,7 @@
 
 const CSSValue* CSSPropertyAPIPage::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
   return CSSPropertyParserHelpers::consumeCustomIdent(range);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPaintOrder.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPaintOrder.cpp
index 2b3e708..d53023b 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPaintOrder.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPaintOrder.cpp
@@ -11,7 +11,7 @@
 
 const CSSValue* CSSPropertyAPIPaintOrder::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueNormal)
     return CSSPropertyParserHelpers::consumeIdent(range);
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIRotate.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIRotate.cpp
index b163f5b..081aaa7a 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIRotate.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIRotate.cpp
@@ -12,7 +12,7 @@
 
 const CSSValue* CSSPropertyAPIRotate::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::cssIndependentTransformPropertiesEnabled());
   CSSValueList* list = CSSValueList::createSpaceSeparated();
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIScrollSnapCoordinate.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIScrollSnapCoordinate.cpp
index 286856f..9f2ce26 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIScrollSnapCoordinate.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIScrollSnapCoordinate.cpp
@@ -26,10 +26,10 @@
 
 const CSSValue* CSSPropertyAPIScrollSnapCoordinate::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueNone)
     return CSSPropertyParserHelpers::consumeIdent(range);
-  return consumePositionList(range, context.mode());
+  return consumePositionList(range, context->mode());
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPISize.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPISize.cpp
index afc34cc..7e871d2 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPISize.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPISize.cpp
@@ -18,7 +18,7 @@
 
 const CSSValue* CSSPropertyAPISize::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSValueList* result = CSSValueList::createSpaceSeparated();
 
   if (range.peek().id() == CSSValueAuto) {
@@ -27,9 +27,9 @@
   }
 
   if (CSSValue* width = CSSPropertyParserHelpers::consumeLength(
-          range, context.mode(), ValueRangeNonNegative)) {
+          range, context->mode(), ValueRangeNonNegative)) {
     CSSValue* height = CSSPropertyParserHelpers::consumeLength(
-        range, context.mode(), ValueRangeNonNegative);
+        range, context->mode(), ValueRangeNonNegative);
     result->append(*width);
     if (height)
       result->append(*height);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationColor.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationColor.cpp
index 2b7bf9d..bcc859a 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationColor.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationColor.cpp
@@ -12,9 +12,9 @@
 
 const CSSValue* CSSPropertyAPITextDecorationColor::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::css3TextDecorationsEnabled());
-  return CSSPropertyParserHelpers::consumeColor(range, context.mode());
+  return CSSPropertyParserHelpers::consumeColor(range, context->mode());
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationSkip.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationSkip.cpp
index 946f7be7..1f1be13 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationSkip.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextDecorationSkip.cpp
@@ -13,7 +13,7 @@
 
 const CSSValue* CSSPropertyAPITextDecorationSkip::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::css3TextDecorationsEnabled());
   CSSValueList* list = CSSValueList::createSpaceSeparated();
   while (true) {
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextUnderlinePosition.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextUnderlinePosition.cpp
index 5a6ce600..26e5ad0 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextUnderlinePosition.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITextUnderlinePosition.cpp
@@ -11,7 +11,7 @@
 
 const CSSValue* CSSPropertyAPITextUnderlinePosition::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   // auto | [ under || [ left | right ] ], but we only support auto | under
   // for now
   DCHECK(RuntimeEnabledFeatures::css3TextDecorationsEnabled());
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITransformOrigin.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITransformOrigin.cpp
index 2079cab..367d874 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITransformOrigin.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITransformOrigin.cpp
@@ -12,17 +12,17 @@
 
 const CSSValue* CSSPropertyAPITransformOrigin::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   CSSValue* resultX = nullptr;
   CSSValue* resultY = nullptr;
   if (CSSPropertyParserHelpers::consumeOneOrTwoValuedPosition(
-          range, context.mode(),
+          range, context->mode(),
           CSSPropertyParserHelpers::UnitlessQuirk::Forbid, resultX, resultY)) {
     CSSValueList* list = CSSValueList::createSpaceSeparated();
     list->append(*resultX);
     list->append(*resultY);
     CSSValue* resultZ = CSSPropertyParserHelpers::consumeLength(
-        range, context.mode(), ValueRangeAll);
+        range, context->mode(), ValueRangeAll);
     if (!resultZ) {
       resultZ =
           CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pixels);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITranslate.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITranslate.cpp
index 49a7b4d3..bb44369 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITranslate.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPITranslate.cpp
@@ -13,19 +13,19 @@
 
 const CSSValue* CSSPropertyAPITranslate::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   DCHECK(RuntimeEnabledFeatures::cssIndependentTransformPropertiesEnabled());
   CSSValue* translate = CSSPropertyParserHelpers::consumeLengthOrPercent(
-      range, context.mode(), ValueRangeAll);
+      range, context->mode(), ValueRangeAll);
   if (!translate)
     return nullptr;
   CSSValueList* list = CSSValueList::createSpaceSeparated();
   list->append(*translate);
   translate = CSSPropertyParserHelpers::consumeLengthOrPercent(
-      range, context.mode(), ValueRangeAll);
+      range, context->mode(), ValueRangeAll);
   if (translate) {
     list->append(*translate);
-    translate = CSSPropertyParserHelpers::consumeLength(range, context.mode(),
+    translate = CSSPropertyParserHelpers::consumeLength(range, context->mode(),
                                                         ValueRangeAll);
     if (translate)
       list->append(*translate);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitPadding.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitPadding.cpp
index 1bc0bda..bff2e7ff 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitPadding.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitPadding.cpp
@@ -12,9 +12,9 @@
 
 const CSSValue* CSSPropertyAPIWebkitPadding::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   return consumeLengthOrPercent(
-      range, context.mode(), ValueRangeNonNegative,
+      range, context->mode(), ValueRangeNonNegative,
       CSSPropertyParserHelpers::UnitlessQuirk::Forbid);
 }
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitTransformOriginZ.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitTransformOriginZ.cpp
index 44a31e29..4e9c360 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitTransformOriginZ.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWebkitTransformOriginZ.cpp
@@ -11,8 +11,8 @@
 
 const CSSValue* CSSPropertyAPIWebkitTransformOriginZ::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
-  return CSSPropertyParserHelpers::consumeLength(range, context.mode(),
+    const CSSParserContext* context) {
+  return CSSPropertyParserHelpers::consumeLength(range, context->mode(),
                                                  ValueRangeAll);
 }
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWillChange.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWillChange.cpp
index 1b18414..d4ed6bb 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWillChange.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIWillChange.cpp
@@ -13,7 +13,7 @@
 
 const CSSValue* CSSPropertyAPIWillChange::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
 
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZIndex.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZIndex.cpp
index a529cb9f..663e350 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZIndex.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZIndex.cpp
@@ -10,7 +10,7 @@
 
 const CSSValue* CSSPropertyAPIZIndex::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (range.peek().id() == CSSValueAuto)
     return CSSPropertyParserHelpers::consumeIdent(range);
   return CSSPropertyParserHelpers::consumeInteger(range);
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZoom.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZoom.cpp
index f467787..dc8a261 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZoom.cpp
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIZoom.cpp
@@ -12,7 +12,7 @@
 
 const CSSValue* CSSPropertyAPIZoom::parseSingleValue(
     CSSParserTokenRange& range,
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   const CSSParserToken& token = range.peek();
   CSSValue* zoom = nullptr;
   if (token.type() == IdentToken) {
@@ -26,17 +26,17 @@
           CSSPropertyParserHelpers::consumeNumber(range, ValueRangeNonNegative);
     }
   }
-  if (zoom && context.useCounter()) {
+  if (zoom && context->isUseCounterRecordingEnabled()) {
     if (!(token.id() == CSSValueNormal ||
           (token.type() == NumberToken &&
            toCSSPrimitiveValue(zoom)->getDoubleValue() == 1) ||
           (token.type() == PercentageToken &&
            toCSSPrimitiveValue(zoom)->getDoubleValue() == 100)))
-      context.useCounter()->count(UseCounter::CSSZoomNotEqualToOne);
+      context->useCounter()->count(UseCounter::CSSZoomNotEqualToOne);
     if (token.id() == CSSValueReset)
-      context.useCounter()->count(UseCounter::CSSZoomReset);
+      context->useCounter()->count(UseCounter::CSSZoomReset);
     if (token.id() == CSSValueDocument)
-      context.useCounter()->count(UseCounter::CSSZoomDocument);
+      context->useCounter()->count(UseCounter::CSSZoomDocument);
   }
   return zoom;
 }
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyDescriptor.h b/third_party/WebKit/Source/core/css/properties/CSSPropertyDescriptor.h
index ad1f73bc..d5cb6bd 100644
--- a/third_party/WebKit/Source/core/css/properties/CSSPropertyDescriptor.h
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyDescriptor.h
@@ -13,7 +13,7 @@
 // Stores function pointers matching those declared in CSSPropertyAPI.
 struct CSSPropertyDescriptor {
   const CSSValue* (*parseSingleValue)(CSSParserTokenRange&,
-                                      const CSSParserContext&);
+                                      const CSSParserContext*);
 
   // Stores whether or not this descriptor is for a valid property. Do not
   // access the contents of this descriptor unless this value is true.
diff --git a/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp b/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
index e548b3b1..7352193 100644
--- a/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
@@ -256,7 +256,7 @@
     if (resolver.resolveTokenRange(
             shorthandValue->variableDataValue()->tokens(),
             disallowAnimationTainted, tokens, isAnimationTainted)) {
-      CSSParserContext context(HTMLStandardMode, 0);
+      CSSParserContext* context = CSSParserContext::create(HTMLStandardMode);
 
       HeapVector<CSSProperty, 256> parsedProperties;
 
diff --git a/third_party/WebKit/Source/core/css/resolver/SharedStyleFinderTest.cpp b/third_party/WebKit/Source/core/css/resolver/SharedStyleFinderTest.cpp
index 497d6db6..8f0c48c 100644
--- a/third_party/WebKit/Source/core/css/resolver/SharedStyleFinderTest.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/SharedStyleFinderTest.cpp
@@ -43,7 +43,7 @@
 
   void addSelector(const String& selector) {
     StyleRuleBase* newRule =
-        CSSParser::parseRule(CSSParserContext(HTMLStandardMode, nullptr),
+        CSSParser::parseRule(CSSParserContext::create(HTMLStandardMode),
                              nullptr, selector + "{color:pink}");
     m_ruleSet->addStyleRule(static_cast<StyleRule*>(newRule),
                             RuleHasNoSpecialState);
diff --git a/third_party/WebKit/Source/core/dom/CSSSelectorWatch.cpp b/third_party/WebKit/Source/core/dom/CSSSelectorWatch.cpp
index 2570be9c..bd1ff5f 100644
--- a/third_party/WebKit/Source/core/dom/CSSSelectorWatch.cpp
+++ b/third_party/WebKit/Source/core/dom/CSSSelectorWatch.cpp
@@ -151,9 +151,10 @@
   StylePropertySet* callbackPropertySet =
       ImmutableStylePropertySet::create(nullptr, 0, UASheetMode);
 
+  CSSParserContext* context = CSSParserContext::create(UASheetMode);
   for (const auto& selector : selectors) {
-    CSSSelectorList selectorList = CSSParser::parseSelector(
-        CSSParserContext(UASheetMode, nullptr), nullptr, selector);
+    CSSSelectorList selectorList =
+        CSSParser::parseSelector(context, nullptr, selector);
     if (!selectorList.isValid())
       continue;
 
diff --git a/third_party/WebKit/Source/core/dom/ProcessingInstruction.cpp b/third_party/WebKit/Source/core/dom/ProcessingInstruction.cpp
index 51b80c1..f056f82d 100644
--- a/third_party/WebKit/Source/core/dom/ProcessingInstruction.cpp
+++ b/third_party/WebKit/Source/core/dom/ProcessingInstruction.cpp
@@ -195,7 +195,8 @@
   }
 
   DCHECK(m_isCSS);
-  CSSParserContext parserContext(document(), nullptr, baseURL, charset);
+  CSSParserContext* parserContext =
+      CSSParserContext::create(document(), baseURL, charset);
 
   StyleSheetContents* newSheet =
       StyleSheetContents::create(href, parserContext);
diff --git a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
index 0562cff..565e7cc 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -625,8 +625,8 @@
     return it->value.get();
 
   CSSSelectorList selectorList = CSSParser::parseSelector(
-      CSSParserContext(document, nullptr, KURL(), emptyString(),
-                       CSSParserContext::StaticProfile),
+      CSSParserContext::create(document, KURL(), emptyString(),
+                               CSSParserContext::StaticProfile),
       nullptr, selectors);
 
   if (!selectorList.first()) {
diff --git a/third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp b/third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp
index 4ca3176..e64ebf2 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp
@@ -22,8 +22,8 @@
       "<body><style>span::before { content: 'X' }</style><span></span></body>");
 
   CSSSelectorList selectorList = CSSParser::parseSelector(
-      CSSParserContext(*document, nullptr, KURL(), emptyString(),
-                       CSSParserContext::StaticProfile),
+      CSSParserContext::create(*document, KURL(), emptyString(),
+                               CSSParserContext::StaticProfile),
       nullptr, "span::before");
   std::unique_ptr<SelectorQuery> query =
       SelectorQuery::adopt(std::move(selectorList));
@@ -31,8 +31,8 @@
   EXPECT_EQ(nullptr, elm);
 
   selectorList = CSSParser::parseSelector(
-      CSSParserContext(*document, nullptr, KURL(), emptyString(),
-                       CSSParserContext::StaticProfile),
+      CSSParserContext::create(*document, KURL(), emptyString(),
+                               CSSParserContext::StaticProfile),
       nullptr, "span");
   query = SelectorQuery::adopt(std::move(selectorList));
   elm = query->queryFirst(*document);
@@ -49,8 +49,8 @@
   document->body()->beginParsingChildren();
 
   CSSSelectorList selectorList = CSSParser::parseSelector(
-      CSSParserContext(*document, nullptr, KURL(), emptyString(),
-                       CSSParserContext::StaticProfile),
+      CSSParserContext::create(*document, KURL(), emptyString(),
+                               CSSParserContext::StaticProfile),
       nullptr, "p:last-of-type");
   std::unique_ptr<SelectorQuery> query =
       SelectorQuery::adopt(std::move(selectorList));
diff --git a/third_party/WebKit/Source/core/dom/StyleEngine.cpp b/third_party/WebKit/Source/core/dom/StyleEngine.cpp
index a708c8a..264afe1 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngine.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngine.cpp
@@ -147,7 +147,7 @@
     return *m_inspectorStyleSheet;
 
   StyleSheetContents* contents =
-      StyleSheetContents::create(CSSParserContext(*m_document, nullptr));
+      StyleSheetContents::create(CSSParserContext::create(*m_document));
   m_inspectorStyleSheet = CSSStyleSheet::create(contents, *m_document);
   markDocumentDirty();
   // TODO(rune@opera.com): Making the active stylesheets up-to-date here is
diff --git a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
index 6487218..6bdeb81 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
@@ -49,7 +49,7 @@
 StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope,
                                                const String& cssText) {
   StyleSheetContents* sheet =
-      StyleSheetContents::create(CSSParserContext(HTMLStandardMode, nullptr));
+      StyleSheetContents::create(CSSParserContext::create(HTMLStandardMode));
   sheet->parseString(cssText);
   HeapHashSet<Member<RuleSet>> ruleSets;
   RuleSet& ruleSet = sheet->ensureRuleSet(MediaQueryEvaluator(),
@@ -64,7 +64,7 @@
 
 TEST_F(StyleEngineTest, DocumentDirtyAfterInject) {
   StyleSheetContents* parsedSheet =
-      StyleSheetContents::create(CSSParserContext(document(), nullptr));
+      StyleSheetContents::create(CSSParserContext::create(document()));
   parsedSheet->parseString("div {}");
   styleEngine().injectAuthorSheet(parsedSheet);
   document().view()->updateAllLifecyclePhases();
@@ -86,7 +86,7 @@
   unsigned beforeCount = styleEngine().styleForElementCount();
 
   StyleSheetContents* parsedSheet =
-      StyleSheetContents::create(CSSParserContext(document(), nullptr));
+      StyleSheetContents::create(CSSParserContext::create(document()));
   parsedSheet->parseString("#t1 { color: green }");
   styleEngine().injectAuthorSheet(parsedSheet);
   document().view()->updateAllLifecyclePhases();
diff --git a/third_party/WebKit/Source/core/html/HTMLContentElement.cpp b/third_party/WebKit/Source/core/html/HTMLContentElement.cpp
index 23f97fa..62331109 100644
--- a/third_party/WebKit/Source/core/html/HTMLContentElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLContentElement.cpp
@@ -63,7 +63,7 @@
   DCHECK(m_shouldParseSelect);
 
   m_selectorList = CSSParser::parseSelector(
-      CSSParserContext(document(), nullptr), nullptr, m_select);
+      CSSParserContext::create(document()), nullptr, m_select);
   m_shouldParseSelect = false;
   m_isValidSelector = validateSelect();
   if (!m_isValidSelector)
diff --git a/third_party/WebKit/Source/core/html/LinkStyle.cpp b/third_party/WebKit/Source/core/html/LinkStyle.cpp
index d69eb9f..a8f7bee 100644
--- a/third_party/WebKit/Source/core/html/LinkStyle.cpp
+++ b/third_party/WebKit/Source/core/html/LinkStyle.cpp
@@ -107,8 +107,8 @@
     }
   }
 
-  CSSParserContext parserContext(m_owner->document(), nullptr, baseURL,
-                                 charset);
+  CSSParserContext* parserContext =
+      CSSParserContext::create(m_owner->document(), baseURL, charset);
 
   DEFINE_STATIC_LOCAL(EnumerationHistogram, restoredCachedStyleSheetHistogram,
                       ("Blink.RestoredCachedStyleSheet", 2));
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasFontCache.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasFontCache.cpp
index bc3cdcf..664b9dc 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasFontCache.cpp
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasFontCache.cpp
@@ -88,7 +88,7 @@
     m_fontLRUList.add(fontString);
   } else {
     parsedStyle = MutableStylePropertySet::create(HTMLStandardMode);
-    CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true, 0);
+    CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true);
     if (parsedStyle->isEmpty())
       return nullptr;
     // According to
diff --git a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
index a9cece0..e9b1379 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
@@ -110,8 +110,8 @@
   StyleSheetContents* styleSheetContents =
       StyleSheetContents::create(strictCSSParserContext());
   String text = " div { " + shorthand + ": " + oldText + "; }";
-  CSSParser::parseSheet(CSSParserContext(*document, nullptr),
-                        styleSheetContents, text);
+  CSSParser::parseSheet(CSSParserContext::create(*document), styleSheetContents,
+                        text);
 
   CSSStyleSheet* styleSheet = CSSStyleSheet::create(styleSheetContents);
   CSSStyleRule* rule = toCSSStyleRule(styleSheet->item(0));
diff --git a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
index 5aa01a3..6f0b8ae 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
@@ -66,8 +66,8 @@
 
 using namespace blink;
 
-static CSSParserContext parserContextForDocument(Document* document) {
-  return document ? CSSParserContext(*document, nullptr)
+static const CSSParserContext* parserContextForDocument(Document* document) {
+  return document ? CSSParserContext::create(*document)
                   : strictCSSParserContext();
 }
 
diff --git a/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.cpp b/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.cpp
index 41dea66..fe50b210 100644
--- a/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.cpp
@@ -186,7 +186,7 @@
 }
 
 StyleSheetContents* CSSStyleSheetResource::restoreParsedStyleSheet(
-    const CSSParserContext& context) {
+    const CSSParserContext* context) {
   if (!m_parsedStyleSheetCache)
     return nullptr;
   if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
@@ -199,7 +199,7 @@
 
   // Contexts must be identical so we know we would get the same exact result if
   // we parsed again.
-  if (m_parsedStyleSheetCache->parserContext() != context)
+  if (*m_parsedStyleSheetCache->parserContext() != *context)
     return nullptr;
 
   return m_parsedStyleSheetCache;
diff --git a/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.h b/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.h
index 60cc69a7..38ac0488 100644
--- a/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.h
+++ b/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResource.h
@@ -53,7 +53,7 @@
 
   void didAddClient(ResourceClient*) override;
 
-  StyleSheetContents* restoreParsedStyleSheet(const CSSParserContext&);
+  StyleSheetContents* restoreParsedStyleSheet(const CSSParserContext*);
   void saveParsedStyleSheet(StyleSheetContents*);
 
   void appendData(const char* data, size_t length) override;
diff --git a/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResourceTest.cpp b/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResourceTest.cpp
index cfbbf10..571a8579 100644
--- a/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/CSSStyleSheetResourceTest.cpp
@@ -79,7 +79,7 @@
       ResourceResponse(cssURL, "style/css", 0, nullAtom, String()), nullptr);
   cssResource->finish();
 
-  CSSParserContext parserContext(HTMLStandardMode, nullptr);
+  CSSParserContext* parserContext = CSSParserContext::create(HTMLStandardMode);
   StyleSheetContents* contents = StyleSheetContents::create(parserContext);
   CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document());
   EXPECT_TRUE(sheet);
diff --git a/third_party/WebKit/Source/core/svg/SVGLength.cpp b/third_party/WebKit/Source/core/svg/SVGLength.cpp
index 91b9d28..aaebeca 100644
--- a/third_party/WebKit/Source/core/svg/SVGLength.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLength.cpp
@@ -140,7 +140,8 @@
     return SVGParseStatus::NoError;
   }
 
-  CSSParserContext svgParserContext(SVGAttributeMode, nullptr);
+  CSSParserContext* svgParserContext =
+      CSSParserContext::create(SVGAttributeMode);
   const CSSValue* parsed =
       CSSParser::parseSingleValue(CSSPropertyX, string, svgParserContext);
   if (!parsed || !parsed->isPrimitiveValue())
diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
index 426c5b1e..b4be242 100644
--- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
@@ -402,7 +402,7 @@
 
   const CSSValue* filterValue =
       CSSParser::parseSingleValue(CSSPropertyFilter, filterString,
-                                  CSSParserContext(HTMLStandardMode, nullptr));
+                                  CSSParserContext::create(HTMLStandardMode));
 
   if (!filterValue || filterValue->isInitialValue() ||
       filterValue->isInheritedValue())
diff --git a/third_party/WebKit/Source/web/WebDocument.cpp b/third_party/WebKit/Source/web/WebDocument.cpp
index 9ccdab7..c233eef2 100644
--- a/third_party/WebKit/Source/web/WebDocument.cpp
+++ b/third_party/WebKit/Source/web/WebDocument.cpp
@@ -186,7 +186,7 @@
   Document* document = unwrap<Document>();
   DCHECK(document);
   StyleSheetContents* parsedSheet =
-      StyleSheetContents::create(CSSParserContext(*document, nullptr));
+      StyleSheetContents::create(CSSParserContext::create(*document));
   parsedSheet->parseString(sourceCode);
   document->styleEngine().injectAuthorSheet(parsedSheet);
 }