Bug 811021. Tell catalog sheets they have the document as an owning node so they won't get double-counted by memory reporters. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 29 Nov 2012 18:24:04 -0500
changeset 114914 cfcaffe563703c9d490f13234cafa7cbdd8bd73c
parent 114913 cba447567a56361415e37f8b355a1fd7c1f5d438
child 114915 5bb43720c04cd6b314230d89e38efa54932af684
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersdbaron
bugs811021
milestone20.0a1
Bug 811021. Tell catalog sheets they have the document as an owning node so they won't get double-counted by memory reporters. r=dbaron
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
layout/style/nsCSSStyleSheet.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -595,17 +595,17 @@ public:
                                             bool aApplicable) = 0;  
 
   /**
    * Just like the style sheet API, but for "catalog" sheets,
    * extra sheets inserted at the UA level.
    */
   virtual int32_t GetNumberOfCatalogStyleSheets() const = 0;
   virtual nsIStyleSheet* GetCatalogStyleSheetAt(int32_t aIndex) const = 0;
-  virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet) = 0;
+  virtual void AddCatalogStyleSheet(nsCSSStyleSheet* aSheet) = 0;
   virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI) = 0;
 
   enum additionalSheetType {
     eAgentSheet,
     eUserSheet,
     eAuthorSheet,
     SheetTypeCount
   };
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1405,16 +1405,17 @@ nsDocument::~nsDocument()
 
   // Let the stylesheets know we're going away
   indx = mStyleSheets.Count();
   while (--indx >= 0) {
     mStyleSheets[indx]->SetOwningDocument(nullptr);
   }
   indx = mCatalogSheets.Count();
   while (--indx >= 0) {
+    static_cast<nsCSSStyleSheet*>(mCatalogSheets[indx])->SetOwningNode(nullptr);
     mCatalogSheets[indx]->SetOwningDocument(nullptr);
   }
   if (mAttrStyleSheet) {
     mAttrStyleSheet->SetOwningDocument(nullptr);
   }
   if (mStyleAttrStyleSheet)
     mStyleAttrStyleSheet->SetOwningDocument(nullptr);
 
@@ -3544,20 +3545,21 @@ nsDocument::GetNumberOfCatalogStyleSheet
 nsIStyleSheet*
 nsDocument::GetCatalogStyleSheetAt(int32_t aIndex) const
 {
   NS_ENSURE_TRUE(0 <= aIndex && aIndex < mCatalogSheets.Count(), nullptr);
   return mCatalogSheets[aIndex];
 }
 
 void
-nsDocument::AddCatalogStyleSheet(nsIStyleSheet* aSheet)
+nsDocument::AddCatalogStyleSheet(nsCSSStyleSheet* aSheet)
 {
   mCatalogSheets.AppendObject(aSheet);
   aSheet->SetOwningDocument(this);
+  aSheet->SetOwningNode(this);
 
   if (aSheet->IsApplicable()) {
     // This is like |AddStyleSheetToStyleSets|, but for an agent sheet.
     nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
       shell->StyleSet()->AppendStyleSheet(nsStyleSet::eAgentSheet, aSheet);
     }
   }
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -590,17 +590,17 @@ public:
   virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
 
   virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex);
   virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
                                             bool aApplicable);
 
   virtual int32_t GetNumberOfCatalogStyleSheets() const;
   virtual nsIStyleSheet* GetCatalogStyleSheetAt(int32_t aIndex) const;
-  virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet);
+  virtual void AddCatalogStyleSheet(nsCSSStyleSheet* aSheet);
   virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI);
 
   virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI);
   virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI);
   virtual nsIStyleSheet* FirstAdditionalAuthorSheet();
 
   virtual nsIChannel* GetChannel() const {
     return mChannel;
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -1372,20 +1372,18 @@ uint64_t
 nsCSSStyleSheet::FindOwningWindowInnerID() const
 {
   uint64_t windowID = 0;
   if (mDocument) {
     windowID = mDocument->InnerWindowID();
   }
 
   if (windowID == 0 && mOwningNode) {
-    nsCOMPtr<nsIContent> node = do_QueryInterface(mOwningNode);
-    if (node) {
-      windowID = node->OwnerDoc()->InnerWindowID();
-    }
+    nsCOMPtr<nsINode> node = do_QueryInterface(mOwningNode);
+    windowID = node->OwnerDoc()->InnerWindowID();
   }
 
   if (windowID == 0 && mOwnerRule) {
     nsCOMPtr<nsIStyleSheet> sheet = static_cast<css::Rule*>(mOwnerRule)->GetStyleSheet();
     if (sheet) {
       nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheet);
       if (cssSheet) {
         windowID = cssSheet->FindOwningWindowInnerID();