Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsContentDLF.cpp File Reference
#include "nsCOMPtr.h"
#include "nsContentDLF.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLAtoms.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsICategoryManager.h"
#include "nsIDocumentLoader.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIURL.h"
#include "nsICSSStyleSheet.h"
#include "nsNodeInfo.h"
#include "nsNodeInfoManager.h"
#include "nsString.h"
#include "nsContentCID.h"
#include "prprf.h"
#include "nsNetUtil.h"
#include "nsICSSLoader.h"
#include "nsCRT.h"
#include "nsIViewSourceChannel.h"
#include "nsRDFCID.h"
#include "nsIRDFResource.h"
#include "imgILoader.h"
#include "nsIParser.h"
#include "nsIPluginManager.h"
#include "nsIPluginHost.h"

Go to the source code of this file.

Defines

#define UA_CSS_URL   "resource://gre/res/ua.css"

Functions

static NS_DEFINE_CID (kPluginManagerCID, NS_PLUGINMANAGER_CID)
static NS_DEFINE_CID (kPluginDocumentCID, NS_PLUGINDOCUMENT_CID)
static NS_DEFINE_IID (kHTMLDocumentCID, NS_HTMLDOCUMENT_CID)
static NS_DEFINE_IID (kXMLDocumentCID, NS_XMLDOCUMENT_CID)
static NS_DEFINE_IID (kImageDocumentCID, NS_IMAGEDOCUMENT_CID)
static NS_DEFINE_IID (kXULDocumentCID, NS_XULDOCUMENT_CID)
nsresult NS_NewDocumentViewer (nsIDocumentViewer **aResult)
nsresult NS_NewContentDocumentLoaderFactory (nsIDocumentLoaderFactory **aResult)
 NS_IMPL_ISUPPORTS1 (nsContentDLF, nsIDocumentLoaderFactory) NS_IMETHODIMP nsContentDLF
static nsresult RegisterTypes (nsICategoryManager *aCatMgr, const char *const *aTypes, PRBool aPersist=PR_TRUE)
static nsresult UnregisterTypes (nsICategoryManager *aCatMgr, const char *const *aTypes)

Variables

static const char *const gHTMLTypes []
static const char *const gXMLTypes []
static const char *const gRDFTypes []

Define Documentation

#define UA_CSS_URL   "resource://gre/res/ua.css"

Definition at line 73 of file nsContentDLF.cpp.


Function Documentation

static NS_DEFINE_CID ( kPluginManagerCID  ,
NS_PLUGINMANAGER_CID   
) [static]
static NS_DEFINE_CID ( kPluginDocumentCID  ,
NS_PLUGINDOCUMENT_CID   
) [static]
static NS_DEFINE_IID ( kHTMLDocumentCID  ,
NS_HTMLDOCUMENT_CID   
) [static]
static NS_DEFINE_IID ( kXMLDocumentCID  ,
NS_XMLDOCUMENT_CID   
) [static]
static NS_DEFINE_IID ( kImageDocumentCID  ,
NS_IMAGEDOCUMENT_CID   
) [static]
static NS_DEFINE_IID ( kXULDocumentCID  ,
NS_XULDOCUMENT_CID   
) [static]

Definition at line 156 of file nsContentDLF.cpp.

{
  EnsureUAStyleSheet();

  // Are we viewing source?
#ifdef MOZ_VIEW_SOURCE
  nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel);
  if (viewSourceChannel)
  {
    aCommand = "view-source";

    // The parser freaks out when it sees the content-type that a
    // view-source channel normally returns.  Get the actual content
    // type of the data.  If it's known, use it; otherwise use
    // text/plain.
    nsCAutoString type;
    viewSourceChannel->GetOriginalContentType(type);
    PRBool knownType = PR_FALSE;
    PRInt32 typeIndex;
    for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) {
      if (type.Equals(gHTMLTypes[typeIndex]) &&
          !type.EqualsLiteral("application/x-view-source")) {
        knownType = PR_TRUE;
      }
    }

    for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) {
      if (type.Equals(gXMLTypes[typeIndex])) {
        knownType = PR_TRUE;
      }
    }

#ifdef MOZ_SVG
    if (nsSVGUtils::SVGEnabled()) {
      for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) {
        if (type.Equals(gSVGTypes[typeIndex])) {
          knownType = PR_TRUE;
        }
      }
    }
#endif // MOZ_SVG

    for (typeIndex = 0; gRDFTypes[typeIndex] && !knownType; ++typeIndex) {
      if (type.Equals(gRDFTypes[typeIndex])) {
        knownType = PR_TRUE;
      }
    }

    if (knownType) {
      viewSourceChannel->SetContentType(type);
    } else {
      viewSourceChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
    }
  } else if (0 == PL_strcmp("application/x-view-source", aContentType)) {
    aChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
    aContentType = "text/plain";
  }
