Bug 1352968 part 1 - Add separate CSSImportRule base class. r=heycam
authorXidorn Quan <me@upsuper.org>
Tue, 30 May 2017 11:10:25 +1000
changeset 361154 f9483649202059918f25ef173e1a5babe6e9580a
parent 361153 0ac37006d5ace7f389a23d1c5a5229c83b709115
child 361155 c1ff58ddedbb07740b5547d9fff7decdb5cd6221
push id31917
push usercbook@mozilla.com
push dateTue, 30 May 2017 09:14:52 +0000
treeherdermozilla-central@0c712d76d598 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1352968
milestone55.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 1352968 part 1 - Add separate CSSImportRule base class. r=heycam MozReview-Commit-ID: 5h6dmij1elX
dom/bindings/Bindings.conf
layout/style/CSSImportRule.cpp
layout/style/CSSImportRule.h
layout/style/ImportRule.h
layout/style/moz.build
layout/style/nsCSSRules.cpp
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -208,20 +208,16 @@ DOMInterfaces = {
     'headerFile': 'nsCSSRules.h',
 },
 
 'CSSGroupingRule': {
     'concrete': False,
     'nativeType': 'mozilla::css::GroupRule',
 },
 
-'CSSImportRule': {
-    'nativeType': 'mozilla::css::ImportRule',
-},
-
 'CSSLexer': {
     'wrapperCache': False
 },
 
 'CSSPrimitiveValue': {
     'nativeType': 'nsROCSSPrimitiveValue',
 },
 
