File: CSSParserContext.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (123 lines) | stat: -rw-r--r-- 4,808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CSSParserContext_h
#define CSSParserContext_h

#include "core/CoreExport.h"
#include "core/css/parser/CSSParserMode.h"
#include "core/fetch/ResourceLoaderOptions.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/Referrer.h"

namespace blink {

class CSSStyleSheet;
class Document;
class StyleSheetContents;
class UseCounter;

class CORE_EXPORT CSSParserContext
    : public GarbageCollectedFinalized<CSSParserContext> {
 public:
  // https://drafts.csswg.org/selectors/#profiles
  enum SelectorProfile { DynamicProfile, StaticProfile };

  // 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.
  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 {
    return !(*this == other);
  }

  CSSParserMode mode() const { return m_mode; }
  CSSParserMode matchMode() const { return m_matchMode; }
  const KURL& baseURL() const { return m_baseURL; }
  const String& charset() const { return m_charset; }
  const Referrer& referrer() const { return m_referrer; }
  bool isHTMLDocument() const { return m_isHTMLDocument; }
  bool isDynamicProfile() const { return m_profile == DynamicProfile; }
  bool isStaticProfile() const { return m_profile == StaticProfile; }

  // This quirk is to maintain compatibility with Android apps built on
  // the Android SDK prior to and including version 18. Presumably, this
  // can be removed any time after 2015. See http://crbug.com/277157.
  bool useLegacyBackgroundSizeShorthandBehavior() const {
    return m_useLegacyBackgroundSizeShorthandBehavior;
  }

  // FIXME: These setters shouldn't exist, however the current lifetime of
  // CSSParserContext is not well understood and thus we sometimes need to
  // override these fields.
  void setMode(CSSParserMode mode) { m_mode = mode; }
  void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; }
  void setCharset(const String& charset) { m_charset = charset; }
  void setReferrer(const Referrer& referrer) { m_referrer = referrer; }

  KURL completeURL(const String& url) const;

  // 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;
  CSSParserMode m_matchMode;
  SelectorProfile m_profile = DynamicProfile;
  Referrer m_referrer;
  bool m_isHTMLDocument;
  bool m_useLegacyBackgroundSizeShorthandBehavior;
  ContentSecurityPolicyDisposition m_shouldCheckContentSecurityPolicy;

  UseCounter* m_useCounter;
};

CORE_EXPORT const CSSParserContext* strictCSSParserContext();

}  // namespace blink

#endif  // CSSParserContext_h