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

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

Issue 2671173002: Change CSSParserContext to have a Document handle (vs UseCounter). (Closed)
Patch Set: fix todo style Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/parser/CSSParserContext.h" 5 #include "core/css/parser/CSSParserContext.h"
6 6
7 #include "core/css/CSSStyleSheet.h" 7 #include "core/css/CSSStyleSheet.h"
8 #include "core/css/StyleSheetContents.h" 8 #include "core/css/StyleSheetContents.h"
9 #include "core/frame/FrameHost.h"
9 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
10 #include "core/frame/csp/ContentSecurityPolicy.h" 11 #include "core/frame/csp/ContentSecurityPolicy.h"
11 #include "core/html/imports/HTMLImportsController.h" 12 #include "core/html/imports/HTMLImportsController.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 // static 16 // static
16 CSSParserContext* CSSParserContext::createWithStyleSheet( 17 CSSParserContext* CSSParserContext::createWithStyleSheet(
17 const CSSParserContext* other, 18 const CSSParserContext* other,
18 const CSSStyleSheet* styleSheet) { 19 const CSSStyleSheet* styleSheet) {
19 return CSSParserContext::create(other, UseCounter::getFrom(styleSheet)); 20 return CSSParserContext::create(
21 other, CSSStyleSheet::singleOwnerDocument(styleSheet));
20 } 22 }
21 23
22 // static 24 // static
23 CSSParserContext* CSSParserContext::createWithStyleSheetContents( 25 CSSParserContext* CSSParserContext::createWithStyleSheetContents(
24 const CSSParserContext* other, 26 const CSSParserContext* other,
25 const StyleSheetContents* styleSheetContents) { 27 const StyleSheetContents* styleSheetContents) {
26 return CSSParserContext::create(other, 28 return CSSParserContext::create(
27 UseCounter::getFrom(styleSheetContents)); 29 other, StyleSheetContents::singleOwnerDocument(styleSheetContents));
28 } 30 }
29 31
30 // static 32 // static
31 CSSParserContext* CSSParserContext::create(const CSSParserContext* other, 33 CSSParserContext* CSSParserContext::create(const CSSParserContext* other,
32 UseCounter* useCounter) { 34 const Document* m_document) {
33 return new CSSParserContext( 35 return new CSSParserContext(
34 other->m_baseURL, other->m_charset, other->m_mode, other->m_matchMode, 36 other->m_baseURL, other->m_charset, other->m_mode, other->m_matchMode,
35 other->m_profile, other->m_referrer, other->m_isHTMLDocument, 37 other->m_profile, other->m_referrer, other->m_isHTMLDocument,
36 other->m_useLegacyBackgroundSizeShorthandBehavior, 38 other->m_useLegacyBackgroundSizeShorthandBehavior,
37 other->m_shouldCheckContentSecurityPolicy, useCounter); 39 other->m_shouldCheckContentSecurityPolicy, m_document);
38 } 40 }
39 41
40 // static 42 // static
41 CSSParserContext* CSSParserContext::create(CSSParserMode mode, 43 CSSParserContext* CSSParserContext::create(CSSParserMode mode,
42 SelectorProfile profile, 44 SelectorProfile profile,
43 UseCounter* useCounter) { 45 const Document* m_document) {
44 return new CSSParserContext(KURL(), emptyString, mode, mode, profile, 46 return new CSSParserContext(KURL(), emptyString, mode, mode, profile,
45 Referrer(), false, false, 47 Referrer(), false, false,
46 DoNotCheckContentSecurityPolicy, useCounter); 48 DoNotCheckContentSecurityPolicy, m_document);
47 } 49 }
48 50
49 // static 51 // static
50 CSSParserContext* CSSParserContext::create(const Document& document, 52 CSSParserContext* CSSParserContext::create(const Document& document,
51 UseCounter* useCounter) { 53 const Document* m_document) {
52 return CSSParserContext::create(document, KURL(), emptyString, DynamicProfile, 54 return CSSParserContext::create(document, KURL(), emptyString, DynamicProfile,
53 useCounter); 55 m_document);
54 } 56 }
55 57
56 // static 58 // static
57 CSSParserContext* CSSParserContext::create(const Document& document, 59 CSSParserContext* CSSParserContext::create(const Document& document,
58 const KURL& baseURLOverride, 60 const KURL& baseURLOverride,
59 const String& charset, 61 const String& charset,
60 SelectorProfile profile, 62 SelectorProfile profile,
61 UseCounter* useCounter) { 63 const Document* m_document) {
62 const KURL baseURL = 64 const KURL baseURL =
63 baseURLOverride.isNull() ? document.baseURL() : baseURLOverride; 65 baseURLOverride.isNull() ? document.baseURL() : baseURLOverride;
64 66
65 CSSParserMode mode = 67 CSSParserMode mode =
66 document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode; 68 document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode;
67 CSSParserMode matchMode; 69 CSSParserMode matchMode;
68 if (HTMLImportsController* importsController = document.importsController()) { 70 if (HTMLImportsController* importsController = document.importsController()) {
69 matchMode = importsController->master()->inQuirksMode() ? HTMLQuirksMode 71 matchMode = importsController->master()->inQuirksMode() ? HTMLQuirksMode
70 : HTMLStandardMode; 72 : HTMLStandardMode;
71 } else { 73 } else {
(...skipping 10 matching lines...) Expand all
82 84
83 ContentSecurityPolicyDisposition policyDisposition; 85 ContentSecurityPolicyDisposition policyDisposition;
84 if (ContentSecurityPolicy::shouldBypassMainWorld(&document)) 86 if (ContentSecurityPolicy::shouldBypassMainWorld(&document))
85 policyDisposition = DoNotCheckContentSecurityPolicy; 87 policyDisposition = DoNotCheckContentSecurityPolicy;
86 else 88 else
87 policyDisposition = CheckContentSecurityPolicy; 89 policyDisposition = CheckContentSecurityPolicy;
88 90
89 return new CSSParserContext(baseURL, charset, mode, matchMode, profile, 91 return new CSSParserContext(baseURL, charset, mode, matchMode, profile,
90 referrer, document.isHTMLDocument(), 92 referrer, document.isHTMLDocument(),
91 useLegacyBackgroundSizeShorthandBehavior, 93 useLegacyBackgroundSizeShorthandBehavior,
92 policyDisposition, useCounter); 94 policyDisposition, m_document);
93 } 95 }
94 96
95 CSSParserContext::CSSParserContext( 97 CSSParserContext::CSSParserContext(
96 const KURL& baseURL, 98 const KURL& baseURL,
97 const String& charset, 99 const String& charset,
98 CSSParserMode mode, 100 CSSParserMode mode,
99 CSSParserMode matchMode, 101 CSSParserMode matchMode,
100 SelectorProfile profile, 102 SelectorProfile profile,
101 const Referrer& referrer, 103 const Referrer& referrer,
102 bool isHTMLDocument, 104 bool isHTMLDocument,
103 bool useLegacyBackgroundSizeShorthandBehavior, 105 bool useLegacyBackgroundSizeShorthandBehavior,
104 ContentSecurityPolicyDisposition policyDisposition, 106 ContentSecurityPolicyDisposition policyDisposition,
105 UseCounter* useCounter) 107 const Document* m_document)
106 : m_baseURL(baseURL), 108 : m_baseURL(baseURL),
107 m_charset(charset), 109 m_charset(charset),
108 m_mode(mode), 110 m_mode(mode),
109 m_matchMode(matchMode), 111 m_matchMode(matchMode),
110 m_profile(profile), 112 m_profile(profile),
111 m_referrer(referrer), 113 m_referrer(referrer),
112 m_isHTMLDocument(isHTMLDocument), 114 m_isHTMLDocument(isHTMLDocument),
113 m_useLegacyBackgroundSizeShorthandBehavior( 115 m_useLegacyBackgroundSizeShorthandBehavior(
114 useLegacyBackgroundSizeShorthandBehavior), 116 useLegacyBackgroundSizeShorthandBehavior),
115 m_shouldCheckContentSecurityPolicy(policyDisposition), 117 m_shouldCheckContentSecurityPolicy(policyDisposition),
116 m_useCounter(useCounter) {} 118 m_document(m_document) {}
117 119
118 bool CSSParserContext::operator==(const CSSParserContext& other) const { 120 bool CSSParserContext::operator==(const CSSParserContext& other) const {
119 return m_baseURL == other.m_baseURL && m_charset == other.m_charset && 121 return m_baseURL == other.m_baseURL && m_charset == other.m_charset &&
120 m_mode == other.m_mode && m_matchMode == other.m_matchMode && 122 m_mode == other.m_mode && m_matchMode == other.m_matchMode &&
121 m_profile == other.m_profile && 123 m_profile == other.m_profile &&
122 m_isHTMLDocument == other.m_isHTMLDocument && 124 m_isHTMLDocument == other.m_isHTMLDocument &&
123 m_useLegacyBackgroundSizeShorthandBehavior == 125 m_useLegacyBackgroundSizeShorthandBehavior ==
124 other.m_useLegacyBackgroundSizeShorthandBehavior; 126 other.m_useLegacyBackgroundSizeShorthandBehavior;
125 } 127 }
126 128
127 const CSSParserContext* strictCSSParserContext() { 129 const CSSParserContext* strictCSSParserContext() {
128 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, 130 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext,
129 (CSSParserContext::create(HTMLStandardMode))); 131 (CSSParserContext::create(HTMLStandardMode)));
130 return &strictContext; 132 return &strictContext;
131 } 133 }
132 134
133 KURL CSSParserContext::completeURL(const String& url) const { 135 KURL CSSParserContext::completeURL(const String& url) const {
134 if (url.isNull()) 136 if (url.isNull())
135 return KURL(); 137 return KURL();
136 if (charset().isEmpty()) 138 if (charset().isEmpty())
137 return KURL(baseURL(), url); 139 return KURL(baseURL(), url);
138 return KURL(baseURL(), url, charset()); 140 return KURL(baseURL(), url, charset());
139 } 141 }
140 142
143 void CSSParserContext::count(UseCounter::Feature feature) const {
144 if (isUseCounterRecordingEnabled())
145 UseCounter::count(*m_document, feature);
146 }
147
148 void CSSParserContext::count(CSSParserMode mode, CSSPropertyID property) const {
149 if (isUseCounterRecordingEnabled() && m_document->frameHost()) {
150 UseCounter* useCounter = &m_document->frameHost()->useCounter();
151 if (useCounter)
152 useCounter->count(mode, property);
153 }
154 }
155
156 bool CSSParserContext::isDocumentHandleEqual(const Document* other) const {
157 return m_document.get() == other;
158 }
159
160 DEFINE_TRACE(CSSParserContext) {
161 visitor->trace(m_document);
162 }
163
141 } // namespace blink 164 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698