Back to index

lightning-sunbird  0.9+nobinonly
nsContentDLF.cpp
Go to the documentation of this file.
00001 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "nsCOMPtr.h"
00038 #include "nsContentDLF.h"
00039 #include "nsGenericHTMLElement.h"
00040 #include "nsHTMLAtoms.h"
00041 #include "nsIComponentManager.h"
00042 #include "nsIComponentRegistrar.h"
00043 #include "nsICategoryManager.h"
00044 #include "nsIDocumentLoader.h"
00045 #include "nsIDocumentLoaderFactory.h"
00046 #include "nsIDocument.h"
00047 #include "nsIDocumentViewer.h"
00048 #include "nsIURL.h"
00049 #include "nsICSSStyleSheet.h"
00050 #include "nsNodeInfo.h"
00051 #include "nsNodeInfoManager.h"
00052 #include "nsString.h"
00053 #include "nsContentCID.h"
00054 #include "prprf.h"
00055 #include "nsNetUtil.h"
00056 #include "nsICSSLoader.h"
00057 #include "nsCRT.h"
00058 #include "nsIViewSourceChannel.h"
00059 
00060 #include "nsRDFCID.h"
00061 #include "nsIRDFResource.h"
00062 
00063 #include "imgILoader.h"
00064 #include "nsIParser.h"
00065 
00066 // plugins
00067 #include "nsIPluginManager.h"
00068 #include "nsIPluginHost.h"
00069 static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
00070 static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
00071 
00072 // URL for the "user agent" style sheet
00073 #define UA_CSS_URL "resource://gre/res/ua.css"
00074 
00075 // Factory code for creating variations on html documents
00076 
00077 #undef NOISY_REGISTRY
00078 
00079 static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
00080 static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
00081 #ifdef MOZ_SVG
00082 static NS_DEFINE_IID(kSVGDocumentCID, NS_SVGDOCUMENT_CID);
00083 #endif
00084 static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
00085 static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
00086 
00087 nsresult
00088 NS_NewDocumentViewer(nsIDocumentViewer** aResult);
00089 
00090 // XXXbz if you change the MIME types here, be sure to update
00091 // nsIParser.h and DetermineParseMode in nsParser.cpp accordingly.
00092 static const char* const gHTMLTypes[] = {
00093   "text/html",
00094   "text/plain",
00095   "text/css",
00096   "text/javascript",
00097   "text/ecmascript",
00098   "application/javascript",
00099   "application/ecmascript",
00100   "application/x-javascript",
00101 #ifdef MOZ_VIEW_SOURCE
00102   "application/x-view-source", //XXX I wish I could just use nsMimeTypes.h here
00103 #endif
00104   "application/xhtml+xml",
00105   0
00106 };
00107   
00108 static const char* const gXMLTypes[] = {
00109   "text/xml",
00110   "application/xml",
00111   0
00112 };
00113 
00114 #ifdef MOZ_SVG
00115 static const char* const gSVGTypes[] = {
00116   "image/svg+xml",
00117   0
00118 };
00119 
00120 #include "nsSVGUtils.h"
00121 #endif
00122 
00123 static const char* const gRDFTypes[] = {
00124   "application/rdf+xml",
00125   "text/rdf",
00126   "application/vnd.mozilla.xul+xml",
00127   "mozilla.application/cached-xul",
00128   0
00129 };
00130 
00131 nsICSSStyleSheet* nsContentDLF::gUAStyleSheet;
00132 
00133 nsresult
00134 NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
00135 {
00136   NS_PRECONDITION(aResult, "null OUT ptr");
00137   if (!aResult) {
00138     return NS_ERROR_NULL_POINTER;
00139   }
00140   nsContentDLF* it = new nsContentDLF();
00141   if (!it) {
00142     return NS_ERROR_OUT_OF_MEMORY;
00143   }
00144 
00145   return CallQueryInterface(it, aResult);
00146 }
00147 
00148 nsContentDLF::nsContentDLF()
00149 {
00150 }
00151 
00152 nsContentDLF::~nsContentDLF()
00153 {
00154 }
00155 
00156 NS_IMPL_ISUPPORTS1(nsContentDLF,
00157                    nsIDocumentLoaderFactory)
00158 
00159 NS_IMETHODIMP
00160 nsContentDLF::CreateInstance(const char* aCommand,
00161                              nsIChannel* aChannel,
00162                              nsILoadGroup* aLoadGroup,
00163                              const char* aContentType, 
00164                              nsISupports* aContainer,
00165                              nsISupports* aExtraInfo,
00166                              nsIStreamListener** aDocListener,
00167                              nsIContentViewer** aDocViewer)
00168 {
00169   EnsureUAStyleSheet();
00170 
00171   // Are we viewing source?
00172 #ifdef MOZ_VIEW_SOURCE
00173   nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel);
00174   if (viewSourceChannel)
00175   {
00176     aCommand = "view-source";
00177 
00178     // The parser freaks out when it sees the content-type that a
00179     // view-source channel normally returns.  Get the actual content
00180     // type of the data.  If it's known, use it; otherwise use
00181     // text/plain.
00182     nsCAutoString type;
00183     viewSourceChannel->GetOriginalContentType(type);
00184     PRBool knownType = PR_FALSE;
00185     PRInt32 typeIndex;
00186     for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) {
00187       if (type.Equals(gHTMLTypes[typeIndex]) &&
00188           !type.EqualsLiteral("application/x-view-source")) {
00189         knownType = PR_TRUE;
00190       }
00191     }
00192 
00193     for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) {
00194       if (type.Equals(gXMLTypes[typeIndex])) {
00195         knownType = PR_TRUE;
00196       }
00197     }
00198 
00199 #ifdef MOZ_SVG
00200     if (nsSVGUtils::SVGEnabled()) {
00201       for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) {
00202         if (type.Equals(gSVGTypes[typeIndex])) {
00203           knownType = PR_TRUE;
00204         }
00205       }
00206     }
00207 #endif // MOZ_SVG
00208 
00209     for (typeIndex = 0; gRDFTypes[typeIndex] && !knownType; ++typeIndex) {
00210       if (type.Equals(gRDFTypes[typeIndex])) {
00211         knownType = PR_TRUE;
00212       }
00213     }
00214 
00215     if (knownType) {
00216       viewSourceChannel->SetContentType(type);
00217     } else {
00218       viewSourceChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
00219     }
00220   } else if (0 == PL_strcmp("application/x-view-source", aContentType)) {
00221     aChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
00222     aContentType = "text/plain";
00223   }
00224 #endif
00225   // Try html
00226   int typeIndex=0;
00227   while(gHTMLTypes[typeIndex]) {
00228     if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
00229       return CreateDocument(aCommand, 
00230                             aChannel, aLoadGroup,
00231                             aContainer, kHTMLDocumentCID,
00232                             aDocListener, aDocViewer);
00233     }
00234   }
00235 
00236   // Try XML
00237   typeIndex = 0;
00238   while(gXMLTypes[typeIndex]) {
00239     if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
00240       return CreateDocument(aCommand, 
00241                             aChannel, aLoadGroup,
00242                             aContainer, kXMLDocumentCID,
00243                             aDocListener, aDocViewer);
00244     }
00245   }
00246 
00247 #ifdef MOZ_SVG
00248   if (nsSVGUtils::SVGEnabled()) {
00249     // Try SVG
00250     typeIndex = 0;
00251     while(gSVGTypes[typeIndex]) {
00252       if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) {
00253         return CreateDocument(aCommand,
00254                               aChannel, aLoadGroup,
00255                               aContainer, kSVGDocumentCID,
00256                               aDocListener, aDocViewer);
00257       }
00258     }
00259   }
00260 #endif
00261 
00262   // Try RDF
00263   typeIndex = 0;
00264   while (gRDFTypes[typeIndex]) {
00265     if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
00266       return CreateRDFDocument(aCommand, 
00267                                aChannel, aLoadGroup,
00268                                aContentType, aContainer,
00269                                aExtraInfo, aDocListener, aDocViewer);
00270     }
00271   }
00272 
00273   // Try image types
00274   nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));
00275   PRBool isReg = PR_FALSE;
00276   loader->SupportImageWithMimeType(aContentType, &isReg);
00277   if (isReg) {
00278     return CreateDocument(aCommand, 
00279                           aChannel, aLoadGroup,
00280                           aContainer, kImageDocumentCID,
00281                           aDocListener, aDocViewer);
00282   }
00283 
00284   nsCOMPtr<nsIPluginHost> ph (do_GetService(kPluginManagerCID));
00285   if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) {
00286     return CreateDocument(aCommand,
00287                           aChannel, aLoadGroup,
00288                           aContainer, kPluginDocumentCID,
00289                           aDocListener, aDocViewer);
00290   }
00291 
00292 
00293   // If we get here, then we weren't able to create anything. Sorry!
00294   return NS_ERROR_FAILURE;
00295 }
00296 
00297 
00298 NS_IMETHODIMP
00299 nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
00300                                         nsIDocument* aDocument,
00301                                         const char *aCommand,
00302                                         nsIContentViewer** aDocViewerResult)
00303 {
00304   nsresult rv = NS_ERROR_FAILURE;  
00305 
00306   EnsureUAStyleSheet();
00307 
00308   do {
00309     nsCOMPtr<nsIDocumentViewer> docv;
00310     rv = NS_NewDocumentViewer(getter_AddRefs(docv));
00311     if (NS_FAILED(rv))
00312       break;
00313 
00314     docv->SetUAStyleSheet(NS_STATIC_CAST(nsIStyleSheet*, gUAStyleSheet));
00315 
00316     // Bind the document to the Content Viewer
00317     nsIContentViewer* cv = NS_STATIC_CAST(nsIContentViewer*, docv.get());
00318     rv = cv->LoadStart(aDocument);
00319     NS_ADDREF(*aDocViewerResult = cv);
00320   } while (PR_FALSE);
00321 
00322   return rv;
00323 }
00324 
00325 NS_IMETHODIMP
00326 nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup, nsIDocument **aDocument)
00327 {
00328   *aDocument = nsnull;
00329 
00330   nsresult rv = NS_ERROR_FAILURE;
00331 
00332   // create a new blank HTML document
00333   nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
00334 
00335   if (blankDoc) {
00336     // initialize
00337     nsCOMPtr<nsIURI> uri;
00338     NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
00339     if (uri) {
00340       blankDoc->ResetToURI(uri, aLoadGroup);
00341       rv = NS_OK;
00342     }
00343   }
00344 
00345   // add some simple content structure
00346   if (NS_SUCCEEDED(rv)) {
00347     rv = NS_ERROR_FAILURE;
00348 
00349     nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
00350 
00351     nsCOMPtr<nsINodeInfo> htmlNodeInfo;
00352 
00353     // generate an html html element
00354     nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None,
00355                      getter_AddRefs(htmlNodeInfo));
00356     nsCOMPtr<nsIContent> htmlElement = NS_NewHTMLHtmlElement(htmlNodeInfo);
00357 
00358     // generate an html head element
00359     nim->GetNodeInfo(nsHTMLAtoms::head, 0, kNameSpaceID_None,
00360                      getter_AddRefs(htmlNodeInfo));
00361     nsCOMPtr<nsIContent> headElement = NS_NewHTMLHeadElement(htmlNodeInfo);
00362 
00363     // generate an html body element
00364     nim->GetNodeInfo(nsHTMLAtoms::body, 0, kNameSpaceID_None,
00365                      getter_AddRefs(htmlNodeInfo));
00366     nsCOMPtr<nsIContent> bodyElement = NS_NewHTMLBodyElement(htmlNodeInfo);
00367 
00368     // blat in the structure
00369     if (htmlElement && headElement && bodyElement) {
00370       rv = blankDoc->SetRootContent(htmlElement);
00371       if (NS_SUCCEEDED(rv)) {
00372         rv = htmlElement->AppendChildTo(headElement, PR_FALSE);
00373 
00374         if (NS_SUCCEEDED(rv)) {
00375           bodyElement->SetContentID(blankDoc->GetAndIncrementContentID());
00376           // XXXbz Why not notifying here?
00377           htmlElement->AppendChildTo(bodyElement, PR_FALSE);
00378         }
00379       }
00380     }
00381   }
00382 
00383   // add a nice bow
00384   if (NS_SUCCEEDED(rv)) {
00385     blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
00386     blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
00387     
00388     *aDocument = blankDoc;
00389     NS_ADDREF(*aDocument);
00390   }
00391   return rv;
00392 }
00393 
00394 
00395 nsresult
00396 nsContentDLF::CreateDocument(const char* aCommand,
00397                              nsIChannel* aChannel,
00398                              nsILoadGroup* aLoadGroup,
00399                              nsISupports* aContainer,
00400                              const nsCID& aDocumentCID,
00401                              nsIStreamListener** aDocListener,
00402                              nsIContentViewer** aDocViewer)
00403 {
00404   nsresult rv = NS_ERROR_FAILURE;
00405 
00406   nsCOMPtr<nsIURI> aURL;
00407   rv = aChannel->GetURI(getter_AddRefs(aURL));
00408   if (NS_FAILED(rv)) return rv;
00409 
00410 #ifdef NOISY_CREATE_DOC
00411   if (nsnull != aURL) {
00412     nsAutoString tmp;
00413     aURL->ToString(tmp);
00414     fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout);
00415     printf(": creating document\n");
00416   }
00417 #endif
00418 
00419   nsCOMPtr<nsIDocument> doc;
00420   nsCOMPtr<nsIDocumentViewer> docv;
00421   do {
00422     // Create the document
00423     doc = do_CreateInstance(aDocumentCID, &rv);
00424     if (NS_FAILED(rv))
00425       break;
00426 
00427     // Create the document viewer  XXX: could reuse document viewer here!
00428     rv = NS_NewDocumentViewer(getter_AddRefs(docv));
00429     if (NS_FAILED(rv))
00430       break;
00431     docv->SetUAStyleSheet(gUAStyleSheet);
00432 
00433     doc->SetContainer(aContainer);
00434 
00435     // Initialize the document to begin loading the data.  An
00436     // nsIStreamListener connected to the parser is returned in
00437     // aDocListener.
00438     rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
00439     if (NS_FAILED(rv))
00440       break;
00441 
00442     // Bind the document to the Content Viewer
00443     rv = docv->LoadStart(doc);
00444     *aDocViewer = docv;
00445     NS_IF_ADDREF(*aDocViewer);
00446   } while (PR_FALSE);
00447 
00448   return rv;
00449 }
00450 
00451 // ...common work for |CreateRDFDocument| and |CreateXULDocumentFromStream|
00452 nsresult
00453 nsContentDLF::CreateRDFDocument(nsISupports* aExtraInfo,
00454                                 nsCOMPtr<nsIDocument>* doc,
00455                                 nsCOMPtr<nsIDocumentViewer>* docv)
00456 {
00457   nsresult rv = NS_ERROR_FAILURE;
00458     
00459   // Create the XUL document
00460   *doc = do_CreateInstance(kXULDocumentCID, &rv);
00461   if (NS_FAILED(rv)) return rv;
00462 
00463   // Create the image content viewer...
00464   rv = NS_NewDocumentViewer(getter_AddRefs(*docv));
00465   if (NS_FAILED(rv)) return rv;
00466 
00467   // Load the UA style sheet if we haven't already done that
00468   (*docv)->SetUAStyleSheet(gUAStyleSheet);
00469 
00470   return NS_OK;
00471 }
00472 
00473 // ...note, this RDF document _may_ be XUL :-)
00474 nsresult
00475 nsContentDLF::CreateRDFDocument(const char* aCommand,
00476                                 nsIChannel* aChannel,
00477                                 nsILoadGroup* aLoadGroup,
00478                                 const char* aContentType,
00479                                 nsISupports* aContainer,
00480                                 nsISupports* aExtraInfo,
00481                                 nsIStreamListener** aDocListener,
00482                                 nsIContentViewer** aDocViewer)
00483 {
00484   nsCOMPtr<nsIDocument> doc;
00485   nsCOMPtr<nsIDocumentViewer> docv;
00486   nsresult rv = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv));
00487   if (NS_FAILED(rv)) {
00488     return rv;
00489   }
00490 
00491   nsCOMPtr<nsIURI> aURL;
00492   rv = aChannel->GetURI(getter_AddRefs(aURL));
00493   if (NS_FAILED(rv)) return rv;
00494 
00495   /* 
00496    * Initialize the document to begin loading the data...
00497    *
00498    * An nsIStreamListener connected to the parser is returned in
00499    * aDocListener.
00500    */
00501 
00502   doc->SetContainer(aContainer);
00503 
00504   rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
00505   if (NS_SUCCEEDED(rv)) {
00506     /*
00507      * Bind the document to the Content Viewer...
00508      */
00509     rv = docv->LoadStart(doc);
00510     *aDocViewer = docv;
00511     NS_IF_ADDREF(*aDocViewer);
00512   }
00513    
00514   return rv;
00515 }
00516 
00517 static nsresult
00518 RegisterTypes(nsICategoryManager* aCatMgr,
00519               const char* const* aTypes,
00520               PRBool aPersist = PR_TRUE)
00521 {
00522   nsresult rv = NS_OK;
00523   while (*aTypes) {
00524     const char* contentType = *aTypes++;
00525 #ifdef NOISY_REGISTRY
00526     printf("Register %s => %s\n", contractid, aPath);
00527 #endif
00528     // add the MIME types layout can handle to the handlers category.
00529     // this allows users of layout's viewers (the docshell for example)
00530     // to query the types of viewers layout can create.
00531     rv = aCatMgr->AddCategoryEntry("Gecko-Content-Viewers", contentType,
00532                                    "@mozilla.org/content/document-loader-factory;1",
00533                                    aPersist, PR_TRUE, nsnull);
00534     if (NS_FAILED(rv)) break;
00535   }
00536   return rv;
00537 }
00538 
00539 static nsresult UnregisterTypes(nsICategoryManager* aCatMgr,
00540                                 const char* const* aTypes)
00541 {
00542   nsresult rv = NS_OK;
00543   while (*aTypes) {
00544     const char* contentType = *aTypes++;
00545     rv = aCatMgr->DeleteCategoryEntry("Gecko-Content-Viewers", contentType, PR_TRUE);
00546     if (NS_FAILED(rv)) break;
00547   }
00548   return rv;
00549 
00550 }
00551 
00552 #ifdef MOZ_SVG
00553 NS_IMETHODIMP
00554 nsContentDLF::RegisterSVG()
00555 {
00556   nsresult rv;
00557   nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
00558   if (NS_FAILED(rv)) return rv;
00559 
00560   return RegisterTypes(catmgr, gSVGTypes, PR_FALSE);
00561 }
00562 
00563 NS_IMETHODIMP
00564 nsContentDLF::UnregisterSVG()
00565 {
00566   nsresult rv;
00567   nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
00568   if (NS_FAILED(rv)) return rv;
00569 
00570   return UnregisterTypes(catmgr, gSVGTypes);
00571 }
00572 #endif
00573 
00574 NS_IMETHODIMP
00575 nsContentDLF::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
00576                                         nsIFile* aPath,
00577                                         const char *aLocation,
00578                                         const char *aType,
00579                                         const nsModuleComponentInfo* aInfo)
00580 {
00581   nsresult rv;
00582 
00583   nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
00584   if (NS_FAILED(rv)) return rv;
00585 
00586   do {
00587     rv = RegisterTypes(catmgr, gHTMLTypes);
00588     if (NS_FAILED(rv))
00589       break;
00590     rv = RegisterTypes(catmgr, gXMLTypes);
00591     if (NS_FAILED(rv))
00592       break;
00593     rv = RegisterTypes(catmgr, gRDFTypes);
00594     if (NS_FAILED(rv))
00595       break;
00596   } while (PR_FALSE);
00597   return rv;
00598 }
00599 
00600 NS_IMETHODIMP
00601 nsContentDLF::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
00602                                           nsIFile* aPath,
00603                                           const char* aRegistryLocation,
00604                                           const nsModuleComponentInfo* aInfo)
00605 {
00606   nsresult rv;
00607   nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
00608   if (NS_FAILED(rv)) return rv;
00609 
00610   do {
00611     rv = UnregisterTypes(catmgr, gHTMLTypes);
00612     if (NS_FAILED(rv))
00613       break;
00614     rv = UnregisterTypes(catmgr, gXMLTypes);
00615     if (NS_FAILED(rv))
00616       break;
00617 #ifdef MOZ_SVG
00618     rv = UnregisterTypes(catmgr, gSVGTypes);
00619     if (NS_FAILED(rv))
00620       break;
00621 #endif
00622     rv = UnregisterTypes(catmgr, gRDFTypes);
00623     if (NS_FAILED(rv))
00624       break;
00625   } while (PR_FALSE);
00626 
00627   return rv;
00628 }
00629 
00630 /* static */ nsresult
00631 nsContentDLF::EnsureUAStyleSheet()
00632 {
00633   if (gUAStyleSheet)
00634     return NS_OK;
00635 
00636   // Load the UA style sheet
00637   nsCOMPtr<nsIURI> uri;
00638   nsresult rv = NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING(UA_CSS_URL));
00639   if (NS_FAILED(rv)) {
00640 #ifdef DEBUG
00641     printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
00642 #endif
00643     return rv;
00644   }
00645   nsCOMPtr<nsICSSLoader> cssLoader;
00646   NS_NewCSSLoader(getter_AddRefs(cssLoader));
00647   if (!cssLoader)
00648     return NS_ERROR_OUT_OF_MEMORY;
00649   nsCOMPtr<nsICSSLoader_MOZILLA_1_8_BRANCH> loader = do_QueryInterface(cssLoader);
00650   rv = loader->LoadSheetSync(uri, PR_TRUE, &gUAStyleSheet);
00651 #ifdef DEBUG
00652   if (NS_FAILED(rv))
00653     printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
00654 #endif
00655   return rv;
00656 }