no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / layout / style / Loader.h
blob70eefffb4a4a99c31289afc5114730febc88c6c6
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
12 #include <tuple>
13 #include <utility>
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"
24 #include "nsTArray.h"
25 #include "nsTObserverArray.h"
26 #include "nsURIHashKey.h"
27 #include "nsRefPtrHashtable.h"
29 class nsICSSLoaderObserver;
30 class nsIConsoleReportCollector;
31 class nsIContent;
32 class nsIPrincipal;
34 namespace mozilla {
36 class PreloadHashKey;
37 class SharedStyleSheetCache;
38 class SheetLoadDataHashKey;
39 class StyleSheet;
41 namespace dom {
42 class DocGroup;
43 class Element;
44 enum class FetchPriority : uint8_t;
45 } // namespace dom
47 // The load data for a <link> or @import style-sheet.
49 // This must contain all the state that affects CSS parsing.
50 class SheetLoadDataHashKey : public PLDHashEntryHdr {
51 public:
52 using KeyType = const SheetLoadDataHashKey&;
53 using KeyTypePointer = const SheetLoadDataHashKey*;
55 explicit SheetLoadDataHashKey(const SheetLoadDataHashKey* aKey)
56 : mURI(aKey->mURI),
57 mPrincipal(aKey->mPrincipal),
58 mLoaderPrincipal(aKey->mLoaderPrincipal),
59 mPartitionPrincipal(aKey->mPartitionPrincipal),
60 mEncodingGuess(aKey->mEncodingGuess),
61 mCORSMode(aKey->mCORSMode),
62 mParsingMode(aKey->mParsingMode),
63 mCompatMode(aKey->mCompatMode),
64 mSRIMetadata(aKey->mSRIMetadata),
65 mIsLinkRelPreload(aKey->mIsLinkRelPreload) {
66 MOZ_COUNT_CTOR(SheetLoadDataHashKey);
69 SheetLoadDataHashKey(nsIURI* aURI, nsIPrincipal* aPrincipal,
70 nsIPrincipal* aLoaderPrincipal,
71 nsIPrincipal* aPartitionPrincipal,
72 NotNull<const Encoding*> aEncodingGuess,
73 CORSMode aCORSMode, css::SheetParsingMode aParsingMode,
74 nsCompatibility aCompatMode,
75 const dom::SRIMetadata& aSRIMetadata,
76 css::StylePreloadKind aPreloadKind)
77 : mURI(aURI),
78 mPrincipal(aPrincipal),
79 mLoaderPrincipal(aLoaderPrincipal),
80 mPartitionPrincipal(aPartitionPrincipal),
81 mEncodingGuess(aEncodingGuess),
82 mCORSMode(aCORSMode),
83 mParsingMode(aParsingMode),
84 mCompatMode(aCompatMode),
85 mSRIMetadata(aSRIMetadata),
86 mIsLinkRelPreload(IsLinkRelPreload(aPreloadKind)) {
87 MOZ_ASSERT(aURI);
88 MOZ_ASSERT(aPrincipal);
89 MOZ_ASSERT(aLoaderPrincipal);
90 MOZ_COUNT_CTOR(SheetLoadDataHashKey);
93 SheetLoadDataHashKey(SheetLoadDataHashKey&& toMove)
94 : mURI(std::move(toMove.mURI)),
95 mPrincipal(std::move(toMove.mPrincipal)),
96 mLoaderPrincipal(std::move(toMove.mLoaderPrincipal)),
97 mPartitionPrincipal(std::move(toMove.mPartitionPrincipal)),
98 mEncodingGuess(std::move(toMove.mEncodingGuess)),
99 mCORSMode(std::move(toMove.mCORSMode)),
100 mParsingMode(std::move(toMove.mParsingMode)),
101 mCompatMode(std::move(toMove.mCompatMode)),
102 mSRIMetadata(std::move(toMove.mSRIMetadata)),
103 mIsLinkRelPreload(std::move(toMove.mIsLinkRelPreload)) {
104 MOZ_COUNT_CTOR(SheetLoadDataHashKey);
107 explicit SheetLoadDataHashKey(const css::SheetLoadData&);
109 MOZ_COUNTED_DTOR(SheetLoadDataHashKey)
111 const SheetLoadDataHashKey& GetKey() const { return *this; }
112 const SheetLoadDataHashKey* GetKeyPointer() const { return this; }
114 bool KeyEquals(const SheetLoadDataHashKey* aKey) const {
115 return KeyEquals(*aKey);
118 bool KeyEquals(const SheetLoadDataHashKey&) const;
120 static const SheetLoadDataHashKey* KeyToPointer(
121 const SheetLoadDataHashKey& aKey) {
122 return &aKey;
124 static PLDHashNumber HashKey(const SheetLoadDataHashKey* aKey) {
125 return nsURIHashKey::HashKey(aKey->mURI);
128 nsIURI* URI() const { return mURI; }
130 nsIPrincipal* Principal() const { return mPrincipal; }
132 nsIPrincipal* LoaderPrincipal() const { return mLoaderPrincipal; }
134 nsIPrincipal* PartitionPrincipal() const { return mPartitionPrincipal; }
136 css::SheetParsingMode ParsingMode() const { return mParsingMode; }
138 enum { ALLOW_MEMMOVE = true };
140 protected:
141 const nsCOMPtr<nsIURI> mURI;
142 const nsCOMPtr<nsIPrincipal> mPrincipal;
143 const nsCOMPtr<nsIPrincipal> mLoaderPrincipal;
144 const nsCOMPtr<nsIPrincipal> mPartitionPrincipal;
145 // The encoding guess is the encoding the sheet would get if the request
146 // didn't have any encoding information like @charset or a Content-Encoding
147 // header.
148 const NotNull<const Encoding*> mEncodingGuess;
149 const CORSMode mCORSMode;
150 const css::SheetParsingMode mParsingMode;
151 const nsCompatibility mCompatMode;
152 dom::SRIMetadata mSRIMetadata;
153 const bool mIsLinkRelPreload;
156 namespace css {
158 class SheetLoadData;
159 class ImportRule;
161 /*********************
162 * Style sheet reuse *
163 *********************/
165 class MOZ_RAII LoaderReusableStyleSheets {
166 public:
167 LoaderReusableStyleSheets() = default;
170 * Look for a reusable sheet (see AddReusableSheet) matching the
171 * given URL. If found, set aResult, remove the reused sheet from
172 * the internal list, and return true. If not found, return false;
173 * in this case, aResult is not modified.
175 * @param aURL the url to match
176 * @param aResult [out] the style sheet which can be reused
178 bool FindReusableStyleSheet(nsIURI* aURL, RefPtr<StyleSheet>& aResult);
181 * Indicate that a certain style sheet is available for reuse if its
182 * URI matches the URI of an @import. Sheets should be added in the
183 * opposite order in which they are intended to be reused.
185 * @param aSheet the sheet which can be reused
187 void AddReusableSheet(StyleSheet* aSheet) {
188 mReusableSheets.AppendElement(aSheet);
191 private:
192 LoaderReusableStyleSheets(const LoaderReusableStyleSheets&) = delete;
193 LoaderReusableStyleSheets& operator=(const LoaderReusableStyleSheets&) =
194 delete;
196 // The sheets that can be reused.
197 nsTArray<RefPtr<StyleSheet>> mReusableSheets;
200 class Loader final {
201 using ReferrerPolicy = dom::ReferrerPolicy;
203 public:
204 using Completed = dom::LinkStyle::Completed;
205 using HasAlternateRel = dom::LinkStyle::HasAlternateRel;
206 using IsAlternate = dom::LinkStyle::IsAlternate;
207 using IsInline = dom::LinkStyle::IsInline;
208 using IsExplicitlyEnabled = dom::LinkStyle::IsExplicitlyEnabled;
209 using MediaMatched = dom::LinkStyle::MediaMatched;
210 using LoadSheetResult = dom::LinkStyle::Update;
211 using SheetInfo = dom::LinkStyle::SheetInfo;
213 Loader();
214 // aDocGroup is used for dispatching SheetLoadData in PostLoadEvent(). It
215 // can be null if you want to use this constructor, and there's no
216 // document when the Loader is constructed.
217 explicit Loader(dom::DocGroup*);
218 explicit Loader(dom::Document*);
220 private:
221 // Private destructor, to discourage deletion outside of Release():
222 ~Loader();
224 public:
225 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Loader)
226 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(Loader)
228 void DropDocumentReference(); // notification that doc is going away
230 void DeregisterFromSheetCache();
231 void RegisterInSheetCache();
233 void SetCompatibilityMode(nsCompatibility aCompatMode) {
234 mDocumentCompatMode = aCompatMode;
237 using StylePreloadKind = css::StylePreloadKind;
239 bool HasLoaded(const SheetLoadDataHashKey& aKey) const {
240 return mLoadsPerformed.Contains(aKey);
243 void WillStartPendingLoad() {
244 MOZ_DIAGNOSTIC_ASSERT(mPendingLoadCount, "Where did this load come from?");
245 mPendingLoadCount--;
248 nsCompatibility CompatMode(StylePreloadKind aPreloadKind) const {
249 // For Link header preload, we guess non-quirks, because otherwise it is
250 // useless for modern pages.
252 // Link element preload is generally good because the speculative html
253 // parser deals with quirks mode properly.
254 if (aPreloadKind == StylePreloadKind::FromLinkRelPreloadHeader) {
255 return eCompatibility_FullStandards;
257 return mDocumentCompatMode;
260 // TODO(emilio): Is the complexity of this method and carrying the titles
261 // around worth it? The alternate sheets will load anyhow eventually...
262 void DocumentStyleSheetSetChanged();
264 // XXXbz sort out what the deal is with events! When should they fire?
267 * Load an inline style sheet. If a successful result is returned and
268 * result.WillNotify() is true, then aObserver is guaranteed to be notified
269 * asynchronously once the sheet is marked complete. If an error is
270 * returned, or if result.WillNotify() is false, aObserver will not be
271 * notified. In addition to parsing the sheet, this method will insert it
272 * into the stylesheet list of this CSSLoader's document.
273 * @param aObserver the observer to notify when the load completes.
274 * May be null.
275 * @param aBuffer the stylesheet data
277 Result<LoadSheetResult, nsresult> LoadInlineStyle(
278 const SheetInfo&, const nsAString& aBuffer,
279 nsICSSLoaderObserver* aObserver);
282 * Load a linked (document) stylesheet. If a successful result is returned,
283 * aObserver is guaranteed to be notified asynchronously once the sheet is
284 * loaded and marked complete, i.e., result.WillNotify() will always return
285 * true. If an error is returned, aObserver will not be notified. In
286 * addition to loading the sheet, this method will insert it into the
287 * stylesheet list of this CSSLoader's document.
288 * @param aObserver the observer to notify when the load completes.
289 * May be null.
291 Result<LoadSheetResult, nsresult> LoadStyleLink(
292 const SheetInfo&, nsICSSLoaderObserver* aObserver);
295 * Load a child (@import-ed) style sheet. In addition to loading the sheet,
296 * this method will insert it into the child sheet list of aParentSheet. If
297 * there is no sheet currently being parsed and the child sheet is not
298 * complete when this method returns, then when the child sheet becomes
299 * complete aParentSheet will be QIed to nsICSSLoaderObserver and
300 * asynchronously notified, just like for LoadStyleLink. Note that if the
301 * child sheet is already complete when this method returns, no
302 * nsICSSLoaderObserver notification will be sent.
304 * @param aParentSheet the parent of this child sheet
305 * @param aParentData the SheetLoadData corresponding to the load of the
306 * parent sheet. May be null for @import rules inserted via
307 * CSSOM.
308 * @param aURL the URL of the child sheet
309 * @param aMedia the already-parsed media list for the child sheet
310 * @param aSavedSheets any saved style sheets which could be reused
311 * for this load
313 nsresult LoadChildSheet(StyleSheet& aParentSheet, SheetLoadData* aParentData,
314 nsIURI* aURL, dom::MediaList* aMedia,
315 LoaderReusableStyleSheets* aSavedSheets);
318 * Called when we hit the internal memory cache with a complete stylesheet.
320 void DidHitCompleteSheetCache(const SheetLoadDataHashKey&,
321 const StyleUseCounters* aCounters);
323 enum class UseSystemPrincipal { No, Yes };
326 * Synchronously load and return the stylesheet at aURL. Any child sheets
327 * will also be loaded synchronously. Note that synchronous loads over some
328 * protocols may involve spinning up a new event loop, so use of this method
329 * does NOT guarantee not receiving any events before the sheet loads. This
330 * method can be used to load sheets not associated with a document.
332 * @param aURL the URL of the sheet to load
333 * @param aParsingMode the mode in which to parse the sheet
334 * (see comments at enum SheetParsingMode, above).
335 * @param aUseSystemPrincipal if true, give the resulting sheet the system
336 * principal no matter where it's being loaded from.
338 * NOTE: At the moment, this method assumes the sheet will be UTF-8, but
339 * ideally it would allow arbitrary encodings. Callers should NOT depend on
340 * non-UTF8 sheets being treated as UTF-8 by this method.
342 * NOTE: A successful return from this method doesn't indicate anything about
343 * whether the data could be parsed as CSS and doesn't indicate anything
344 * about the status of child sheets of the returned sheet.
346 Result<RefPtr<StyleSheet>, nsresult> LoadSheetSync(
347 nsIURI*, SheetParsingMode = eAuthorSheetFeatures,
348 UseSystemPrincipal = UseSystemPrincipal::No);
351 * Asynchronously load the stylesheet at aURL. If a successful result is
352 * returned, aObserver is guaranteed to be notified asynchronously once the
353 * sheet is loaded and marked complete. This method can be used to load
354 * sheets not associated with a document.
356 * @param aURL the URL of the sheet to load
357 * @param aParsingMode the mode in which to parse the sheet
358 * (see comments at enum SheetParsingMode, above).
359 * @param aUseSystemPrincipal if true, give the resulting sheet the system
360 * principal no matter where it's being loaded from.
361 * @param aReferrerInfo referrer information of the sheet.
362 * @param aObserver the observer to notify when the load completes.
363 * Must not be null.
364 * @param aEarlyHintPreloaderId to connect back to the early hint preload
365 * channel. Null means no connect back should happen
366 * @return the sheet to load. Note that the sheet may well not be loaded by
367 * the time this method returns.
369 * NOTE: At the moment, this method assumes the sheet will be UTF-8, but
370 * ideally it would allow arbitrary encodings. Callers should NOT depend on
371 * non-UTF8 sheets being treated as UTF-8 by this method.
373 Result<RefPtr<StyleSheet>, nsresult> LoadSheet(
374 nsIURI* aURI, StylePreloadKind, const Encoding* aPreloadEncoding,
375 nsIReferrerInfo* aReferrerInfo, nsICSSLoaderObserver* aObserver,
376 uint64_t aEarlyHintPreloaderId, CORSMode aCORSMode,
377 const nsAString& aNonce, const nsAString& aIntegrity,
378 dom::FetchPriority aFetchPriority);
381 * As above, but without caring for a couple things.
382 * Only to be called by `PreloadedStyleSheet::PreloadAsync`.
384 Result<RefPtr<StyleSheet>, nsresult> LoadSheet(nsIURI*, SheetParsingMode,
385 UseSystemPrincipal,
386 nsICSSLoaderObserver*);
389 * Stop loading all sheets. All nsICSSLoaderObservers involved will be
390 * notified with NS_BINDING_ABORTED as the status, possibly synchronously.
392 void Stop();
395 * nsresult Loader::StopLoadingSheet(nsIURI* aURL), which notifies the
396 * nsICSSLoaderObserver with NS_BINDING_ABORTED, was removed in Bug 556446.
397 * It can be found in revision 2c44a32052ad.
401 * Whether the loader is enabled or not.
402 * When disabled, processing of new styles is disabled and an attempt
403 * to do so will fail with a return code of
404 * NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
405 * currently loading styles or already processed styles.
407 bool GetEnabled() { return mEnabled; }
408 void SetEnabled(bool aEnabled) { mEnabled = aEnabled; }
410 uint32_t ParsedSheetCount() const { return mParsedSheetCount; }
413 * Get the document we live for. May return null.
415 dom::Document* GetDocument() const { return mDocument; }
417 bool IsDocumentAssociated() const { return mIsDocumentAssociated; }
420 * Return true if this loader has pending loads (ones that would send
421 * notifications to an nsICSSLoaderObserver attached to this loader).
422 * If called from inside nsICSSLoaderObserver::StyleSheetLoaded, this will
423 * return false if and only if that is the last StyleSheetLoaded
424 * notification the CSSLoader knows it's going to send. In other words, if
425 * two sheets load at once (via load coalescing, e.g.), HasPendingLoads()
426 * will return true during notification for the first one, and false
427 * during notification for the second one.
429 bool HasPendingLoads();
432 * Add an observer to this loader. The observer will be notified
433 * for all loads that would have notified their own observers (even
434 * if those loads don't have observers attached to them).
435 * Load-specific observers will be notified before generic
436 * observers. The loader holds a reference to the observer.
438 * aObserver must not be null.
440 void AddObserver(nsICSSLoaderObserver* aObserver);
443 * Remove an observer added via AddObserver.
445 void RemoveObserver(nsICSSLoaderObserver* aObserver);
447 // These interfaces are public only for the benefit of static functions
448 // within nsCSSLoader.cpp.
450 // IsAlternateSheet can change our currently selected style set if none is
451 // selected and aHasAlternateRel is false.
452 IsAlternate IsAlternateSheet(const nsAString& aTitle, bool aHasAlternateRel);
454 // Measure our size.
455 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
457 enum class SheetState : uint8_t {
458 NeedsParser = 0,
459 Pending,
460 Loading,
461 Complete
464 // The loader principal is the document's node principal, if this loader is
465 // owned by a document, or the system principal otherwise.
466 nsIPrincipal* LoaderPrincipal() const;
468 // The partitioned principal is the document's partitioned principal, if this
469 // loader is owned by a document, or the system principal otherwise.
470 nsIPrincipal* PartitionedPrincipal() const;
472 bool ShouldBypassCache() const;
474 enum class PendingLoad { No, Yes };
476 private:
477 friend class mozilla::SharedStyleSheetCache;
478 friend class SheetLoadData;
479 friend class StreamLoader;
481 // Only to be called by `LoadSheet`.
482 [[nodiscard]] bool MaybeDeferLoad(SheetLoadData& aLoadData,
483 SheetState aSheetState,
484 PendingLoad aPendingLoad,
485 const SheetLoadDataHashKey& aKey);
487 // Only to be called by `LoadSheet`.
488 bool MaybeCoalesceLoadAndNotifyOpen(SheetLoadData& aLoadData,
489 SheetState aSheetState,
490 const SheetLoadDataHashKey& aKey,
491 const PreloadHashKey& aPreloadKey);
493 // Only to be called by `LoadSheet`.
494 [[nodiscard]] nsresult LoadSheetSyncInternal(SheetLoadData& aLoadData,
495 SheetState aSheetState);
497 void AdjustPriority(const SheetLoadData& aLoadData, nsIChannel* aChannel);
499 // Only to be called by `LoadSheet`.
500 [[nodiscard]] nsresult LoadSheetAsyncInternal(
501 SheetLoadData& aLoadData, uint64_t aEarlyHintPreloaderId,
502 const SheetLoadDataHashKey& aKey);
504 // Helpers to conditionally block onload if mDocument is non-null.
505 void IncrementOngoingLoadCountAndMaybeBlockOnload() {
506 if (!mOngoingLoadCount++) {
507 BlockOnload();
511 void DecrementOngoingLoadCountAndMaybeUnblockOnload() {
512 MOZ_DIAGNOSTIC_ASSERT(mOngoingLoadCount);
513 MOZ_DIAGNOSTIC_ASSERT(mOngoingLoadCount > mPendingLoadCount);
514 if (!--mOngoingLoadCount) {
515 UnblockOnload(false);
519 void BlockOnload();
520 void UnblockOnload(bool aFireSync);
522 nsresult CheckContentPolicy(nsIPrincipal* aLoadingPrincipal,
523 nsIPrincipal* aTriggeringPrincipal,
524 nsIURI* aTargetURI, nsINode* aRequestingNode,
525 const nsAString& aNonce, StylePreloadKind);
527 std::tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
528 const SheetInfo& aInfo, css::SheetParsingMode aParsingMode,
529 bool aSyncLoad, css::StylePreloadKind aPreloadKind) {
530 nsIPrincipal* triggeringPrincipal = aInfo.mTriggeringPrincipal
531 ? aInfo.mTriggeringPrincipal.get()
532 : LoaderPrincipal();
533 return CreateSheet(aInfo.mURI, aInfo.mContent, triggeringPrincipal,
534 aParsingMode, aInfo.mCORSMode,
535 /* aPreloadOrParentDataEncoding = */ nullptr,
536 aInfo.mIntegrity, aSyncLoad, aPreloadKind);
539 // For inline style, the aURI param is null, but the aLinkingContent
540 // must be non-null then. The loader principal must never be null
541 // if aURI is not null.
542 std::tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
543 nsIURI* aURI, nsIContent* aLinkingContent,
544 nsIPrincipal* aTriggeringPrincipal, css::SheetParsingMode, CORSMode,
545 const Encoding* aPreloadOrParentDataEncoding, const nsAString& aIntegrity,
546 bool aSyncLoad, StylePreloadKind);
548 // Pass in either a media string or the MediaList from the CSSParser. Don't
549 // pass both.
551 // This method will set the sheet's enabled state based on IsAlternate and co.
552 MediaMatched PrepareSheet(StyleSheet&, const nsAString& aTitle,
553 const nsAString& aMediaString, dom::MediaList*,
554 IsAlternate, IsExplicitlyEnabled);
556 // Inserts a style sheet in a document or a ShadowRoot.
557 void InsertSheetInTree(StyleSheet& aSheet);
558 // Inserts a style sheet into a parent style sheet.
559 void InsertChildSheet(StyleSheet& aSheet, StyleSheet& aParentSheet);
561 Result<RefPtr<StyleSheet>, nsresult> InternalLoadNonDocumentSheet(
562 nsIURI* aURL, StylePreloadKind, SheetParsingMode aParsingMode,
563 UseSystemPrincipal, const Encoding* aPreloadEncoding,
564 nsIReferrerInfo* aReferrerInfo, nsICSSLoaderObserver* aObserver,
565 CORSMode aCORSMode, const nsAString& aNonce, const nsAString& aIntegrity,
566 uint64_t aEarlyHintPreloaderId, dom::FetchPriority aFetchPriority);
568 RefPtr<StyleSheet> LookupInlineSheetInCache(const nsAString&, nsIPrincipal*);
570 // Synchronously notify of a cached load data.
571 void NotifyOfCachedLoad(RefPtr<SheetLoadData>);
573 // Start the loads of all the sheets in mPendingDatas
574 void StartDeferredLoads();
576 // Note: LoadSheet is responsible for setting the sheet to complete on
577 // failure.
578 nsresult LoadSheet(SheetLoadData&, SheetState, uint64_t aEarlyHintPreloaderId,
579 PendingLoad = PendingLoad::No);
581 enum class AllowAsyncParse {
582 Yes,
586 // Parse the stylesheet in the load data.
588 // Returns whether the parse finished. It may not finish e.g. if the sheet had
589 // an @import.
591 // If this function returns Completed::Yes, then ParseSheet also called
592 // SheetComplete on aLoadData.
593 Completed ParseSheet(const nsACString&, const RefPtr<SheetLoadDataHolder>&,
594 AllowAsyncParse);
596 // The load of the sheet in the load data is done, one way or another.
597 // Do final cleanup.
598 void SheetComplete(SheetLoadData&, nsresult);
600 // Notify observers on an individual data. This is different from
601 // SheetComplete for loads that are shared.
602 void NotifyObservers(SheetLoadData&, nsresult);
604 // Mark the given SheetLoadData, as well as any of its siblings, parents, etc
605 // transitively, as failed. The idea is to mark as failed any load that was
606 // directly or indirectly @importing the sheet this SheetLoadData represents.
608 // if aOnlyForLoader is non-null, then only loads for a given loader will be
609 // marked as failing. This is useful to only cancel loads associated to a
610 // given loader, in case they were marked as canceled.
611 static void MarkLoadTreeFailed(SheetLoadData&,
612 Loader* aOnlyForLoader = nullptr);
614 // A shorthand to mark a possible link preload as used to supress "unused"
615 // warning in the console.
616 void MaybeNotifyPreloadUsed(SheetLoadData&);
618 nsRefPtrHashtable<nsStringHashKey, StyleSheet> mInlineSheets;
620 // A set with all the different loads we've done in a given document, for the
621 // purpose of not posting duplicate performance entries for them.
622 nsTHashtable<const SheetLoadDataHashKey> mLoadsPerformed;
624 RefPtr<SharedStyleSheetCache> mSheets;
626 // Our array of "global" observers
627 nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver>> mObservers;
629 // This reference is nulled by the Document in it's destructor through
630 // DropDocumentReference().
631 dom::Document* MOZ_NON_OWNING_REF mDocument; // the document we live for
633 // For dispatching events via DocGroup::Dispatch() when mDocument is nullptr.
634 RefPtr<dom::DocGroup> mDocGroup;
636 nsCompatibility mDocumentCompatMode;
638 nsCOMPtr<nsIConsoleReportCollector> mReporter;
640 // Number of datas for asynchronous sheet loads still waiting to be notified.
641 // This includes pending stylesheets whose load hasn't started yet but which
642 // we need to, but not inline or constructable stylesheets, though the
643 // constructable stylesheets bit may change, see bug 1642227.
644 uint32_t mOngoingLoadCount = 0;
646 // The number of sheets that have been deferred / are in a pending state.
647 uint32_t mPendingLoadCount = 0;
649 // The number of stylesheets that we have parsed, for testing purposes.
650 Atomic<uint32_t, MemoryOrdering::Relaxed> mParsedSheetCount{0};
652 bool mEnabled = true;
654 // Whether we had a document at the point of creation.
655 bool mIsDocumentAssociated = false;
657 #ifdef DEBUG
658 // Whether we're in a necko callback atm.
659 bool mSyncCallback = false;
660 #endif
663 } // namespace css
664 } // namespace mozilla
666 #endif /* mozilla_css_Loader_h */