Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsIStyleSheetLinkingElement.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
#ifndef nsIStyleSheetLinkingElement_h__
7
#define nsIStyleSheetLinkingElement_h__
8
9
10
#include "nsISupports.h"
11
#include "mozilla/StyleSheet.h"
12
#include "mozilla/Result.h"
13
14
class nsIContent;
15
class nsICSSLoaderObserver;
16
class nsIPrincipal;
17
class nsIURI;
18
19
#define NS_ISTYLESHEETLINKINGELEMENT_IID          \
20
{ 0xa8b79f3b, 0x9d18, 0x4f9c, \
21
  { 0xb1, 0xaa, 0x8c, 0x9b, 0x1b, 0xaa, 0xac, 0xad } }
22
23
class nsIStyleSheetLinkingElement : public nsISupports {
24
public:
25
  enum class ForceUpdate
26
  {
27
    Yes,
28
    No,
29
  };
30
31
  enum class Completed
32
  {
33
    Yes,
34
    No,
35
  };
36
37
  enum class HasAlternateRel
38
  {
39
    Yes,
40
    No
41
  };
42
43
  enum class IsAlternate
44
  {
45
    Yes,
46
    No,
47
  };
48
49
  enum class IsInline
50
  {
51
    Yes,
52
    No
53
  };
54
55
  enum class MediaMatched
56
  {
57
    Yes,
58
    No,
59
  };
60
61
  struct Update
62
  {
63
  private:
64
    bool mWillNotify;
65
    bool mIsAlternate;
66
    bool mMediaMatched;
67
68
  public:
69
    Update()
70
      : mWillNotify(false)
71
      , mIsAlternate(false)
72
      , mMediaMatched(false)
73
0
    { }
74
75
    Update(Completed aCompleted, IsAlternate aIsAlternate, MediaMatched aMediaMatched)
76
      : mWillNotify(aCompleted == Completed::No)
77
      , mIsAlternate(aIsAlternate == IsAlternate::Yes)
78
      , mMediaMatched(aMediaMatched == MediaMatched::Yes)
79
0
    { }
80
81
    bool WillNotify() const
82
0
    {
83
0
      return mWillNotify;
84
0
    }
85
86
    bool ShouldBlock() const
87
0
    {
88
0
      if (!mWillNotify) {
89
0
        return false;
90
0
      }
91
0
92
0
      return !mIsAlternate && mMediaMatched;
93
0
    }
94
  };
95
96
  struct MOZ_STACK_CLASS SheetInfo
97
  {
98
    nsIContent* mContent;
99
    // FIXME(emilio): do these really need to be strong refs?
100
    nsCOMPtr<nsIURI> mURI;
101
102
    // The principal of the scripted caller that initiated the load, if
103
    // available. Otherwise null.
104
    nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
105
    mozilla::net::ReferrerPolicy mReferrerPolicy;
106
    mozilla::CORSMode mCORSMode;
107
    nsString mTitle;
108
    nsString mMedia;
109
    nsString mIntegrity;
110
111
    bool mHasAlternateRel;
112
    bool mIsInline;
113
114
    SheetInfo(const nsIDocument&,
115
              nsIContent*,
116
              already_AddRefed<nsIURI> aURI,
117
              already_AddRefed<nsIPrincipal> aTriggeringPrincipal,
118
              mozilla::net::ReferrerPolicy aReferrerPolicy,
119
              mozilla::CORSMode aCORSMode,
120
              const nsAString& aTitle,
121
              const nsAString& aMedia,
122
              HasAlternateRel aHasAlternateRel,
123
              IsInline aIsInline);
124
125
    ~SheetInfo();
126
  };
127
128
129
  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID)
130
131
  /**
132
   * Used to make the association between a style sheet and
133
   * the element that linked it to the document.
134
   *
135
   * @param aStyleSheet the style sheet associated with this
136
   *                    element.
137
   */
138
  virtual void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) = 0;
139
140
  /**
141
   * Used to obtain the style sheet linked in by this element.
142
   *
143
   * @return the style sheet associated with this element.
144
   */
145
  virtual mozilla::StyleSheet* GetStyleSheet() = 0;
146
147
  /**
148
   * Initialize the stylesheet linking element. If aDontLoadStyle is
149
   * true the element will ignore the first modification to the
150
   * element that would cause a stylesheet to be loaded. Subsequent
151
   * modifications to the element will not be ignored.
152
   */
153
  virtual void InitStyleLinkElement(bool aDontLoadStyle) = 0;
154
155
  /**
156
   * Tells this element to update the stylesheet.
157
   *
158
   * @param aObserver    observer to notify once the stylesheet is loaded.
159
   *                     This will be passed to the CSSLoader
160
   */
161
  virtual mozilla::Result<Update, nsresult>
162
    UpdateStyleSheet(nsICSSLoaderObserver* aObserver) = 0;
163
164
  /**
165
   * Tells this element whether to update the stylesheet when the
166
   * element's properties change.
167
   *
168
   * @param aEnableUpdates update on changes or not.
169
   */
170
  virtual void SetEnableUpdates(bool aEnableUpdates) = 0;
171
172
  /**
173
   * Gets the charset that the element claims the style sheet is in.
174
   * Can return empty string to indicate that we have no charset
175
   * information.
176
   *
177
   * @param aCharset the charset
178
   */
179
  virtual void GetCharset(nsAString& aCharset) = 0;
180
181
  /**
182
   * Tells this element to use a different base URI. This is used for
183
   * proper loading of xml-stylesheet processing instructions in XUL overlays
184
   * and is only currently used by nsXMLStylesheetPI.
185
   *
186
   * @param aNewBaseURI the new base URI, nullptr to use the default base URI.
187
   */
188
  virtual void OverrideBaseURI(nsIURI* aNewBaseURI) = 0;
189
190
  // This doesn't entirely belong here since they only make sense for
191
  // some types of linking elements, but it's a better place than
192
  // anywhere else.
193
  virtual void SetLineNumber(uint32_t aLineNumber) = 0;
194
195
  /**
196
   * Get the line number, as previously set by SetLineNumber.
197
   *
198
   * @return the line number of this element; or 1 if no line number
199
   *         was set
200
   */
201
  virtual uint32_t GetLineNumber() = 0;
202
203
  // This doesn't entirely belong here since they only make sense for
204
  // some types of linking elements, but it's a better place than
205
  // anywhere else.
206
  virtual void SetColumnNumber(uint32_t aColumnNumber) = 0;
207
208
  /**
209
   * Get the column number, as previously set by SetColumnNumber.
210
   *
211
   * @return the column number of this element; or 1 if no column number
212
   *         was set
213
   */
214
  virtual uint32_t GetColumnNumber() = 0;
215
};
216
217
NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleSheetLinkingElement,
218
                              NS_ISTYLESHEETLINKINGELEMENT_IID)
219
220
#endif // nsILinkingElement_h__