#endif
  // Try html
  int typeIndex=0;
  while(gHTMLTypes[typeIndex]) {
    if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
      return CreateDocument(aCommand, 
                            aChannel, aLoadGroup,
                            aContainer, kHTMLDocumentCID,
                            aDocListener, aDocViewer);
    }
  }

  // Try XML
  typeIndex = 0;
  while(gXMLTypes[typeIndex]) {
    if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
      return CreateDocument(aCommand, 
                            aChannel, aLoadGroup,
                            aContainer, kXMLDocumentCID,
                            aDocListener, aDocViewer);
    }
  }

#ifdef MOZ_SVG
  if (nsSVGUtils::SVGEnabled()) {
    // Try SVG
    typeIndex = 0;
    while(gSVGTypes[typeIndex]) {
      if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) {
        return CreateDocument(aCommand,
                              aChannel, aLoadGroup,
                              aContainer, kSVGDocumentCID,
                              aDocListener, aDocViewer);
      }
    }
  }
#endif

  // Try RDF
  typeIndex = 0;
  while (gRDFTypes[typeIndex]) {
    if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
      return CreateRDFDocument(aCommand, 
                               aChannel, aLoadGroup,
                               aContentType, aContainer,
                               aExtraInfo, aDocListener, aDocViewer);
    }
  }

  // Try image types
  nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));
  PRBool isReg = PR_FALSE;
  loader->SupportImageWithMimeType(aContentType, &isReg);
  if (isReg) {
    return CreateDocument(aCommand, 
                          aChannel, aLoadGroup,
                          aContainer, kImageDocumentCID,
                          aDocListener, aDocViewer);
  }

  nsCOMPtr<nsIPluginHost> ph (do_GetService(kPluginManagerCID));
  if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) {
    return CreateDocument(aCommand,
                          aChannel, aLoadGroup,
                          aContainer, kPluginDocumentCID,
                          aDocListener, aDocViewer);
  }


  // If we get here, then we weren't able to create anything. Sorry!
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Definition at line 134 of file nsContentDLF.cpp.

{
  NS_PRECONDITION(aResult, "null OUT ptr");
  if (!aResult) {
    return NS_ERROR_NULL_POINTER;
  }
  nsContentDLF* it = new nsContentDLF();
  if (!it) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  return CallQueryInterface(it, aResult);
}

Here is the call graph for this function:

Definition at line 465 of file nsDocumentViewer.cpp.

{
  *aResult = new DocumentViewerImpl(nsnull);
  if (!*aResult) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  NS_ADDREF(*aResult);

  return NS_OK;
}
static nsresult RegisterTypes ( nsICategoryManager aCatMgr,
const char *const aTypes,
PRBool  aPersist = PR_TRUE 
) [static]

Definition at line 518 of file nsContentDLF.cpp.

{
  nsresult rv = NS_OK;
  while (*aTypes) {
    const char* contentType = *aTypes++;
#ifdef NOISY_REGISTRY
    printf("Register %s => %s\n", contractid, aPath);
#endif
    // add the MIME types layout can handle to the handlers category.
    // this allows users of layout's viewers (the docshell for example)
    // to query the types of viewers layout can create.
    rv = aCatMgr->AddCategoryEntry("Gecko-Content-Viewers", contentType,
                                   "@mozilla.org/content/document-loader-factory;1",
                                   aPersist, PR_TRUE, nsnull);
    if (NS_FAILED(rv)) break;
  }
  return rv;
}

Here is the caller graph for this function:

static nsresult UnregisterTypes ( nsICategoryManager aCatMgr,
const char *const aTypes 
) [static]

Definition at line 539 of file nsContentDLF.cpp.

{
  nsresult rv = NS_OK;
  while (*aTypes) {
    const char* contentType = *aTypes++;
    rv = aCatMgr->DeleteCategoryEntry("Gecko-Content-Viewers", contentType, PR_TRUE);
    if (NS_FAILED(rv)) break;
  }
  return rv;

}

Here is the caller graph for this function:


Variable Documentation

const char* const gHTMLTypes[] [static]
Initial value:
 {
  "text/html",
  "text/plain",
  "text/css",
  "text/javascript",
  "text/ecmascript",
  "application/javascript",
  "application/ecmascript",
  "application/x-javascript",



  "application/xhtml+xml",
  0
}

Definition at line 92 of file nsContentDLF.cpp.

const char* const gRDFTypes[] [static]
Initial value:
 {
  "application/rdf+xml",
  "text/rdf",
  "application/vnd.mozilla.xul+xml",
  "mozilla.application/cached-xul",
  0
}

Definition at line 123 of file nsContentDLF.cpp.

const char* const gXMLTypes[] [static]
Initial value:
 {
  "text/xml",
  "application/xml",
  0
}

Definition at line 108 of file nsContentDLF.cpp.