OLD | NEW |
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 #ifndef CSSParserContext_h | 5 #ifndef CSSParserContext_h |
6 #define CSSParserContext_h | 6 #define CSSParserContext_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/css/parser/CSSParserMode.h" | 9 #include "core/css/parser/CSSParserMode.h" |
10 #include "core/fetch/ResourceLoaderOptions.h" | 10 #include "core/fetch/ResourceLoaderOptions.h" |
11 #include "platform/weborigin/KURL.h" | 11 #include "platform/weborigin/KURL.h" |
12 #include "platform/weborigin/Referrer.h" | 12 #include "platform/weborigin/Referrer.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
| 16 class CSSStyleSheet; |
16 class Document; | 17 class Document; |
| 18 class StyleSheetContents; |
17 class UseCounter; | 19 class UseCounter; |
18 | 20 |
19 class CORE_EXPORT CSSParserContext { | 21 class CORE_EXPORT CSSParserContext |
20 USING_FAST_MALLOC(CSSParserContext); | 22 : public GarbageCollectedFinalized<CSSParserContext> { |
21 | |
22 public: | 23 public: |
23 // https://drafts.csswg.org/selectors/#profiles | 24 // https://drafts.csswg.org/selectors/#profiles |
24 enum SelectorProfile { DynamicProfile, StaticProfile }; | 25 enum SelectorProfile { DynamicProfile, StaticProfile }; |
25 | 26 |
26 CSSParserContext(CSSParserMode, | 27 // All three of these factories copy the context and override the current |
27 UseCounter*, | 28 // UseCounter handle. |
28 SelectorProfile = DynamicProfile); | 29 static CSSParserContext* createWithStyleSheet(const CSSParserContext*, |
| 30 const CSSStyleSheet*); |
| 31 static CSSParserContext* createWithStyleSheetContents( |
| 32 const CSSParserContext*, |
| 33 const StyleSheetContents*); |
| 34 // FIXME: This constructor shouldn't exist if we properly piped the UseCounter |
| 35 // through the CSS subsystem. Currently the UseCounter life time is too crazy |
| 36 // and we need a way to override it. |
| 37 static CSSParserContext* create(const CSSParserContext* other, UseCounter*); |
| 38 |
| 39 static CSSParserContext* create(CSSParserMode, |
| 40 SelectorProfile = DynamicProfile, |
| 41 UseCounter* = nullptr); |
29 // FIXME: We shouldn't need the UseCounter argument as we could infer it from | 42 // FIXME: We shouldn't need the UseCounter argument as we could infer it from |
30 // the Document but some callers want to disable use counting (e.g. the | 43 // the Document but some callers want to disable use counting (e.g. the |
31 // WebInspector). | 44 // WebInspector). |
32 CSSParserContext(const Document&, | 45 static CSSParserContext* create(const Document&, UseCounter*); |
33 UseCounter*, | 46 static CSSParserContext* create(const Document&, |
34 const KURL& baseURL = KURL(), | 47 const KURL& baseURLOverride = KURL(), |
35 const String& charset = emptyString(), | 48 const String& charset = emptyString(), |
36 SelectorProfile = DynamicProfile); | 49 SelectorProfile = DynamicProfile, |
37 // FIXME: This constructor shouldn't exist if we properly piped the UseCounter | 50 UseCounter* = nullptr); |
38 // through the CSS subsystem. Currently the UseCounter life time is too crazy | |
39 // and we need a way to override it. | |
40 CSSParserContext(const CSSParserContext&, UseCounter*); | |
41 | 51 |
42 bool operator==(const CSSParserContext&) const; | 52 bool operator==(const CSSParserContext&) const; |
43 bool operator!=(const CSSParserContext& other) const { | 53 bool operator!=(const CSSParserContext& other) const { |
44 return !(*this == other); | 54 return !(*this == other); |
45 } | 55 } |
46 | 56 |
47 CSSParserMode mode() const { return m_mode; } | 57 CSSParserMode mode() const { return m_mode; } |
48 CSSParserMode matchMode() const { return m_matchMode; } | 58 CSSParserMode matchMode() const { return m_matchMode; } |
49 const KURL& baseURL() const { return m_baseURL; } | 59 const KURL& baseURL() const { return m_baseURL; } |
50 const String& charset() const { return m_charset; } | 60 const String& charset() const { return m_charset; } |
(...skipping 15 matching lines...) Expand all Loading... |
66 void setMode(CSSParserMode mode) { m_mode = mode; } | 76 void setMode(CSSParserMode mode) { m_mode = mode; } |
67 void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; } | 77 void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; } |
68 void setCharset(const String& charset) { m_charset = charset; } | 78 void setCharset(const String& charset) { m_charset = charset; } |
69 void setReferrer(const Referrer& referrer) { m_referrer = referrer; } | 79 void setReferrer(const Referrer& referrer) { m_referrer = referrer; } |
70 | 80 |
71 KURL completeURL(const String& url) const; | 81 KURL completeURL(const String& url) const; |
72 | 82 |
73 // This may return nullptr if counting is disabled. | 83 // This may return nullptr if counting is disabled. |
74 // See comments on constructors. | 84 // See comments on constructors. |
75 UseCounter* useCounter() const { return m_useCounter; } | 85 UseCounter* useCounter() const { return m_useCounter; } |
| 86 bool isUseCounterRecordingEnabled() const { return m_useCounter; } |
76 | 87 |
77 ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy() const { | 88 ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy() const { |
78 return m_shouldCheckContentSecurityPolicy; | 89 return m_shouldCheckContentSecurityPolicy; |
79 } | 90 } |
80 | 91 |
| 92 DEFINE_INLINE_TRACE() {} |
| 93 |
81 private: | 94 private: |
| 95 CSSParserContext(const KURL& baseURL, |
| 96 const String& charset, |
| 97 CSSParserMode, |
| 98 CSSParserMode matchMode, |
| 99 SelectorProfile, |
| 100 const Referrer&, |
| 101 bool isHTMLDocument, |
| 102 bool useLegacyBackgroundSizeShorthandBehavior, |
| 103 ContentSecurityPolicyDisposition, |
| 104 UseCounter*); |
| 105 |
82 KURL m_baseURL; | 106 KURL m_baseURL; |
83 String m_charset; | 107 String m_charset; |
84 CSSParserMode m_mode; | 108 CSSParserMode m_mode; |
85 CSSParserMode m_matchMode; | 109 CSSParserMode m_matchMode; |
86 SelectorProfile m_profile = DynamicProfile; | 110 SelectorProfile m_profile = DynamicProfile; |
87 Referrer m_referrer; | 111 Referrer m_referrer; |
88 bool m_isHTMLDocument; | 112 bool m_isHTMLDocument; |
89 bool m_useLegacyBackgroundSizeShorthandBehavior; | 113 bool m_useLegacyBackgroundSizeShorthandBehavior; |
90 ContentSecurityPolicyDisposition m_shouldCheckContentSecurityPolicy; | 114 ContentSecurityPolicyDisposition m_shouldCheckContentSecurityPolicy; |
91 | 115 |
92 UseCounter* m_useCounter; | 116 UseCounter* m_useCounter; |
93 }; | 117 }; |
94 | 118 |
95 CORE_EXPORT const CSSParserContext& strictCSSParserContext(); | 119 CORE_EXPORT const CSSParserContext* strictCSSParserContext(); |
96 | 120 |
97 } // namespace blink | 121 } // namespace blink |
98 | 122 |
99 #endif // CSSParserMode_h | 123 #endif // CSSParserContext_h |
OLD | NEW |