/src/mozilla-central/dom/base/nsStyleLinkElement.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 | | |
7 | | /* |
8 | | * A base class which implements nsIStyleSheetLinkingElement and can |
9 | | * be subclassed by various content nodes that want to load |
10 | | * stylesheets (<style>, <link>, processing instructions, etc). |
11 | | */ |
12 | | |
13 | | #ifndef nsStyleLinkElement_h___ |
14 | | #define nsStyleLinkElement_h___ |
15 | | |
16 | | #include "mozilla/Attributes.h" |
17 | | #include "mozilla/CORSMode.h" |
18 | | #include "mozilla/StyleSheetInlines.h" |
19 | | #include "mozilla/Unused.h" |
20 | | #include "mozilla/net/ReferrerPolicy.h" |
21 | | #include "nsCOMPtr.h" |
22 | | #include "nsIStyleSheetLinkingElement.h" |
23 | | #include "nsTArray.h" |
24 | | |
25 | | class nsIDocument; |
26 | | class nsIURI; |
27 | | |
28 | | namespace mozilla { |
29 | | class CSSStyleSheet; |
30 | | namespace dom { |
31 | | class ShadowRoot; |
32 | | } // namespace dom |
33 | | } // namespace mozilla |
34 | | |
35 | | class nsStyleLinkElement : public nsIStyleSheetLinkingElement |
36 | | { |
37 | | public: |
38 | | nsStyleLinkElement(); |
39 | | virtual ~nsStyleLinkElement(); |
40 | | |
41 | | NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override = 0; |
42 | | |
43 | 0 | mozilla::StyleSheet* GetSheet() const { return mStyleSheet; } |
44 | | |
45 | | // nsIStyleSheetLinkingElement |
46 | | void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) override; |
47 | | mozilla::StyleSheet* GetStyleSheet() override; |
48 | | void InitStyleLinkElement(bool aDontLoadStyle) override; |
49 | | |
50 | | mozilla::Result<Update, nsresult> |
51 | | UpdateStyleSheet(nsICSSLoaderObserver*) override; |
52 | | |
53 | | void SetEnableUpdates(bool aEnableUpdates) override; |
54 | | void GetCharset(nsAString& aCharset) override; |
55 | | |
56 | | void OverrideBaseURI(nsIURI* aNewBaseURI) override; |
57 | | void SetLineNumber(uint32_t aLineNumber) override; |
58 | | uint32_t GetLineNumber() override; |
59 | | void SetColumnNumber(uint32_t aColumnNumber) override; |
60 | | uint32_t GetColumnNumber() override; |
61 | | |
62 | | enum RelValue { |
63 | | ePREFETCH = 0x00000001, |
64 | | eDNS_PREFETCH = 0x00000002, |
65 | | eSTYLESHEET = 0x00000004, |
66 | | eNEXT = 0x00000008, |
67 | | eALTERNATE = 0x00000010, |
68 | | ePRECONNECT = 0x00000020, |
69 | | // NOTE: 0x40 is unused |
70 | | ePRELOAD = 0x00000080 |
71 | | }; |
72 | | |
73 | | // The return value is a bitwise or of 0 or more RelValues. |
74 | | static uint32_t ParseLinkTypes(const nsAString& aTypes); |
75 | | |
76 | | void UpdateStyleSheetInternal() |
77 | 0 | { |
78 | 0 | mozilla::Unused << UpdateStyleSheetInternal(nullptr, nullptr); |
79 | 0 | } |
80 | | protected: |
81 | | /** |
82 | | * @param aOldDocument should be non-null only if we're updating because we |
83 | | * removed the node from the document. |
84 | | * @param aOldShadowRoot should be non-null only if we're updating because we |
85 | | * removed the node from a shadow tree. |
86 | | * @param aForceUpdate true will force the update even if the URI has not |
87 | | * changed. This should be used in cases when something |
88 | | * about the content that affects the resulting sheet |
89 | | * changed but the URI may not have changed. |
90 | | * |
91 | | * TODO(emilio): Should probably pass a single DocumentOrShadowRoot. |
92 | | */ |
93 | | mozilla::Result<Update, nsresult> UpdateStyleSheetInternal( |
94 | | nsIDocument* aOldDocument, |
95 | | mozilla::dom::ShadowRoot* aOldShadowRoot, |
96 | | ForceUpdate = ForceUpdate::No); |
97 | | |
98 | | // Gets a suitable title and media for SheetInfo out of an element, which |
99 | | // needs to be `this`. |
100 | | // |
101 | | // NOTE(emilio): Needs nsString instead of nsAString because of |
102 | | // CompressWhitespace. |
103 | | static void GetTitleAndMediaForElement(const mozilla::dom::Element&, |
104 | | nsString& aTitle, |
105 | | nsString& aMedia); |
106 | | |
107 | | // Returns whether the type attribute specifies the text/css mime type. |
108 | | static bool IsCSSMimeTypeAttribute(const mozilla::dom::Element&); |
109 | | |
110 | | virtual mozilla::Maybe<SheetInfo> GetStyleSheetInfo() = 0; |
111 | | |
112 | | // CC methods |
113 | | void Unlink(); |
114 | | void Traverse(nsCycleCollectionTraversalCallback &cb); |
115 | | |
116 | | private: |
117 | | /** |
118 | | * @param aOldDocument should be non-null only if we're updating because we |
119 | | * removed the node from the document. |
120 | | * @param aOldShadowRoot The ShadowRoot that used to contain the style. |
121 | | * Passed as a parameter because on an update, the node |
122 | | * is removed from the tree before the sheet is removed |
123 | | * from the ShadowRoot. |
124 | | * @param aForceUpdate true will force the update even if the URI has not |
125 | | * changed. This should be used in cases when something |
126 | | * about the content that affects the resulting sheet |
127 | | * changed but the URI may not have changed. |
128 | | */ |
129 | | mozilla::Result<Update, nsresult> |
130 | | DoUpdateStyleSheet(nsIDocument* aOldDocument, |
131 | | mozilla::dom::ShadowRoot* aOldShadowRoot, |
132 | | nsICSSLoaderObserver* aObserver, |
133 | | ForceUpdate); |
134 | | |
135 | | RefPtr<mozilla::StyleSheet> mStyleSheet; |
136 | | protected: |
137 | | nsCOMPtr<nsIPrincipal> mTriggeringPrincipal; |
138 | | bool mDontLoadStyle; |
139 | | bool mUpdatesEnabled; |
140 | | uint32_t mLineNumber; |
141 | | uint32_t mColumnNumber; |
142 | | }; |
143 | | |
144 | | #endif /* nsStyleLinkElement_h___ */ |
145 | | |