Remove nsICSSStyleSheet and replace all uses with nsCSSStyleSheet. (Bug 239008) r=dbaron
authorCraig Topper <craig.topper@gmail.com>
Tue, 11 May 2010 13:41:47 -0700
changeset 42163 5329c2d9c968a667427d6b1babf50dfe86caf5c0
parent 42162 c660b23286f592e4966ff5dab769b217214c2010
child 42164 779fd4bb356ec4135ff316119c5dbd5c1ab53995
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs239008
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Remove nsICSSStyleSheet and replace all uses with nsCSSStyleSheet. (Bug 239008) r=dbaron
chrome/src/nsChromeRegistry.cpp
content/base/public/nsIDocument.h
content/base/src/nsContentSink.cpp
content/base/src/nsContentSink.h
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/base/src/nsFrameLoader.cpp
content/base/src/nsStyleLinkElement.cpp
content/xbl/src/nsXBLPrototypeBinding.cpp
content/xbl/src/nsXBLPrototypeBinding.h
content/xbl/src/nsXBLPrototypeResources.cpp
content/xbl/src/nsXBLPrototypeResources.h
content/xbl/src/nsXBLResourceLoader.cpp
content/xbl/src/nsXBLResourceLoader.h
content/xml/document/src/nsXMLContentSink.cpp
content/xml/document/src/nsXMLContentSink.h
content/xslt/src/xslt/txMozillaXMLOutput.cpp
content/xslt/src/xslt/txMozillaXMLOutput.h
content/xul/document/src/nsXULDocument.cpp
content/xul/document/src/nsXULDocument.h
content/xul/document/src/nsXULPrototypeCache.cpp
content/xul/document/src/nsXULPrototypeCache.h
editor/idl/nsIEditorStyleSheets.idl
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditor.h
editor/libeditor/base/nsStyleSheetTxns.cpp
editor/libeditor/base/nsStyleSheetTxns.h
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/html/nsHTMLEditor.h
editor/libeditor/html/nsHTMLEditorStyle.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsPresShell.cpp
layout/base/nsStyleSheetService.cpp
layout/build/nsContentDLF.h
layout/build/nsLayoutStatics.cpp
layout/mathml/nsMathMLFrame.cpp
layout/style/Makefile.in
layout/style/nsCSSLoader.cpp
layout/style/nsCSSLoader.h
layout/style/nsCSSParser.cpp
layout/style/nsCSSParser.h
layout/style/nsCSSRule.cpp
layout/style/nsCSSRule.h
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRuleProcessor.h
layout/style/nsCSSRules.cpp
layout/style/nsCSSRules.h
layout/style/nsCSSStyleRule.cpp
layout/style/nsCSSStyleSheet.cpp
layout/style/nsCSSStyleSheet.h
layout/style/nsICSSGroupRule.h
layout/style/nsICSSImportRule.h
layout/style/nsICSSLoaderObserver.h
layout/style/nsICSSNameSpaceRule.h
layout/style/nsICSSRule.h
layout/style/nsICSSStyleRule.h
layout/style/nsICSSStyleSheet.h
layout/style/nsIMediaList.h
layout/style/nsIStyleSheet.h
layout/style/nsLayoutStylesheetCache.cpp
layout/style/nsLayoutStylesheetCache.h
layout/style/nsStyleSet.cpp
layout/style/test/ParseCSS.cpp
parser/htmlparser/src/nsParser.cpp
--- a/chrome/src/nsChromeRegistry.cpp
+++ b/chrome/src/nsChromeRegistry.cpp
@@ -70,17 +70,17 @@
 #include "nsWidgetsCID.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsXPIDLString.h"
 #include "nsXULAppAPI.h"
 #include "nsTextFormatter.h"
 
 #include "nsIAtom.h"
 #include "nsICommandLine.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIConsoleService.h"
 #include "nsIDirectoryService.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDocShell.h"
 #include "nsIDocumentObserver.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMLocation.h"
@@ -960,17 +960,17 @@ nsresult nsChromeRegistry::RefreshWindow
       nsIStyleSheet *sheet = agentSheets[l];
 
       nsCOMPtr<nsIURI> uri;
       rv = sheet->GetSheetURI(getter_AddRefs(uri));
       if (NS_FAILED(rv)) return rv;
 
       if (IsChromeURI(uri)) {
         // Reload the sheet.
-        nsCOMPtr<nsICSSStyleSheet> newSheet;
+        nsRefPtr<nsCSSStyleSheet> newSheet;
         rv = document->LoadChromeSheetSync(uri, PR_TRUE,
                                            getter_AddRefs(newSheet));
         if (NS_FAILED(rv)) return rv;
         if (newSheet) {
           rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE;
           if (NS_FAILED(rv)) return rv;
         }
       }
