Line data Source code
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/. */
6 :
7 : #ifndef mozilla_ServoStyleSheet_h
8 : #define mozilla_ServoStyleSheet_h
9 :
10 : #include "mozilla/dom/SRIMetadata.h"
11 : #include "mozilla/RefPtr.h"
12 : #include "mozilla/ServoBindingTypes.h"
13 : #include "mozilla/StyleSheet.h"
14 : #include "mozilla/StyleSheetInfo.h"
15 : #include "mozilla/URLExtraData.h"
16 : #include "nsCompatibility.h"
17 : #include "nsStringFwd.h"
18 :
19 : namespace mozilla {
20 :
21 : class ServoCSSRuleList;
22 :
23 : namespace css {
24 : class Loader;
25 : class LoaderReusableStyleSheets;
26 : }
27 :
28 : // -------------------------------
29 : // Servo Style Sheet Inner Data Container
30 : //
31 :
32 : struct ServoStyleSheetInner final : public StyleSheetInfo
33 : {
34 : ServoStyleSheetInner(CORSMode aCORSMode,
35 : ReferrerPolicy aReferrerPolicy,
36 : const dom::SRIMetadata& aIntegrity,
37 : css::SheetParsingMode aParsingMode);
38 : ServoStyleSheetInner(ServoStyleSheetInner& aCopy,
39 : ServoStyleSheet* aPrimarySheet);
40 : ~ServoStyleSheetInner();
41 :
42 : StyleSheetInfo* CloneFor(StyleSheet* aPrimarySheet) override;
43 :
44 : size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
45 :
46 : RefPtr<const RawServoStyleSheetContents> mContents;
47 :
48 : // XXX StyleSheetInfo already has mSheetURI, mBaseURI, and mPrincipal.
49 : // Can we somehow replace them with URLExtraData directly? The issue
50 : // is currently URLExtraData is immutable, but URIs in StyleSheetInfo
51 : // seems to be mutable, so we probably cannot set them altogether.
52 : // Also, this is mostly a duplicate reference of the same url data
53 : // inside RawServoStyleSheet. We may want to just use that instead.
54 : RefPtr<URLExtraData> mURLData;
55 : };
56 :
57 :
58 : /**
59 : * CSS style sheet object that is a wrapper for a Servo Stylesheet.
60 : */
61 :
62 : // CID for the ServoStyleSheet class
63 : // a6f31472-ab69-4beb-860f-c221431ead77
64 : #define NS_SERVO_STYLE_SHEET_IMPL_CID \
65 : { 0xa6f31472, 0xab69, 0x4beb, \
66 : { 0x86, 0x0f, 0xc2, 0x21, 0x43, 0x1e, 0xad, 0x77 } }
67 :
68 :
69 : class ServoStyleSheet : public StyleSheet
70 : {
71 : public:
72 : ServoStyleSheet(css::SheetParsingMode aParsingMode,
73 : CORSMode aCORSMode,
74 : net::ReferrerPolicy aReferrerPolicy,
75 : const dom::SRIMetadata& aIntegrity);
76 :
77 : already_AddRefed<ServoStyleSheet> CreateEmptyChildSheet(
78 : already_AddRefed<dom::MediaList> aMediaList) const;
79 :
80 : NS_DECL_ISUPPORTS_INHERITED
81 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoStyleSheet, StyleSheet)
82 :
83 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_SERVO_STYLE_SHEET_IMPL_CID)
84 :
85 : bool HasRules() const;
86 :
87 : MOZ_MUST_USE nsresult ParseSheet(css::Loader* aLoader,
88 : const nsAString& aInput,
89 : nsIURI* aSheetURI,
90 : nsIURI* aBaseURI,
91 : nsIPrincipal* aSheetPrincipal,
92 : uint32_t aLineNumber,
93 : nsCompatibility aCompatMode,
94 : css::LoaderReusableStyleSheets* aReusableSheets = nullptr);
95 :
96 : nsresult ReparseSheet(const nsAString& aInput);
97 :
98 0 : const RawServoStyleSheetContents* RawContents() const {
99 0 : return Inner()->mContents;
100 : }
101 :
102 : void SetContentsForImport(const RawServoStyleSheetContents* aContents) {
103 : MOZ_ASSERT(!Inner()->mContents);
104 : Inner()->mContents = aContents;
105 : }
106 :
107 0 : URLExtraData* URLData() const { return Inner()->mURLData; }
108 :
109 0 : void DidDirty() override {}
110 :
111 : already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
112 : dom::CSSImportRule* aCloneOwnerRule,
113 : nsIDocument* aCloneDocument,
114 : nsINode* aCloneOwningNode) const final;
115 :
116 : // nsICSSLoaderObserver interface
117 : NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
118 : nsresult aStatus) final;
119 :
120 : // Internal GetCssRules method which do not have security check and
121 : // completelness check.
122 : ServoCSSRuleList* GetCssRulesInternal();
123 :
124 : protected:
125 : virtual ~ServoStyleSheet();
126 :
127 : void LastRelease();
128 :
129 0 : ServoStyleSheetInner* Inner() const
130 : {
131 0 : return static_cast<ServoStyleSheetInner*>(mInner);
132 : }
133 :
134 : // Internal methods which do not have security check and completeness check.
135 : uint32_t InsertRuleInternal(const nsAString& aRule,
136 : uint32_t aIndex, ErrorResult& aRv);
137 : void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
138 : nsresult InsertRuleIntoGroupInternal(const nsAString& aRule,
139 : css::GroupRule* aGroup,
140 : uint32_t aIndex);
141 :
142 0 : void EnabledStateChangedInternal() {}
143 :
144 : size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
145 :
146 : private:
147 : ServoStyleSheet(const ServoStyleSheet& aCopy,
148 : ServoStyleSheet* aParentToUse,
149 : dom::CSSImportRule* aOwnerRuleToUse,
150 : nsIDocument* aDocumentToUse,
151 : nsINode* aOwningNodeToUse);
152 :
153 : void DropRuleList();
154 :
155 : // Take the recently cloned sheets from the `@import` rules, and reparent them
156 : // correctly to `aPrimarySheet`.
157 : void BuildChildListAfterInnerClone();
158 :
159 : RefPtr<ServoCSSRuleList> mRuleList;
160 :
161 : friend class StyleSheet;
162 : };
163 :
164 : NS_DEFINE_STATIC_IID_ACCESSOR(ServoStyleSheet, NS_SERVO_STYLE_SHEET_IMPL_CID)
165 :
166 : } // namespace mozilla
167 :
168 : #endif // mozilla_ServoStyleSheet_h
|