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/. */
7 /* loading of CSS style sheets using the network APIs */
9 #ifndef mozilla_css_Loader_h
10 #define mozilla_css_Loader_h
15 #include "mozilla/Attributes.h"
16 #include "mozilla/CORSMode.h"
17 #include "mozilla/css/StylePreloadKind.h"
18 #include "mozilla/dom/LinkStyle.h"
19 #include "mozilla/MemoryReporting.h"
20 #include "mozilla/UniquePtr.h"
21 #include "nsCompatibility.h"
22 #include "nsCycleCollectionParticipant.h"
23 #include "nsStringFwd.h"
25 #include "nsTObserverArray.h"
26 #include "nsURIHashKey.h"
27 #include "nsRefPtrHashtable.h"
29 class nsICSSLoaderObserver
;
30 class nsIConsoleReportCollector
;
37 class SharedStyleSheetCache
;
38 class SheetLoadDataHashKey
;
46 // The load data for a <link> or @import style-sheet.
48 // This must contain all the state that affects CSS parsing.
49 class SheetLoadDataHashKey
: public PLDHashEntryHdr
{
51 using KeyType
= const SheetLoadDataHashKey
&;
52 using KeyTypePointer
= const SheetLoadDataHashKey
*;
54 explicit SheetLoadDataHashKey(const SheetLoadDataHashKey
* aKey
)
56 mPrincipal(aKey
->mPrincipal
),
57 mLoaderPrincipal(aKey
->mLoaderPrincipal
),
58 mPartitionPrincipal(aKey
->mPartitionPrincipal
),
59 mEncodingGuess(aKey
->mEncodingGuess
),
60 mCORSMode(aKey
->mCORSMode
),
61 mParsingMode(aKey
->mParsingMode
),
62 mCompatMode(aKey
->mCompatMode
),
63 mSRIMetadata(aKey
->mSRIMetadata
),
64 mIsLinkRelPreload(aKey
->mIsLinkRelPreload
) {
65 MOZ_COUNT_CTOR(SheetLoadDataHashKey
);
68 SheetLoadDataHashKey(nsIURI
* aURI
, nsIPrincipal
* aPrincipal
,
69 nsIPrincipal
* aLoaderPrincipal
,
70 nsIPrincipal
* aPartitionPrincipal
,
71 NotNull
<const Encoding
*> aEncodingGuess
,
72 CORSMode aCORSMode
, css::SheetParsingMode aParsingMode
,
73 nsCompatibility aCompatMode
,
74 const dom::SRIMetadata
& aSRIMetadata
,
75 css::StylePreloadKind aPreloadKind
)
77 mPrincipal(aPrincipal
),
78 mLoaderPrincipal(aLoaderPrincipal
),
79 mPartitionPrincipal(aPartitionPrincipal
),
80 mEncodingGuess(aEncodingGuess
),
82 mParsingMode(aParsingMode
),
83 mCompatMode(aCompatMode
),
84 mSRIMetadata(aSRIMetadata
),
85 mIsLinkRelPreload(IsLinkRelPreload(aPreloadKind
)) {
87 MOZ_ASSERT(aPrincipal
);
88 MOZ_ASSERT(aLoaderPrincipal
);
89 MOZ_COUNT_CTOR(SheetLoadDataHashKey
);
92 SheetLoadDataHashKey(SheetLoadDataHashKey
&& toMove
)
93 : mURI(std::move(toMove
.mURI
)),
94 mPrincipal(std::move(toMove
.mPrincipal
)),
95 mLoaderPrincipal(std::move(toMove
.mLoaderPrincipal
)),
96 mPartitionPrincipal(std::move(toMove
.mPartitionPrincipal
)),
97 mEncodingGuess(std::move(toMove
.mEncodingGuess
)),
98 mCORSMode(std::move(toMove
.mCORSMode
)),
99 mParsingMode(std::move(toMove
.mParsingMode
)),
100 mCompatMode(std::move(toMove
.mCompatMode
)),
101 mSRIMetadata(std::move(toMove
.mSRIMetadata
)),
102 mIsLinkRelPreload(std::move(toMove
.mIsLinkRelPreload
)) {
103 MOZ_COUNT_CTOR(SheetLoadDataHashKey
);
106 explicit SheetLoadDataHashKey(const css::SheetLoadData
&);
108 MOZ_COUNTED_DTOR(SheetLoadDataHashKey
)
110 const SheetLoadDataHashKey
& GetKey() const { return *this; }
111 const SheetLoadDataHashKey
* GetKeyPointer() const { return this; }
113 bool KeyEquals(const SheetLoadDataHashKey
* aKey
) const {
114 return KeyEquals(*aKey
);
117 bool KeyEquals(const SheetLoadDataHashKey
&) const;
119 static const SheetLoadDataHashKey
* KeyToPointer(
120 const SheetLoadDataHashKey
& aKey
) {
123 static PLDHashNumber
HashKey(const SheetLoadDataHashKey
* aKey
) {
124 return nsURIHashKey::HashKey(aKey
->mURI
);
127 nsIURI
* URI() const { return mURI
; }
129 nsIPrincipal
* Principal() const { return mPrincipal
; }
131 nsIPrincipal
* LoaderPrincipal() const { return mLoaderPrincipal
; }
133 nsIPrincipal
* PartitionPrincipal() const { return mPartitionPrincipal
; }
135 css::SheetParsingMode
ParsingMode() const { return mParsingMode
; }
137 enum { ALLOW_MEMMOVE
= true };
140 const nsCOMPtr
<nsIURI
> mURI
;
141 const nsCOMPtr
<nsIPrincipal
> mPrincipal
;
142 const nsCOMPtr
<nsIPrincipal
> mLoaderPrincipal
;
143 const nsCOMPtr
<nsIPrincipal
> mPartitionPrincipal
;
144 // The encoding guess is the encoding the sheet would get if the request
145 // didn't have any encoding information like @charset or a Content-Encoding
147 const NotNull
<const Encoding
*> mEncodingGuess
;
148 const CORSMode mCORSMode
;
149 const css::SheetParsingMode mParsingMode
;
150 const nsCompatibility mCompatMode
;
151 dom::SRIMetadata mSRIMetadata
;
152 const bool mIsLinkRelPreload
;
160 /*********************
161 * Style sheet reuse *
162 *********************/
164 class MOZ_RAII LoaderReusableStyleSheets
{
166 LoaderReusableStyleSheets() = default;
169 * Look for a reusable sheet (see AddReusableSheet) matching the
170 * given URL. If found, set aResult, remove the reused sheet from
171 * the internal list, and return true. If not found, return false;
172 * in this case, aResult is not modified.
174 * @param aURL the url to match
175 * @param aResult [out] the style sheet which can be reused
177 bool FindReusableStyleSheet(nsIURI
* aURL
, RefPtr
<StyleSheet
>& aResult
);
180 * Indicate that a certain style sheet is available for reuse if its
181 * URI matches the URI of an @import. Sheets should be added in the
182 * opposite order in which they are intended to be reused.
184 * @param aSheet the sheet which can be reused
186 void AddReusableSheet(StyleSheet
* aSheet
) {
187 mReusableSheets
.AppendElement(aSheet
);
191 LoaderReusableStyleSheets(const LoaderReusableStyleSheets
&) = delete;
192 LoaderReusableStyleSheets
& operator=(const LoaderReusableStyleSheets
&) =
195 // The sheets that can be reused.
196 nsTArray
<RefPtr
<StyleSheet
>> mReusableSheets
;
200 using ReferrerPolicy
= dom::ReferrerPolicy
;
203 using Completed
= dom::LinkStyle::Completed
;
204 using HasAlternateRel
= dom::LinkStyle::HasAlternateRel
;
205 using IsAlternate
= dom::LinkStyle::IsAlternate
;
206 using IsInline
= dom::LinkStyle::IsInline
;
207 using IsExplicitlyEnabled
= dom::LinkStyle::IsExplicitlyEnabled
;
208 using MediaMatched
= dom::LinkStyle::MediaMatched
;
209 using LoadSheetResult
= dom::LinkStyle::Update
;
210 using SheetInfo
= dom::LinkStyle::SheetInfo
;
213 // aDocGroup is used for dispatching SheetLoadData in PostLoadEvent(). It
214 // can be null if you want to use this constructor, and there's no
215 // document when the Loader is constructed.
216 explicit Loader(dom::DocGroup
*);
217 explicit Loader(dom::Document
*);
220 // Private destructor, to discourage deletion outside of Release():
224 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Loader
)
225 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(Loader
)
227 void DropDocumentReference(); // notification that doc is going away
229 void DeregisterFromSheetCache();
230 void RegisterInSheetCache();
232 void SetCompatibilityMode(nsCompatibility aCompatMode
) {
233 mDocumentCompatMode
= aCompatMode
;
236 using StylePreloadKind
= css::StylePreloadKind
;
238 bool HasLoaded(const SheetLoadDataHashKey
& aKey
) const {
239 return mLoadsPerformed
.Contains(aKey
);
242 void WillStartPendingLoad() {
243 MOZ_DIAGNOSTIC_ASSERT(mPendingLoadCount
, "Where did this load come from?");
247 nsCompatibility
CompatMode(StylePreloadKind aPreloadKind
) const {
248 // For Link header preload, we guess non-quirks, because otherwise it is
249 // useless for modern pages.
251 // Link element preload is generally good because the speculative html
252 // parser deals with quirks mode properly.
253 if (aPreloadKind
== StylePreloadKind::FromLinkRelPreloadHeader
) {
254 return eCompatibility_FullStandards
;
256 return mDocumentCompatMode
;
259 // TODO(emilio): Is the complexity of this method and carrying the titles
260 // around worth it? The alternate sheets will load anyhow eventually...
261 void DocumentStyleSheetSetChanged();
263 // XXXbz sort out what the deal is with events! When should they fire?
266 * Load an inline style sheet. If a successful result is returned and
267 * result.WillNotify() is true, then aObserver is guaranteed to be notified
268 * asynchronously once the sheet is marked complete. If an error is
269 * returned, or if result.WillNotify() is false, aObserver will not be
270 * notified. In addition to parsing the sheet, this method will insert it
271 * into the stylesheet list of this CSSLoader's document.
272 * @param aObserver the observer to notify when the load completes.
274 * @param aBuffer the stylesheet data
276 Result
<LoadSheetResult
, nsresult
> LoadInlineStyle(
277 const SheetInfo
&, const nsAString
& aBuffer
,
278 nsICSSLoaderObserver
* aObserver
);
281 * Load a linked (document) stylesheet. If a successful result is returned,
282 * aObserver is guaranteed to be notified asynchronously once the sheet is
283 * loaded and marked complete, i.e., result.WillNotify() will always return
284 * true. If an error is returned, aObserver will not be notified. In
285 * addition to loading the sheet, this method will insert it into the
286 * stylesheet list of this CSSLoader's document.
287 * @param aObserver the observer to notify when the load completes.
290 Result
<LoadSheetResult
, nsresult
> LoadStyleLink(
291 const SheetInfo
&, nsICSSLoaderObserver
* aObserver
);
294 * Load a child (@import-ed) style sheet. In addition to loading the sheet,
295 * this method will insert it into the child sheet list of aParentSheet. If
296 * there is no sheet currently being parsed and the child sheet is not
297 * complete when this method returns, then when the child sheet becomes
298 * complete aParentSheet will be QIed to nsICSSLoaderObserver and
299 * asynchronously notified, just like for LoadStyleLink. Note that if the
300 * child sheet is already complete when this method returns, no
301 * nsICSSLoaderObserver notification will be sent.
303 * @param aParentSheet the parent of this child sheet
304 * @param aParentData the SheetLoadData corresponding to the load of the
305 * parent sheet. May be null for @import rules inserted via
307 * @param aURL the URL of the child sheet
308 * @param aMedia the already-parsed media list for the child sheet
309 * @param aSavedSheets any saved style sheets which could be reused
312 nsresult
LoadChildSheet(StyleSheet
& aParentSheet
, SheetLoadData
* aParentData
,
313 nsIURI
* aURL
, dom::MediaList
* aMedia
,
314 LoaderReusableStyleSheets
* aSavedSheets
);
317 * Called when we hit the internal memory cache with a complete stylesheet.
319 void DidHitCompleteSheetCache(const SheetLoadDataHashKey
&,
320 const StyleUseCounters
* aCounters
);
322 enum class UseSystemPrincipal
{ No
, Yes
};
325 * Synchronously load and return the stylesheet at aURL. Any child sheets
326 * will also be loaded synchronously. Note that synchronous loads over some
327 * protocols may involve spinning up a new event loop, so use of this method
328 * does NOT guarantee not receiving any events before the sheet loads. This
329 * method can be used to load sheets not associated with a document.
331 * @param aURL the URL of the sheet to load
332 * @param aParsingMode the mode in which to parse the sheet
333 * (see comments at enum SheetParsingMode, above).
334 * @param aUseSystemPrincipal if true, give the resulting sheet the system
335 * principal no matter where it's being loaded from.
337 * NOTE: At the moment, this method assumes the sheet will be UTF-8, but
338 * ideally it would allow arbitrary encodings. Callers should NOT depend on
339 * non-UTF8 sheets being treated as UTF-8 by this method.
341 * NOTE: A successful return from this method doesn't indicate anything about
342 * whether the data could be parsed as CSS and doesn't indicate anything
343 * about the status of child sheets of the returned sheet.
345 Result
<RefPtr
<StyleSheet
>, nsresult
> LoadSheetSync(
346 nsIURI
*, SheetParsingMode
= eAuthorSheetFeatures
,
347 UseSystemPrincipal
= UseSystemPrincipal::No
);
350 * Asynchronously load the stylesheet at aURL. If a successful result is
351 * returned, aObserver is guaranteed to be notified asynchronously once the
352 * sheet is loaded and marked complete. This method can be used to load
353 * sheets not associated with a document.
355 * @param aURL the URL of the sheet to load
356 * @param aParsingMode the mode in which to parse the sheet
357 * (see comments at enum SheetParsingMode, above).
358 * @param aUseSystemPrincipal if true, give the resulting sheet the system
359 * principal no matter where it's being loaded from.
360 * @param aReferrerInfo referrer information of the sheet.
361 * @param aObserver the observer to notify when the load completes.
363 * @param aEarlyHintPreloaderId to connect back to the early hint preload
364 * channel. Null means no connect back should happen
365 * @return the sheet to load. Note that the sheet may well not be loaded by
366 * the time this method returns.
368 * NOTE: At the moment, this method assumes the sheet will be UTF-8, but
369 * ideally it would allow arbitrary encodings. Callers should NOT depend on
370 * non-UTF8 sheets being treated as UTF-8 by this method.
372 Result
<RefPtr
<StyleSheet
>, nsresult
> LoadSheet(
373 nsIURI
* aURI
, StylePreloadKind
, const Encoding
* aPreloadEncoding
,
374 nsIReferrerInfo
* aReferrerInfo
, nsICSSLoaderObserver
* aObserver
,
375 uint64_t aEarlyHintPreloaderId
, CORSMode aCORSMode
,
376 const nsAString
& aNonce
, const nsAString
& aIntegrity
);
379 * As above, but without caring for a couple things.
381 Result
<RefPtr
<StyleSheet
>, nsresult
> LoadSheet(nsIURI
*, SheetParsingMode
,
383 nsICSSLoaderObserver
*);
386 * Stop loading all sheets. All nsICSSLoaderObservers involved will be
387 * notified with NS_BINDING_ABORTED as the status, possibly synchronously.
392 * nsresult Loader::StopLoadingSheet(nsIURI* aURL), which notifies the
393 * nsICSSLoaderObserver with NS_BINDING_ABORTED, was removed in Bug 556446.
394 * It can be found in revision 2c44a32052ad.
398 * Whether the loader is enabled or not.
399 * When disabled, processing of new styles is disabled and an attempt
400 * to do so will fail with a return code of
401 * NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
402 * currently loading styles or already processed styles.
404 bool GetEnabled() { return mEnabled
; }
405 void SetEnabled(bool aEnabled
) { mEnabled
= aEnabled
; }
407 uint32_t ParsedSheetCount() const { return mParsedSheetCount
; }
410 * Get the document we live for. May return null.
412 dom::Document
* GetDocument() const { return mDocument
; }
414 bool IsDocumentAssociated() const { return mIsDocumentAssociated
; }
417 * Return true if this loader has pending loads (ones that would send
418 * notifications to an nsICSSLoaderObserver attached to this loader).
419 * If called from inside nsICSSLoaderObserver::StyleSheetLoaded, this will
420 * return false if and only if that is the last StyleSheetLoaded
421 * notification the CSSLoader knows it's going to send. In other words, if
422 * two sheets load at once (via load coalescing, e.g.), HasPendingLoads()
423 * will return true during notification for the first one, and false
424 * during notification for the second one.
426 bool HasPendingLoads();
429 * Add an observer to this loader. The observer will be notified
430 * for all loads that would have notified their own observers (even
431 * if those loads don't have observers attached to them).
432 * Load-specific observers will be notified before generic
433 * observers. The loader holds a reference to the observer.
435 * aObserver must not be null.
437 void AddObserver(nsICSSLoaderObserver
* aObserver
);
440 * Remove an observer added via AddObserver.
442 void RemoveObserver(nsICSSLoaderObserver
* aObserver
);
444 // These interfaces are public only for the benefit of static functions
445 // within nsCSSLoader.cpp.
447 // IsAlternateSheet can change our currently selected style set if none is
448 // selected and aHasAlternateRel is false.
449 IsAlternate
IsAlternateSheet(const nsAString
& aTitle
, bool aHasAlternateRel
);
452 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const;
454 enum class SheetState
: uint8_t {
461 // The loader principal is the document's node principal, if this loader is
462 // owned by a document, or the system principal otherwise.
463 nsIPrincipal
* LoaderPrincipal() const;
465 // The partitioned principal is the document's partitioned principal, if this
466 // loader is owned by a document, or the system principal otherwise.
467 nsIPrincipal
* PartitionedPrincipal() const;
469 bool ShouldBypassCache() const;
471 enum class PendingLoad
{ No
, Yes
};
474 friend class mozilla::SharedStyleSheetCache
;
475 friend class SheetLoadData
;
476 friend class StreamLoader
;
478 // Only to be called by `LoadSheet`.
479 [[nodiscard
]] bool MaybeDeferLoad(SheetLoadData
& aLoadData
,
480 SheetState aSheetState
,
481 PendingLoad aPendingLoad
,
482 const SheetLoadDataHashKey
& aKey
);
484 // Only to be called by `LoadSheet`.
485 bool MaybeCoalesceLoadAndNotifyOpen(SheetLoadData
& aLoadData
,
486 SheetState aSheetState
,
487 const SheetLoadDataHashKey
& aKey
,
488 const PreloadHashKey
& aPreloadKey
);
490 // Only to be called by `LoadSheet`.
491 [[nodiscard
]] nsresult
LoadSheetSyncInternal(SheetLoadData
& aLoadData
,
492 SheetState aSheetState
);
494 // Only to be called by `LoadSheet`.
495 [[nodiscard
]] nsresult
LoadSheetAsyncInternal(
496 SheetLoadData
& aLoadData
, uint64_t aEarlyHintPreloaderId
,
497 const SheetLoadDataHashKey
& aKey
);
499 // Helpers to conditionally block onload if mDocument is non-null.
500 void IncrementOngoingLoadCountAndMaybeBlockOnload() {
501 if (!mOngoingLoadCount
++) {
506 void DecrementOngoingLoadCountAndMaybeUnblockOnload() {
507 MOZ_DIAGNOSTIC_ASSERT(mOngoingLoadCount
);
508 MOZ_DIAGNOSTIC_ASSERT(mOngoingLoadCount
> mPendingLoadCount
);
509 if (!--mOngoingLoadCount
) {
510 UnblockOnload(false);
515 void UnblockOnload(bool aFireSync
);
517 nsresult
CheckContentPolicy(nsIPrincipal
* aLoadingPrincipal
,
518 nsIPrincipal
* aTriggeringPrincipal
,
519 nsIURI
* aTargetURI
, nsINode
* aRequestingNode
,
520 const nsAString
& aNonce
, StylePreloadKind
);
522 std::tuple
<RefPtr
<StyleSheet
>, SheetState
> CreateSheet(
523 const SheetInfo
& aInfo
, css::SheetParsingMode aParsingMode
,
524 bool aSyncLoad
, css::StylePreloadKind aPreloadKind
) {
525 nsIPrincipal
* triggeringPrincipal
= aInfo
.mTriggeringPrincipal
526 ? aInfo
.mTriggeringPrincipal
.get()
528 return CreateSheet(aInfo
.mURI
, aInfo
.mContent
, triggeringPrincipal
,
529 aParsingMode
, aInfo
.mCORSMode
,
530 /* aPreloadOrParentDataEncoding = */ nullptr,
531 aInfo
.mIntegrity
, aSyncLoad
, aPreloadKind
);
534 // For inline style, the aURI param is null, but the aLinkingContent
535 // must be non-null then. The loader principal must never be null
536 // if aURI is not null.
537 std::tuple
<RefPtr
<StyleSheet
>, SheetState
> CreateSheet(
538 nsIURI
* aURI
, nsIContent
* aLinkingContent
,
539 nsIPrincipal
* aTriggeringPrincipal
, css::SheetParsingMode
, CORSMode
,
540 const Encoding
* aPreloadOrParentDataEncoding
, const nsAString
& aIntegrity
,
541 bool aSyncLoad
, StylePreloadKind
);
543 // Pass in either a media string or the MediaList from the CSSParser. Don't
546 // This method will set the sheet's enabled state based on IsAlternate and co.
547 MediaMatched
PrepareSheet(StyleSheet
&, const nsAString
& aTitle
,
548 const nsAString
& aMediaString
, dom::MediaList
*,
549 IsAlternate
, IsExplicitlyEnabled
);
551 // Inserts a style sheet in a document or a ShadowRoot.
552 void InsertSheetInTree(StyleSheet
& aSheet
);
553 // Inserts a style sheet into a parent style sheet.
554 void InsertChildSheet(StyleSheet
& aSheet
, StyleSheet
& aParentSheet
);
556 Result
<RefPtr
<StyleSheet
>, nsresult
> InternalLoadNonDocumentSheet(
557 nsIURI
* aURL
, StylePreloadKind
, SheetParsingMode aParsingMode
,
558 UseSystemPrincipal
, const Encoding
* aPreloadEncoding
,
559 nsIReferrerInfo
* aReferrerInfo
, nsICSSLoaderObserver
* aObserver
,
560 CORSMode aCORSMode
, const nsAString
& aNonce
, const nsAString
& aIntegrity
,
561 uint64_t aEarlyHintPreloaderId
);
563 RefPtr
<StyleSheet
> LookupInlineSheetInCache(const nsAString
&, nsIPrincipal
*);
565 // Synchronously notify of a cached load data.
566 void NotifyOfCachedLoad(RefPtr
<SheetLoadData
>);
568 // Start the loads of all the sheets in mPendingDatas
569 void StartDeferredLoads();
571 // Note: LoadSheet is responsible for setting the sheet to complete on
573 nsresult
LoadSheet(SheetLoadData
&, SheetState
, uint64_t aEarlyHintPreloaderId
,
574 PendingLoad
= PendingLoad::No
);
576 enum class AllowAsyncParse
{
581 // Parse the stylesheet in the load data.
583 // Returns whether the parse finished. It may not finish e.g. if the sheet had
586 // If this function returns Completed::Yes, then ParseSheet also called
587 // SheetComplete on aLoadData.
588 Completed
ParseSheet(const nsACString
&, SheetLoadData
&, AllowAsyncParse
);
590 // The load of the sheet in the load data is done, one way or another.
592 void SheetComplete(SheetLoadData
&, nsresult
);
594 // Notify observers on an individual data. This is different from
595 // SheetComplete for loads that are shared.
596 void NotifyObservers(SheetLoadData
&, nsresult
);
598 // Mark the given SheetLoadData, as well as any of its siblings, parents, etc
599 // transitively, as failed. The idea is to mark as failed any load that was
600 // directly or indirectly @importing the sheet this SheetLoadData represents.
602 // if aOnlyForLoader is non-null, then only loads for a given loader will be
603 // marked as failing. This is useful to only cancel loads associated to a
604 // given loader, in case they were marked as canceled.
605 static void MarkLoadTreeFailed(SheetLoadData
&,
606 Loader
* aOnlyForLoader
= nullptr);
608 // A shorthand to mark a possible link preload as used to supress "unused"
609 // warning in the console.
610 void MaybeNotifyPreloadUsed(SheetLoadData
&);
612 nsRefPtrHashtable
<nsStringHashKey
, StyleSheet
> mInlineSheets
;
614 // A set with all the different loads we've done in a given document, for the
615 // purpose of not posting duplicate performance entries for them.
616 nsTHashtable
<const SheetLoadDataHashKey
> mLoadsPerformed
;
618 RefPtr
<SharedStyleSheetCache
> mSheets
;
620 // Our array of "global" observers
621 nsTObserverArray
<nsCOMPtr
<nsICSSLoaderObserver
>> mObservers
;
623 // This reference is nulled by the Document in it's destructor through
624 // DropDocumentReference().
625 dom::Document
* MOZ_NON_OWNING_REF mDocument
; // the document we live for
627 // For dispatching events via DocGroup::Dispatch() when mDocument is nullptr.
628 RefPtr
<dom::DocGroup
> mDocGroup
;
630 nsCompatibility mDocumentCompatMode
;
632 nsCOMPtr
<nsIConsoleReportCollector
> mReporter
;
634 // Number of datas for asynchronous sheet loads still waiting to be notified.
635 // This includes pending stylesheets whose load hasn't started yet but which
636 // we need to, but not inline or constructable stylesheets, though the
637 // constructable stylesheets bit may change, see bug 1642227.
638 uint32_t mOngoingLoadCount
= 0;
640 // The number of sheets that have been deferred / are in a pending state.
641 uint32_t mPendingLoadCount
= 0;
643 // The number of stylesheets that we have parsed, for testing purposes.
644 uint32_t mParsedSheetCount
= 0;
646 bool mEnabled
= true;
648 // Whether we had a document at the point of creation.
649 bool mIsDocumentAssociated
= false;
652 // Whether we're in a necko callback atm.
653 bool mSyncCallback
= false;
658 } // namespace mozilla
660 #endif /* mozilla_css_Loader_h */