@@ -999,22 +999,22 @@ nsresult nsChromeRegistry::RefreshWindow
     if (!oldSheets.AppendObject(styleSheet)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   // Iterate over our old sheets and kick off a sync load of the new
   // sheet if and only if it's a chrome URL.
   for (i = 0; i < count; i++) {
-    nsCOMPtr<nsICSSStyleSheet> sheet = do_QueryInterface(oldSheets[i]);
+    nsRefPtr<nsCSSStyleSheet> sheet = do_QueryObject(oldSheets[i]);
     nsIURI* uri = sheet ? sheet->GetOriginalURI() : nsnull;
 
     if (uri && IsChromeURI(uri)) {
       // Reload the sheet.
-      nsCOMPtr<nsICSSStyleSheet> newSheet;
+      nsRefPtr<nsCSSStyleSheet> newSheet;
       // XXX what about chrome sheets that have a title or are disabled?  This
       // only works by sheer dumb luck.
       document->LoadChromeSheetSync(uri, PR_FALSE, getter_AddRefs(newSheet));
       // Even if it's null, we put in in there.
       newSheets.AppendObject(newSheet);
     }
     else {
       // Just use the same sheet.
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -65,17 +65,17 @@
 
 class nsIContent;
 class nsPresContext;
 class nsIPresShell;
 class nsIDocShell;
 class nsStyleSet;
 class nsIStyleSheet;
 class nsIStyleRule;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 class nsIViewManager;
 class nsIScriptGlobalObject;
 class nsIDOMEvent;
 class nsIDOMEventTarget;
 class nsIDeviceContext;
 class nsIParser;
 class nsIDOMNode;
 class nsIDOMElement;
@@ -111,18 +111,18 @@ class Loader;
 
 namespace dom {
 class Link;
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 #define NS_IDOCUMENT_IID      \
-{ 0xa979dabe, 0x75de, 0x4c2d, \
-  { 0x8b, 0x83, 0x17, 0xb2, 0xde, 0x9d, 0x9d, 0x37 } }
+{ 0x625fe492, 0x0344, 0x406c, \
+  { 0xaf, 0x7f, 0x55, 0xfe, 0xa2, 0x6b, 0x3d, 0x20 } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 // Document states
 
 // RTL locale: specific to the XUL localedir attribute
 #define NS_DOCUMENT_STATE_RTL_LOCALE              (1 << 0)
@@ -1280,17 +1280,17 @@ public:
    * Called by the chrome registry to load style sheets.  Can be put
    * back there if and when when that module is merged with libgklayout.
    *
    * This always does a synchronous load.  If aIsAgentSheet is true,
    * it also uses the system principal and enables unsafe rules.
    * DO NOT USE FOR UNTRUSTED CONTENT.
    */
   virtual nsresult LoadChromeSheetSync(nsIURI* aURI, PRBool aIsAgentSheet,
-                                       nsICSSStyleSheet** aSheet) = 0;
+                                       nsCSSStyleSheet** aSheet) = 0;
 
   /**
    * Returns true if the locale used for the document specifies a direction of
    * right to left. For chrome documents, this comes from the chrome registry.
    * This is used to determine the current state for the :-moz-locale-dir pseudoclass
    * so once can know whether a document is expected to be rendered left-to-right
    * or right-to-left.
    */
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -318,17 +318,17 @@ nsContentSink::Init(nsIDocument* aDoc,
 
   mCanInterruptParser = sCanInterruptParser;
 
   return NS_OK;
 
 }
 
 NS_IMETHODIMP
-nsContentSink::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+nsContentSink::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                 PRBool aWasAlternate,
                                 nsresult aStatus)
 {
   if (!aWasAlternate) {
     NS_ASSERTION(mPendingSheetCount > 0, "How'd that happen?");
     --mPendingSheetCount;
 
     if (mPendingSheetCount == 0 &&
--- a/content/base/src/nsContentSink.h
+++ b/content/base/src/nsContentSink.h
@@ -122,17 +122,17 @@ class nsContentSink : public nsICSSLoade
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsContentSink,
                                            nsIScriptLoaderObserver)
   NS_DECL_NSISCRIPTLOADEROBSERVER
 
     // nsITimerCallback
   NS_DECL_NSITIMERCALLBACK
 
   // nsICSSLoaderObserver
-  NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
+  NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, PRBool aWasAlternate,
                               nsresult aStatus);
 
   virtual nsresult ProcessMETATag(nsIContent* aContent);
 
   // nsIContentSink implementation helpers
   NS_HIDDEN_(nsresult) WillParseImpl(void);
   NS_HIDDEN_(nsresult) WillInterruptImpl(void);
   NS_HIDDEN_(nsresult) WillResumeImpl(void);
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -3551,17 +3551,17 @@ nsDocument::EnsureCatalogStyleSheet(cons
         if (uriStr.Equals(aStyleSheetURI))
           return;
       }
     }
 
     nsCOMPtr<nsIURI> uri;
     NS_NewURI(getter_AddRefs(uri), aStyleSheetURI);
     if (uri) {
-      nsCOMPtr<nsICSSStyleSheet> sheet;
+      nsRefPtr<nsCSSStyleSheet> sheet;
       cssLoader->LoadSheetSync(uri, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
       if (sheet) {
         BeginUpdate(UPDATE_STYLE);
         AddCatalogStyleSheet(sheet);
         EndUpdate(UPDATE_STYLE);
       }
     }
   }
@@ -7580,17 +7580,17 @@ namespace {
 
 /**
  * Stub for LoadSheet(), since all we want is to get the sheet into
  * the CSSLoader's style cache
  */
 class StubCSSLoaderObserver : public nsICSSLoaderObserver {
 public:
   NS_IMETHOD
-  StyleSheetLoaded(nsICSSStyleSheet*, PRBool, nsresult)
+  StyleSheetLoaded(nsCSSStyleSheet*, PRBool, nsresult)
   {
     return NS_OK;
   }
   NS_DECL_ISUPPORTS
 };
 NS_IMPL_ISUPPORTS1(StubCSSLoaderObserver, nsICSSLoaderObserver)
 
 }
@@ -7604,17 +7604,17 @@ nsDocument::PreloadStyle(nsIURI* uri, co
   // Charset names are always ASCII.
   CSSLoader()->LoadSheet(uri, NodePrincipal(),
                          NS_LossyConvertUTF16toASCII(charset),
                          obs);
 }
 
 nsresult
 nsDocument::LoadChromeSheetSync(nsIURI* uri, PRBool isAgentSheet,
-                                nsICSSStyleSheet** sheet)
+                                nsCSSStyleSheet** sheet)
 {
   return CSSLoader()->LoadSheetSync(uri, isAgentSheet, isAgentSheet, sheet);
 }
 
 class nsDelayedEventDispatcher : public nsRunnable
 {
 public:
   nsDelayedEventDispatcher(nsTArray<nsCOMPtr<nsIDocument> >& aDocuments)
@@ -7740,41 +7740,40 @@ nsIDocument::CreateStaticClone(nsISuppor
   nsCOMPtr<nsIDocument> clonedDoc;
   if (NS_SUCCEEDED(rv)) {
     clonedDoc = do_QueryInterface(clonedNode);
     nsCOMPtr<nsIDOMDocument> clonedDOMDoc = do_QueryInterface(clonedDoc);
     if (clonedDOMDoc) {
       clonedDoc->mOriginalDocument = this;
       PRInt32 sheetsCount = GetNumberOfStyleSheets();
       for (PRInt32 i = 0; i < sheetsCount; ++i) {
-        nsCOMPtr<nsICSSStyleSheet> sheet =
-          do_QueryInterface(GetStyleSheetAt(i));
+        nsRefPtr<nsCSSStyleSheet> sheet = do_QueryObject(GetStyleSheetAt(i));
         if (sheet) {
           PRBool applicable = PR_TRUE;
           sheet->GetApplicable(applicable);
           if (applicable) {
-            nsCOMPtr<nsICSSStyleSheet> clonedSheet =
+            nsRefPtr<nsCSSStyleSheet> clonedSheet =
               sheet->Clone(nsnull, nsnull, clonedDoc, nsnull);
             NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!");
             if (clonedSheet) {
               clonedDoc->AddStyleSheet(clonedSheet);
             }
           }
         }
       }
 
       sheetsCount = GetNumberOfCatalogStyleSheets();
       for (PRInt32 i = 0; i < sheetsCount; ++i) {
-        nsCOMPtr<nsICSSStyleSheet> sheet =
-          do_QueryInterface(GetCatalogStyleSheetAt(i));
+        nsRefPtr<nsCSSStyleSheet> sheet =
+          do_QueryObject(GetCatalogStyleSheetAt(i));
         if (sheet) {
           PRBool applicable = PR_TRUE;
           sheet->GetApplicable(applicable);
           if (applicable) {
-            nsCOMPtr<nsICSSStyleSheet> clonedSheet =
+            nsRefPtr<nsCSSStyleSheet> clonedSheet =
               sheet->Clone(nsnull, nsnull, clonedDoc, nsnull);
             NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!");
             if (clonedSheet) {
               clonedDoc->AddCatalogStyleSheet(clonedSheet);
             }
           }
         }
       }
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -914,17 +914,17 @@ public:
 
   void MaybeEndOutermostXBLUpdate();
 
   virtual void MaybePreLoadImage(nsIURI* uri);
 
   virtual void PreloadStyle(nsIURI* uri, const nsAString& charset);
 
   virtual nsresult LoadChromeSheetSync(nsIURI* uri, PRBool isAgentSheet,
-                                       nsICSSStyleSheet** sheet);
+                                       nsCSSStyleSheet** sheet);
 
   virtual nsISupports* GetCurrentContentSink();
 
   virtual PRInt32 GetDocumentState();
 
   virtual void RegisterFileDataUri(nsACString& aUri);
 
   // Only BlockOnload should call this!
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -81,17 +81,16 @@
 #include "nsIURI.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 
 #include "nsGkAtoms.h"
 #include "nsINameSpaceManager.h"
 
 #include "nsThreadUtils.h"
-#include "nsICSSStyleSheet.h"
 #include "nsIContentViewer.h"
 
 class nsAsyncDocShellDestroyer : public nsRunnable
 {
 public:
   nsAsyncDocShellDestroyer(nsIDocShell* aDocShell)
     : mDocShell(aDocShell)
   {
--- a/content/base/src/nsStyleLinkElement.cpp
+++ b/content/base/src/nsStyleLinkElement.cpp
@@ -42,17 +42,17 @@
  * be subclassed by various content nodes that want to load
  * stylesheets (<style>, <link>, processing instructions, etc).
  */
 
 #include "nsStyleLinkElement.h"
 
 #include "nsIContent.h"
 #include "nsCSSLoader.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIDocument.h"
 #include "nsIDOMComment.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMStyleSheet.h"
 #include "nsIDOMText.h"
 #include "nsIUnicharInputStream.h"
 #include "nsISimpleUnicharStreamFactory.h"
 #include "nsNetUtil.h"
@@ -72,23 +72,23 @@ nsStyleLinkElement::nsStyleLinkElement()
 nsStyleLinkElement::~nsStyleLinkElement()
 {
   nsStyleLinkElement::SetStyleSheet(nsnull);
 }
 
 NS_IMETHODIMP 
 nsStyleLinkElement::SetStyleSheet(nsIStyleSheet* aStyleSheet)
 {
-  nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(mStyleSheet);
+  nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(mStyleSheet);
   if (cssSheet) {
     cssSheet->SetOwningNode(nsnull);
   }
 
   mStyleSheet = aStyleSheet;
-  cssSheet = do_QueryInterface(mStyleSheet);
+  cssSheet = do_QueryObject(mStyleSheet);
   if (cssSheet) {
     nsCOMPtr<nsIDOMNode> node;
     CallQueryInterface(this,
                        static_cast<nsIDOMNode**>(getter_AddRefs(node)));
     if (node) {
       cssSheet->SetOwningNode(node);
     }
   }
--- a/content/xbl/src/nsXBLPrototypeBinding.cpp
+++ b/content/xbl/src/nsXBLPrototypeBinding.cpp
@@ -1041,17 +1041,17 @@ nsXBLPrototypeBinding::GetRuleProcessor(
 {
   if (mResources) {
     return mResources->mRuleProcessor;
   }
   
   return nsnull;
 }
 
-nsCOMArray<nsICSSStyleSheet>*
+nsXBLPrototypeResources::sheet_array_type*
 nsXBLPrototypeBinding::GetStyleSheets()
 {
   if (mResources) {
     return &mResources->mStyleSheetList;
   }
 
   return nsnull;
 }
--- a/content/xbl/src/nsXBLPrototypeBinding.h
+++ b/content/xbl/src/nsXBLPrototypeBinding.h
@@ -38,33 +38,33 @@
 
 #ifndef nsXBLPrototypeBinding_h__
 #define nsXBLPrototypeBinding_h__
 
 #include "nsCOMPtr.h"
 #include "nsXBLPrototypeResources.h"
 #include "nsXBLPrototypeHandler.h"
 #include "nsXBLProtoImplMethod.h"
-#include "nsICSSStyleSheet.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsWeakReference.h"
 #include "nsIContent.h"
 #include "nsHashtable.h"
 #include "nsIXBLDocumentInfo.h"
 #include "nsCOMArray.h"
 #include "nsXBLProtoImpl.h"
 
 class nsIAtom;
 class nsIDocument;
 class nsIScriptContext;
 class nsSupportsHashtable;
 class nsIXBLService;
 class nsFixedSizeAllocator;
 class nsXBLProtoImplField;
 class nsXBLBinding;
+class nsCSSStyleSheet;
 
 // *********************************************************************/
 // The XBLPrototypeBinding class
 
 // Instances of this class are owned by the nsXBLDocumentInfo object returned
 // by XBLDocumentInfo().  Consumers who want to refcount things should refcount
 // that.
 class nsXBLPrototypeBinding
@@ -144,22 +144,22 @@ public:
   PRBool IsChrome() { return mXBLDocInfoWeak->IsChrome(); }
   
   PRBool HasBasePrototype() { return mHasBaseProto; }
   void SetHasBasePrototype(PRBool aHasBase) { mHasBaseProto = aHasBase; }
 
   void SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent);
 
   nsIStyleRuleProcessor* GetRuleProcessor();
-  nsCOMArray<nsICSSStyleSheet>* GetStyleSheets();
+  nsXBLPrototypeResources::sheet_array_type* GetStyleSheets();
 
   PRBool HasInsertionPoints() { return mInsertionPointTable != nsnull; }
   
   PRBool HasStyleSheets() {
-    return mResources && mResources->mStyleSheetList.Count() > 0;
+    return mResources && mResources->mStyleSheetList.Length() > 0;
   }
 
   nsresult FlushSkinSheets();
 
   void InstantiateInsertionPoints(nsXBLBinding* aBinding);
 
   // XXXbz this aIndex has nothing to do with an index into the child
   // list of the insertion parent or anything.
--- a/content/xbl/src/nsXBLPrototypeResources.cpp
+++ b/content/xbl/src/nsXBLPrototypeResources.cpp
@@ -31,17 +31,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsICSSStyleSheet.h"
 #include "nsIStyleRuleProcessor.h"
 #include "nsIDocument.h"
 #include "nsIContent.h"
 #include "nsIXBLService.h"
 #include "nsIServiceManager.h"
 #include "nsXBLResourceLoader.h"
 #include "nsXBLPrototypeResources.h"
 #include "nsXBLPrototypeBinding.h"
@@ -98,47 +97,46 @@ static PRBool IsChromeURI(nsIURI* aURI)
   if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome)
     return PR_TRUE;
   return PR_FALSE;
 }
 
 nsresult
 nsXBLPrototypeResources::FlushSkinSheets()
 {
-  if (mStyleSheetList.Count() == 0)
+  if (mStyleSheetList.Length() == 0)
     return NS_OK;
 
   nsCOMPtr<nsIDocument> doc;
   mLoader->mBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(doc));
   mozilla::css::Loader* cssLoader = doc->CSSLoader();
 
   // We have scoped stylesheets.  Reload any chrome stylesheets we
   // encounter.  (If they aren't skin sheets, it doesn't matter, since
   // they'll still be in the chrome cache.
   mRuleProcessor = nsnull;
 
-  nsCOMArray<nsICSSStyleSheet> oldSheets(mStyleSheetList);
+  sheet_array_type oldSheets(mStyleSheetList);
   mStyleSheetList.Clear();
 
-  PRInt32 i;
-  PRInt32 count = oldSheets.Count();
-  for (i = 0; i < count; i++) {
-    nsICSSStyleSheet* oldSheet = oldSheets[i];
+  for (sheet_array_type::size_type i = 0, count = oldSheets.Length();
+       i < count; ++i) {
+    nsCSSStyleSheet* oldSheet = oldSheets[i];
 
     nsCOMPtr<nsIURI> uri;
     oldSheet->GetSheetURI(getter_AddRefs(uri));
 
-    nsCOMPtr<nsICSSStyleSheet> newSheet;
+    nsRefPtr<nsCSSStyleSheet> newSheet;
     if (IsChromeURI(uri)) {
       if (NS_FAILED(cssLoader->LoadSheetSync(uri, getter_AddRefs(newSheet))))
         continue;
     }
     else {
       newSheet = oldSheet;
     }
 
-    mStyleSheetList.AppendObject(newSheet);
+    mStyleSheetList.AppendElement(newSheet);
   }
   mRuleProcessor = new nsCSSRuleProcessor(mStyleSheetList, 
                                           nsStyleSet::eDocSheet);
 
   return NS_OK;
 }
--- a/content/xbl/src/nsXBLPrototypeResources.h
+++ b/content/xbl/src/nsXBLPrototypeResources.h
@@ -37,26 +37,25 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsXBLPrototypeResources_h__
 #define nsXBLPrototypeResources_h__
 
 #include "nsCOMPtr.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsIStyleRuleProcessor.h"
-#include "nsCOMArray.h"
 
 class nsIContent;
 class nsIAtom;
 class nsIDocument;
 class nsIScriptContext;
 class nsSupportsHashtable;
 class nsXBLResourceLoader;
 class nsXBLPrototypeBinding;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 
 // *********************************************************************/
 // The XBLPrototypeResources class
 
 class nsXBLPrototypeResources
 {
 public:
   void LoadResources(PRBool* aResult);
@@ -64,16 +63,17 @@ public:
   void AddResourceListener(nsIContent* aElement);
   nsresult FlushSkinSheets();
 
   nsXBLPrototypeResources(nsXBLPrototypeBinding* aBinding);
   ~nsXBLPrototypeResources();
 
 // MEMBER VARIABLES
   nsXBLResourceLoader* mLoader; // A loader object. Exists only long enough to load resources, and then it dies.
-  nsCOMArray<nsICSSStyleSheet> mStyleSheetList; // A list of loaded stylesheets for this binding.
+  typedef nsTArray<nsRefPtr<nsCSSStyleSheet> > sheet_array_type;
+  sheet_array_type mStyleSheetList; // A list of loaded stylesheets for this binding.
 
   // The list of stylesheets converted to a rule processor.
   nsCOMPtr<nsIStyleRuleProcessor> mRuleProcessor;
 };
 
 #endif
 
--- a/content/xbl/src/nsXBLResourceLoader.cpp
+++ b/content/xbl/src/nsXBLResourceLoader.cpp
@@ -31,17 +31,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIStyleRuleProcessor.h"
 #include "nsIDocument.h"
 #include "nsIContent.h"
 #include "nsIPresShell.h"
 #include "nsIXBLService.h"
 #include "nsIServiceManager.h"
 #include "nsXBLResourceLoader.h"
 #include "nsXBLPrototypeResources.h"
@@ -148,17 +148,17 @@ nsXBLResourceLoader::LoadResources(PRBoo
       PRBool chrome;
       nsresult rv;
       if (NS_SUCCEEDED(url->SchemeIs("chrome", &chrome)) && chrome)
       {
         rv = nsContentUtils::GetSecurityManager()->
           CheckLoadURIWithPrincipal(docPrincipal, url,
                                     nsIScriptSecurityManager::ALLOW_CHROME);
         if (NS_SUCCEEDED(rv)) {
-          nsCOMPtr<nsICSSStyleSheet> sheet;
+          nsRefPtr<nsCSSStyleSheet> sheet;
           rv = cssLoader->LoadSheetSync(url, getter_AddRefs(sheet));
           NS_ASSERTION(NS_SUCCEEDED(rv), "Load failed!!!");
           if (NS_SUCCEEDED(rv))
           {
             rv = StyleSheetLoaded(sheet, PR_FALSE, NS_OK);
             NS_ASSERTION(NS_SUCCEEDED(rv), "Processing the style sheet failed!!!");
           }
         }
@@ -177,26 +177,26 @@ nsXBLResourceLoader::LoadResources(PRBoo
   
   // Destroy our resource list.
   delete mResourceList;
   mResourceList = nsnull;
 }
 
 // nsICSSLoaderObserver
 NS_IMETHODIMP
-nsXBLResourceLoader::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+nsXBLResourceLoader::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                       PRBool aWasAlternate,
                                       nsresult aStatus)
 {
   if (!mResources) {
     // Our resources got destroyed -- just bail out
     return NS_OK;
   }
    
-  mResources->mStyleSheetList.AppendObject(aSheet);
+  mResources->mStyleSheetList.AppendElement(aSheet);
 
   if (!mInLoadResourcesFunc)
     mPendingSheets--;
   
   if (mPendingSheets == 0) {
     // All stylesheets are loaded.  
     mResources->mRuleProcessor =
       new nsCSSRuleProcessor(mResources->mStyleSheetList, 
--- a/content/xbl/src/nsXBLResourceLoader.h
+++ b/content/xbl/src/nsXBLResourceLoader.h
@@ -73,17 +73,17 @@ struct nsXBLResource {
 
 class nsXBLResourceLoader : public nsICSSLoaderObserver
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsXBLResourceLoader)
 
   // nsICSSLoaderObserver
-  NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
+  NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, PRBool aWasAlternate,
                               nsresult aStatus);
 
   void LoadResources(PRBool* aResult);
   void AddResource(nsIAtom* aResourceType, const nsAString& aSrc);
   void AddResourceListener(nsIContent* aElement);
 
   nsXBLResourceLoader(nsXBLPrototypeBinding* aBinding,
                       nsXBLPrototypeResources* aResources);
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -54,17 +54,17 @@
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIDOMComment.h"
 #include "nsIDOMCDATASection.h"
 #include "nsDOMDocumentType.h"
 #include "nsHTMLParts.h"
 #include "nsCRT.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsCSSLoader.h"
 #include "nsGkAtoms.h"
 #include "nsContentUtils.h"
 #include "nsIScriptContext.h"
 #include "nsINameSpaceManager.h"
 #include "nsIServiceManager.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIContentViewer.h"
@@ -457,17 +457,17 @@ nsXMLContentSink::OnTransformDone(nsresu
   ScrollToRef();
 
   originalDocument->EndLoad();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXMLContentSink::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+nsXMLContentSink::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                    PRBool aWasAlternate,
                                    nsresult aStatus)
 {
   if (!mPrettyPrinting) {
     return nsContentSink::StyleSheetLoaded(aSheet, aWasAlternate, aStatus);
   }
 
   if (!mDocument->CSSLoader()->HasPendingLoads()) {
@@ -1252,19 +1252,19 @@ nsXMLContentSink::HandleDoctypeDecl(cons
     return rv;
   }
 
   if (aCatalogData && mCSSLoader && mDocument) {
     // bug 124570 - we only expect additional agent sheets for now -- ignore
     // exit codes, error are not fatal here, just that the stylesheet won't apply
     nsCOMPtr<nsIURI> uri(do_QueryInterface(aCatalogData));
     if (uri) {
-      nsCOMPtr<nsICSSStyleSheet> sheet;
+      nsRefPtr<nsCSSStyleSheet> sheet;
       mCSSLoader->LoadSheetSync(uri, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
-      
+
 #ifdef NS_DEBUG
       nsCAutoString uriStr;
       uri->GetSpec(uriStr);
       printf("Loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed");
 #endif
       if (sheet) {
         mDocument->BeginUpdate(UPDATE_STYLE);
         mDocument->AddCatalogStyleSheet(sheet);
--- a/content/xml/document/src/nsXMLContentSink.h
+++ b/content/xml/document/src/nsXMLContentSink.h
@@ -102,17 +102,17 @@ public:
   virtual nsISupports *GetTarget();
   virtual PRBool IsScriptExecuting();
 
   // nsITransformObserver
   NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument);
   NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument);
 
   // nsICSSLoaderObserver
-  NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
+  NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, PRBool aWasAlternate,
                               nsresult aStatus);
   static PRBool ParsePIData(const nsString &aData, nsString &aHref,
                           nsString &aTitle, nsString &aMedia,
                           PRBool &aIsAlternate);
 
 protected:
   // Start layout.  If aIgnorePendingSheets is true, this will happen even if
   // we still have stylesheet loads pending.  Otherwise, we'll wait until the
--- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp
@@ -52,17 +52,17 @@
 #include "nsContentCID.h"
 #include "nsNetUtil.h"
 #include "nsUnicharUtils.h"
 #include "txAtoms.h"
 #include "txLog.h"
 #include "nsIConsoleService.h"
 #include "nsIDOMDocumentFragment.h"
 #include "nsINameSpaceManager.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "txStringUtils.h"
 #include "txURIUtils.h"
 #include "nsIHTMLDocument.h"
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsIDocumentTransformer.h"
 #include "nsCSSLoader.h"
 #include "nsICharsetAlias.h"
 #include "nsIHTMLContentSink.h"
@@ -980,17 +980,17 @@ txTransformNotifier::ScriptEvaluated(nsr
     if (mScriptElements.RemoveObject(aElement)) {
         SignalTransformEnd();
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP 
-txTransformNotifier::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+txTransformNotifier::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                       PRBool aWasAlternate,
                                       nsresult aStatus)
 {
     if (mPendingStylesheetCount == 0) {
         // We weren't waiting on this stylesheet anyway.  This can happen if
         // SignalTransformEnd got called with an error aResult.  See
         // http://bugzilla.mozilla.org/show_bug.cgi?id=215465.
         return NS_OK;
--- a/content/xslt/src/xslt/txMozillaXMLOutput.h
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.h
@@ -64,17 +64,17 @@ class txTransformNotifier : public nsISc
 {
 public:
     txTransformNotifier();
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSISCRIPTLOADEROBSERVER
     
     // nsICSSLoaderObserver
-    NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+    NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                 PRBool aWasAlternate,
                                 nsresult aStatus);
 
     void Init(nsITransformObserver* aObserver);
     nsresult AddScriptElement(nsIScriptElement* aElement);
     void AddPendingStylesheet();
     void OnTransformEnd(nsresult aResult = NS_OK);
     void OnTransformStart();
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -108,17 +108,17 @@
 #include "nsIScriptGlobalObjectOwner.h"
 #include "nsIScriptRuntime.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsNodeInfoManager.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentUtils.h"
 #include "nsIParser.h"
 #include "nsIParserService.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsCSSLoader.h"
 #include "nsIScriptError.h"
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsEventDispatcher.h"
 #include "nsContentErrors.h"
 #include "nsIObserverService.h"
 #include "nsNodeUtils.h"
 #include "nsIDocShellTreeItem.h"
@@ -3148,17 +3148,17 @@ nsresult
 nsXULDocument::DoneWalking()
 {
     NS_PRECONDITION(mPendingSheets == 0, "there are sheets to be loaded");
     NS_PRECONDITION(!mStillWalking, "walk not done");
 
     // XXXldb This is where we should really be setting the chromehidden
     // attribute.
 
-    PRUint32 count = mOverlaySheets.Count();
+    PRUint32 count = mOverlaySheets.Length();
     for (PRUint32 i = 0; i < count; ++i) {
         AddStyleSheet(mOverlaySheets[i]);
     }
     mOverlaySheets.Clear();
 
     if (!mDocumentLoaded) {
         // Make sure we don't reenter here from StartLayout().  Note that
         // setting mDocumentLoaded to true here means that if StartLayout()
@@ -3258,17 +3258,17 @@ nsXULDocument::DoneWalking()
             }
         }
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXULDocument::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+nsXULDocument::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                 PRBool aWasAlternate,
                                 nsresult aStatus)
 {
     if (!aWasAlternate) {
         // Don't care about when alternate sheets finish loading
 
         NS_ASSERTION(mPendingSheets > 0,
             "Unexpected StyleSheetLoaded notification");
@@ -3888,28 +3888,28 @@ nsXULDocument::AddPrototypeSheets()
 {
     nsresult rv;
 
     const nsCOMArray<nsIURI>& sheets = mCurrentPrototype->GetStyleSheetReferences();
 
     for (PRInt32 i = 0; i < sheets.Count(); i++) {
         nsCOMPtr<nsIURI> uri = sheets[i];
 
-        nsCOMPtr<nsICSSStyleSheet> incompleteSheet;
+        nsRefPtr<nsCSSStyleSheet> incompleteSheet;
         rv = CSSLoader()->LoadSheet(uri,
                                     mCurrentPrototype->DocumentPrincipal(),
                                     EmptyCString(), this,
                                     getter_AddRefs(incompleteSheet));
 
         // XXXldb We need to prevent bogus sheets from being held in the
         // prototype's list, but until then, don't propagate the failure
         // from LoadSheet (and thus exit the loop).
         if (NS_SUCCEEDED(rv)) {
             ++mPendingSheets;
-            if (!mOverlaySheets.AppendObject(incompleteSheet)) {
+            if (!mOverlaySheets.AppendElement(incompleteSheet)) {
                 return NS_ERROR_OUT_OF_MEMORY;
             }
         }
     }
 
     return NS_OK;
 }
 
--- a/content/xul/document/src/nsXULDocument.h
+++ b/content/xul/document/src/nsXULDocument.h
@@ -171,17 +171,17 @@ public:
 
     // nsIDOMXULDocument interface
     NS_DECL_NSIDOMXULDOCUMENT
 
     // nsIDOMNSDocument
     NS_IMETHOD GetContentType(nsAString& aContentType);
 
     // nsICSSLoaderObserver
-    NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+    NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                 PRBool aWasAlternate,
                                 nsresult aStatus);
 
     virtual void EndUpdate(nsUpdateType aUpdateType);
 
     virtual PRBool IsDocumentRightToLeft();
 
     virtual void ResetDocumentDirection();
@@ -299,17 +299,17 @@ protected:
      * called in this situation.
      */
     PRPackedBool               mStillWalking;
 
     /**
      * An array of style sheets, that will be added (preserving order) to the
      * document after all of them are loaded (in DoneWalking).
      */
-    nsCOMArray<nsICSSStyleSheet> mOverlaySheets;
+    nsTArray<nsRefPtr<nsCSSStyleSheet> > mOverlaySheets;
 
     nsCOMPtr<nsIDOMXULCommandDispatcher>     mCommandDispatcher; // [OWNER] of the focus tracker
 
     // Maintains the template builders that have been attached to
     // content elements
     typedef nsInterfaceHashtable<nsISupportsHashKey, nsIXULTemplateBuilder>
         BuilderTable;
     BuilderTable* mTemplateBuilderTable;
--- a/content/xul/document/src/nsXULPrototypeCache.cpp
+++ b/content/xul/document/src/nsXULPrototypeCache.cpp
@@ -40,17 +40,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsXULPrototypeCache.h"
 
 #include "nsContentUtils.h"
 #include "plstr.h"
 #include "nsXULPrototypeDocument.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIScriptRuntime.h"
 #include "nsIServiceManager.h"
 #include "nsIURI.h"
 #include "nsIXBLDocumentInfo.h"
 
 #include "nsIChromeRegistry.h"
 #include "nsIFastLoadService.h"
 #include "nsIFastLoadFileControl.h"
@@ -238,17 +238,17 @@ nsXULPrototypeCache::PutPrototype(nsXULP
     nsCOMPtr<nsIURI> uri = aDocument->GetURI();
     // Put() releases any old value and addrefs the new one
     NS_ENSURE_TRUE(mPrototypeTable.Put(uri, aDocument), NS_ERROR_OUT_OF_MEMORY);
 
     return NS_OK;
 }
 
 nsresult
-nsXULPrototypeCache::PutStyleSheet(nsICSSStyleSheet* aStyleSheet)
+nsXULPrototypeCache::PutStyleSheet(nsCSSStyleSheet* aStyleSheet)
 {
     nsCOMPtr<nsIURI> uri;
     nsresult rv = aStyleSheet->GetSheetURI(getter_AddRefs(uri));
     if (NS_FAILED(rv))
         return rv;
 
    NS_ENSURE_TRUE(mStyleSheetTable.Put(uri, aStyleSheet),
                   NS_ERROR_OUT_OF_MEMORY);
@@ -340,17 +340,17 @@ FlushSkinXBL(nsIURI* aKey, nsCOMPtr<nsIX
   if (!strncmp(str.get(), "/skin", 5)) {
     ret = PL_DHASH_REMOVE;
   }
 
   return ret;
 }
 
 static PLDHashOperator
-FlushSkinSheets(nsIURI* aKey, nsCOMPtr<nsICSSStyleSheet>& aSheet, void* aClosure)
+FlushSkinSheets(nsIURI* aKey, nsRefPtr<nsCSSStyleSheet>& aSheet, void* aClosure)
 {
   nsCOMPtr<nsIURI> uri;
   aSheet->GetSheetURI(getter_AddRefs(uri));
   nsCAutoString str;
   uri->GetPath(str);
 
   PLDHashOperator ret = PL_DHASH_NEXT;
 
--- a/content/xul/document/src/nsXULPrototypeCache.h
+++ b/content/xul/document/src/nsXULPrototypeCache.h
@@ -39,27 +39,27 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsXULPrototypeCache_h__
 #define nsXULPrototypeCache_h__
 
 #include "nsCOMPtr.h"
-#include "nsICSSStyleSheet.h"
 #include "nsIObserver.h"
 #include "nsIXBLDocumentInfo.h"
 #include "nsIXULPrototypeCache.h"
 #include "nsDataHashtable.h"
 #include "nsInterfaceHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsURIHashKey.h"
 #include "nsXULPrototypeDocument.h"
 
 class nsIFastLoadService;
+class nsCSSStyleSheet;
 
 struct CacheScriptEntry
 {
     PRUint32    mScriptTypeID; // the script language ID.
     void*       mScriptObject; // the script object.
 };
 
 /**
@@ -120,25 +120,25 @@ public:
         return mXBLDocTable.GetWeak(aURL);
     }
     nsresult PutXBLDocumentInfo(nsIXBLDocumentInfo* aDocumentInfo);
 
     /**
      * Get a style sheet by URI. If the style sheet is not in the cache,
      * returns nsnull.
      */
-    nsICSSStyleSheet* GetStyleSheet(nsIURI* aURI) {
+    nsCSSStyleSheet* GetStyleSheet(nsIURI* aURI) {
         return mStyleSheetTable.GetWeak(aURI);
     }
 
     /**
      * Store a style sheet in the cache. The key, style sheet's URI is obtained
      * from the style sheet itself.
      */
-    nsresult PutStyleSheet(nsICSSStyleSheet* aStyleSheet);
+    nsresult PutStyleSheet(nsCSSStyleSheet* aStyleSheet);
 
 
     static nsXULPrototypeCache* GetInstance();
     static nsIFastLoadService* GetFastLoadService();
 
     static void ReleaseGlobals()
     {
         NS_IF_RELEASE(sInstance);
@@ -152,17 +152,17 @@ protected:
     virtual ~nsXULPrototypeCache();
 
     static nsXULPrototypeCache* sInstance;
 
     void FlushScripts();
     void FlushSkinFiles();
 
     nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument>  mPrototypeTable; // owns the prototypes
-    nsInterfaceHashtable<nsURIHashKey,nsICSSStyleSheet>    mStyleSheetTable;
+    nsRefPtrHashtable<nsURIHashKey,nsCSSStyleSheet>        mStyleSheetTable;
     nsDataHashtable<nsURIHashKey,CacheScriptEntry>         mScriptTable;
     nsInterfaceHashtable<nsURIHashKey,nsIXBLDocumentInfo>  mXBLDocTable;
 
     ///////////////////////////////////////////////////////////////////////////
     // FastLoad
     // this is really a hash set, with a dummy data parameter
     nsDataHashtable<nsURIHashKey,PRUint32> mFastLoadURITable;
 
--- a/editor/idl/nsIEditorStyleSheets.idl
+++ b/editor/idl/nsIEditorStyleSheets.idl
@@ -34,20 +34,20 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 %{C++
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 %}
 
-[ptr] native nsICSSStyleSheet(nsICSSStyleSheet);
+[ptr] native nsCSSStyleSheet(nsCSSStyleSheet);
 
 [scriptable, uuid(4805e682-49b9-11d3-9ce4-ed60bd6cb5bc)]
 
 interface nsIEditorStyleSheets : nsISupports
 {
   /** Load and apply the style sheet, specified by aURL, to the
     * editor's document, replacing the last style sheet added (if any).
     * This is always asynchronous, and may cause network I/O.
@@ -103,22 +103,22 @@ interface nsIEditorStyleSheets : nsISupp
   /** Enable or disable the given style sheet from the editor's document
     * This is always synchronous
     *
     * @param aURL  The style sheet to be enabled or disabled
     * @param aEnable true to enable, or false to disable the style sheet
     */
   void enableStyleSheet(in AString aURL, in PRBool aEnable);
 
-  /** Get the nsICSSStyleSheet associated with the given URL.
+  /** Get the nsCSSStyleSheet associated with the given URL.
     *
     * @param aURL         The style sheet's URL
     * @return             the style sheet
     */
-  [noscript] nsICSSStyleSheet getStyleSheetForURL(in AString aURL);
+  [noscript] nsCSSStyleSheet getStyleSheetForURL(in AString aURL);
 
-  /** Get the URL associated with the given nsICSSStyleSheet.
+  /** Get the URL associated with the given nsCSSStyleSheet.
     *
     * @param aStyleSheet  The style sheet
     * @return             the style sheet's URL
     */
-  [noscript] AString getURLForStyleSheet(in nsICSSStyleSheet aStyleSheet);
+  [noscript] AString getURLForStyleSheet(in nsCSSStyleSheet aStyleSheet);
 };
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -74,17 +74,17 @@
 #include "nsIAtom.h"
 #include "nsCaret.h"
 #include "nsIWidget.h"
 #include "nsIPlaintextEditor.h"
 #include "nsGUIEvent.h"  // nsTextEventReply
 
 #include "nsIFrame.h"  // Needed by IME code
 
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 
 #include "nsIContent.h"
 #include "nsServiceManagerUtils.h"
 
 // transactions the editor knows how to build
 #include "EditAggregateTxn.h"
 #include "PlaceholderTxn.h"
 #include "ChangeAttributeTxn.h"
@@ -4596,30 +4596,30 @@ nsEditor::CreateTxnForIMEText(const nsAS
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(mIMETextNode, mIMETextOffset, mIMEBufferLength,
                        mIMETextRangeList, aStringToInsert, mSelConWeak);
 }
 
 
 NS_IMETHODIMP 
-nsEditor::CreateTxnForAddStyleSheet(nsICSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn)
+nsEditor::CreateTxnForAddStyleSheet(nsCSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn)
 {
   *aTxn = new AddStyleSheetTxn();
   if (! *aTxn)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aSheet);
 }
 
 
 
 NS_IMETHODIMP 
-nsEditor::CreateTxnForRemoveStyleSheet(nsICSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn)
+nsEditor::CreateTxnForRemoveStyleSheet(nsCSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn)
 {
   *aTxn = new RemoveStyleSheetTxn();
   if (! *aTxn)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aSheet);
 }
--- a/editor/libeditor/base/nsEditor.h
+++ b/editor/libeditor/base/nsEditor.h
@@ -53,17 +53,16 @@
 #include "nsIDOMCharacterData.h"
 #include "nsIPrivateTextRange.h"
 #include "nsITransactionManager.h"
 #include "nsIComponentManager.h"
 #include "nsCOMArray.h"
 #include "nsIEditActionListener.h"
 #include "nsIEditorObserver.h"
 #include "nsIDocumentStateListener.h"
-#include "nsICSSStyleSheet.h"
 #include "nsIDOMElement.h"
 #include "nsSelectionState.h"
 #include "nsIEditorSpellCheck.h"
 #include "nsIInlineSpellChecker.h"
 #include "nsPIDOMEventTarget.h"
 #include "nsStubMutationObserver.h"
 #include "nsIViewManager.h"
 #include "nsCycleCollectionParticipant.h"
@@ -81,16 +80,17 @@ class SplitElementTxn;
 class JoinElementTxn;
 class EditAggregateTxn;
 class IMETextTxn;
 class AddStyleSheetTxn;
 class RemoveStyleSheetTxn;
 class nsIFile;
 class nsISelectionController;
 class nsIDOMEventTarget;
+class nsCSSStyleSheet;
 
 #define kMOZEditorBogusNodeAttrAtom nsEditProperty::mozEditorBogusNode
 #define kMOZEditorBogusNodeValue NS_LITERAL_STRING("TRUE")
 
 /** implementation of an editor object.  it will be the controller/focal point 
  *  for the main editor services. i.e. the GUIManager, publishing, transaction 
  *  manager, event interfaces. the idea for the event interfaces is to have them 
  *  delegate the actual commands to the editor independent of the XPFE implementation.
@@ -255,21 +255,21 @@ protected:
                                     PRInt32 aOffset,
                                     InsertTextTxn ** aTxn);
 
   NS_IMETHOD CreateTxnForIMEText(const nsAString & aStringToInsert,
                                  IMETextTxn ** aTxn);
 
   /** create a transaction for adding a style sheet
     */
-  NS_IMETHOD CreateTxnForAddStyleSheet(nsICSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn);
+  NS_IMETHOD CreateTxnForAddStyleSheet(nsCSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn);
 
   /** create a transaction for removing a style sheet
     */
-  NS_IMETHOD CreateTxnForRemoveStyleSheet(nsICSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn);
+  NS_IMETHOD CreateTxnForRemoveStyleSheet(nsCSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn);
   
   NS_IMETHOD DeleteText(nsIDOMCharacterData *aElement,
                         PRUint32             aOffset,
                         PRUint32             aLength);
 
 //  NS_IMETHOD DeleteRange(nsIDOMRange *aRange);
 
   NS_IMETHOD CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
--- a/editor/libeditor/base/nsStyleSheetTxns.cpp
+++ b/editor/libeditor/base/nsStyleSheetTxns.cpp
@@ -33,17 +33,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #include "nsEditor.h"
 
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIDocument.h"
 #include "nsIDocumentObserver.h"
 #include "nsISelectionController.h"
 
 
 #include "nsStyleSheetTxns.h"
 
 static void
@@ -80,33 +80,30 @@ AddStyleSheetTxn::AddStyleSheetTxn()
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(AddStyleSheetTxn)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AddStyleSheetTxn, EditTxn)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSheet)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AddStyleSheetTxn, EditTxn)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSheet)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mSheet, nsIStyleSheet)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn)
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMETHODIMP
-AddStyleSheetTxn::Init(nsIEditor *aEditor, nsICSSStyleSheet *aSheet)
+AddStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
 {
-  if (!aEditor)
-    return NS_ERROR_INVALID_ARG;
-
-  if (!aSheet)
+  if (!aEditor || !aSheet)
     return NS_ERROR_INVALID_ARG;
 
   mEditor = aEditor;
-  mSheet = do_QueryInterface(aSheet);
+  mSheet = aSheet;
   
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 AddStyleSheetTxn::DoTransaction()
 {
@@ -147,34 +144,31 @@ RemoveStyleSheetTxn::RemoveStyleSheetTxn
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(RemoveStyleSheetTxn)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(RemoveStyleSheetTxn, EditTxn)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSheet)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(RemoveStyleSheetTxn, EditTxn)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSheet)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mSheet, nsIStyleSheet)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn)
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMETHODIMP
-RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsICSSStyleSheet *aSheet)
+RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
 {
-  if (!aEditor)
-    return NS_ERROR_INVALID_ARG;
-
-  if (!aSheet)
+  if (!aEditor || !aSheet)
     return NS_ERROR_INVALID_ARG;
 
   mEditor = aEditor;
-  mSheet = do_QueryInterface(aSheet);
-  
+  mSheet = aSheet;
+
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 RemoveStyleSheetTxn::DoTransaction()
 {
   if (!mEditor || !mSheet)
--- a/editor/libeditor/base/nsStyleSheetTxns.h
+++ b/editor/libeditor/base/nsStyleSheetTxns.h
@@ -36,61 +36,60 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsStylesheetTxns_h__
 #define nsStylesheetTxns_h__
 
 #include "EditTxn.h"
 #include "nsCOMPtr.h"
 #include "nsIEditor.h"
-#include "nsICSSStyleSheet.h"
 
 class AddStyleSheetTxn : public EditTxn
 {
 public:
   /** Initialize the transaction.
     * @param aEditor the object providing core editing operations
     * @param aSheet   the stylesheet to add
     */
   NS_IMETHOD Init(nsIEditor         *aEditor,
-                  nsICSSStyleSheet  *aSheet);
+                  nsCSSStyleSheet   *aSheet);
 
   AddStyleSheetTxn();
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AddStyleSheetTxn, EditTxn)
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
 
   NS_DECL_EDITTXN
 
 protected:
 
-  nsIEditor*  mEditor;									// the editor that created this transaction
-  nsCOMPtr<nsICSSStyleSheet>	mSheet;		// the style sheet to add
-  
+  nsIEditor*  mEditor;                  // the editor that created this transaction
+  nsRefPtr<nsCSSStyleSheet>  mSheet;    // the style sheet to add
+
 };
 
 
 class RemoveStyleSheetTxn : public EditTxn
 {
 public:
   /** Initialize the transaction.
     * @param aEditor the object providing core editing operations
     * @param aSheet   the stylesheet to remove
     */
   NS_IMETHOD Init(nsIEditor         *aEditor,
-                  nsICSSStyleSheet  *aSheet);
-	
+                  nsCSSStyleSheet   *aSheet);
+
   RemoveStyleSheetTxn();
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(RemoveStyleSheetTxn, EditTxn)
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
 
   NS_DECL_EDITTXN
 
 protected:
 
-  nsIEditor*  mEditor;									// the editor that created this transaction
-  nsCOMPtr<nsICSSStyleSheet>	mSheet;		// the style sheet to remove
-  
+  nsIEditor*  mEditor;                  // the editor that created this transaction
+  nsRefPtr<nsCSSStyleSheet>  mSheet;    // the style sheet to remove
+
 };
 
 
 #endif /* nsStylesheetTxns_h__ */
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -57,17 +57,16 @@
 #include "nsIDOMComment.h"
 #include "nsISelection.h"
 #include "nsISelectionPrivate.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsIDOMHTMLImageElement.h"
 #include "nsISelectionController.h"
 #include "nsIFileChannel.h"
 
-#include "nsICSSStyleSheet.h"
 #include "nsIDocumentObserver.h"
 #include "nsIDocumentStateListener.h"
 
 #include "nsIEnumerator.h"
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMNSRange.h"
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -67,17 +67,17 @@
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsISelectionController.h"
 #include "nsIDOMHTMLHtmlElement.h"
 #include "nsGUIEvent.h"
 #include "nsIDOMEventGroup.h"
 #include "nsILinkHandler.h"
 
 #include "nsCSSLoader.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIDOMStyleSheet.h"
 #include "nsIDocumentObserver.h"
 #include "nsIDocumentStateListener.h"
 
 #include "nsIEnumerator.h"
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
 #include "nsIDOMRange.h"
@@ -3381,17 +3381,17 @@ nsHTMLEditor::ReplaceStyleSheet(const ns
 
   return ps->GetDocument()->CSSLoader()->
     LoadSheet(uaURI, nsnull, EmptyCString(), this);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::RemoveStyleSheet(const nsAString &aURL)
 {
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
   if (!sheet)
     return NS_ERROR_UNEXPECTED;
 
   nsRefPtr<RemoveStyleSheetTxn> txn;
   rv = CreateTxnForRemoveStyleSheet(sheet, getter_AddRefs(txn));
   if (!txn) rv = NS_ERROR_NULL_POINTER;
@@ -3423,17 +3423,17 @@ nsHTMLEditor::AddOverrideStyleSheet(cons
 
   nsCOMPtr<nsIURI> uaURI;
   nsresult rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We MUST ONLY load synchronous local files (no @import)
   // XXXbz Except this will actually try to load remote files
   // synchronously, of course..
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   // Editor override style sheets may want to style Gecko anonymous boxes
   rv = ps->GetDocument()->CSSLoader()->
     LoadSheetSync(uaURI, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
 
   // Synchronous loads should ALWAYS return completed
   if (!sheet)
     return NS_ERROR_NULL_POINTER;
 
@@ -3468,17 +3468,17 @@ nsHTMLEditor::ReplaceOverrideStyleSheet(
 
   return AddOverrideStyleSheet(aURL);
 }
 
 // Do NOT use transaction system for override style sheets
 NS_IMETHODIMP
 nsHTMLEditor::RemoveOverrideStyleSheet(const nsAString &aURL)
 {
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
 
   // Make sure we remove the stylesheet from our internal list in all
   // cases.
   nsresult rv = RemoveStyleSheetFromList(aURL);
 
   if (!sheet)
     return NS_OK; /// Don't fail if sheet not found
@@ -3492,96 +3492,88 @@ nsHTMLEditor::RemoveOverrideStyleSheet(c
 
   // Remove it from our internal list
   return rv;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::EnableStyleSheet(const nsAString &aURL, PRBool aEnable)
 {
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
   if (!sheet)
     return NS_OK; // Don't fail if sheet not found
 
-  nsCOMPtr<nsIDOMStyleSheet> domSheet(do_QueryInterface(sheet));
-  NS_ASSERTION(domSheet, "Sheet not implementing nsIDOMStyleSheet!");
-
   // Ensure the style sheet is owned by our document.
   nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
   rv = sheet->SetOwningDocument(doc);
   NS_ENSURE_SUCCESS(rv, rv);
   
-  return domSheet->SetDisabled(!aEnable);
+  return sheet->SetDisabled(!aEnable);
 }
 
 PRBool
 nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL)
 {
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
   if (NS_FAILED(rv))
     return PR_FALSE;
 
   // Enable sheet if already loaded.
   if (sheet)
   {
     // Ensure the style sheet is owned by our document.
     nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
     rv = sheet->SetOwningDocument(doc);
     if (NS_FAILED(rv))
       return PR_FALSE;
 
-    nsCOMPtr<nsIDOMStyleSheet> domSheet(do_QueryInterface(sheet));
-    NS_ASSERTION(domSheet, "Sheet not implementing nsIDOMStyleSheet!");
-    
-    domSheet->SetDisabled(PR_FALSE);
+    sheet->SetDisabled(PR_FALSE);
     return PR_TRUE;
   }
   return PR_FALSE;
 }
 
 nsresult
 nsHTMLEditor::AddNewStyleSheetToList(const nsAString &aURL,
-                                     nsICSSStyleSheet *aStyleSheet)
+                                     nsCSSStyleSheet *aStyleSheet)
 {
-  PRInt32 countSS = mStyleSheets.Count();
+  PRUint32 countSS = mStyleSheets.Length();
   PRUint32 countU = mStyleSheetURLs.Length();
 
   if (countU < 0 || countSS != countU)
     return NS_ERROR_UNEXPECTED;
 
   if (!mStyleSheetURLs.AppendElement(aURL))
     return NS_ERROR_UNEXPECTED;
 
-  return mStyleSheets.AppendObject(aStyleSheet) ? NS_OK : NS_ERROR_UNEXPECTED;
+  return mStyleSheets.AppendElement(aStyleSheet) ? NS_OK : NS_ERROR_UNEXPECTED;
 }
 
 nsresult
 nsHTMLEditor::RemoveStyleSheetFromList(const nsAString &aURL)
 {
   // is it already in the list?
   PRUint32 foundIndex;
   foundIndex = mStyleSheetURLs.IndexOf(aURL);
   if (foundIndex == mStyleSheetURLs.NoIndex)
     return NS_ERROR_FAILURE;
 
   // Attempt both removals; if one fails there's not much we can do.
-  nsresult rv = NS_OK;
-  if (!mStyleSheets.RemoveObjectAt(foundIndex))
-    rv = NS_ERROR_FAILURE;
+  mStyleSheets.RemoveElementAt(foundIndex);
   mStyleSheetURLs.RemoveElementAt(foundIndex);
 
-  return rv;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetStyleSheetForURL(const nsAString &aURL,
-                                  nsICSSStyleSheet **aStyleSheet)
+                                  nsCSSStyleSheet **aStyleSheet)
 {
   NS_ENSURE_ARG_POINTER(aStyleSheet);
   *aStyleSheet = 0;
 
   // is it already in the list?
   PRUint32 foundIndex;
   foundIndex = mStyleSheetURLs.IndexOf(aURL);
   if (foundIndex == mStyleSheetURLs.NoIndex)
@@ -3592,17 +3584,17 @@ nsHTMLEditor::GetStyleSheetForURL(const 
     return NS_ERROR_FAILURE;
 
   NS_ADDREF(*aStyleSheet);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsHTMLEditor::GetURLForStyleSheet(nsICSSStyleSheet *aStyleSheet,
+nsHTMLEditor::GetURLForStyleSheet(nsCSSStyleSheet *aStyleSheet,
                                   nsAString &aURL)
 {
   // is it already in the list?
   PRInt32 foundIndex = mStyleSheets.IndexOf(aStyleSheet);
 
   // Don't fail if we don't find it in our list
   // Note: mStyleSheets is nsCOMArray, so its IndexOf() method
   // returns -1 on failure.
@@ -3887,17 +3879,17 @@ nsHTMLEditor::DebugUnitTests(PRInt32 *ou
 #ifdef XP_MAC
 #pragma mark -
 #pragma mark  StyleSheet utils 
 #pragma mark -
 #endif
 
 
 NS_IMETHODIMP 
-nsHTMLEditor::StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
+nsHTMLEditor::StyleSheetLoaded(nsCSSStyleSheet* aSheet, PRBool aWasAlternate,
                                nsresult aStatus)
 {
   nsresult rv = NS_OK;
   nsAutoEditBatch batchIt(this);
 
   if (!mLastStyleSheetURL.IsEmpty())
     RemoveStyleSheet(mLastStyleSheetURL);
 
@@ -3905,19 +3897,18 @@ nsHTMLEditor::StyleSheetLoaded(nsICSSSty
   rv = CreateTxnForAddStyleSheet(aSheet, getter_AddRefs(txn));
   if (!txn) rv = NS_ERROR_NULL_POINTER;
   if (NS_SUCCEEDED(rv))
   {
     rv = DoTransaction(txn);
     if (NS_SUCCEEDED(rv))
     {
       // Get the URI, then url spec from the sheet
-      nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
       nsCOMPtr<nsIURI> uri;
-      rv = sheet->GetSheetURI(getter_AddRefs(uri));
+      rv = aSheet->GetSheetURI(getter_AddRefs(uri));
 
       if (NS_SUCCEEDED(rv))
       {
         nsCAutoString spec;
         rv = uri->GetSpec(spec);
 
         if (NS_SUCCEEDED(rv))
         {
--- a/editor/libeditor/html/nsHTMLEditor.h
+++ b/editor/libeditor/html/nsHTMLEditor.h
@@ -65,16 +65,17 @@
 #include "nsIHTMLAbsPosEditor.h"
 #include "nsIHTMLInlineTableEditor.h"
 #include "nsIHTMLObjectResizeListener.h"
 
 #include "nsIDocumentObserver.h"
 
 #include "nsPoint.h"
 #include "nsTArray.h"
+#include "nsAutoPtr.h"
 
 class nsIDOMKeyEvent;
 class nsITransferable;
 class nsIDOMNSRange;
 class nsIDocumentEncoder;
 class nsIClipboard;
 class TypeInState;
 class nsIContentFilter;
@@ -364,17 +365,17 @@ public:
                             nsCOMPtr<nsIDOMNode> *aInOutNode, 
                             PRInt32 *aInOutOffset,
                             nsIDOMDocument *aDoc);
   NS_IMETHOD_(PRBool) IsModifiableNode(nsIDOMNode *aNode);
 
   NS_IMETHOD SelectAll();
 
   /* ------------ nsICSSLoaderObserver -------------- */
-  NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aWasAlternate,
+  NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet*aSheet, PRBool aWasAlternate,
                               nsresult aStatus);
 
   /* ------------ Utility Routines, not part of public API -------------- */
   NS_IMETHOD TypedText(const nsAString& aString, PRInt32 aAction);
   nsresult InsertNodeAtPoint( nsIDOMNode *aNode, 
                               nsCOMPtr<nsIDOMNode> *ioParent, 
                               PRInt32 *ioOffset, 
                               PRBool aNoEmptyNodes);
@@ -412,22 +413,22 @@ public:
                            PRBool aSafeToAskFrames,
                            PRBool *aSeenBR);
 
   // Returns TRUE if sheet was loaded, false if it wasn't
   PRBool   EnableExistingStyleSheet(const nsAString& aURL);
 
   // Dealing with the internal style sheet lists:
   NS_IMETHOD GetStyleSheetForURL(const nsAString &aURL,
-                               nsICSSStyleSheet **_retval);
-  NS_IMETHOD GetURLForStyleSheet(nsICSSStyleSheet *aStyleSheet, nsAString &aURL);
+                                 nsCSSStyleSheet **_retval);
+  NS_IMETHOD GetURLForStyleSheet(nsCSSStyleSheet *aStyleSheet, nsAString &aURL);
 
   // Add a url + known style sheet to the internal lists:
   nsresult AddNewStyleSheetToList(const nsAString &aURL,
-                                  nsICSSStyleSheet *aStyleSheet);
+                                  nsCSSStyleSheet *aStyleSheet);
 
   nsresult RemoveStyleSheetFromList(const nsAString &aURL);
                        
 protected:
 
   NS_IMETHOD  InitRules();
 
   // Create the event listeners for the editor to install
@@ -747,17 +748,17 @@ protected:
   // Used by GetFirstSelectedCell and GetNextSelectedCell
   PRInt32  mSelectedCellIndex;
 
   nsString mLastStyleSheetURL;
   nsString mLastOverrideStyleSheetURL;
 
   // Maintain a list of associated style sheets and their urls.
   nsTArray<nsString> mStyleSheetURLs;
-  nsCOMArray<nsICSSStyleSheet> mStyleSheets;
+  nsTArray<nsRefPtr<nsCSSStyleSheet> > mStyleSheets;
   
   // an array for holding default style settings
   nsTArray<PropItem*> mDefaultStyles;
 
    // for real-time spelling
    nsCOMPtr<nsITextServicesDocument> mTextServices;
 
   // And a static range utils service
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -46,17 +46,16 @@
 #include "nsIDOMAttr.h"
 #include "nsIDOMKeyListener.h" 
 #include "nsIDOMMouseListener.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsISelection.h"
 #include "nsISelectionPrivate.h"
 #include "nsIDOMHTMLImageElement.h"
 #include "nsISelectionController.h"
-#include "nsICSSStyleSheet.h"
 #include "nsIDocumentObserver.h"
 #include "TypeInState.h"
 
 #include "nsIEnumerator.h"
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
 #include "nsAttrName.h"
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -56,17 +56,17 @@
 #include "nsIPrivateDOMEvent.h"
 #include "nsIDOMBeforeUnloadEvent.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIEventStateManager.h"
 #include "nsStyleSet.h"
 #include "nsIStyleSheet.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIFrame.h"
 
 #include "nsILinkHandler.h"
 #include "nsIDOMDocument.h"
 #include "nsISelectionListener.h"
 #include "nsISelectionPrivate.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMNSHTMLDocument.h"
@@ -2112,17 +2112,17 @@ DocumentViewerImpl::CreateStyleSet(nsIDo
   
   // Handle the user sheets.
 #ifdef DEBUG
   nsCOMPtr<nsISupports> debugDocContainer = aDocument->GetContainer();
   nsCOMPtr<nsIDocShellTreeItem> debugDocShell(do_QueryReferent(mContainer));
   NS_ASSERTION(SameCOMIdentity(debugDocContainer, debugDocShell),
                "Unexpected containers");
 #endif
-  nsICSSStyleSheet* sheet = nsnull;
+  nsCSSStyleSheet* sheet = nsnull;
   if (nsContentUtils::IsInChromeDocshell(aDocument)) {
     sheet = nsLayoutStylesheetCache::UserChromeSheet();
   }
   else {
     sheet = nsLayoutStylesheetCache::UserContentSheet();
   }
 
   if (sheet)
@@ -2130,17 +2130,17 @@ DocumentViewerImpl::CreateStyleSet(nsIDo
 
   // Append chrome sheets (scrollbars + forms).
   PRBool shouldOverride = PR_FALSE;
   // We don't want a docshell here for external resource docs, so just
   // look at mContainer.
   nsCOMPtr<nsIDocShell> ds(do_QueryReferent(mContainer));
   nsCOMPtr<nsIDOMEventTarget> chromeHandler;
   nsCOMPtr<nsIURI> uri;
-  nsCOMPtr<nsICSSStyleSheet> csssheet;
+  nsRefPtr<nsCSSStyleSheet> csssheet;
 
   if (ds) {
     ds->GetChromeEventHandler(getter_AddRefs(chromeHandler));
   }
   if (chromeHandler) {
     nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
     nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
     if (elt && content) {
@@ -2179,18 +2179,18 @@ DocumentViewerImpl::CreateStyleSet(nsIDo
 
   sheet = nsLayoutStylesheetCache::FormsSheet();
   if (sheet) {
     styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
   }
 
   // Make sure to clone the quirk sheet so that it can be usefully
   // enabled/disabled as needed.
-  nsCOMPtr<nsICSSStyleSheet> quirkClone;
-  nsICSSStyleSheet* quirkSheet;
+  nsRefPtr<nsCSSStyleSheet> quirkClone;
+  nsCSSStyleSheet* quirkSheet;
   if (!nsLayoutStylesheetCache::UASheet() ||
       !(quirkSheet = nsLayoutStylesheetCache::QuirkSheet()) ||
       !(quirkClone = quirkSheet->Clone(nsnull, nsnull, nsnull, nsnull)) ||
       !sheet) {
     delete styleSet;
     return NS_ERROR_OUT_OF_MEMORY;
   }
   // quirk.css needs to come after the regular UA sheet (or more precisely,
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -58,17 +58,17 @@
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "mozilla/dom/Element.h"
 #include "nsIDocument.h"
 #include "nsIDOMXULDocument.h"
 #include "nsStubDocumentObserver.h"
 #include "nsStyleSet.h"
-#include "nsICSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
+#include "nsCSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
 #include "nsIDOMCSSStyleSheet.h"  // for Pref-related rule management (bugs 22963,20760,31816)
 #include "nsINameSpaceManager.h"  // for Pref-related rule management (bugs 22963,20760,31816)
 #include "nsIServiceManager.h"
 #include "nsFrame.h"
 #include "nsIViewManager.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
 #include "prlog.h"
@@ -1031,18 +1031,18 @@ protected:
       frameSelection->SetMouseDownState(PR_FALSE);
     }
     if (gCaptureInfo.mContent &&
         gCaptureInfo.mContent->GetOwnerDoc() == mDocument) {
       SetCapturingContent(nsnull, 0);
     }
   }
 
-  nsCOMPtr<nsICSSStyleSheet> mPrefStyleSheet; // mStyleSet owns it but we
-                                              // maintain a ref, may be null
+  nsRefPtr<nsCSSStyleSheet> mPrefStyleSheet; // mStyleSet owns it but we
+                                             // maintain a ref, may be null
 #ifdef DEBUG
   PRUint32                  mUpdateCount;
 #endif
   // reflow roots that need to be reflowed, as both a queue and a hashtable
   nsTArray<nsIFrame*> mDirtyRoots;
 
   PRPackedBool mDocumentLoading;
 
--- a/layout/base/nsStyleSheetService.cpp
+++ b/layout/base/nsStyleSheetService.cpp
@@ -37,17 +37,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 /* implementation of interface for managing user and user-agent style sheets */
 
 #include "prlog.h"
 #include "nsStyleSheetService.h"
 #include "nsIStyleSheet.h"
 #include "nsCSSLoader.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIURI.h"
 #include "nsContentCID.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsICategoryManager.h"
 #include "nsISupportsPrimitives.h"
 #include "nsNetUtil.h"
 #include "nsIObserverService.h"
@@ -167,17 +167,17 @@ nsStyleSheetService::LoadAndRegisterShee
                                                   PRUint32 aSheetType)
 {
   NS_ENSURE_ARG(aSheetType == AGENT_SHEET || aSheetType == USER_SHEET);
   NS_ENSURE_ARG_POINTER(aSheetURI);
 
   nsRefPtr<mozilla::css::Loader> loader = new mozilla::css::Loader();
   NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY);
 
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   // Allow UA sheets, but not user sheets, to use unsafe rules
   nsresult rv = loader->LoadSheetSync(aSheetURI, aSheetType == AGENT_SHEET,
                                       PR_TRUE, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!mSheets[aSheetType].AppendObject(sheet)) {
     rv = NS_ERROR_OUT_OF_MEMORY;
   }
--- a/layout/build/nsContentDLF.h
+++ b/layout/build/nsContentDLF.h
@@ -37,17 +37,16 @@
 
 #ifndef nsContentDLF_h__
 #define nsContentDLF_h__
 
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIDocumentViewer.h"
 #include "nsIDocument.h"
 
-class nsICSSStyleSheet;
 class nsIChannel;
 class nsIComponentManager;
 class nsIContentViewer;
 class nsIDocumentViewer;
 class nsIFile;
 class nsIInputStream;
 class nsILoadGroup;
 class nsIStreamListener;
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -48,17 +48,16 @@
 #include "nsCSSFrameConstructor.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSParser.h"
 #include "nsCSSProps.h"
 #include "nsCSSPseudoClasses.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRendering.h"
 #include "nsCSSScanner.h"
-#include "nsICSSStyleSheet.h"
 #include "nsDOMAttribute.h"
 #include "nsDOMClassInfo.h"
 #include "nsEventListenerManager.h"
 #include "nsFrame.h"
 #include "nsGenericElement.h"  // for nsDOMEventRTTearoff
 #include "nsGlobalWindow.h"
 #include "nsGkAtoms.h"
 #include "nsImageFrame.h"
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -40,17 +40,16 @@
 #include "nsMathMLFrame.h"
 #include "nsMathMLChar.h"
 #include "nsCSSPseudoElements.h"
 
 // used to map attributes into CSS rules
 #include "nsIDocument.h"
 #include "nsStyleSet.h"
 #include "nsIStyleSheet.h"
-#include "nsICSSStyleSheet.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsICSSRule.h"
 #include "nsICSSStyleRule.h"
 #include "nsStyleChangeList.h"
 #include "nsFrameManager.h"
 #include "nsNetUtil.h"
 #include "nsIURI.h"
 #include "nsContentCID.h"
--- a/layout/style/Makefile.in
+++ b/layout/style/Makefile.in
@@ -77,17 +77,16 @@ EXPORTS		= \
 		nsICSSImportRule.h \
 		nsICSSLoaderObserver.h \
 		nsICSSNameSpaceRule.h \
 		nsICSSPseudoComparator.h \
 		nsICSSRule.h \
 		nsICSSRuleList.h \
 		nsICSSStyleRule.h \
 		nsICSSStyleRuleDOMWrapper.h \
-		nsICSSStyleSheet.h \
 		nsIStyleRule.h \
 		nsIStyleRuleProcessor.h \
 		nsIStyleSheet.h \
 		nsLayoutStylesheetCache.h \
 		nsRuleData.h \
 		nsRuleNode.h \
 		nsRuleProcessorData.h \
 		nsRuleWalker.h \
--- a/layout/style/nsCSSLoader.cpp
+++ b/layout/style/nsCSSLoader.cpp
@@ -72,17 +72,17 @@
 #include "nsIScriptSecurityManager.h"
 #include "nsContentPolicyUtils.h"
 #include "nsITimelineService.h"
 #include "nsIHttpChannel.h"
 #include "nsIScriptError.h"
 #include "nsMimeTypes.h"
 #include "nsIAtom.h"
 #include "nsIDOM3Node.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsCSSParser.h"
 #include "nsICSSImportRule.h"
 #include "nsThreadUtils.h"
 #include "nsGkAtoms.h"
 #include "nsDocShellCID.h"
 #include "nsIChannelClassifier.h"
@@ -139,34 +139,34 @@ class SheetLoadData : public nsIRunnable
                       public nsIUnicharStreamLoaderObserver
 {
 public:
   virtual ~SheetLoadData(void);
   // Data for loading a sheet linked from a document
   SheetLoadData(Loader* aLoader,
                 const nsSubstring& aTitle,
                 nsIURI* aURI,
-                nsICSSStyleSheet* aSheet,
+                nsCSSStyleSheet* aSheet,
                 nsIStyleSheetLinkingElement* aOwningElement,
                 PRBool aIsAlternate,
                 nsICSSLoaderObserver* aObserver,
                 nsIPrincipal* aLoaderPrincipal);
 
   // Data for loading a sheet linked from an @import rule
   SheetLoadData(Loader* aLoader,
                 nsIURI* aURI,
-                nsICSSStyleSheet* aSheet,
+                nsCSSStyleSheet* aSheet,
                 SheetLoadData* aParentData,
                 nsICSSLoaderObserver* aObserver,
                 nsIPrincipal* aLoaderPrincipal);
 
   // Data for loading a non-document sheet
   SheetLoadData(Loader* aLoader,
                 nsIURI* aURI,
-                nsICSSStyleSheet* aSheet,
+                nsCSSStyleSheet* aSheet,
                 PRBool aSyncLoad,
                 PRBool aAllowUnsafeRules,
                 PRBool aUseSystemPrincipal,
                 const nsCString& aCharset,
                 nsICSSLoaderObserver* aObserver,
                 nsIPrincipal* aLoaderPrincipal);
 
   already_AddRefed<nsIURI> GetReferrerURI();
@@ -188,17 +188,17 @@ public:
 
   // URI we're loading.  Null for inline sheets
   nsCOMPtr<nsIURI>           mURI;
 
   // Should be 1 for non-inline sheets.
   PRUint32                   mLineNumber;
 
   // The sheet we're loading data for
-  nsCOMPtr<nsICSSStyleSheet> mSheet;
+  nsRefPtr<nsCSSStyleSheet>  mSheet;
 
   // Linked list of datas for the same URI as us
   SheetLoadData*             mNext;  // strong ref
 
   // Load data for the sheet that @import-ed us if we were @import-ed
   // during the parse
   SheetLoadData*             mParentData;  // strong ref
 
@@ -308,17 +308,17 @@ static const char* const gStateStrings[]
 /********************************
  * SheetLoadData implementation *
  ********************************/
 NS_IMPL_ISUPPORTS2(SheetLoadData, nsIUnicharStreamLoaderObserver, nsIRunnable)
 
 SheetLoadData::SheetLoadData(Loader* aLoader,
                              const nsSubstring& aTitle,
                              nsIURI* aURI,
-                             nsICSSStyleSheet* aSheet,
+                             nsCSSStyleSheet* aSheet,
                              nsIStyleSheetLinkingElement* aOwningElement,
                              PRBool aIsAlternate,
                              nsICSSLoaderObserver* aObserver,
                              nsIPrincipal* aLoaderPrincipal)
   : mLoader(aLoader),
     mTitle(aTitle),
     mURI(aURI),
     mLineNumber(1),
@@ -339,17 +339,17 @@ SheetLoadData::SheetLoadData(Loader* aLo
     mLoaderPrincipal(aLoaderPrincipal)
 {
   NS_PRECONDITION(mLoader, "Must have a loader!");
   NS_ADDREF(mLoader);
 }
 
 SheetLoadData::SheetLoadData(Loader* aLoader,
                              nsIURI* aURI,
-                             nsICSSStyleSheet* aSheet,
+                             nsCSSStyleSheet* aSheet,
                              SheetLoadData* aParentData,
                              nsICSSLoaderObserver* aObserver,
                              nsIPrincipal* aLoaderPrincipal)
   : mLoader(aLoader),
     mURI(aURI),
     mLineNumber(1),
     mSheet(aSheet),
     mNext(nsnull),
@@ -379,17 +379,17 @@ SheetLoadData::SheetLoadData(Loader* aLo
   }
 
   NS_POSTCONDITION(!mUseSystemPrincipal || mSyncLoad,
                    "Shouldn't use system principal for async loads");
 }
 
 SheetLoadData::SheetLoadData(Loader* aLoader,
                              nsIURI* aURI,
-                             nsICSSStyleSheet* aSheet,
+                             nsCSSStyleSheet* aSheet,
                              PRBool aSyncLoad,
                              PRBool aAllowUnsafeRules,
                              PRBool aUseSystemPrincipal,
                              const nsCString& aCharset,
                              nsICSSLoaderObserver* aObserver,
                              nsIPrincipal* aLoaderPrincipal)
   : mLoader(aLoader),
     mURI(aURI),
@@ -1045,47 +1045,47 @@ Loader::CheckLoadAllowed(nsIPrincipal* a
       return NS_ERROR_CONTENT_BLOCKED;
     }
   }
 
   return NS_OK;
 }
 
 /**
- * CreateSheet() creates an nsICSSStyleSheet object for the given URI,
+ * CreateSheet() creates an nsCSSStyleSheet object for the given URI,
  * if any.  If there is no URI given, we just create a new style sheet
  * object.  Otherwise, we check for an existing style sheet object for
  * that uri in various caches and clone it if we find it.  Cloned
  * sheets will have the title/media/enabled state of the sheet they
  * are clones off; make sure to call PrepareSheet() on the result of
  * CreateSheet().
  */
 nsresult
 Loader::CreateSheet(nsIURI* aURI,
                     nsIContent* aLinkingContent,
                     nsIPrincipal* aLoaderPrincipal,
                     PRBool aSyncLoad,
                     StyleSheetState& aSheetState,
-                    nsICSSStyleSheet** aSheet)
+                    nsCSSStyleSheet** aSheet)
 {
   LOG(("css::Loader::CreateSheet"));
   NS_PRECONDITION(aSheet, "Null out param!");
 
   NS_ENSURE_TRUE((mCompleteSheets.IsInitialized() || mCompleteSheets.Init()) &&
                    (mLoadingDatas.IsInitialized() || mLoadingDatas.Init()) &&
                    (mPendingDatas.IsInitialized() || mPendingDatas.Init()),
                  NS_ERROR_OUT_OF_MEMORY);
   
   nsresult rv = NS_OK;
   *aSheet = nsnull;
   aSheetState = eSheetStateUnknown;
   
   if (aURI) {
     aSheetState = eSheetComplete;
-    nsCOMPtr<nsICSSStyleSheet> sheet;
+    nsRefPtr<nsCSSStyleSheet> sheet;
 
     // First, the XUL cache
 #ifdef MOZ_XUL
     if (IsChromeURI(aURI)) {
       nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
       if (cache) {
         if (cache->IsEnabled()) {
           sheet = cache->GetStyleSheet(aURI);
@@ -1208,17 +1208,17 @@ Loader::CreateSheet(nsIURI* aURI,
 }
 
 /**
  * PrepareSheet() handles setting the media and title on the sheet, as
  * well as setting the enabled state based on the title and whether
  * the sheet had "alternate" in its rel.
  */
 nsresult
-Loader::PrepareSheet(nsICSSStyleSheet* aSheet,
+Loader::PrepareSheet(nsCSSStyleSheet* aSheet,
                      const nsSubstring& aTitle,
                      const nsSubstring& aMediaString,
                      nsMediaList* aMediaList,
                      PRBool aHasAlternateRel,
                      PRBool *aIsAlternate)
 {
   NS_PRECONDITION(aSheet, "Must have a sheet!");
 
@@ -1261,17 +1261,17 @@ Loader::PrepareSheet(nsICSSStyleSheet* a
  *    linking elements
  * 2) Sheets without linking elements are inserted in the order in
  *    which the inserting requests come in, since all of these are
  *    inserted during header data processing in the content sink
  * 3) Sheets with linking elements are ordered based on document order
  *    as determined by CompareDocumentPosition.
  */
 nsresult
-Loader::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
+Loader::InsertSheetInDoc(nsCSSStyleSheet* aSheet,
                          nsIContent* aLinkingContent,
                          nsIDocument* aDocument)
 {
   LOG(("css::Loader::InsertSheetInDoc"));
   NS_PRECONDITION(aSheet, "Nothing to insert");
   NS_PRECONDITION(aDocument, "Must have a document to insert into");
 
   // XXX Need to cancel pending sheet loads for this element, if any
@@ -1341,18 +1341,18 @@ Loader::InsertSheetInDoc(nsICSSStyleShee
  * parent sheets.  Here we want to just insert based on order of the
  * @import rules that imported the sheets.  In theory we can't just
  * append to the end because the CSSOM can insert @import rules.  In
  * practice, we get the call to load the child sheet before the CSSOM
  * has finished inserting the @import rule, so we have no idea where
  * to put it anyway.  So just append for now.
  */
 nsresult
-Loader::InsertChildSheet(nsICSSStyleSheet* aSheet,
-                         nsICSSStyleSheet* aParentSheet,
+Loader::InsertChildSheet(nsCSSStyleSheet* aSheet,
+                         nsCSSStyleSheet* aParentSheet,
                          nsICSSImportRule* aParentRule)
 {
   LOG(("css::Loader::InsertChildSheet"));
   NS_PRECONDITION(aSheet, "Nothing to insert");
   NS_PRECONDITION(aParentSheet, "Need a parent to insert into");
   NS_PRECONDITION(aParentSheet, "How did we get imported?");
 
   // child sheets should always start out enabled, even if they got
@@ -1839,17 +1839,17 @@ Loader::LoadInlineStyle(nsIContent* aEle
 
   nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement));
   NS_ASSERTION(owningElement, "Element is not a style linking element!");
   
 
   // Since we're not planning to load a URI, no need to hand a principal to the
   // load data or to CreateSheet().
   StyleSheetState state;
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = CreateSheet(nsnull, aElement, nsnull, PR_FALSE, state,
                             getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ASSERTION(state == eSheetNeedsParser,
                "Inline sheets should not be cached");
 
   rv = PrepareSheet(sheet, aTitle, aMedia, nsnull, PR_FALSE,
                     aIsAlternate);
@@ -1918,17 +1918,17 @@ Loader::LoadStyleLink(nsIContent* aEleme
     context = mDocument;
   }
   nsresult rv = CheckLoadAllowed(principal, aURL, context);
   if (NS_FAILED(rv)) return rv;
 
   LOG(("  Passed load check"));
   
   StyleSheetState state;
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   rv = CreateSheet(aURL, aElement, principal, PR_FALSE, state,
                    getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = PrepareSheet(sheet, aTitle, aMedia, nsnull, aHasAlternateRel,
                     aIsAlternate);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -1978,17 +1978,17 @@ Loader::LoadStyleLink(nsIContent* aEleme
   rv = LoadSheet(data, state);
   NS_ENSURE_SUCCESS(rv, rv);
 
   data->mMustNotify = PR_TRUE;
   return rv;
 }
 
 nsresult
-Loader::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
+Loader::LoadChildSheet(nsCSSStyleSheet* aParentSheet,
                        nsIURI* aURL, 
                        nsMediaList* aMedia,
                        nsICSSImportRule* aParentRule)
 {
   LOG(("css::Loader::LoadChildSheet"));
   NS_PRECONDITION(aURL, "Must have a URI to load");
   NS_PRECONDITION(aParentSheet, "Must have a parent sheet");
 
@@ -2001,17 +2001,17 @@ Loader::LoadChildSheet(nsICSSStyleSheet*
 
   nsCOMPtr<nsIDOMNode> owningNode;
 
   // check for an owning document: if none, don't bother walking up the parent
   // sheets
   nsCOMPtr<nsIDocument> owningDoc;
   nsresult rv = aParentSheet->GetOwningDocument(*getter_AddRefs(owningDoc));
   if (NS_SUCCEEDED(rv) && owningDoc) {
-    nsCOMPtr<nsIDOMStyleSheet> nextParentSheet(do_QueryInterface(aParentSheet));
+    nsCOMPtr<nsIDOMStyleSheet> nextParentSheet(aParentSheet);
     NS_ENSURE_TRUE(nextParentSheet, NS_ERROR_FAILURE); //Not a stylesheet!?
 
     nsCOMPtr<nsIDOMStyleSheet> topSheet;
     //traverse our way to the top-most sheet
     do {
       topSheet.swap(nextParentSheet);
       topSheet->GetParentStyleSheet(getter_AddRefs(nextParentSheet));
     } while (nextParentSheet);
@@ -2051,22 +2051,22 @@ Loader::LoadChildSheet(nsICSSStyleSheet*
     }
 
     NS_ASSERTION(parentData->mSheet == aParentSheet,
                  "Unexpected call to LoadChildSheet");
   } else {
     LOG(("  No parent load; must be CSSOM"));
     // No parent load data, so the sheet will need to be notified when
     // we finish, if it can be, if we do the load asynchronously.
-    observer = do_QueryInterface(aParentSheet);
+    observer = aParentSheet;
   }
 
   // Now that we know it's safe to load this (passes security check and not a
   // loop) do so
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   StyleSheetState state;
   rv = CreateSheet(aURL, nsnull, principal,
                    parentData ? parentData->mSyncLoad : PR_FALSE,
                    state, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
 
   const nsSubstring& empty = EmptyString();
   rv = PrepareSheet(sheet, empty, empty, aMedia);
@@ -2104,30 +2104,30 @@ Loader::LoadChildSheet(nsICSSStyleSheet*
     data->mMustNotify = PR_TRUE;
   }
   return rv;  
 }
 
 nsresult
 Loader::LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules,
                       PRBool aUseSystemPrincipal,
-                      nsICSSStyleSheet** aSheet)
+                      nsCSSStyleSheet** aSheet)
 {
   LOG(("css::Loader::LoadSheetSync"));
   return InternalLoadNonDocumentSheet(aURL, aAllowUnsafeRules,
                                       aUseSystemPrincipal, nsnull,
                                       EmptyCString(), aSheet, nsnull);
 }
 
 nsresult
 Loader::LoadSheet(nsIURI* aURL,
                   nsIPrincipal* aOriginPrincipal,
                   const nsCString& aCharset,
                   nsICSSLoaderObserver* aObserver,
-                  nsICSSStyleSheet** aSheet)
+                  nsCSSStyleSheet** aSheet)
 {
   LOG(("css::Loader::LoadSheet(aURL, aObserver, aSheet) api call"));
   NS_PRECONDITION(aSheet, "aSheet is null");
   return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE,
                                       aOriginPrincipal, aCharset,
                                       aSheet, aObserver);
 }
 
@@ -2144,17 +2144,17 @@ Loader::LoadSheet(nsIURI* aURL,
 }
 
 nsresult
 Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, 
                                      PRBool aAllowUnsafeRules,
                                      PRBool aUseSystemPrincipal,
                                      nsIPrincipal* aOriginPrincipal,
                                      const nsCString& aCharset,
-                                     nsICSSStyleSheet** aSheet,
+                                     nsCSSStyleSheet** aSheet,
                                      nsICSSLoaderObserver* aObserver)
 {
   NS_PRECONDITION(aURL, "Must have a URI to load");
   NS_PRECONDITION(aSheet || aObserver, "Sheet and observer can't both be null");
   NS_PRECONDITION(!aUseSystemPrincipal || !aObserver,
                   "Shouldn't load system-principal sheets async");
   NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
 
@@ -2170,17 +2170,17 @@ Loader::InternalLoadNonDocumentSheet(nsI
   }
 
   nsresult rv = CheckLoadAllowed(aOriginPrincipal, aURL, mDocument);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   StyleSheetState state;
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   PRBool syncLoad = (aObserver == nsnull);
   
   rv = CreateSheet(aURL, nsnull, aOriginPrincipal, syncLoad, state,
                    getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
 
   const nsSubstring& empty = EmptyString();
   rv = PrepareSheet(sheet, empty, empty, nsnull);
@@ -2218,17 +2218,17 @@ Loader::InternalLoadNonDocumentSheet(nsI
     data->mMustNotify = PR_TRUE;
   }
 
   return rv;
 }
 
 nsresult
 Loader::PostLoadEvent(nsIURI* aURI,
-                      nsICSSStyleSheet* aSheet,
+                      nsCSSStyleSheet* aSheet,
                       nsICSSLoaderObserver* aObserver,
                       PRBool aWasAlternate)
 {
   LOG(("css::Loader::PostLoadEvent"));
   NS_PRECONDITION(aSheet, "Must have sheet");
   NS_PRECONDITION(aObserver, "Must have observer");
 
   nsRefPtr<SheetLoadData> evt =
--- a/layout/style/nsCSSLoader.h
+++ b/layout/style/nsCSSLoader.h
@@ -41,24 +41,25 @@
 #define nsICSSLoader_h___
 
 #include "nsIPrincipal.h"
 #include "nsAString.h"
 #include "nsAutoPtr.h"
 #include "nsCompatibility.h"
 #include "nsDataHashtable.h"
 #include "nsInterfaceHashtable.h"
+#include "nsRefPtrHashtable.h"
 #include "nsTArray.h"
 #include "nsTObserverArray.h"
 #include "nsURIHashKey.h"
 
 class nsIAtom;
 class nsICSSImportRule;
 class nsICSSLoaderObserver;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 class nsIContent;
 class nsIDocument;
 class nsIUnicharInputStream;
 class nsCSSParser;
 class nsMediaList;
 
 namespace mozilla {
 
@@ -223,17 +224,17 @@ public:
    * nsICSSLoaderObserver notification will be sent.
    *
    * @param aParentSheet the parent of this child sheet
    * @param aURL the URL of the child sheet
    * @param aMedia the already-parsed media list for the child sheet
    * @param aRule the @import rule importing this child.  This is used to
    *              properly order the child sheet list of aParentSheet.
    */
-  nsresult LoadChildSheet(nsICSSStyleSheet* aParentSheet,
+  nsresult LoadChildSheet(nsCSSStyleSheet* aParentSheet,
                           nsIURI* aURL,
                           nsMediaList* aMedia,
                           nsICSSImportRule* aRule);
 
   /**
    * Synchronously load and return the stylesheet at aURL.  Any child sheets
    * will also be loaded synchronously.  Note that synchronous loads over some
    * protocols may involve spinning up a new event loop, so use of this method
@@ -257,22 +258,22 @@ public:
    * non-UTF8 sheets being treated as UTF-8 by this method.
    *
    * NOTE: A successful return from this method doesn't indicate anything about
    * whether the data could be parsed as CSS and doesn't indicate anything
    * about the status of child sheets of the returned sheet.
    */
   nsresult LoadSheetSync(nsIURI* aURL, PRBool aEnableUnsafeRules,
                          PRBool aUseSystemPrincipal,
-                         nsICSSStyleSheet** aSheet);
+                         nsCSSStyleSheet** aSheet);
 
   /**
    * As above, but aUseSystemPrincipal and aEnableUnsafeRules are assumed false.
    */
-  nsresult LoadSheetSync(nsIURI* aURL, nsICSSStyleSheet** aSheet) {
+  nsresult LoadSheetSync(nsIURI* aURL, nsCSSStyleSheet** aSheet) {
     return LoadSheetSync(aURL, PR_FALSE, PR_FALSE, aSheet);
   }
 
   /**
    * Asynchronously load the stylesheet at aURL.  If a successful result is
    * returned, aObserver is guaranteed to be notified asynchronously once the
    * sheet is loaded and marked complete.  This method can be used to load
    * sheets not associated with a document.
@@ -290,17 +291,17 @@ public:
    *                  Must not be null.
    * @param [out] aSheet the sheet to load. Note that the sheet may well
    *              not be loaded by the time this method returns.
    */
   nsresult LoadSheet(nsIURI* aURL,
                      nsIPrincipal* aOriginPrincipal,
                      const nsCString& aCharset,
                      nsICSSLoaderObserver* aObserver,
-                     nsICSSStyleSheet** aSheet);
+                     nsCSSStyleSheet** aSheet);
 
   /**
    * Same as above, to be used when the caller doesn't care about the
    * not-yet-loaded sheet.
    */
   nsresult LoadSheet(nsIURI* aURL,
                      nsIPrincipal* aOriginPrincipal,
                      const nsCString& aCharset,
@@ -378,53 +379,53 @@ private:
   // For inline style, the aURI param is null, but the aLinkingContent
   // must be non-null then.  The loader principal must never be null
   // if aURI is not null.
   nsresult CreateSheet(nsIURI* aURI,
                        nsIContent* aLinkingContent,
                        nsIPrincipal* aLoaderPrincipal,
                        PRBool aSyncLoad,
                        StyleSheetState& aSheetState,
-                       nsICSSStyleSheet** aSheet);
+                       nsCSSStyleSheet** aSheet);
 
   // Pass in either a media string or the nsMediaList from the
   // CSSParser.  Don't pass both.
   // If aIsAlternate is non-null, this method will set *aIsAlternate to
   // correspond to the sheet's enabled state (which it will set no matter what)
-  nsresult PrepareSheet(nsICSSStyleSheet* aSheet,
+  nsresult PrepareSheet(nsCSSStyleSheet* aSheet,
                         const nsAString& aTitle,
                         const nsAString& aMediaString,
                         nsMediaList* aMediaList,
                         PRBool aHasAlternateRel = PR_FALSE,
                         PRBool *aIsAlternate = nsnull);
 
-  nsresult InsertSheetInDoc(nsICSSStyleSheet* aSheet,
+  nsresult InsertSheetInDoc(nsCSSStyleSheet* aSheet,
                             nsIContent* aLinkingContent,
                             nsIDocument* aDocument);
 
-  nsresult InsertChildSheet(nsICSSStyleSheet* aSheet,
-                            nsICSSStyleSheet* aParentSheet,
+  nsresult InsertChildSheet(nsCSSStyleSheet* aSheet,
+                            nsCSSStyleSheet* aParentSheet,
                             nsICSSImportRule* aParentRule);
 
   nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
                                         PRBool aAllowUnsafeRules,
                                         PRBool aUseSystemPrincipal,
                                         nsIPrincipal* aOriginPrincipal,
                                         const nsCString& aCharset,
-                                        nsICSSStyleSheet** aSheet,
+                                        nsCSSStyleSheet** aSheet,
                                         nsICSSLoaderObserver* aObserver);
 
   // Post a load event for aObserver to be notified about aSheet.  The
   // notification will be sent with status NS_OK unless the load event is
   // canceled at some point (in which case it will be sent with
   // NS_BINDING_ABORTED).  aWasAlternate indicates the state when the load was
   // initiated, not the state at some later time.  aURI should be the URI the
   // sheet was loaded from (may be null for inline sheets).
   nsresult PostLoadEvent(nsIURI* aURI,
-                         nsICSSStyleSheet* aSheet,
+                         nsCSSStyleSheet* aSheet,
                          nsICSSLoaderObserver* aObserver,
                          PRBool aWasAlternate);
 
   // Start the loads of all the sheets in mPendingDatas
   void StartAlternateLoads();
 
   // Handle an event posted by PostLoadEvent
   void HandleLoadEvent(SheetLoadData* aEvent);
@@ -446,17 +447,17 @@ private:
   void SheetComplete(SheetLoadData* aLoadData, nsresult aStatus);
 
   // The guts of SheetComplete.  This may be called recursively on parent datas
   // or datas that had glommed on to a single load.  The array is there so load
   // datas whose observers need to be notified can be added to it.
   void DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
                        LoadDataArray& aDatasToNotify);
 
-  nsInterfaceHashtable<URIAndPrincipalHashKey, nsICSSStyleSheet>
+  nsRefPtrHashtable<URIAndPrincipalHashKey, nsCSSStyleSheet>
                     mCompleteSheets;
   nsDataHashtable<URIAndPrincipalHashKey, SheetLoadData*>
                     mLoadingDatas; // weak refs
   nsDataHashtable<URIAndPrincipalHashKey, SheetLoadData*>
                     mPendingDatas; // weak refs
 
   // We're not likely to have many levels of @import...  But likely to have
   // some.  Allocate some storage, what the hell.
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -51,17 +51,17 @@
 #include "nsCSSKeywords.h"
 #include "nsCSSScanner.h"
 #include "nsCSSLoader.h"
 #include "nsICSSStyleRule.h"
 #include "nsICSSImportRule.h"
 #include "nsCSSRules.h"
 #include "nsICSSNameSpaceRule.h"
 #include "nsIUnicharInputStream.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsCSSDeclaration.h"
 #include "nsStyleConsts.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
@@ -165,17 +165,17 @@ static void AppendRuleToSheet(nsICSSRule
 // Your basic top-down recursive descent style parser
 // The exposed methods and members of this class are precisely those
 // needed by nsCSSParser, far below.
 class CSSParserImpl {
 public:
   CSSParserImpl();
   ~CSSParserImpl();
 
-  nsresult SetStyleSheet(nsICSSStyleSheet* aSheet);
+  nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
 
   nsresult SetQuirkMode(PRBool aQuirkMode);
 
 #ifdef  MOZ_SVG
   nsresult SetSVGMode(PRBool aSVGMode);
 #endif
 
   nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
@@ -623,17 +623,17 @@ protected:
 
   // The URI to be used as an HTTP "Referer" and for error reporting.
   nsCOMPtr<nsIURI> mSheetURI;
 
   // The principal of the sheet involved
   nsCOMPtr<nsIPrincipal> mSheetPrincipal;
 
   // The sheet we're parsing into
-  nsCOMPtr<nsICSSStyleSheet> mSheet;
+  nsRefPtr<nsCSSStyleSheet> mSheet;
 
   // Used for @import rules
   mozilla::css::Loader* mChildLoader; // not ref counted, it owns us
 
   // Sheet section we're in.  This is used to enforce correct ordering of the
   // various rule types (eg the fact that a @charset rule must come before
   // anything else).  Note that there are checks of similar things in various
   // places in nsCSSStyleSheet.cpp (e.g in insertRule, RebuildChildList).
@@ -764,17 +764,17 @@ CSSParserImpl::CSSParserImpl()
 
 CSSParserImpl::~CSSParserImpl()
 {
   mData.AssertInitialState();
   mTempData.AssertInitialState();
 }
 
 nsresult
-CSSParserImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
+CSSParserImpl::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   if (aSheet != mSheet) {
     // Switch to using the new sheet, if any
     mGroupStack.Clear();
     mSheet = aSheet;
     if (mSheet) {
       mNameSpaceMap = mSheet->GetNameSpaceMap();
     } else {
@@ -9547,17 +9547,17 @@ CSSParserImpl::ParseMarker()
 
 } // anonymous namespace
 
 // Recycling of parser implementation objects
 
 static CSSParserImpl* gFreeList = nsnull;
 
 nsCSSParser::nsCSSParser(mozilla::css::Loader* aLoader,
-                         nsICSSStyleSheet* aSheet)
+                         nsCSSStyleSheet* aSheet)
 {
   CSSParserImpl *impl = gFreeList;
   if (impl) {
     gFreeList = impl->mNextFree;
     impl->mNextFree = nsnull;
   } else {
     impl = new CSSParserImpl();
   }
@@ -9593,17 +9593,17 @@ nsCSSParser::Shutdown()
       delete tofree;
       tofree = next;
     }
 }
 
 // Wrapper methods
 
 nsresult
-nsCSSParser::SetStyleSheet(nsICSSStyleSheet* aSheet)
+nsCSSParser::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   return static_cast<CSSParserImpl*>(mImpl)->
     SetStyleSheet(aSheet);
 }
 
 nsresult
 nsCSSParser::SetQuirkMode(PRBool aQuirkMode)
 {
--- a/layout/style/nsCSSParser.h
+++ b/layout/style/nsCSSParser.h
@@ -42,17 +42,17 @@
 
 #include "nsAString.h"
 #include "nsCSSProperty.h"
 #include "nsColor.h"
 #include "nsCOMArray.h"
 
 class nsICSSRule;
 class nsICSSStyleRule;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 class nsIPrincipal;
 class nsIURI;
 class nsIUnicharInputStream;
 class nsCSSDeclaration;
 struct nsCSSSelectorList;
 class nsMediaList;
 
 namespace mozilla {
@@ -61,36 +61,36 @@ namespace css {
 }
 }
 
 // Interface to the css parser.
 
 class NS_STACK_CLASS nsCSSParser {
 public:
   nsCSSParser(mozilla::css::Loader* aLoader = nsnull,
-              nsICSSStyleSheet* aSheet = nsnull);
+              nsCSSStyleSheet* aSheet = nsnull);
   ~nsCSSParser();
 
   static void Shutdown();
 
 private:
   // not to be implemented
   nsCSSParser(nsCSSParser const&);
   nsCSSParser& operator=(nsCSSParser const&);
 
 public:
   // If this is false, memory allocation failed in the constructor
   // and all other methods will crash.
   operator bool() const
   { return !!mImpl; }
 
   // Set a style sheet for the parser to fill in. The style sheet must
-  // implement the nsICSSStyleSheet interface.  Null can be passed in to clear
+  // implement the nsCSSStyleSheet interface.  Null can be passed in to clear
   // out an existing stylesheet reference.
-  nsresult SetStyleSheet(nsICSSStyleSheet* aSheet);
+  nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
 
   // Set whether or not to emulate Nav quirks
   nsresult SetQuirkMode(PRBool aQuirkMode);
 
 #ifdef  MOZ_SVG
   // Set whether or not we are in an SVG element
   nsresult SetSVGMode(PRBool aSVGMode);
 #endif
--- a/layout/style/nsCSSRule.cpp
+++ b/layout/style/nsCSSRule.cpp
@@ -34,17 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* base class for all rule types in a CSS style sheet */
 
 #include "nsCSSRule.h"
 #include "nsCRT.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 
 nsCSSRule::nsCSSRule(void)
   : mRefCnt(0),
     mSheet(nsnull),
     mParentRule(nsnull)
 {
 }
 
@@ -67,17 +67,17 @@ NS_IMETHODIMP
 nsCSSRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
 {
   NS_IF_ADDREF(mSheet);
   aSheet = mSheet;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsCSSRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
+nsCSSRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   // We don't reference count this up reference. The style sheet
   // will tell us when it's going away or when we're detached from
   // it.
   mSheet = aSheet;
   return NS_OK;
 }
 
--- a/layout/style/nsCSSRule.h
+++ b/layout/style/nsCSSRule.h
@@ -38,17 +38,17 @@
 /* base class for all rule types in a CSS style sheet */
 
 #ifndef nsCSSRule_h___
 #define nsCSSRule_h___
 
 #include "nsISupports.h"
 
 class nsIStyleSheet;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 struct nsRuleData;
 class nsICSSGroupRule;
 
 class nsCSSRule {
 public:
   nsCSSRule(void);
   nsCSSRule(const nsCSSRule& aCopy);
   virtual ~nsCSSRule(void);
@@ -57,25 +57,25 @@ public:
   NS_IMETHOD_(nsrefcnt) AddRef();
   NS_IMETHOD_(nsrefcnt) Release();
 protected:
   nsAutoRefCnt mRefCnt;
   NS_DECL_OWNINGTHREAD
 public:
 
   NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
-  NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
+  NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aSheet);
 
   NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
 
   // nsIStyleRule methods
   // The new mapping function.
   NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
 
 protected:
-  nsICSSStyleSheet*   mSheet;                         
+  nsCSSStyleSheet*    mSheet;
   nsICSSGroupRule*    mParentRule;
 #ifdef DEBUG_REFS
   PRInt32 mInstance;
 #endif
 };
 
 #endif /* nsCSSRule_h___ */
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -470,17 +470,17 @@ RuleHash::~RuleHash()
     RuleValue* value = mUniversalRules;
     if (value) {
       printf("  Universal rules:\n");
       do {
         nsAutoString selectorText;
         PRUint32 lineNumber = value->mRule->GetLineNumber();
         nsCOMPtr<nsIStyleSheet> sheet;
         value->mRule->GetStyleSheet(*getter_AddRefs(sheet));
-        nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(sheet);
+        nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheet);
         value->mSelector->ToString(selectorText, cssSheet);
 
         printf("    line %d, %s\n",
                lineNumber, NS_ConvertUTF16toUTF8(selectorText).get());
         value = value->mNext;
       } while (value);
     }
   }
@@ -834,31 +834,33 @@ nsPrivateBrowsingObserver::Observe(nsISu
 }
 
 static nsPrivateBrowsingObserver *gPrivateBrowsingObserver = nsnull;
 
 // -------------------------------
 // CSS Style rule processor implementation
 //
 
-nsCSSRuleProcessor::nsCSSRuleProcessor(const nsCOMArray<nsICSSStyleSheet>& aSheets,
+nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
                                        PRUint8 aSheetType)
   : mSheets(aSheets)
   , mRuleCascades(nsnull)
   , mLastPresContext(nsnull)
   , mSheetType(aSheetType)
 {
-  for (PRInt32 i = mSheets.Count() - 1; i >= 0; --i)
+  for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
     mSheets[i]->AddRuleProcessor(this);
+  }
 }
 
 nsCSSRuleProcessor::~nsCSSRuleProcessor()
 {
-  for (PRInt32 i = mSheets.Count() - 1; i >= 0; --i)
+  for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
     mSheets[i]->DropRuleProcessor(this);
+  }
   mSheets.Clear();
   ClearRuleCascades();
 }
 
 NS_IMPL_ISUPPORTS1(nsCSSRuleProcessor, nsIStyleRuleProcessor)
 
 /* static */ nsresult
 nsCSSRuleProcessor::Startup()
@@ -2814,34 +2816,32 @@ CascadeRuleEnumFunc(nsICSSRule* aRule, v
     ptr->mRule = fontFaceRule;
     ptr->mSheetType = data->mSheetType;
   }
 
   return PR_TRUE;
 }
 
 /* static */ PRBool
-nsCSSRuleProcessor::CascadeSheetEnumFunc(nsICSSStyleSheet* aSheet, void* aData)
+nsCSSRuleProcessor::CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData)
 {
-  nsCSSStyleSheet*  sheet = static_cast<nsCSSStyleSheet*>(aSheet);
-  CascadeEnumData* data = static_cast<CascadeEnumData*>(aData);
   PRBool bSheetApplicable = PR_TRUE;
-  sheet->GetApplicable(bSheetApplicable);
+  aSheet->GetApplicable(bSheetApplicable);
 
   if (bSheetApplicable &&
-      sheet->UseForPresentation(data->mPresContext, data->mCacheKey) &&
-      sheet->mInner) {
-    nsCSSStyleSheet* child = sheet->mInner->mFirstChild;
+      aSheet->UseForPresentation(aData->mPresContext, aData->mCacheKey) &&
+      aSheet->mInner) {
+    nsCSSStyleSheet* child = aSheet->mInner->mFirstChild;
     while (child) {
-      CascadeSheetEnumFunc(child, data);
+      CascadeSheet(child, aData);
       child = child->mNext;
     }
 
-    if (!sheet->mInner->mOrderedRules.EnumerateForwards(CascadeRuleEnumFunc,
-                                                        data))
+    if (!aSheet->mInner->mOrderedRules.EnumerateForwards(CascadeRuleEnumFunc,
+                                                         aData))
       return PR_FALSE;
   }
   return PR_TRUE;
 }
 
 static int CompareWeightData(const void* aArg1, const void* aArg2,
                              void* closure)
 {
@@ -2908,29 +2908,32 @@ nsCSSRuleProcessor::RefreshRuleCascade(n
       *cascadep = cascade->mNext;
       cascade->mNext = mRuleCascades;
       mRuleCascades = cascade;
 
       return;
     }
   }
 
-  if (mSheets.Count() != 0) {
+  if (mSheets.Length() != 0) {
     nsAutoPtr<RuleCascadeData> newCascade(
       new RuleCascadeData(aPresContext->Medium(),
                           eCompatibility_NavQuirks == aPresContext->CompatibilityMode()));
     if (newCascade) {
       CascadeEnumData data(aPresContext, newCascade->mFontFaceRules,
                            newCascade->mCacheKey,
                            newCascade->mRuleHash.Arena(),
                            mSheetType);
       if (!data.mRulesByWeight.ops)
         return; /* out of memory */
-      if (!mSheets.EnumerateForwards(CascadeSheetEnumFunc, &data))
-        return; /* out of memory */
+
+      for (PRUint32 i = 0; i < mSheets.Length(); ++i) {
+        if (!CascadeSheet(mSheets.ElementAt(i), &data))
+          return; /* out of memory */
+      }
 
       // Sort the hash table of per-weight linked lists by weight.
       PRUint32 weightCount = data.mRulesByWeight.entryCount;
       nsAutoArrayPtr<PerWeightData> weightArray(new PerWeightData[weightCount]);
       FillWeightArrayData fwData(weightArray);
       PL_DHashTableEnumerate(&data.mRulesByWeight, FillWeightArray, &fwData);
       NS_QuickSort(weightArray, weightCount, sizeof(PerWeightData),
                    CompareWeightData, nsnull);
--- a/layout/style/nsCSSRuleProcessor.h
+++ b/layout/style/nsCSSRuleProcessor.h
@@ -48,32 +48,34 @@
 #include "nsIStyleRuleProcessor.h"
 #include "nsCSSStyleSheet.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 #include "nsCSSRules.h"
 
 struct RuleCascadeData;
 struct nsCSSSelectorList;
+struct CascadeEnumData;
 
 /**
  * The CSS style rule processor provides a mechanism for sibling style
  * sheets to combine their rule processing in order to allow proper
  * cascading to happen.
  *
  * CSS style rule processors keep a live reference on all style sheets
  * bound to them.  The CSS style sheets keep a weak reference to all the
  * processors that they are bound to (many to many).  The CSS style sheet
  * is told when the rule processor is going away (via DropRuleProcessor).
  */
 
 class nsCSSRuleProcessor: public nsIStyleRuleProcessor {
 public:
-  nsCSSRuleProcessor(const nsCOMArray<nsICSSStyleSheet>& aSheets, 
-                     PRUint8 aSheetType);
+  typedef nsTArray<nsRefPtr<nsCSSStyleSheet> > sheet_array_type;
+
+  nsCSSRuleProcessor(const sheet_array_type& aSheets, PRUint8 aSheetType);
   virtual ~nsCSSRuleProcessor();
 
   NS_DECL_ISUPPORTS
 
 public:
   nsresult ClearRuleCascades();
 
   static nsresult Startup();
@@ -120,23 +122,23 @@ public:
 #ifdef DEBUG
   void AssertQuirksChangeOK() {
     NS_ASSERTION(!mRuleCascades, "can't toggle quirks style sheet without "
                                  "clearing rule cascades");
   }
 #endif
 
 private:
-  static PRBool CascadeSheetEnumFunc(nsICSSStyleSheet* aSheet, void* aData);
+  static PRBool CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData);
 
   RuleCascadeData* GetRuleCascade(nsPresContext* aPresContext);
   void RefreshRuleCascade(nsPresContext* aPresContext);
 
   // The sheet order here is the same as in nsStyleSet::mSheets
-  nsCOMArray<nsICSSStyleSheet> mSheets;
+  sheet_array_type mSheets;
 
   // active first, then cached (most recent first)
   RuleCascadeData* mRuleCascades;
 
   // The last pres context for which GetRuleCascades was called.
   nsPresContext *mLastPresContext;
   
   // type of stylesheet using this processor
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -44,17 +44,17 @@
 #include "nsICSSNameSpaceRule.h"
 
 #include "nsString.h"
 #include "nsIAtom.h"
 #include "nsIURL.h"
 
 #include "nsCSSRule.h"
 #include "nsCSSProps.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 
 #include "nsCOMPtr.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsIDOMCSSRule.h"
 #include "nsIDOMCSSImportRule.h"
 #include "nsIDOMCSSMediaRule.h"
 #include "nsIDOMCSSMozDocumentRule.h"
 #include "nsIDOMCSSCharsetRule.h"
@@ -70,17 +70,17 @@
 #include "nsStyleConsts.h"
 #include "nsDOMError.h"
 #include "nsStyleUtil.h"
 #include "nsCSSDeclaration.h"
 #include "nsPrintfCString.h"
 
 #define IMPL_STYLE_RULE_INHERIT(_class, super) \
 NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); }  \
-NS_IMETHODIMP _class::SetStyleSheet(nsICSSStyleSheet* aSheet) { return super::SetStyleSheet(aSheet); }  \
+NS_IMETHODIMP _class::SetStyleSheet(nsCSSStyleSheet* aSheet) { return super::SetStyleSheet(aSheet); }  \
 NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); }  \
 nsIDOMCSSRule* _class::GetDOMRuleWeak(nsresult *aResult) { *aResult = NS_OK; return this; }  \
 NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; } 
 
 #define IMPL_STYLE_RULE_INHERIT2(_class, super) \
 NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); }  \
 NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); }  \
 NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; } 
@@ -388,45 +388,45 @@ public:
 
   // nsICSSImportRule methods
   NS_IMETHOD SetURLSpec(const nsString& aURLSpec);
   NS_IMETHOD GetURLSpec(nsString& aURLSpec) const;
 
   NS_IMETHOD SetMedia(const nsString& aMedia);
   NS_IMETHOD GetMedia(nsString& aMedia) const;
 
-  NS_IMETHOD SetSheet(nsICSSStyleSheet*);
+  NS_IMETHOD SetSheet(nsCSSStyleSheet*);
   
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMCSSImportRule interface
   NS_DECL_NSIDOMCSSIMPORTRULE
 
 protected:
   nsString  mURLSpec;
   nsRefPtr<nsMediaList> mMedia;
-  nsCOMPtr<nsICSSStyleSheet> mChildSheet;
+  nsRefPtr<nsCSSStyleSheet> mChildSheet;
 };
 
 CSSImportRuleImpl::CSSImportRuleImpl(nsMediaList* aMedia)
   : nsCSSRule()
   , mURLSpec()
   , mMedia(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.
 }
 
 CSSImportRuleImpl::CSSImportRuleImpl(const CSSImportRuleImpl& aCopy)
   : nsCSSRule(aCopy),
     mURLSpec(aCopy.mURLSpec)
 {
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   if (aCopy.mChildSheet) {
     sheet = aCopy.mChildSheet->Clone(nsnull, this, nsnull, nsnull);
   }
   SetSheet(sheet);
   // SetSheet sets mMedia appropriately
 }
 
 CSSImportRuleImpl::~CSSImportRuleImpl(void)
@@ -523,30 +523,28 @@ CSSImportRuleImpl::GetMedia(nsString& aM
     return mMedia->GetText(aMedia);
   } else {
     aMedia.Truncate();
     return NS_OK;
   }
 }
 
 NS_IMETHODIMP
-CSSImportRuleImpl::SetSheet(nsICSSStyleSheet* aSheet)
+CSSImportRuleImpl::SetSheet(nsCSSStyleSheet* aSheet)
 {
   nsresult rv;
   NS_ENSURE_ARG_POINTER(aSheet);
   
   // set the new sheet
   mChildSheet = aSheet;
   aSheet->SetOwnerRule(this);
 
   // set our medialist to be the same as the sheet's medialist
-  nsCOMPtr<nsIDOMStyleSheet> sheet(do_QueryInterface(mChildSheet, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIDOMMediaList> mediaList;
-  rv = sheet->GetMedia(getter_AddRefs(mediaList));
+  rv = mChildSheet->GetMedia(getter_AddRefs(mediaList));
   NS_ENSURE_SUCCESS(rv, rv);
   mMedia = static_cast<nsMediaList*>(mediaList.get());
   
   return NS_OK;
 }
 
 nsresult
 NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult, 
@@ -692,23 +690,23 @@ nsCSSGroupRule::~nsCSSGroupRule()
   }
 }
 
 IMPL_STYLE_RULE_INHERIT2(nsCSSGroupRule, nsCSSRule)
 
 static PRBool
 SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
 {
-  nsICSSStyleSheet* sheet = (nsICSSStyleSheet*)aSheet;
+  nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
   aRule->SetStyleSheet(sheet);
   return PR_TRUE;
 }
 
 NS_IMETHODIMP
-nsCSSGroupRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
+nsCSSGroupRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   mRules.EnumerateForwards(SetStyleSheetReference, aSheet);
   return nsCSSRule::SetStyleSheet(aSheet);
 }
 
 #ifdef DEBUG
 NS_IMETHODIMP
 nsCSSGroupRule::List(FILE* out, PRInt32 aIndent) const
@@ -930,17 +928,17 @@ NS_INTERFACE_MAP_BEGIN(nsCSSMediaRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsCSSGroupRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule)
 NS_INTERFACE_MAP_END
 
 NS_IMETHODIMP
-nsCSSMediaRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
+nsCSSMediaRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   if (mMedia) {
     // Set to null so it knows it's leaving one sheet and joining another.
     mMedia->SetStyleSheet(nsnull);
     mMedia->SetStyleSheet(aSheet);
   }
 
   return nsCSSGroupRule::SetStyleSheet(aSheet);
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -53,17 +53,17 @@
 #include "nsCSSProperty.h"
 #include "nsCSSValue.h"
 
 class CSSGroupRuleRuleListImpl;
 class nsMediaList;
 
 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE  \
 NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
-NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
+NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aSheet); \
 NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
 NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
 
 #define DECL_STYLE_RULE_INHERIT  \
 DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
 nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
 
 // inherits from nsCSSRule and also implements methods on nsICSSGroupRule
@@ -123,17 +123,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIStyleRule methods
 #ifdef DEBUG
   NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
   // nsICSSRule methods
-  NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); //override nsCSSGroupRule
+  NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aSheet); //override nsCSSGroupRule
   NS_IMETHOD GetType(PRInt32& aType) const;
   NS_IMETHOD Clone(nsICSSRule*& aClone) const;
   nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
   {
     *aResult = NS_OK;
     return this;
   }
 
--- a/layout/style/nsCSSStyleRule.cpp
+++ b/layout/style/nsCSSStyleRule.cpp
@@ -44,17 +44,17 @@
  * declarations
  */
 
 #include "nsCOMPtr.h"
 #include "nsCSSRule.h"
 #include "nsICSSStyleRule.h"
 #include "nsICSSGroupRule.h"
 #include "nsCSSDeclaration.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsCSSLoader.h"
 #include "nsIURL.h"
 #include "nsIDocument.h"
 #include "nsIDeviceContext.h"
 #include "nsIAtom.h"
 #include "nsCRT.h"
 #include "nsString.h"
 #include "nsStyleConsts.h"
@@ -530,17 +530,17 @@ PRInt32 nsCSSSelector::CalcWeight() cons
   return weight;
 }
 
 //
 // Builds the textual representation of a selector. Called by DOM 2 CSS 
 // StyleRule:selectorText
 //
 void
-nsCSSSelector::ToString(nsAString& aString, nsICSSStyleSheet* aSheet,
+nsCSSSelector::ToString(nsAString& aString, nsCSSStyleSheet* aSheet,
                         PRBool aAppend) const
 {
   if (!aAppend)
    aString.Truncate();
 
   // selectors are linked from right-to-left, so the next selector in
   // the linked list actually precedes this one in the resulting string
   nsAutoTArray<const nsCSSSelector*, 8> stack;
@@ -573,32 +573,32 @@ nsCSSSelector::ToString(nsAString& aStri
         }
       }
     }
   }
 }
 
 void
 nsCSSSelector::AppendToStringWithoutCombinators
-                   (nsAString& aString, nsICSSStyleSheet* aSheet) const
+                   (nsAString& aString, nsCSSStyleSheet* aSheet) const
 {
   AppendToStringWithoutCombinatorsOrNegations(aString, aSheet, PR_FALSE);
 
   for (const nsCSSSelector* negation = mNegations; negation;
        negation = negation->mNegations) {
     aString.AppendLiteral(":not(");
     negation->AppendToStringWithoutCombinatorsOrNegations(aString, aSheet,
                                                           PR_TRUE);
     aString.Append(PRUnichar(')'));
   }
 }
 
 void
 nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations
-                   (nsAString& aString, nsICSSStyleSheet* aSheet,
+                   (nsAString& aString, nsCSSStyleSheet* aSheet,
                    PRBool aIsNegated) const
 {
   nsAutoString temp;
   PRBool isPseudoElement = IsPseudoElement();
 
   // For non-pseudo-element selectors or for lone pseudo-elements, deal with
   // namespace prefixes.
   PRBool wroteNamespace = PR_FALSE;
@@ -860,17 +860,17 @@ nsCSSSelectorList::AddSelector(PRUnichar
   }
 
   newSel->mNext = mSelectors;
   mSelectors = newSel;
   return newSel;
 }
 
 void
-nsCSSSelectorList::ToString(nsAString& aResult, nsICSSStyleSheet* aSheet)
+nsCSSSelectorList::ToString(nsAString& aResult, nsCSSStyleSheet* aSheet)
 {
   aResult.Truncate();
   nsCSSSelectorList *p = this;
   for (;;) {
     p->mSelectors->ToString(aResult, aSheet, PR_TRUE);
     p = p->mNext;
     if (!p)
       break;
@@ -1080,17 +1080,17 @@ DOMCSSDeclarationImpl::GetCSSParsingEnvi
 
   nsCOMPtr<nsIStyleSheet> sheet;
   if (mRule) {
     mRule->GetStyleSheet(*getter_AddRefs(sheet));
     if (sheet) {
       sheet->GetSheetURI(aSheetURI);
       sheet->GetBaseURI(aBaseURI);
 
-      nsCOMPtr<nsICSSStyleSheet> cssSheet(do_QueryInterface(sheet));
+      nsRefPtr<nsCSSStyleSheet> cssSheet(do_QueryObject(sheet));
       if (cssSheet) {
         NS_ADDREF(*aSheetPrincipal = cssSheet->Principal());
       }
 
       nsCOMPtr<nsIDocument> document;
       sheet->GetOwningDocument(*getter_AddRefs(document));
       if (document) {
         NS_ADDREF(*aCSSLoader = document->CSSLoader());
@@ -1209,17 +1209,17 @@ DOMCSSStyleRuleImpl::SetCssText(const ns
 
 NS_IMETHODIMP    
 DOMCSSStyleRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
 {
   if (!Rule()) {
     *aSheet = nsnull;
     return NS_OK;
   }
-  nsCOMPtr<nsICSSStyleSheet> sheet;
+  nsRefPtr<nsCSSStyleSheet> sheet;
   Rule()->GetParentStyleSheet(getter_AddRefs(sheet));
   if (!sheet) {
     *aSheet = nsnull;
     return NS_OK;
   }
   return CallQueryInterface(sheet, aSheet);
 }
 
@@ -1298,23 +1298,23 @@ public:
   virtual void SetLineNumber(PRUint32 aLineNumber);
 
   virtual nsCSSDeclaration* GetDeclaration(void) const;
 
   virtual nsIStyleRule* GetImportantRule(void);
   virtual void RuleMatched();
 
   NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
-  NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
+  NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aSheet);
   
   NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
 
   virtual nsresult GetCssText(nsAString& aCssText);
   virtual nsresult SetCssText(const nsAString& aCssText);
-  virtual nsresult GetParentStyleSheet(nsICSSStyleSheet** aSheet);
+  virtual nsresult GetParentStyleSheet(nsCSSStyleSheet** aSheet);
   virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule);
   virtual nsresult GetSelectorText(nsAString& aSelectorText);
   virtual nsresult SetSelectorText(const nsAString& aSelectorText);
 
   NS_IMETHOD GetType(PRInt32& aType) const;
   NS_IMETHOD Clone(nsICSSRule*& aClone) const;
 
   nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
@@ -1477,17 +1477,17 @@ CSSStyleRuleImpl::RuleMatched()
 NS_IMETHODIMP
 CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
 {
 // XXX What about inner, etc.
   return nsCSSRule::GetStyleSheet(aSheet);
 }
 
 NS_IMETHODIMP
-CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
+CSSStyleRuleImpl::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   return nsCSSRule::SetStyleSheet(aSheet);
 }
 
 NS_IMETHODIMP
 CSSStyleRuleImpl::SetParentRule(nsICSSGroupRule* aRule)
 {
   return nsCSSRule::SetParentRule(aRule);
@@ -1610,17 +1610,17 @@ CSSStyleRuleImpl::GetCssText(nsAString& 
 /* virtual */ nsresult    
 CSSStyleRuleImpl::SetCssText(const nsAString& aCssText)
 {
   // XXX TBI - need to re-parse rule & declaration
   return NS_OK;
 }
 
 /* virtual */ nsresult    
-CSSStyleRuleImpl::GetParentStyleSheet(nsICSSStyleSheet** aSheet)
+CSSStyleRuleImpl::GetParentStyleSheet(nsCSSStyleSheet** aSheet)
 {
   *aSheet = mSheet;
   NS_IF_ADDREF(*aSheet);
   return NS_OK;
 }
 
 /* virtual */ nsresult    
 CSSStyleRuleImpl::GetParentRule(nsICSSGroupRule** aParentRule)
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -551,21 +551,19 @@ nsMediaList::GetText(nsAString& aMediaTe
 // it should be doing....
 nsresult
 nsMediaList::SetText(const nsAString& aMediaText)
 {
   nsCSSParser parser;
   NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
 
   PRBool htmlMode = PR_FALSE;
-  nsCOMPtr<nsIDOMStyleSheet> domSheet =
-    do_QueryInterface(static_cast<nsICSSStyleSheet*>(mStyleSheet));
-  if (domSheet) {
+  if (mStyleSheet) {
     nsCOMPtr<nsIDOMNode> node;
-    domSheet->GetOwnerNode(getter_AddRefs(node));
+    mStyleSheet->GetOwnerNode(getter_AddRefs(node));
     htmlMode = !!node;
   }
 
   return parser.ParseMediaList(nsString(aMediaText), nsnull, 0,
                                this, htmlMode);
 }
 
 PRBool
@@ -576,21 +574,21 @@ nsMediaList::Matches(nsPresContext* aPre
     if (mArray[i]->Matches(aPresContext, aKey)) {
       return PR_TRUE;
     }
   }
   return mIsEmpty;
 }
 
 nsresult
-nsMediaList::SetStyleSheet(nsICSSStyleSheet *aSheet)
+nsMediaList::SetStyleSheet(nsCSSStyleSheet *aSheet)
 {
   NS_ASSERTION(aSheet == mStyleSheet || !aSheet || !mStyleSheet,
                "multiple style sheets competing for one media list");
-  mStyleSheet = static_cast<nsCSSStyleSheet*>(aSheet);
+  mStyleSheet = aSheet;
   return NS_OK;
 }
 
 nsresult
 nsMediaList::Clone(nsMediaList** aResult)
 {
   nsRefPtr<nsMediaList> result = new nsMediaList();
   if (!result || !result->mArray.AppendElements(mArray.Length()))
@@ -765,33 +763,33 @@ nsMediaList::Append(const nsAString& aNe
   return rv;
 }
 
 // -------------------------------
 // CSS Style Sheet Inner Data Container
 //
 
 
-nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsICSSStyleSheet* aPrimarySheet)
+nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsCSSStyleSheet* aPrimarySheet)
   : mSheets(),
     mComplete(PR_FALSE)
 #ifdef DEBUG
     , mPrincipalSet(PR_FALSE)
 #endif
 {
   MOZ_COUNT_CTOR(nsCSSStyleSheetInner);
   mSheets.AppendElement(aPrimarySheet);
 
   mPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
 }
 
 static PRBool SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
 {
   if (aRule) {
-    aRule->SetStyleSheet((nsICSSStyleSheet*)aSheet);
+    aRule->SetStyleSheet(static_cast<nsCSSStyleSheet*>(aSheet));
   }
   return PR_TRUE;
 }
 
 static PRBool
 CloneRuleInto(nsICSSRule* aRule, void* aArray)
 {
   nsICSSRule* clone = nsnull;
@@ -837,22 +835,22 @@ nsCSSStyleSheet::RebuildChildList(nsICSS
   nsCOMPtr<nsIDOMCSSImportRule> importRule(do_QueryInterface(aRule));
   NS_ASSERTION(importRule, "GetType lied");
 
   nsCOMPtr<nsIDOMCSSStyleSheet> childSheet;
   importRule->GetStyleSheet(getter_AddRefs(childSheet));
 
   // Have to do this QI to be safe, since XPConnect can fake
   // nsIDOMCSSStyleSheets
-  nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(childSheet);
+  nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(childSheet);
   if (!cssSheet) {
     return PR_TRUE;
   }
 
-  (*builder->sheetSlot) = static_cast<nsCSSStyleSheet*>(cssSheet.get());
+  (*builder->sheetSlot) = cssSheet;
   builder->SetParentLinks(*builder->sheetSlot);
   builder->sheetSlot = &(*builder->sheetSlot)->mNext;
   return PR_TRUE;
 }
 
 nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
                                            nsCSSStyleSheet* aPrimarySheet)
   : mSheets(),
@@ -884,23 +882,23 @@ nsCSSStyleSheetInner::~nsCSSStyleSheetIn
 
 nsCSSStyleSheetInner* 
 nsCSSStyleSheetInner::CloneFor(nsCSSStyleSheet* aPrimarySheet)
 {
   return new nsCSSStyleSheetInner(*this, aPrimarySheet);
 }
 
 void
-nsCSSStyleSheetInner::AddSheet(nsICSSStyleSheet* aSheet)
+nsCSSStyleSheetInner::AddSheet(nsCSSStyleSheet* aSheet)
 {
   mSheets.AppendElement(aSheet);
 }
 
 void
-nsCSSStyleSheetInner::RemoveSheet(nsICSSStyleSheet* aSheet)
+nsCSSStyleSheetInner::RemoveSheet(nsCSSStyleSheet* aSheet)
 {
   if (1 == mSheets.Length()) {
     NS_ASSERTION(aSheet == mSheets.ElementAt(0), "bad parent");
     delete this;
     return;
   }
   if (aSheet == mSheets.ElementAt(0)) {
     mSheets.RemoveElementAt(0);
@@ -967,40 +965,38 @@ nsCSSStyleSheetInner::CreateNamespaceMap
   return NS_OK;
 }
 
 // -------------------------------
 // CSS Style Sheet
 //
 
 nsCSSStyleSheet::nsCSSStyleSheet()
-  : nsICSSStyleSheet(),
-    mRefCnt(0),
+  : mRefCnt(0),
     mTitle(), 
     mMedia(nsnull),
     mParent(nsnull),
     mOwnerRule(nsnull),
     mRuleCollection(nsnull),
     mDocument(nsnull),
     mOwningNode(nsnull),
     mDisabled(PR_FALSE),
     mDirty(PR_FALSE),
     mRuleProcessors(nsnull)
 {
 
   mInner = new nsCSSStyleSheetInner(this);
 }
 
 nsCSSStyleSheet::nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
-                                 nsICSSStyleSheet* aParentToUse,
+                                 nsCSSStyleSheet* aParentToUse,
                                  nsICSSImportRule* aOwnerRuleToUse,
                                  nsIDocument* aDocumentToUse,
                                  nsIDOMNode* aOwningNodeToUse)
-  : nsICSSStyleSheet(),
-    mRefCnt(0),
+  : mRefCnt(0),
     mTitle(aCopy.mTitle), 
     mMedia(nsnull),
     mParent(aParentToUse),
     mOwnerRule(aOwnerRuleToUse),
     mRuleCollection(nsnull), // re-created lazily
     mDocument(aDocumentToUse),
     mOwningNode(aOwningNodeToUse),
     mDisabled(aCopy.mDisabled),
@@ -1055,23 +1051,25 @@ nsCSSStyleSheet::~nsCSSStyleSheet()
   }
 }
 
 
 DOMCI_DATA(CSSStyleSheet, nsCSSStyleSheet)
 
 // QueryInterface implementation for nsCSSStyleSheet
 NS_INTERFACE_MAP_BEGIN(nsCSSStyleSheet)
-  NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet)
   NS_INTERFACE_MAP_ENTRY(nsIStyleSheet)
   NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
   NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleSheet)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleSheet)
+  if (aIID.Equals(NS_GET_IID(nsCSSStyleSheet)))
+    foundInterface = reinterpret_cast<nsISupports*>(this);
+  else
 NS_INTERFACE_MAP_END
 
 
 NS_IMPL_ADDREF(nsCSSStyleSheet)
 NS_IMPL_RELEASE(nsCSSStyleSheet)
 
 
 nsresult
@@ -1275,17 +1273,17 @@ nsCSSStyleSheet::SetOwnerRule(nsICSSImpo
 already_AddRefed<nsICSSImportRule>
 nsCSSStyleSheet::GetOwnerRule()
 {
   NS_IF_ADDREF(mOwnerRule);
   return mOwnerRule;
 }
 
 void
-nsCSSStyleSheet::AppendStyleSheet(nsICSSStyleSheet* aSheet)
+nsCSSStyleSheet::AppendStyleSheet(nsCSSStyleSheet* aSheet)
 {
   NS_PRECONDITION(nsnull != aSheet, "null arg");
 
   if (NS_SUCCEEDED(WillDirty())) {
     nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
 
     nsRefPtr<nsCSSStyleSheet>* tail = &mInner->mFirstChild;
     while (*tail) {
@@ -1297,17 +1295,17 @@ nsCSSStyleSheet::AppendStyleSheet(nsICSS
     // it's going away.
     sheet->mParent = this;
     sheet->mDocument = mDocument;
     DidDirty();
   }
 }
 
 void
-nsCSSStyleSheet::InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex)
+nsCSSStyleSheet::InsertStyleSheetAt(nsCSSStyleSheet* aSheet, PRInt32 aIndex)
 {
   NS_PRECONDITION(nsnull != aSheet, "null arg");
 
   if (NS_SUCCEEDED(WillDirty())) {
     nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
 
     nsRefPtr<nsCSSStyleSheet>* tail = &mInner->mFirstChild;
     while (*tail && aIndex) {
@@ -1429,17 +1427,17 @@ nsCSSStyleSheet::StyleSheetCount() const
   while (child) {
     count++;
     child = child->mNext;
   }
 
   return count;
 }
 
-already_AddRefed<nsICSSStyleSheet>
+already_AddRefed<nsCSSStyleSheet>
 nsCSSStyleSheet::GetStyleSheetAt(PRInt32 aIndex) const
 {
   // XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
   // that this isn't done too often. If it is, we need to change the
   // underlying storage mechanism
   nsCSSStyleSheet* child = mInner->mFirstChild;
   while (child && (0 != aIndex)) {
     --aIndex;
@@ -1478,18 +1476,18 @@ nsCSSStyleSheet::AppendAllChildSheets(ns
        child = child->mNext) {
     if (!aArray.AppendElement(child)) {
       return PR_FALSE;
     }
   }
   return PR_TRUE;
 }
 
-already_AddRefed<nsICSSStyleSheet>
-nsCSSStyleSheet::Clone(nsICSSStyleSheet* aCloneParent,
+already_AddRefed<nsCSSStyleSheet>
+nsCSSStyleSheet::Clone(nsCSSStyleSheet* aCloneParent,
                        nsICSSImportRule* aCloneOwnerRule,
                        nsIDocument* aCloneDocument,
                        nsIDOMNode* aCloneOwningNode) const
 {
   nsCSSStyleSheet* clone = new nsCSSStyleSheet(*this,
                                                aCloneParent,
                                                aCloneOwnerRule,
                                                aCloneDocument,
@@ -2115,28 +2113,24 @@ nsCSSStyleSheet::ReplaceRuleInGroup(nsIC
 
   result = aGroup->ReplaceStyleRule(aOld, aNew);
   DidDirty();
   return result;
 }
 
 // nsICSSLoaderObserver implementation
 NS_IMETHODIMP
-nsCSSStyleSheet::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
+nsCSSStyleSheet::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
                                   PRBool aWasAlternate,
                                   nsresult aStatus)
 {
 #ifdef DEBUG
-  nsCOMPtr<nsIStyleSheet> styleSheet(do_QueryInterface(aSheet));
-  NS_ASSERTION(styleSheet, "Sheet not implementing nsIStyleSheet!\n");
   nsCOMPtr<nsIStyleSheet> parentSheet;
   aSheet->GetParentSheet(*getter_AddRefs(parentSheet));
-  nsCOMPtr<nsIStyleSheet> thisSheet;
-  QueryInterface(NS_GET_IID(nsIStyleSheet), getter_AddRefs(thisSheet));
-  NS_ASSERTION(thisSheet == parentSheet, "We are being notified of a sheet load for a sheet that is not our child!\n");
+  NS_ASSERTION(this == parentSheet, "We are being notified of a sheet load for a sheet that is not our child!\n");
 #endif
   
   if (mDocument && NS_SUCCEEDED(aStatus)) {
     nsCOMPtr<nsICSSImportRule> ownerRule = aSheet->GetOwnerRule();
     
     mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
 
     // XXXldb @import rules shouldn't even implement nsIStyleRule (but
@@ -2151,17 +2145,17 @@ nsCSSStyleSheet::StyleSheetLoaded(nsICSS
 
 nsIURI*
 nsCSSStyleSheet::GetOriginalURI() const
 {
   return mInner->mOriginalSheetURI;
 }
 
 nsresult
-NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult)
+NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult)
 {
   *aInstancePtrResult = nsnull;
   nsCSSStyleSheet  *it = new nsCSSStyleSheet();
 
   if (!it) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
--- a/layout/style/nsCSSStyleSheet.h
+++ b/layout/style/nsCSSStyleSheet.h
@@ -42,53 +42,60 @@
 /* representation of a CSS style sheet */
 
 #ifndef nsCSSStyleSheet_h_
 #define nsCSSStyleSheet_h_
 
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
-#include "nsICSSStyleSheet.h"
+#include "nsIStyleSheet.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsCOMArray.h"
 
+class nsICSSRule;
+class nsXMLNameSpaceMap;
+class nsCSSRuleProcessor;
+class nsMediaList;
+class nsICSSGroupRule;
+class nsICSSImportRule;
+class nsIPrincipal;
 class nsIURI;
 class nsMediaList;
 class nsMediaQueryResultCacheKey;
 class nsCSSStyleSheet;
 class nsPresContext;
 template<class E> class nsTArray;
 
 // -------------------------------
 // CSS Style Sheet Inner Data Container
 //
 
 class nsCSSStyleSheetInner {
 public:
   friend class nsCSSStyleSheet;
   friend class nsCSSRuleProcessor;
-  friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
+  friend nsresult NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult);
 private:
-  nsCSSStyleSheetInner(nsICSSStyleSheet* aPrimarySheet);
+  nsCSSStyleSheetInner(nsCSSStyleSheet* aPrimarySheet);
   nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
                        nsCSSStyleSheet* aPrimarySheet);
   ~nsCSSStyleSheetInner();
 
   nsCSSStyleSheetInner* CloneFor(nsCSSStyleSheet* aPrimarySheet);
-  void AddSheet(nsICSSStyleSheet* aSheet);
-  void RemoveSheet(nsICSSStyleSheet* aSheet);
+  void AddSheet(nsCSSStyleSheet* aSheet);
+  void RemoveSheet(nsCSSStyleSheet* aSheet);
 
   void RebuildNameSpaces();
 
   // Create a new namespace map
   nsresult CreateNamespaceMap();
 
-  nsAutoTArray<nsICSSStyleSheet*, 8> mSheets;
+  nsAutoTArray<nsCSSStyleSheet*, 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;
   nsCOMArray<nsICSSRule> 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
@@ -106,25 +113,34 @@ private:
 
 // -------------------------------
 // CSS Style Sheet
 //
 
 class CSSRuleListImpl;
 struct ChildSheetListBuilder;
 
-class nsCSSStyleSheet : public nsICSSStyleSheet, 
+// CID for the nsCSSStyleSheet class
+// 55f243d9-d985-490c-9eea-095c7fa35cf4
+#define NS_CSS_STYLE_SHEET_IMPL_CID     \
+{ 0x55f243d9, 0xd985, 0x490c, \
+ { 0x9e, 0xea, 0x09, 0x5c, 0x7f, 0xa3, 0x5c, 0xf4 } }
+
+
+class nsCSSStyleSheet : public nsIStyleSheet,
                         public nsIDOMCSSStyleSheet,
                         public nsICSSLoaderObserver
 {
 public:
   nsCSSStyleSheet();
 
   NS_DECL_ISUPPORTS
 
+  NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
+
   // nsIStyleSheet interface
   NS_IMETHOD GetSheetURI(nsIURI** aSheetURI) const;
   NS_IMETHOD GetBaseURI(nsIURI** aBaseURI) const;
   NS_IMETHOD GetTitle(nsString& aTitle) const;
   NS_IMETHOD GetType(nsString& aType) const;
   NS_IMETHOD_(PRBool) HasRules() const;
   NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
   NS_IMETHOD SetEnabled(PRBool aEnabled);
@@ -132,52 +148,51 @@ public:
   NS_IMETHOD SetComplete();
   NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const;  // may be null
   NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;  // may be null
   NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
   
-  // nsICSSStyleSheet interface
-  virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet);
-  virtual void InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex);
+  virtual void AppendStyleSheet(nsCSSStyleSheet* aSheet);
+  virtual void InsertStyleSheetAt(nsCSSStyleSheet* aSheet, PRInt32 aIndex);
   virtual void PrependStyleRule(nsICSSRule* aRule);
   virtual void AppendStyleRule(nsICSSRule* aRule);
   virtual void ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew);
   virtual PRInt32 StyleRuleCount() const;
   virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
   virtual nsresult DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex);
   virtual nsresult InsertRuleIntoGroup(const nsAString& aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
   virtual nsresult ReplaceRuleInGroup(nsICSSGroupRule* aGroup, nsICSSRule* aOld, nsICSSRule* aNew);
   virtual PRInt32 StyleSheetCount() const;
-  virtual already_AddRefed<nsICSSStyleSheet> GetStyleSheetAt(PRInt32 aIndex) const;
+  virtual already_AddRefed<nsCSSStyleSheet> GetStyleSheetAt(PRInt32 aIndex) const;
   virtual void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
   virtual void SetPrincipal(nsIPrincipal* aPrincipal);
   virtual nsIPrincipal* Principal() const;
   virtual void SetTitle(const nsAString& aTitle);
   virtual void SetMedia(nsMediaList* aMedia);
   virtual void SetOwningNode(nsIDOMNode* aOwningNode);
   virtual void SetOwnerRule(nsICSSImportRule* aOwnerRule);
   virtual already_AddRefed<nsICSSImportRule> GetOwnerRule();
   virtual nsXMLNameSpaceMap* GetNameSpaceMap() const;
-  virtual already_AddRefed<nsICSSStyleSheet> Clone(nsICSSStyleSheet* aCloneParent,
-                                                   nsICSSImportRule* aCloneOwnerRule,
-                                                   nsIDocument* aCloneDocument,
-                                                   nsIDOMNode* aCloneOwningNode) const;
+  virtual already_AddRefed<nsCSSStyleSheet> Clone(nsCSSStyleSheet* aCloneParent,
+                                                  nsICSSImportRule* aCloneOwnerRule,
+                                                  nsIDocument* aCloneDocument,
+                                                  nsIDOMNode* aCloneOwningNode) const;
   virtual PRBool IsModified() const;
   virtual void SetModified(PRBool aModified);
   virtual nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
   virtual nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
   virtual nsresult InsertRuleInternal(const nsAString& aRule,
                                 PRUint32 aIndex, PRUint32* aReturn);
   virtual nsIURI* GetOriginalURI() const;
 
   // nsICSSLoaderObserver interface
-  NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
+  NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, PRBool aWasAlternate,
                               nsresult aStatus);
 
   enum EnsureUniqueInnerResult {
     // No work was needed to ensure a unique inner.
     eUniqueInner_AlreadyUnique,
     // A clone was done to ensure a unique inner (which means the style
     // rules in this sheet have changed).
     eUniqueInner_ClonedInner,
@@ -200,21 +215,21 @@ public:
   NS_DECL_NSIDOMCSSSTYLESHEET
 
   // Function used as a callback to rebuild our inner's child sheet
   // list after we clone a unique inner for ourselves.
   static PRBool RebuildChildList(nsICSSRule* aRule, void* aBuilder);
 
 private:
   nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
-                  nsICSSStyleSheet* aParentToUse,
+                  nsCSSStyleSheet* aParentToUse,
                   nsICSSImportRule* aOwnerRuleToUse,
                   nsIDocument* aDocumentToUse,
                   nsIDOMNode* aOwningNodeToUse);
-  
+
   // These are not supported and are not implemented! 
   nsCSSStyleSheet(const nsCSSStyleSheet& aCopy); 
   nsCSSStyleSheet& operator=(const nsCSSStyleSheet& aCopy); 
 
 protected:
   virtual ~nsCSSStyleSheet();
 
   void ClearRuleCascades();
@@ -229,28 +244,32 @@ protected:
 
   // Add the namespace mapping from this @namespace rule to our namespace map
   nsresult RegisterNamespaceRule(nsICSSRule* aRule);
 
 protected:
   nsString              mTitle;
   nsCOMPtr<nsMediaList> mMedia;
   nsRefPtr<nsCSSStyleSheet> mNext;
-  nsICSSStyleSheet*     mParent;    // weak ref
+  nsCSSStyleSheet*      mParent;    // weak ref
   nsICSSImportRule*     mOwnerRule; // weak ref
 
   CSSRuleListImpl*      mRuleCollection;
   nsIDocument*          mDocument; // weak ref; parents maintain this for their children
   nsIDOMNode*           mOwningNode; // weak ref
   PRPackedBool          mDisabled;
   PRPackedBool          mDirty; // has been modified 
 
   nsCSSStyleSheetInner* mInner;
 
   nsAutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
 
   friend class nsMediaList;
   friend class nsCSSRuleProcessor;
-  friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
+  friend nsresult NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult);
   friend struct ChildSheetListBuilder;
 };
 
+NS_DEFINE_STATIC_IID_ACCESSOR(nsCSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)
+
+nsresult NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult);
+
 #endif /* !defined(nsCSSStyleSheet_h_) */
--- a/layout/style/nsICSSGroupRule.h
+++ b/layout/style/nsICSSGroupRule.h
@@ -45,19 +45,19 @@
 
 #include "nsICSSRule.h"
 #include "nsCOMArray.h"
 
 class nsIAtom;
 class nsPresContext;
 class nsMediaQueryResultCacheKey;
 
-// IID for the nsICSSGroupRule interface {67b8492e-6d8d-43a5-8037-71eb269f24fe}
+// IID for the nsICSSGroupRule interface {d0f07b17-e9c7-4a54-aaa4-622425b38d27}
 #define NS_ICSS_GROUP_RULE_IID     \
-{0x67b8492e, 0x6d8d, 0x43a5, {0x80, 0x37, 0x71, 0xeb, 0x26, 0x9f, 0x24, 0xfe}}
+{0xd0f07b17, 0xe9c7, 0x4a54, {0xaa, 0xa4, 0x62, 0x24, 0x25, 0xb3, 0x8d, 0x27}}
 
 class nsICSSGroupRule : public nsICSSRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_GROUP_RULE_IID)
 
   NS_IMETHOD  AppendStyleRule(nsICSSRule* aRule) = 0;
 
   NS_IMETHOD  StyleRuleCount(PRInt32& aCount) const = 0;
--- a/layout/style/nsICSSImportRule.h
+++ b/layout/style/nsICSSImportRule.h
@@ -42,31 +42,31 @@
 
 #include "nsICSSRule.h"
 #include "nsString.h"
 
 class nsIAtom;
 class nsIURI;
 class nsMediaList;
 
-// IID for the nsICSSImportRule interface {33824a60-1a09-11d3-805a-006008159b5a}
+// IID for the nsICSSImportRule interface {b2e65d15-6673-4548-a65a-c45ce87304f2}
 #define NS_ICSS_IMPORT_RULE_IID     \
-{0x33824a60, 0x1a09, 0x11d3, {0x80, 0x5a, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
+{0xb2e65d15, 0x6673, 0x4548, {0xa6, 0x5a, 0xc4, 0x5c, 0xe8, 0x73, 0x04, 0xf2}}
 
 class nsICSSImportRule : public nsICSSRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_IMPORT_RULE_IID)
 
   NS_IMETHOD SetURLSpec(const nsString& aURLSpec) = 0;
   NS_IMETHOD GetURLSpec(nsString& aURLSpec) const = 0;
 
   NS_IMETHOD SetMedia(const nsString& aMedia) = 0;
   NS_IMETHOD GetMedia(nsString& aMedia) const = 0;
 
-  NS_IMETHOD SetSheet(nsICSSStyleSheet*) = 0;
+  NS_IMETHOD SetSheet(nsCSSStyleSheet*) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSImportRule, NS_ICSS_IMPORT_RULE_IID)
 
 nsresult
 NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult, 
                     const nsString& aURLSpec, nsMediaList* aMedia);
 
--- a/layout/style/nsICSSLoaderObserver.h
+++ b/layout/style/nsICSSLoaderObserver.h
@@ -38,20 +38,20 @@
 /* internal interface for observing CSS style sheet loads */
 
 #ifndef nsICSSLoaderObserver_h___
 #define nsICSSLoaderObserver_h___
 
 #include "nsISupports.h"
 
 #define NS_ICSSLOADEROBSERVER_IID     \
-{ 0xf5e8eb0f, 0x4c44, 0x49d5,       \
-{0xb1, 0xe9, 0xab, 0x39, 0x23, 0x93, 0xc0, 0xf8} }
+{ 0x7eb90c74, 0xea0c, 0x4df5,       \
+{0xa1, 0x5f, 0x95, 0xf0, 0x6a, 0x98, 0xb9, 0x40} }
 
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 
 class nsICSSLoaderObserver : public nsISupports {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSLOADEROBSERVER_IID)
 
   /**
    * StyleSheetLoaded is called after aSheet is marked complete and before any
    * load events associated with aSheet are fired.
@@ -62,15 +62,15 @@ public:
    *        aIsAlternate if one of those methods were used to load the sheet,
    *        and will always be false otherwise.
    * @param aStatus is a success code if the sheet loaded successfully and a
    *        failure code otherwise.  Note that successful load of aSheet
    *        doesn't indicate anything about whether the data actually parsed
    *        as CSS, and doesn't indicate anything about the status of any child
    *        sheets of aSheet.
    */
-  NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
+  NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, PRBool aWasAlternate,
                               nsresult aStatus) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSLoaderObserver, NS_ICSSLOADEROBSERVER_IID)
 
 #endif // nsICSSLoaderObserver_h___
--- a/layout/style/nsICSSNameSpaceRule.h
+++ b/layout/style/nsICSSNameSpaceRule.h
@@ -39,21 +39,20 @@
 
 #ifndef nsICSSNameSpaceRule_h___
 #define nsICSSNameSpaceRule_h___
 
 #include "nsICSSRule.h"
 //#include "nsString.h"
 
 class nsIAtom;
-class nsIURI;
 
-// IID for the nsICSSNameSpaceRule interface {2469c930-1a09-11d3-805a-006008159b5a}
+// IID for the nsICSSNameSpaceRule interface {c2116a9f-370d-458a-80c1-c6445089a8b7}
 #define NS_ICSS_NAMESPACE_RULE_IID     \
-{0x2469c930, 0x1a09, 0x11d3, {0x80, 0x5a, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
+{0xc2116a9f, 0x370d, 0x458a, {0x80, 0xc1, 0xc6, 0x44, 0x50, 0x89, 0xa8, 0xb7}}
 
 class nsICSSNameSpaceRule : public nsICSSRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_NAMESPACE_RULE_IID)
 
   NS_IMETHOD  GetPrefix(nsIAtom*& aPrefix) const = 0;
   NS_IMETHOD  SetPrefix(nsIAtom* aPrefix) = 0;
 
--- a/layout/style/nsICSSRule.h
+++ b/layout/style/nsICSSRule.h
@@ -38,24 +38,24 @@
 /* internal interface for all rule types in a CSS style sheet */
 
 #ifndef nsICSSRule_h___
 #define nsICSSRule_h___
 
 #include "nsIStyleRule.h"
 #include "nsIDOMCSSRule.h"
 
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 class nsICSSGroupRule;
 class nsAString;
 
-// IID for the nsICSSRule interface {98d426f7-2ef9-44f5-8d06-e064f486a18c}
+// IID for the nsICSSRule interface {72250d73-dbb2-4409-90fe-e8e0283a2510}
 #define NS_ICSS_RULE_IID     \
-{ 0x98d426f7, 0x2ef9, 0x44f5, \
- { 0x8d, 0x06, 0xe0, 0x64, 0xf4, 0x86, 0xa1, 0x8c } }
+{ 0x72250d73, 0xdbb2, 0x4409, \
+ { 0x90, 0xfe, 0xe8, 0xe0, 0x28, 0x3a, 0x25, 0x10 } }
 
 // inheriting from nsIStyleRule is only for style rules, not other rule types
 class nsICSSRule : public nsIStyleRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_RULE_IID)
   // The constants in this list must maintain the following invariants:
   //   If a rule of type N must appear before a rule of type M in stylesheets
   //   then N < M
@@ -71,17 +71,17 @@ public:
     FONT_FACE_RULE,
     PAGE_RULE,
     DOCUMENT_RULE
   };
 
   NS_IMETHOD GetType(PRInt32& aType) const = 0;
 
   NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const = 0;
-  NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
+  NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aSheet) = 0;
   NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule) = 0;
 
   NS_IMETHOD Clone(nsICSSRule*& aClone) const = 0;
 
   // Note that this returns null for inline style rules since they aren't
   // supposed to have a DOM rule representation (and our code wouldn't work).
   nsresult GetDOMRule(nsIDOMCSSRule** aDOMRule)
   {
--- a/layout/style/nsICSSStyleRule.h
+++ b/layout/style/nsICSSStyleRule.h
@@ -52,17 +52,17 @@
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsIAtom.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSPseudoClasses.h"
 
 class nsIAtom;
 class nsCSSDeclaration;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 struct nsCSSSelectorList;
 
 struct nsAtomList {
 public:
   nsAtomList(nsIAtom* aAtom);
   nsAtomList(const nsString& aAtomValue);
   ~nsAtomList(void);
 
@@ -188,27 +188,27 @@ public:
 
   inline PRBool IsPseudoElement() const {
     return mLowercaseTag && !mCasedTag;
   }
 
   // Calculate the specificity of this selector (not including its mNext!).
   PRInt32 CalcWeight() const;
 
-  void ToString(nsAString& aString, nsICSSStyleSheet* aSheet,
+  void ToString(nsAString& aString, nsCSSStyleSheet* aSheet,
                 PRBool aAppend = PR_FALSE) const;
 
 private:
   void AddPseudoClassInternal(nsPseudoClassList *aPseudoClass);
   nsCSSSelector* Clone(PRBool aDeepNext, PRBool aDeepNegations) const;
 
   void AppendToStringWithoutCombinators(nsAString& aString,
-                                        nsICSSStyleSheet* aSheet) const;
+                                        nsCSSStyleSheet* aSheet) const;
   void AppendToStringWithoutCombinatorsOrNegations(nsAString& aString,
-                                                   nsICSSStyleSheet* aSheet,
+                                                   nsCSSStyleSheet* aSheet,
                                                    PRBool aIsNegated)
                                                         const;
   // Returns true if this selector can have a namespace specified (which
   // happens if and only if the default namespace would apply to this
   // selector).
   PRBool CanBeNamespaced(PRBool aIsNegated) const;
   // Calculate the specificity of this selector (not including its mNext
   // or its mNegations).
@@ -266,17 +266,17 @@ struct nsCSSSelectorList {
    * The list owns the new selector.
    * The caller is responsible for updating |mWeight|.
    */
   nsCSSSelector* AddSelector(PRUnichar aOperator);
 
   /**
    * Should be used only on the first in the list
    */
-  void ToString(nsAString& aResult, nsICSSStyleSheet* aSheet);
+  void ToString(nsAString& aResult, nsCSSStyleSheet* aSheet);
 
   /**
    * Do a deep clone.  Should be used only on the first in the list.
    */
   nsCSSSelectorList* Clone() const { return Clone(PR_TRUE); }
 
   nsCSSSelector*     mSelectors;
   PRInt32            mWeight;
@@ -284,20 +284,20 @@ struct nsCSSSelectorList {
 private: 
   nsCSSSelectorList* Clone(PRBool aDeep) const;
 
   // These are not supported and are not implemented! 
   nsCSSSelectorList(const nsCSSSelectorList& aCopy);
   nsCSSSelectorList& operator=(const nsCSSSelectorList& aCopy); 
 };
 
-// e665007e-5d4a-433a-9056-4310701c08b9
+// 1aae9e9d-21c3-4993-90b1-66aa6809f597
 #define NS_ICSS_STYLE_RULE_IID \
-{ 0xe665007e, 0x5d4a, 0x433a, \
-  { 0x90, 0x56, 0x43, 0x10, 0x70, 0x1c, 0x08, 0xb9 } }
+{ 0x1aae9e9d, 0x21c3, 0x4993, \
+  { 0x90, 0xb1, 0x66, 0xaa, 0x68, 0x09, 0xf5, 0x97 } }
 
 class nsICSSStyleRule : public nsICSSRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_RULE_IID)
 
   // null for style attribute
   virtual nsCSSSelectorList* Selector(void) = 0;
 
@@ -322,17 +322,17 @@ public:
    * The rule processor must call this method before calling
    * nsRuleWalker::Forward on this rule during rule matching.
    */
   virtual void RuleMatched() = 0;
 
   // hooks for DOM rule
   virtual nsresult GetCssText(nsAString& aCssText) = 0;
   virtual nsresult SetCssText(const nsAString& aCssText) = 0;
-  virtual nsresult GetParentStyleSheet(nsICSSStyleSheet** aSheet) = 0;
+  virtual nsresult GetParentStyleSheet(nsCSSStyleSheet** aSheet) = 0;
   virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule) = 0;
   virtual nsresult GetSelectorText(nsAString& aSelectorText) = 0;
   virtual nsresult SetSelectorText(const nsAString& aSelectorText) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSStyleRule, NS_ICSS_STYLE_RULE_IID)
 
 nsresult
deleted file mode 100644
--- a/layout/style/nsICSSStyleSheet.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* representation of a CSS style sheet */
-
-#ifndef nsICSSStyleSheet_h___
-#define nsICSSStyleSheet_h___
-
-#include "nsIStyleSheet.h"
-#include "nsCOMPtr.h"
-
-class nsICSSRule;
-class nsIDOMNode;
-class nsXMLNameSpaceMap;
-class nsCSSRuleProcessor;
-class nsMediaList;
-class nsICSSGroupRule;
-class nsICSSImportRule;
-class nsIPrincipal;
-class nsAString;
-
-// IID for the nsICSSStyleSheet interface
-// 94d4d747-f690-4eb6-96c0-196a1b3659dc
-#define NS_ICSS_STYLE_SHEET_IID     \
-{ 0x94d4d747, 0xf690, 0x4eb6, \
- { 0x96, 0xc0, 0x19, 0x6a, 0x1b, 0x36, 0x59, 0xdc } }
-
-class nsICSSStyleSheet : public nsIStyleSheet {
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_SHEET_IID)
-
-  virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet) = 0;
-  virtual void InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex) = 0;
-
-  // XXX do these belong here or are they generic?
-  virtual void PrependStyleRule(nsICSSRule* aRule) = 0;
-  virtual void AppendStyleRule(nsICSSRule* aRule) = 0;
-  virtual void ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew) = 0;
-
-  virtual PRInt32 StyleRuleCount() const = 0;
-  virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const = 0;
-
-  virtual nsresult DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex) = 0;
-  virtual nsresult InsertRuleIntoGroup(const nsAString & aRule, nsICSSGroupRule* aGroup,
-                                       PRUint32 aIndex, PRUint32* _retval) = 0;
-  virtual nsresult ReplaceRuleInGroup(nsICSSGroupRule* aGroup, nsICSSRule* aOld,
-                                      nsICSSRule* aNew) = 0;
-
-  virtual PRInt32 StyleSheetCount() const = 0;
-  virtual already_AddRefed<nsICSSStyleSheet> GetStyleSheetAt(PRInt32 aIndex) const = 0;
-
-  /**
-   * SetURIs must be called on all sheets before parsing into them.
-   * SetURIs may only be called while the sheet is 1) incomplete and 2)
-   * has no rules in it
-   */
-  virtual void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
-                       nsIURI* aBaseURI) = 0;
-
-  /**
-   * SetPrincipal should be called on all sheets before parsing into them.
-   * This can only be called once with a non-null principal.  Calling this with
-   * a null pointer is allowed and is treated as a no-op.
-   */
-  virtual void SetPrincipal(nsIPrincipal* aPrincipal) = 0;
-
-  // Principal() never returns a null pointer.
-  virtual nsIPrincipal* Principal() const = 0;
-
-  virtual void SetTitle(const nsAString& aTitle) = 0;
-  virtual void SetMedia(nsMediaList* aMedia) = 0;
-  virtual void SetOwningNode(nsIDOMNode* aOwningNode) = 0;
-
-  virtual void SetOwnerRule(nsICSSImportRule* aOwnerRule) = 0;
-  virtual already_AddRefed<nsICSSImportRule> GetOwnerRule() = 0;
-  
-  // get namespace map for sheet
-  virtual nsXMLNameSpaceMap* GetNameSpaceMap() const = 0;
-
-  virtual already_AddRefed<nsICSSStyleSheet> Clone(nsICSSStyleSheet* aCloneParent,
-                                                   nsICSSImportRule* aCloneOwnerRule,
-                                                   nsIDocument* aCloneDocument,
-                                                   nsIDOMNode* aCloneOwningNode) const = 0;
-
-  virtual PRBool IsModified() const = 0; // returns the mDirty status of the sheet
-  virtual void SetModified(PRBool aModified) = 0;
-
-  virtual nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor) = 0;
-  virtual nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor) = 0;
-
-  /**
-   * Like the DOM insertRule() method, but doesn't do any security checks
-   */
-  virtual nsresult InsertRuleInternal(const nsAString& aRule,
-                                PRUint32 aIndex, PRUint32* aReturn) = 0;
-
-  /* Get the URI this sheet was originally loaded from, if any.  Can
-     return null */
-  virtual nsIURI* GetOriginalURI() const = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSStyleSheet, NS_ICSS_STYLE_SHEET_IID)
-
-nsresult
-NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
-
-#endif /* nsICSSStyleSheet_h___ */
--- a/layout/style/nsIMediaList.h
+++ b/layout/style/nsIMediaList.h
@@ -49,17 +49,17 @@
 #include "nsAString.h"
 #include "nsTArray.h"
 #include "nsTPtrArray.h"
 #include "nsIAtom.h"
 #include "nsMediaFeatures.h"
 #include "nsCSSValue.h"
 
 class nsPresContext;
