Bug 1250788 - Part 3.1: Factor out CSSStyleSheetInner members so they can be used by ServoStyleSheet. r=bholley
authorCameron McCormack <cam@mcc.id.au>
Fri, 26 Feb 2016 12:51:01 +1100
changeset 322002 a5003168dd68995070fffd4b2fc925153b1ff8d2
parent 322001 9471c9a842ef1710ae31c5b59d3e3c4393096f14
child 322003 a576bae691378d6a016c154bee89e8c3376b34d8
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1250788
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1250788 - Part 3.1: Factor out CSSStyleSheetInner members so they can be used by ServoStyleSheet. r=bholley
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/StyleSheetInfo.cpp
layout/style/StyleSheetInfo.h
layout/style/moz.build
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -836,32 +836,20 @@ namespace mozilla {
 // CSS Style Sheet Inner Data Container
 //
 
 
 CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheet* aPrimarySheet,
                                        CORSMode aCORSMode,
                                        ReferrerPolicy aReferrerPolicy,
                                        const SRIMetadata& aIntegrity)
-  : mSheets()
-  , mCORSMode(aCORSMode)
-  , mReferrerPolicy (aReferrerPolicy)
-  , mIntegrity(aIntegrity)
-  , mComplete(false)
-#ifdef DEBUG
-  , mPrincipalSet(false)
-#endif
+  : StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
 {
   MOZ_COUNT_CTOR(CSSStyleSheetInner);
   mSheets.AppendElement(aPrimarySheet);
-
-  mPrincipal = nsNullPrincipal::Create();
-  if (!mPrincipal) {
-    NS_RUNTIMEABORT("nsNullPrincipal::Init failed");
-  }
 }
 
 static bool SetStyleSheetReference(css::Rule* aRule, void* aSheet)
 {
   if (aRule) {
     aRule->SetStyleSheet(static_cast<CSSStyleSheet*>(aSheet));
   }
   return true;
@@ -954,28 +942,17 @@ CSSStyleSheet::SizeOfIncludingThis(Mallo
 
     s = s->mNext;
   }
   return n;
 }
 
 CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
                                        CSSStyleSheet* aPrimarySheet)
-  : mSheets(),
-    mSheetURI(aCopy.mSheetURI),
-    mOriginalSheetURI(aCopy.mOriginalSheetURI),
-    mBaseURI(aCopy.mBaseURI),
-    mPrincipal(aCopy.mPrincipal),
-    mCORSMode(aCopy.mCORSMode),
-    mReferrerPolicy(aCopy.mReferrerPolicy),
-    mIntegrity(aCopy.mIntegrity),
-    mComplete(aCopy.mComplete)
-#ifdef DEBUG
-    , mPrincipalSet(aCopy.mPrincipalSet)
-#endif
+  : StyleSheetInfo(aCopy)
 {
   MOZ_COUNT_CTOR(CSSStyleSheetInner);
   AddSheet(aPrimarySheet);
   aCopy.mOrderedRules.EnumerateForwards(css::GroupRule::CloneRuleInto, &mOrderedRules);
   mOrderedRules.EnumerateForwards(SetStyleSheetReference, aPrimarySheet);
 
   ChildSheetListBuilder builder = { &mFirstChild, aPrimarySheet };
   mOrderedRules.EnumerateForwards(CSSStyleSheet::RebuildChildList, &builder);
@@ -1363,37 +1340,25 @@ CSSStyleSheet::DropStyleSet(nsStyleSet* 
   DebugOnly<bool> found = mStyleSets.RemoveElement(aStyleSet);
   NS_ASSERTION(found, "didn't find style set");
 }
 
 void
 CSSStyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
                        nsIURI* aBaseURI)
 {
-  NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
-
   NS_ASSERTION(mInner->mOrderedRules.Count() == 0 && !mInner->mComplete,
-               "Can't call SetURL on sheets that are complete or have rules");
-
-  mInner->mSheetURI = aSheetURI;
-  mInner->mOriginalSheetURI = aOriginalSheetURI;
-  mInner->mBaseURI = aBaseURI;
+               "Can't call SetURIs on sheets that are complete or have rules");
+  mInner->SetURIs(aSheetURI, aOriginalSheetURI, aBaseURI);
 }
 
 void
 CSSStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
 {
-  NS_PRECONDITION(!mInner->mPrincipalSet,
-                  "Should have an inner whose principal has not yet been set");
-  if (aPrincipal) {
-    mInner->mPrincipal = aPrincipal;
-#ifdef DEBUG
-    mInner->mPrincipalSet = true;
-#endif
-  }
+  mInner->SetPrincipal(aPrincipal);
 }
 
 nsIURI*
 CSSStyleSheet::GetSheetURI() const
 {
   return mInner->mSheetURI;
 }
 
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -7,16 +7,17 @@
 /* representation of a CSS style sheet */
 
 #ifndef mozilla_CSSStyleSheet_h
 #define mozilla_CSSStyleSheet_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/IncrementalClearCOMRuleArray.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/StyleSheetInfo.h"
 #include "mozilla/css/SheetParsingMode.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/CSSStyleSheetBinding.h"
 
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsIDOMCSSStyleSheet.h"
@@ -51,22 +52,21 @@ class ImportRule;
 namespace dom {
 class CSSRuleList;
 } // namespace dom
 
   // -------------------------------
 // CSS Style Sheet Inner Data Container
 //
 
