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