new file mode 100644
--- /dev/null
+++ b/layout/style/CSSImportRule.cpp
@@ -0,0 +1,54 @@
+/* -*- 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 "mozilla/dom/CSSImportRule.h"
+
+#include "mozilla/dom/CSSImportRuleBinding.h"
+#include "mozilla/dom/MediaList.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_ADDREF_INHERITED(CSSImportRule, css::Rule)
+NS_IMPL_RELEASE_INHERITED(CSSImportRule, css::Rule)
+
+// QueryInterface implementation for CSSImportRule
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CSSImportRule)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
+NS_INTERFACE_MAP_END_INHERITING(css::Rule)
+
+bool
+CSSImportRule::IsCCLeaf() const
+{
+  // We're not a leaf.
+  return false;
+}
+
+NS_IMETHODIMP
+CSSImportRule::GetMedia(nsIDOMMediaList** aMedia)
+{
+  NS_ENSURE_ARG_POINTER(aMedia);
+  NS_ADDREF(*aMedia = Media());
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+CSSImportRule::GetStyleSheet(nsIDOMCSSStyleSheet** aStyleSheet)
+{
+  NS_ENSURE_ARG_POINTER(aStyleSheet);
+  NS_IF_ADDREF(*aStyleSheet = GetStyleSheet());
+  return NS_OK;
+}
+
+/* virtual */ JSObject*
+CSSImportRule::WrapObject(JSContext* aCx,
+                          JS::Handle<JSObject*> aGivenProto)
+{
+  return CSSImportRuleBinding::Wrap(aCx, this, aGivenProto);
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/CSSImportRule.h
@@ -0,0 +1,50 @@
+/* -*- 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_dom_CSSImportRule_h
+#define mozilla_dom_CSSImportRule_h
+
+#include "mozilla/css/Rule.h"
+#include "nsIDOMCSSImportRule.h"
+
+namespace mozilla {
+namespace dom {
+
+class CSSImportRule : public css::Rule
+                    , public nsIDOMCSSImportRule
+{
+protected:
+  using Rule::Rule;
+  virtual ~CSSImportRule() {}
+
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+  bool IsCCLeaf() const final;
+
+  int32_t GetType() const final { return css::Rule::IMPORT_RULE; }
+  using Rule::GetType;
+
+  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
+    const override = 0;
+
+  // nsIDOMCSSImportRule interface
+  NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
+  NS_IMETHOD GetStyleSheet(nsIDOMCSSStyleSheet** aStyleSheet) final;
+
+  // WebIDL interface
+  uint16_t Type() const final { return nsIDOMCSSRule::IMPORT_RULE; }
+  // The XPCOM GetHref is fine, since it never fails.
+  virtual dom::MediaList* Media() const = 0;
+  virtual StyleSheet* GetStyleSheet() const = 0;
+
+  JSObject* WrapObject(JSContext* aCx,
+                       JS::Handle<JSObject*> aGivenProto) override;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_CSSImportRule_h
--- a/layout/style/ImportRule.h
+++ b/layout/style/ImportRule.h
@@ -6,74 +6,65 @@
 /* class for CSS @import rules */
 
 #ifndef mozilla_css_ImportRule_h__
 #define mozilla_css_ImportRule_h__
 
 #include "mozilla/Attributes.h"
 
 #include "mozilla/MemoryReporting.h"
-#include "mozilla/css/Rule.h"
-#include "nsIDOMCSSImportRule.h"
+#include "mozilla/dom/CSSImportRule.h"
 
 class nsMediaList;
 class nsString;
 
 namespace mozilla {
 
 class CSSStyleSheet;
 class StyleSheet;
 
 namespace dom {
 class MediaList;
 }
 
 namespace css {
 
-class ImportRule final : public Rule,
-                         public nsIDOMCSSImportRule
+class ImportRule final : public dom::CSSImportRule
 {
 public:
   ImportRule(nsMediaList* aMedia, const nsString& aURLSpec,
              uint32_t aLineNumber, uint32_t aColumnNumber);
 private:
   // for |Clone|
   ImportRule(const ImportRule& aCopy);
   ~ImportRule();
 public:
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImportRule, Rule)
   NS_DECL_ISUPPORTS_INHERITED
-  virtual bool IsCCLeaf() const override;
 
-  using Rule::GetStyleSheet; // unhide since nsIDOMCSSImportRule has its own GetStyleSheet
+  // unhide since nsIDOMCSSImportRule has its own GetStyleSheet
+  using dom::CSSImportRule::GetStyleSheet;
 
   // Rule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
 #endif
-  virtual int32_t GetType() const override;
-  using Rule::GetType;
   virtual already_AddRefed<Rule> Clone() const override;
 
   void SetSheet(CSSStyleSheet*);
 
   virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
 
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
   // nsIDOMCSSImportRule interface
-  NS_DECL_NSIDOMCSSIMPORTRULE
+  NS_IMETHOD GetHref(nsAString& aHref) final;
 
   // WebIDL interface
-  uint16_t Type() const override;
   void GetCssTextImpl(nsAString& aCssText) const override;
-  // The XPCOM GetHref is fine, since it never fails.
-  dom::MediaList* Media() const;
-  StyleSheet* GetStyleSheet() const;
+  dom::MediaList* Media() const final;
+  StyleSheet* GetStyleSheet() const final;
 
 private:
   nsString  mURLSpec;
   RefPtr<nsMediaList> mMedia;
   RefPtr<CSSStyleSheet> mChildSheet;
 };
 
 } // namespace css
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -131,16 +131,17 @@ EXPORTS.mozilla += [
     'StyleSheet.h',
     'StyleSheetInfo.h',
     'StyleSheetInlines.h',
     'URLExtraData.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'CSS.h',
+    'CSSImportRule.h',
     'CSSKeyframeRule.h',
     'CSSKeyframesRule.h',
     'CSSLexer.h',
     'CSSMediaRule.h',
     'CSSMozDocumentRule.h',
     'CSSNamespaceRule.h',
     'CSSPageRule.h',
     'CSSRuleList.h',
@@ -167,16 +168,17 @@ EXPORTS.mozilla.css += [
     'URLMatchingFunction.h',
 ]
 
 UNIFIED_SOURCES += [
     'AnimationCollection.cpp',
     'BindingStyleRule.cpp',
     'CounterStyleManager.cpp',
     'CSS.cpp',
+    'CSSImportRule.cpp',
     'CSSKeyframeRule.cpp',
     'CSSKeyframesRule.cpp',
     'CSSLexer.cpp',
     'CSSMediaRule.cpp',
     'CSSMozDocumentRule.cpp',
     'CSSPageRule.cpp',
     'CSSRuleList.cpp',
     'CSSStyleSheet.cpp',
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -31,17 +31,16 @@
 
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include "nsStyleUtil.h"
 #include "mozilla/DeclarationBlockInlines.h"
 #include "nsCSSParser.h"
 #include "nsDOMClassInfoID.h"
 #include "mozilla/dom/CSSStyleDeclarationBinding.h"
-#include "mozilla/dom/CSSImportRuleBinding.h"
 #include "mozilla/dom/CSSFontFaceRuleBinding.h"
 #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h"
 #include "mozilla/dom/CSSCounterStyleRuleBinding.h"
 #include "StyleRule.h"
 #include "nsFont.h"
 #include "nsIURI.h"
 #include "mozAutoDocUpdate.h"
 #include "nsCCUncollectableMarker.h"
@@ -168,28 +167,28 @@ Rule::GetParentRule() const
 }
 
 // -------------------------------------------
 // ImportRule
 //
 
 ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec,
                        uint32_t aLineNumber, uint32_t aColumnNumber)
-  : Rule(aLineNumber, aColumnNumber)
+  : CSSImportRule(aLineNumber, aColumnNumber)
   , mURLSpec(aURLSpec)
   , mMedia(aMedia)
 {
   MOZ_ASSERT(aMedia);
   // XXXbz This is really silly.... the mMedia here will be replaced
   // with itself if we manage to load a sheet.  Which should really
   // never fail nowadays, in sane cases.
 }
 
 ImportRule::ImportRule(const ImportRule& aCopy)
-  : Rule(aCopy),
+  : CSSImportRule(aCopy),
     mURLSpec(aCopy.mURLSpec)
 {
   // Whether or not an @import rule has a null sheet is a permanent
   // property of that @import rule, since it is null only if the target
   // sheet failed security checks.
   if (aCopy.mChildSheet) {
     RefPtr<StyleSheet> sheet =
       aCopy.mChildSheet->Clone(nullptr, this, nullptr, nullptr);
@@ -204,32 +203,24 @@ ImportRule::ImportRule(const ImportRule&
 
 ImportRule::~ImportRule()
 {
   if (mChildSheet) {
     mChildSheet->SetOwnerRule(nullptr);
   }
 }
 
-NS_IMPL_ADDREF_INHERITED(ImportRule, Rule)
-NS_IMPL_RELEASE_INHERITED(ImportRule, Rule)
-
-NS_IMPL_CYCLE_COLLECTION_INHERITED(ImportRule, Rule, mMedia, mChildSheet)
-
-bool
-ImportRule::IsCCLeaf() const
-{
-  // We're not a leaf.
-  return false;
-}
+NS_IMPL_ADDREF_INHERITED(ImportRule, CSSImportRule)
+NS_IMPL_RELEASE_INHERITED(ImportRule, CSSImportRule)
+
+NS_IMPL_CYCLE_COLLECTION_INHERITED(ImportRule, CSSImportRule, mMedia, mChildSheet)
 
 // QueryInterface implementation for ImportRule
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
-NS_INTERFACE_MAP_END_INHERITING(Rule)
+NS_INTERFACE_MAP_END_INHERITING(CSSImportRule)
 
 #ifdef DEBUG
 /* virtual */ void
 ImportRule::List(FILE* out, int32_t aIndent) const
 {
   nsAutoCString str;
   // Indent
   for (int32_t indent = aIndent; --indent >= 0; ) {
@@ -243,22 +234,16 @@ ImportRule::List(FILE* out, int32_t aInd
   nsAutoString mediaText;
   mMedia->GetText(mediaText);
   AppendUTF16toUTF8(mediaText, str);
   str.AppendLiteral("\n");
   fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
-/* virtual */ int32_t
-ImportRule::GetType() const
-{
-  return Rule::IMPORT_RULE;
-}
-
 /* virtual */ already_AddRefed<Rule>
 ImportRule::Clone() const
 {
   RefPtr<Rule> clone = new ImportRule(*this);
   return clone.forget();
 }
 
 void
@@ -269,22 +254,16 @@ ImportRule::SetSheet(CSSStyleSheet* aShe
   // set the new sheet
   mChildSheet = aSheet;
   aSheet->SetOwnerRule(this);
 
   // set our medialist to be the same as the sheet's medialist
   mMedia = static_cast<nsMediaList*>(mChildSheet->Media());
 }
 
-uint16_t
-ImportRule::Type() const
-{
-  return nsIDOMCSSRule::IMPORT_RULE;
-}
-
 void
 ImportRule::GetCssTextImpl(nsAString& aCssText) const
 {
   aCssText.AssignLiteral("@import url(");
   nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
   aCssText.Append(')');
   if (mMedia) {
     nsAutoString mediaText;
@@ -311,55 +290,30 @@ ImportRule::GetStyleSheet() const
 
 NS_IMETHODIMP
 ImportRule::GetHref(nsAString & aHref)
 {
   aHref = mURLSpec;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-ImportRule::GetMedia(nsIDOMMediaList * *aMedia)
-{
-  NS_ENSURE_ARG_POINTER(aMedia);
-
-  NS_ADDREF(*aMedia = mMedia);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-ImportRule::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
-{
-  NS_ENSURE_ARG_POINTER(aStyleSheet);
-
-  NS_IF_ADDREF(*aStyleSheet = mChildSheet);
-  return NS_OK;
-}
-
 /* virtual */ size_t
 ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   return aMallocSizeOf(this);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - mURLSpec
   //
   // The following members are not measured:
   // - mMedia, because it is measured via CSSStyleSheet::mMedia
   // - mChildSheet, because it is measured via CSSStyleSheetInner::mSheets
 }
 
-/* virtual */ JSObject*
-ImportRule::WrapObject(JSContext* aCx,
-                       JS::Handle<JSObject*> aGivenProto)
-{
-  return CSSImportRuleBinding::Wrap(aCx, this, aGivenProto);
-}
-
 // -------------------------------------------
 // nsICSSMediaRule
 //
 MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber)
   : CSSMediaRule(aLineNumber, aColumnNumber)
 {
 }