1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* loading of CSS style sheets using the network APIs */
40 #ifndef nsICSSLoader_h___
41 #define nsICSSLoader_h___
43 #include "nsISupports.h"
44 #include "nsSubstring.h"
45 #include "nsCompatibility.h"
50 class nsICSSStyleSheet
;
54 class nsIUnicharInputStream
;
55 class nsICSSLoaderObserver
;
57 class nsICSSImportRule
;
60 // IID for the nsICSSLoader interface
61 // 0c6d7e76-dddc-4727-b557-7ef531127e11
62 #define NS_ICSS_LOADER_IID \
63 { 0x0c6d7e76, 0xdddc, 0x4727, \
64 { 0xb5, 0x57, 0x7e, 0xf5, 0x31, 0x12, 0x7e, 0x11 } }
66 typedef void (*nsCSSLoaderCallbackFunc
)(nsICSSStyleSheet
* aSheet
, void *aData
, PRBool aDidNotify
);
68 class nsICSSLoader
: public nsISupports
{
70 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_LOADER_IID
)
72 NS_IMETHOD
Init(nsIDocument
* aDocument
) = 0;
73 NS_IMETHOD
DropDocumentReference(void) = 0; // notification that doc is going away
75 NS_IMETHOD
SetCaseSensitive(PRBool aCaseSensitive
) = 0;
76 NS_IMETHOD
SetCompatibilityMode(nsCompatibility aCompatMode
) = 0;
77 NS_IMETHOD
SetPreferredSheet(const nsAString
& aTitle
) = 0;
78 NS_IMETHOD
GetPreferredSheet(nsAString
& aTitle
) = 0;
80 // Get/Recycle a CSS parser for general use
81 NS_IMETHOD
GetParserFor(nsICSSStyleSheet
* aSheet
,
82 nsICSSParser
** aParser
) = 0;
83 NS_IMETHOD
RecycleParser(nsICSSParser
* aParser
) = 0;
85 // XXXbz sort out what the deal is with events! When should they fire?
88 * Load an inline style sheet. If a successful result is returned and
89 * *aCompleted is false, then aObserver is guaranteed to be notified
90 * asynchronously once the sheet is marked complete. If an error is
91 * returned, or if *aCompleted is true, aObserver will not be notified. In
92 * addition to parsing the sheet, this method will insert it into the
93 * stylesheet list of this CSSLoader's document.
95 * @param aElement the element linking to the stylesheet. This must not be
96 * null and must implement nsIStyleSheetLinkingElement.
97 * @param aStream the character stream that holds the stylesheet data.
98 * @param aLineNumber the line number at which the stylesheet data started.
99 * @param aTitle the title of the sheet.
100 * @param aMedia the media string for the sheet.
101 * @param aObserver the observer to notify when the load completes.
103 * @param [out] aCompleted whether parsing of the sheet completed.
104 * @param [out] aIsAlternate whether the stylesheet ended up being an
107 NS_IMETHOD
LoadInlineStyle(nsIContent
* aElement
,
108 nsIUnicharInputStream
* aStream
,
109 PRUint32 aLineNumber
,
110 const nsSubstring
& aTitle
,
111 const nsSubstring
& aMedia
,
112 nsICSSLoaderObserver
* aObserver
,
114 PRBool
* aIsAlternate
) = 0;
117 * Load a linked (document) stylesheet. If a successful result is returned,
118 * aObserver is guaranteed to be notified asynchronously once the sheet is
119 * loaded and marked complete. If an error is returned, aObserver will not
120 * be notified. In addition to loading the sheet, this method will insert it
121 * into the stylesheet list of this CSSLoader's document.
123 * @param aElement the element linking to the the stylesheet. May be null.
124 * @param aURL the URL of the sheet.
125 * @param aTitle the title of the sheet.
126 * @param aMedia the media string for the sheet.
127 * @param aHasAlternateRel whether the rel for this link included
129 * @param aObserver the observer to notify when the load completes.
131 * @param [out] aIsAlternate whether the stylesheet actually ended up beinga
132 * an alternate sheet. Note that this need not match
135 NS_IMETHOD
LoadStyleLink(nsIContent
* aElement
,
137 const nsSubstring
& aTitle
,
138 const nsSubstring
& aMedia
,
139 PRBool aHasAlternateRel
,
140 nsICSSLoaderObserver
* aObserver
,
141 PRBool
* aIsAlternate
) = 0;
144 * Load a child (@import-ed) style sheet. In addition to loading the sheet,
145 * this method will insert it into the child sheet list of aParentSheet. If
146 * there is no sheet currently being parsed and the child sheet is not
147 * complete when this method returns, then when the child sheet becomes
148 * complete aParentSheet will be QIed to nsICSSLoaderObserver and
149 * asynchronously notified, just like for LoadStyleLink. Note that if the
150 * child sheet is already complete when this method returns, no
151 * nsICSSLoaderObserver notification will be sent.
153 * @param aParentSheet the parent of this child sheet
154 * @param aURL the URL of the child sheet
155 * @param aMedia the already-parsed media list for the child sheet
156 * @param aRule the @import rule importing this child. This is used to
157 * properly order the child sheet list of aParentSheet.
159 NS_IMETHOD
LoadChildSheet(nsICSSStyleSheet
* aParentSheet
,
162 nsICSSImportRule
* aRule
) = 0;
165 * Synchronously load and return the stylesheet at aURL. Any child sheets
166 * will also be loaded synchronously. Note that synchronous loads over some
167 * protocols may involve spinning up a new event loop, so use of this method
168 * does NOT guarantee not receiving any events before the sheet loads. This
169 * method can be used to load sheets not associated with a document.
171 * @param aURL the URL of the sheet to load
172 * @param [out] aSheet the loaded, complete sheet.
173 * @param aEnableUnsafeRules whether unsafe rules are enabled for this
175 * Unsafe rules are rules that can violate key Gecko invariants if misused.
176 * In particular, most anonymous box pseudoelements must be very carefully
177 * styled or we will have severe problems. Therefore unsafe rules should
178 * never be enabled for stylesheets controlled by untrusted sites; preferably
179 * unsafe rules should only be enabled for agent sheets.
181 * NOTE: At the moment, this method assumes the sheet will be UTF-8, but
182 * ideally it would allow arbitrary encodings. Callers should NOT depend on
183 * non-UTF8 sheets being treated as UTF-8 by this method.
185 * NOTE: A successful return from this method doesn't indicate anything about
186 * whether the data could be parsed as CSS and doesn't indicate anything
187 * about the status of child sheets of the returned sheet.
189 NS_IMETHOD
LoadSheetSync(nsIURI
* aURL
, PRBool aEnableUnsafeRules
,
190 nsICSSStyleSheet
** aSheet
) = 0;
193 * As above, but aEnableUnsafeRules is assumed false.
195 nsresult
LoadSheetSync(nsIURI
* aURL
, nsICSSStyleSheet
** aSheet
) {
196 return LoadSheetSync(aURL
, PR_FALSE
, aSheet
);
200 * Asynchronously load the stylesheet at aURL. If a successful result is
201 * returned, aObserver is guaranteed to be notified asynchronously once the
202 * sheet is loaded and marked complete. This method can be used to load
203 * sheets not associated with a document.
205 * @param aURL the URL of the sheet to load
206 * @param aOriginPrincipal the principal to use for security checks. This
207 * can be null to indicate that these checks should
209 * @param aObserver the observer to notify when the load completes.
211 * @param [out] aSheet the sheet to load. Note that the sheet may well
212 * not be loaded by the time this method returns.
214 NS_IMETHOD
LoadSheet(nsIURI
* aURL
,
215 nsIPrincipal
* aOriginPrincipal
,
216 nsICSSLoaderObserver
* aObserver
,
217 nsICSSStyleSheet
** aSheet
) = 0;
220 * Same as above, to be used when the caller doesn't care about the
221 * not-yet-loaded sheet.
223 NS_IMETHOD
LoadSheet(nsIURI
* aURL
,
224 nsIPrincipal
* aOriginPrincipal
,
225 nsICSSLoaderObserver
* aObserver
) = 0;
228 * Stop loading all sheets. All nsICSSLoaderObservers involved will be
229 * notified with NS_BINDING_ABORTED as the status, possibly synchronously.
231 NS_IMETHOD
Stop(void) = 0;
234 * Stop loading one sheet. The nsICSSLoaderObserver involved will be
235 * notified with NS_BINDING_ABORTED as the status, possibly synchronously.
237 NS_IMETHOD
StopLoadingSheet(nsIURI
* aURL
) = 0;
240 * Whether the loader is enabled or not.
241 * When disabled, processing of new styles is disabled and an attempt
242 * to do so will fail with a return code of
243 * NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
244 * currently loading styles or already processed styles.
246 NS_IMETHOD
GetEnabled(PRBool
*aEnabled
) = 0;
247 NS_IMETHOD
SetEnabled(PRBool aEnabled
) = 0;
250 * Return true if this nsICSSLoader has pending loads (ones that would send
251 * notifications to an nsICSSLoaderObserver attached to this nsICSSLoader).
252 * If called from inside nsICSSLoaderObserver::StyleSheetLoaded, this will
253 * return PR_FALSE if and only if that is the last StyleSheetLoaded
254 * notification the CSSLoader knows it's going to send. In other words, if
255 * two sheets load at once (via load coalescing, e.g.), HasPendingLoads()
256 * will return PR_TRUE during notification for the first one, and PR_FALSE
257 * during notification for the second one.
259 NS_IMETHOD_(PRBool
) HasPendingLoads() = 0;
262 * Add an observer to this nsICSSLoader. The observer will be notified for
263 * all loads that would have notified their own observers (even if those
264 * loads don't have observers attached to them). Load-specific observers
265 * will be notified before generic observers. The CSSLoader holds a
266 * reference to the observer.
268 * aObserver must not be null.
270 NS_IMETHOD
AddObserver(nsICSSLoaderObserver
* aObserver
) = 0;
273 * Remove an observer added via AddObserver.
275 NS_IMETHOD_(void) RemoveObserver(nsICSSLoaderObserver
* aObserver
) = 0;
278 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSLoader
, NS_ICSS_LOADER_IID
)
281 NS_NewCSSLoader(nsIDocument
* aDocument
, nsICSSLoader
** aLoader
);
284 NS_NewCSSLoader(nsICSSLoader
** aLoader
);
286 #endif /* nsICSSLoader_h___ */