-class CSSStyleSheetInner
+class CSSStyleSheetInner : public StyleSheetInfo
 {
 public:
   friend class mozilla::CSSStyleSheet;
   friend class ::nsCSSRuleProcessor;
-  typedef net::ReferrerPolicy ReferrerPolicy;
 
 private:
   CSSStyleSheetInner(CSSStyleSheet* aPrimarySheet,
                      CORSMode aCORSMode,
                      ReferrerPolicy aReferrerPolicy,
                      const dom::SRIMetadata& aIntegrity);
   CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
                      CSSStyleSheet* aPrimarySheet);
@@ -79,38 +79,24 @@ private:
   void RebuildNameSpaces();
 
   // Create a new namespace map
   nsresult CreateNamespaceMap();
 
   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 
   AutoTArray<CSSStyleSheet*, 8> mSheets;
-  nsCOMPtr<nsIURI>       mSheetURI; // for error reports, etc.
-  nsCOMPtr<nsIURI>       mOriginalSheetURI;  // for GetHref.  Can be null.
-  nsCOMPtr<nsIURI>       mBaseURI; // for resolving relative URIs
-  nsCOMPtr<nsIPrincipal> mPrincipal;
   IncrementalClearCOMRuleArray mOrderedRules;
   nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
   // Linked list of child sheets.  This is al fundamentally broken, because
   // each of the child sheets has a unique parent... We can only hope (and
   // currently this is the case) that any time page JS can get ts hands on a
   // child sheet that means we've already ensured unique inners throughout its
   // parent chain and things are good.
   RefPtr<CSSStyleSheet> mFirstChild;
-  CORSMode               mCORSMode;
-  // The Referrer Policy of a stylesheet is used for its child sheets, so it is
-  // stored here.
-  ReferrerPolicy         mReferrerPolicy;
-  dom::SRIMetadata       mIntegrity;
-  bool                   mComplete;
-
-#ifdef DEBUG
-  bool                   mPrincipalSet;
-#endif
 };
 
 
 // -------------------------------
 // CSS Style Sheet
 //
 
 // CID for the CSSStyleSheet class
