/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_StyleSheet_h #define mozilla_StyleSheet_h #include "mozilla/css/SheetParsingMode.h" #include "mozilla/dom/CSSStyleSheetBinding.h" #include "mozilla/dom/SRIMetadata.h" #include "mozilla/net/ReferrerPolicy.h" #include "mozilla/CORSMode.h" #include "mozilla/MozPromise.h" #include "mozilla/RefPtr.h" #include "mozilla/ServoBindingTypes.h" #include "mozilla/ServoUtils.h" #include "mozilla/StyleSheetInfo.h" #include "mozilla/URLExtraData.h" #include "nsICSSLoaderObserver.h" #include "nsWrapperCache.h" #include "nsCompatibility.h" #include "nsStringFwd.h" class nsIDocument; class nsINode; class nsIPrincipal; namespace mozilla { class ServoCSSRuleList; class ServoStyleSet; typedef MozPromise StyleSheetParsePromise; namespace css { class GroupRule; class Loader; class LoaderReusableStyleSheets; class Rule; class SheetLoadData; } namespace dom { class CSSImportRule; class CSSRuleList; class DocumentOrShadowRoot; class MediaList; class ShadowRoot; class SRIMetadata; } // namespace dom class StyleSheet final : public nsICSSLoaderObserver , public nsWrapperCache { StyleSheet(const StyleSheet& aCopy, StyleSheet* aParentToUse, dom::CSSImportRule* aOwnerRuleToUse, dom::DocumentOrShadowRoot* aDocOrShadowRootToUse, nsINode* aOwningNodeToUse); virtual ~StyleSheet(); public: StyleSheet(css::SheetParsingMode aParsingMode, CORSMode aCORSMode, net::ReferrerPolicy aReferrerPolicy, const dom::SRIMetadata& aIntegrity); NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StyleSheet) already_AddRefed CreateEmptyChildSheet( already_AddRefed aMediaList) const; bool HasRules() const; // Parses a stylesheet. The aLoadData argument corresponds to the // SheetLoadData for this stylesheet. It may be null in some cases. RefPtr ParseSheet(css::Loader* aLoader, const nsACString& aBytes, css::SheetLoadData* aLoadData); // Common code that needs to be called after servo finishes parsing. This is // shared between the parallel and sequential paths. void FinishAsyncParse(already_AddRefed aSheetContents); // Similar to the above, but guarantees that parsing will be performed // synchronously. void ParseSheetSync(css::Loader* aLoader, const nsACString& aBytes, css::SheetLoadData* aLoadData, uint32_t aLineNumber, css::LoaderReusableStyleSheets* aReusableSheets = nullptr); nsresult ReparseSheet(const nsAString& aInput); const RawServoStyleSheetContents* RawContents() const { return Inner().mContents; } void SetContentsForImport(const RawServoStyleSheetContents* aContents) { MOZ_ASSERT(!Inner().mContents); Inner().mContents = aContents; } URLExtraData* URLData() const { return Inner().mURLData; } // nsICSSLoaderObserver interface NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate, nsresult aStatus) final; // Internal GetCssRules methods which do not have security check and // completeness check. ServoCSSRuleList* GetCssRulesInternal(); // Returns the stylesheet's Servo origin as an OriginFlags value. OriginFlags GetOrigin(); /** * The different changes that a stylesheet may go through. * * Used by the StyleSets in order to handle more efficiently some kinds of * changes. */ enum class ChangeType { Added, Removed, ApplicableStateChanged, RuleAdded, RuleRemoved, RuleChanged, }; void SetOwningNode(nsINode* aOwningNode) { mOwningNode = aOwningNode; } css::SheetParsingMode ParsingMode() const { return mParsingMode; } mozilla::dom::CSSStyleSheetParsingMode ParsingModeDOM(); /** * Whether the sheet is complete. */ bool IsComplete() const; void SetComplete(); /** * Set the stylesheet to be enabled. This may or may not make it * applicable. Note that this WILL inform the sheet's document of * its new applicable state if the state changes but WILL NOT call * BeginUpdate() or EndUpdate() on the document -- calling those is * the caller's responsibility. This allows use of SetEnabled when * batched updates are desired. If you want updates handled for * you, see SetDisabled(). */ void SetEnabled(bool aEnabled); // Whether the sheet is for an inline