diff --git a/layout/style/ServoStyleSheet.cpp b/layout/style/ServoStyleSheet.cpp index 8b860c6bcd74..5e3b674953dc 100644 --- a/layout/style/ServoStyleSheet.cpp +++ b/layout/style/ServoStyleSheet.cpp @@ -18,13 +18,24 @@ using namespace mozilla::dom; namespace mozilla { +// ------------------------------- +// CSS Style Sheet Inner Data Container +// + +ServoStyleSheetInner::ServoStyleSheetInner(CORSMode aCORSMode, + ReferrerPolicy aReferrerPolicy, + const SRIMetadata& aIntegrity) + : StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity) +{ +} + ServoStyleSheet::ServoStyleSheet(css::SheetParsingMode aParsingMode, CORSMode aCORSMode, net::ReferrerPolicy aReferrerPolicy, const dom::SRIMetadata& aIntegrity) : StyleSheet(StyleBackendType::Servo, aParsingMode) { - mInner = new StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity); + mInner = new ServoStyleSheetInner(aCORSMode, aReferrerPolicy, aIntegrity); mInner->AddSheet(this); } @@ -54,7 +65,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END bool ServoStyleSheet::HasRules() const { - return mSheet && Servo_StyleSheet_HasRules(mSheet); + return Inner()->mSheet && Servo_StyleSheet_HasRules(Inner()->mSheet); } nsresult @@ -75,13 +86,13 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader, NS_ENSURE_SUCCESS(rv, rv); NS_ConvertUTF16toUTF8 input(aInput); - if (!mSheet) { - mSheet = + if (!Inner()->mSheet) { + Inner()->mSheet = Servo_StyleSheet_FromUTF8Bytes(aLoader, this, &input, mParsingMode, &baseString, base, referrer, principal).Consume(); } else { - Servo_StyleSheet_ClearAndUpdate(mSheet, aLoader, this, &input, base, + Servo_StyleSheet_ClearAndUpdate(Inner()->mSheet, aLoader, this, &input, base, referrer, principal); } @@ -91,7 +102,7 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader, void ServoStyleSheet::LoadFailed() { - mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume(); + Inner()->mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume(); } void @@ -114,7 +125,8 @@ CSSRuleList* ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv) { if (!mRuleList) { - RefPtr rawRules = Servo_StyleSheet_GetRules(mSheet).Consume(); + RefPtr rawRules = + Servo_StyleSheet_GetRules(Inner()->mSheet).Consume(); mRuleList = new ServoCSSRuleList(this, rawRules.forget()); } return mRuleList; diff --git a/layout/style/ServoStyleSheet.h b/layout/style/ServoStyleSheet.h index 6574049ca47b..5c28b727f69b 100644 --- a/layout/style/ServoStyleSheet.h +++ b/layout/style/ServoStyleSheet.h @@ -23,6 +23,20 @@ class Loader; class Rule; } +// ------------------------------- +// Servo Style Sheet Inner Data Container +// + +struct ServoStyleSheetInner : public StyleSheetInfo +{ + ServoStyleSheetInner(CORSMode aCORSMode, + ReferrerPolicy aReferrerPolicy, + const dom::SRIMetadata& aIntegrity); + + RefPtr mSheet; +}; + + /** * CSS style sheet object that is a wrapper for a Servo Stylesheet. */ @@ -53,10 +67,12 @@ public: */ void LoadFailed(); - RawServoStyleSheet* RawSheet() const { return mSheet; } + RawServoStyleSheet* RawSheet() const { + return Inner()->mSheet; + } void SetSheetForImport(RawServoStyleSheet* aSheet) { - MOZ_ASSERT(!mSheet); - mSheet = aSheet; + MOZ_ASSERT(!Inner()->mSheet); + Inner()->mSheet = aSheet; } // WebIDL CSSStyleSheet API @@ -73,6 +89,11 @@ public: protected: virtual ~ServoStyleSheet(); + ServoStyleSheetInner* Inner() const + { + return static_cast(mInner); + } + // Internal methods which do not have security check and completeness check. dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv); uint32_t InsertRuleInternal(const nsAString& aRule, @@ -84,7 +105,6 @@ protected: private: void DropRuleList(); - RefPtr mSheet; RefPtr mRuleList; friend class StyleSheet;