1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
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).
13 #ifndef nsStyleLinkElement_h___
14 #define nsStyleLinkElement_h___
16 #include "mozilla/Attributes.h"
17 #include "mozilla/CORSMode.h"
18 #include "mozilla/CSSStyleSheet.h"
20 #include "nsIStyleSheetLinkingElement.h"
30 } // namespace mozilla
32 class nsStyleLinkElement
: public nsIStyleSheetLinkingElement
36 virtual ~nsStyleLinkElement();
38 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) MOZ_OVERRIDE
= 0;
40 mozilla::CSSStyleSheet
* GetSheet() const { return mStyleSheet
; }
42 // nsIStyleSheetLinkingElement
43 NS_IMETHOD
SetStyleSheet(mozilla::CSSStyleSheet
* aStyleSheet
) MOZ_OVERRIDE
;
44 NS_IMETHOD_(mozilla::CSSStyleSheet
*) GetStyleSheet() MOZ_OVERRIDE
;
45 NS_IMETHOD
InitStyleLinkElement(bool aDontLoadStyle
) MOZ_OVERRIDE
;
46 NS_IMETHOD
UpdateStyleSheet(nsICSSLoaderObserver
* aObserver
,
49 bool aForceReload
) MOZ_OVERRIDE
;
50 NS_IMETHOD
SetEnableUpdates(bool aEnableUpdates
) MOZ_OVERRIDE
;
51 NS_IMETHOD
GetCharset(nsAString
& aCharset
) MOZ_OVERRIDE
;
53 virtual void OverrideBaseURI(nsIURI
* aNewBaseURI
) MOZ_OVERRIDE
;
54 virtual void SetLineNumber(uint32_t aLineNumber
) MOZ_OVERRIDE
;
57 ePREFETCH
= 0x00000001,
58 eDNS_PREFETCH
= 0x00000002,
59 eSTYLESHEET
= 0x00000004,
61 eALTERNATE
= 0x00000010,
62 eHTMLIMPORT
= 0x00000020
65 // The return value is a bitwise or of 0 or more RelValues.
66 // aPrincipal is used to check if HTML imports is enabled for the
67 // provided principal.
68 static uint32_t ParseLinkTypes(const nsAString
& aTypes
,
69 nsIPrincipal
* aPrincipal
);
71 static bool IsImportEnabled(nsIPrincipal
* aPrincipal
);
73 void UpdateStyleSheetInternal()
75 UpdateStyleSheetInternal(nullptr, nullptr);
79 * @param aOldDocument should be non-null only if we're updating because we
80 * removed the node from the document.
81 * @param aForceUpdate true will force the update even if the URI has not
82 * changed. This should be used in cases when something
83 * about the content that affects the resulting sheet
84 * changed but the URI may not have changed.
86 nsresult
UpdateStyleSheetInternal(nsIDocument
*aOldDocument
,
87 mozilla::dom::ShadowRoot
*aOldShadowRoot
,
88 bool aForceUpdate
= false);
90 void UpdateStyleSheetScopedness(bool aIsNowScoped
);
92 virtual already_AddRefed
<nsIURI
> GetStyleSheetURL(bool* aIsInline
) = 0;
93 virtual void GetStyleSheetInfo(nsAString
& aTitle
,
97 bool* aIsAlternate
) = 0;
99 virtual mozilla::CORSMode
GetCORSMode() const
101 // Default to no CORS
102 return mozilla::CORS_NONE
;
107 void Traverse(nsCycleCollectionTraversalCallback
&cb
);
111 * @param aOldDocument should be non-null only if we're updating because we
112 * removed the node from the document.
113 * @param aOldShadowRoot The ShadowRoot that used to contain the style.
114 * Passed as a parameter because on an update, the node
115 * is removed from the tree before the sheet is removed
116 * from the ShadowRoot.
117 * @param aForceUpdate true will force the update even if the URI has not
118 * changed. This should be used in cases when something
119 * about the content that affects the resulting sheet
120 * changed but the URI may not have changed.
122 nsresult
DoUpdateStyleSheet(nsIDocument
* aOldDocument
,
123 mozilla::dom::ShadowRoot
* aOldShadowRoot
,
124 nsICSSLoaderObserver
* aObserver
,
129 nsRefPtr
<mozilla::CSSStyleSheet
> mStyleSheet
;
132 bool mUpdatesEnabled
;
133 uint32_t mLineNumber
;
136 #endif /* nsStyleLinkElement_h___ */