new file mode 100644
--- /dev/null
+++ b/layout/style/StyleSheetInfo.cpp
@@ -0,0 +1,73 @@
+/* -*- 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/. */
+
+#include "StyleSheetInfo.h"
+
+#include "nsIURI.h"
+#include "nsNullPrincipal.h"
+
+namespace mozilla {
+
+using namespace mozilla::dom;
+
+StyleSheetInfo::StyleSheetInfo(CORSMode aCORSMode,
+                               ReferrerPolicy aReferrerPolicy,
+                               const SRIMetadata& aIntegrity)
+  : mCORSMode(aCORSMode)
+  , mReferrerPolicy (aReferrerPolicy)
+  , mIntegrity(aIntegrity)
+  , mComplete(false)
+#ifdef DEBUG
+  , mPrincipalSet(false)
+#endif
+{
+  mPrincipal = nsNullPrincipal::Create();
+  if (!mPrincipal) {
+    NS_RUNTIMEABORT("nsNullPrincipal::Init failed");
+  }
+}
+
+StyleSheetInfo::StyleSheetInfo(const StyleSheetInfo& aCopy)
+  : mSheetURI(aCopy.mSheetURI)
+  , mOriginalSheetURI(aCopy.mOriginalSheetURI)
+  , mBaseURI(aCopy.mBaseURI)
+  , mPrincipal(aCopy.mPrincipal)
+  , mCORSMode(aCopy.mCORSMode)
+  , mReferrerPolicy(aCopy.mReferrerPolicy)
+  , mIntegrity(aCopy.mIntegrity)
+  , mComplete(aCopy.mComplete)
+#ifdef DEBUG
+  , mPrincipalSet(aCopy.mPrincipalSet)
+#endif
+{
+}
+
+void
+StyleSheetInfo::SetURIs(nsIURI* aSheetURI,
+                        nsIURI* aOriginalSheetURI,
+                        nsIURI* aBaseURI)
+{
+  NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
+
+  mSheetURI = aSheetURI;
+  mOriginalSheetURI = aOriginalSheetURI;
+  mBaseURI = aBaseURI;
+}
+
+void
+StyleSheetInfo::SetPrincipal(nsIPrincipal* aPrincipal)
+{
+  NS_PRECONDITION(!mPrincipalSet, "Should only set principal once");
+
+  if (aPrincipal) {
+    mPrincipal = aPrincipal;
+#ifdef DEBUG
+    mPrincipalSet = true;
+#endif
+  }
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/StyleSheetInfo.h
@@ -0,0 +1,59 @@
+/* -*- 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_StyleSheetInfo_h
+#define mozilla_StyleSheetInfo_h
+
+#include "mozilla/dom/SRIMetadata.h"
+#include "mozilla/net/ReferrerPolicy.h"
+#include "mozilla/CORSMode.h"
+
+namespace mozilla {
+class CSSStyleSheet;
+} // namespace mozilla
+class nsCSSRuleProcessor;
+class nsIPrincipal;
+class nsIURI;
+
+namespace mozilla {
+
+/**
+ * Superclass for data common to CSSStyleSheetInner and ServoStyleSheet.
+ */
+class StyleSheetInfo
+{
+public:
+  friend class mozilla::CSSStyleSheet;
+  friend class ::nsCSSRuleProcessor;
+  typedef net::ReferrerPolicy ReferrerPolicy;
+
+  StyleSheetInfo(CORSMode aCORSMode,
+                 ReferrerPolicy aReferrerPolicy,
+                 const dom::SRIMetadata& aIntegrity);
+  StyleSheetInfo(const StyleSheetInfo& aCopy);
+
+  void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
+  void SetPrincipal(nsIPrincipal* aPrincipal);
+
+protected:
+  nsCOMPtr<nsIURI>       mSheetURI; // for error reports, etc.
+  nsCOMPtr<nsIURI>       mOriginalSheetURI;  // for GetHref.  Can be null.
+  nsCOMPtr<nsIURI>       mBaseURI; // for resolving relative URIs
+  nsCOMPtr<nsIPrincipal> mPrincipal;
+  CORSMode               mCORSMode;
+  // The Referrer Policy of a stylesheet is used for its child sheets, so it is
+  // stored here.
+  ReferrerPolicy         mReferrerPolicy;
+  dom::SRIMetadata       mIntegrity;
+  bool                   mComplete;
+#ifdef DEBUG
+  bool                   mPrincipalSet;
+#endif
+};
+
+} // namespace mozilla
+
+#endif // mozilla_StyleSheetInfo_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -95,16 +95,17 @@ EXPORTS.mozilla += [
     'ServoStyleSheet.h',
     'SheetType.h',
     'StyleAnimationValue.h',
     'StyleBackendType.h',
     'StyleSetHandle.h',
     'StyleSetHandleInlines.h',
     'StyleSheetHandle.h',
     'StyleSheetHandleInlines.h',
+    'StyleSheetInfo.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'CSS.h',
     'CSSLexer.h',
     'CSSRuleList.h',
     'CSSValue.h',
     'FontFace.h',
@@ -182,16 +183,17 @@ UNIFIED_SOURCES += [
     'nsTransitionManager.cpp',
     'RuleNodeCacheConditions.cpp',
     'RuleProcessorCache.cpp',
     'ServoBindings.cpp',
     'ServoStyleSet.cpp',
     'ServoStyleSheet.cpp',
     'StyleAnimationValue.cpp',
     'StyleRule.cpp',
+    'StyleSheetInfo.cpp',
     'SVGAttrAnimationRuleProcessor.cpp',
 ]
 
 # nsCSSRuleProcessor.cpp needs to be built separately because it uses plarena.h.
 # nsLayoutStylesheetCache.cpp needs to be built separately because it uses
 # nsExceptionHandler.h, which includes windows.h.
 SOURCES += [
     'nsCSSRuleProcessor.cpp',