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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserMode.h

Issue 2580793005: Split the CSSParserContext class out of CSSParserMode into its own file. (Closed)
Patch Set: one extra missing include Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * Copyright (C) 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above 9 * 1. Redistributions of source code must retain the above
10 * copyright notice, this list of conditions and the following 10 * copyright notice, this list of conditions and the following
(...skipping 13 matching lines...) Expand all
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef CSSParserMode_h 31 #ifndef CSSParserMode_h
32 #define CSSParserMode_h 32 #define CSSParserMode_h
33 33
34 #include "core/CoreExport.h"
35 #include "core/fetch/ResourceLoaderOptions.h"
36 #include "platform/weborigin/KURL.h"
37 #include "platform/weborigin/Referrer.h"
38
39 namespace blink { 34 namespace blink {
40 35
41 class Document;
42
43 // Must not grow beyond 3 bits, due to packing in StylePropertySet. 36 // Must not grow beyond 3 bits, due to packing in StylePropertySet.
44 enum CSSParserMode { 37 enum CSSParserMode {
45 HTMLStandardMode, 38 HTMLStandardMode,
46 HTMLQuirksMode, 39 HTMLQuirksMode,
47 // HTML attributes are parsed in quirks mode but also allows internal 40 // HTML attributes are parsed in quirks mode but also allows internal
48 // properties and values. 41 // properties and values.
49 HTMLAttributeMode, 42 HTMLAttributeMode,
50 // SVG attributes are parsed in quirks mode but rules differ slightly. 43 // SVG attributes are parsed in quirks mode but rules differ slightly.
51 SVGAttributeMode, 44 SVGAttributeMode,
52 // @viewport/@font-face rules are specially tagged in StylePropertySet so 45 // @viewport/@font-face rules are specially tagged in StylePropertySet so
(...skipping 19 matching lines...) Expand all
72 65
73 inline bool isCSSViewportParsingEnabledForMode(CSSParserMode mode) { 66 inline bool isCSSViewportParsingEnabledForMode(CSSParserMode mode) {
74 return mode == CSSViewportRuleMode; 67 return mode == CSSViewportRuleMode;
75 } 68 }
76 69
77 inline bool isUseCounterEnabledForMode(CSSParserMode mode) { 70 inline bool isUseCounterEnabledForMode(CSSParserMode mode) {
78 // We don't count the UA style sheet in our statistics. 71 // We don't count the UA style sheet in our statistics.
79 return mode != UASheetMode; 72 return mode != UASheetMode;
80 } 73 }
81 74
82 class UseCounter;
83
84 class CORE_EXPORT CSSParserContext {
85 USING_FAST_MALLOC(CSSParserContext);
86
87 public:
88 // https://drafts.csswg.org/selectors/#profiles
89 enum SelectorProfile { DynamicProfile, StaticProfile };
90
91 CSSParserContext(CSSParserMode,
92 UseCounter*,
93 SelectorProfile = DynamicProfile);
94 // FIXME: We shouldn't need the UseCounter argument as we could infer it from
95 // the Document but some callers want to disable use counting (e.g. the
96 // WebInspector).
97 CSSParserContext(const Document&,
98 UseCounter*,
99 const KURL& baseURL = KURL(),
100 const String& charset = emptyString(),
101 SelectorProfile = DynamicProfile);
102 // FIXME: This constructor shouldn't exist if we properly piped the UseCounter
103 // through the CSS subsystem. Currently the UseCounter life time is too crazy
104 // and we need a way to override it.
105 CSSParserContext(const CSSParserContext&, UseCounter*);
106
107 bool operator==(const CSSParserContext&) const;
108 bool operator!=(const CSSParserContext& other) const {
109 return !(*this == other);
110 }
111
112 CSSParserMode mode() const { return m_mode; }
113 CSSParserMode matchMode() const { return m_matchMode; }
114 const KURL& baseURL() const { return m_baseURL; }
115 const String& charset() const { return m_charset; }
116 const Referrer& referrer() const { return m_referrer; }
117 bool isHTMLDocument() const { return m_isHTMLDocument; }
118 bool isDynamicProfile() const { return m_profile == DynamicProfile; }
119 bool isStaticProfile() const { return m_profile == StaticProfile; }
120
121 // This quirk is to maintain compatibility with Android apps built on
122 // the Android SDK prior to and including version 18. Presumably, this
123 // can be removed any time after 2015. See http://crbug.com/277157.
124 bool useLegacyBackgroundSizeShorthandBehavior() const {
125 return m_useLegacyBackgroundSizeShorthandBehavior;
126 }
127
128 // FIXME: These setters shouldn't exist, however the current lifetime of
129 // CSSParserContext is not well understood and thus we sometimes need to
130 // override these fields.
131 void setMode(CSSParserMode mode) { m_mode = mode; }
132 void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; }
133 void setCharset(const String& charset) { m_charset = charset; }
134 void setReferrer(const Referrer& referrer) { m_referrer = referrer; }
135
136 KURL completeURL(const String& url) const;
137
138 // This may return nullptr if counting is disabled.
139 // See comments on constructors.
140 UseCounter* useCounter() const { return m_useCounter; }
141
142 ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy() const {
143 return m_shouldCheckContentSecurityPolicy;
144 }
145
146 private:
147 KURL m_baseURL;
148 String m_charset;
149 CSSParserMode m_mode;
150 CSSParserMode m_matchMode;
151 SelectorProfile m_profile = DynamicProfile;
152 Referrer m_referrer;
153 bool m_isHTMLDocument;
154 bool m_useLegacyBackgroundSizeShorthandBehavior;
155 ContentSecurityPolicyDisposition m_shouldCheckContentSecurityPolicy;
156
157 UseCounter* m_useCounter;
158 };
159
160 CORE_EXPORT const CSSParserContext& strictCSSParserContext();
161
162 } // namespace blink 75 } // namespace blink
163 76
164 #endif // CSSParserMode_h 77 #endif // CSSParserMode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698