Bug 1290218 Part 5: Subclass StyleSheetInfo to move the ServoStyleSheet raw sheet into its mInner. draft
authorBrad Werth <bwerth@mozilla.com>
Wed, 08 Feb 2017 12:35:48 -0800
changeset 480744 19710016755f36b05d9bd3eedb90acd1c7d342b4
parent 480743 a93aaf305f014e62815ad1ea4b31caa2a3db6754
child 480745 76e04a255f32eb344ae78c362f0e7923f07401b8
push id44647
push userbwerth@mozilla.com
push dateWed, 08 Feb 2017 21:49:09 +0000
bugs1290218
milestone54.0a1
Bug 1290218 Part 5: Subclass StyleSheetInfo to move the ServoStyleSheet raw sheet into its mInner. MozReview-Commit-ID: Cu0qp3e8L5n
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -2,34 +2,46 @@
 /* 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/. */
 
 #include "mozilla/ServoStyleSheet.h"
 
 #include "mozilla/css/Rule.h"
+#include "mozilla/css/ImportRule.h"
 #include "mozilla/StyleBackendType.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/ServoCSSRuleList.h"
 #include "mozilla/dom/CSSRuleList.h"
 
 #include "mozAutoDocUpdate.h"
 
 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);
 }
 
 ServoStyleSheet::~ServoStyleSheet()
 {
   UnparentChildren();
 
   DropSheet();
@@ -49,17 +61,18 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Se
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(StyleSheet)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoStyleSheet, StyleSheet)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleList)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 bool
 ServoStyleSheet::HasRules() const
 {
-  return mSheet && Servo_StyleSheet_HasRules(mSheet);
+  ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+  return inner->mSheet && Servo_StyleSheet_HasRules(inner->mSheet);
 }
 
 nsresult
 ServoStyleSheet::ParseSheet(css::Loader* aLoader,
                             const nsAString& aInput,
                             nsIURI* aSheetURI,
                             nsIURI* aBaseURI,
                             nsIPrincipal* aSheetPrincipal,
@@ -70,39 +83,42 @@ ServoStyleSheet::ParseSheet(css::Loader*
   RefPtr<ThreadSafePrincipalHolder> principal =
     new ThreadSafePrincipalHolder(aSheetPrincipal);
 
   nsCString baseString;
   nsresult rv = aBaseURI->GetSpec(baseString);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF16toUTF8 input(aInput);
-  if (!mSheet) {
-    mSheet =
+  ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+  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);
   }
 
   return NS_OK;
 }
 
 void
 ServoStyleSheet::LoadFailed()
 {
-  mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume();
+  ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+  inner->mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume();
 }
 
 void
 ServoStyleSheet::DropSheet()
 {
-  mSheet = nullptr;
+  ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+  inner->mSheet = nullptr;
   DropRuleList();
 }
 
 void
 ServoStyleSheet::DropRuleList()
 {
   if (mRuleList) {
     mRuleList->DropReference();
@@ -116,17 +132,19 @@ ServoStyleSheet::GetDOMOwnerRule() const
   NS_ERROR("stylo: Don't know how to get DOM owner rule for ServoStyleSheet");
   return nullptr;
 }
 
 CSSRuleList*
 ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
 {
   if (!mRuleList) {
-    RefPtr<ServoCssRules> rawRules = Servo_StyleSheet_GetRules(mSheet).Consume();
+    ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+    RefPtr<ServoCssRules> rawRules =
+      Servo_StyleSheet_GetRules(inner->mSheet).Consume();
     mRuleList = new ServoCSSRuleList(this, rawRules.forget());
   }
   return mRuleList;
 }
 
 uint32_t
 ServoStyleSheet::InsertRuleInternal(const nsAString& aRule,
                                     uint32_t aIndex, ErrorResult& aRv)
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -18,16 +18,30 @@ namespace mozilla {
 
 class ServoCSSRuleList;
 
 namespace css {
 class Loader;
 class Rule;
 }
 
+// -------------------------------
+// Servo Style Sheet Inner Data Container
+//
+
+struct ServoStyleSheetInner : public StyleSheetInfo
+{
+  ServoStyleSheetInner(CORSMode aCORSMode,
+                       ReferrerPolicy aReferrerPolicy,
+                       const dom::SRIMetadata& aIntegrity);
+
+  RefPtr<RawServoStyleSheet> mSheet;
+};
+
+
 /**
  * CSS style sheet object that is a wrapper for a Servo Stylesheet.
  */
 class ServoStyleSheet : public StyleSheet
 {
 public:
   ServoStyleSheet(css::SheetParsingMode aParsingMode,
                   CORSMode aCORSMode,
@@ -48,20 +62,24 @@ public:
 
   /**
    * Called instead of ParseSheet to initialize the Servo stylesheet object
    * for a failed load. Either ParseSheet or LoadFailed must be called before
    * adding a ServoStyleSheet to a ServoStyleSet.
    */
   void LoadFailed();
 
-  RawServoStyleSheet* RawSheet() const { return mSheet; }
+  RawServoStyleSheet* RawSheet() const {
+    ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+    return inner->mSheet;
+  }
   void SetSheetForImport(RawServoStyleSheet* aSheet) {
-    MOZ_ASSERT(!mSheet);
-    mSheet = aSheet;
+    ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
+    MOZ_ASSERT(!inner->mSheet);
+    inner->mSheet = aSheet;
   }
 
   // WebIDL CSSStyleSheet API
   // Can't be inline because we can't include ImportRule here.  And can't be
   // called GetOwnerRule because that would be ambiguous with the ImportRule
   // version.
   css::Rule* GetDOMOwnerRule() const final;
 
@@ -80,17 +98,16 @@ protected:
   void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
 
   void EnabledStateChangedInternal() {}
 
 private:
   void DropSheet();
   void DropRuleList();
 
-  RefPtr<RawServoStyleSheet> mSheet;
   RefPtr<ServoCSSRuleList> mRuleList;
 
   friend class StyleSheet;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ServoStyleSheet_h