-class nsICSSStyleSheet;
+class nsCSSStyleSheet;
 class nsCSSStyleSheet;
 
 struct nsMediaExpression {
   enum Range { eMin, eMax, eEqual };
 
   const nsMediaFeature *mFeature;
   Range mRange;
   nsCSSValue mValue;
@@ -183,17 +183,17 @@ public:
   NS_DECL_ISUPPORTS
 
   NS_DECL_NSIDOMMEDIALIST
 
   nsresult GetText(nsAString& aMediaText);
   nsresult SetText(const nsAString& aMediaText);
   PRBool Matches(nsPresContext* aPresContext,
                  nsMediaQueryResultCacheKey& aKey);
-  nsresult SetStyleSheet(nsICSSStyleSheet* aSheet);
+  nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
   nsresult AppendQuery(nsAutoPtr<nsMediaQuery>& aQuery) {
     // Takes ownership of aQuery (if it succeeds)
     if (!mArray.AppendElement(aQuery.get())) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
     aQuery.forget();
     return NS_OK;
   }
--- a/layout/style/nsIStyleSheet.h
+++ b/layout/style/nsIStyleSheet.h
@@ -60,17 +60,17 @@ class nsIStyleRuleProcessor;
 { 0x7b2d31da, 0xc3fb, 0x4537,   \
  { 0xbd, 0x97, 0x33, 0x72, 0x72, 0xb8, 0x35, 0x68 } }
 
 /**
  * A style sheet is a thing associated with a document that has style
  * rules.  Those style rules can be reached in one of two ways, depending
  * on which level of the nsStyleSet it is in:
  *   1) It can be |QueryInterface|d to nsIStyleRuleProcessor
- *   2) It can be |QueryInterface|d to nsICSSStyleSheet, with which the
+ *   2) It can be |QueryInterface|d to nsCSSStyleSheet, with which the
  *      |nsStyleSet| uses an |nsCSSRuleProcessor| to access the rules.
  */
 class nsIStyleSheet : public nsISupports {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_SHEET_IID)
 
   // basic style sheet data
   NS_IMETHOD GetSheetURI(nsIURI** aSheetURI) const = 0;
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -40,16 +40,17 @@
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsCSSLoader.h"
 #include "nsIFile.h"
 #include "nsLayoutCID.h"
 #include "nsNetUtil.h"
 #include "nsIObserverService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIXULRuntime.h"
+#include "nsCSSStyleSheet.h"
 
 NS_IMPL_ISUPPORTS1(nsLayoutStylesheetCache, nsIObserver)
 
 nsresult
 nsLayoutStylesheetCache::Observe(nsISupports* aSubject,
                             const char* aTopic,
                             const PRUnichar* aData)
 {
@@ -66,17 +67,17 @@ nsLayoutStylesheetCache::Observe(nsISupp
     mFormsSheet = nsnull;
   }
   else {
     NS_NOTREACHED("Unexpected observer topic.");
   }
   return NS_OK;
 }
 
-nsICSSStyleSheet*
+nsCSSStyleSheet*
 nsLayoutStylesheetCache::ScrollbarsSheet()
 {
   EnsureGlobal();
   if (!gStyleCache)
     return nsnull;
 
   if (!gStyleCache->mScrollbarsSheet) {
     nsCOMPtr<nsIURI> sheetURI;
@@ -87,17 +88,17 @@ nsLayoutStylesheetCache::ScrollbarsSheet
     if (sheetURI)
       LoadSheet(sheetURI, gStyleCache->mScrollbarsSheet, PR_FALSE);
     NS_ASSERTION(gStyleCache->mScrollbarsSheet, "Could not load scrollbars.css.");
   }
 
   return gStyleCache->mScrollbarsSheet;
 }
 
-nsICSSStyleSheet*
+nsCSSStyleSheet*
 nsLayoutStylesheetCache::FormsSheet()
 {
   EnsureGlobal();
   if (!gStyleCache)
     return nsnull;
 
   if (!gStyleCache->mFormsSheet) {
     nsCOMPtr<nsIURI> sheetURI;
@@ -109,47 +110,47 @@ nsLayoutStylesheetCache::FormsSheet()
       LoadSheet(sheetURI, gStyleCache->mFormsSheet, PR_TRUE);
 
     NS_ASSERTION(gStyleCache->mFormsSheet, "Could not load forms.css.");
   }
 
   return gStyleCache->mFormsSheet;
 }
 
-nsICSSStyleSheet*
+nsCSSStyleSheet*
 nsLayoutStylesheetCache::UserContentSheet()
 {
   EnsureGlobal();
   if (!gStyleCache)
     return nsnull;
 
   return gStyleCache->mUserContentSheet;
 }
 
-nsICSSStyleSheet*
+nsCSSStyleSheet*
 nsLayoutStylesheetCache::UserChromeSheet()
 {
   EnsureGlobal();
   if (!gStyleCache)
     return nsnull;
 
   return gStyleCache->mUserChromeSheet;
 }
 
-nsICSSStyleSheet*
+nsCSSStyleSheet*
 nsLayoutStylesheetCache::UASheet()
 {
   EnsureGlobal();
   if (!gStyleCache)
     return nsnull;
 
   return gStyleCache->mUASheet;
 }
 
-nsICSSStyleSheet*
+nsCSSStyleSheet*
 nsLayoutStylesheetCache::QuirkSheet()
 {
   EnsureGlobal();
   if (!gStyleCache)
     return nsnull;
 
   return gStyleCache->mQuirkSheet;
 }
@@ -235,32 +236,32 @@ nsLayoutStylesheetCache::InitFromProfile
   contentFile->Append(NS_LITERAL_STRING("userContent.css"));
   chromeFile->Append(NS_LITERAL_STRING("userChrome.css"));
 
   LoadSheetFile(contentFile, mUserContentSheet);
   LoadSheetFile(chromeFile, mUserChromeSheet);
 }
 
 void
-nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet> &aSheet)
+nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, nsRefPtr<nsCSSStyleSheet> &aSheet)
 {
   PRBool exists = PR_FALSE;
   aFile->Exists(&exists);
 
   if (!exists) return;
 
   nsCOMPtr<nsIURI> uri;
   NS_NewFileURI(getter_AddRefs(uri), aFile);
 
   LoadSheet(uri, aSheet, PR_FALSE);
 }
 
 void
 nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
-                                   nsCOMPtr<nsICSSStyleSheet> &aSheet,
+                                   nsRefPtr<nsCSSStyleSheet> &aSheet,
                                    PRBool aEnableUnsafeRules)
 {
   if (!aURI) {
     NS_ERROR("Null URI. Out of memory?");
     return;
   }
 
   if (!gCSSLoader) { 
--- a/layout/style/nsLayoutStylesheetCache.h
+++ b/layout/style/nsLayoutStylesheetCache.h
@@ -33,56 +33,58 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsLayoutStylesheetCache_h__
 #define nsLayoutStylesheetCache_h__
 
-#include "nsICSSStyleSheet.h"
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
+#include "nsAutoPtr.h"
 
 class nsIFile;
+class nsCSSStyleSheet;
+class nsIURI;
 
 namespace mozilla {
 namespace css {
 class Loader;
 }
 }
 
 class nsLayoutStylesheetCache
  : public nsIObserver
 {
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
-  static nsICSSStyleSheet* ScrollbarsSheet();
-  static nsICSSStyleSheet* FormsSheet();
-  static nsICSSStyleSheet* UserContentSheet();
-  static nsICSSStyleSheet* UserChromeSheet();
-  static nsICSSStyleSheet* UASheet();
-  static nsICSSStyleSheet* QuirkSheet();
+  static nsCSSStyleSheet* ScrollbarsSheet();
+  static nsCSSStyleSheet* FormsSheet();
+  static nsCSSStyleSheet* UserContentSheet();
+  static nsCSSStyleSheet* UserChromeSheet();
+  static nsCSSStyleSheet* UASheet();
+  static nsCSSStyleSheet* QuirkSheet();
 
   static void Shutdown();
 
 private:
   nsLayoutStylesheetCache();
   ~nsLayoutStylesheetCache();
 
   static void EnsureGlobal();
   void InitFromProfile();
-  static void LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet> &aSheet);
-  static void LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSheet,
+  static void LoadSheetFile(nsIFile* aFile, nsRefPtr<nsCSSStyleSheet> &aSheet);
+  static void LoadSheet(nsIURI* aURI, nsRefPtr<nsCSSStyleSheet> &aSheet,
                         PRBool aEnableUnsafeRules);
 
   static nsLayoutStylesheetCache* gStyleCache;
   static mozilla::css::Loader* gCSSLoader;
-  nsCOMPtr<nsICSSStyleSheet> mScrollbarsSheet;
-  nsCOMPtr<nsICSSStyleSheet> mFormsSheet;
-  nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
-  nsCOMPtr<nsICSSStyleSheet> mUserChromeSheet;
-  nsCOMPtr<nsICSSStyleSheet> mUASheet;
-  nsCOMPtr<nsICSSStyleSheet> mQuirkSheet;
+  nsRefPtr<nsCSSStyleSheet> mScrollbarsSheet;
+  nsRefPtr<nsCSSStyleSheet> mFormsSheet;
+  nsRefPtr<nsCSSStyleSheet> mUserContentSheet;
+  nsRefPtr<nsCSSStyleSheet> mUserChromeSheet;
+  nsRefPtr<nsCSSStyleSheet> mUASheet;
+  nsRefPtr<nsCSSStyleSheet> mQuirkSheet;
 };
 
 #endif
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -41,17 +41,17 @@
 /*
  * the container for the style sheets that apply to a presentation, and
  * the internal API that the style system exposes for creating (and
  * potentially re-creating) style contexts
  */
 
 #include "nsStyleSet.h"
 #include "nsNetUtil.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 #include "nsIDocument.h"
 #include "nsRuleWalker.h"
 #include "nsStyleContext.h"
 #include "nsICSSStyleRule.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsIContent.h"
@@ -209,21 +209,21 @@ nsStyleSet::GatherRuleProcessors(sheetTy
   if (mSheets[aType].Count()) {
     switch (aType) {
       case eAgentSheet:
       case eUserSheet:
       case eDocSheet:
       case eOverrideSheet: {
         // levels containing CSS stylesheets
         nsCOMArray<nsIStyleSheet>& sheets = mSheets[aType];
-        nsCOMArray<nsICSSStyleSheet> cssSheets(sheets.Count());
+        nsTArray<nsRefPtr<nsCSSStyleSheet> > cssSheets(sheets.Count());
         for (PRInt32 i = 0, i_end = sheets.Count(); i < i_end; ++i) {
-          nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(sheets[i]);
+          nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheets[i]);
           NS_ASSERTION(cssSheet, "not a CSS sheet");
-          cssSheets.AppendObject(cssSheet);
+          cssSheets.AppendElement(cssSheet);
         }
         mRuleProcessors[aType] = new nsCSSRuleProcessor(cssSheets, 
                                                         PRUint8(aType));
       } break;
 
       default:
         // levels containing non-CSS stylesheets
         NS_ASSERTION(mSheets[aType].Count() == 1, "only one sheet per level");
--- a/layout/style/test/ParseCSS.cpp
+++ b/layout/style/test/ParseCSS.cpp
@@ -47,17 +47,17 @@
 #include "nsXPCOM.h"
 #include "nsCOMPtr.h"
 
 #include "nsILocalFile.h"
 #include "nsNetUtil.h"
 
 #include "nsContentCID.h"
 #include "nsCSSLoader.h"
-#include "nsICSSStyleSheet.h"
+#include "nsCSSStyleSheet.h"
 
 static already_AddRefed<nsIURI>
 FileToURI(const char *aFilename, nsresult *aRv = 0)
 {
     nsCOMPtr<nsILocalFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, aRv));
     NS_ENSURE_TRUE(lf, nsnull);
     // XXX Handle relative paths somehow.
     lf->InitWithNativePath(nsDependentCString(aFilename));
@@ -68,17 +68,17 @@ FileToURI(const char *aFilename, nsresul
         *aRv = rv;
     return uri;
 }
 
 static int
 ParseCSSFile(nsIURI *aSheetURI)
 {
     nsRefPtr<mozilla::css::Loader> = new mozilla::css::Loader();
-    nsCOMPtr<nsICSSStyleSheet> sheet;
+    nsRefPtr<nsCSSStyleSheet> sheet;
     loader->LoadSheetSync(aSheetURI, getter_AddRefs(sheet));
     NS_ASSERTION(sheet, "sheet load failed");
     /* This can happen if the file can't be found (e.g. you
      * ask for a relative path and xpcom/io rejects it)
      */
     if (!sheet)
         return -1;
     PRBool complete;
--- a/parser/htmlparser/src/nsParser.cpp
+++ b/parser/htmlparser/src/nsParser.cpp
@@ -66,17 +66,16 @@
 #include "nsStreamUtils.h"
 #include "nsHTMLTokenizer.h"
 #include "nsIDocument.h"
 #include "nsNetUtil.h"
 #include "nsScriptLoader.h"
 #include "nsDataHashtable.h"
 #include "nsIThreadPool.h"
 #include "nsXPCOMCIDInternal.h"
-#include "nsICSSStyleSheet.h"
 #include "nsMimeTypes.h"
 
 #ifdef MOZ_VIEW_SOURCE
 #include "nsViewSourceHTML.h"
 #endif
 
 #define NS_PARSER_FLAG_PARSER_ENABLED         0x00000002
 #define NS_PARSER_FLAG_OBSERVERS_ENABLED      0x00000004