Bug 785630 - nsIDocument's mAttrStyleSheet can be nsRefPtr r=khuey
authorDavid Zbarsky <dzbarsky@gmail.com>
Sun, 26 Aug 2012 12:51:58 -0400
changeset 105519 ad09eafd9bd4da63a3c162bf2dc15248e737a944
parent 105518 029b553451eb52eb3a36a16d4160a9c417fd4bac
child 105520 11a5ebc0e43a196d74ebeed4f60ca64563d2a28c
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerskhuey
bugs785630
milestone17.0a1
Bug 785630 - nsIDocument's mAttrStyleSheet can be nsRefPtr r=khuey
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -1767,17 +1767,17 @@ protected:
 
   // A reference to the element last returned from GetRootElement().
   mozilla::dom::Element* mCachedRootElement;
 
   // We hold a strong reference to mNodeInfoManager through mNodeInfo
   nsNodeInfoManager* mNodeInfoManager; // [STRONG]
   nsRefPtr<mozilla::css::Loader> mCSSLoader;
   nsRefPtr<mozilla::css::ImageLoader> mStyleImageLoader;
-  nsHTMLStyleSheet* mAttrStyleSheet;
+  nsRefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
 
   // The set of all object, embed, applet, video and audio elements for
   // which this is the owner document. (They might not be in the document.)
   // These are non-owning pointers, the elements are responsible for removing
   // themselves when they go away.
   nsAutoPtr<nsTHashtable<nsPtrHashKey<nsIContent> > > mFreezableElements;
 
   // The set of all links that need their status resolved.  Links must add themselves
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1617,17 +1617,16 @@ nsDocument::~nsDocument()
     mStyleSheets[indx]->SetOwningDocument(nullptr);
   }
   indx = mCatalogSheets.Count();
   while (--indx >= 0) {
     mCatalogSheets[indx]->SetOwningDocument(nullptr);
   }
   if (mAttrStyleSheet) {
     mAttrStyleSheet->SetOwningDocument(nullptr);
-    NS_RELEASE(mAttrStyleSheet);
   }
   if (mStyleAttrStyleSheet)
     mStyleAttrStyleSheet->SetOwningDocument(nullptr);
 
   if (mListenerManager) {
     mListenerManager->Disconnect();
     UnsetFlags(NODE_HAS_LISTENERMANAGER);
   }
@@ -2271,17 +2270,16 @@ nsDocument::ResetStylesheetsToURI(nsIURI
     nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
       shell->StyleSet()->RemoveStyleSheet(nsStyleSet::ePresHintSheet,
                                           mAttrStyleSheet);
     }
     mAttrStyleSheet->Reset(aURI);
   } else {
     mAttrStyleSheet = new nsHTMLStyleSheet(aURI, this);
-    NS_ADDREF(mAttrStyleSheet);
   }
 
   // Don't use AddStyleSheet, since it'll put the sheet into style
   // sets in the document level, which is not desirable here.
   mAttrStyleSheet->SetOwningDocument(this);
   
   if (mStyleAttrStyleSheet) {
     // Remove this sheet from all style sets